

























@@ -66,6 +66,15 @@ function mockClaudeCliCredentialRead() {
6666);
6767}
686869+function expectFields(value: unknown, expected: Record<string, unknown>): void {
70+expect(value).toBeTypeOf("object");
71+expect(value).not.toBeNull();
72+const record = value as Record<string, unknown>;
73+for (const [key, expectedValue] of Object.entries(expected)) {
74+expect(record[key], key).toEqual(expectedValue);
75+}
76+}
77+6978describe("cli credentials", () => {
7079beforeAll(async () => {
7180({
@@ -232,13 +241,13 @@ describe("cli credentials", () => {
232241if (!first || !second) {
233242throw new Error("expected cached Claude CLI credentials to be available");
234243}
235-expect(first).toMatchObject({
244+expectFields(first, {
236245type: "oauth",
237246provider: "anthropic",
238247access: expect.stringMatching(/^token-/),
239248refresh: "cached-refresh",
240249});
241-expect(second).toMatchObject({
250+expectFields(second, {
242251type: "oauth",
243252provider: "anthropic",
244253access: expect.stringMatching(/^token-/),
@@ -277,7 +286,7 @@ describe("cli credentials", () => {
277286execSync: execSyncMock,
278287});
279288280-expect(withKeychain).toMatchObject({
289+expectFields(withKeychain, {
281290type: "oauth",
282291provider: "anthropic",
283292refresh: "cached-refresh",
@@ -305,7 +314,7 @@ describe("cli credentials", () => {
305314execSync: execSyncMock,
306315});
307316308-expect(withKeychain).toMatchObject({
317+expectFields(withKeychain, {
309318type: "oauth",
310319provider: "anthropic",
311320refresh: "cached-refresh",
@@ -337,7 +346,7 @@ describe("cli credentials", () => {
337346338347const creds = readCodexCliCredentials({ platform: "darwin", execSync: execSyncMock });
339348340-expect(creds).toMatchObject({
349+expectFields(creds, {
341350access: createJwtWithExp(expSeconds),
342351refresh: "keychain-refresh",
343352provider: "openai-codex",
@@ -370,7 +379,7 @@ describe("cli credentials", () => {
370379371380const creds = readCodexCliCredentials({ execSync: execSyncMock });
372381373-expect(creds).toMatchObject({
382+expectFields(creds, {
374383access: createJwtWithExp(expSeconds),
375384refresh: "file-refresh",
376385provider: "openai-codex",
@@ -403,7 +412,7 @@ describe("cli credentials", () => {
403412execSync: execSyncMock,
404413});
405414406-expect(creds).toMatchObject({
415+expectFields(creds, {
407416access: createJwtWithExp(expSeconds),
408417refresh: "file-refresh",
409418provider: "openai-codex",
@@ -439,7 +448,7 @@ describe("cli credentials", () => {
439448execSync: execSyncMock,
440449});
441450442-expect(withKeychain).toMatchObject({
451+expectFields(withKeychain, {
443452access: createJwtWithExp(expSeconds),
444453refresh: "keychain-refresh",
445454provider: "openai-codex",
@@ -486,12 +495,12 @@ describe("cli credentials", () => {
486495execSync: execSyncMock,
487496});
488497489-expect(withKeychain).toMatchObject({
498+expectFields(withKeychain, {
490499refresh: "keychain-refresh",
491500expires: keychainExpiry * 1000,
492501provider: "openai-codex",
493502});
494-expect(withoutPrompt).toMatchObject({
503+expectFields(withoutPrompt, {
495504refresh: "file-refresh",
496505expires: fileExpiry * 1000,
497506provider: "openai-codex",
@@ -526,7 +535,7 @@ describe("cli credentials", () => {
526535execSync: execSyncMock,
527536});
528537529-expect(first).toMatchObject({
538+expectFields(first, {
530539refresh: "stale-refresh",
531540expires: firstExpiry * 1000,
532541});
@@ -550,7 +559,7 @@ describe("cli credentials", () => {
550559execSync: execSyncMock,
551560});
552561553-expect(second).toMatchObject({
562+expectFields(second, {
554563refresh: "fresh-refresh",
555564expires: secondExpiry * 1000,
556565});
@@ -581,7 +590,7 @@ describe("cli credentials", () => {
581590582591const creds = readGeminiCliCredentialsCached({ homeDir: tempHome, ttlMs: 0 });
583592584-expect(creds).toMatchObject({
593+expectFields(creds, {
585594type: "oauth",
586595provider: "google-gemini-cli",
587596access: "gemini-access",
@@ -611,7 +620,7 @@ describe("cli credentials", () => {
611620612621const creds = readGeminiCliCredentialsCached({ homeDir: tempHome, ttlMs: 0 });
613622614-expect(creds).toMatchObject({
623+expectFields(creds, {
615624type: "oauth",
616625provider: "google-gemini-cli",
617626access: "gemini-access",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。