Skip to content

fix(build): clean dist on build — eliminate flaky local test runs - #31

Merged
sandstream merged 1 commit into
mainfrom
fix/test-build-clean-dist
Jun 22, 2026
Merged

sandstream merged 1 commit into
mainfrom
fix/test-build-clean-dist

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Root cause (investigated, not guessed)

Local npm test runs were flaky: the test count drifted (2355 → 2359 → 2361 across runs) with sporadic file-level "not ok" and zero failing subtests. This was previously assumed to be a migration-runner concurrency race; it is not.

Systematic debugging isolated it to a dirty dist/:

  • build (unlike build:prod) never ran rm -rf dist, so compiled .js from deleted/renamed sources accumulated (found 1244 orphan files locally).
  • Editor/cloud-sync conflict copies (foo 2.ts, foo 3.ts, …) compiled to dist/foo [0-9].js; the tsconfig exclude only covered * 2.ts.
  • The test glob dist/*.test.js then ran those orphans as duplicate/divergent tests → nondeterministic counts and intermittent failures.

Proof: removing the junk + clean rebuild gave 16 consecutive runs at a stable 2355 tests / 0 failures (before: drift + occasional 1 fail). CI was already immune (fresh clone + build:prod cleans dist), which is why this only bit local runs.

Fix

  • build now rm -rf dist before tsc (matches build:prod) → every run tests only current sources.
  • tsconfig + tsconfig.prod conflict-copy exclude widened * 2.ts → * [0-9].ts / * [0-9].tsx (covers 3/ 4 copies too).

No source/behavior changes — build hygiene only.

Verify

npm run build && npm test → junk=0, 132 test files, 2355 tests, 0 fail (stable across 16 runs).

🤖 Generated with Claude Code

…aky tests)

The test flake (drifting counts, sporadic file-level 'not ok' with no failing
subtests) was a dirty dist/, not a concurrency race. 'build' never cleaned
dist/, so stale compiled output from renamed/deleted sources plus sync
conflict copies (* 2.ts/* 3.ts → dist/* [0-9].js) lingered and the test glob
ran them as duplicate/divergent tests. Now 'build' rm -rf dist first (like
build:prod), and the tsconfig exclude covers * [0-9].ts/.tsx (was * 2.ts only).
Verified stable: 16 consecutive runs at 2355 tests / 0 fail.
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit f3dcf83 into main Jun 22, 2026
16 checks passed
@sandstream
sandstream deleted the fix/test-build-clean-dist branch June 22, 2026 07:38
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