Skip to content

Find the tests of a monorepo app that imports through its own @/ alias - #4462

Closed
dtoelke wants to merge 1 commit into
garrytan:mainfrom
dtoelke:nested-tsconfig-path-aliases
Closed

dtoelke wants to merge 1 commit into
garrytan:mainfrom
dtoelke:nested-tsconfig-path-aliases

Conversation

@dtoelke

@dtoelke dtoelke commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

The checks that run before a PR opens now find the tests of a monorepo app that imports through its own @/ alias.

Why: only the repository root's tsconfig was read for paths, so every source file in such an app failed as having no test, even with a test right beside it.

Nothing to do: a repo whose only tsconfig is at the root resolves exactly as before.

Why (in your own words)

Our monorepo has an Expo app at apps/mobile whose tsconfig.json maps @/* to ./src/*. Its tests import the code they cover as @/media/close-bar. /ship stopped on 14 touched files in that app with PREGATE_NO_LANE, because the import graph reads paths and baseUrl from the root tsconfig only and could not follow any @/ import under apps/mobile. The --explain output even names the gap ("specifiers in test files that resolve to no repo file ... or report the resolver gap"). The only workaround was a dependencies entry per source file.

This change reads each file's aliases from the nearest tsconfig.json or jsconfig.json above it that declares paths or baseUrl (itself or through a relative extends). A nested config that declares neither defers to the next one up, and the root config governs everything else, so no file loses an alias it has today.

Live evidence

repro.sh builds a throwaway repo: a policy with a dependencies key, apps/mobile/tsconfig.json with "paths": { "@/*": ["./src/*"] }, apps/mobile/src/media/close-bar.ts, and a test beside it that imports @/media/close-bar. A branch edits close-bar.ts, then it runs gstack-pregate --base main --allow-repo-commands --stage tests --only lanes --explain. Temp paths are shortened to <tmp>.

Before, on main at e1cfcea:

PREGATE: tests fail in 0.2s — lanes: 1 touched file(s) with no test lane: apps/mobile/src/media/close-bar.ts
tests      lanes     fail                195 ms  1 touched file(s) with no test lane: apps/mobile/src/media/close-bar.ts (PREGATE_NO_LANE)
    lanes: FAIL lanes — apps/mobile/src/media/close-bar.ts has no test lane
PREGATE: fail tree=b368cdc6bf05 head=5edc0df21634 checks=1 of 8
--- explain ---
apps/mobile/src/media/close-bar.ts: no lane; specifiers in test files that resolve to no repo file: apps/mobile/src/media/close-bar.test.ts: '@/media/close-bar' [touched]
apps/mobile/src/media/close-bar.ts: if a test covers it, declare the file under dependencies in .gstack/pregate.json, or report the resolver gap [touched]
exit=1

After, on this branch:

PREGATE: tests pass in 0.2s — lanes: 1 tests ran in 1 file(s), exit 0
tests      lanes     pass                236 ms  1 tests ran in 1 file(s), exit 0
    lanes: ran: bun test './apps/mobile/src/media/close-bar.test.ts'
    lanes:    1 pass
    lanes:    0 fail
PREGATE: pass tree=b368cdc6bf05 head=e0dffb0e8b4f checks=1 of 8
--- explain ---
apps/mobile/src/media/close-bar.test.ts ← apps/mobile/src/media/close-bar.ts (import) [touched]

The three new tests in test/pregate-import-graph-paths.test.ts fail on main and pass here:

# main's lib/pregate/import-graph.ts with the new tests
(fail) import graph: nested tsconfig paths govern the files under them > an alias in a nested tsconfig maps a source file under it to the test that imports it
(fail) import graph: nested tsconfig paths govern the files under them > each app resolves the same alias through its own config; the root config still governs files outside them
(fail) import graph: nested tsconfig paths govern the files under them > a nested config takes paths through a relative extends, joined relative to the config that declares them
 16 pass
 3 fail

# this branch
 19 pass
 0 fail

The reproduction script:

#!/usr/bin/env bash
# repro.sh <gstack checkout>
set -eu
GSTACK=$1
T=$(mktemp -d)
git init -q --bare "$T/origin.git"
git init -q -b main "$T/work" && cd "$T/work"
git config user.email [email protected] && git config user.name repro && git config commit.gpgsign false
git remote add origin "$T/origin.git"
mkdir -p .gstack apps/mobile/src/media
echo '{ "runner": "bun test {files}", "dependencies": { "README.md": [] } }' > .gstack/pregate.json
echo '# repro' > README.md
echo '{ "compilerOptions": { "strict": true, "paths": { "@/*": ["./src/*"] } } }' > apps/mobile/tsconfig.json
echo 'export const label = () => "Close";' > apps/mobile/src/media/close-bar.ts
printf '%s\n' "import { expect, test } from 'bun:test';" "import { label } from '@/media/close-bar';" "test('label', () => expect(label()).toBe('Close'));" > apps/mobile/src/media/close-bar.test.ts
git add -A && git commit -q -m base && git push -q -u origin main
git checkout -q -b change
echo 'export const label = () => "Close";  // edited' > apps/mobile/src/media/close-bar.ts
git commit -q -am 'edit close-bar'
GSTACK_HOME="$T/home" "$GSTACK/bin/gstack-pregate" --base main --allow-repo-commands --stage tests --only lanes --explain 2>&1 || echo "exit=$?"

Scope

  • Changed: lib/pregate/import-graph.ts (readPathAliases takes a directory; new pathAliasResolver picks the governing config per importing file; buildGraph uses it), three tests, one paragraph in docs/pregate.md, a changelog fragment.
  • Verified live by: the reproduction above on macOS with Bun 1.3.13; bun run typecheck; test/pregate-import-graph-paths.test.ts; the six other test files that use the import graph, where no test fails here that does not also fail on main. It has also run in a private pnpm monorepo's /ship since 2026-11-11.
  • Did NOT test: Windows; TypeScript project references; the full free suite (bun run test).

Liveness proof (required for external contributors)

Checklist

  • Liveness screenshot attached (GSTACK PR typed live into a real surface) or PR author is @garrytan (owner exemption)
  • This is not a generated-file-only diff (I edited the source/template and regenerated)
  • No ETHOS.md edits, and no changes to voice / founder perspective / YC references
  • New public command / external service / host adapter has an accepted issue linked (or N/A)
  • Linked issue or reproduction: reproduction above

The import graph read tsconfig paths and baseUrl from the repository root
only, so a test under apps/mobile that imports '@/media/close-bar' through
apps/mobile/tsconfig.json was invisible and the source file it covers had
no test to run. Each importing file now takes its aliases from the nearest
tsconfig.json or jsconfig.json above it that declares paths or baseUrl; a
nested config that declares neither defers to the next one up, and the
root config governs the rest.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@trunk-io

trunk-io Bot commented Nov 17, 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

capy-ai Bot added a commit that referenced this pull request Nov 17, 2026
…wn @/ alias (#4464)

/ship's pre-push test selection now finds the tests of a monorepo app
that imports through its own `@/` alias (for example `apps/mobile`
mapping `@/*` to `./src/*`).

Why: only the root tsconfig was read, so every touched file in such an
app failed with `PREGATE_NO_LANE` even with a test beside it. Rebuilt
from #4462 by @dtoelke, who found and fixed it; thank you.

Nothing to do: a repo whose only tsconfig is at the root (gstack itself)
resolves exactly as before.

Co-authored-by: stackpt-agent <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p2v/outside-voice#1 reader=outside-voice
@capy-ai

capy-ai Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Thank you, @dtoelke. You found a real gap and diagnosed it clearly: monorepo apps with their own @/ alias had no tests selected. Your fix landed in #4464, rebuilt on current main as we do for every outside change, with you credited on the commit and in the changelog. It also keeps extends inside the repository and reads config files through the existing size-limited, in-repo reader. Closing this one in favor of #4464.

@capy-ai capy-ai Bot closed this Nov 17, 2026
@capy-ai

capy-ai Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

For reference, the fix is on main as commit 44c904f (#4464). Thanks again, @dtoelke.

@stackpt-agent
stackpt-agent deleted the nested-tsconfig-path-aliases branch November 17, 2026 23:20
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.

2 participants