diff --git a/src/main/rate-limits/kimi-fetcher-wsl-home.test.ts b/src/main/rate-limits/kimi-fetcher-wsl-home.test.ts index be448003657..c8ba2d12ed7 100644 --- a/src/main/rate-limits/kimi-fetcher-wsl-home.test.ts +++ b/src/main/rate-limits/kimi-fetcher-wsl-home.test.ts @@ -1,3 +1,4 @@ +import { join } from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' const netFetchMock = vi.hoisted(() => vi.fn()) @@ -20,12 +21,12 @@ vi.mock('node:fs/promises', () => ({ return contents } })) -// Posix-shaped host home so `node:path.join` behaves the same on every test runner. vi.mock('node:os', () => ({ homedir: () => '/home/neil' })) import { fetchKimiRateLimits } from './kimi-fetcher' -const HOST_CREDENTIALS = '/home/neil/.kimi-code/credentials/kimi-code.json' +// Built with `join` so the key matches the separator the fetcher emits on this runner's platform. +const HOST_CREDENTIALS = join('/home/neil', '.kimi-code', 'credentials', 'kimi-code.json') const WSL_HOME = '\\\\wsl.localhost\\Ubuntu\\home\\neil\\.kimi-code' const WSL_CREDENTIALS = `${WSL_HOME}\\credentials\\kimi-code.json` diff --git a/src/main/rate-limits/kimi-fetcher.test.ts b/src/main/rate-limits/kimi-fetcher.test.ts index 01a7c10bd09..e1684ff1ada 100644 --- a/src/main/rate-limits/kimi-fetcher.test.ts +++ b/src/main/rate-limits/kimi-fetcher.test.ts @@ -1,3 +1,4 @@ +import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const netFetchMock = vi.hoisted(() => vi.fn()) @@ -55,6 +56,11 @@ const USAGE_RESPONSE = { subType: 'TYPE_PURCHASE' } +// Built with `join` so the expectation matches the separator the fetcher emits on this platform. +function hostCredentialsPath(kimiHome: string): string { + return join(kimiHome, 'credentials', 'kimi-code.json') +} + function freshCredentials(): string { // expires_at far in the future (seconds). return JSON.stringify({ access_token: 'tok-abc', expires_at: 99_999_999_999 }) @@ -161,7 +167,7 @@ describe('fetchKimiRateLimits', () => { const result = await fetchKimiRateLimits() expect(result.status).toBe('ok') - expect(fsState.readPaths).toEqual(['/home/test/.kimi-code/credentials/kimi-code.json']) + expect(fsState.readPaths).toEqual([hostCredentialsPath('/home/test/.kimi-code')]) }) it('honors KIMI_CODE_HOME for the host home', async () => { @@ -172,7 +178,7 @@ describe('fetchKimiRateLimits', () => { const result = await fetchKimiRateLimits() expect(result.status).toBe('ok') - expect(fsState.readPaths).toEqual(['/custom/kimi-home/credentials/kimi-code.json']) + expect(fsState.readPaths).toEqual([hostCredentialsPath('/custom/kimi-home')]) }) it('ignores a blank KIMI_CODE_HOME instead of reading from the process cwd', async () => { @@ -182,6 +188,6 @@ describe('fetchKimiRateLimits', () => { await fetchKimiRateLimits() - expect(fsState.readPaths).toEqual(['/home/test/.kimi-code/credentials/kimi-code.json']) + expect(fsState.readPaths).toEqual([hostCredentialsPath('/home/test/.kimi-code')]) }) })