From 25813e4f57729ad162aca8e11b133f229f4d8ad3 Mon Sep 17 00:00:00 2001 From: neal Date: Wed, 18 Nov 2026 22:34:07 -0500 Subject: [PATCH 1/3] perf(scripts): run the script tests beside ci and skip repeated hooks scripts/check ran the script suites, then ci, then a pre-commit sweep that re-ran structure and payload-parity, which the gate had already run over the whole tree. The suites and ci both wait mostly on git and child processes, so running them together takes about as long as ci alone. The suites' output is held until ci ends so the two never interleave, both statuses must pass, and an interrupt exits at once and stops the suites rather than waiting on them. The pre-commit sweep now skips the hooks that repeat a gate step: structure, payload-parity, and the template's addon-adoption and reference-assertions, which ci's pytest already collects. They still run at commit time. repo-builder's pytest suite gains a conftest that points git's global and system config at /dev/null, as the shell harness already does. A global core.hooksPath attribution hook otherwise ran on every fixture commit and took about a sixth of the suite's time. Generated-By: claude-opus-5-5 --- .../docs/github_repository_structure.md | 2 +- .../src/base-repo/scripts/check | 62 +++++++++++++++---- .../src/base-repo/scripts/tests/check-test | 13 ++++ apps/repo-builder/CLAUDE.md | 2 +- .../src/scripts/tests/conftest.py | 15 +++++ scripts/CLAUDE.md | 2 +- scripts/check | 62 +++++++++++++++---- scripts/tests/check-test | 13 ++++ 8 files changed, 144 insertions(+), 27 deletions(-) create mode 100644 apps/repo-builder/src/scripts/tests/conftest.py diff --git a/apps/github-repository-template/docs/github_repository_structure.md b/apps/github-repository-template/docs/github_repository_structure.md index ebdd7f21..95d2405d 100644 --- a/apps/github-repository-template/docs/github_repository_structure.md +++ b/apps/github-repository-template/docs/github_repository_structure.md @@ -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. diff --git a/apps/github-repository-template/src/base-repo/scripts/check b/apps/github-repository-template/src/base-repo/scripts/check index 867e76c5..45c23a31 100755 --- a/apps/github-repository-template/src/base-repo/scripts/check +++ b/apps/github-repository-template/src/base-repo/scripts/check @@ -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. @@ -73,12 +64,52 @@ fi scripts/payload-parity /dev/null); do + stop_tree "$child" + done + kill "$1" 2>/dev/null || true +} + +script_tests_log="$(mktemp)" +scripts/script-tests "$script_tests_log" 2>&1 & +script_tests_pid=$! +trap 'stop_tree "$script_tests_pid"; rm -f "$script_tests_log"' EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +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 +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 @@ -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 @@ -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 diff --git a/apps/github-repository-template/src/base-repo/scripts/tests/check-test b/apps/github-repository-template/src/base-repo/scripts/tests/check-test index ff52a920..2135817d 100755 --- a/apps/github-repository-template/src/base-repo/scripts/tests/check-test +++ b/apps/github-repository-template/src/base-repo/scripts/tests/check-test @@ -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)" diff --git a/apps/repo-builder/CLAUDE.md b/apps/repo-builder/CLAUDE.md index 10c9f881..ff71b3fd 100644 --- a/apps/repo-builder/CLAUDE.md +++ b/apps/repo-builder/CLAUDE.md @@ -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 diff --git a/apps/repo-builder/src/scripts/tests/conftest.py b/apps/repo-builder/src/scripts/tests/conftest.py new file mode 100644 index 00000000..c5e7558b --- /dev/null +++ b/apps/repo-builder/src/scripts/tests/conftest.py @@ -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 diff --git a/scripts/CLAUDE.md b/scripts/CLAUDE.md index 1f78747d..b6c512ab 100644 --- a/scripts/CLAUDE.md +++ b/scripts/CLAUDE.md @@ -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 diff --git a/scripts/check b/scripts/check index 867e76c5..45c23a31 100755 --- a/scripts/check +++ b/scripts/check @@ -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. @@ -73,12 +64,52 @@ fi scripts/payload-parity /dev/null); do + stop_tree "$child" + done + kill "$1" 2>/dev/null || true +} + +script_tests_log="$(mktemp)" +scripts/script-tests "$script_tests_log" 2>&1 & +script_tests_pid=$! +trap 'stop_tree "$script_tests_pid"; rm -f "$script_tests_log"' EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +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 +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 @@ -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 @@ -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 diff --git a/scripts/tests/check-test b/scripts/tests/check-test index ff52a920..2135817d 100755 --- a/scripts/tests/check-test +++ b/scripts/tests/check-test @@ -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)" From bfd9111e575c0af4d0508c6904992be09382aa94 Mon Sep 17 00:00:00 2001 From: neal Date: Wed, 18 Nov 2026 22:41:48 -0500 Subject: [PATCH 2/3] perf(scripts): stop the background script tests as one process group Review found the recursive pgrep walk could miss a suite started between the walk and the kill, and it leaned on pgrep, which doctor does not require. set -m puts the suites in a process group of their own, so one kill reaches every member, in pure bash. The Commands contract lines in both CLAUDE.md copies still described the old order, script tests first; they now say the tests run beside ci. Generated-By: claude-opus-5-5 --- CLAUDE.md | 2 +- .../src/base-repo/CLAUDE.md | 2 +- .../src/base-repo/scripts/check | 14 +++++--------- scripts/check | 14 +++++--------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 15ab1f71..607e3904 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 ` — 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`) diff --git a/apps/github-repository-template/src/base-repo/CLAUDE.md b/apps/github-repository-template/src/base-repo/CLAUDE.md index ad89aeb6..b9ae2b5d 100644 --- a/apps/github-repository-template/src/base-repo/CLAUDE.md +++ b/apps/github-repository-template/src/base-repo/CLAUDE.md @@ -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 ` — 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 ] [-- args…]` — start a unit; the unit name is required when `apps/` holds several diff --git a/apps/github-repository-template/src/base-repo/scripts/check b/apps/github-repository-template/src/base-repo/scripts/check index 45c23a31..0cb574d6 100755 --- a/apps/github-repository-template/src/base-repo/scripts/check +++ b/apps/github-repository-template/src/base-repo/scripts/check @@ -85,18 +85,14 @@ fi # 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. -stop_tree() { - local child - for child in $(pgrep -P "$1" 2>/dev/null); do - stop_tree "$child" - done - kill "$1" 2>/dev/null || true -} - +# 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. script_tests_log="$(mktemp)" +set -m scripts/script-tests "$script_tests_log" 2>&1 & script_tests_pid=$! -trap 'stop_tree "$script_tests_pid"; rm -f "$script_tests_log"' EXIT +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 diff --git a/scripts/check b/scripts/check index 45c23a31..0cb574d6 100755 --- a/scripts/check +++ b/scripts/check @@ -85,18 +85,14 @@ fi # 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. -stop_tree() { - local child - for child in $(pgrep -P "$1" 2>/dev/null); do - stop_tree "$child" - done - kill "$1" 2>/dev/null || true -} - +# 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. script_tests_log="$(mktemp)" +set -m scripts/script-tests "$script_tests_log" 2>&1 & script_tests_pid=$! -trap 'stop_tree "$script_tests_pid"; rm -f "$script_tests_log"' EXIT +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 From fb5ef63f1d447342cf4258cc89b2ca6e8ba60f84 Mon Sep 17 00:00:00 2001 From: neal Date: Wed, 18 Nov 2026 22:52:33 -0500 Subject: [PATCH 3/3] perf(scripts): trap SIGPIPE so a group-killed gate stops its suites In their own process group, the background script tests miss a TERM sent to the gate's group, as timeout and agent harnesses send it. That signal also kills tee, so the gate's next write raised SIGPIPE, which exited without running the EXIT trap and left the suites running. Trapping PIPE routes that exit through the trap. A group SIGKILL still leaves them to finish on their own, as no trap can catch it. Generated-By: claude-opus-5-5 --- .../src/base-repo/scripts/check | 8 ++++++-- scripts/check | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/github-repository-template/src/base-repo/scripts/check b/apps/github-repository-template/src/base-repo/scripts/check index 0cb574d6..c2cb3f0a 100755 --- a/apps/github-repository-template/src/base-repo/scripts/check +++ b/apps/github-repository-template/src/base-repo/scripts/check @@ -86,7 +86,10 @@ fi # 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. +# 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 "$script_tests_log" 2>&1 & @@ -95,6 +98,7 @@ 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=$? @@ -102,7 +106,7 @@ 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 +trap - INT TERM PIPE cat "$script_tests_log" (( ci_status == 0 )) || exit "$ci_status" (( script_tests_status == 0 )) || exit "$script_tests_status" diff --git a/scripts/check b/scripts/check index 0cb574d6..c2cb3f0a 100755 --- a/scripts/check +++ b/scripts/check @@ -86,7 +86,10 @@ fi # 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. +# 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 "$script_tests_log" 2>&1 & @@ -95,6 +98,7 @@ 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=$? @@ -102,7 +106,7 @@ 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 +trap - INT TERM PIPE cat "$script_tests_log" (( ci_status == 0 )) || exit "$ci_status" (( script_tests_status == 0 )) || exit "$script_tests_status"