Skip to content

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

Closed

Description

@shounakjoshi88-a11y

Follow-ups from the review of #85 (both noted as non-blocking there — this issue tracks them). Neither is a safety problem: both currently fail safe by disqualifying the selective route more often than necessary, they just limit how much of #83 the GO_TESTDATA route delivers in real repos.

1. The bare "testdata" reference token over-disqualifies the route

In goPackageTestDataOwnerFor (src/repo/impact.ts), the disqualification check builds its patterns from referenceTokens(dataDir) for p/testdata, and that token list includes the bare testdata literal. With ancestors: true, contentNamesPath matches a path-less word, so any other package containing the very common idioms

filepath.Join("testdata", name)
os.ReadDir("testdata")

disqualifies p's route — even though in package q, a bare testdata resolves to q/testdata, which has nothing to do with p/testdata.

In a repo where two or more packages each use their own testdata, the selective route would rarely be chosen (always falling back), failing safe but wasting the analysis.

Suggested direction (from the review of #85): resolve a bare testdata token against the reader's own package directory and treat it as a reference to that package's testdata only. A slash-bearing reference (p/testdata/…) should keep its current treatment, since that genuinely names another package's tree.

2. Reader scans are repeated per changed file — memoize per dataDir

Every changed file under the same testdata directory runs the same disqualifies scan over goReadersByPackage and goOutsideReaders again: same readers, same contents, same result. On a golden-file refresh that touches many files in one tree, the scan is repeated for each.

Suggested direction: cache the scan outcome keyed by the owning dataDir (valid for one analysis run, keeping the current readRepositoryFile single-read semantics), so a large refresh only pays once per tree.

Happy to take these in a separate PR if a maintainer confirms scope.

Activity

  1. adityankale190895 commented on Nov 10, 2026

    @adityankale190895
    Member

    Thanks for writing these up, @shounakjoshi88-a11y. Confirmed on both, and yes, please take them. One PR covering both is fine, or two if that's easier to review.

    1. Bare testdata token. Agreed. Today referenceTokens(dataDir) includes the bare testdata literal, so filepath.Join("testdata", name) in any other package disqualifies p's route. Some things to keep the fix safe:

    • Resolve the bare token against the reader's own package directory only for readers in goReadersByPackage. Those run with the package as their working directory. For goOutsideReaders (nested modules, non-Go tests, discovery-excluded .go files) we don't know the working directory, so keep the current conservative behaviour there.
    • Slash-bearing references (p/testdata/..., ../p/testdata) keep their current treatment, as you said.
    • Please add a regression test for the split-argument form, filepath.Join("..", "p", "testdata"). It's still caught by the bare p ancestor token, and the fix shouldn't lose that.
    • A test with two packages that each read their own testdata, with the selective route chosen for a change under either one, would show the intended win.

    2. Per-dataDir memo. Agreed, with one caveat: filePattern adds file-specific tokens (the basename and the full path) on top of dirPattern. So cache the directory-level verdict per dataDir, but keep the file-specific check per changed file. A disqualified dataDir can short-circuit every file under it. Scope the cache to one analysis run, like goPackageTestDataOwner.

    Please run npm run audit:boundary before pushing if the PR adds any new files.

    Separately, and no pressure: if you have a Go project of your own, I'd love to hear how DiffCI's test selection does on it. The Community result form is the easiest way to share, and misses are just as useful as wins. And if the project has been useful to you, a star helps other people find it.

  2. shounakjoshi88-a11y commented on Nov 20, 2026

    @shounakjoshi88-a11y
    ContributorAuthor

    Thanks for the detailed scope — both are in #334.

    The bare testdata token is dropped only for goReadersByPackage; outside readers keep it, and the slash-bearing path plus the bare ancestor p are untouched so the split filepath.Join("..", "p", "testdata") case still disqualifies. The directory verdict is cached per dataDir for one analysis run, with the file-specific basename/path check left per file.

    Fixtures cover the two-package win (fails on base), the split reference, the outside-reader case, and multiple changed files under one tree. npm run typecheck, npm run audit:boundary and the Go runtime-inputs suite (59 tests) are green; the single full-suite failure reproduces on base. Commits are DCO signed as CONTRIBUTING.md asks.

    I don't have a Go project of my own to run DiffCI on, but I can point it at one of the corpus clones on this machine if that would be useful data.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions