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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Use these instead of per-language tools; each detects the languages present and

- `scripts/doctor` — verify local toolchains, dependencies, hooks, and configuration without contacting hosted services
- `scripts/repo-settings check` — inspect GitHub-hosted security and branch settings; run explicitly, since it needs the network and administration visibility
- `scripts/check` — the full local gate: `doctor`, the script tests, lint, format, type check, test, build, the security audit, and pre-commit over every file, tracked and untracked. It prints only the Result table and always writes the full run to `tmp/check.log`; `--verbose` streams everything. It reads no hosted GitHub state but is not offline: `commitlint-test` and pre-commit's hook environments fetch on first use
- `scripts/check` — the full local gate: `doctor`, `structure` and `payload-parity`, then lint, format, type check, test, and build with the script tests beside them, the security audit, and pre-commit over every file, tracked and untracked. It prints only the Result table and always writes the full run to `tmp/check.log`; `--verbose` streams everything. It reads no hosted GitHub state but is not offline: `commitlint-test` and pre-commit's hook environments fetch on first use
- `scripts/fix` — the write half of `check`: lint autofix, then formatting, for every stack, unconditionally and in that order so the formatter lays out what the linter rewrote. Go, Swift and Kotlin have no lint autofix and report `lint-fix` `not-applicable`. A `lint-fix` FAIL means findings remain that need hand work
- `scripts/summarize <command…>` — run a check and print only its Result table with findings, then a verdict line of its exit status and a count per state, exiting with that status; read `ci` and other commands through this, since `check` already does
- `scripts/clean` — recursively delete build output and tool caches (`dist`, `build`, `coverage`, `__pycache__`, `.*_cache`, `*.pyc`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The specific operating parameters for the AI agent.

`scripts/script-tests`: Runs every `scripts/tests/*-test` concurrently, one per CPU, and prints each one's output whole once all have finished, naming every test that failed. Called by `scripts/check` and by `ci.yml`, so both run the suites the same way. The suites spend their time waiting on git and child processes, so running them side by side cuts the wall time several-fold.

`scripts/check`: The full local gate. By default it prints only the Result table and the findings under any check that failed, by running itself under `scripts/summarize`, and it writes the complete run to `tmp/check.log` every time, passing or failing, since a pre-commit fixer repairs the file and a re-run no longer reproduces the failure. `--verbose` streams the whole run live, still writing the log. Exits with the gate's status either way.
`scripts/check`: The full local gate. By default it prints only the Result table and the findings under any check that failed, by running itself under `scripts/summarize`, and it writes the complete run to `tmp/check.log` every time, passing or failing, since a pre-commit fixer repairs the file and a re-run no longer reproduces the failure. `--verbose` streams the whole run live, still writing the log. Exits with the gate's status either way. `scripts/script-tests` runs beside `scripts/ci`, since neither fills the CPUs, with its output printed once `ci` ends; the pre-commit sweep runs last, because its fixers rewrite files the other two read, and skips the hooks that repeat a step the gate already ran over the whole tree.

`scripts/summarize`: Runs a check command and prints only its Result table — one line per check, the findings under any that failed — dropping every other thing the command wrote. Exits with that command's status, so it can stand in for the command rather than only report on it, and ends with a verdict line naming that status and a count per state. `scripts/check` is its first caller; it stays the way to read `scripts/ci` and any other command. It is the one consumer of the printed layout `scripts/libs/result.sh` documents, which is where a change to the column widths has to be reflected.

Expand Down
2 changes: 1 addition & 1 deletion apps/github-repository-template/src/base-repo/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ These sections are identical in every repository built from the template. Do not

Use these instead of per-language tools. `check` and `fix` run for every language present and report `pass`, `not-applicable`, `unavailable`, or `FAIL`.

- `scripts/check` — the full local gate, a superset of CI except the pull request's changelog check: doctor, script tests, structure, lint, format, type check, test, build, security audit, pre-commit over every file. Prints only the Result table, with the full run in `tmp/check.log`; `--verbose` streams everything
- `scripts/check` — the full local gate, a superset of CI except the pull request's changelog check: doctor, structure, then lint, format, type check, test, and build with the script tests beside them, security audit, pre-commit over every file. Prints only the Result table, with the full run in `tmp/check.log`; `--verbose` streams everything
- `scripts/fix` — lint autofix, then formatting
- `scripts/summarize <command…>` — run a check and print only its Result table, then a verdict line of its exit status and a count per state; read `ci` and other commands through this, since `check` already does
- `scripts/run [unit] [--entry <name>] [-- args…]` — start a unit; the unit name is required when `apps/` holds several
Expand Down
62 changes: 50 additions & 12 deletions apps/github-repository-template/src/base-repo/scripts/check
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ fi

scripts/doctor

# Run before the checks they guard. They verify the language-capabilities
# interface, its workflow adapters, and that routine local commands stay offline.
if [[ ! -x scripts/script-tests ]]; then
echo "scripts/script-tests is missing or not executable."
exit 1
fi

scripts/script-tests

# Where a file sits, checked before what is in it. A misplaced file passes every
# language check in this repository, because each one reads the manifests and
# never asks whether the tree around them matches the rules.
Expand All @@ -73,12 +64,52 @@ fi

scripts/payload-parity </dev/null

if [[ ! -x scripts/script-tests ]]; then
echo "scripts/script-tests is missing or not executable."
exit 1
fi

if [[ ! -x scripts/ci ]]; then
echo "scripts/ci is missing or not executable."
exit 1
fi

scripts/ci
# The script tests verify the language-capabilities interface, its workflow
# adapters, and that routine local commands stay offline. They run beside ci
# rather than before it, because both spend most of their time waiting on git
# and child processes, so neither fills the CPUs and the pair takes as long as
# ci alone. Both only read the tree. pre-commit's sweep below stays after them,
# since its fixers rewrite files that ci's linters and tests read.
#
# The suites' output is held and printed whole once ci has finished, so the two
# never interleave, and both must pass. A background job in a non-interactive
# shell ignores SIGINT, so an interrupt exits the gate at once, without waiting
# for the suites, and the EXIT trap stops them rather than leaving them running.
# set -m starts the suites in a process group of their own, so one signal to the
# group reaches every suite at once, including one started mid-shutdown. Being
# their own group, a signal to the gate's group misses them: TERM still reaches
# the trap, and PIPE, from an output pipe the same signal closed, gets one too.
# A group SIGKILL runs no trap, so the suites finish on their own.
script_tests_log="$(mktemp)"
set -m
scripts/script-tests </dev/null >"$script_tests_log" 2>&1 &
script_tests_pid=$!
set +m
trap 'kill -- -"$script_tests_pid" 2>/dev/null || true; rm -f "$script_tests_log"' EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
trap 'exit 141' PIPE

ci_status=0
scripts/ci || ci_status=$?
script_tests_status=0
wait "$script_tests_pid" || script_tests_status=$?
# Reaped, so its PID may now belong to another process.
trap 'rm -f "$script_tests_log"' EXIT
trap - INT TERM PIPE
cat "$script_tests_log"
(( ci_status == 0 )) || exit "$ci_status"
(( script_tests_status == 0 )) || exit "$script_tests_status"

# The security workflow blocks a pull request the same way the CI workflow does,
# so leaving it out here means finding out on the pull request instead of before
Expand All @@ -99,10 +130,17 @@ scripts/security
# no-commit-to-branch is skipped rather than run. It reads the current branch
# instead of any file, so on main it fails this whole sweep for a commit that
# is not being made.
#
# So is every hook that repeats a step this gate already ran over the whole
# tree: structure and payload-parity above, and the template repository's
# addon-adoption and reference-assertions, which are test files its pytest run
# in ci collects. They stay on at commit time, where nothing else runs them.
# Naming a hook a repository lacks skips nothing.
skip=no-commit-to-branch,structure,payload-parity,addon-adoption,reference-assertions
if [[ -s .pre-commit-config.yaml ]]; then
echo
echo "Running pre-commit across all files"
SKIP=no-commit-to-branch pre-commit run --all-files
SKIP="$skip" pre-commit run --all-files

# --all-files means every file Git knows about, so a file written but not yet
# staged is not one of them. That is this sweep's blind spot at the moment it
Expand All @@ -120,6 +158,6 @@ if [[ -s .pre-commit-config.yaml ]]; then
if (( ${#untracked[@]} )); then
echo
echo "Running pre-commit across ${#untracked[@]} untracked file(s)"
SKIP=no-commit-to-branch pre-commit run --files "${untracked[@]}"
SKIP="$skip" pre-commit run --files "${untracked[@]}"
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ else
fail "wanted the failing step's status 7, got $status"
fi

gate_fixture "a failing script test fails the gate after ci has run"
printf '#!/usr/bin/env bash\necho "chatter from script-tests"\nexit 3\n' > "$work/scripts/script-tests"
out="$(cd "$work" && scripts/check --verbose 2>&1)"
status=$?
if (( status == 3 )) \
&& grep -q 'chatter from script-tests' <<< "$out" \
&& grep -qE '^lint +pass' <<< "$out" \
&& ! grep -q 'chatter from security' <<< "$out"; then
pass
else
fail "wanted exit 3 with both outputs and no later step, got exit $status: $out"
fi

gate_fixture "summarize still reads check" \
'echo "audit FAIL 1 violation(s)"; exit 1'
out="$(cd "$work" && scripts/summarize scripts/check 2>&1)"
Expand Down
2 changes: 1 addition & 1 deletion apps/repo-builder/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Develops the `/repo-builder` skill, which builds a repository from the payload a

A fourth claim was added that way: every path the payload ships is reached by an ownership rule, checked against this repository's `.repo-template.json` and against the canonical `apps/github-repository-template/src/ownership.json` every generate writes. It reads two ownership lists rather than the references, and it belongs here because the claim it settles is one the references make — an unmatched path is product-owned, so a payload path no rule reaches sits outside every update with nothing naming it. It asserts reachability of each list separately rather than agreement between them, because the two describe different repositories and are free to diverge: this repository's manifest is the payload's shape plus its own merges. Each is kept complete on its own, which is what makes a rule added to the payload a rule added to both. `reaches()` is a hand-copy of `preflight.py`'s `path_matches` for the two shapes the lists use, kept rather than imported for the stdlib-only reason above; it is strictly the narrower of the two, so it can only false-alarm.

Every git command `test_preflight.py` writes by hand goes through its own `git` or `git_output` helper, never `subprocess.run` direct. The helper supplies a `-c user.name`/`-c user.email` identity on every call, because a hand commit is the only kind that falls back to ambient git config and a CI runner has none — its gecos field is empty, so git fails with "empty ident name" where a developer machine silently succeeds. A new call site that bypasses the helper passes locally and fails in CI. Fixture commits are exempt: `src/evals/setup_fixture.py` carries its own `GIT_ENV`. `test_retrofit.py` imports those two helpers from `test_preflight.py` rather than holding a copy, so the rule has one home. A subcommand that commits itself, as `hooks` does in its throwaway worktree, gets the same identity through `GIT_AUTHOR_*`/`GIT_COMMITTER_*` in the environment the test runs it under, and an isolated `GIT_CONFIG_GLOBAL` so the machine's own global hooks never reach the run. `HooksTests` run the payload's real hooks and skip, naming why, where pre-commit cannot build their environments. They copy the payload over the fixture rather than building a retrofit's real layout, and set a prior `core.hooksPath` per case through that isolated config — none, global, or local — since which directory git was running decides what gets chained. The host is the one thing the suite stands in for: `stub_gh` in `test_retrofit.py` puts a `gh` first on `PATH` that replays recorded responses and logs every call, so a test asserts both what the host answered and which writes were sent.
Every git command `test_preflight.py` writes by hand goes through its own `git` or `git_output` helper, never `subprocess.run` direct. The helper supplies a `-c user.name`/`-c user.email` identity on every call, because a hand commit is the only kind that falls back to ambient git config and a CI runner has none — its gecos field is empty, so git fails with "empty ident name". `src/scripts/tests/conftest.py` points `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` at `/dev/null` for the whole pytest run, as `scripts/tests/libs/harness.sh` does for the shell suites, so a call site that bypasses the helper fails locally as it would in CI, and no commit a test makes runs the operator's global hooks. Fixture commits are exempt: `src/evals/setup_fixture.py` carries its own `GIT_ENV`. `test_retrofit.py` imports those two helpers from `test_preflight.py` rather than holding a copy, so the rule has one home. A subcommand that commits itself, as `hooks` does in its throwaway worktree, gets the same identity through `GIT_AUTHOR_*`/`GIT_COMMITTER_*` in the environment the test runs it under, and its own `GIT_CONFIG_GLOBAL` where a case needs a global config, which overrides the suite's. `HooksTests` run the payload's real hooks and skip, naming why, where pre-commit cannot build their environments. They copy the payload over the fixture rather than building a retrofit's real layout, and set a prior `core.hooksPath` per case through that isolated config — none, global, or local — since which directory git was running decides what gets chained. The host is the one thing the suite stands in for: `stub_gh` in `test_retrofit.py` puts a `gh` first on `PATH` that replays recorded responses and logs every call, so a test asserts both what the host answered and which writes were sent.

## Verification

Expand Down
15 changes: 15 additions & 0 deletions apps/repo-builder/src/scripts/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Isolates every test's git from the operator's user and system config.

The suite scaffolds throwaway repositories and commits in them, and each
commit otherwise runs whatever the operator's global config names, such as a
core.hooksPath attribution hook: a fixture then reads state from outside the
repository, and the suite spent about a sixth of its time in that hook. This is
the isolation scripts/tests/libs/harness.sh gives the shell suites, and what a
CI runner has anyway. A test that needs a global config sets GIT_CONFIG_GLOBAL
in the environment it passes, which overrides this one.
"""

import os

os.environ["GIT_CONFIG_GLOBAL"] = os.devnull
os.environ["GIT_CONFIG_SYSTEM"] = os.devnull
2 changes: 1 addition & 1 deletion scripts/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Every change here belongs in `apps/github-repository-template/src/base-repo/scri

## Verification

`scripts/check` runs every suite through `script-tests` before the checks they guard, then `structure` and `payload-parity` before `ci`. `ci.yml` runs them the same way before toolchain setup, with `pre-commit` installed first so `adr-index-test` and `commitlint-test` do not skip their hook-wiring cases. shellcheck runs via pre-commit with `-x`, skipping the payload's `scripts/`, which `payload-parity` holds identical to this tree.
`scripts/check` runs `structure` and `payload-parity`, then every suite through `script-tests` beside `ci`, holding the suites' output until `ci` ends, and its pre-commit sweep last, skipping the hooks that repeat a gate step. `ci.yml` runs the suites before toolchain setup, with `pre-commit` installed first so `adr-index-test` and `commitlint-test` do not skip their hook-wiring cases. shellcheck runs via pre-commit with `-x`, skipping the payload's `scripts/`, which `payload-parity` holds identical to this tree.

## Child Index

Expand Down
Loading