Skip to content

fix(build): detect orphaned compiled tests before building - #5647

Open
seekskyworld wants to merge 3 commits into
apache:mainfrom
seekskyworld:fix/5641-orphaned-test-output
Open

seekskyworld wants to merge 3 commits into
apache:mainfrom
seekskyworld:fix/5641-orphaned-test-output

Conversation

@seekskyworld

@seekskyworld seekskyworld commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

After a test source is removed or renamed, incremental TypeScript builds leave its compiled copy in dist, and test:dist still runs it. Root npm run build now detects these orphaned tests before compiling, lists their paths, and directs contributors to npm run rebuild, which clears both output and incremental state.

The check preserves normal incremental builds and does not delete individual compiler outputs. It covers the repository's src → dist layouts, including Desktop's nested main tests and UI TSX tests. Contributor guidance and CI regression coverage are included.

Fixes #5641

Verification

  • Real TypeScript reproduction: compile a test, delete its source, compile again; both compilations succeed and the old test remains. The new guard exits 1 and reports that file.
  • 140 script tests pass, including four new cases covering deleted/renamed tests, supported source extensions, clean checkouts, and the actual npm build/rebuild lifecycle. Removing the prebuild hook makes the lifecycle regression fail.
  • Full repository build, typecheck, lint, format check, Desktop/UI knip, ASF headers, and diff checks pass on Node 24.18.1. The guard also passes against the completed repository build.
  • npm run check:release passes all 203 release-contract tests; 19 focused guard/file-policy tests pass. The first hosted run identified fixture paths that looked like real workspace references; the fixture namespace was corrected in the follow-up commit and the revised tests pass in CI.
  • Application workspace test suites were not rerun; this change affects build tooling only.

Current validation (2026-10-10)

Merged main 2463d86c3, preserving both the new Electron installer CI test and orphan guard, plus the worktree-development documentation. All conflicts are resolved in 0c3316eb0.

  • Full build/typecheck/lint/format, Desktop/UI knip, ASF headers and diff checks pass.
  • 90 build-guard/planner/workflow tests pass.
  • The complete storage artifact-writer-lock file passes 10/10, including the same child-held writer-lock export case that failed in the older hosted run. No lock assertions or production storage code were changed.

Hosted check

The older run 35902091783 failed in the storage lock test; attribution to this PR was not established. A fresh run is requested by the main-sync push and is pending. The earlier result is not treated as green on the strength of a local rerun.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: OpenAI Codex inspected the issue, implemented and tested the build guard, and drafted this description under human direction.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Hosted CI update (2026-10-12): run 38037653011 failed in the unchanged Usage Storybook usage-long-tail / usage-narrow width assertion (168.03125 <= 168). The failure remains unresolved; this PR does not change that surface. Automated status update by OpenAI Codex.

Generated-by: OpenAI Codex
Signed-off-by: seekskyworld <djh1813553759@gmail.com>
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 23, 2026
Generated-by: OpenAI Codex
Signed-off-by: seekskyworld <djh1813553759@gmail.com>

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current six-file root prebuild scanner for orphan compiled test artifacts and its tests. I found no substantiated P0–P3 issue attributable to this change; the four focused scanner tests and diff check pass. This is not ready to merge: the current-head required test check is failing in an unchanged storage artifact-writer-lock concurrency test (PR attribution remains unproven), and this branch conflicts with main. Please resolve the conflict and investigate/rerun the required check before merge. I did not run the full test suite or validate every build artifact layout.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@me2seeks me2seeks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review notice: This comment was posted by an automated review agent operated by me2seeks make. It is not an independent human review and does not replace one.

Summary

Adds a root prebuild guard that fails the build when dist/**/*.test.{js,jsx,mjs,cjs} has no matching source under src/, with docs and a CI lane. The issue is real — incremental tsc never deletes outputs for removed sources, and test:dist then runs ghost tests. The solution is minimal (detect + direct to npm run rebuild rather than deleting), workspaces are explicit paths (package.json:16-30), Desktop's nested dist/main/__tests__ layout and .d.ts/.map siblings are correctly handled, and the npm-lifecycle test would fail if the hook were dropped.

Findings

  1. [P2] The test lane is red on the current head (run 35902091783): storage test bundle export excludes a mutation queued behind the same child-held writer lock. The body claims it is unrelated to this build-tooling change — plausible, but it must be re-run green or demonstrated to fail on unmodified main before merge.
  2. No code-level findings. The check correctly no-ops on unbuilt checkouts, skips symlinked entries, keeps module-specific extension mapping (mjs→mts/mjs, cjs→cts/cjs), and its mutation coverage is real (removing the prebuild hook fails the lifecycle regression).

Verdict

needs-discussion — code is merge-ready, but the failing test lane on head needs a green re-run or proof of pre-existing failure.

Generated-by: OpenAI Codex
Signed-off-by: seekskyworld <djh1813553759@gmail.com>
@seekskyworld

Copy link
Copy Markdown
Contributor Author

Synced main 2463d86 and resolved the workflow/contributor-guide conflicts in 0c3316e. The unchanged artifact-writer-lock test file now passes 10/10 locally, including the previously failing export case. Build/typecheck/lint/format, both knip gates, ASF headers, and 90 guard/planner/workflow tests pass. The new push requests fresh required CI; the previous red run has not been relabelled as successful.

Automated update by OpenAI Codex under the contributor’s direction.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Incremental review from 0e34d7ee (previously reviewed, no P0–P3) to 0c3316eb. The update is only a merge of main (2463d86c); git range-diff shows both author commits unchanged.

Merge resolution (git show --remerge-diff): three conflicts, all resolved correctly. In .github/workflows/ci.yml, the Test CI planner list keeps both this PR's scripts/check-orphaned-test-output.test.mjs and main's scripts/install-electron-with-retry.test.mjs. In CONTRIBUTING.md and CONTRIBUTING.zh-CN.md, main's new dev:worktree paragraph is kept, followed by the build paragraph with this PR's npm run rebuild sentence. No other content was lost or added.

Prior findings / blockers: the branch conflict with main is resolved. The earlier red test (unchanged storage artifact-writer-lock concurrency test) does not recur: "Run affected standard workspace tests" passes on this head. In the Build step, node scripts/check-orphaned-test-output.mjs runs and passes against the merged tree.

New findings: none.

CI / mergeability: MERGEABLE/BLOCKED. audit, owner (macOS, Windows), package, and package-linux pass. test is red. The only failing step is Storybook smoke: settings-pages.stories.tsx:2835 (product-settings-pages--usage-long-tail / --usage-narrow) reports "expected 168.03125 to be less than or equal to 168". That is a known main-side sub-pixel flake in the Usage time-cell width check. This PR does not touch that story or the Settings Usage surface, so it is not PR-caused. Main's latest CI run skipped Storybook, so it cannot serve as a direct comparison. A rerun is needed for a green required gate.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(scripts): build leaves compiled tests for deleted sources in dist, and they still run

4 participants