mirror of
https://github.com/stablyai/orca.git
synced 2026-10-26 16:02:42 +00:00
test(rate-limits): build Kimi credential-path expectations with path.join
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).
This commit is contained in:
@@ -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`
|
||||
|
||||
|
||||
@@ -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')])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user