Skip to content

Commit e265d53

Browse files
test(config): cover the post-reset rollback the rejected-newer path depends on
CodeRabbit follow-up comment on the 4b3d007 review (Trivial, Functional Correctness, Quick win) against ContextProxy.spec.ts:710-713. It held: the test added in 4b3d007 settles both post-reset writes successfully, so nothing exercises the rollback record that a reset leaves empty. A regression that only records a landed write in persistedValues when no newer write is still in flight passed every test in the file. New test issues an older and a newer write for the same key after resetAllState(), resolves the older one, rejects the newer one, and asserts the mirror reports the landed value - both through getGlobalState() and through getValues(), which is the object export() reads. That test kills the regression CodeRabbit described: recording persistedValues only for the last write standing now fails it. Sweep over the handler: 6 of 7 mutants killed; the survivor is still dropping writeSequences.clear() from the reset, unobservable behind the generation guard. ContextProxy.spec.ts: 48/48. Full unit suite 58 failed / 12009 passed, same 15 pre-existing Windows failures. check-types: 114 pre-existing errors, none in a touched file. ESLint exits 0 with --max-warnings=0 and eslint-suppressions.json unchanged (a --prune-suppressions run rewrote the file without changing any count; reverted).
1 parent 4b3d007 commit e265d53

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎src/core/config/__tests__/ContextProxy.spec.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,32 @@ describe("ContextProxy", () => {
712712

713713
expect(proxy.getGlobalState("apiProvider")).toBe("openrouter")
714714
})
715+
716+
it("restores the write that landed after the reset when a newer one is rejected", async () => {
717+
await proxy.resetAllState()
718+
719+
let settleOlder: (value: undefined) => void = () => {}
720+
let failNewer: (error: Error) => void = () => {}
721+
mockGlobalState.update.mockImplementationOnce(() => new Promise((resolve) => (settleOlder = resolve)))
722+
const older = proxy.updateGlobalState("apiProvider", "anthropic")
723+
mockGlobalState.update.mockImplementationOnce(() => new Promise((_resolve, reject) => (failNewer = reject)))
724+
const newer = proxy.updateGlobalState("apiProvider", "openrouter")
725+
726+
settleOlder(undefined)
727+
await older
728+
729+
// The newer write is still in flight, so the mirror still holds its value.
730+
expect(proxy.getGlobalState("apiProvider")).toBe("openrouter")
731+
732+
failNewer(new Error("globalState write failed"))
733+
await expect(newer).rejects.toThrow("globalState write failed")
734+
735+
// The reset emptied both the mirror and the rollback record, so the landing of
736+
// the older write is the only thing storage holds - the rejected newer write
737+
// falls back to it, not to nothing.
738+
expect(proxy.getGlobalState("apiProvider")).toBe("anthropic")
739+
expect(proxy.getValues().apiProvider).toBe("anthropic")
740+
})
715741
})
716742

717743
describe("invalid apiProvider migration", () => {

0 commit comments

Comments
 (0)