passwd --reset-keyring keeps cloud sync on (#301)

backup() moved sync.json away with the old keyring, so the fresh keyring
never replaced the account copy (seen live on 2026-12-02; fixed by hand with
keyring sync --use-local).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-12-02 07:13:09 -08:00 • committed by GitHub
parent cb0a938e89
commit f10c94ca38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View file

@ -81,12 +81,14 @@ describe("logicsrc passwd", () => {
it("--reset-keyring starts a fresh keyring under the new password and returns its recovery key", async () => {
await seed("vault pw", "lost");
keyring.writeSync({ cloud: true });
const r = await changeAllPasswords(
{ noSync: true, resetKeyring: true },
{ vault, keyring, ask: answers("vault pw"), askNew: async () => "new", say: () => {} }
);
expect(r.keyring).toBe("created");
expect(r.keyringRecoveryKey).toBeTruthy();
expect(keyring.readSync().cloud).toBe(true);
await expect(unlockKeyring(keyring.readMeta()!, { passphrase: "new" })).resolves.toBeInstanceOf(Uint8Array);
}, 60_000);
});

View file

@ -110,9 +110,13 @@ export async function changeAllPasswords(opts: { resetKeyring?: boolean; noSync?
keyring.writeMeta(await rewrapUserKey(keyringMeta, keyringKey, password));
result.keyring = "changed";
} else if (opts.resetKeyring || !keyringMeta) {
// backup() moves the whole dir away, sync.json included: keep the cloud
// setting, or the fresh keyring never replaces the account's copy.
const cloud = keyringMeta ? keyring.readSync().cloud : false;
if (keyringMeta) keyring.backup();
const created = await createKeyring(password);
keyring.writeMeta(created.meta);
keyring.writeSync({ ...keyring.readSync(), cloud });
result.keyring = "created";
result.keyringRecoveryKey = created.recoveryKey;
}