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
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ that runs the same commands from anywhere, using the checkout you are in.
- Verify cheapest first, and broaden only once the narrower step passes: builds
and test runs are slow and memory-hungry, and on a busy machine they wait for
a slot, so don't spend one to find a type or compile error.
1. `tools check --fast`: format, lint, `cargo check` and typecheck of only
what changed, and the repository rules. It builds and tests nothing.
1. `tools check --fast`: lint, `cargo check` and typecheck of only what
changed, the format check CI runs (the whole tree, in under a second), and
the repository rules. It builds and tests nothing.
2. `tools build <workspace>` when a test needs built output: that workspace
and what it depends on, rebuilding only what is out of date. Not
`npm run build`, which rebuilds every workspace, the release CLI and
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ empty directory with no Node on PATH (pass `-- --binary FILE` to verify a
release asset).

When iterating, run the fastest checks first and widen gradually: start with
`tools check --fast` (format, lint, `cargo check`, and typecheck of what
changed), run `tools build <workspace>` if a test needs built output, run the
narrowest test with `tools test <target> --filter <name>`, and only then run
`tools check --affected`, `tools test --affected`, and full `npm run check`.
`tools check --fast` (CI's format check, and lint, `cargo check` and typecheck
of what changed), run `tools build <workspace>` if a test needs built output,
run the narrowest test with `tools test <target> --filter <name>`, and only then
run `tools check --affected`, `tools test --affected`, and full `npm run check`.
Catching a compile error in `--fast` takes seconds instead of burning minutes—or
waiting for a build slot on a shared machine—in a full build or test run. Keep
strict error, cancellation, geometry, progress, and input-validation assertions
Expand Down
14 changes: 5 additions & 9 deletions tools/cli/src/lib/gates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {linkProblems} from './links.ts'
import {inDependencyOrder, readmeProblems, type Unit} from './packages.ts'
import {parseConsidered, parseFormatCheck, parseProblems, parseStalePages, tail, type Problem} from './problems.ts'
import {display, run, type Command} from './repo.ts'
import {changedFiles, fastTypecheck, lintPlan, npm, npx} from './typed-gates.ts'
import {fastTypecheck, lintPlan, npm} from './typed-gates.ts'
import {versionProblems} from './release-check.ts'
import {existsSync} from 'node:fs'
import {join} from 'node:path'
Expand Down Expand Up @@ -151,14 +151,10 @@ export const gates: Gate[] = [
{
name: 'format',
fast: true,
description: 'Formatting (oxfmt --check)',
plan: context => {
if (!context.affected) return {commands: [npx('oxfmt', '--check')]}
const files = changedFiles(context, /\.([cm]?[jt]sx?|json|jsonc|ya?ml|css|html|toml)$/u)
return files.length
? {commands: [npx('oxfmt', '--check', '--no-error-on-unmatched-pattern', ...files)]}
: {skip: 'no formattable file changed'}
},
description: 'Formatting (npm run format:check)',
// The whole repository, as CI checks it, even with --fast or --affected: it takes under a second, and a list of
// changed files can only drift from what CI checks (Markdown went unchecked when the list filtered by extension).
plan: () => ({commands: [npm('run', '--silent', 'format:check')]}),
parse: parseFormatCheck,
fix: `${TOOLS} fix --only format`,
},
Expand Down
14 changes: 14 additions & 0 deletions tools/cli/test/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {Affected} from '../src/lib/affected.ts'
import {buildInputs, buildState, inputSignature, recordBuild} from '../src/lib/builds.ts'
import {gates, type GateContext} from '../src/lib/gates.ts'
import type {Unit} from '../src/lib/packages.ts'
import {readJson, workspaceRoot} from '../src/lib/repo.ts'
import {recordSuccess, restoreIfUnchanged, snapshot, staleness} from '../src/commands/work/build.ts'
import {nodeTestPattern, testPlan} from '../src/commands/work/test.ts'

Expand Down Expand Up @@ -57,6 +58,19 @@ test('--fast leaves out every gate that builds, tests or reads the whole tree',
)
})

test("the format gate runs CI's format check, whatever changed and however scoped", () => {
const ci = ['npm run --silent format:check']
const units = [unit('app')]
// A Markdown change (and every other file oxfmt formats) is checked with --fast, as CI checks it.
for (const files of [['docs/guide.md'], ['packages/app/test/x.test.mjs'], []]) {
assert.deepEqual(argvs(plan('format', {root: '.', units, affected: affected(['app'], [], ['ts']), files, fast: true})), ci)
}
assert.deepEqual(argvs(plan('format', {root: '.', units})), ci)
const scripts = readJson<{scripts: Record<string, string>}>(workspaceRoot, 'package.json')?.scripts ?? {}
assert.equal(scripts['format:check'], 'oxfmt --check')
assert.match(scripts['check:no-test'] ?? '', /npm run format:check/u)
})

test('cargo check covers the changed crates with --fast, and their dependants with --affected', () => {
const units = [
unit('core', {kinds: ['crate'], names: ['core'], scripts: []}),
Expand Down
Loading