@soleur/opencode 3.382.6 → 3.382.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/constraint-scaffold/SKILL.md +61 -3
- package/skills/constraint-scaffold/references/fix-constraints-stage-a.emitted.sha256 +32 -0
- package/skills/constraint-scaffold/scripts/constraint-scaffold.sh +199 -7
- package/skills/constraint-scaffold/test/fixtures/stage-a.v1.0.236.emitted +240 -0
- package/skills/constraint-scaffold/test/refresh-stage-a.test.sh +465 -0
package/package.json
CHANGED
|
@@ -57,8 +57,9 @@ Generate the gate into `apps/web-platform` (default mode — detect Next.js, req
|
|
|
57
57
|
`components/` and `server/` to exist under the target, emit config + shared runner + CI workflow,
|
|
58
58
|
capture the initial baseline, **prove the gate bites** (see Bite-proof below), then write the
|
|
59
59
|
boundary README and the agent-instructions pointer last). Non-destructive: refuses to overwrite an
|
|
60
|
-
existing `.cjs`, runner, or workflow (there is no `--force`);
|
|
61
|
-
|
|
60
|
+
existing `.cjs`, runner, or workflow (there is no `--force`); only two artifacts are ever re-written:
|
|
61
|
+
the baseline JSON via `--refresh-baseline`, and the Stage A auto-recovery workflow via
|
|
62
|
+
`--refresh-stage-a` (below); the README block and the pointer line are
|
|
62
63
|
append-once (marker-keyed, never rewritten):
|
|
63
64
|
|
|
64
65
|
```bash
|
|
@@ -77,6 +78,51 @@ gate, and the fix is the listed import, not a re-run. In refresh mode nothing is
|
|
|
77
78
|
bash "${CLAUDE_PLUGIN_ROOT}/skills/constraint-scaffold/scripts/constraint-scaffold.sh" --refresh-baseline
|
|
78
79
|
```
|
|
79
80
|
|
|
81
|
+
Refresh a stale auto-recovery workflow (agent-only; never shown to the founder). Run it when a repo that
|
|
82
|
+
already installed the scaffold carries an old claude-code-action pin in its Stage A workflow, or when
|
|
83
|
+
the plugin's Stage A template changed: the default mode refuses to overwrite, so the first install's
|
|
84
|
+
pin stays. The workflow must be committed and the tree clean. `--refresh-stage-a` re-emits exactly
|
|
85
|
+
one file, `apps/web-platform/.github/workflows/fix-constraints-stage-a.yml`, and only when the installed
|
|
86
|
+
bytes are an exact historical emission listed in
|
|
87
|
+
[fix-constraints-stage-a.emitted.sha256](./references/fix-constraints-stage-a.emitted.sha256). It
|
|
88
|
+
converges the file on the **current** template, so it is a content upgrade (install command, model id,
|
|
89
|
+
token wiring) as well as a pin bump, and it normalises the file mode to 0644. The current template
|
|
90
|
+
installs with `npm ci`, so the target needs a committed `package-lock.json`. Soleur's own
|
|
91
|
+
repo-root dogfood copy is hand-maintained and is not reachable by this flag.
|
|
92
|
+
|
|
93
|
+
Outcomes and the next step:
|
|
94
|
+
|
|
95
|
+
| Exit | Meaning | Next step |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| 0 | `already current`, or `refreshed` | after `refreshed`: review with `git diff` and commit |
|
|
98
|
+
| 67 | workflow untracked, or tree dirty | commit the workflow / the other changes, re-run |
|
|
99
|
+
| 69 | run lock held | wait and re-run (a lock whose owner died clears on the next run; a lock with no owner pid yet is honoured for a minute) |
|
|
100
|
+
| 69 | no sha256 tool, a repository under `/proc`, `/sys` or `/dev`, or an I/O failure (mktemp, render, chmod, mv) | fix the tool or location; a re-run alone does not help |
|
|
101
|
+
| 70 | no `.dependency-cruiser.cjs`, or no stage-a workflow | restore the file from git; installs that predate the two-stage split have no Stage A file |
|
|
102
|
+
| 75 | refused, file left byte-unchanged | see below |
|
|
103
|
+
| 143 | interrupted | review `git diff`; the file is replaced only by a final atomic rename |
|
|
104
|
+
|
|
105
|
+
Exit **75** means: the installed copy is edited or from a version the ledger does not know (the report
|
|
106
|
+
shows only the template-side differences, never your file: read your own file and merge by hand; after
|
|
107
|
+
a hand merge the flag keeps refusing, because the file is no longer a known emission), is newer than
|
|
108
|
+
this plugin's template (update the plugin; there is no downgrade), is a symlink or behind one (replace
|
|
109
|
+
it with a regular file by hand), has no tracked `package-lock.json` beside it (commit one, or merge by
|
|
110
|
+
hand; checked only when a write would happen, so an already-current file still exits 0), or changed
|
|
111
|
+
while the command ran (re-run). There is no bite-proof: the swap changes none of
|
|
112
|
+
config, runner or baseline. If the run is SIGKILLed, delete the leftover untracked
|
|
113
|
+
`.fix-constraints-stage-a.*` file next to the workflow (never `git add -A`):
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
bash "${CLAUDE_PLUGIN_ROOT}/skills/constraint-scaffold/scripts/constraint-scaffold.sh" --refresh-stage-a
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Authors of a Stage A template change:** when [fix-constraints-stage-a.template](./references/fix-constraints-stage-a.template) changes,
|
|
120
|
+
the ledger must gain a row (the regeneration command is in the ledger header), but only if the change
|
|
121
|
+
keeps the frozen Stage A to Stage B interface (workflow name, artifact-name prefixes, `meta.json`
|
|
122
|
+
schema) and the `contents: read` permission set (ADR-071 amendment 2026-11-05). The template is never
|
|
123
|
+
edited for this: any template edit changes its own emission hash, and a test case reddens until the row
|
|
124
|
+
is appended.
|
|
125
|
+
|
|
80
126
|
## What it emits (into `apps/web-platform/`)
|
|
81
127
|
|
|
82
128
|
| Artifact | Role |
|
|
@@ -123,10 +169,14 @@ that it ran green once:
|
|
|
123
169
|
7. The helper removes the worktree (also on INT/TERM — the handler exits 143 with the worktree gone).
|
|
124
170
|
One verdict line on stdout: `constraint-scaffold: bite-proof pass -> fail(no-client-to-server-secret@direct, no-client-to-server-secret-transitive@via-hop) -> pass depcruise=<version>`.
|
|
125
171
|
|
|
172
|
+
**Exit code 75** is `--refresh-stage-a` only: it removes nothing and leaves the workflow byte-unchanged
|
|
173
|
+
(see the refresh block above).
|
|
174
|
+
|
|
126
175
|
**Exit codes 71–74 and what the agent does next.** Every bite failure prints
|
|
127
176
|
`constraint-scaffold: bite-proof FAILED (<code>): <msg>` and the last 40 lines of the relevant log
|
|
128
177
|
on stdout. In **default mode** the self-cleanup is armed before the first artifact is written and
|
|
129
|
-
disarmed only after the bite has passed, so this holds for every failure in between — 66..74
|
|
178
|
+
disarmed only after the bite has passed, so this holds for every failure in between — 66..74 (75 is
|
|
179
|
+
stage-a-mode only, removes nothing, and leaves the file byte-unchanged), an
|
|
130
180
|
unusable `TMPDIR`, a `set -e` abort, an INT/TERM (143), a runner interrupted by a terminal Ctrl-C
|
|
131
181
|
(130): the script removes every artifact this run emitted (config, runner, the three workflows, the
|
|
132
182
|
baseline; empty `scripts/` and `.github/workflows/` directories are removed too) and says so — the
|
|
@@ -162,6 +212,14 @@ dependency-cruiser; every 71/72/73/74 arm through the stub; both rule names asse
|
|
|
162
212
|
probe files; worktree removal on success, on failure and on TERM; default-mode self-cleanup leaving
|
|
163
213
|
the fixture tree as it was; and the `TMPDIR`-inside-repo refusal.
|
|
164
214
|
|
|
215
|
+
`test/refresh-stage-a.test.sh` (scripts shard) pins `--refresh-stage-a`: refresh of a ledger-listed
|
|
216
|
+
emission (mode 0644), the already-current no-op, refusal of an edited or newline-stripped copy with no
|
|
217
|
+
echo of the user's file, the guard order (70 before 67 before 69; symlink before tree; lockfile only when a write would happen), the no-downgrade
|
|
218
|
+
rule, fail-closed on a missing, empty or comment-only ledger, the ledger itself (newest row last, unique,
|
|
219
|
+
64-hex), the empty-digest arm, symlinked file / `.github` / `apps`, the `package-lock.json` precondition,
|
|
220
|
+
the run-lock rows (owner-less grace, dead owner, EPERM), that no other emitted file is written, that
|
|
221
|
+
neither the script nor the ledger carries a pin literal, and the frozen Stage A to Stage B interface.
|
|
222
|
+
|
|
165
223
|
`test/boundary.test.sh` (scripts shard) proves the gate is not vacuous: a value import of `server/**`
|
|
166
224
|
via the `@/server/…` alias FAILS, an `import type` of the same PASSES, route-group/metacharacter
|
|
167
225
|
paths are matched (regex-escaping), an empty from-set while `"use client"` files exist is a hard
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Emission ledger for fix-constraints-stage-a.template (consumed by `constraint-scaffold.sh --refresh-stage-a`).
|
|
2
|
+
#
|
|
3
|
+
# Each data row is the sha256 of one historical, substituted emission of the Stage A template
|
|
4
|
+
# (the template with __TARGET_DIR__ replaced by apps/web-platform). Only the first
|
|
5
|
+
# whitespace-separated field is read; the rest is a human note. Comment and blank lines are ignored.
|
|
6
|
+
#
|
|
7
|
+
# ORDER IS THE SEQUENCE. Rows are appended chronologically, newest last, and are never reordered
|
|
8
|
+
# or removed: the line position of a row is its rank, and the refresh refuses to move an installed
|
|
9
|
+
# file to an OLDER template (no downgrade). A row certifies only that Soleur emitted these bytes
|
|
10
|
+
# once. A refresh converges the file on the CURRENT template, so it is a content upgrade (install
|
|
11
|
+
# command, model id, token wiring), not only a pin bump.
|
|
12
|
+
# Rows 1-2 installed with `bun install`; the refresh needs `package-lock.json` in the target (the
|
|
13
|
+
# current template runs `npm ci`) and refuses (75) without it.
|
|
14
|
+
#
|
|
15
|
+
# Append a row ONLY when fix-constraints-stage-a.template changes AND the new template keeps the
|
|
16
|
+
# frozen Stage A to Stage B interface and the `contents: read` permission set (ADR-071 amendment
|
|
17
|
+
# 2026-11-05). test/refresh-stage-a.test.sh (case 7a) reddens unless the LAST data row is the
|
|
18
|
+
# current template's emission, every row is a unique 64-hex digest, and the file was not reordered.
|
|
19
|
+
#
|
|
20
|
+
# Regenerate or re-derive any row from git history (run from the repository root):
|
|
21
|
+
# T=plugins/soleur/skills/constraint-scaffold/references/fix-constraints-stage-a.template
|
|
22
|
+
# for c in $(git log --reverse --format=%h -- "$T"); do
|
|
23
|
+
# git show "$c:$T" | sed 's|__TARGET_DIR__|apps/web-platform|g' | sha256sum
|
|
24
|
+
# done
|
|
25
|
+
# For an uncommitted template edit, the row to append is:
|
|
26
|
+
# sed 's|__TARGET_DIR__|apps/web-platform|g' "$T" | sha256sum
|
|
27
|
+
b8187a33c668e44a00cff048117d2ed1b6d568b90b5c10b28f21bb5e46d99386 2026-07-01 initial two-stage emission (bun install --frozen-lockfile, model sonnet-4-6)
|
|
28
|
+
889e8a08481de2af5909b59043f8df0a59207374aa30f35deca3676a0fe536bc 2026-07-01 model moved to sonnet-5
|
|
29
|
+
e68d1cc2ce56c3e60c6ed939172ef19d83bcb85a606ae8442934898e873941e3 2026-08-16 install step moved to npm ci --ignore-scripts
|
|
30
|
+
5130360de005d5534dfab73ad5fb1af8dd8a196c72e97eb1eb08d17ceb7facbe 2026-09-30 model moved to claude-sonnet-5-5
|
|
31
|
+
45fdc5c5e0060d8ced95d64688061dc567beba1329a9323b6b6a7817ecdd2895 2026-10-05 adds the github_token input (needed for OIDC) and moves the action pin forward
|
|
32
|
+
58377282013228a6bd5bbf1a9d647ee2710622711efa58710999b3c46585a1da 2026-11-05 moves the action pin to the Bun 1.4.4 pair
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
# origin/main merge-base (so a same-PR violation is NOT
|
|
18
18
|
# grandfathered), then bite-proof. Never writes README/pointer.
|
|
19
19
|
# Agent-only; never shown to the founder.
|
|
20
|
+
# --refresh-stage-a re-emit ONE file, the Stage A auto-recovery workflow
|
|
21
|
+
# (fix-constraints-stage-a.yml), when the installed copy is byte-identical
|
|
22
|
+
# to a historical emission listed in
|
|
23
|
+
# references/fix-constraints-stage-a.emitted.sha256. Anything else (edited,
|
|
24
|
+
# unknown version, newer than this plugin's template) is refused with 75
|
|
25
|
+
# and left untouched. Needs a committed workflow and a clean tree. No
|
|
26
|
+
# bite-proof: the swap changes none of config, runner or baseline. ADR-071
|
|
27
|
+
# amendment 2026-11-05. Agent-only; never shown to the founder.
|
|
20
28
|
#
|
|
21
29
|
# Base ref: origin/main when it exists, else the remote's default branch (origin/HEAD, e.g. a
|
|
22
30
|
# founder repo on master). Neither present -> 69 BEFORE anything is written.
|
|
@@ -31,12 +39,27 @@
|
|
|
31
39
|
# 67 dirty working tree (baseline capture requires a clean tree)
|
|
32
40
|
# 68 dependency-cruiser binary missing, or baseline capture failed
|
|
33
41
|
# 69 git/base-ref/worktree/temp-dir error, TMPDIR resolves inside the repository, or another
|
|
34
|
-
# scaffold run holds the run lock (<git-common-dir>/constraint-scaffold.lock, owner pid inside
|
|
35
|
-
#
|
|
42
|
+
# scaffold run holds the run lock (<git-common-dir>/constraint-scaffold.lock, owner pid inside;
|
|
43
|
+
# a live owner, or a lock younger than a minute that has no owner pid yet, is held). In
|
|
44
|
+
# --refresh-stage-a also: no sha256 tool, a repository under /proc, /sys or /dev, a failed
|
|
45
|
+
# mktemp/render/chmod/mv, or a digest that is not 64 hex.
|
|
46
|
+
# 70 --refresh-baseline / --refresh-stage-a before generation (no .dependency-cruiser.cjs yet, or
|
|
47
|
+
# no fix-constraints-stage-a.yml to refresh — run default mode first)
|
|
36
48
|
# 71 bite-proof: gate did not pass on the clean HEAD tree before the probe (config/toolchain)
|
|
37
49
|
# 72 bite-proof: gate did NOT reject the injected client->server-secret imports on their edges
|
|
38
50
|
# 73 bite-proof: gate did not return to green after the probes were removed
|
|
39
51
|
# 74 bite-proof: real client->server-secret violation(s) on HEAD newer than the baseline
|
|
52
|
+
# 75 --refresh-stage-a refused, file left byte-unchanged (merge by hand, update the plugin, or fix
|
|
53
|
+
# the named precondition and re-run): the installed workflow is not a known
|
|
54
|
+
# pristine emission (edited, or a version the ledger does not know), is NEWER than this
|
|
55
|
+
# plugin's template (update the plugin; never downgrade), is a symlink or sits behind one,
|
|
56
|
+
# the target has no tracked package-lock.json (the current template installs with `npm ci`), this
|
|
57
|
+
# plugin's ledger lacks its own template's emission, or the file changed during the run.
|
|
58
|
+
#
|
|
59
|
+
# (--refresh-stage-a has its own, smaller window: it removes only its own temp file
|
|
60
|
+
# `.fix-constraints-stage-a.XXXXXX` and its run lock, via the same trap. Only a SIGKILL leaves
|
|
61
|
+
# either behind; the recovery is to delete the untracked temp file, never `git add -A`; a stale
|
|
62
|
+
# lock clears itself on the next run.)
|
|
40
63
|
#
|
|
41
64
|
# In default mode the self-cleanup is armed BEFORE the first artifact is written and disarmed
|
|
42
65
|
# only after the bite has passed: every failure in between (67..74, a failed `mktemp`, a
|
|
@@ -78,6 +101,18 @@ esac
|
|
|
78
101
|
physdir() { ( cd -- "$1" 2>/dev/null && pwd -P ); }
|
|
79
102
|
# physpath <path>: physical path of a file that may not exist yet, via its (existing) parent.
|
|
80
103
|
physpath() { local d; d="$(physdir "$(dirname -- "$1")")" || return 1; [[ -n "$d" ]] && printf '%s/%s' "$d" "$(basename -- "$1")"; }
|
|
104
|
+
# assert_fixture_dir: the CANONICAL copy (byte-for-byte; fixture-dir-operand-assert.test.sh pins every copy). It refuses an
|
|
105
|
+
# empty, relative, `..`-bearing or filesystem-root operand; the stage-a refresh calls it before each write.
|
|
106
|
+
assert_fixture_dir() {
|
|
107
|
+
case "${1-}" in
|
|
108
|
+
"") printf 'FATAL: fixture dir is EMPTY; git -C "" would operate on %s\n' "$PWD" >&2; exit 2 ;;
|
|
109
|
+
*/../*|*/..) printf 'FATAL: fixture dir %s contains ..; refusing\n' "$1" >&2; exit 2 ;;
|
|
110
|
+
/proc/*|/sys/*|/dev/*) printf 'FATAL: fixture dir %s is a synthetic-fs path; refusing\n' "$1" >&2; exit 2 ;;
|
|
111
|
+
/|//|/.) printf 'FATAL: fixture dir resolves to the filesystem root; refusing\n' >&2; exit 2 ;;
|
|
112
|
+
/*) : ;;
|
|
113
|
+
*) printf 'FATAL: fixture dir %s is RELATIVE; refusing\n' "$1" >&2; exit 2 ;;
|
|
114
|
+
esac
|
|
115
|
+
}
|
|
81
116
|
# Canonical form once (a trailing slash would defeat every `${f#"$REPO_ROOT"/}` display and the
|
|
82
117
|
# TMPDIR containment case below), re-guarded: the value now comes from a command substitution.
|
|
83
118
|
REPO_ROOT="$(physdir "$REPO_ROOT")"
|
|
@@ -128,7 +163,8 @@ MODE="default"
|
|
|
128
163
|
case "${1:-}" in
|
|
129
164
|
"") MODE="default" ;;
|
|
130
165
|
--refresh-baseline) MODE="refresh" ;;
|
|
131
|
-
|
|
166
|
+
--refresh-stage-a) MODE="stage-a" ;;
|
|
167
|
+
*) die "unknown argument: $1 (expected none, --refresh-baseline or --refresh-stage-a)" 64 ;;
|
|
132
168
|
esac
|
|
133
169
|
|
|
134
170
|
# --- Precondition: target is a Next.js app -----------------------------------
|
|
@@ -166,12 +202,18 @@ remove_emitted_artifacts() {
|
|
|
166
202
|
# both signals because the distinction buys nothing here). Both the baseline capture and the
|
|
167
203
|
# bite-proof are callers, so there is exactly one trap owner and no ordering hazard.
|
|
168
204
|
WT=""
|
|
205
|
+
# The Stage A refresh's temp file (initialised here so an early `die` under `set -u` cannot trip an
|
|
206
|
+
# unbound variable inside the EXIT trap and replace the intended exit code).
|
|
207
|
+
STAGE_A_TMP=""
|
|
169
208
|
# _wt_cleanup [interrupted]: the ONE trap handler. Removes the worktree if one is open and, in
|
|
170
209
|
# default mode, every artifact this run emitted. The word "interrupted" is printed only when a
|
|
171
210
|
# signal arrived; a failed step says "run aborted".
|
|
172
211
|
_wt_cleanup() {
|
|
173
212
|
local why="${1:-run aborted}"
|
|
174
213
|
release_run_lock
|
|
214
|
+
if [[ -n "${STAGE_A_TMP:-}" ]]; then
|
|
215
|
+
rm -f -- "$STAGE_A_TMP"
|
|
216
|
+
fi
|
|
175
217
|
if [[ -n "${WT:-}" ]]; then
|
|
176
218
|
git -C "$REPO_ROOT" worktree remove --force "$WT" >/dev/null 2>&1 || true
|
|
177
219
|
rm -rf -- "$WT"
|
|
@@ -181,6 +223,8 @@ _wt_cleanup() {
|
|
|
181
223
|
local removed
|
|
182
224
|
removed="$(remove_emitted_artifacts)"
|
|
183
225
|
[[ -n "$removed" ]] && say "$why; removed: $removed"
|
|
226
|
+
elif [[ "$why" == "interrupted" && "$MODE" == "stage-a" ]]; then
|
|
227
|
+
say "interrupted (stage-a refresh): the workflow is replaced only by the final atomic rename; review it with \`git diff\` before deciding"
|
|
184
228
|
elif [[ "$why" == "interrupted" ]]; then
|
|
185
229
|
say "interrupted (refresh mode): nothing removed; the committed baseline may already have been rewritten — review it with \`git diff\` before deciding"
|
|
186
230
|
fi
|
|
@@ -189,7 +233,9 @@ _wt_cleanup() {
|
|
|
189
233
|
# Run lock: two scaffold runs in one repo (a default run and a --refresh-baseline, or two
|
|
190
234
|
# sessions) would each `mv` into the same baseline and one run's cleanup would delete the other's
|
|
191
235
|
# staged inputs mid-bite. One `mkdir` lock in the git common dir, holding the owner pid; a stale
|
|
192
|
-
# lock (owner gone) is taken over, a live one is a 69 with the pid named
|
|
236
|
+
# lock (owner gone) is taken over, a live one is a 69 with the pid named, and so is a lock with no
|
|
237
|
+
# owner pid yet that is under a minute old (a run between its mkdir and its pid write). Released by
|
|
238
|
+
# the handler.
|
|
193
239
|
RUN_LOCK=""
|
|
194
240
|
take_run_lock() {
|
|
195
241
|
local common
|
|
@@ -199,12 +245,19 @@ take_run_lock() {
|
|
|
199
245
|
if ! mkdir "$RUN_LOCK" 2>/dev/null; then
|
|
200
246
|
local owner
|
|
201
247
|
owner="$(cat "$RUN_LOCK/pid" 2>/dev/null || true)"
|
|
202
|
-
|
|
248
|
+
# `kill -0` fails with EPERM for a live process owned by another user, so "gone" needs `ps -p` too.
|
|
249
|
+
if [[ -n "$owner" ]] && { kill -0 "$owner" 2>/dev/null || ps -p "$owner" >/dev/null 2>&1; }; then
|
|
203
250
|
RUN_LOCK=""
|
|
204
251
|
fail_stdout 69 "another constraint-scaffold run (pid $owner) is in progress in this repository; wait for it"
|
|
205
252
|
fi
|
|
253
|
+
# A lock directory with no owner yet is a run caught between its `mkdir` and its pid write, not a
|
|
254
|
+
# stale lock: honour it while the directory is under a minute old (`find -mmin` exists on GNU and BSD).
|
|
255
|
+
if [[ -z "$owner" && -n "$(find "$RUN_LOCK" -prune -mmin -1 -print 2>/dev/null || true)" ]]; then
|
|
256
|
+
RUN_LOCK=""
|
|
257
|
+
fail_stdout 69 "another constraint-scaffold run is starting in this repository (the run lock has no owner pid yet); wait a moment and re-run"
|
|
258
|
+
fi
|
|
206
259
|
rm -rf -- "$RUN_LOCK"
|
|
207
|
-
mkdir "$RUN_LOCK" 2>/dev/null || { RUN_LOCK=""; fail_stdout 69 "cannot take the run lock at $
|
|
260
|
+
mkdir "$RUN_LOCK" 2>/dev/null || { local lockpath="$RUN_LOCK"; RUN_LOCK=""; fail_stdout 69 "cannot take the run lock at $lockpath"; }
|
|
208
261
|
fi
|
|
209
262
|
printf '%s\n' "$$" > "$RUN_LOCK/pid"
|
|
210
263
|
}
|
|
@@ -500,6 +553,145 @@ emit_pointer() {
|
|
|
500
553
|
fi
|
|
501
554
|
}
|
|
502
555
|
|
|
556
|
+
# --- --refresh-stage-a ------------------------------------------------------------------------
|
|
557
|
+
# Re-emit ONE file, the Stage A workflow, over an installed copy that is byte-identical to a
|
|
558
|
+
# historical emission. The clobber control is a sha256 LEDGER of every historical substituted
|
|
559
|
+
# emission (references/fix-constraints-stage-a.emitted.sha256, rows in chronological order, newest
|
|
560
|
+
# last); the tree guard only makes the result reviewable. The pin is read from the template at run
|
|
561
|
+
# time, so this script carries no action pin of its own (claude-pin-lockstep.test.ts stays whole).
|
|
562
|
+
STAGE_A_TEMPLATE="$REF_DIR/fix-constraints-stage-a.template"
|
|
563
|
+
STAGE_A_LEDGER="$REF_DIR/fix-constraints-stage-a.emitted.sha256"
|
|
564
|
+
|
|
565
|
+
# sha256_hex <file>: the bare 64-hex digest on stdout, or nothing when the tool printed none. Never
|
|
566
|
+
# dies (it runs inside command substitutions); the caller validates the shape.
|
|
567
|
+
sha256_hex() {
|
|
568
|
+
local out=""
|
|
569
|
+
if command -v sha256sum >/dev/null 2>&1; then
|
|
570
|
+
out="$(sha256sum "$1" 2>/dev/null || true)"
|
|
571
|
+
elif command -v shasum >/dev/null 2>&1; then
|
|
572
|
+
out="$(shasum -a 256 "$1" 2>/dev/null || true)"
|
|
573
|
+
fi
|
|
574
|
+
printf '%s' "${out%% *}"
|
|
575
|
+
}
|
|
576
|
+
is_sha256() { [[ "$1" =~ ^[0-9a-f]{64}$ ]]; }
|
|
577
|
+
|
|
578
|
+
# ledger_rank <sha>: the 1-based rank of the row among the ledger's data rows, or nothing. Exact
|
|
579
|
+
# equality on the FIRST field only (a substring or prefix match would admit a different hash), so a
|
|
580
|
+
# missing, empty or comment-only ledger matches nothing. Always returns 0: the caller tests the OUTPUT.
|
|
581
|
+
ledger_rank() {
|
|
582
|
+
[[ -f "$STAGE_A_LEDGER" ]] || return 0
|
|
583
|
+
awk -v h="$1" '/^[[:space:]]*#/ || !NF {next} {n++} ($1 "") == (h "") {print n; exit}' "$STAGE_A_LEDGER" || true
|
|
584
|
+
return 0
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
# stage_a_report: the template-side lines only, bounded in width and count. The user's own file is
|
|
588
|
+
# NEVER printed (a secret pasted into an edited workflow must not reach an agent transcript); the
|
|
589
|
+
# agent reads its own file when it merges by hand. Wrapped so SIGPIPE from `head` cannot abort.
|
|
590
|
+
stage_a_report() {
|
|
591
|
+
{ diff -- "$FIXWORKFLOW_A" "$STAGE_A_TMP" | grep -v '^< ' | cut -c1-200 | head -60 || true; }
|
|
592
|
+
return 0
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
refresh_stage_a() {
|
|
596
|
+
local dest="$FIXWORKFLOW_A" dest_dir want_dir want have want_rank have_rank now
|
|
597
|
+
# 1. Existence first, before every check that can fail for another reason or write a lock. A
|
|
598
|
+
# dangling symlink is not a file, so it is also 70.
|
|
599
|
+
[[ -f "$CFG" ]] || die "no .dependency-cruiser.cjs at $TARGET_REL — run the default mode first to generate the gate" 70
|
|
600
|
+
[[ -f "$dest" ]] || die "no fix-constraints-stage-a.yml at $TARGET_REL/.github/workflows to refresh — restore it from git if it was deleted (git checkout -- <path>); an install that predates the two-stage split has no Stage A file and is not covered by this flag" 70
|
|
601
|
+
if ! command -v sha256sum >/dev/null 2>&1 && ! command -v shasum >/dev/null 2>&1; then
|
|
602
|
+
die "no sha256 tool (sha256sum or shasum) on PATH" 69
|
|
603
|
+
fi
|
|
604
|
+
# 2. Path safety. A symlinked FILE is refused; so is any destination whose PHYSICAL directory is
|
|
605
|
+
# not exactly <target>/.github/workflows (a symlinked .github passes a repo-containment check
|
|
606
|
+
# and would redirect the write). The expected directory is built from the physical REPO_ROOT
|
|
607
|
+
# and the literal target, not resolved from TARGET, so a symlinked apps/ or apps/web-platform/
|
|
608
|
+
# cannot satisfy it. After the check `dest` is rebound to its physical form, so the recheck and
|
|
609
|
+
# the mv use the same directory the check approved.
|
|
610
|
+
if [[ -L "$dest" ]]; then
|
|
611
|
+
die "fix-constraints-stage-a.yml is a symlink; refusing to refresh through it (left unchanged)" 75
|
|
612
|
+
fi
|
|
613
|
+
dest_dir="$(physdir "$(dirname -- "$dest")")" || dest_dir=""
|
|
614
|
+
want_dir="$REPO_ROOT/$TARGET_REL/.github/workflows"
|
|
615
|
+
case "$dest_dir" in
|
|
616
|
+
/proc/*|/sys/*|/dev/*) die "the repository sits under a synthetic filesystem ($dest_dir); refusing (left unchanged)" 69 ;;
|
|
617
|
+
esac
|
|
618
|
+
if [[ -z "$dest_dir" || "$dest_dir" != "$want_dir" ]]; then
|
|
619
|
+
die "the physical directory of fix-constraints-stage-a.yml (${dest_dir:-unresolvable}) is not $TARGET_REL/.github/workflows; refusing to write through a redirected directory (left unchanged)" 75
|
|
620
|
+
fi
|
|
621
|
+
dest="$dest_dir/${dest##*/}"
|
|
622
|
+
|
|
623
|
+
# 3. Reviewable: tracked and clean. The hash gate below, not this, is the clobber control.
|
|
624
|
+
if ! git -C "$REPO_ROOT" ls-files --error-unmatch -- "${dest#"$REPO_ROOT"/}" >/dev/null 2>&1; then
|
|
625
|
+
die "fix-constraints-stage-a.yml is not tracked by git — commit the workflow first so the refresh is reviewable with git diff" 67
|
|
626
|
+
fi
|
|
627
|
+
require_clean_tree "before refreshing the stage-a workflow"
|
|
628
|
+
# 4. Arm the single trap owner, THEN take the lock (a failed take never removes another run's lock).
|
|
629
|
+
trap '_wt_cleanup' EXIT
|
|
630
|
+
trap '_wt_cleanup interrupted; trap - EXIT; exit 143' INT TERM
|
|
631
|
+
take_run_lock
|
|
632
|
+
# 5. Fresh emission to a temp file next to the destination (same filesystem: atomic rename).
|
|
633
|
+
STAGE_A_TMP="$(mktemp "$dest_dir/.fix-constraints-stage-a.XXXXXX")" || die "cannot create a temp file next to fix-constraints-stage-a.yml" 69
|
|
634
|
+
# assert_fixture_dir is called at each write operand because the repo-wide fixture-relative
|
|
635
|
+
# ratchet counts an unproven operand; both operands are already physical absolute paths here.
|
|
636
|
+
assert_fixture_dir "$STAGE_A_TMP"
|
|
637
|
+
sed "s|__TARGET_DIR__|$TARGET_REL|g" "$STAGE_A_TEMPLATE" > "$STAGE_A_TMP" || die "cannot render the stage-a template" 69
|
|
638
|
+
want="$(sha256_hex "$STAGE_A_TMP")"
|
|
639
|
+
have="$(sha256_hex "$dest")"
|
|
640
|
+
# An empty or malformed digest must never reach classification: with both digests empty,
|
|
641
|
+
# `have == want` below would print "already current" over a tool that measured nothing.
|
|
642
|
+
if ! is_sha256 "$want" || ! is_sha256 "$have"; then
|
|
643
|
+
die "could not compute a sha256 for the stage-a workflow (the hash tool printed no digest); left unchanged" 69
|
|
644
|
+
fi
|
|
645
|
+
# 6. Already current: the one outcome that never consults the ledger, and writes nothing.
|
|
646
|
+
if [[ "$have" == "$want" ]]; then
|
|
647
|
+
say "fix-constraints-stage-a.yml already current; nothing to do"
|
|
648
|
+
exit 0
|
|
649
|
+
fi
|
|
650
|
+
# 7. Classify against the ledger.
|
|
651
|
+
want_rank="$(ledger_rank "$want")"
|
|
652
|
+
have_rank="$(ledger_rank "$have")"
|
|
653
|
+
if [[ -z "$want_rank" ]]; then
|
|
654
|
+
die "this plugin's ledger (references/fix-constraints-stage-a.emitted.sha256) is missing, empty or lacks its own template's emission; update the plugin. Left unchanged" 75
|
|
655
|
+
fi
|
|
656
|
+
if [[ -z "$have_rank" ]]; then
|
|
657
|
+
say "FAILED (75): fix-constraints-stage-a.yml differs from every known emission (edited, or a version this ledger does not know); left unchanged"
|
|
658
|
+
say "template-side differences follow (your file is not printed; read it yourself and merge by hand; limited to 60 lines):"
|
|
659
|
+
stage_a_report
|
|
660
|
+
say "full target: references/fix-constraints-stage-a.template with __TARGET_DIR__ replaced by $TARGET_REL. After a hand merge this flag keeps refusing: the file is no longer a known emission"
|
|
661
|
+
log "fix-constraints-stage-a.yml is not a known pristine emission; left unchanged"
|
|
662
|
+
exit 75
|
|
663
|
+
fi
|
|
664
|
+
if [[ "$have_rank" -gt "$want_rank" ]]; then
|
|
665
|
+
die "the installed fix-constraints-stage-a.yml is newer than this plugin's template (ledger row $have_rank of $want_rank); update the plugin, do not downgrade. Left unchanged" 75
|
|
666
|
+
fi
|
|
667
|
+
# The current template installs with `npm ci` in the target; a repo whose gate predates that (the
|
|
668
|
+
# earliest emissions installed with bun) may have no package-lock.json, and the refreshed job
|
|
669
|
+
# would then fail at its install step on the first PR that needs recovery. Checked only when a
|
|
670
|
+
# write is about to happen (an already-current file exited above), and the lockfile must be
|
|
671
|
+
# tracked: an untracked or gitignored one is absent on a clean CI clone.
|
|
672
|
+
if [[ ! -f "$TARGET/package-lock.json" ]] \
|
|
673
|
+
|| ! git -C "$REPO_ROOT" ls-files --error-unmatch -- "$TARGET_REL/package-lock.json" >/dev/null 2>&1; then
|
|
674
|
+
die "$TARGET_REL/package-lock.json is missing or not tracked by git and the current stage-a template installs with \`npm ci\`; commit a lockfile there, or merge the template into your workflow by hand (left unchanged)" 75
|
|
675
|
+
fi
|
|
676
|
+
# 8. Pre-write recheck (narrows the window; the residual is a microsecond-wide race with an editor.
|
|
677
|
+
# The committed copy stays recoverable with `git checkout -- <file>`; an edit saved inside that
|
|
678
|
+
# window and not yet committed would be lost), then the one write.
|
|
679
|
+
now="$(sha256_hex "$dest")"
|
|
680
|
+
if [[ ! -f "$dest" || -d "$dest" || -L "$dest" || "$now" != "$have" ]]; then
|
|
681
|
+
die "fix-constraints-stage-a.yml changed during the run; left unchanged — re-run" 75
|
|
682
|
+
fi
|
|
683
|
+
chmod 0644 "$STAGE_A_TMP" || die "cannot set the mode on the refreshed workflow (left unchanged)" 69
|
|
684
|
+
assert_fixture_dir "$dest"
|
|
685
|
+
mv -f -- "$STAGE_A_TMP" "$dest" || die "could not replace fix-constraints-stage-a.yml (the original is intact)" 69
|
|
686
|
+
STAGE_A_TMP=""
|
|
687
|
+
say "refreshed fix-constraints-stage-a.yml (ledger row $have_rank -> $want_rank); review the change with \`git diff\` and commit it"
|
|
688
|
+
exit 0
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
if [[ "$MODE" == "stage-a" ]]; then
|
|
692
|
+
refresh_stage_a
|
|
693
|
+
fi
|
|
694
|
+
|
|
503
695
|
if [[ "$MODE" == "refresh" ]]; then
|
|
504
696
|
[[ -f "$CFG" ]] || die "no .dependency-cruiser.cjs at $TARGET_REL — run the default mode first to generate the gate" 70
|
|
505
697
|
require_clean_tree "before capturing the baseline"
|
|
@@ -525,7 +717,7 @@ fi
|
|
|
525
717
|
require_clean_tree "before generating the gate"
|
|
526
718
|
|
|
527
719
|
for f in "$CFG" "$RUNNER" "$WORKFLOW" "$FIXWORKFLOW_A" "$FIXWORKFLOW_B"; do
|
|
528
|
-
[[ -e "$f" ]] && die "refuse-if-exists: ${f#"$REPO_ROOT"/} already present (no --force). Committed gate: re-baseline via --refresh-baseline. Untracked leftovers of a killed first install: delete them (\`git clean -n $TARGET_REL\` lists them), run \`git worktree prune\`, re-run" 66
|
|
720
|
+
[[ -e "$f" ]] && die "refuse-if-exists: ${f#"$REPO_ROOT"/} already present (no --force). Committed gate: re-baseline via --refresh-baseline; a committed, stale fix-constraints-stage-a.yml: --refresh-stage-a. Untracked leftovers of a killed first install: delete them (\`git clean -n $TARGET_REL\` lists them), run \`git worktree prune\`, re-run" 66
|
|
529
721
|
done
|
|
530
722
|
[[ -e "$BASELINE" ]] && die "refuse-if-exists: ${BASELINE#"$REPO_ROOT"/} already present (re-baseline via --refresh-baseline)" 66
|
|
531
723
|
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
name: fix-constraints-stage-a
|
|
2
|
+
|
|
3
|
+
# Stage A — UNTRUSTED producer of the two-stage constraint-gate recovery (ADR-074, #5814).
|
|
4
|
+
# GENERATED by `plugins/soleur/skills/constraint-scaffold` into apps/web-platform's CI. The agent
|
|
5
|
+
# — never the founder — owns this file and gate maintenance. Runs on `pull_request` — NOT the
|
|
6
|
+
# privileged issue_comment / pull-request-target trigger — holds NO write token, and treats
|
|
7
|
+
# running PR-head code as
|
|
8
|
+
# the EXPECTED, safe thing (`pull_request` is CodeQL's designated untrusted context). If the
|
|
9
|
+
# L1 constraint-gate is red on a same-repo PR, it dispatches the agent to FIX it (fix-only —
|
|
10
|
+
# never grows the suppression baseline), re-verifies the gate is green, and uploads the fix
|
|
11
|
+
# as a full-post-image-contents artifact (per-file sha256 + meta.json) for the privileged
|
|
12
|
+
# Stage B (fix-constraints-stage-b, workflow_run) to apply. No commit, no push, no repo-write
|
|
13
|
+
# scope here.
|
|
14
|
+
#
|
|
15
|
+
# SECURITY: `permissions: contents: read` ONLY. The write capability lives exclusively in
|
|
16
|
+
# Stage B, which never executes this untrusted tree (Git Data API, no checkout/no apply). The
|
|
17
|
+
# name: field above is load-bearing — Stage B's `on: workflow_run: workflows:` matches it by
|
|
18
|
+
# NAME, not by filename; a rename here silently stops recovery. Manual retry: re-run this
|
|
19
|
+
# workflow (workflow_dispatch) or push a commit to the PR.
|
|
20
|
+
|
|
21
|
+
on:
|
|
22
|
+
pull_request:
|
|
23
|
+
types: [opened, synchronize, reopened]
|
|
24
|
+
paths:
|
|
25
|
+
- 'apps/web-platform/app/**'
|
|
26
|
+
- 'apps/web-platform/components/**'
|
|
27
|
+
- 'apps/web-platform/server/**'
|
|
28
|
+
- 'apps/web-platform/.dependency-cruiser.cjs'
|
|
29
|
+
- 'apps/web-platform/.dependency-cruiser-known-violations.json'
|
|
30
|
+
workflow_dispatch:
|
|
31
|
+
|
|
32
|
+
permissions:
|
|
33
|
+
contents: read
|
|
34
|
+
|
|
35
|
+
concurrency:
|
|
36
|
+
# One agent dispatch per head SHA — a push-storm on one PR can't fan out N paid runs.
|
|
37
|
+
group: fix-constraints-a-${{ github.event.pull_request.head.sha || github.sha }}
|
|
38
|
+
cancel-in-progress: true
|
|
39
|
+
|
|
40
|
+
jobs:
|
|
41
|
+
produce:
|
|
42
|
+
# Loop guard: Stage B opens `soleur/fix-constraints/<pr>` follow-up PRs; those must never
|
|
43
|
+
# re-dispatch Stage A (github.head_ref is empty on workflow_dispatch → guard passes).
|
|
44
|
+
if: >-
|
|
45
|
+
github.event_name == 'workflow_dispatch' ||
|
|
46
|
+
!startsWith(github.head_ref, 'soleur/fix-constraints/')
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
timeout-minutes: 30
|
|
49
|
+
permissions:
|
|
50
|
+
contents: read
|
|
51
|
+
steps:
|
|
52
|
+
- name: Checkout the PR head (immutable SHA)
|
|
53
|
+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
|
54
|
+
with:
|
|
55
|
+
# pull_request checks out the ephemeral merge ref by default; pin to the immutable
|
|
56
|
+
# head SHA so the tree the gate runs on == the tree Stage B attests via head_sha.
|
|
57
|
+
ref: ${{ github.event.pull_request.head.sha }}
|
|
58
|
+
persist-credentials: false
|
|
59
|
+
|
|
60
|
+
- name: Preflight — API key present?
|
|
61
|
+
id: preflight
|
|
62
|
+
# Self-contained key-presence gate: sets ok=true iff ANTHROPIC_API_KEY is set (fork PRs
|
|
63
|
+
# get no secret → ok=false → the fix agent is skipped). The Soleur dogfood swaps this for
|
|
64
|
+
# a richer `./.github/actions/anthropic-preflight` composite that ALSO soft-skips on
|
|
65
|
+
# billing-cap / transient API errors; tenants get this minimal check so the template
|
|
66
|
+
# depends on no repo-local action.
|
|
67
|
+
env:
|
|
68
|
+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
69
|
+
run: |
|
|
70
|
+
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
|
|
71
|
+
echo "ok=true" >> "$GITHUB_OUTPUT"
|
|
72
|
+
else
|
|
73
|
+
echo "ok=false" >> "$GITHUB_OUTPUT"
|
|
74
|
+
echo "::notice::ANTHROPIC_API_KEY not set — skipping the fix agent (recovery is same-repo only)."
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
- name: Setup Bun # the gate's depcruise binary lives in node_modules
|
|
78
|
+
uses: oven-sh/setup-bun@3d267786b128fe76c2f16a390aa2448b815359f3 # v2.1.2
|
|
79
|
+
with:
|
|
80
|
+
bun-version-file: ".bun-version"
|
|
81
|
+
|
|
82
|
+
- name: Install dependencies (no postinstall scripts over untrusted PR code)
|
|
83
|
+
working-directory: apps/web-platform
|
|
84
|
+
# --ignore-scripts kills the postinstall ACE vector on fork-controlled package.json.
|
|
85
|
+
# (It does NOT stop the gate's own .dependency-cruiser.cjs from running — that is the
|
|
86
|
+
# accepted Stage-A residual, bounded by the capped/rotatable key + no write token.)
|
|
87
|
+
run: npm ci --ignore-scripts
|
|
88
|
+
|
|
89
|
+
- name: Run the constraint-gate (capture rc)
|
|
90
|
+
id: gate
|
|
91
|
+
run: |
|
|
92
|
+
set +e
|
|
93
|
+
bash apps/web-platform/scripts/constraint-gates.sh
|
|
94
|
+
echo "rc=$?" >> "$GITHUB_OUTPUT"
|
|
95
|
+
|
|
96
|
+
- name: Dispatch agent to fix the gate (fix-only)
|
|
97
|
+
if: steps.gate.outputs.rc != '0' && steps.preflight.outputs.ok == 'true'
|
|
98
|
+
id: agent
|
|
99
|
+
uses: anthropics/claude-code-action@20f0b248c5003db4b9ca43c45e17949bcdc36d2d # v1.0.236
|
|
100
|
+
with:
|
|
101
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
102
|
+
# `id-token: write` is deliberately ABSENT here (untrusted pull_request
|
|
103
|
+
# context — see ADR-074): the explicit input is the only safe token
|
|
104
|
+
# path. Verified at the pinned SHA: inputs.github_token ->
|
|
105
|
+
# OVERRIDE_GITHUB_TOKEN makes setupGitHubToken return BEFORE
|
|
106
|
+
# getOidcToken. Without it the agent step OIDC-hard-fails ~15 s in —
|
|
107
|
+
# the latent defect the dogfood copy carried until its repair.
|
|
108
|
+
github_token: ${{ github.token }}
|
|
109
|
+
# Model pin + action SHA mirror claude-code-review.yml verbatim (CI-validated).
|
|
110
|
+
# Pin freshness is model-launch-review's job — do NOT substitute a model id from memory.
|
|
111
|
+
claude_args: '--model claude-sonnet-5-5 --max-turns 20 --allowedTools Bash,Read,Write,Edit,Glob,Grep'
|
|
112
|
+
prompt: |
|
|
113
|
+
A constraint-gate tripped on this PR. Run `apps/web-platform/scripts/constraint-gates.sh`,
|
|
114
|
+
read the failure, and FIX the offending import so a client ("use client") module no longer
|
|
115
|
+
value-imports the server-only tree (server/**). Make file edits ONLY under
|
|
116
|
+
apps/web-platform/{app,components,server}.
|
|
117
|
+
You are FIX-ONLY: do NOT run the constraint-scaffold generator, do NOT pass
|
|
118
|
+
--refresh-baseline, and do NOT edit .dependency-cruiser-known-violations.json — growing
|
|
119
|
+
the suppression baseline would whitelist a real client->server-secret leak and is a
|
|
120
|
+
maintainer-only local action, never an auto-recovery path.
|
|
121
|
+
If the failure is not a real leak you can fix with an import change, make NO edits.
|
|
122
|
+
Do NOT commit or push — the workflow owns delivery.
|
|
123
|
+
|
|
124
|
+
- name: Re-run the gate to VERIFY the fix
|
|
125
|
+
# Assert the invariant — never trust "agent exited 0" (it exits 0 even on give-up).
|
|
126
|
+
if: steps.agent.outcome == 'success'
|
|
127
|
+
id: verify
|
|
128
|
+
run: |
|
|
129
|
+
set +e
|
|
130
|
+
bash apps/web-platform/scripts/constraint-gates.sh
|
|
131
|
+
echo "rc=$?" >> "$GITHUB_OUTPUT"
|
|
132
|
+
# `git status --porcelain` (not `git diff`) so a fix that CREATES a new in-scope
|
|
133
|
+
# file (untracked) counts as changed — `git diff` ignores untracked files.
|
|
134
|
+
if [ -z "$(git status --porcelain)" ]; then
|
|
135
|
+
echo "changed=false" >> "$GITHUB_OUTPUT"
|
|
136
|
+
else
|
|
137
|
+
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
138
|
+
fi
|
|
139
|
+
|
|
140
|
+
- name: Build recovery artifact (full post-image contents + per-file sha256 + meta.json)
|
|
141
|
+
# Only when the agent produced a real, verified-green change. FIX-ONLY + in-scope:
|
|
142
|
+
# any changed path outside apps/web-platform/{app,components,server} (incl. the baseline
|
|
143
|
+
# JSON, constraint-gates.sh, .github/**, *.cjs) ABORTS the artifact — baseline growth is
|
|
144
|
+
# maintainer-only; auto-recovery never ships an out-of-scope edit.
|
|
145
|
+
if: steps.verify.outputs.rc == '0' && steps.verify.outputs.changed == 'true'
|
|
146
|
+
id: artifact
|
|
147
|
+
env:
|
|
148
|
+
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
149
|
+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
150
|
+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
|
|
151
|
+
run: |
|
|
152
|
+
set -euo pipefail
|
|
153
|
+
staging="${RUNNER_TEMP}/fix-constraints-patch"
|
|
154
|
+
rm -rf "$staging"; mkdir -p "$staging/files"
|
|
155
|
+
# Stage ALL agent changes (tracked edits AND new untracked in-scope files; git add
|
|
156
|
+
# respects .gitignore so node_modules etc. are excluded), then enumerate them
|
|
157
|
+
# NUL-delimited so any filename survives. Out-of-scope edits are still enumerated
|
|
158
|
+
# here so the allowlist below can ABORT on them (never silently ship a partial fix).
|
|
159
|
+
git add -A
|
|
160
|
+
mapfile -d '' changed < <(git diff --cached --name-only -z)
|
|
161
|
+
if [ "${#changed[@]}" -eq 0 ]; then
|
|
162
|
+
echo "::notice::no changed files — nothing to deliver"; exit 0
|
|
163
|
+
fi
|
|
164
|
+
# Positive-charset, end-anchored allowlist + explicit absolute/`..` reject (matches
|
|
165
|
+
# Stage B's validator; defense-in-depth so the producer's scope boundary does not rely
|
|
166
|
+
# on a git-diff normalization invariant).
|
|
167
|
+
allow_re='^apps/web-platform/(app|components|server)/[A-Za-z0-9._/-]+$'
|
|
168
|
+
files_json='[]'
|
|
169
|
+
for f in "${changed[@]}"; do
|
|
170
|
+
if [[ "$f" == /* ]] || [[ "$f" == *".."* ]] || [[ ! "$f" =~ $allow_re ]]; then
|
|
171
|
+
echo "::error::agent edited an out-of-scope path (${f}) — auto-recovery is fix-only and in-scope-only; no artifact produced. A maintainer must review."
|
|
172
|
+
# Record the give-up reason so the marker step (below) can tell Stage B to comment.
|
|
173
|
+
echo "giveup_reason=edited an out-of-scope path" >> "$GITHUB_OUTPUT"
|
|
174
|
+
exit 0 # no recovery artifact => a give-up marker is produced instead
|
|
175
|
+
fi
|
|
176
|
+
dest="$staging/files/$f"
|
|
177
|
+
mkdir -p "$(dirname "$dest")"
|
|
178
|
+
cp "$f" "$dest"
|
|
179
|
+
sha="$(sha256sum "$f" | awk '{print $1}')"
|
|
180
|
+
files_json="$(jq -c --arg p "$f" --arg s "$sha" '. + [{path:$p, sha256:$s}]' <<<"$files_json")"
|
|
181
|
+
done
|
|
182
|
+
jq -n --arg pr "$PR_NUMBER" --arg sha "$HEAD_SHA" --arg ref "$HEAD_REF" \
|
|
183
|
+
--argjson files "$files_json" \
|
|
184
|
+
'{pr_number: ($pr|tonumber), head_sha: $sha, head_ref: $ref, files: $files, touches_baseline: false}' \
|
|
185
|
+
> "$staging/meta.json"
|
|
186
|
+
echo "dir=${staging}" >> "$GITHUB_OUTPUT"
|
|
187
|
+
echo "produced=true" >> "$GITHUB_OUTPUT"
|
|
188
|
+
|
|
189
|
+
- name: Upload recovery artifact
|
|
190
|
+
if: steps.artifact.outputs.produced == 'true'
|
|
191
|
+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
|
192
|
+
with:
|
|
193
|
+
name: fix-constraints-patch-${{ github.event.pull_request.number }}
|
|
194
|
+
path: ${{ steps.artifact.outputs.dir }}
|
|
195
|
+
retention-days: 1
|
|
196
|
+
if-no-files-found: error
|
|
197
|
+
|
|
198
|
+
- name: Build give-up marker (red gate, no in-scope fix delivered)
|
|
199
|
+
# The gate was RED but no recovery artifact was produced (no key, agent didn't run,
|
|
200
|
+
# made no edits, still red after the fix, or greened via an out-of-scope path). Emit a
|
|
201
|
+
# tiny marker so the privileged Stage B can post ONE "maintainer needed" comment on the
|
|
202
|
+
# PR — the founder is NEVER left silently deadlocked (plan AC: no terminal state is
|
|
203
|
+
# silent). No marker when the gate was already green (nothing tripped → no comment).
|
|
204
|
+
if: steps.gate.outputs.rc != '0' && steps.artifact.outputs.produced != 'true'
|
|
205
|
+
id: giveup
|
|
206
|
+
env:
|
|
207
|
+
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
208
|
+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
209
|
+
PREFLIGHT_OK: ${{ steps.preflight.outputs.ok }}
|
|
210
|
+
AGENT_OUTCOME: ${{ steps.agent.outcome }}
|
|
211
|
+
VERIFY_RC: ${{ steps.verify.outputs.rc }}
|
|
212
|
+
ARTIFACT_REASON: ${{ steps.artifact.outputs.giveup_reason }}
|
|
213
|
+
run: |
|
|
214
|
+
set -euo pipefail
|
|
215
|
+
if [ "${PREFLIGHT_OK}" != 'true' ]; then
|
|
216
|
+
reason="the fix agent could not run (API key unavailable or a fork PR)"
|
|
217
|
+
elif [ -n "${ARTIFACT_REASON}" ]; then
|
|
218
|
+
reason="${ARTIFACT_REASON}"
|
|
219
|
+
elif [ "${AGENT_OUTCOME}" != 'success' ]; then
|
|
220
|
+
reason="the fix agent did not complete"
|
|
221
|
+
elif [ "${VERIFY_RC}" != '0' ]; then
|
|
222
|
+
reason="the gate was still red after the agent's attempt"
|
|
223
|
+
else
|
|
224
|
+
reason="the agent made no edits — this gate may not be auto-fixable"
|
|
225
|
+
fi
|
|
226
|
+
staging="${RUNNER_TEMP}/fix-constraints-giveup"
|
|
227
|
+
rm -rf "$staging"; mkdir -p "$staging"
|
|
228
|
+
jq -n --arg pr "$PR_NUMBER" --arg sha "$HEAD_SHA" --arg r "$reason" \
|
|
229
|
+
'{pr_number: ($pr|tonumber), head_sha: $sha, reason: $r}' > "$staging/meta.json"
|
|
230
|
+
echo "dir=${staging}" >> "$GITHUB_OUTPUT"
|
|
231
|
+
echo "produced=true" >> "$GITHUB_OUTPUT"
|
|
232
|
+
|
|
233
|
+
- name: Upload give-up marker
|
|
234
|
+
if: steps.giveup.outputs.produced == 'true'
|
|
235
|
+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
|
236
|
+
with:
|
|
237
|
+
name: fix-constraints-giveup-${{ github.event.pull_request.number }}
|
|
238
|
+
path: ${{ steps.giveup.outputs.dir }}
|
|
239
|
+
retention-days: 1
|
|
240
|
+
if-no-files-found: error
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# `constraint-scaffold.sh --refresh-stage-a` (ADR-071 amendment 2026-11-05, tracker #12146).
|
|
3
|
+
#
|
|
4
|
+
# The mode re-emits exactly one file, apps/web-platform/.github/workflows/fix-constraints-stage-a.yml,
|
|
5
|
+
# and only when the existing bytes are an exact, ledger-listed historical emission of the template
|
|
6
|
+
# (references/fix-constraints-stage-a.emitted.sha256). Anything else is refused with exit 75 and the
|
|
7
|
+
# file is left byte-identical. This suite drives the mode through fourteen cases against hermetic
|
|
8
|
+
# `git init` fixtures (CONSTRAINT_SCAFFOLD_REPO_ROOT); the real apps/web-platform tree is never touched.
|
|
9
|
+
# A case that varies the ledger or the template runs a per-case SANDBOX COPY of scripts/ and
|
|
10
|
+
# references/ (the script derives REF_DIR from its own location, so the repo-root override alone
|
|
11
|
+
# cannot move the ledger).
|
|
12
|
+
#
|
|
13
|
+
# Runs in the scripts shard (scripts/test-all.sh globs plugins/soleur/skills/*/test/*.test.sh).
|
|
14
|
+
# Accumulate-then-exit; every command substitution that can fail is guarded so `set -e` cannot
|
|
15
|
+
# abort before a verdict is recorded. Portable to bash 3.2 / BSD userland: no mapfile, no stat,
|
|
16
|
+
# no realpath, no \b.
|
|
17
|
+
set -euo pipefail
|
|
18
|
+
# A self-invoked suite builds sandboxes under TMPDIR; default it to the roomy tmpfs-free path.
|
|
19
|
+
export TMPDIR="${TMPDIR:-/var/tmp}"
|
|
20
|
+
|
|
21
|
+
REPO_ROOT="$(git -C "$(dirname "${BASH_SOURCE[0]}")" rev-parse --show-toplevel)"
|
|
22
|
+
SKILL="$REPO_ROOT/plugins/soleur/skills/constraint-scaffold"
|
|
23
|
+
REAL_SCRIPTS="$SKILL/scripts"
|
|
24
|
+
REAL_REFS="$SKILL/references"
|
|
25
|
+
OLD_FIXTURE="$SKILL/test/fixtures/stage-a.v1.0.236.emitted"
|
|
26
|
+
FIX_A_REL="apps/web-platform/.github/workflows/fix-constraints-stage-a.yml"
|
|
27
|
+
WF_DIR_REL="apps/web-platform/.github/workflows"
|
|
28
|
+
|
|
29
|
+
passes=0
|
|
30
|
+
fails=0
|
|
31
|
+
# The INDEPENDENT row counter (ADR-193 #2): incremented at every call site, never inside
|
|
32
|
+
# pass()/fail(), so a stubbed fail() drops a verdict without dropping its count.
|
|
33
|
+
cases=0
|
|
34
|
+
pass() { printf 'ok - %s\n' "$1"; passes=$((passes + 1)); }
|
|
35
|
+
fail() { printf 'FAIL - %s\n' "$1"; fails=$((fails + 1)); }
|
|
36
|
+
# Instrument self-test (direction, not only presence). Reported with printf >&2 + exit 1.
|
|
37
|
+
fail "instrument self-test (expected — proves fail() records a FAILURE)" >/dev/null
|
|
38
|
+
pass "instrument self-test (expected — proves pass() records a PASS)" >/dev/null
|
|
39
|
+
if [[ "$fails" != "1" || "$passes" != "1" ]]; then
|
|
40
|
+
printf '[FATAL] HELPER CONTROL BROKEN: after one fail() and one pass(), fails=%s passes=%s (want 1/1)\n' "$fails" "$passes" >&2
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
43
|
+
passes=0; fails=0
|
|
44
|
+
|
|
45
|
+
# Verdict helpers. chk records one row from a command's exit status. rcis records a row for the
|
|
46
|
+
# exit code AND remembers whether it matched, so the state rows that follow it (bytes unchanged,
|
|
47
|
+
# no leftover) are recorded as FAILURES when the code was wrong: "bytes unchanged" is trivially
|
|
48
|
+
# true when nothing ran at all, which would make the RED run report false greens.
|
|
49
|
+
RC=0
|
|
50
|
+
OUT=""
|
|
51
|
+
ERR=""
|
|
52
|
+
RC_OK=0
|
|
53
|
+
chk() { local label="$1"; shift; cases=$((cases + 1)); if "$@"; then pass "$label"; else fail "$label"; fi; }
|
|
54
|
+
rcis() {
|
|
55
|
+
local label="$1" want="$2"
|
|
56
|
+
cases=$((cases + 1)); RC_OK=0
|
|
57
|
+
if [[ "$RC" == "$want" ]]; then RC_OK=1; pass "$label (rc $RC)"; else fail "$label (want rc $want, got $RC; stdout: $(printf '%s' "$OUT" | tail -n 2 | tr '\n' ' '))"; fi
|
|
58
|
+
}
|
|
59
|
+
state() { local label="$1"; shift; cases=$((cases + 1)); if [[ "$RC_OK" == 1 ]] && "$@"; then pass "$label"; else fail "$label"; fi; }
|
|
60
|
+
# Instrument control for the row helpers (the pass/fail control above cannot see these): drive each
|
|
61
|
+
# helper once in each direction and require the counters to move accordingly. Reported with printf + exit, never through the helpers under test.
|
|
62
|
+
c0=$cases; p0=$passes; f0=$fails
|
|
63
|
+
RC=7; RC_OK=1
|
|
64
|
+
chk "control" false >/dev/null; rcis "control" 0 >/dev/null; state "control" true >/dev/null
|
|
65
|
+
f1=$fails; p1=$passes
|
|
66
|
+
RC=0; RC_OK=1
|
|
67
|
+
chk "control" true >/dev/null; rcis "control" 0 >/dev/null; state "control" true >/dev/null
|
|
68
|
+
if [[ $((f1 - f0)) -ne 3 || $((passes - p1)) -ne 3 || $((cases - c0)) -ne 6 ]]; then
|
|
69
|
+
printf '[FATAL] HELPER CONTROL BROKEN: chk/rcis/state did not record 3 failures then 3 passes (fails +%s, passes +%s, rows +%s)\n' \
|
|
70
|
+
"$((f1 - f0))" "$((passes - p1))" "$((cases - c0))" >&2
|
|
71
|
+
exit 1
|
|
72
|
+
fi
|
|
73
|
+
# The 3 deliberate failures are the control working: unwind them as failures and count them as passes,
|
|
74
|
+
# so the 6 control rows stay in `cases` and the MIN_ROWS floor notices if this block is deleted.
|
|
75
|
+
fails=$f0; passes=$((p0 + 6)); RC=0; RC_OK=0
|
|
76
|
+
|
|
77
|
+
# assert_fixture_dir: the CANONICAL copy (byte-for-byte; fixture-dir-operand-assert.test.sh pins it).
|
|
78
|
+
assert_fixture_dir() {
|
|
79
|
+
case "${1-}" in
|
|
80
|
+
"") printf 'FATAL: fixture dir is EMPTY; git -C "" would operate on %s\n' "$PWD" >&2; exit 2 ;;
|
|
81
|
+
*/../*|*/..) printf 'FATAL: fixture dir %s contains ..; refusing\n' "$1" >&2; exit 2 ;;
|
|
82
|
+
/proc/*|/sys/*|/dev/*) printf 'FATAL: fixture dir %s is a synthetic-fs path; refusing\n' "$1" >&2; exit 2 ;;
|
|
83
|
+
/|//|/.) printf 'FATAL: fixture dir resolves to the filesystem root; refusing\n' >&2; exit 2 ;;
|
|
84
|
+
/*) : ;;
|
|
85
|
+
*) printf 'FATAL: fixture dir %s is RELATIVE; refusing\n' "$1" >&2; exit 2 ;;
|
|
86
|
+
esac
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
TMPROOT="$(mktemp -d)"
|
|
90
|
+
assert_fixture_dir "$TMPROOT"
|
|
91
|
+
cleanup() { assert_fixture_dir "$TMPROOT"; rm -rf -- "$TMPROOT"; }
|
|
92
|
+
trap cleanup EXIT
|
|
93
|
+
mkdir -p "$TMPROOT/tmp"
|
|
94
|
+
# Hermetic git environment for the fixtures (the repo's chokepoint, #7849).
|
|
95
|
+
# shellcheck source=../../../test/lib/git-fixture-env.sh
|
|
96
|
+
source "$REPO_ROOT/plugins/soleur/test/lib/git-fixture-env.sh"
|
|
97
|
+
mkdir -p "$TMPROOT/anchor"
|
|
98
|
+
git_fixture_env "$TMPROOT/anchor" || { echo "FATAL: git_fixture_env refused $TMPROOT/anchor" >&2; exit 1; }
|
|
99
|
+
|
|
100
|
+
sha_of() {
|
|
101
|
+
local h
|
|
102
|
+
if command -v sha256sum >/dev/null 2>&1; then h="$(sha256sum "$1")"; else h="$(shasum -a 256 "$1")"; fi
|
|
103
|
+
printf '%s' "${h%% *}"
|
|
104
|
+
}
|
|
105
|
+
same_bytes() { cmp -s "$1" "$2"; }
|
|
106
|
+
mode_of() { local l; l="$(ls -l "$1")"; printf '%s' "${l:0:10}"; }
|
|
107
|
+
inode_of() { local l; l="$(ls -i "$1")"; l="${l# }"; printf '%s' "${l%% *}"; }
|
|
108
|
+
# Ledger data rows, parsed the way the script parses them: first field of every non-comment line.
|
|
109
|
+
ledger_hashes() { awk '/^[[:space:]]*#/ || !NF {next} {print $1}' "$1"; }
|
|
110
|
+
fresh_emission() { sed "s|__TARGET_DIR__|apps/web-platform|g" "$1/fix-constraints-stage-a.template"; }
|
|
111
|
+
has_forty_hex() { grep -Eq '(^|[^0-9a-f])[0-9a-f]{40}([^0-9a-f]|$)' "$1"; }
|
|
112
|
+
has_action_ref() { grep -Fq 'claude-code-action@' "$1"; }
|
|
113
|
+
|
|
114
|
+
# --- Base fixture: a Next.js-shaped app with the scaffold's artifacts committed -------------------
|
|
115
|
+
BASE="$TMPROOT/base"
|
|
116
|
+
mkdir -p "$BASE/apps/web-platform/app" "$BASE/apps/web-platform/components" "$BASE/apps/web-platform/server" \
|
|
117
|
+
"$BASE/apps/web-platform/scripts" "$BASE/$WF_DIR_REL"
|
|
118
|
+
git -C "$BASE" init -q
|
|
119
|
+
git -C "$BASE" config user.email "test@example.com"
|
|
120
|
+
git -C "$BASE" config user.name "test"
|
|
121
|
+
printf 'node_modules\n' > "$BASE/.gitignore"
|
|
122
|
+
printf 'module.exports = {};\n' > "$BASE/apps/web-platform/next.config.js"
|
|
123
|
+
printf '{ "dependencies": { "next": "15.0.0" } }\n' > "$BASE/apps/web-platform/package.json"
|
|
124
|
+
printf 'export default function Page() { return null; }\n' > "$BASE/apps/web-platform/app/page.tsx"
|
|
125
|
+
printf '"use client";\nexport const G = () => "g";\n' > "$BASE/apps/web-platform/components/g.tsx"
|
|
126
|
+
printf 'export const APP = "fixture";\n' > "$BASE/apps/web-platform/server/config.ts"
|
|
127
|
+
printf '{ "lockfileVersion": 3 }\n' > "$BASE/apps/web-platform/package-lock.json"
|
|
128
|
+
printf 'sentinel-config\n' > "$BASE/apps/web-platform/.dependency-cruiser.cjs"
|
|
129
|
+
printf 'sentinel-runner\n' > "$BASE/apps/web-platform/scripts/constraint-gates.sh"
|
|
130
|
+
printf 'sentinel-baseline\n' > "$BASE/apps/web-platform/.dependency-cruiser-known-violations.json"
|
|
131
|
+
printf 'sentinel-gates-workflow\n' > "$BASE/$WF_DIR_REL/constraint-gates.yml"
|
|
132
|
+
printf 'sentinel-stage-b\n' > "$BASE/$WF_DIR_REL/fix-constraints-stage-b.yml"
|
|
133
|
+
cp "$OLD_FIXTURE" "$BASE/$FIX_A_REL"
|
|
134
|
+
git -C "$BASE" add -A
|
|
135
|
+
git -C "$BASE" commit -q -m "seed app and scaffold artifacts"
|
|
136
|
+
|
|
137
|
+
# new_case <name>: a fresh copy of the base fixture. Prints the path.
|
|
138
|
+
new_case() { local fx="$TMPROOT/$1"; cp -R "$BASE" "$fx"; printf '%s' "$fx"; }
|
|
139
|
+
commit_all() { assert_fixture_dir "$1"; git -C "$1" add -A; git -C "$1" commit -q -m "${2:-change}"; }
|
|
140
|
+
# new_sandbox <name>: a per-case copy of scripts/ and references/ so a case can vary the ledger or
|
|
141
|
+
# the template. Prints the scripts dir to run.
|
|
142
|
+
new_sandbox() { local sb="$TMPROOT/sb-$1"; mkdir -p "$sb"; cp -R "$REAL_SCRIPTS" "$sb/scripts"; cp -R "$REAL_REFS" "$sb/references"; printf '%s' "$sb"; }
|
|
143
|
+
|
|
144
|
+
# run_refresh <fixture> [<scripts-dir>]: sets RC, OUT (stdout), ERR (stderr).
|
|
145
|
+
run_refresh() {
|
|
146
|
+
local fx="$1" sd="${2:-$REAL_SCRIPTS}"
|
|
147
|
+
RC=0
|
|
148
|
+
OUT="$(CONSTRAINT_SCAFFOLD_REPO_ROOT="$fx" TMPDIR="$TMPROOT/tmp" bash "$sd/constraint-scaffold.sh" --refresh-stage-a 2>"$TMPROOT/err")" || RC=$?
|
|
149
|
+
ERR="$(cat "$TMPROOT/err")"
|
|
150
|
+
}
|
|
151
|
+
no_leftover() { local fx="$1"; compgen -G "$fx/$WF_DIR_REL/.fix-constraints-stage-a.*" >/dev/null && return 1; [[ ! -e "$fx/.git/constraint-scaffold.lock" ]]; }
|
|
152
|
+
no_leftover_clean() { no_leftover "$1" && [[ -z "$(git -C "$1" status --porcelain)" ]]; }
|
|
153
|
+
no_temp() { ! compgen -G "$1/$WF_DIR_REL/.fix-constraints-stage-a.*" >/dev/null; }
|
|
154
|
+
out_has() { grep -Fq -- "$1" <<<"$OUT"; }
|
|
155
|
+
out_lacks() { ! grep -Fq -- "$1" <<<"$OUT$ERR"; }
|
|
156
|
+
out_has_line() { grep -Eq -- "$1" <<<"$OUT"; }
|
|
157
|
+
fresh_real="$TMPROOT/fresh-real"
|
|
158
|
+
fresh_emission "$REAL_REFS" > "$fresh_real"
|
|
159
|
+
|
|
160
|
+
# --- 1. Refresh the v1.0.236 fixture (clean, committed, under umask 077) --------------------------
|
|
161
|
+
FX="$(new_case c1)"
|
|
162
|
+
old_umask="$(umask)"; umask 077
|
|
163
|
+
run_refresh "$FX"
|
|
164
|
+
umask "$old_umask"
|
|
165
|
+
rcis "1a refresh of the v1.0.236 emission" 0
|
|
166
|
+
state "1b bytes equal the fresh emission of the template" same_bytes "$FX/$FIX_A_REL" "$fresh_real"
|
|
167
|
+
state "1c mode is 0644 (mktemp's 0600 must not leak)" test "$(mode_of "$FX/$FIX_A_REL")" = "-rw-r--r--"
|
|
168
|
+
state "1d no leftover temp file or lock directory" no_leftover "$FX"
|
|
169
|
+
|
|
170
|
+
# --- 2. Already current: never consults the ledger -------------------------------------------------
|
|
171
|
+
FX="$(new_case c2)"
|
|
172
|
+
cp "$fresh_real" "$FX/$FIX_A_REL"
|
|
173
|
+
commit_all "$FX" "current"
|
|
174
|
+
SB="$(new_sandbox c2)"
|
|
175
|
+
rm -f "$SB/references/fix-constraints-stage-a.emitted.sha256"
|
|
176
|
+
: > "$TMPROOT/ref2"; touch -t 200001010000 "$TMPROOT/ref2" "$FX/$FIX_A_REL"
|
|
177
|
+
ino_before="$(inode_of "$FX/$FIX_A_REL")"
|
|
178
|
+
run_refresh "$FX" "$SB/scripts"
|
|
179
|
+
rcis "2a already-current file with the ledger removed" 0
|
|
180
|
+
chk "2a' says already current" out_has "already current"
|
|
181
|
+
state "2b not rewritten (backdated mtime not advanced)" test ! "$FX/$FIX_A_REL" -nt "$TMPROOT/ref2"
|
|
182
|
+
state "2c not rewritten (inode unchanged)" test "$(inode_of "$FX/$FIX_A_REL")" = "$ino_before"
|
|
183
|
+
state "2d no leftover temp file or lock directory" no_leftover_clean "$FX"
|
|
184
|
+
|
|
185
|
+
FX="$(new_case c2e)"; assert_fixture_dir "$FX"
|
|
186
|
+
cp "$fresh_real" "$FX/$FIX_A_REL"
|
|
187
|
+
git -C "$FX" rm -q apps/web-platform/package-lock.json
|
|
188
|
+
commit_all "$FX" "current, no lockfile"
|
|
189
|
+
run_refresh "$FX"
|
|
190
|
+
rcis "2e an already-current file exits 0 even without a lockfile (nothing would be written)" 0
|
|
191
|
+
|
|
192
|
+
# --- 3. Edited copy: refused, file untouched, user's content never printed ------------------------
|
|
193
|
+
TOKEN="sk-""ant-api03-ZZZZ$(printf 'Z%.0s' 1 2 3 4 5 6 7 8)SYNTH"
|
|
194
|
+
FX="$(new_case c3)"
|
|
195
|
+
{ head -n 100 "$OLD_FIXTURE"; printf '# edited by a founder: %s\n' "$TOKEN"; tail -n +101 "$OLD_FIXTURE"; } > "$FX/$FIX_A_REL"
|
|
196
|
+
cp "$FX/$FIX_A_REL" "$TMPROOT/c3.before"
|
|
197
|
+
commit_all "$FX" "edited"
|
|
198
|
+
run_refresh "$FX"
|
|
199
|
+
rcis "3a edited copy is refused" 75
|
|
200
|
+
state "3b bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$TMPROOT/c3.before"
|
|
201
|
+
state "3c report shows template-side lines" out_has_line '^> '
|
|
202
|
+
state "3c' report never prints the existing side or the planted token" out_lacks "$TOKEN"
|
|
203
|
+
state "3c'' report has no existing-side line" test -z "$(grep -E '^< ' <<<"$OUT" || true)"
|
|
204
|
+
state "3d no leftover" no_leftover_clean "$FX"
|
|
205
|
+
|
|
206
|
+
# --- 4. Final newline stripped: exact bytes, not normalised text ----------------------------------
|
|
207
|
+
FX="$(new_case c4)"
|
|
208
|
+
printf '%s' "$(<"$OLD_FIXTURE")" > "$FX/$FIX_A_REL"
|
|
209
|
+
cp "$FX/$FIX_A_REL" "$TMPROOT/c4.before"
|
|
210
|
+
commit_all "$FX" "no newline"
|
|
211
|
+
run_refresh "$FX"
|
|
212
|
+
rcis "4a stripped final newline is refused" 75
|
|
213
|
+
state "4b bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$TMPROOT/c4.before"
|
|
214
|
+
|
|
215
|
+
# --- 5. Guards before the write (destination always holds ledger-member bytes) --------------------
|
|
216
|
+
dirty_other() { printf 'dirty\n' >> "$1/$WF_DIR_REL/constraint-gates.yml"; }
|
|
217
|
+
hold_lock() { mkdir -p "$1/.git/constraint-scaffold.lock"; printf '%s\n' "$$" > "$1/.git/constraint-scaffold.lock/pid"; }
|
|
218
|
+
lock_pid_is_mine() { [[ "$(cat "$1/.git/constraint-scaffold.lock/pid" 2>/dev/null || true)" == "$$" ]]; }
|
|
219
|
+
|
|
220
|
+
FX="$(new_case c5a)"; dirty_other "$FX"
|
|
221
|
+
run_refresh "$FX"
|
|
222
|
+
rcis "5a dirty tree" 67
|
|
223
|
+
state "5a' bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$OLD_FIXTURE"
|
|
224
|
+
|
|
225
|
+
FX="$(new_case c5b)"; hold_lock "$FX"
|
|
226
|
+
run_refresh "$FX"
|
|
227
|
+
rcis "5b live lock on a clean tree (positive control that the lock is reached)" 69
|
|
228
|
+
state "5b' bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$OLD_FIXTURE"
|
|
229
|
+
state "5b'' the other run's lock was not taken over" lock_pid_is_mine "$FX"
|
|
230
|
+
|
|
231
|
+
FX="$(new_case c5c)"; dirty_other "$FX"; hold_lock "$FX"
|
|
232
|
+
run_refresh "$FX"
|
|
233
|
+
rcis "5c dirty tree plus live lock (tree check precedes the lock)" 67
|
|
234
|
+
|
|
235
|
+
FX="$(new_case c5d)"; dirty_other "$FX"
|
|
236
|
+
mkdir -p "$TMPROOT/outside5d"; cp "$OLD_FIXTURE" "$TMPROOT/outside5d/target"
|
|
237
|
+
rm -f "$FX/$FIX_A_REL"; ln -s "$TMPROOT/outside5d/target" "$FX/$FIX_A_REL"
|
|
238
|
+
run_refresh "$FX"
|
|
239
|
+
rcis "5d symlinked destination on a dirty tree (symlink check precedes the tree check)" 75
|
|
240
|
+
|
|
241
|
+
FX="$(new_case c5e)"
|
|
242
|
+
assert_fixture_dir "$FX"
|
|
243
|
+
git -C "$FX" rm -q --cached "$FIX_A_REL"
|
|
244
|
+
git -C "$FX" commit -q -m "untrack stage a"
|
|
245
|
+
run_refresh "$FX"
|
|
246
|
+
rcis "5e untracked but byte-valid destination (must be reviewable with git diff)" 67
|
|
247
|
+
state "5e' bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$OLD_FIXTURE"
|
|
248
|
+
|
|
249
|
+
# --- 6. Existence precedes everything, and takes no lock ------------------------------------------
|
|
250
|
+
FX="$(new_case c6a)"; dirty_other "$FX"; hold_lock "$FX"; rm -f "$FX/$FIX_A_REL"
|
|
251
|
+
run_refresh "$FX"
|
|
252
|
+
rcis "6a stage-a absent on a dirty tree with a live lock" 70
|
|
253
|
+
state "6d the mode took no lock (the pre-created lock is untouched)" lock_pid_is_mine "$FX"
|
|
254
|
+
|
|
255
|
+
FX="$(new_case c6b)"; rm -f "$FX/apps/web-platform/.dependency-cruiser.cjs"; commit_all "$FX" "no config"
|
|
256
|
+
run_refresh "$FX"
|
|
257
|
+
rcis "6b config absent" 70
|
|
258
|
+
|
|
259
|
+
FX="$(new_case c6c)"; dirty_other "$FX"; hold_lock "$FX"
|
|
260
|
+
rm -f "$FX/$FIX_A_REL"; ln -s "$TMPROOT/does-not-exist-6c" "$FX/$FIX_A_REL"
|
|
261
|
+
run_refresh "$FX"
|
|
262
|
+
rcis "6c dangling-symlink destination" 70
|
|
263
|
+
|
|
264
|
+
# --- 7. Ledger anchored to the template; no downgrade ---------------------------------------------
|
|
265
|
+
want_hash="$(sha_of "$fresh_real")"
|
|
266
|
+
ledger_rows="$(ledger_hashes "$REAL_REFS/fix-constraints-stage-a.emitted.sha256" 2>/dev/null || true)"
|
|
267
|
+
last_row="${ledger_rows##*$'\n'}"
|
|
268
|
+
bad_rows="$(grep -Evc '^[0-9a-f]{64}$' <<<"$ledger_rows" || true)"
|
|
269
|
+
dup_rows="$(sort <<<"$ledger_rows" | uniq -d)"
|
|
270
|
+
chk "7a the LAST ledger row is the CURRENT template's emission ($want_hash): append a row only if the template keeps the frozen Stage A to Stage B interface and contents: read; regenerate with the command in the ledger header" test "$last_row" = "$want_hash"
|
|
271
|
+
chk "7a' no ledger row is a duplicate (a duplicate makes a legitimate upgrade read as a downgrade)" test -z "$dup_rows"
|
|
272
|
+
HIST_PIN="b8187a33c668e44a00cff048117d2ed1b6d568b90b5c10b28f21bb5e46d99386
|
|
273
|
+
889e8a08481de2af5909b59043f8df0a59207374aa30f35deca3676a0fe536bc
|
|
274
|
+
e68d1cc2ce56c3e60c6ed939172ef19d83bcb85a606ae8442934898e873941e3
|
|
275
|
+
5130360de005d5534dfab73ad5fb1af8dd8a196c72e97eb1eb08d17ceb7facbe
|
|
276
|
+
45fdc5c5e0060d8ced95d64688061dc567beba1329a9323b6b6a7817ecdd2895"
|
|
277
|
+
first_rows="$(printf '%s\n' "$ledger_rows" | head -n 5)"
|
|
278
|
+
chk "7a''' the first five (historical) ledger rows are pinned in order: reordering or deleting one changes every older install's rank" test "$first_rows" = "$HIST_PIN"
|
|
279
|
+
chk "7a'' every ledger row is a lowercase 64-hex digest and there are at least two rows" test "$bad_rows" = 0 -a "$(printf '%s\n' "$ledger_rows" | wc -l | tr -d ' ')" -ge 2
|
|
280
|
+
|
|
281
|
+
FX="$(new_case c7b)"
|
|
282
|
+
SB="$(new_sandbox c7b)"
|
|
283
|
+
{ cat "$REAL_REFS/fix-constraints-stage-a.template"; printf '# ledger-rank-older\n'; } > "$SB/references/fix-constraints-stage-a.template"
|
|
284
|
+
{ cat "$REAL_REFS/fix-constraints-stage-a.template"; printf '# ledger-rank-newer\n'; } > "$TMPROOT/tpl-newer"
|
|
285
|
+
sed "s|__TARGET_DIR__|apps/web-platform|g" "$SB/references/fix-constraints-stage-a.template" > "$TMPROOT/em-older"
|
|
286
|
+
sed "s|__TARGET_DIR__|apps/web-platform|g" "$TMPROOT/tpl-newer" > "$TMPROOT/em-newer"
|
|
287
|
+
printf '# synthetic two-row ledger for the downgrade case\n%s older\n%s newer\n' "$(sha_of "$TMPROOT/em-older")" "$(sha_of "$TMPROOT/em-newer")" \
|
|
288
|
+
> "$SB/references/fix-constraints-stage-a.emitted.sha256"
|
|
289
|
+
cp "$TMPROOT/em-newer" "$FX/$FIX_A_REL"; commit_all "$FX" "newest era installed"
|
|
290
|
+
run_refresh "$FX" "$SB/scripts"
|
|
291
|
+
rcis "7b installed file newer than the plugin's template is refused" 75
|
|
292
|
+
state "7b' bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$TMPROOT/em-newer"
|
|
293
|
+
state "7b'' says the installed file is newer" out_has "newer than this plugin"
|
|
294
|
+
state "7b''' prints no diff on a downgrade refusal" test -z "$(grep -E '^[<>] ' <<<"$OUT" || true)"
|
|
295
|
+
state "7b'''' no leftover temp file or lock directory" no_leftover_clean "$FX"
|
|
296
|
+
|
|
297
|
+
# --- 8. Ledger unusable: fail closed ---------------------------------------------------------------
|
|
298
|
+
for variant in removed no-data-rows comment-only; do
|
|
299
|
+
FX="$(new_case "c8-$variant")"
|
|
300
|
+
SB="$(new_sandbox "c8-$variant")"
|
|
301
|
+
ledger="$SB/references/fix-constraints-stage-a.emitted.sha256"
|
|
302
|
+
case "$variant" in
|
|
303
|
+
removed) rm -f "$ledger" ;;
|
|
304
|
+
no-data-rows) printf '\n \n\n' > "$ledger" ;;
|
|
305
|
+
comment-only) printf '# only a comment\n# and another\n' > "$ledger" ;;
|
|
306
|
+
esac
|
|
307
|
+
run_refresh "$FX" "$SB/scripts"
|
|
308
|
+
rcis "8 ledger $variant refuses the stale fixture" 75
|
|
309
|
+
state "8 ledger $variant leaves the bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$OLD_FIXTURE"
|
|
310
|
+
state "8 ledger $variant leaves no temp file or lock directory" no_leftover_clean "$FX"
|
|
311
|
+
done
|
|
312
|
+
|
|
313
|
+
# --- 9. Symlink and hash-tool arms -----------------------------------------------------------------
|
|
314
|
+
FX="$(new_case c9a)"
|
|
315
|
+
mkdir -p "$TMPROOT/outside9a"; cp "$OLD_FIXTURE" "$TMPROOT/outside9a/target"
|
|
316
|
+
rm -f "$FX/$FIX_A_REL"; ln -s "$TMPROOT/outside9a/target" "$FX/$FIX_A_REL"; commit_all "$FX" "symlinked stage a"
|
|
317
|
+
run_refresh "$FX"
|
|
318
|
+
rcis "9a symlinked destination file (clean tree)" 75
|
|
319
|
+
state "9a' the symlink target is unchanged" same_bytes "$TMPROOT/outside9a/target" "$OLD_FIXTURE"
|
|
320
|
+
state "9a'' no diff printed" test -z "$(grep -E '^[<>] ' <<<"$OUT" || true)"
|
|
321
|
+
|
|
322
|
+
FX="$(new_case c9b)"
|
|
323
|
+
assert_fixture_dir "$FX"
|
|
324
|
+
git -C "$FX" mv apps/web-platform/.github .github
|
|
325
|
+
ln -s ../../.github "$FX/apps/web-platform/.github"
|
|
326
|
+
commit_all "$FX" "symlinked .github parent"
|
|
327
|
+
run_refresh "$FX"
|
|
328
|
+
rcis "9b symlinked parent directory (physical dir must equal the target's workflows dir)" 75
|
|
329
|
+
state "9b' the pointed-at file is unchanged" same_bytes "$FX/.github/workflows/fix-constraints-stage-a.yml" "$OLD_FIXTURE"
|
|
330
|
+
|
|
331
|
+
FX="$(new_case c9c)"
|
|
332
|
+
FAKE="$TMPROOT/fakebin"; mkdir -p "$FAKE"
|
|
333
|
+
for tool in sha256sum shasum; do
|
|
334
|
+
cat > "$FAKE/$tool" <<'FAKE'
|
|
335
|
+
#!/usr/bin/env bash
|
|
336
|
+
# Strict fake: the only accepted shapes are `sha256sum FILE` and `shasum -a 256 FILE`; both emit an
|
|
337
|
+
# EMPTY digest. Any other argv exits 64 so a changed call shape in the script is a loud failure here.
|
|
338
|
+
case "$(basename "$0"):$#:${1:-}:${2:-}" in
|
|
339
|
+
sha256sum:1:*) printf '\n'; exit 0 ;;
|
|
340
|
+
shasum:3:-a:256) printf '\n'; exit 0 ;;
|
|
341
|
+
*) echo "unexpected argv: $*" >> "${FAKE_REFUSED:?}"; exit 64 ;;
|
|
342
|
+
esac
|
|
343
|
+
FAKE
|
|
344
|
+
chmod +x "$FAKE/$tool"
|
|
345
|
+
done
|
|
346
|
+
# Positive control: the fake must log an argv it refuses, or the empty-log row below proves nothing.
|
|
347
|
+
FAKE_REFUSED="$TMPROOT/fake-probe" PATH="$FAKE:$PATH" sha256sum --probe unexpected-argv >/dev/null 2>&1 || true
|
|
348
|
+
chk "9c control: the fake records an unexpected argv" test -s "$TMPROOT/fake-probe"
|
|
349
|
+
RC=0
|
|
350
|
+
OUT="$(FAKE_REFUSED="$TMPROOT/fake-refused" PATH="$FAKE:$PATH" CONSTRAINT_SCAFFOLD_REPO_ROOT="$FX" TMPDIR="$TMPROOT/tmp" bash "$REAL_SCRIPTS/constraint-scaffold.sh" --refresh-stage-a 2>"$TMPROOT/err")" || RC=$?
|
|
351
|
+
ERR="$(cat "$TMPROOT/err")"
|
|
352
|
+
rcis "9c empty digest from the hash tool is an error, never a ledger match" 69
|
|
353
|
+
state "9c' bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$OLD_FIXTURE"
|
|
354
|
+
state "9c'' the script called the hash tools only with argv shapes the fake accepts" test ! -s "$TMPROOT/fake-refused"
|
|
355
|
+
|
|
356
|
+
FX="$(new_case c9d)"
|
|
357
|
+
assert_fixture_dir "$FX"
|
|
358
|
+
git -C "$FX" mv apps appsreal
|
|
359
|
+
ln -s appsreal "$FX/apps"
|
|
360
|
+
commit_all "$FX" "symlinked apps"
|
|
361
|
+
run_refresh "$FX"
|
|
362
|
+
rcis "9d symlinked apps/ directory (physical dir must equal the literal target path)" 75
|
|
363
|
+
state "9d' the file behind the symlink is unchanged" same_bytes "$FX/appsreal/web-platform/.github/workflows/fix-constraints-stage-a.yml" "$OLD_FIXTURE"
|
|
364
|
+
|
|
365
|
+
# --- 10. A refresh writes the one file and nothing else -------------------------------------------
|
|
366
|
+
FX="$(new_case c10)"
|
|
367
|
+
SNAP="$TMPROOT/snap10"; mkdir -p "$SNAP"
|
|
368
|
+
others="apps/web-platform/.dependency-cruiser.cjs apps/web-platform/scripts/constraint-gates.sh apps/web-platform/.dependency-cruiser-known-violations.json $WF_DIR_REL/constraint-gates.yml $WF_DIR_REL/fix-constraints-stage-b.yml"
|
|
369
|
+
n=0; for f in $others; do n=$((n + 1)); cp "$FX/$f" "$SNAP/$n"; done
|
|
370
|
+
run_refresh "$FX"
|
|
371
|
+
rcis "10a refresh succeeds" 0
|
|
372
|
+
state "10a' the destination changed" test ! "$(sha_of "$FX/$FIX_A_REL")" = "$(sha_of "$OLD_FIXTURE")"
|
|
373
|
+
n=0; untouched=1; for f in $others; do n=$((n + 1)); same_bytes "$FX/$f" "$SNAP/$n" || untouched=0; done
|
|
374
|
+
state "10b stage-b, gates workflow, config, runner and baseline are byte-unchanged" test "$untouched" = 1
|
|
375
|
+
state "10c git sees exactly one modified path and no stray file" test "$(git -C "$FX" status --porcelain)" = " M $FIX_A_REL"
|
|
376
|
+
|
|
377
|
+
# --- 11. No pin literal in the script or the ledger -----------------------------------------------
|
|
378
|
+
POS="$TMPROOT/pos11"
|
|
379
|
+
{ printf 'uses: anthropics/claude-code-action@'; printf 'a%.0s' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40; printf '\n'; } > "$POS"
|
|
380
|
+
chk "11a positive control: the helpers find a 40-hex string" has_forty_hex "$POS"
|
|
381
|
+
chk "11a' positive control: the helpers find an action reference" has_action_ref "$POS"
|
|
382
|
+
chk "11 inputs exist (grep rc 2 is not a pass)" test -f "$REAL_SCRIPTS/constraint-scaffold.sh" -a -f "$REAL_REFS/fix-constraints-stage-a.emitted.sha256"
|
|
383
|
+
chk "11b constraint-scaffold.sh carries no action reference" test ! "$(has_action_ref "$REAL_SCRIPTS/constraint-scaffold.sh" && echo y || echo n)" = y
|
|
384
|
+
chk "11b' constraint-scaffold.sh carries no 40-hex string" test ! "$(has_forty_hex "$REAL_SCRIPTS/constraint-scaffold.sh" && echo y || echo n)" = y
|
|
385
|
+
chk "11c the ledger carries no action reference" test ! "$(has_action_ref "$REAL_REFS/fix-constraints-stage-a.emitted.sha256" && echo y || echo n)" = y
|
|
386
|
+
chk "11c' the ledger carries no 40-hex string" test ! "$(has_forty_hex "$REAL_REFS/fix-constraints-stage-a.emitted.sha256" && echo y || echo n)" = y
|
|
387
|
+
|
|
388
|
+
# --- 12. Frozen Stage A to Stage B interface and privilege (asserted on the CURRENT template) -----
|
|
389
|
+
TPL="$REAL_REFS/fix-constraints-stage-a.template"
|
|
390
|
+
TPL_CODE="$TMPROOT/tpl-code"; grep -vE '^[[:space:]]*#' "$TPL" > "$TPL_CODE" || true
|
|
391
|
+
on_block() { awk '/^on:/{p=1;next} p&&/^[^ \t]/{exit} p' "$TPL_CODE"; }
|
|
392
|
+
triggers="$(on_block | grep -E '^ [a-z_]+:' | sed 's/:.*//; s/^ //' | sort | tr '\n' ' ' || true)"
|
|
393
|
+
perm_block="$(awk '/^permissions:/{p=1;next} p&&/^[^ \t]/{exit} p' "$TPL_CODE" | grep -v '^[[:space:]]*$' || true)"
|
|
394
|
+
chk "12a name is fix-constraints-stage-a (Stage B filters on it)" grep -Fxq 'name: fix-constraints-stage-a' "$TPL"
|
|
395
|
+
chk "12b artifact name prefix fix-constraints-patch- is kept (in code, not a comment)" grep -Fq 'name: fix-constraints-patch-' "$TPL_CODE"
|
|
396
|
+
chk "12b' artifact name prefix fix-constraints-giveup- is kept (in code, not a comment)" grep -Fq 'name: fix-constraints-giveup-' "$TPL_CODE"
|
|
397
|
+
chk "12c triggers are pull_request (+ workflow_dispatch for manual retry) only; got: $triggers" test "$triggers" = "pull_request workflow_dispatch "
|
|
398
|
+
chk "12d top-level permissions are exactly contents: read" test "$perm_block" = " contents: read"
|
|
399
|
+
DENY_TRIGGER='pull_request_target|workflow_run|issue_comment'
|
|
400
|
+
DENY_WRITE=':[[:space:]]*["'"'"']?write|write-all|id-token'
|
|
401
|
+
chk "12 control: the comment-stripped template body is non-empty" test -s "$TPL_CODE"
|
|
402
|
+
chk "12 control: the trigger deny pattern fires on a quoted pull_request_target key" grep -Eq "$DENY_TRIGGER" <<<' "pull_request_target":'
|
|
403
|
+
chk "12 control: the write deny pattern fires on write-all" grep -Eq "$DENY_WRITE" <<<'permissions: write-all'
|
|
404
|
+
chk "12 control: the write deny pattern fires on a quoted write value" grep -Eq "$DENY_WRITE" <<<' contents: "write"'
|
|
405
|
+
chk "12c' no privileged or chained trigger spelling anywhere in the template body (quoted keys included)" test -z "$(grep -E "$DENY_TRIGGER" "$TPL_CODE" || true)"
|
|
406
|
+
chk "12e no write scope, write-all or id-token anywhere in the template body (any quoting or flow style)" test -z "$(grep -E "$DENY_WRITE" "$TPL_CODE" || true)"
|
|
407
|
+
|
|
408
|
+
# --- 13. The run lock: an owner-less fresh lock is held, an old one is stale, EPERM is not "gone" ----
|
|
409
|
+
FX="$(new_case c13a)"; mkdir -p "$FX/.git/constraint-scaffold.lock"
|
|
410
|
+
run_refresh "$FX"
|
|
411
|
+
rcis "13a fresh lock directory with no owner pid yet is held, not taken over" 69
|
|
412
|
+
state "13a' the lock directory is untouched" test -d "$FX/.git/constraint-scaffold.lock"
|
|
413
|
+
|
|
414
|
+
FX="$(new_case c13b)"; mkdir -p "$FX/.git/constraint-scaffold.lock"; touch -t 200001010000 "$FX/.git/constraint-scaffold.lock"
|
|
415
|
+
run_refresh "$FX"
|
|
416
|
+
rcis "13b owner-less lock older than the grace window is stale and taken over" 0
|
|
417
|
+
|
|
418
|
+
FX="$(new_case c13c)"; mkdir -p "$FX/.git/constraint-scaffold.lock"; printf '1\n' > "$FX/.git/constraint-scaffold.lock/pid"
|
|
419
|
+
run_refresh "$FX"
|
|
420
|
+
root_note=""; if kill -0 1 2>/dev/null; then root_note=" (running with kill -0 rights on pid 1: the ps -p leg is NOT discriminated here)"; fi
|
|
421
|
+
rcis "13c a live process of another user (pid 1: kill -0 says EPERM) is not read as gone$root_note" 69
|
|
422
|
+
|
|
423
|
+
FX="$(new_case c13d)"; mkdir -p "$FX/.git/constraint-scaffold.lock"
|
|
424
|
+
(exit 0) & dead_pid=$!; wait "$dead_pid" || true
|
|
425
|
+
printf '%s\n' "$dead_pid" > "$FX/.git/constraint-scaffold.lock/pid"
|
|
426
|
+
run_refresh "$FX"
|
|
427
|
+
rcis "13d a FRESH lock whose owner pid is dead is stale and taken over (the owner-less grace must not hold it)" 0
|
|
428
|
+
|
|
429
|
+
# --- 14. The current template installs with npm ci: no lockfile, no refresh -------------------------
|
|
430
|
+
FX="$(new_case c14)"
|
|
431
|
+
assert_fixture_dir "$FX"
|
|
432
|
+
git -C "$FX" rm -q apps/web-platform/package-lock.json
|
|
433
|
+
git -C "$FX" commit -q -m "no lockfile"
|
|
434
|
+
run_refresh "$FX"
|
|
435
|
+
rcis "14a target without package-lock.json is refused (a bun-era install would break at npm ci)" 75
|
|
436
|
+
state "14b bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$OLD_FIXTURE"
|
|
437
|
+
state "14c no leftover temp file or lock directory" no_leftover_clean "$FX"
|
|
438
|
+
|
|
439
|
+
FX="$(new_case c14d)"
|
|
440
|
+
assert_fixture_dir "$FX"
|
|
441
|
+
git -C "$FX" rm -q --cached apps/web-platform/package-lock.json
|
|
442
|
+
git -C "$FX" commit -q -m "untrack the lockfile"
|
|
443
|
+
run_refresh "$FX"
|
|
444
|
+
rcis "14d a present but untracked package-lock.json is refused (it is absent on a clean CI clone)" 75
|
|
445
|
+
state "14e bytes unchanged" same_bytes "$FX/$FIX_A_REL" "$OLD_FIXTURE"
|
|
446
|
+
|
|
447
|
+
# --- Accounting -------------------------------------------------------------------------------------
|
|
448
|
+
if [[ $((passes + fails)) -ne "$cases" ]]; then
|
|
449
|
+
printf '\n[FATAL] accounting: passes+fails (%d) != cases (%d).\n' "$((passes + fails))" "$cases" >&2
|
|
450
|
+
printf ' A row was counted but its verdict was not recorded — that is what a neutered pass()/fail() looks like.\n' >&2
|
|
451
|
+
echo "refresh-stage-a.test.sh: $passes passed, $fails failed ($cases rows)"
|
|
452
|
+
exit 1
|
|
453
|
+
fi
|
|
454
|
+
|
|
455
|
+
# --- Anti-vacuity floor (ADR-193 #1). The literal sits directly above the `if`. -----------------------
|
|
456
|
+
MIN_ROWS=98
|
|
457
|
+
if [[ "$cases" -lt "$MIN_ROWS" ]]; then
|
|
458
|
+
printf '\n[FATAL] anti-vacuity floor: only %d row(s) ran, expected >= %d.\n' "$cases" "$MIN_ROWS" >&2
|
|
459
|
+
printf ' Rows were deleted or skipped; a green run here would be a coverage loss.\n' >&2
|
|
460
|
+
echo "refresh-stage-a.test.sh: $passes passed, $fails failed ($cases rows)"
|
|
461
|
+
exit 1
|
|
462
|
+
fi
|
|
463
|
+
|
|
464
|
+
echo "refresh-stage-a.test.sh: $passes passed, $fails failed ($cases rows)"
|
|
465
|
+
[[ "$fails" -eq 0 ]]
|