mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 08:03:20 +00:00
The three usage scanners and their stores, plus the renderer usage-overview model, each carried a file-level `eslint-disable max-lines` and had grown to 338-769 counted lines against a 300-line budget. AGENTS.md calls for splitting rather than suppressing, and config/max-lines-baseline.txt is a shrink-only ratchet, so this removes all seven suppressions and prunes their entries (341 -> 334). Each file is cut along the seams it already had -- and that several of the suppression comments named out loud: filesystem discovery / record parsing / attribution / aggregation for the scanners, and pricing policy / scope filters / rollups / session rows / automation attribution for the stores. Pure move, no behavior change. Code is relocated verbatim; the only edits are import plumbing and, where a private class method became a free function, the mechanical `this.state` -> `state` parameter threading. Every converted call site passes `this.state` at call time and the automation path takes a live `getState: () => this.state` getter, so no state is snapshotted. No barrel exports: each new module owns real logic and importers point at the owner. Verified: oxlint clean, ratchet passes, typecheck clean, full unit suite green (remaining failures are pre-existing load flakes in untouched files, each green when re-run serially), no import cycles among the 64 affected modules, and a statement-level diff of every split confirms the moves are verbatim.
87 lines
2.8 KiB
TypeScript
87 lines
2.8 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import type { Dirent, Stats } from 'node:fs'
|
|
import type * as FsPromises from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
|
|
const { getLegacyCopiedCodexSessionBridgeScanPreferenceMock, readdirMock, statMock } = vi.hoisted(
|
|
() => ({
|
|
getLegacyCopiedCodexSessionBridgeScanPreferenceMock: vi.fn(),
|
|
readdirMock: vi.fn<(dirPath: string) => Promise<Dirent[]>>(),
|
|
statMock: vi.fn<(filePath: string) => Promise<Stats>>()
|
|
})
|
|
)
|
|
|
|
vi.mock('fs/promises', async () => {
|
|
const actual = await vi.importActual<typeof FsPromises>('fs/promises')
|
|
return {
|
|
...actual,
|
|
readdir: readdirMock,
|
|
stat: statMock
|
|
}
|
|
})
|
|
|
|
const FILE_COUNT = 125_000
|
|
const FAKE_ROOT = join('/', 'tmp', 'orca-large-codex-home')
|
|
const RUNTIME_SESSIONS_ROOT = join(FAKE_ROOT, 'runtime', 'sessions')
|
|
const SYSTEM_SESSIONS_ROOT = join(FAKE_ROOT, 'system', 'sessions')
|
|
const RUNTIME_BULK_DIR = join(RUNTIME_SESSIONS_ROOT, 'bulk')
|
|
|
|
vi.mock('../codex/codex-home-paths', () => ({
|
|
getOrcaManagedCodexHomePath: () => join(FAKE_ROOT, 'runtime'),
|
|
getOrcaUserDataPath: () => FAKE_ROOT,
|
|
getSystemCodexHomePath: () => join(FAKE_ROOT, 'system')
|
|
}))
|
|
|
|
vi.mock('../codex/codex-session-bridge', () => ({
|
|
getLegacyCopiedCodexSessionBridgeScanPreference:
|
|
getLegacyCopiedCodexSessionBridgeScanPreferenceMock
|
|
}))
|
|
|
|
function dirent(name: string, kind: 'directory' | 'file'): Dirent {
|
|
return {
|
|
name,
|
|
isDirectory: () => kind === 'directory',
|
|
isFile: () => kind === 'file'
|
|
} as Dirent
|
|
}
|
|
|
|
const largeSessionEntries = Array.from({ length: FILE_COUNT }, (_, index) =>
|
|
dirent(`session-${index}.jsonl`, 'file')
|
|
)
|
|
|
|
describe('listCodexSessionFiles large directories', () => {
|
|
beforeEach(() => {
|
|
getLegacyCopiedCodexSessionBridgeScanPreferenceMock.mockReset()
|
|
getLegacyCopiedCodexSessionBridgeScanPreferenceMock.mockReturnValue(null)
|
|
readdirMock.mockReset()
|
|
statMock.mockReset()
|
|
})
|
|
|
|
it('keeps nested session scans past the JavaScript spread-argument limit', async () => {
|
|
readdirMock.mockImplementation(async (dirPath) => {
|
|
if (dirPath === RUNTIME_SESSIONS_ROOT) {
|
|
return [dirent('bulk', 'directory')]
|
|
}
|
|
if (dirPath === RUNTIME_BULK_DIR) {
|
|
return largeSessionEntries
|
|
}
|
|
if (dirPath === SYSTEM_SESSIONS_ROOT) {
|
|
return []
|
|
}
|
|
throw new Error(`Unexpected readdir path: ${dirPath}`)
|
|
})
|
|
statMock.mockImplementation(async (filePath) => {
|
|
const match = /session-(\d+)\.jsonl$/.exec(filePath.replaceAll('\\', '/'))
|
|
return {
|
|
dev: 1,
|
|
ino: match ? Number(match[1]) + 1 : 0
|
|
} as Stats
|
|
})
|
|
|
|
const { listCodexSessionFiles } = await import('./codex-session-file-discovery')
|
|
|
|
await expect(listCodexSessionFiles()).resolves.toHaveLength(FILE_COUNT)
|
|
expect(getLegacyCopiedCodexSessionBridgeScanPreferenceMock).not.toHaveBeenCalled()
|
|
})
|
|
})
|