Skip to content
Myr

Keep deploys and dev servers out of a project's lanes, keep go test's flag values, and infer a plain install without a lockfile

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Review of 205 against its ask and AGENTS.md; each finding fixed test-first. - A workflow or hook step that runs a dev, deploy, release or watch script by name no longer becomes a lane when the script's body happens to run a known tool: `npm run deploy` (`vite build && wrangler deploy`) was `checks.build`, and `npm run dev` (`vitest`) was `checks.unit`, which watches forever. Root scripts already refused these names; steps now do too. - `go test`'s one-file form keeps every flag with its value and drops only the package patterns. `go test -tags integration ./...` was `go test -tags "./$(dirname {path})"`, so the directory became the tag. - Setup inferred from `package.json` with no committed lockfile is `<manager> install`, not `npm ci` or a `--frozen-lockfile` install, which refuse to run without one. - The finder reads `.lefthook.yaml`, the fourth lefthook name the judge closure already holds. - The finder takes `{path}` from `kinds.ts`'s `PATH_PLACEHOLDER` instead of a second copy; its two lookup sets are typed read-only. - judge.ts comments no longer point at the private build plan (a spec section, a wave and an issue number). - Tests: the mixed workflow fixture gains a deploy that builds and a dev server; a `go test -tags … -run …` row; a lockfile-free repo; one row per lefthook file name. Each failed by assertion before its fix.

authored by oscabriel · committed by oscabriel · parent b0c8839 · Browse files · 4 files+106 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+106 added−29 removed

  • tests:+51 added−2 removed
  • other:+55 added−27 removed

4 files+106 added−29 removed

modified:packages/checks/src/finder.ts+49 added-21 removed
8 unmodified lines
9import { LaneName } from "@repo/protocol/ids";10import { Array as Arr, Option, Result, Schema } from "effect";11import { parse } from "yaml";1213import { PATH_PLACEHOLDER } from "./kinds.ts";1415/** The run block as it travels before decoding. */16export type RunBlockEncoded = typeof RunBlock.Encoded;1718/** One file of a repo, by its path from the root. */
12 unmodified lines
31 readonly run: Partial<RunBlockEncoded>;32 readonly sources: readonly string[];33}3433/** The placeholder a `test` command holds for the one check file it runs. */34const PATH = "{path}";3535/** The lane names the finder prefers; any other lane takes its script's name. */36type Canonical = "build" | "format" | "lint" | "types" | "unit";3738const isLaneName = Schema.is(LaneName);
344 unmodified lines
383 ? [...tokens, ...added]384 : [...tokens.slice(0, at), ...added, ...tokens.slice(at)];385};386387/** A `go test` package pattern: `.`, `./pkg`, `./...`, `example.com/m/...`. */388const isGoPackages = (arg: string) =>389 arg === "." ||390 arg.startsWith("./") ||391 arg.startsWith("../") ||392 arg.includes("...");393394/**395 * The command that runs one test file, for runners that can: `vitest run`396 * → `vitest run {path}`. Go runs a package and Cargo a test target, so theirs397 * name the file's directory or stem through the shell.
9 unmodified lines
407408 if (startsWith(rest, ["vitest"])) {409 const args = rest[1] === "run" ? rest.slice(2) : rest.slice(1);410405 return write("vitest", "run", ...args, PATH);411 return write("vitest", "run", ...args, PATH_PLACEHOLDER);412 }413414 if (415 ["jest", "mocha", "ava", "pytest"].some((tool) => rest[0] === tool) ||
2 unmodified lines
418 ["node", "--test"],419 ["deno", "test"],420 ].some((tool) => startsWith(rest, tool))421 ) {416 return write(...rest, PATH);422 return write(...rest, PATH_PLACEHOLDER);423 }424425 if (startsWith(rest, ["go", "test"])) {426 // Keep every flag and its value (`-run TestX`); drop the packages.420 const flags = rest.slice(2).filter((arg) => arg.startsWith("-"));427 const flags = rest.slice(2).filter((arg) => !isGoPackages(arg));428422 return write("go", "test", ...flags, `"./$(dirname ${PATH})"`);429 return write("go", "test", ...flags, `"./$(dirname ${PATH_PLACEHOLDER})"`);430 }431432 if (startsWith(rest, ["cargo", "test"])) {433 return write(427 ...insertBefore(rest, "--", ["--test", `"$(basename ${PATH} .rs)"`])434 ...insertBefore(rest, "--", [435 "--test",436 `"$(basename ${PATH_PLACEHOLDER} .rs)"`,437 ])438 );439 }440441 return Option.none();
151 unmodified lines
593 })594 ),595});596587const PRE_COMMIT_STAGES = new Set(["commit", "pre-commit"]);597const PRE_COMMIT_STAGES: ReadonlySet<string> = new Set([598 "commit",599 "pre-commit",600]);601602/** pre-commit's hook ids that name a canonical lane. */603const HOOKS: ReadonlyMap<string, Canonical> = new Map([604 ["ruff", "lint"],
18 unmodified lines
623const isWorkflow = (file: RepoFile) => workflowFile.test(file.path);624625const huskyFile = /^\.husky\/pre-(?:commit|push)$/u;626614const LEFTHOOK = new Set(["lefthook.yml", "lefthook.yaml", ".lefthook.yml"]);627// Every name lefthook reads its config from, as the judge closure lists them.628const LEFTHOOK: ReadonlySet<string> = new Set([629 "lefthook.yml",630 "lefthook.yaml",631 ".lefthook.yml",632 ".lefthook.yaml",633]);634635const PRE_COMMIT = ".pre-commit-config.yaml";636637const byPath = (left: RepoFile, right: RepoFile) =>
40 unmodified lines
678 );679680 const fallback = Option.flatMap(ownName, scriptLane);681682 // A dev server, deploy or release is no check, whatever tool its body runs.683 const neverALane = [step.name, task].some((name) =>684 Option.exists(name, (text) => NEVER_A_LANE.test(text))685 );686663 return fixes(runner.body)687 return neverALane || fixes(runner.body)688 ? Option.none()689 : Option.map(690 Option.orElse(lane, () => fallback),691 (name) => ({
204 unmodified lines
896 * Finds a project's run block in its files. Sources rank CI workflows first,897 * then lefthook, husky and pre-commit hooks, then root `package.json`898 * scripts; a lower source only adds lanes the higher ones lack. Lanes are899 * named `lint`, `types`, `unit`, `build` and `format` when the finder knows876 * the tool or the name, else by their script's name. `test` runs one file877 * (`{path}`) for runners it knows (vitest, jest, bun test, pytest, go test,878 * cargo test, and a few more); otherwise it is the unit lane's command as879 * found. Setup is the install commands the top source runs, or else the880 * package manager's install. A file that doesn't parse is skipped with its881 * reason in `sources`; nothing found leaves `run` and `sources` empty.900 * the tool or the name, else by their script's name; a dev server, deploy,901 * release or fixer is never a lane. `test` runs one file (`{path}`) for902 * runners it knows (vitest, jest, bun test, pytest, go test, cargo test, and903 * a few more); otherwise it is the unit lane's command as found. Setup is the904 * install commands the top source runs, or else the package manager's905 * install, frozen only when a lockfile is committed. A file that doesn't906 * parse is skipped with its reason in `sources`; nothing found leaves `run`907 * and `sources` empty.908 */909export const findRunBlock = (files: readonly RepoFile[]): FoundRunBlock => {910 const sorted = files.toSorted(byPath);911 const root = readPackage(sorted);
54 unmodified lines
966 const lockfile = LOCKFILES.find(967 ([name, owner]) => owner === manager && sorted.some(fileNamed(name))968 );969970 // A frozen install refuses to run without a lockfile, so none means a plain one.971 const inferred =972 setup.length === 0 && Option.isSome(rootPackage)946 ? Option.some({947 command: INSTALL[manager],948 from: lockfile?.[0] ?? PACKAGE_JSON,949 })973 ? Option.some(974 lockfile === undefined975 ? { command: `${manager} install`, from: PACKAGE_JSON }976 : { command: INSTALL[manager], from: lockfile[0] }977 )978 : Option.none();979980 const commands = [981 ...setup.map(([command]) => command),
29 unmodified lines
modified:packages/checks/src/judge.ts+6 added-6 removed
15 unmodified lines
16/** A closure glob that starts with this takes paths back out of the closure. */17const EXCLUDE = "!";1819/**20 * What every project's judge holds before its run block adds to it (spec21 * §4.2 `packages/gate`): the config folder, the env schema and committed env22 * files (never `*.local` ones), CI, test and lint config, the tsconfig files,23 * git and harness hook config, and generated contribute skills. W4 issue 41124 * adds lint plugin sources, rule fixtures and more harnesses.20 * What every project's judge holds before its run block adds to it: the21 * config folder, the env schema and committed env files (never `*.local`22 * ones), CI, test and lint config, the tsconfig files, git and harness hook23 * config, and generated contribute skills. Lint plugin sources and rule24 * fixtures are not in it yet.25 */26export const defaultJudgeGlobs: readonly Glob[] = [27 `${Brand.configDir}/**`,28 "**/.env.schema",
164 unmodified lines
193194/**195 * The files a tsconfig extends, followed until the chain ends or leaves the196 * repo. A package specifier (`@tsconfig/node24`) is a dependency, not a path.197 * A file that doesn't parse as JSON ends its branch (411 reads JSONC).197 * A file that doesn't parse as plain JSON (JSONC, say) ends its branch.198 */199const extendsChain = (200 start: string,201 contents: ReadonlyMap<string, string>
175 unmodified lines
modified:packages/checks/test/fixtures/finder/repos.ts+7 added-2 removed
193 unmodified lines
194 JSON.stringify({ scripts: { test: "vitest run" } })195 ),196];197198/** A workflow that runs a fixer, a deploy, an unknown script and both kinds of `ruff format`. */198/**199 * A workflow that runs a fixer, a deploy that builds first, a dev server, an200 * unknown script and both kinds of `ruff format`.201 */202export const mixedWorkflow: readonly RepoFile[] = [203 file(204 "package.json",205 JSON.stringify({206 scripts: {204 deploy: "wrangler deploy",207 deploy: "vite build && wrangler deploy",208 dev: "vitest",209 "gen:check": "node scripts/gen.js --check",210 },211 })212 ),
5 unmodified lines
218 " - run: npm ci",219 " - run: npx prettier --write .",220 " - run: npm run gen:check",221 " - run: npm run deploy",222 " - run: npm run dev",223 " - run: ruff format .",224 " - run: ruff format --check .",225 " - run: echo done"226 ),
1 unmodified line
modified:packages/checks/test/finder.test.ts+44 added
116 unmodified lines
117 ],118 });119 });120121 it("infers a plain install when the repo commits no lockfile, since a frozen one would refuse", () => {122 expect(123 findRunBlock([124 {125 content: JSON.stringify({ scripts: { test: "vitest run" } }),126 path: "package.json",127 },128 ])129 ).toStrictEqual({130 run: {131 checks: { unit: "npm test" },132 setup: "npm install",133 test: "vitest run {path}",134 },135 sources: [136 "setup inferred from package.json",137 "test from package.json",138 "checks.unit from package.json",139 ],140 });141 });142143 it("names a lane by its script when the tool is unknown, and never takes a fixer or a deploy", () => {144 expect(findRunBlock(mixedWorkflow)).toStrictEqual({145 run: {146 checks: {
9 unmodified lines
156 ],157 });158 });159160 it.each(["lefthook.yml", "lefthook.yaml", ".lefthook.yml", ".lefthook.yaml"])(161 "reads lefthook's commands from %s, a name the judge closure holds",162 (path) => {163 expect(164 findRunBlock([165 {166 content:167 "pre-commit:\n commands:\n lint:\n run: npx eslint {staged_files}\n",168 path,169 },170 ])171 ).toStrictEqual({172 run: { checks: { lint: "npx eslint ." } },173 sources: [`checks.lint from ${path}`],174 });175 }176 );177178 it("finds nothing in a repo with no scripts, CI or hooks", () => {179 expect(findRunBlock(nothing)).toStrictEqual({ run: {}, sources: [] });180 });181
25 unmodified lines
207 ["uv run pytest -q", "uv run pytest -q {path}"],208 ["python -m pytest", "python -m pytest {path}"],209 ["go test -race ./...", 'go test -race "./$(dirname {path})"'],210 [211 "go test -tags integration -run TestWeek ./pkg/...",212 'go test -tags integration -run TestWeek "./$(dirname {path})"',213 ],214 [215 "cargo test --all-features",216 'cargo test --all-features --test "$(basename {path} .rs)"',217 ],218 ["make test", "make test"],
11 unmodified lines