Skip to content

fix(go): scope a bare testdata reference to the reading package - #334

Merged
adityankale190895 merged 2 commits into
DiffCI:mainfrom
shounakjoshi88-a11y:fix/testdata-references-and-memo
Nov 21, 2026
Merged

adityankale190895 merged 2 commits into
DiffCI:mainfrom
shounakjoshi88-a11y:fix/testdata-references-and-memo

Conversation

@shounakjoshi88-a11y

Copy link
Copy Markdown
Contributor

Both follow-ups from #90, in one PR as you said was fine.

1. Bare testdata resolves inside the reading package

goReported packages run with their own directory as the working directory, so filepath.Join("testdata", name) in package q names q/testdata, not p/testdata. I drop only the bare testdata token from the patterns used for goReadersByPackage. Everything else is unchanged:

  • readers outside package discovery keep the original unfiltered pattern (unknown working directory → conservative);
  • slash-bearing tokens (p/testdata, ../p/testdata) and the bare ancestor p stay, so a split filepath.Join("..", "p", "testdata") still disqualifies;
  • the file-specific basename/path tokens stay, so a reader that names the actual golden file still disqualifies.

2. Directory-level verdict memoized per dataDir

The verdict from the directory tokens is cached for one analysis run alongside the rest of the Go testdata state. A disqualified directory short-circuits every changed file under it; the basename/full-path check is still done per file. One readRepositoryFile call per reader is preserved (the analyzer already dedupes those reads).

Fixtures

  • two packages each reading their own testdata → selective route for a change under either tree (fails on the base);
  • split filepath.Join("..", "p", "testdata") → full validation still;
  • an outside reader with a bare testdata → full validation still;
  • several changed files under one tree → all get the owner's selective route.

Validation

  • npm run typecheck — clean
  • npm run audit:boundary — clean (450 files, no new files added)
  • npx tsx --test tests/repo/go-runtime-inputs.test.ts — 59/59 pass
  • full npm test — one pre-existing failure in action-verify.test.ts (repository output cannot close the summary fence) that reproduces identically on the unmodified base
  • DCO sign-off included per CONTRIBUTING.md

Closes #90.

A go-reported package runs with its own directory as the working directory, so a bare "testdata" in a sibling's filepath.Join("testdata", name) names that sibling's tree, not the changed one. Drop that one token for package readers; keep it for readers outside package discovery, whose working directory is unknown. Slash-bearing paths and the bare ancestor package name stay, so a split filepath.Join("..", "p", "testdata") still disqualifies.

Also memoize the directory-level verdict per testdata directory for one analysis run; the file-specific basename/path check stays per changed file, and a disqualified directory short-circuits every file under it.

New fixtures: two packages each reading their own testdata stay selective; a split relative reference and an outside reader's bare testdata still fall back; several changed files under one tree all select the owner. npm run typecheck, npm run audit:boundary and the go-runtime-inputs suite (59 tests) are green; the one full-suite failure in action-verify.test.ts reproduces on base.

Signed-off-by: Shounak Joshi <[email protected]>
@adityankale190895

Copy link
Copy Markdown
Member

Thanks, this is a clean follow-up: the per-dataDir cache resets each run, each reader is read once, an unreadable reader still fails closed, and outside readers keep the unfiltered pattern. The sibling-package win works as described.

One case regresses, though: a package below the owner that reads the owner's testdata through ... For p/sub reading p/testdata, a change to p/testdata/golden.json:

p/sub/sub_test.go reads it with main this PR
filepath.Join("..", "testdata", name) FULL (includes p/sub) SELECTIVE, p/value_test.go only
os.ReadDir("../testdata") FULL SELECTIVE, p/value_test.go only
filepath.Glob("../testdata/*.json") FULL SELECTIVE, p/value_test.go only

Without the bare testdata token, the prefilter pattern for p/testdata is just p/testdata and bare p, and ../testdata matches neither, so contentNamesPath never gets to resolve ../testdata from p/sub (which it would do correctly). The per-file check only helps when the reader names the exact file.

A bare testdata can only reach the owner's tree from a package inside it, so a fix is to keep the unfiltered patterns for those readers:

const below = (pkg: string) => owner === "." || pkg.startsWith(`${owner}/`);

and use outsideDirPattern / outsideFilePattern for readers in a below(pkg) package, in both the directory loop and the per-file loop. With that change all three cases above go back to FULL, and the Go runtime-inputs suite passes (62/62, including your four new tests).

Could you add that, plus a regression test with a p/sub package (it needs a p/sub entry in the fixture's go list metadata) reading filepath.Join("..", "testdata", name)? Happy to merge after that.

@shounakjoshi88-a11y

Copy link
Copy Markdown
Contributor Author

Good catch, and thanks for the precise diagnosis and the suggested below check. Fixed in fbc9dfa.

I kept the unfiltered patterns for readers in packages below the owner, using owner === "." || pkg.startsWith(\${owner}/`), in both the directory-level scan and the per-file scan. The bare testdata` token is now dropped only for readers in genuinely unrelated packages, which was the intent.

The fixture now registers a p/sub package in the synthetic go list metadata, and there are three regression cases for p/sub reading p/testdata through ..: filepath.Join("..", "testdata", name), os.ReadDir("../testdata") and filepath.Glob("../testdata/*.json"). All three fail on the previous head (SELECTIVE) and pass here (FULL). The Go runtime-inputs suite is 63/63, npm run typecheck and npm run audit:boundary are clean.

Ready for another look whenever you are.

@adityankale190895

Copy link
Copy Markdown
Member

Thanks @shounakjoshi88-a11y, this matches the scope in #90. The sibling-package, split-reference and outside-reader fixtures are exactly what I hoped for.

One thing to fix before merge: check (ubuntu-26.04, 22) fails on the new test a package below the owner reading testdata through .. keeps full validation. All three cases (join, readdir, glob) report cancelledByParent. The assertions never ran.

The cause is the nested test(...) calls inside the async parent. They aren't attached to the parent's context or awaited, so on Node 22 the parent finishes and cancels them. Node 24 is more lenient, which is why that job and probably your local run passed. Taking the context and awaiting each subtest should fix it:

test("a package below the owner reading testdata through .. keeps full validation", async (t) => {
  // ...readers...
  for (const [name, source] of Object.entries(readers)) {
    await t.test(`below owner: ${name}`, async () => {
      // ...unchanged...
    });
  }
});

Once Node 22 is green, could you check the Windows jobs too? They were cancelled in this run, so they never tested the change.

On running DiffCI against a corpus clone: yes please, that would be useful data. The Community result form works for that too.

A sub-package of the owner also runs with its own working directory, so a bare 'testdata' there can still reach the owner's tree through '..'. Use the unfiltered patterns for readers in packages below the owner, in both the directory and per-file scans, so ../testdata reaches the path resolver again.

Adds a p/sub fixture package and three regression cases (filepath.Join, os.ReadDir, filepath.Glob). All three fail on the previous head and pass here; the Go runtime-inputs suite is 63/63, typecheck and boundary audit are clean.

Signed-off-by: Shounak Joshi <[email protected]>
@shounakjoshi88-a11y
shounakjoshi88-a11y force-pushed the fix/testdata-references-and-memo branch from fbc9dfa to 4fbf976 Compare November 21, 2026 05:20
@shounakjoshi88-a11y

Copy link
Copy Markdown
Contributor Author

CI caught a problem in my regression test: three check jobs failed with "test did not finish before its parent and was cancelled". I had created the three cases with plain test() calls inside an already running async test, so Node 22 and the Windows runners cancelled them as the parent finished. Node 24 on Ubuntu happened to let them pass.

Fixed in 4fbf976 by making the parent take t and using await t.test(...) for the three cases. The suite is 63/63 locally with no cancelled tests, typecheck is clean, and the branch is force-pushed.

The remaining "Awaiting approval" is just GitHub holding fork workflows until a maintainer approves them.

@adityankale190895
adityankale190895 merged commit cd0b7a7 into DiffCI:main Nov 21, 2026
13 checks passed
@adityankale190895

Copy link
Copy Markdown
Member

Merged, thanks @shounakjoshi88-a11y! Packages that read their own testdata now keep the selective route instead of disqualifying each other. The sub-package .. case and the Node 22 fix made it a solid change.

That's your second Go fix after #85. If you want to chat about DiffCI or what to pick up next, the project Discord is here: https://discord.gg/vAftSVeYgk

And yes to the corpus-clone run whenever you have time. Results go in the Community result form, and misses are just as useful as wins.

adityankale190895 added a commit that referenced this pull request Nov 22, 2026
Usage pings carry selection counts (mode, tests selected, tests total,
path-rule comparator). Moves the CLI's Core pin to 2304f70 so #333 and
#334 ship.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: adityankale190895 <[email protected]>
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.

GO_TESTDATA selective route follow-ups: bare testdata token over-disqualifies; per-dataDir reader-scan memo

2 participants