Skip to content

fix(test): make the scf-core suites load, run, and complete - #507

Merged
thinkclay merged 2 commits into
mainfrom
claude/scf-core-test-repair
Jul 30, 2026
Merged

thinkclay merged 2 commits into
mainfrom
claude/scf-core-test-repair

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Six suites in scf-core were reporting zero tests or dying on first render, and the
suite as a whole could never finish. None of it was a bad assertion.

Four infrastructure faults

1. expo ships raw TypeScript, not compiled JS. Its package.json points main/module
at src/Expo.ts, and build/ holds only .d.ts. So Expo.fx.tsx → ./winter → runtime.ts
executes, and that file wires up Fast Refresh, HMR and the Metro message socket with bare
CommonJS require('./setupFastRefresh') calls on .ts siblings. Vitest transforms the module
to ESM but leaves the requires, and Node can't resolve an extensionless .ts at runtime.

Stubbed at ./winter specifically: a require() left in transformed output is executed by
Node and never reaches Vite's resolver — only the ESM import is interceptable, which is why
aliasing the deeper modules silently did nothing. Nothing is lost; the winter polyfills
(FormData, TextDecoder, URL, …) are separate modules imported elsewhere.

2. react-native-safe-area-context resolved to raw src/ rather than its compiled build,
so the TS-only typeof type query in SafeArea.types.ts reached Node as JS: Unexpected token 'typeof'. Pinned to lib/module — the real module, not a mock.

3. useBottomBarContext missing from the @scaffald/ui mock. The real hook reads a context
with a default and never throws, but vitest turns an absent export on a mocked module into a
hard error — so every suite rendering a dashboard screen died.

4. profile-employment-left.test.tsx declared vi.mock("@scaffald/ui") three times. Only
one registration survives per module path, and the survivor exported useToast alone — hence
No "Stack" export. The other two blocks (185 and 274 lines) were dead code.

Plus SafeAreaProvider needs seeded initialMetrics (jsdom never measures a frame), and
ApplicationWizard's nine renders had no QueryClientProvider.

Suite Before After
ipip / riasec / occupation wizards 0 tests (aborted on import) 7 passed, 10 pre-existing skips
ApplicationWizard 9 failed 9 passed
profile-employment-left 36 failed 40 passed
ResultsRail 0 tests 2 passed
MapSearchInput, WorkerPreviewModal, ResumeImportWidget failing green off the shared fixes

The OOM

A full run died with a JS heap OOM (SIGABRT) at both 4 GB and 8 GB — pool: "threads" shares
one heap across 333 files. Switched this project to pool: 'forks':

921 tests | 829 passed | 31 failed | 58 skipped
333 files | 17 failed files

A real result instead of a crash — the first this suite has ever reported.

Risk, and how it was checked

Four of the six changed files are shared test infrastructure imported by every suite in the
repo (vitest.config.ts, test-utils.tsx, beyond-ui.tsx). That, not scf-core, was the real
risk:

Gate Result
pnpm test:unit exit 0, 6 projects
pnpm check exit 0 — lint 10/10, typecheck 12/12

What this does NOT do

scf-core stays in the exclusion lists (package.json:12, package.json:158,
scripts/prepush.sh:32). Un-excluding was the original goal, and it isn't earned yet:

  • 31 tests still genuinely fail — UserProfilePanel (18), MapSearchInput (7), TeamForm (4).
    MapSearchInput passes in a small group and fails in the full run, which smells of cross-file
    state leakage rather than a broken assertion.
  • The nx executor path is unconfirmed. nx run scf-core:test hadn't finished after 11 minutes
    and was killed, so whether @nx/vitest:test honours the pool setting is an open question. Safe
    to land regardless — scf-core is in no CI path today — but it must be settled first, since CI
    would invoke it through nx.

Un-excluding now would turn an invisible problem into a permanently red gate: the same failure
mode as the 80%-vs-37% coverage threshold removed in #492. Runnable is the prerequisite; green
earns the gate. Both caveats are tracked in #504.

CI

Actions is out of included minutes until the allowance resets on the 1st, so this is verified
locally only. No live services are involved in any of the gates above.

🤖 Generated with Claude Code

thinkclay and others added 2 commits July 30, 2026 15:22
Six suites in scf-core were reporting zero tests or dying on the first render.
None of it was a bad assertion — four infrastructure faults, three of which had
nothing to do with the tests themselves.

1. expo ships raw TypeScript, not compiled JS: package.json points main/module
   at src/Expo.ts and build/ holds only .d.ts. So Expo.fx.tsx -> ./winter ->
   runtime.ts executes, and that file wires up Fast Refresh, HMR and the Metro
   message socket with bare CommonJS `require('./setupFastRefresh')` calls on
   .ts siblings. Vitest transforms the module to ESM but leaves the requires,
   and Node cannot resolve an extensionless .ts at runtime. Any test importing
   expo aborted before running.

   Stubbed at ./winter specifically. A require() left in transformed output is
   executed by Node and never reaches Vite's resolver — only the ESM import is
   interceptable, which is why aliasing the deeper modules silently did nothing.
   Nothing is lost: the winter polyfills (FormData, TextDecoder, URL, ...) are
   separate modules imported elsewhere; the index pulls in the runtime alone.

2. react-native-safe-area-context resolved to its raw src/ rather than its
   compiled build, so the TS-only `typeof` type query in SafeArea.types.ts
   reached Node as JS: "Unexpected token 'typeof'". Pinned to lib/module — the
   real module, not a mock, so behaviour is unchanged.

3. useBottomBarContext was missing from the @scaffald/ui mock. The real hook
   reads a context with a default and never throws, but vitest turns an absent
   export on a mocked module into a hard error, so every suite rendering a
   dashboard screen died.

4. profile-employment-left.test.tsx declared vi.mock("@scaffald/ui") three
   times. Only one registration survives per module path and the survivor
   exported useToast alone — hence `No "Stack" export`. The other two blocks
   (185 and 274 lines) were dead. Consolidated to one.

Plus: SafeAreaProvider needs seeded initialMetrics because jsdom never measures
a frame, and ApplicationWizard's nine renders had no QueryClientProvider.

  wizards (ipip/riasec/occupation)  0 tests ->  7 passed, 10 pre-existing skips
  ApplicationWizard                 9 failed -> 9 passed
  profile-employment-left          36 failed -> 40 passed
  ResultsRail                       0 tests ->  2 passed
  MapSearchInput, WorkerPreviewModal, ResumeImportWidget: green off the shared fixes

Four of the five files here are shared test infrastructure imported by every
suite in the repo, so the risk was regression elsewhere. Verified: pnpm test:unit
exit 0 across 6 projects, pnpm check exit 0 (lint 10/10, typecheck 12/12).

NOT un-excluding scf-core from affected:test/test:unit/prepush, which was the
original goal. A full run OOMs (SIGABRT) at both 4 GB and 8 GB — pool: "threads"
shares heap across 329 files and nothing is reclaimed between them. That is
pre-existing and structural; these fixes accelerate it only because three files
that used to abort for free now render real trees. Filed as #504. Un-excluding a
suite that cannot complete would trade an invisible problem for a permanently
red gate, which is the mistake #492 removed.

Co-Authored-By: Claude Opus 5 <[email protected]>
The root config uses `pool: "threads"`, which shares one heap across every file.
Over this project's 333 test files nothing is reclaimed between them and the run
dies with a JS heap OOM (SIGABRT) at both 4 GB and 8 GB — no assertion fails,
the process simply runs out of memory. That is why scf-core is excluded from
every aggregate command: it could never finish.

Forks give each file its own process, so its heap is released on exit.

Verified by direct vitest invocation:

  vitest run --config packages/scf-core/vitest.config.ts --pool=forks --maxWorkers=2
  921 tests | 829 passed | 31 failed | 58 skipped
  333 files | 17 failed files

A real result instead of a crash, and the first time this suite has reported one.

Two caveats, both recorded in #504:

- The same run through the nx executor (`nx run scf-core:test`) had not finished
  after 11 minutes and was killed, so whether `@nx/vitest:test` honours the pool
  setting is NOT yet confirmed. This is safe to land regardless — scf-core is
  excluded from every CI path today — but it must be settled before the suite is
  un-excluded, since CI would invoke it through nx.

- 31 tests still fail for real. Biggest clusters are UserProfilePanel (18),
  MapSearchInput (7) and TeamForm (4). MapSearchInput passes when run in a small
  group and fails in the full run, which smells of cross-file state leakage
  rather than a broken assertion.

So scf-core stays in the exclusion lists for now. Runnable is the prerequisite;
green is what earns the gate.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit 8f7c49d into main Jul 30, 2026
3 of 5 checks passed
@thinkclay
thinkclay deleted the claude/scf-core-test-repair branch July 30, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant