Skip to content

Commit 9480f3f

Browse files
committed
test: cover the commit-null token fallback from review
When commitRefreshedAuth cannot resolve the account after persist it returns null, and the caller must fall back to the refresh result's access token (never the stale token on the original account object, which would 401 downstream and falsely trigger invalidation cooldown). https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
1 parent f93ebd3 commit 9480f3f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test/rotation-token-refresh.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ describe("ensureFreshAccessToken", () => {
133133
});
134134
});
135135

136+
it("falls back to the refresh result's token when the commit cannot resolve the account", async () => {
137+
const accountManager = managerWith(STALE_EXPIRES);
138+
const original = accountManager.getAccountByIndex(0);
139+
if (!original) throw new Error("fixture account missing");
140+
queuedRefreshMock.mockResolvedValue({
141+
type: "success",
142+
access: "access-new",
143+
refresh: "refresh-new",
144+
expires: NOW + 7_200_000,
145+
});
146+
// The account vanished from storage between refresh and persist: the
147+
// commit reports null and the caller must use the freshly refreshed
148+
// token, never the stale one on the original account object.
149+
vi.spyOn(accountManager, "commitRefreshedAuth").mockResolvedValue(null);
150+
151+
const result = await ensureFreshAccessToken(refreshParams(accountManager));
152+
153+
expect(result.ok).toBe(true);
154+
if (result.ok) {
155+
expect(result.accessToken).toBe("access-new");
156+
expect(result.account).toBe(original);
157+
}
158+
});
159+
136160
it("deduplicates concurrent commits for the same refreshed account", async () => {
137161
const accountManager = managerWith(STALE_EXPIRES);
138162
const commit = vi.spyOn(accountManager, "commitRefreshedAuth");

0 commit comments

Comments
 (0)