From ae9bd4d4830e81b9e1a9f070805cdaddd75b684d Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Fri, 7 Aug 2026 18:53:38 -0700 Subject: [PATCH] test(rate-limits): build Kimi credential-path expectations with path.join MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The host-home assertions hardcoded POSIX separators, so they only passed on a POSIX runner — on a Windows dev machine `join` emits backslashes and all four cases failed (three assertion mismatches plus a WSL-suite fixture whose map key never matched the path the fetcher read). --- src/main/rate-limits/kimi-fetcher-wsl-home.test.ts | 5 +++-- src/main/rate-limits/kimi-fetcher.test.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) 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')]) }) })