Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Pre-commit gate, a quick check that the change broke nothing large:
# 1. format:check — Prettier, verify only (run `npm run format` to fix)
# 2. lint — eslint, one rule: multi-line comments are starred blocks
# 3. test — golden suite, values only: engine/tests/golden/runAll.ts
# 4. test:unit:hook — the unit tests of canon, cade and web, and the engine's
# 1. lint:hook — Prettier (verify only; `npm run format` fixes) and eslint,
# on the staged files only (scripts/hook-lint.mjs)
# 2. test — golden suite, values only: engine/tests/golden/runAll.ts
# 3. test:unit:hook — the unit tests of canon, cade and web, and the engine's
# without the whole-return tests (each form's form.test.ts), which run only
# for the forms this commit changes (scripts/hook-unit-tests.mjs)
#
# The slow tests do not run here. Every unit test, the integration tests, the full
# The slow checks do not run here. Format and lint of the whole repository,
# every unit test, the integration tests, the full
# required-inputs check and the PDF fill run on GitHub for each pull request
# (.github/workflows/gates.yml), side by side, and a pull request merges only
# when its "all gates" check is green. Run one locally when you need it:
Expand All @@ -17,7 +18,6 @@
# in two stages (expected.ts before fact-fix, or vice versa). Don't make
# that a habit.

npm run format:check
npm run lint
npm run lint:hook
npm test
npm run test:unit:hook
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ Most readers open a PR on a phone and do not open the diff. The description must
- `Risk: routine` or `Risk: high — <what could break and for whom>`; add `Complex: <why>` when the reader needs more than a glance, and `Pattern change: <old → new>` when the PR changes how we do something. A pattern change also updates this file.
3. **What changed**: one bullet per idea, in the order a reader would ask. Name a file only when the reader has to go there.
4. **Example outcome** when a user or operator sees something different: the real screen text, log line or command output.
5. **Verified**: what ran and what did not. Say "not run" out loud. A pull request merges only when its `all gates` check on GitHub is green. The check (`.github/workflows/gates.yml`) runs every test on GitHub's runners as parallel jobs: typecheck, lint and format, the scenario values, the PDF fill, the unit tests, the integration tests and the full required-inputs check. No job calls a model or needs a secret. GitHub tests the head merged with `main` as of the last push; when `main` moved since, `gh pr update-branch <number>` runs the check again. The commit hook is only a quick check (format, lint, scenario values, and the unit tests without the whole-return tests of forms the commit does not change: `scripts/hook-unit-tests.mjs`), so the pull request's check is the one place where the filled PDFs, the integration tests and every removed answer are checked. `gh pr checks <number> --watch` waits for the result.
5. **Verified**: what ran and what did not. Say "not run" out loud. A pull request merges only when its `all gates` check on GitHub is green. The check (`.github/workflows/gates.yml`) runs every test on GitHub's runners as parallel jobs: typecheck, lint and format, the scenario values, the PDF fill, the unit tests, the integration tests and the full required-inputs check. No job calls a model or needs a secret. GitHub tests the head merged with `main` as of the last push; when `main` moved since, `gh pr update-branch <number>` runs the check again. The commit hook is only a quick check (format and lint of the staged files, scenario values, and the unit tests without the whole-return tests of forms the commit does not change: `scripts/hook-unit-tests.mjs`), so the pull request's check is the one place where the filled PDFs, the integration tests and every removed answer are checked. `gh pr checks <number> --watch` waits for the result.
6. **PDFs to review** when the PR adds or changes a PDF: one link for each file to its page on the PR's branch, `https://github.com/captaincole/OpenReturn/blob/<branch>/<path>`. GitHub's diff does not show a PDF; the file's page does. Put the files a person must read first (a made input document, the filled return of a new form), then the other filled returns, then blank forms. `git diff --name-only --diff-filter=AM origin/main...HEAD -- '*.pdf'` lists the files. After a push that changes the list, update it.
7. **Refs**: the issue, the PRs it builds on, the doc that recommends the change.

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"test:pdf": "npm -w @openreturn/engine run test:pdf",
"test:inputs": "npm -w @openreturn/engine run test:inputs",
"test:unit": "npm -w @openreturn/engine run test:unit && npm -w canon run test:unit && npm -w cade run test:unit && npm --prefix web run test:unit",
"lint:hook": "node scripts/hook-lint.mjs",
"test:unit:hook": "node scripts/hook-unit-tests.mjs && npm -w canon run test:unit && npm -w cade run test:unit && npm --prefix web run test:unit",
"test:integration": "npm -w @openreturn/engine run test:integration && npm -w cade run test:integration",
"coverage": "npm -w @openreturn/engine run coverage",
Expand Down
38 changes: 38 additions & 0 deletions scripts/hook-lint.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node
/*
* Format check and lint for the commit hook, on the staged files only.
*
* `npm run format:check` and `npm run lint` read every file of the repository
* (about 80 seconds and 220 seconds on a busy machine). A commit changes a few
* files, and those take a few seconds. GitHub runs both over the whole
* repository for each pull request (.github/workflows/gates.yml).
*/
import { execFileSync, spawnSync } from "node:child_process";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const root = join(dirname(fileURLToPath(import.meta.url)), "..");

/* The extensions that `npm run format:check` and `npm run lint` cover. */
const CHECKED = [".ts", ".tsx", ".mjs", ".js"];

const staged = execFileSync("git", ["diff", "--cached", "--name-only", "--diff-filter=ACMR"], {
cwd: root,
encoding: "utf8",
})
.split("\n")
.filter((file) => CHECKED.some((extension) => file.endsWith(extension)));

if (staged.length === 0) {
console.log("No staged code file: nothing to format-check or lint.");
process.exit(0);
}

const run = (tool, args) =>
spawnSync("npx", [tool, ...args, ...staged], { cwd: root, stdio: "inherit" }).status ?? 1;

console.log(`Format check and lint of ${staged.length} staged file(s).`);
const format = run("prettier", ["--check", "--ignore-unknown"]);
if (format !== 0) process.exit(format);
/* A staged file that the lint config ignores is not a warning here. */
process.exit(run("eslint", ["--max-warnings", "0", "--no-warn-ignored"]));
Loading