mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-14 12:25:27 +00:00
test(cliproxy): replace process-wide mock.module with DI seams
Bun's `mock.module()` is process-wide and is NOT undone by `mock.restore()`. Two test files used module-level mocks that leaked across test runs, silently breaking unrelated suites that imported the mocked modules transitively: - tests/unit/cliproxy/version-checker-stale-cache.test.ts mocked binary/version-checker, contaminating cliproxy-stats-routes-install and cliproxy-stats-routes-model-update suites that import a route module which transitively imports version-checker. - tests/unit/cliproxy/service-manager-startup.test.ts mocked 8 modules at top level (binary-manager, stats-fetcher, etc.), contaminating any later file that imports them. CI happens to be green because file ordering on the GitHub runner places victim files BEFORE contaminators in `bun test`. On Linux locally the order is reversed, producing 6 reproducible test failures on every `bun run test:fast` run. A change in OS, bun version, or new test files that import the mocked modules could silently flip the CI runner's order and surface these failures unexpectedly. Replaced module-level mocks with explicit dependency-injection seams in production code, following the existing pattern in version-checker.ts and version-cache.ts (`fetchJsonFn?`, `fetchLatestVersionFn?`): - src/cliproxy/types.ts: `BinaryManagerConfig.checkForUpdatesFn` (optional) - src/cliproxy/binary/lifecycle.ts: route through new fn with default - src/cliproxy/service-manager.ts: `ensureCliproxyService(deps?)` with optional `ensureBinaryFn`, `detectRunningProxyFn`, `configNeedsRegenerationFn`, `withStartupLockFn` All deps fields are optional with real-implementation defaults, so production callers are unchanged. Tests now inject deterministic stubs through call-site parameters instead of module-level mocks. Verified locally: \`bun run validate\` is now 2540 pass / 0 fail (previously 2534 pass / 6 fail at the same upstream/main HEAD). Built [OnSteroids](https://onsteroids.ai)
This commit is contained in:
@@ -57,7 +57,8 @@ function clampToMaxStable(version: string | undefined, verbose: boolean): string
|
||||
async function handleAutoUpdate(config: BinaryManagerConfig, verbose: boolean): Promise<void> {
|
||||
const backend: CLIProxyBackend = config.backend ?? DEFAULT_BACKEND;
|
||||
const backendLabel = getBackendLabel(backend);
|
||||
const updateResult = await checkForUpdates(config.binPath, config.version, verbose, backend);
|
||||
const checkFn = config.checkForUpdatesFn ?? checkForUpdates;
|
||||
const updateResult = await checkFn(config.binPath, config.version, verbose, backend);
|
||||
const currentVersion = updateResult.currentVersion;
|
||||
const latestVersion = updateResult.latestVersion;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user