test(cli): remove module mocks so the suite passes in any file order

Merged
SA
1mo ago
+297-334

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

LeakerVictimFix
scripts/add and scripts/manage tests mocked lib/configresolve-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-attachmentsworkspaces/archive testthe 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_processany later filespawnHostService(options, spawnProcess = spawn)
lib/config.test.ts mocked node:fsany later filewriteConfig(config, fs = {...})
status/command.test.ts (in-file order)itselfremoves the manifest after each test
workspaces/get testitself, when SUPERSET_WORKSPACE_ID is set in the shellsaves, 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: the SUPERSET_HOME_DIR and SUPERSET_CONFIG_PATH constants are replaced by getSupersetConfigPath() and the existing getSupersetHomeDir(). 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, start and config 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_DIR and the config path per call instead of once at import, so tests write a real config into a temp home instead of faking lib/config.
  • Command tests run against a real local tRPC server (lib/host/test-helpers.ts), replacing mocks of lib/host-target, lib/host-workspaces, and lib/upload-attachments.
  • spawnHostService and writeConfig take the function they call (spawn, fs methods) as an optional parameter, removing the node:child_process and node:fs module mocks.
  • The status test removes its manifest after each test; workspaces get saves, clears, and restores SUPERSET_WORKSPACE_ID.
  • agents create is now tested with --local instead 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.