Skip to content

Test selection finds tests for TypeScript files imported with a .js extension - #4401

Open
mikhailsal wants to merge 1 commit into
garrytan:mainfrom
mikhailsal:fix/pregate-nodenext-js-imports
Open

mikhailsal wants to merge 1 commit into
garrytan:mainfrom
mikhailsal:fix/pregate-nodenext-js-imports

Conversation

@mikhailsal

Copy link
Copy Markdown

Why (in your own words)

In a TypeScript repo that uses NodeNext resolution, imports are written with the emitted extension: './x.js' for x.ts. pregate's import graph only appended extensions, so it never matched these imports. Every touched source file then had no test lane, /verify stopped at UNMAPPED, and pregate at PREGATE_NO_POLICY / PREGATE_NO_LANE, even though dozens of tests import those files. This change makes resolveCandidate also try the TypeScript counterpart of a .js / .jsx / .mjs / .cjs specifier. It does so after the existing extension list, so a real .js file still wins.

Fixes #4398

Live evidence

The real repo is mikhailsal/telegram-harness-cli, a NodeNext TypeScript project. Here is the /verify test selection for its PR #9 diff:

# before (gstack 1.96.0.0)
$ gstack-checks run --only tests --allow-repo-commands --base <pr base>
CHECK tests UNMAPPED 9.5s  44 tests ran in 9 file(s), exit 0; 10 touched file(s) with no test lane under no policy (starter printed)
TODO src/channels/catalog.ts: no test lane and no nearby test; ...
TODO src/core/results.ts: no test lane and no nearby test; ...
TODO tests/core/continuation-fixture.ts: no test lane and no nearby test; ...

# after (this patch)
CHECK tests PASS 24.7s

I also probed buildGraph + testsFor on the same repo, before → after: src/core/results.ts 0 → 30 tests, src/channels/catalog.ts 0 → 57, src/core/events.ts 0 → 30, tests/core/continuation-fixture.ts 0 → 2.

The new test in test/pregate-import-graph-paths.test.ts fails without the fix and passes with it:

$ bun test test/pregate-import-graph-paths.test.ts   # fix reverted
 1 fail
$ bun test test/pregate-import-graph-paths.test.ts test/pregate-selection.test.ts test/pregate-policy-lane-verdicts.test.ts test/pregate-lanes-large-selection.test.ts test/pregate-docs-lane-review.test.ts
 95 pass
 0 fail
$ bun run typecheck && bun run typecheck:test
test typecheck ratchet: 812 known diagnostics, none new.

Scope

  • Changed: lib/pregate/import-graph.ts (resolveCandidate, +3 lines) and one new test case.
  • Verified live by: /verify test selection on the NodeNext repo above (UNMAPPED → PASS), plus the probe and tests above.
  • Did NOT test: the full free suite, Windows/macOS gates, and bundler-specific resolution beyond the .js→.ts rewrite (for example moduleSuffixes).

Liveness proof (required for external contributors)

Checklist

🤖 Generated with Claude Code

TypeScript's NodeNext (and bundler) convention imports a source file by
its emitted name: `import { x } from './x.js'` names `x.ts`. The import
graph only appended extensions, so `./x.js` never matched `x.ts`, every
such edge was dropped, and in a repo written this way every touched
source file came out with no test lane (UNMAPPED in /verify,
PREGATE_NO_LANE / PREGATE_NO_POLICY in pregate), including test helpers
imported by the tests themselves.

resolveCandidate now also tries the TypeScript counterpart of a `.js`,
`.jsx`, `.mjs` or `.cjs` specifier (`.ts`, `.tsx`, `.mts`, `.cts`) after
the existing extension list, so a real `.js` file still wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Nov 16, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@mikhailsal mikhailsal changed the title pregate: resolve NodeNext .js specifiers to their .ts sources Test selection finds tests for TypeScript files imported with a .js extension Nov 16, 2026
@mikhailsal

Copy link
Copy Markdown
Author

I'm not going to do the liveness screenshot, it's not worth my time. The fix is three lines plus a regression test, with before/after evidence above and in #4398. If that's not enough and you don't care about the bug, feel free to close this and live with it.

@mikhailsal
mikhailsal marked this pull request as ready for review November 16, 2026 02:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T02:46:37.122081Z e2da72d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@capy-ai

capy-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Thank you. This is the fix for #4398, and it's small and correct: trying the TypeScript counterpart after the existing extension list keeps real .js files winning. We're taking it. Outside code is rebuilt on current main rather than merged directly, so it will land as a new change with you credited as co-author, and this PR will be closed with a link then. gstack's tooling is frozen until November 21, so expect it after that.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pregate: NodeNext './x.js' imports of x.ts are not resolved, so every touched TS source is UNMAPPED / no test lane

1 participant