Public: anyone can read this; the crew can change it.
The fast tier guesses for an unseen file by its importers, and reads no doc through a helper the suite runs #17111
Merged 47h 59m ago, live in production
fix/selection-blind-docs → main 0 commits 1 thread · 1 unresolved
5 files
changed +122
−18
src/checks/scans.ts +6 −5
| @@ -233,11 +233,12 @@ function docNamesFor(doc: string): string[] { | ||
| 233 | 233 | */ |
| 234 | 234 | function docDirNamesFor(doc: string): string[] { |
| 235 | 235 | const parts = doc.split("/"); |
| 236 | const names: string[] = []; | |
| 237 | for (let i = 1; i < parts.length; i++) | |
| 238 | for (const at of new Set([parts.slice(0, i).join("/"), parts[i - 1]!])) | |
| 239 | names.push(`"${at}"`, `'${at}'`, `\`${at}\``, `"${at}/"`, `'${at}/'`, `\`${at}/\``, `\`${at}/\${`); | |
| 240 | return names; | |
| 236 | if (parts.length < 2) return []; | |
| 237 | // The doc's own directory as a whole path, never an ancestor or a bare last name: "features" is a | |
| 238 | // palette id and a route as often as a directory, and naming "docs" lists the top, not | |
| 239 | // docs/features (a doc change read through such names selected some 1,450 tests). | |
| 240 | const at = parts.slice(0, -1).join("/"); | |
| 241 | return [`"${at}"`, `'${at}'`, `\`${at}\``, `"${at}/"`, `'${at}/'`, `\`${at}/\``, `\`${at}/\${`]; | |
| 241 | 242 | } |
| 242 | 243 | |
| 243 | 244 | /** Each tree's files as code, read once however many scripts a diff holds. */ |
src/checks/tiers.ts +40 −5
| @@ -217,6 +217,25 @@ export interface FastPlan { | ||
| 217 | 217 | readonly blindBy: ReadonlyMap<string, string>; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | /** Why a src file blinds a plan when no test executes it: guessed for by its importers alone. */ | |
| 221 | const UNEXECUTED = "no test executes it"; | |
| 222 | ||
| 223 | /** Above this share of the measured tests, a src file is a shared helper, not a particular read. */ | |
| 224 | const SHARED_SHARE = 0.5; | |
| 225 | ||
| 226 | /** | |
| 227 | * The src files more than {@link SHARED_SHARE} of the measured tests execute: hubs (http/server.ts, | |
| 228 | * core/reserved.ts). A doc read through one, or an import guess walked through one, would reach | |
| 229 | * nearly every test and says nothing about this change. | |
| 230 | */ | |
| 231 | function hubsOf(impact: Impact | undefined): ReadonlySet<string> { | |
| 232 | if (impact === undefined) return new Set(); | |
| 233 | const counts = new Map<string, number>(); | |
| 234 | for (const files of impact.values()) for (const f of files) counts.set(f, (counts.get(f) ?? 0) + 1); | |
| 235 | const over = impact.size * SHARED_SHARE; | |
| 236 | return new Set([...counts].filter(([, n]) => n > over).map(([f]) => f)); | |
| 237 | } | |
| 238 | ||
| 220 | 239 | /** |
| 221 | 240 | * The fast tier for a diff: a changed test; a test importing a changed file |
| 222 | 241 | * directly or through up to two hops of source; a test whose name matches a |
| @@ -267,8 +286,12 @@ export function fastSet(input: FastInput): FastPlan { | ||
| 267 | 286 | const readers = isDoc(f) ? input.docReaders?.(f) : undefined; |
| 268 | 287 | if (readers !== undefined) docs.set(f, readers); |
| 269 | 288 | } |
| 289 | const hubs = hubsOf(impact); | |
| 290 | // A source most of the suite executes is no read of this doc (src/core/reserved.ts names "docs" | |
| 291 | // among its reserved words): left out of the reach, the loading guess and the import guess alike. | |
| 270 | 292 | const docOf = new Map<string, string>(); |
| 271 | for (const [doc, readers] of docs) for (const source of readers.sources) if (!docOf.has(source)) docOf.set(source, doc); | |
| 293 | for (const [doc, readers] of docs) | |
| 294 | for (const source of readers.sources) if (!hubs.has(source) && !docOf.has(source)) docOf.set(source, doc); | |
| 272 | 295 | // A src file that reads a doc while the suite loads: who uses what it read the map cannot say. |
| 273 | 296 | const docLoads = [...docOf.keys()].filter((source) => loads.has(source)); |
| 274 | 297 | // A change the map cannot see (a src file no test executes, or a file |
| @@ -287,7 +310,7 @@ export function fastSet(input: FastInput): FastPlan { | ||
| 287 | 310 | grew = true; |
| 288 | 311 | } |
| 289 | 312 | } |
| 290 | for (const f of reached.unreached) if (!through.has(f)) blindBy.set(f, "no test executes it"); | |
| 313 | for (const f of reached.unreached) if (!through.has(f)) blindBy.set(f, UNEXECUTED); | |
| 291 | 314 | for (const f of diffed) |
| 292 | 315 | if ( |
| 293 | 316 | !f.startsWith("src/") && |
| @@ -299,12 +322,16 @@ export function fastSet(input: FastInput): FastPlan { | ||
| 299 | 322 | blindBy.set(f, isDoc(f) && input.docReaders !== undefined ? "a doc its readers cannot bound" : "outside src/ and test/"); |
| 300 | 323 | } |
| 301 | 324 | const blind = blindBy.size > 0; |
| 325 | // A src file no test executes is guessed for by its importers and its name: what it can break is | |
| 326 | // what imports it. Only a change nothing in the tree bounds (a file outside src/ and test/, a doc | |
| 327 | // its readers cannot bound) runs every quick test as well. | |
| 328 | const wide = [...blindBy.values()].some((reason) => reason !== UNEXECUTED); | |
| 302 | 329 | // What loading runs is guessed by each test's imports, without blinding the rest (#14845). |
| 303 | 330 | const guessing = blind || loadRun.length > 0 || docLoads.length > 0; |
| 304 | 331 | // A test the map has never seen (a new one) is judged by the guesses. |
| 305 | 332 | const guessed = (test: string): boolean => |
| 306 | 333 | impact === undefined || guessing || !impact.has(test); |
| 307 | const quickAll = (test: string): boolean => impact === undefined || blind || !impact.has(test); | |
| 334 | const quickAll = (test: string): boolean => impact === undefined || wide || !impact.has(test); | |
| 308 | 335 | const take = (test: string, reason: string): void => { |
| 309 | 336 | if (tests.has(test) && !why.has(test)) why.set(test, reason); |
| 310 | 337 | }; |
| @@ -351,6 +378,7 @@ export function fastSet(input: FastInput): FastPlan { | ||
| 351 | 378 | for (const [test, source] of reached.tests) |
| 352 | 379 | take(test, test === LOADS_ONLY ? `loads ${source}` : `executes ${source}`); |
| 353 | 380 | for (const [doc, mine] of docs) for (const test of mine.tests) take(test, `reads ${doc}`); |
| 381 | // Through a source that names the doc (hubs left out above), the tests that execute it can read it. | |
| 354 | 382 | if (impact && docOf.size > 0) |
| 355 | 383 | for (const [test, source] of reach([...docOf.keys()], impact).tests) |
| 356 | 384 | take(test, `reads ${docOf.get(source)!} through ${source}`); |
| @@ -377,6 +405,10 @@ export function fastSet(input: FastInput): FastPlan { | ||
| 377 | 405 | for (const file of frontier) { |
| 378 | 406 | if (seen.has(file)) continue; |
| 379 | 407 | seen.add(file); |
| 408 | // A hub is not walked through: everything is a few hops from http/server.ts, so a guess | |
| 409 | // through it would take every test that loads the server. A test the map has not seen | |
| 410 | // (`lookFor` is the whole diff) still walks every hop. | |
| 411 | if (hubs.has(file) && lookFor(test) !== changed) continue; | |
| 380 | 412 | next.push(...input.imports(file)); |
| 381 | 413 | } |
| 382 | 414 | frontier = next; |
| @@ -434,12 +466,15 @@ export function reasonLine(plan: Pick<FastPlan, "files" | "why">): string { | ||
| 434 | 466 | /** |
| 435 | 467 | * Why the plan is blind, for the log, or `undefined` when it is not: |
| 436 | 468 | * `blind (every quick test, guesses for every test) by docs/x.md (a doc its |
| 437 | * readers cannot bound), src/y.ts (no test executes it)`. | |
| 469 | * readers cannot bound), src/y.ts (no test executes it)`. A plan blind only by | |
| 470 | * src files no test executes guesses for their importers alone: | |
| 471 | * `blind (guesses for its importers) by src/y.ts (no test executes it)`. | |
| 438 | 472 | */ |
| 439 | 473 | export function blindLine(plan: Pick<FastPlan, "blindBy">): string | undefined { |
| 440 | 474 | if (plan.blindBy.size === 0) return undefined; |
| 441 | 475 | const by = [...plan.blindBy].map(([file, why]) => `${file} (${why})`).join(", "); |
| 442 | return `blind (every quick test, guesses for every test) by ${by}`; | |
| 476 | const wide = [...plan.blindBy.values()].some((why) => why !== UNEXECUTED); | |
| 477 | return `blind (${wide ? "every quick test, guesses for every test" : "guesses for its importers"}) by ${by}`; | |
| 443 | 478 | } |
| 444 | 479 | |
| 445 | 480 | /** `220` → `3m40s`, `45` → `45s`. */ |
test/check-script-readers.test.ts +16 −5
| @@ -114,13 +114,24 @@ describe("the tests that can read a doc (#14845)", () => { | ||
| 114 | 114 | const tests = ["test/threats.test.ts", "test/agents.test.ts", "test/gate.test.ts", "test/b.test.ts"]; |
| 115 | 115 | const readers = (doc: string) => docReaders(doc, tree, tests); |
| 116 | 116 | |
| 117 | test("a test naming it reads it, a comment does not, and src/ listing its directory is a source", () => { | |
| 117 | test("a test naming it reads it, a comment does not, and src/ listing its own directory is a source", () => { | |
| 118 | 118 | expect(readers("docs/THREATS.md")).toEqual({ tests: ["test/threats.test.ts"], sources: ["src/view/docs.ts"] }); |
| 119 | 119 | expect(readers("AGENTS.md")).toEqual({ tests: ["test/agents.test.ts"], sources: [] }); |
| 120 | expect(readers("docs/features/absorb.md")).toEqual({ | |
| 121 | tests: [], | |
| 122 | sources: ["src/view/docs.ts", "src/web/link.ts"], | |
| 123 | }); | |
| 120 | // docs.ts names "docs", the top, not docs/features: only the file naming absorb.md reads it. | |
| 121 | expect(readers("docs/features/absorb.md")).toEqual({ tests: [], sources: ["src/web/link.ts"] }); | |
| 122 | }); | |
| 123 | ||
| 124 | test("a doc's directory is its own whole path: a bare last name or an ancestor is no source", () => { | |
| 125 | const named = treeOf( | |
| 126 | { | |
| 127 | ...files, | |
| 128 | "src/tui/palette.ts": 'export const ids = ["features", "docs"];', | |
| 129 | "src/web/features.ts": 'const DIR = join(root, "docs/features");', | |
| 130 | }, | |
| 131 | ["scripts/gate.ts", "test/helpers/preload.ts"], | |
| 132 | ["test/helpers/preload.ts"], | |
| 133 | ); | |
| 134 | expect(docReaders("docs/features/keymap.md", named, tests)).toEqual({ tests: [], sources: ["src/web/features.ts"] }); | |
| 124 | 135 | }); |
| 125 | 136 | |
| 126 | 137 | test("the check's own script reading it is followed to its importers; the preload or a manifest unbounds it", () => { |
test/check-tiers.test.ts +16 −1
| @@ -153,7 +153,8 @@ describe("the fast set, by measured coverage", () => { | ||
| 153 | 153 | |
| 154 | 154 | test("a changed file no test executes is said, and judged by the guesses", () => { |
| 155 | 155 | const plan = fastSet({ ...base, changed: ["src/web/phone.ts", "src/web/x.ts"] }); |
| 156 | expect(plan.files).toEqual(["test/web-phone.test.ts", "test/tiny.test.ts"]); | |
| 156 | // tiny is quick, but neither imports nor is named for x.ts: it stays out. | |
| 157 | expect(plan.files).toEqual(["test/web-phone.test.ts"]); | |
| 157 | 158 | expect(plan.line).toBe( |
| 158 | 159 | "by coverage and imports: 2 changed files reach 1 test; src/web/x.ts reaches none", |
| 159 | 160 | ); |
| @@ -243,6 +244,20 @@ describe("the fast set, by measured coverage", () => { | ||
| 243 | 244 | expect(blindLine(plan)).toBeUndefined(); |
| 244 | 245 | }); |
| 245 | 246 | |
| 247 | test("a doc read through a helper most of the suite executes selects nobody through it; a particular source still does", () => { | |
| 248 | // shared.ts is executed by three of the five measured tests: a helper, not a read of the doc. | |
| 249 | const wide = new Map([...impact].map(([test, files]) => [test, test.includes("tiny") || test.includes("deep") ? files : [...files, "src/shared.ts"]])); | |
| 250 | const input = { | |
| 251 | ...base, | |
| 252 | impact: wide, | |
| 253 | docReaders: (doc: string) => (doc === "docs/features/keymap.md" ? { tests: ["test/deep.test.ts"], sources: ["src/shared.ts", "src/tiny.ts"] } : undefined), | |
| 254 | }; | |
| 255 | const plan = fastSet({ ...input, changed: ["docs/features/keymap.md"] }); | |
| 256 | expect(plan.why.get("test/deep.test.ts")).toBe("reads docs/features/keymap.md"); | |
| 257 | expect(plan.why.get("test/tiny.test.ts")).toBe("reads docs/features/keymap.md through src/tiny.ts"); | |
| 258 | for (const test of ["test/snapshot-store.test.ts", "test/snapshot.test.ts", "test/web-phone.test.ts"]) expect(plan.why.has(test)).toBe(false); | |
| 259 | }); | |
| 260 | ||
| 246 | 261 | test("a doc nothing bounds, and any other file the map cannot see, blinds the plan and is named (#14845)", () => { |
| 247 | 262 | const unbound = fastSet({ ...base, docReaders: () => undefined, changed: ["src/snapshot/store.ts", "AGENTS.md"] }); |
| 248 | 263 | expect(unbound.why.get("test/tiny.test.ts")).toBe("quick"); |
test/impact-use-not-load.test.ts +44 −2
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | import { describe, expect, test } from "bun:test"; |
| 9 | 9 | import { HUB_IMPORTS, coverOf, usedFiles } from "../src/checks/impact.ts"; |
| 10 | import { RULE_TESTS, fastSet } from "../src/checks/tiers.ts"; | |
| 10 | import { RULE_TESTS, fastSet, blindLine } from "../src/checks/tiers.ts"; | |
| 11 | 11 | |
| 12 | 12 | describe("used, not loaded", () => { |
| 13 | 13 | // What a process that only loads the suite runs: the preload's own files. |
| @@ -87,9 +87,51 @@ describe("a new file does not blind the plan when the diff leads to it", () => { | ||
| 87 | 87 | expect(p.files).not.toContain("test/quick.test.ts"); |
| 88 | 88 | }); |
| 89 | 89 | |
| 90 | test("one nothing in the diff leads to still blinds it, and every quick test runs", () => { | |
| 90 | test("one nothing in the diff leads to is guessed for by its importers and name, never every quick test", () => { | |
| 91 | 91 | const p = plan(["src/snapshot/service.ts", "src/snapshot/orphan.ts"]); |
| 92 | 92 | expect([...p.blindBy.keys()]).toEqual(["src/snapshot/orphan.ts"]); |
| 93 | // A quick test that neither imports nor is named for the new file stays out (31% of pull checks | |
| 94 | // ran every quick test for one such file). | |
| 95 | expect(p.files).not.toContain("test/quick.test.ts"); | |
| 96 | expect(p.files).not.toContain("test/other.test.ts"); | |
| 97 | expect(blindLine(p)).toBe("blind (guesses for its importers) by src/snapshot/orphan.ts (no test executes it)"); | |
| 98 | // A test that imports it, and one named for it, are guessed in. | |
| 99 | const withImporter = fastSet({ | |
| 100 | changed: ["src/snapshot/orphan.ts"], | |
| 101 | tests: [...tests, "test/snapshot-orphan.test.ts"], | |
| 102 | imports: (file) => (file === "test/other.test.ts" ? ["src/snapshot/orphan.ts"] : imports(file)), | |
| 103 | times, | |
| 104 | impact, | |
| 105 | }); | |
| 106 | expect(withImporter.why.get("test/other.test.ts")).toBe("imports src/snapshot/orphan.ts"); | |
| 107 | expect(withImporter.why.get("test/snapshot-orphan.test.ts")).toBe("named for src/snapshot/orphan.ts"); | |
| 108 | expect(withImporter.files).not.toContain("test/quick.test.ts"); | |
| 109 | }); | |
| 110 | ||
| 111 | test("the import guess does not walk through a hub most of the suite executes", () => { | |
| 112 | // hub.ts is executed by all three measured tests: a guess through it would take them all. | |
| 113 | const hubbed = new Map([...impact].map(([test, files]) => [test, [...files, "src/http/hub.ts"]])); | |
| 114 | const p = fastSet({ | |
| 115 | changed: ["src/snapshot/orphan.ts"], | |
| 116 | tests, | |
| 117 | imports: (file) => | |
| 118 | ({ | |
| 119 | "test/system.test.ts": ["src/http/hub.ts"], | |
| 120 | "test/other.test.ts": ["src/snapshot/orphan.ts"], | |
| 121 | "src/http/hub.ts": ["src/snapshot/orphan.ts"], | |
| 122 | })[file] ?? [], | |
| 123 | times, | |
| 124 | impact: hubbed, | |
| 125 | }); | |
| 126 | // Its own importer is guessed in; the test that reaches it only through the hub is not. | |
| 127 | expect(p.why.get("test/other.test.ts")).toBe("imports src/snapshot/orphan.ts"); | |
| 128 | expect(p.why.has("test/system.test.ts")).toBe(false); | |
| 129 | expect(p.files).not.toContain("test/quick.test.ts"); | |
| 130 | }); | |
| 131 | ||
| 132 | test("a change nothing in the tree bounds still runs every quick test", () => { | |
| 133 | const p = plan(["src/snapshot/service.ts", "static/app.js"]); | |
| 93 | 134 | expect(p.files).toContain("test/quick.test.ts"); |
| 135 | expect(blindLine(p)).toBe("blind (every quick test, guesses for every test) by static/app.js (outside src/ and test/)"); | |
| 94 | 136 | }); |
| 95 | 137 | }); |
new above
offline
Same
widecomputation as in fastSet. Share one helper so the log line and the plan always agree.