Skip to content

Commit d281366

Browse files
committed
refactor: drop unused pool lastUsed preservation
1 parent fe4d83c commit d281366

2 files changed

Lines changed: 2 additions & 127 deletions

File tree

lib/runtime/account-pool.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export type TokenSuccessWithAccount = Extract<
1616
export async function persistAccountPoolResults(params: {
1717
results: TokenSuccessWithAccount[];
1818
replaceAll?: boolean;
19-
preserveLastUsedOnUpdate?: boolean;
2019
modelFamilies: readonly ModelFamily[];
2120
withAccountStorageTransaction: <T>(
2221
handler: (
@@ -32,11 +31,7 @@ export async function persistAccountPoolResults(params: {
3231
) => string | undefined;
3332
sanitizeEmail: (email: string | undefined) => string | undefined;
3433
}): Promise<void> {
35-
const {
36-
results,
37-
replaceAll = false,
38-
preserveLastUsedOnUpdate = false,
39-
} = params;
34+
const { results, replaceAll = false } = params;
4035
if (results.length === 0) return;
4136

4237
await params.withAccountStorageTransaction(async (loadedStorage, persist) => {
@@ -166,9 +161,7 @@ export async function persistAccountPoolResults(params: {
166161
refreshToken: result.refresh,
167162
accessToken: result.access,
168163
expiresAt: result.expires,
169-
lastUsed: preserveLastUsedOnUpdate
170-
? (existing.lastUsed ?? now)
171-
: now,
164+
lastUsed: now,
172165
workspaces: mergedWorkspaces,
173166
currentWorkspaceIndex: nextCurrentWorkspaceIndex,
174167
};

test/account-pool.test.ts

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -52,122 +52,4 @@ describe("account pool helper", () => {
5252
activeIndexByFamily: { codex: 0 },
5353
});
5454
});
55-
56-
it("advances lastUsed when updating an existing account by default", async () => {
57-
const persist = vi.fn(async () => undefined);
58-
const originalLastUsed = 456;
59-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(789);
60-
61-
try {
62-
await persistAccountPoolResults({
63-
results: [
64-
{
65-
type: "success",
66-
access: "access-token-next",
67-
refresh: "refresh-token",
68-
expires: 999,
69-
},
70-
],
71-
replaceAll: false,
72-
modelFamilies: ["codex"],
73-
withAccountStorageTransaction: async (handler) =>
74-
handler(
75-
{
76-
version: 3,
77-
activeIndex: 0,
78-
activeIndexByFamily: { codex: 0 },
79-
accounts: [
80-
{
81-
accountId: "acct_1",
82-
email: "user@example.com",
83-
refreshToken: "refresh-token",
84-
accessToken: "access-token-old",
85-
expiresAt: 123,
86-
addedAt: 111,
87-
lastUsed: originalLastUsed,
88-
enabled: true,
89-
},
90-
],
91-
},
92-
persist,
93-
),
94-
findMatchingAccountIndex: () => 0,
95-
extractAccountId: () => "acct_1",
96-
extractAccountEmail: () => "user@example.com",
97-
sanitizeEmail: (email) => email,
98-
});
99-
} finally {
100-
nowSpy.mockRestore();
101-
}
102-
103-
expect(persist).toHaveBeenCalledWith(
104-
expect.objectContaining({
105-
accounts: [
106-
expect.objectContaining({
107-
refreshToken: "refresh-token",
108-
accessToken: "access-token-next",
109-
expiresAt: 999,
110-
lastUsed: 789,
111-
}),
112-
],
113-
}),
114-
);
115-
});
116-
117-
it("preserves lastUsed for report-style updates when requested", async () => {
118-
const persist = vi.fn(async () => undefined);
119-
const originalLastUsed = 456;
120-
121-
await persistAccountPoolResults({
122-
results: [
123-
{
124-
type: "success",
125-
access: "access-token-next",
126-
refresh: "refresh-token",
127-
expires: 999,
128-
},
129-
],
130-
replaceAll: false,
131-
preserveLastUsedOnUpdate: true,
132-
modelFamilies: ["codex"],
133-
withAccountStorageTransaction: async (handler) =>
134-
handler(
135-
{
136-
version: 3,
137-
activeIndex: 0,
138-
activeIndexByFamily: { codex: 0 },
139-
accounts: [
140-
{
141-
accountId: "acct_1",
142-
email: "user@example.com",
143-
refreshToken: "refresh-token",
144-
accessToken: "access-token-old",
145-
expiresAt: 123,
146-
addedAt: 111,
147-
lastUsed: originalLastUsed,
148-
enabled: true,
149-
},
150-
],
151-
},
152-
persist,
153-
),
154-
findMatchingAccountIndex: () => 0,
155-
extractAccountId: () => "acct_1",
156-
extractAccountEmail: () => "user@example.com",
157-
sanitizeEmail: (email) => email,
158-
});
159-
160-
expect(persist).toHaveBeenCalledWith(
161-
expect.objectContaining({
162-
accounts: [
163-
expect.objectContaining({
164-
refreshToken: "refresh-token",
165-
accessToken: "access-token-next",
166-
expiresAt: 999,
167-
lastUsed: originalLastUsed,
168-
}),
169-
],
170-
}),
171-
);
172-
});
17355
});

0 commit comments

Comments
 (0)