Skip to content

Commit 5ad6026

Browse files
committed
fix(observability-map): keep the test task out of the turbo cache
The suite scans apps/webapp/app, packages/plugins/src, internal-packages/rbac/src and four files under .github/workflows, none of which turbo hashes for this package, so turbo run test replayed a pass recorded before those trees changed. Measured rather than argued: a route file with a syntax error fails the suite under vitest, and the same tree came back FULL TURBO in 301ms with the failure cached away as a success. inputs was tried and rejected rather than assumed unworkable. Turbo 1.x does accept .. in an input glob, and ../../apps/webapp/app/** did bust the cache on a route change, but it replaces the default file set instead of adding to it, so the same config silently dropped this package's own vitest.config.ts from the hash. The $TURBO_DEFAULT$ token that would add rather than replace is turbo 2.x only and matches nothing on 1.10.3. Costs about 23s per run and no CI job pays it: the dedicated workflow calls vitest without turbo, and unit-tests-internal.yml runs cold. Reported by Devin on #4455.
1 parent f06e723 commit 5ad6026

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

internal-packages/observability-map/src/integration.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,37 @@ describe("the package's tests are wired into the gate", () => {
213213
});
214214
});
215215

216+
/**
217+
* The third road into this suite, after the two workflows above: `turbo run test`, which is what
218+
* `pnpm run test` and `pnpm run test:internal` reach it by.
219+
*
220+
* Turbo keys a task's cache on the package's own files. This suite's real inputs are mostly not
221+
* its own files, they are `apps/webapp/app`, `packages/plugins/src`, `internal-packages/rbac/src`
222+
* and the workflow files read above, so turbo happily replayed a pass recorded before a route
223+
* changed. Measured rather than argued: a route file with a syntax error in it makes
224+
* `parses every route file and produces a report inside a wide band` fail under vitest, and the
225+
* same tree came back FULL TURBO in 301ms with the failure cached away as a success.
226+
*
227+
* So the task is uncacheable, and this asserts that, because the config is one line and reads like
228+
* a performance oversight to anyone who does not know what the suite reads.
229+
*
230+
* What this does not assert is the rejected alternative. `inputs` can name `../../apps/webapp/...`
231+
* and does bust the cache, but it replaces turbo 1.x's default file set instead of adding to it,
232+
* so it drops the package's own files from the hash unless every one of them is listed too; that
233+
* was measured the same way, by editing `vitest.config.ts` and getting FULL TURBO back. The
234+
* reasoning lives in `turbo.json` next to the config it explains.
235+
*/
236+
describe("the third road in, turbo", () => {
237+
it("keeps its test task out of the turbo cache", () => {
238+
const config = readFileSync(resolve(__dirname, "../turbo.json"), "utf8");
239+
// Comments are legal in turbo.json and this one carries the reasoning, so strip them to parse.
240+
const pipeline = JSON.parse(config.replace(/^\s*\/\/.*$/gm, "")) as {
241+
pipeline?: { test?: { cache?: boolean } };
242+
};
243+
expect(pipeline.pipeline?.test?.cache).toBe(false);
244+
});
245+
});
246+
216247
describe("counting candidates independently of the scanner", () => {
217248
// The counter is only worth having if it disagrees with the scanner somewhere. It does: the
218249
// scanner attributes nothing to a nested file that is not `route.ts`/`route.tsx`, and the
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://turborepo.org/schema.json",
3+
"extends": ["//"],
4+
"pipeline": {
5+
// Uncacheable on purpose. This suite's real inputs live outside the package: it scans
6+
// `apps/webapp/app`, `packages/plugins/src`, `internal-packages/rbac/src` and four files under
7+
// `.github/workflows`. The root `test` task keys the cache on this package's own files, so a
8+
// cached pass replayed after a route change broke the scan, which is a guard that stops
9+
// guarding while still reading green.
10+
//
11+
// `inputs` was tried and rejected rather than assumed unworkable. Turbo 1.x does accept `..`
12+
// in an input glob, and `../../apps/webapp/app/**` did bust the cache on a route change. What
13+
// it also does is replace the default file set rather than add to it, so the same config
14+
// silently dropped this package's own `vitest.config.ts` from the hash: editing it replayed a
15+
// cached pass. The `$TURBO_DEFAULT$` token that adds rather than replaces is turbo 2.x only
16+
// and matches nothing on the 1.10.3 here. Trading a stale-on-routes hole for a
17+
// stale-on-own-config hole is not a fix, and an inputs list mirroring what the tests read is
18+
// one more thing that drifts out of sync without saying so.
19+
//
20+
// Cost is about 23s per run, and no CI job pays it: the dedicated workflow calls vitest
21+
// without turbo, and `unit-tests-internal.yml` runs cold.
22+
//
23+
// `it("keeps its test task out of the turbo cache")` in `src/integration.test.ts` fails if
24+
// this is removed.
25+
"test": {
26+
"dependsOn": ["^build"],
27+
"outputs": [],
28+
"cache": false
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)