pnpm test on dev is not a trustworthy signal: random teardown error + 2 env-dependent failures #55
Labels
No labels
bug
discussion
enhancement
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
edufeed/edufeed-app#55
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
pnpm testondevis not currently a trustworthy pass/fail signal. Two independent problems, neither of which fails a test.1. Random non-zero exit from an
EnvironmentTeardownError(no test fails)Every so often the run ends like this while reporting every test passed:
The error is an unhandled rejection during environment teardown:
A lazy
svelte/reactivityimport lands after vitest has torn down the jsdom environment forGlobalFAB.test.js.It is a race, and the count varies run to run on an unchanged tree. Five consecutive full runs on clean
dev:It does not reproduce when
GlobalFAB.test.jsis run alone, or together with just the membership suites — it needs full-suite load. Consequence: CI ondevgoes red at random with nothing actually broken, and a genuinely broken build is indistinguishable from this at a glance.Worth knowing for anyone debugging it: two samples are not enough to attribute this to a branch. It cost me a nearly-published false attribution — I saw 5 errors on a feature branch, got 0 twice on clean
dev, and concluded the branch caused it. Sampling five each showed the same distribution.2. Two tests fail on a fresh clone because
pnpm testdoes not load.envBoth read
process.envdirectly, andvitest rundoes not populate it from.env. Workaround:That is how every "5149/5149" figure in the membership thread was obtained. Anyone on a fresh clone — and CI, which has no
.env— sees two red tests unrelated to their change.Fix direction (not prescriptive): either load the env in the vitest setup for those files, or have the tests supply their own fixture values instead of reading the ambient environment. The second is probably better — a unit test that needs 25 real
naddrs from a deployment env is testing the environment as much as the code.Not urgent, but do not lose it
Neither problem is a product bug and neither blocks a release. They matter because together they make a red test run uninformative, which is exactly when you most want it to be informative.
Filed at the request of @laoc_buzz from the membership thread in #edufeed-app. Observed on
dev@09842a48.Second, deterministic instance: three tests pass only because of the developer's
direnvFound while baselining the suite for #31. On a fresh worktree with
.envcopied but direnv not allowed, three tests fail on cleandev@3353662b:The first two fail with
Error: Missing env: SCHEME_NADDR_EDUCATIONAL_LEVELatscripts/lib/publish-forms-build.mjs:16.Why it is a test bug, not a config bug
publish-forms-build.test.mjs:79-83deliberately stubs the env so it does not need real values:But
amb-basicinscripts/data/edufeed-forms.json:81grew a thirdvocabRef—educational-level— and the stub list was never updated. Vitest does not load.envintoprocess.env, so the test should have failed from that commit onward. It does not, because.envrccontainsdotenv_if_exists: with direnv active the shell exports all 25SCHEME_NADDR_*vars,req()finds the real value, and the gap is invisible.Confirmed both directions, same commit, same checkout:
So the tests are green on every developer machine with direnv and red anywhere without it — CI, a container, a fresh worktree. Whichever way CI is set up, one of the two states is lying.
Fix
Add the missing
vi.stubEnv('SCHEME_NADDR_EDUCATIONAL_LEVEL', fakeNaddr('educational-level'))— and better, derive the stub list from the form's ownvocabRefs so adding a fourth cannot silently reintroduce this. A test that reads ambient env is exactly the class of thing this issue is about.The third failure (
ResourceFormWizard.edit-prefill, 10.5s before failing) also cleared once the env was exported, so it is likely the same root cause via a slow path rather than an independent flake — I did not isolate it further.Full suite with the env exported: 5177/5177, 468 files. The
GlobalFABteardown race in the original report still surfaces intermittently asErrors: 1and is unaffected by any of this.