test(cli): remove module mocks so the suite passes in any file order
Part of removing cross-file test leaks so suites do not depend on bun test --isolate. mock.module is process-wide in bun: without --isolate, a fake reaches every test file that loads later.
Leaks fixed
| Leaker | Victim | Fix |
|---|---|---|
scripts/add and scripts/manage tests mocked lib/config | resolve-auth.test.ts ("Not logged in") | the home directory is read per call, so tests write a real config into a temp home |
workspaces/create, agents/create, workspaces/get, browser/open tests mocked lib/host-target, lib/host-workspaces, lib/cloud-workspaces, lib/upload-attachments | workspaces/archive test | the tests run the real resolution code against a local Bun.serve that speaks tRPC (lib/host/test-helpers.ts) |
lib/host/spawn.test.ts mocked node:child_process | any later file | spawnHostService(options, spawnProcess = spawn) |
lib/config.test.ts mocked node:fs | any later file | writeConfig(config, fs = {...}) |
status/command.test.ts (in-file order) | itself | removes the manifest after each test |
workspaces/get test | itself, when SUPERSET_WORKSPACE_ID is set in the shell | saves, clears and restores the variable |
No mock.module call remains in packages/cli. No test was deleted (374 before and after).
Production changes
lib/config.ts: theSUPERSET_HOME_DIRandSUPERSET_CONFIG_PATHconstants are replaced bygetSupersetConfigPath()and the existinggetSupersetHomeDir(). The variable does not change during a CLI run, so a per-call read gives the same value.lib/host/spawn.ts,lib/config.ts: one optional parameter each, defaulting to the real function.lib/host/manifest.ts,lib/analytics.ts, two cloud-workspace resolvers,startandconfig check: same paths, computed per call.
Verification
bun 1.4.2, bun test --randomize --seed N, seeds 1-12: 374 pass, 0 fail without --isolate and with it. One --isolate run (seed 7) hung once on bun 1.4.2 and passed on three reruns; that is the sync-spawn bug that #8311 works around in CI. Repo typecheck and biome pass.
One behaviour change in a test: agents create is now tested with --local and not --host host-1.
Summary by cubic
Removes all mock.module calls from the CLI tests so the suite passes in any file order without bun test --isolate. mock.module is process-wide in bun, so fakes from one test file leaked into files that loaded later and caused order-dependent failures.
- The CLI now reads
SUPERSET_HOME_DIRand the config path per call instead of once at import, so tests write a real config into a temp home instead of fakinglib/config. - Command tests run against a real local tRPC server (
lib/host/test-helpers.ts), replacing mocks oflib/host-target,lib/host-workspaces, andlib/upload-attachments. spawnHostServiceandwriteConfigtake the function they call (spawn, fs methods) as an optional parameter, removing thenode:child_processandnode:fsmodule mocks.- The
statustest removes its manifest after each test;workspaces getsaves, clears, and restoresSUPERSET_WORKSPACE_ID. agents createis now tested with--localinstead of--host host-1.
No test was deleted (374 before and after). Typecheck and biome pass.
Summary by CodeRabbit
- Improvements
- The CLI now consistently uses the current configuration and home-directory paths when checking settings, starting services, and accessing cached data.
- Tests
- Updated CLI command and configuration tests to use more realistic local service and filesystem setups. This improves coverage of workspace, browser, script, and configuration scenarios.