fix(secrets): 同机换号继承上一账号的密钥与代理

A 号在桌面端配好密钥后登出,B 号登录时服务端与本地都缺这些配置,
任务只能整批失败。现在登出前把当前账号的明文密钥与代理存进本机
app.json,B 首次加载时只补服务端空缺的模块(fill-only,后台锁定的
代理不覆盖),并写回 B 的本地镜像与 proxy_users;检测状态不继承,
设置页提示逐项点「检测」确认。

同时修掉登出顺序反了的问题:原来先移除 uid 再清镜像,镜像键带
uid,实际删的是 uid=0 的键,A 的明文镜像会留在本机;换号/会话过期
后内存里的 A 明文也会被 B 继续读到。现在先留快照、再清缓存、最后
移除 uid,并在 uid 变化时作废旧会话缓存、给在飞的加载加 epoch 栅栏。
This commit is contained in:
2026-10-25 22:37:13 +08:00
parent 9b2469ec33
commit 8323245567
7 changed files with 544 additions and 46 deletions
@@ -138,6 +138,23 @@ test('登录页认停用/删除标记:各有判定入口、各自关自动登
)
})
test('登出先留继承快照再清缓存,且清缓存必须早于移除 uid', () => {
const cleanupStart = loginPageSource.indexOf('const clearSignedOutState = () => {')
const captureCall = loginPageSource.indexOf('void captureApiSecretsForInheritance()')
assert.ok(cleanupStart > 0, '登出清理函数不见了')
assert.ok(captureCall > cleanupStart, '登出时应先调用继承快照再执行清理')
const cleanupBody = loginPageSource.slice(cleanupStart, captureCall)
const clearAt = cleanupBody.indexOf('clearApiSecretCache()')
const removeUidAt = cleanupBody.indexOf("removeItem('uid')")
assert.ok(clearAt > 0, '登出清理没有清密钥缓存')
assert.ok(removeUidAt > clearAt, '密钥镜像键带 uid,先移除 uid 会删错键、把本账号明文留在本机')
assert.match(
loginPageSource,
/captureApiSecretsForInheritance\(\)\.then\(clearSignedOutState, clearSignedOutState\)/,
'继承快照失败也必须照常登出',
)
})
test('停用/删除文案必须互不冒充:停用句不说删除、删除句不说停用', () => {
const disabledLine = loginPageSource
.split('\n')