@soleur/opencode 3.378.18 → 3.379.2

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.
@@ -0,0 +1,348 @@
1
+ #!/usr/bin/env bash
2
+ # issues (2 of 2): Guard 3 (idempotency and resume) and Guard 4 (epic edits are confined to the marked section).
3
+ # Preview, --check-plan, Guard 1 and Guard 2 are in issues-guards.test.sh; both source issues-common.sh.
4
+ set -uo pipefail
5
+ source "$(dirname "${BASH_SOURCE[0]}")/issues-common.sh"
6
+ check "instrument self-test" selftest
7
+ check "the 1 s pause between writes is forced to 0 for the suite" test "$LAUNCH_CHECK_PAUSE" = 0
8
+
9
+ # ---------------------------------------------------------------- 7. Guard 3: idempotency and resume
10
+ full_case() { newcase; only_first "$R" "$1"; prev; }
11
+ full_case 7; calls_reset
12
+ with GH_STUB_FAIL_AFTER=3 -- create; FIRST_OUT="$OUT"
13
+ check "G3.1: the 4th item create fails -> created=3 and the failed ids are named" bash -c '[ "$(kv "$1" SOLEUR_LAUNCH_CHECK_ISSUES created)" = 3 ] && [ -n "$(kv "$1" SOLEUR_LAUNCH_CHECK_ISSUES failed)" ] && [ "$(kv "$1" SOLEUR_LAUNCH_CHECK_ISSUES failed)" != "-" ]' _ "$FIRST_OUT"
14
+ check "G3.1: ... and the run aborts issues-incomplete (rc 2)" abort_is 2 issues-incomplete "$FIRST_OUT"
15
+ check "G3.1: the fake tracker holds 3 items and one epic after the failure (state read from the tracker)" bash -c '[ "$1" = 3 ] && [ "$2" = 1 ]' _ "$(items_n)" "$(epics_n)"
16
+ check "G3.1: the abort and the summary carry plan=<dir> and phase=, and the exact resume command" bash -c 'c=$(cmd_line "$1"); grep -q "plan=" "$1" && grep -q "phase=" "$1" && [ -n "$c" ] && grep -q -- "--plan " <<<"$c"' _ "$FIRST_OUT"
17
+ calls_reset; create
18
+ check "G3.1: re-running the same plan completes (rc 0)" test "$RC" = 0
19
+ check "G3.1: the tracker holds 7 items and exactly one epic, each id once, all linked" bash -c '[ "$1" = 7 ] && [ "$2" = 1 ] && [ "$3" = 1 ] && [ "$4" = 7 ]' _ "$(items_n)" "$(epics_n)" "$(max_dup)" "$(linked_n)"
20
+ check "G3.1: the re-run created only the 4 missing issues (issue POSTs == 4)" test "$(n_post POST 'repos/acme/demo/issues$')" = 4
21
+ check "G3.1: created.tsv in the plan directory lists what the runs created and the plan directory survives (mode 700)" bash -c '[ -s "$1/created.tsv" ] && [ "$(ls -ld "$1" | cut -c1-10)" = drwx------ ]' _ "$PLAN"
22
+ calls_reset; create; calls_reset; create
23
+ check "G3 must-PASS: a re-run of an already complete plan records zero writes (no PATCH for a byte-identical section)" bash -c '[ "$1" = 0 ] && [ "$2" = 7 ]' _ "$(n_writes)" "$(items_n)"
24
+ full_case 7; calls_reset
25
+ with GH_STUB_TRANSPORT_ERROR_AFTER_CREATE=2 -- create
26
+ check "G3.2: a transport error right after a create (unknown outcome) ends the run non-zero with the created issues in the tracker" bash -c '[ "$1" != 0 ] && [ "$2" -ge 2 ]' _ "$RC" "$(items_n)"
27
+ before_items=$(items_n); calls_reset; create
28
+ check "G3.2: the re-run creates no duplicate and links the orphan: 7 items, 7 links, each marker once, at least 2 items existed before" bash -c '[ "$1" = 7 ] && [ "$2" = 7 ] && [ "$3" = 1 ] && [ "$4" -ge 2 ]' _ "$(items_n)" "$(linked_n)" "$(max_dup)" "$before_items"
29
+ check "G3.2: no child was linked by more than one POST in the re-run" bash -c '[ "$1" -le 1 ] && [ "$2" = 7 ]' _ "$(cj '[.[]|select(.method=="POST" and (.path|test("sub_issues$")))|.fields[]|select(.k=="sub_issue_id")|.v]|group_by(.)|map(length)|max // 0')" "$(linked_n)"
30
+ full_case 7; CLOSED_ID=$(create_ids | sed -n 1p); ORPH_ID=$(create_ids | sed -n 2p)
31
+ stub_reset acme/demo private; seed_label lc:launch-check ededed
32
+ seed 301 closed stub-user lc:launch-check "<!-- launch-check:gap=$CLOSED_ID -->"; seed 302 open stub-user lc:launch-check "<!-- launch-check:gap=$ORPH_ID -->"
33
+ prev
34
+ check "G3.3: the preview reports the closed issue by number" grep -q "#301" "$OUT"
35
+ calls_reset; create
36
+ orph_db=$(tr_q '[.[]|select(.number==302)|.id]|first'); orph_links=$(cj "[.[]|select(.method==\"POST\" and (.path|test(\"sub_issues\$\")))|.fields[]|select(.k==\"sub_issue_id\" and .v==\"$orph_db\")]|length")
37
+ check "G3.3: a closed marked issue is not recreated (one carrier of its marker, still closed)" bash -c '[ "$1" = 1 ] && [ "$2" = closed ]' _ "$(marker_n "$CLOSED_ID")" "$(tr_q '[.[]|select(.number==301)|.state]|first')"
38
+ check "G3.4: an open marked issue with no parent is not recreated and is linked exactly once" bash -c '[ "$1" = 1 ] && [ "$2" = 1 ] && [ "$3" = 302 ]' _ "$(marker_n "$ORPH_ID")" "$orph_links" "$(tr_q '[.[]|select(.parent != null and .number==302)|.number]|first')"
39
+ full_case 7; stub_reset acme/demo private; seed_label lc:severity-high 123456; prev; calls_reset; create
40
+ check "G3.6: a pre-existing lc:severity-high label is untouched: no label write names it and its colour is unchanged" bash -c '[ "$(cj "[.[]|select(.method==\"POST\" and (.path|test(\"/labels\$\")) and (.fields[]|select(.k==\"name\" and .v==\"lc:severity-high\")))]|length")" = 0 ] && [ "$(jq -r "[.[]|select(.name==\"lc:severity-high\")|.color]|first" "$1/labels.json")" = 123456 ]' _ "$ST"
41
+ check "G3.6 control: absent labels were created (lc:launch-check and lc:epic exist now)" bash -c 'jq -e "map(.name)|index(\"lc:launch-check\") != null and index(\"lc:epic\") != null" "$1/labels.json" >/dev/null' _ "$ST"
42
+ full_case 7; D_ID=$(create_ids | sed -n 1p); A_ID=$(create_ids | sed -n 2p); B_ID=$(create_ids | sed -n 3p)
43
+ stub_reset acme/demo private; seed 401 open stub-user lc:launch-check "<!-- launch-check:gap=$D_ID -->"; seed 402 open stub-user lc:launch-check "<!-- launch-check:gap=$D_ID -->"
44
+ prev; calls_reset; create
45
+ check "G3.7: duplicates of one id resolve to the lowest number (no create for it): 6 item creates + the epic" test "$(n_post POST 'repos/acme/demo/issues$')" = 7
46
+ # a several-marker issue (each marker on its own line) that names a finding of this plan stops the run before any write
47
+ full_case 7; stub_reset acme/demo private
48
+ seed 403 open stub-user lc:launch-check $'<!-- launch-check:gap='"$A_ID"$' -->\n\n<!-- launch-check:gap='"$B_ID"$' -->'
49
+ prev
50
+ check "G3.13: the preview warns about the several-marker issue and counts it as ignored" bash -c 'grep -q "^Ignored 1 issues" "$1" && grep -q "#403" "$1" && grep -q "more than one launch-check marker" "$1"' _ "$OUT"
51
+ calls_reset; create
52
+ check "G3.13: a several-marker issue that carries a marker of this plan writes nothing" bash -c '[ "$1" = 0 ]' _ "$(n_writes)"
53
+ check "G3.13: ... and aborts issue-ambiguous (rc 2)" abort_is 2 issue-ambiguous
54
+ # several-marker issues that name no finding of this plan are only ignored and counted
55
+ full_case 7; stub_reset acme/demo private
56
+ seed 404 open stub-user lc:launch-check $'<!-- launch-check:gap=ZZ-01 -->\n<!-- launch-check:gap=ZZ-02 -->'
57
+ prev; calls_reset; create
58
+ check "G3.13: a several-marker issue that names no finding of this plan is ignored: the run completes (rc 0) and files all 7 (8 issues on the tracker with the seeded one)" bash -c '[ "$1" = 0 ] && [ "$2" = 8 ]' _ "$RC" "$(items_n)"
59
+ # a several-marker issue that is an epic candidate is an ambiguous epic
60
+ full_case 3; stub_reset acme/demo private
61
+ seed 405 open stub-user lc:launch-check,lc:epic $'<!-- launch-check:epic -->\n\n<!-- launch-check:gap=ZZ-09 -->'
62
+ prev; calls_reset; create
63
+ check "G3.13: a several-marker epic candidate writes nothing" bash -c '[ "$1" = 0 ]' _ "$(n_writes)"
64
+ check "G3.13: ... and aborts epic-ambiguous (rc 2)" abort_is 2 epic-ambiguous
65
+ # a marker that is only QUOTED mid-text (or in a quote block) is not a marker: the epic stays the one epic and no second one is filed
66
+ full_case 3; stub_reset acme/demo private; seed_label lc:launch-check ededed; seed_label lc:epic ededed
67
+ QID=$(create_ids | sed -n 1p)
68
+ seed 531 open stub-user lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"$'\n\nCustomer note: we saw <!-- launch-check:gap='"$QID"$' --> in an old issue.\n> <!-- launch-check:gap=ZZ-77 -->\n'
69
+ prev; calls_reset; create
70
+ check "G3.14: an epic body that quotes a marker is still read as the one epic: rc 0, no second epic is filed" bash -c '[ "$1" = 0 ] && [ "$2" = 1 ]' _ "$RC" "$(epics_n)"
71
+ check "G3.14: ... and the quoted gap id is still filed (a quote hides nothing): its marker is carried by a sub-issue" test "$(marker_n "$QID")" -ge 1
72
+ # label-bearing issues with no usable marker (null, empty, or a marker that is not alone on its line) are ignored and counted in the preview
73
+ full_case 3; stub_reset acme/demo private
74
+ seed 611 open stub-user lc:launch-check NULL; seed 612 open stub-user lc:launch-check 'no marker here'; seed 613 open stub-user lc:launch-check 'inline <!-- launch-check:gap=ZZ-05 --> only'
75
+ prev
76
+ check "G3.15: the preview counts the three marker-less issues as ignored and names them" bash -c 'grep -q "^Ignored 3 issues" "$1" && grep -q "#611" "$1" && grep -q "#613" "$1"' _ "$OUT"
77
+ # P2 marker tolerance: a marker line followed by spaces or tabs (and an optional CR) is still a whole-line marker
78
+ for tail in ' ' $'\t' $' \t ' ; do
79
+ full_case 3; stub_reset acme/demo private; seed_label lc:launch-check ededed; seed_label lc:epic ededed
80
+ seed 501 open stub-user lc:launch-check,lc:epic "$(sed "1s/\$/$tail/" "$SAMPLE/epic.md")"
81
+ prev; calls_reset; create
82
+ check "marker tolerance: an epic whose marker line ends in trailing blanks ($(printf '%s' "$tail" | od -An -c | tr -s ' ' | tr -d '\n')) is THE epic: rc 0, no second epic is filed" bash -c '[ "$1" = 0 ] && [ "$2" = 1 ]' _ "$RC" "$(epics_n)"
83
+ check "marker tolerance: ... and the preview did not call it an epic candidate" bash -c '! grep -q "epic candidate" "$1"' _ "$SCRATCH/pv$N.out"
84
+ done
85
+ full_case 7; stub_reset acme/demo private; GA=$(create_ids | sed -n 1p); GB=$(create_ids | sed -n 2p)
86
+ seed 541 open stub-user lc:launch-check "<!-- launch-check:gap=$GA --> "; seed 542 open stub-user lc:launch-check "<!-- launch-check:gap=$GB -->"$'\t'
87
+ prev; calls_reset; create
88
+ check "marker tolerance: a gap marker with a trailing space or tab is read as filed: each of the two ids still carries exactly one marker (no duplicate)" bash -c '[ "$1" = 1 ] && [ "$2" = 1 ] && [ "$3" = 1 ]' _ "$(marker_n "$GA")" "$(marker_n "$GB")" "$(max_dup)"
89
+ check "marker tolerance: ... the preview planned only the other 5 and the create filed exactly those 5 (rc 0)" bash -c '[ "$1" = 0 ] && [ "$2" = 5 ] && [ "$3" = 7 ]' _ "$RC" "$(kv "$OUT" SOLEUR_LAUNCH_CHECK_ISSUES created)" "$(items_n)"
90
+ # the whole-line rule still holds: quoted, indented, blockquoted and trailing-text markers read as no marker
91
+ full_case 3; stub_reset acme/demo private
92
+ seed 561 open stub-user lc:launch-check ' <!-- launch-check:gap=ZZ-06 -->'; seed 562 open stub-user lc:launch-check '> <!-- launch-check:gap=ZZ-07 -->'
93
+ seed 563 open stub-user lc:launch-check '<!-- launch-check:gap=ZZ-08 --> and more text'; seed 564 open stub-user lc:launch-check $'\t<!-- launch-check:gap=ZZ-09 -->'
94
+ prev
95
+ check "marker tolerance (known-bad): indented, blockquoted, tab-indented and trailing-text markers are still NOT markers: all four are ignored" bash -c 'grep -q "^Ignored 4 issues" "$1"' _ "$OUT"
96
+ # P2 epic candidates: an lc:epic issue with no usable marker is an epic candidate, never silently skipped
97
+ for eb in NULL 'no marker at all' '> <!-- launch-check:epic -->' ' <!-- launch-check:epic -->' '<!-- launch-check:epic --> trailing words'; do
98
+ full_case 3; stub_reset acme/demo private; seed 551 open stub-user lc:launch-check,lc:epic "$eb"
99
+ prev
100
+ check "epic candidate ($eb): the preview warns that an epic candidate lost its marker, in its own words" bash -c 'grep -q "^An epic candidate carries several marker lines or lost its marker" "$1" && ! grep -q "More than one open or closed epic" "$1"' _ "$OUT"
101
+ calls_reset; create
102
+ check "epic candidate ($eb): create writes nothing" bash -c '[ "$1" = 0 ]' _ "$(n_writes)"
103
+ check "epic candidate ($eb): ... and aborts epic-ambiguous detail=ignored-epic (rc 2)" bash -c 'grep -q "reason=epic-ambiguous detail=ignored-epic" "$1"' _ "$OUT"; check "epic candidate ($eb): ... marker and rc" abort_is 2 epic-ambiguous
104
+ done
105
+ # a dead awk stops the run; it is never read as "nothing found"
106
+ full_case 7; stub_reset acme/demo private; AA=$(create_ids | sed -n 2p); AB=$(create_ids | sed -n 3p)
107
+ seed 403 open stub-user lc:launch-check $'<!-- launch-check:gap='"$AA"$' -->\n\n<!-- launch-check:gap='"$AB"$' -->'
108
+ calls_reset; with PATH="$SHIM:$PATH" AWK_DIE='($2 in id)' -- prev --plan-out "$SCRATCH/podie$N"
109
+ check "awk dies (preview, ignored-issue scan): the preview stops issues-incomplete phase=lookup (rc 2), prints no plan marker and writes no plan" bash -c 'grep -q "reason=issues-incomplete phase=lookup detail=malformed" "$1" && ! grep -q "^SOLEUR_LAUNCH_CHECK_ISSUES_PLAN" "$1" && [ -z "$(ls -A "$2" 2>/dev/null)" ]' _ "$OUT" "$SCRATCH/podie$N"; check "awk dies (preview): ... marker and rc" abort_is 2 issues-incomplete
110
+ prev
111
+ calls_reset; with PATH="$SHIM:$PATH" AWK_DIE='($2 in id)' -- create
112
+ check "awk dies (create, live gate): a several-marker issue naming a plan gap with a dead scan writes nothing and stops issues-incomplete phase=lookup (rc 2), never proceeds as 'no hit'" bash -c '[ "$1" = 0 ] && grep -q "phase=lookup detail=malformed" "$2"' _ "$(n_writes)" "$OUT"; check "awk dies (create, live gate): ... marker and rc" abort_is 2 issues-incomplete
113
+ calls_reset; create
114
+ check "awk dies (control): the same plan without the shim hits the real gate (issue-ambiguous, rc 2)" abort_is 2 issue-ambiguous
115
+ full_case 3; calls_reset; with PATH="$SHIM:$PATH" AWK_DIE='[xX]' -- create
116
+ check "awk dies (epic section, ticked boxes): the run stops issues-incomplete phase=epic detail=malformed (rc 2) and the epic is not rewritten" bash -c 'grep -q "phase=epic detail=malformed" "$1" && [ "$2" = 0 ]' _ "$OUT" "$(n_post PATCH 'issues/[0-9]+$')"; check "awk dies (epic section, ticked boxes): ... marker and rc" abort_is 2 issues-incomplete
117
+ full_case 4; calls_reset; with GH_STUB_SUBISSUE=403 PATH="$SHIM:$PATH" AWK_DIE='print $2, $1 }' -- create
118
+ check "awk dies (task list, item numbers): the run stops issues-incomplete phase=epic detail=malformed (rc 2) and the epic is not rewritten with an empty task list" bash -c 'grep -q "phase=epic detail=malformed" "$1" && [ "$2" = 0 ]' _ "$OUT" "$(n_post PATCH 'issues/[0-9]+$')"; check "awk dies (task list): ... marker and rc" abort_is 2 issues-incomplete
119
+ # the link-failure policy is one rule at both sites: the children listing of an existing epic follows it too
120
+ full_case 3; stub_reset acme/demo private; seed_label lc:launch-check ededed; seed_label lc:epic ededed; seed 531 open stub-user lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"
121
+ prev; calls_reset; with GH_STUB_SUBISSUE=ratelimit -- create
122
+ check "link policy (children listing): a rate limit on the listing of an existing epic's children stops the run issues-incomplete phase=link before any item is filed" bash -c 'grep -q "phase=link" "$1" && [ "$2" = 0 ]' _ "$OUT" "$(n_post POST 'repos/acme/demo/issues$')"; check "link policy (children listing): ... marker and rc" abort_is 2 issues-incomplete
123
+ calls_reset; with GH_STUB_SUBISSUE=403 -- create
124
+ check "link policy (children listing): a 403 on that listing latches the run to the task list (rc 0, fallback=task-list)" bash -c '[ "$1" = 0 ] && [ "$(kv "$2" SOLEUR_LAUNCH_CHECK_ISSUES fallback)" = task-list ]' _ "$RC" "$OUT"
125
+ full_case 3; stub_reset acme/demo private; seed 501 closed stub-user lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"
126
+ prev
127
+ check "G3.8: preview prints a plain warning for a closed epic" bash -c 'grep -qi "closed" "$1" && grep -qi "epic" "$1"' _ "$OUT"
128
+ calls_reset; create
129
+ check "G3.8: create writes nothing and says how to recover (reopen it or remove the lc:epic label)" bash -c '[ "$1" = 0 ] && grep -qi "reopen" "$2"' _ "$(n_writes)" "$OUT"
130
+ check "G3.8: create aborts epic-closed (rc 2)" abort_is 2 epic-closed
131
+ full_case 3; stub_reset acme/demo private; seed 511 open stub-user lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"; seed 512 open stub-user lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"
132
+ prev; calls_reset; create
133
+ check "G3.8: two labelled epic candidates write nothing" bash -c '[ "$1" = 0 ]' _ "$(n_writes)"
134
+ check "G3.8: ... and abort epic-ambiguous (rc 2)" abort_is 2 epic-ambiguous
135
+ full_case 3; stub_reset acme/demo private; seed 521 open someone-else lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"
136
+ prev; calls_reset; create
137
+ check "G3.12: an epic authored by another login writes nothing and names epic-author" bash -c '[ "$1" = 0 ] && grep -q "epic-author" "$2"' _ "$(n_writes)" "$OUT"
138
+ check "G3.12: ... and aborts plan-invalid (rc 2)" abort_is 2 plan-invalid
139
+ check "G3.12: the abort carries its own recovery text (remove the lc:epic label or run as its author; do not preview again)" bash -c 'grep -qi "lc:epic" "$1" && grep -qi "created" "$1" && grep -qi "do not preview again" "$1"' _ "$OUT"
140
+ full_case 3; stub_reset acme/demo private; seed 522 open someone-else lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"
141
+ prev
142
+ check "G3.12: the PREVIEW already warns that the epic was created by another account" bash -c 'grep -qi "another account" "$1"' _ "$OUT"
143
+ full_case 3; stub_reset acme/demo private; seed 523 open stub-user lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"
144
+ prev
145
+ check "G3.12: ... and says nothing of the kind when the epic is the signed-in account's own" bash -c '! grep -qi "another account" "$1"' _ "$OUT"
146
+ # an enterprise-managed login holds an underscore (jdoe_acme): it must be read as the author, not as "-"
147
+ full_case 3; stub_reset acme/demo private; seed 524 open jdoe_acme lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"
148
+ with GH_STUB_LOGIN=jdoe_acme -- prev; calls_reset; with GH_STUB_LOGIN=jdoe_acme -- create
149
+ check "G3.12: an epic authored by jdoe_acme and a run as jdoe_acme proceed (rc 0, one epic, no second epic filed)" bash -c '[ "$1" = 0 ] && [ "$2" = 1 ]' _ "$RC" "$(epics_n)"
150
+ for st in 403 404 410 422; do
151
+ full_case 4; calls_reset; with GH_STUB_SUBISSUE=$st -- create
152
+ check "G3.9 (UNVERIFIED-STUB-ONLY $st): the first failed link latches the run to the task list: one link call, rc 0, fallback=task-list" bash -c '[ "$1" = 1 ] && [ "$2" = 0 ] && [ "$(kv "$3" SOLEUR_LAUNCH_CHECK_ISSUES fallback)" = task-list ]' _ "$(n_post POST 'sub_issues$')" "$RC" "$OUT"
153
+ epic_body_to "$SCRATCH/epic.fb"
154
+ check "G3.9 ($st): the epic section lists every created item as an unchecked task line" bash -c '[ "$(grep -c "^- \[ \] #[0-9]" "$1")" = 4 ]' _ "$SCRATCH/epic.fb"
155
+ done
156
+ # L1: a rate limit, a 5xx or a transport failure on a link says nothing about the feature, so it stops the run resumably (phase=link)
157
+ for st in ratelimit 502; do
158
+ full_case 4; calls_reset; with GH_STUB_SUBISSUE=$st -- create; LNK_OUT="$OUT"
159
+ check "L1 ($st): a failed link is not latched to the task list: the run stops issues-incomplete phase=link (rc 2) with fallback=none" bash -c '[ "$1" = 2 ] && grep -q "phase=link" "$2" && [ "$(kv "$2" SOLEUR_LAUNCH_CHECK_ISSUES fallback)" = none ]' _ "$RC" "$LNK_OUT"
160
+ check "L1 ($st): ... and the resume command is printed" bash -c 'c=$(cmd_line "$1"); [ -n "$c" ] && grep -q -- "--plan " <<<"$c"' _ "$LNK_OUT"
161
+ check "L1 ($st): ... after exactly one link attempt (the first failure stops the run)" test "$(n_post POST 'sub_issues$')" = 1
162
+ [ "$st" != ratelimit ] || check "L1 (ratelimit): the rate-limit hint is printed with the stopped run" bash -c 'grep -qi "rate" "$1"' _ "$LNK_OUT"
163
+ calls_reset; create
164
+ check "L1 ($st): the re-run completes (rc 0) with real links for all 4 items and each marker once" bash -c '[ "$1" = 0 ] && [ "$2" = 4 ] && [ "$3" = 1 ] && [ "$4" = none ]' _ "$RC" "$(linked_n)" "$(max_dup)" "$(kv "$OUT" SOLEUR_LAUNCH_CHECK_ISSUES fallback)"
165
+ done
166
+ # one progress line per item as it happens (an agent shell with a 120 s default timeout must see progress before the end)
167
+ check "progress: a stopped run printed one created line and one linked line per item already made, before the summary" bash -c '[ "$(grep -c "^created: #" "$1")" = 3 ] && [ "$(grep -c "^linked: #" "$1")" = 3 ] && [ "$(grep -n "^created: #" "$1" | tail -n 1 | cut -d: -f1)" -lt "$(grep -n "^SOLEUR_LAUNCH_CHECK_ISSUES " "$1" | head -n 1 | cut -d: -f1)" ]' _ "$FIRST_OUT"
168
+ # a signal ends the run: the summary and the resume command come first when a write was attempted (the exit code is 128 plus the signal)
169
+ sigrun() { # sigrun <TERM|HUP>: start create against a stub whose item create sleeps, signal it in that window
170
+ ( exec env -u GIT_DIR -u GIT_INDEX_FILE -u GIT_WORK_TREE -u GIT_OBJECT_DIRECTORY -u GIT_COMMON_DIR -u GIT_NAMESPACE GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null \
171
+ GH_STUB_SLEEP=2 bash "${LCS:-$LC}" issues --create --target "$R" --facts "$FACTS" --judged "$JUD" --plan "$PLAN" --confirm-repo acme/demo --confirm-count "$(plan_n)" ) > "$SCRATCH/sig.$1.out" 2>&1 &
172
+ local pid=$! i
173
+ for i in $(seq 1 600); do [ "$(n_post POST 'repos/acme/demo/issues$')" -ge 2 ] && break; sleep 0.1; done
174
+ kill -s "$1" "$pid"; wait "$pid"; RC=$?; OUT="$SCRATCH/sig.$1.out"
175
+ }
176
+ # A shell that inherited SIGHUP as ignored (a run under nohup) can neither trap it nor be hung up: that is the environment, not the tool.
177
+ hup_ignored() { local m; m=$(awk '/^SigIgn:/ {print $2}' /proc/$$/status 2>/dev/null); [ -n "$m" ] && [ $((16#$m & 1)) -ne 0 ]; }
178
+ for sg in TERM HUP; do
179
+ if [ "$sg" = HUP ] && hup_ignored; then
180
+ for _ in 1 2 3; do check "signal (HUP): not applicable here, this run inherited SIGHUP as ignored (nohup); the TERM rows cover the handler" true; done
181
+ continue
182
+ fi
183
+ full_case 4; calls_reset; sigrun $sg; want=143; [ "$sg" = HUP ] && want=129
184
+ check "signal ($sg): exit code $want, the summary says phase=interrupted and the exact resume command is printed" bash -c '[ "$1" = "$2" ] && grep -q "^SOLEUR_LAUNCH_CHECK_ISSUES .*phase=interrupted" "$3" && [ -n "$(cmd_line "$3")" ] && grep -q -- "--plan " <<<"$(cmd_line "$3")" && grep -q "reason=issues-incomplete phase=interrupted" "$3"' _ "$RC" "$want" "$OUT"
185
+ check "signal ($sg): the interrupted run had written (anti-vacuous: at least the epic and one item exist)" test "$(n_writes)" -ge 2
186
+ calls_reset; create
187
+ check "signal ($sg): the resume completes (rc 0) with 4 items, one epic, each marker once, all linked" bash -c '[ "$1" = 0 ] && [ "$2" = 4 ] && [ "$3" = 1 ] && [ "$4" = 1 ] && [ "$5" = 4 ]' _ "$RC" "$(items_n)" "$(epics_n)" "$(max_dup)" "$(linked_n)"
188
+ done
189
+ full_case 3; one=$(create_ids | sed -n 1p); sed "s/^finding $one open\$/finding $one accepted 2026-11-03 accepted after the preview/" "$R/$REPORT_REL" > "$R/r.new" && mv "$R/r.new" "$R/$REPORT_REL"
190
+ calls_reset; create
191
+ check "G3.10: accepting a finding after the preview makes create write nothing" bash -c '[ "$1" = 0 ]' _ "$(n_writes)"
192
+ check "G3.10: ... and abort report-stale (rc 2)" abort_is 2 report-stale
193
+ full_case 3; jq '.visibility="public"' "$ST/repo.json" > "$ST/r.new" && mv "$ST/r.new" "$ST/repo.json"; calls_reset; create
194
+ check "G3: a plan recorded PRIVATE against a LIVE PUBLIC repo writes nothing" bash -c '[ "$1" = 0 ]' _ "$(n_writes)"
195
+ check "G3: ... and aborts confirm-public-required (rc 2)" abort_is 2 confirm-public-required
196
+ create --confirm-public
197
+ check "G3: --confirm-public makes the same run proceed" bash -c '[ "$1" = 0 ] && [ "$2" -gt 0 ]' _ "$RC" "$(n_writes)"
198
+ full_case 7; jq '.visibility="public"' "$ST/repo.json" > "$ST/r.new" && mv "$ST/r.new" "$ST/repo.json"; calls_reset; with GH_STUB_FAIL_AFTER=3 -- create --confirm-public
199
+ check "resume hint (public): the stopped run prints the resume command WITHOUT --confirm-public, and the separate line that names it" bash -c 'c=$(cmd_line "$1"); [ -n "$c" ] && ! grep -q -- "--confirm-public" <<<"$c" && grep -q "append --confirm-public" "$1"' _ "$OUT"
200
+ check "resume hint (public): the stopped run is issues-incomplete (anti-vacuous: the hint was printed by a real failure)" abort_is 2 issues-incomplete
201
+ full_case 7; calls_reset; with GH_STUB_FAIL_AFTER=3 -- create
202
+ check "resume hint (private): the resume command is printed and no --confirm-public line appears" bash -c 'c=$(cmd_line "$1"); [ -n "$c" ] && ! grep -q -- "--confirm-public" "$1"' _ "$OUT"
203
+ full_case 3; jq '.visibility="internal"' "$ST/repo.json" > "$ST/r.new" && mv "$ST/r.new" "$ST/repo.json"; calls_reset; create
204
+ check "G3: an internal repository is gated like a public one (confirm-public-required)" abort_is 2 confirm-public-required
205
+ # a repository whose visibility the API did not give (the field missing, or a value this tool does not know) is UNKNOWN, and UNKNOWN is gated
206
+ for vz in missing weird; do
207
+ full_case 3
208
+ if [ "$vz" = missing ]; then jq 'del(.visibility)' "$ST/repo.json" > "$ST/r.new"; else jq '.visibility="weird"' "$ST/repo.json" > "$ST/r.new"; fi
209
+ mv "$ST/r.new" "$ST/repo.json"; calls_reset; create
210
+ check "G3: a $vz visibility is read as UNKNOWN and gated like a public repository: zero writes" bash -c '[ "$1" = 0 ]' _ "$(n_writes)"
211
+ check "G3: ... aborts confirm-public-required naming visibility=UNKNOWN (rc 2)" bash -c 'grep -q "visibility=UNKNOWN" "$1"' _ "$OUT"; check "G3: ... marker and rc ($vz visibility)" abort_is 2 confirm-public-required
212
+ create --confirm-public
213
+ check "G3: --confirm-public makes the same $vz-visibility run proceed" bash -c '[ "$1" = 0 ] && [ "$2" -gt 0 ]' _ "$RC" "$(n_writes)"
214
+ done
215
+ full_case 3; calls_reset; create
216
+ check "G1 must-PASS: a PRIVATE repository runs without --confirm-public" bash -c '[ "$1" = 0 ]' _ "$RC"
217
+ full_case 3; calls_reset; with GH_STUB_LIST=fail -- create
218
+ check "G3.11: a failed listing writes nothing and says phase=lookup (never read as none found)" bash -c '[ "$1" = 0 ] && grep -q "phase=lookup" "$2"' _ "$(n_writes)" "$OUT"
219
+ check "G3.11: ... and aborts issues-incomplete (rc 2)" abort_is 2 issues-incomplete
220
+ calls_reset; with GH_STUB_LIST=malformed -- create
221
+ check "G3.11 (UNVERIFIED-STUB-ONLY): malformed listing output writes nothing and says phase=lookup" bash -c '[ "$1" = 0 ] && grep -q "phase=lookup" "$2"' _ "$(n_writes)" "$OUT"
222
+ calls_reset; with GH_STUB_LIST=emptyfail -- create
223
+ check "G3.11: a listing call that fails with NOTHING on stdout and stderr is not 'none found': zero writes and phase=lookup" bash -c '[ "$1" = 0 ] && grep -q "phase=lookup" "$2"' _ "$(n_writes)" "$OUT"
224
+ check "G3.11: ... and aborts issues-incomplete (rc 2)" abort_is 2 issues-incomplete
225
+ stub_reset acme/demo private; seed 601 open stub-user lc:launch-check NULL; seed 602 open stub-user lc:launch-check ''; seed 603 open stub-user lc:launch-check 'no marker here'
226
+ calls_reset; create
227
+ check "G3.11 (UNVERIFIED-STUB-ONLY, gojq null handling): null, empty and marker-less bodies are ignored cleanly and the run completes" bash -c '[ "$1" = 0 ] && [ "$2" = 3 ]' _ "$RC" "$(tr_q '[.[]|select(.number>=100 and .number<600)|select(.labels|map(.name)|index("lc:epic")|not)]|length')"
228
+ full_case 3; ID3=$(create_ids | sed -n 3p); stub_reset acme/demo private
229
+ for i in 1 2 3 4 5; do seed $((700 + i)) closed stub-user lc:launch-check "<!-- launch-check:gap=ZZ-0$i -->"; done; seed 706 closed stub-user lc:launch-check "<!-- launch-check:gap=$ID3 -->"
230
+ calls_reset; with GH_STUB_PER_PAGE=2 -- create
231
+ maxpages=$(awk -F'\t' '{ if ($2 + 0 > m) m = $2 + 0 } END { print m + 0 }' "$ST/pages.log" 2>/dev/null)
232
+ check "G3: a listing forced onto at least 3 pages is read completely (the id on the last page is not recreated)" bash -c '[ "$1" -ge 3 ] && [ "$2" = 1 ]' _ "$maxpages" "$(marker_n "$ID3")"
233
+ full_case 7; with GH_STUB_FAIL_AFTER=3 -- create; calls_reset; with LC_TEST_NOLIVE=1 -- create
234
+ check "G3.5 mutation: with the live lookup removed from the re-run, duplicates appear (so the resume rows are sensitive)" bash -c '[ "$1" -ge 2 ] || [ "$2" -gt 7 ]' _ "$(max_dup)" "$(items_n)"
235
+ full_case 7; calls_reset; with GH_STUB_FAIL_AFTER=2 GH_STUB_FAIL_KIND=ratelimit -- create
236
+ check "G3: a rate-limit failure names the rate limit and the re-run line" bash -c 'grep -qi "rate" "$1" && grep -q -- "--create" "$1"' _ "$OUT"
237
+ check "G3: ... and stops the run issues-incomplete (rc 2)" abort_is 2 issues-incomplete
238
+ calls_reset; create
239
+ check "G3: the re-run after a rate limit completes with 7 items" bash -c '[ "$1" = 0 ] && [ "$2" = 7 ]' _ "$RC" "$(items_n)"
240
+ full_case 7; calls_reset; with GH_STUB_FAIL_AFTER=1 GH_STUB_FAIL_KIND=secret -- create
241
+ check "G2.12: a secret-shaped string on the stub's stderr never reaches stdout or stderr of the run, nor the raw HTTP line" bash -c '! grep -qF -- "$1" "$2" && ! grep -qF "token=" "$2" && ! grep -q "HTTP 502" "$2"' _ "$(stub_secret)" "$OUT"
242
+ check "G2.12: a failed write still yields the closed-token summary line" grep -q "^SOLEUR_LAUNCH_CHECK_ISSUES " "$OUT"
243
+ check "G2: every printed line of a failed create passes lc_scrub (no tab or carriage return)" bash -c 'grep -q "^SOLEUR_LAUNCH_CHECK_ISSUES " "$1" && ! grep -q "$(printf "\t")" "$1" && ! grep -q "$(printf "\r")" "$1"' _ "$OUT"
244
+ full_case 3; TMPD="$SCRATCH/tmpd"; mkdir -p "$TMPD"; with TMPDIR="$TMPD" -- create
245
+ check "no lc-work or lc-gate temp file is left behind after a create (only the plan directory survives)" bash -c '[ "$1" = 0 ] && [ -z "$(ls -A "$2")" ]' _ "$RC" "$TMPD"
246
+
247
+ # every remaining call that can fail ends the run in a closed abort that names its phase, with no raw tracker text; the re-run completes
248
+ for rp in labels-get:lookup labels-post:create epic-post:epic epic-patch:epic; do
249
+ route=${rp%%:*}; ph=${rp#*:}
250
+ full_case 3; calls_reset; with GH_STUB_FAIL_ROUTE=$route -- create; RT_OUT="$OUT"; RT_ITEMS=$(items_n); RT_EPICS=$(epics_n)
251
+ check "failed call ($route): the run stops issues-incomplete phase=$ph detail=http-500 (rc 2)" bash -c 'grep -q "reason=issues-incomplete phase=$2 detail=http-500" "$1"' _ "$RT_OUT" "$ph"; check "failed call ($route): ... marker and rc" abort_is 2 issues-incomplete "$RT_OUT"
252
+ check "failed call ($route): ... no raw tracker text reaches the output (no HTTP line, no server message)" bash -c '! grep -qE "HTTP [0-9]{3}|Server Error" "$1"' _ "$RT_OUT"
253
+ case "$route" in
254
+ labels-get) check "failed call ($route): ... before the first write" test "$(n_writes)" = 0 ;;
255
+ labels-post) check "failed call ($route): ... before any issue exists" bash -c '[ "$1" = 0 ] && [ "$2" = 0 ]' _ "$RT_ITEMS" "$RT_EPICS" ;;
256
+ epic-post) check "failed call ($route): ... no item and no epic exists" bash -c '[ "$1" = 0 ] && [ "$2" = 0 ]' _ "$RT_ITEMS" "$RT_EPICS" ;;
257
+ epic-patch) check "failed call ($route): ... the items and the epic exist, only the epic section is unwritten" bash -c '[ "$1" = 3 ] && [ "$2" = 1 ]' _ "$RT_ITEMS" "$RT_EPICS" ;;
258
+ esac
259
+ calls_reset; create
260
+ check "failed call ($route): the re-run completes (rc 0) with 3 items, one epic, each marker once" bash -c '[ "$1" = 0 ] && [ "$2" = 3 ] && [ "$3" = 1 ] && [ "$4" = 1 ]' _ "$RC" "$(items_n)" "$(epics_n)" "$(max_dup)"
261
+ done
262
+ # the signed-in login is read before anything is written when an epic already exists
263
+ full_case 3; stub_reset acme/demo private; seed 531 open stub-user lc:launch-check,lc:epic "$(cat "$SAMPLE/epic.md")"; prev; calls_reset; with GH_STUB_FAIL_ROUTE=user-get -- create
264
+ check "failed call (user-get): the author check cannot read the login: phase=lookup, zero writes, no raw text" bash -c 'grep -q "reason=issues-incomplete phase=lookup detail=http-500" "$1" && [ "$2" = 0 ] && ! grep -qE "HTTP [0-9]{3}|Server Error" "$1"' _ "$OUT" "$(n_writes)"; check "failed call (user-get): ... marker and rc" abort_is 2 issues-incomplete
265
+ # a paginated listing that dies after its first page is not a complete listing
266
+ full_case 3; stub_reset acme/demo private; for i in 1 2 3 4 5; do seed $((800 + i)) closed stub-user lc:launch-check "<!-- launch-check:gap=ZZ-0$i -->"; done
267
+ prev; calls_reset; with GH_STUB_PER_PAGE=2 GH_STUB_PAGE_FAIL_AFTER=1 -- create
268
+ check "interrupted pagination: a listing that fails after page 1 stops the run phase=lookup with zero writes (a partial listing is never 'the issues that exist')" bash -c '[ "$1" = 0 ] && grep -q "phase=lookup" "$2"' _ "$(n_writes)" "$OUT"; check "interrupted pagination: ... marker and rc" abort_is 2 issues-incomplete
269
+ # a label someone else created after the listing (already_exists on the label POST, its detail on stdout where the CLI puts it) is not a failure
270
+ full_case 7; PVOUT_L="$OUT"; for lbl in $(sed -n 's/^Labels ensured if absent (.*): \(.*\)\.$/\1/p' "$PVOUT_L"); do seed_label "$lbl" ededed; done
271
+ calls_reset; with GH_STUB_LABELS_STALE=1 -- create
272
+ check "label race: the labels listing misses labels that exist, the POST answers 422 already_exists, and the run goes on (rc 0, all 7 items filed)" bash -c '[ "$1" = 0 ] && [ "$2" = 7 ] && [ "$(jq -r "length" "$3/labels.json")" -ge 4 ]' _ "$RC" "$(items_n)" "$ST"
273
+ check "label race (anti-vacuous): the stale listing really led to label POSTs that the stub answered with 422" bash -c '[ "$(cj "[.[]|select(.method==\"POST\" and (.path|test(\"/labels\$\")))]|length")" -ge 4 ]' _
274
+
275
+ # the preview names the labels the create will ensure, and the set it prints is the set the create then holds
276
+ full_case 7; PVOUT="$OUT"; calls_reset; create
277
+ check "labels: the preview prints 'Labels ensured if absent' and the create consent text mentions the absent labels" bash -c 'grep -q "^Labels ensured if absent" "$1" && grep -q "create the absent labels" "$1"' _ "$PVOUT"
278
+ check "labels: the create succeeded (rc 0, all 7 items, so every label an issue carries existed) and the set the preview printed equals the set the stub holds after it (all were absent)" bash -c 'printed=$(sed -n "s/^Labels ensured if absent (.*): \(.*\)\.\$/\1/p" "$1" | tr " " "\n" | sort | tr "\n" " "); have=$(jq -r ".[].name" "$2/labels.json" | sort | tr "\n" " "); [ -n "$printed" ] && [ "$printed" = "$have" ] && [ "$(wc -w <<<"$printed")" -ge 4 ] && [ "$3" = 0 ] && [ "$4" = 7 ] && [ "$(jq -r "[.[].labels[].name]|unique|length" "$2/issues.json")" -le "$(wc -w <<<"$printed")" ]' _ "$PVOUT" "$ST" "$RC" "$(items_n)"
279
+
280
+ # the pause between writes is real when no test seam is set: N writes -> N-1 sleeps of 1 s, none before the first write
281
+ PSHIM="$SCRATCH/sleepshim"; mkdir -p "$PSHIM"
282
+ cat > "$PSHIM/sleep" <<'EOS'
283
+ #!/usr/bin/env bash
284
+ # records how many tracker writes had been made when it was called, and its argument; returns at once
285
+ printf '%s\t%s\n' "$(jq -s '[.[]|select(.class=="write")]|length' "$ST/calls.log" 2>/dev/null || echo '?')" "$*" >> "$SLEEP_LOG"
286
+ exit 0
287
+ EOS
288
+ chmod +x "$PSHIM/sleep"
289
+ full_case 4; calls_reset; : > "$SCRATCH/sleep.log"
290
+ env -u LAUNCH_CHECK_TEST -u LAUNCH_CHECK_PAUSE -u GIT_DIR -u GIT_INDEX_FILE -u GIT_WORK_TREE -u GIT_OBJECT_DIRECTORY -u GIT_COMMON_DIR -u GIT_NAMESPACE \
291
+ GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null PATH="$PSHIM:$PATH" SLEEP_LOG="$SCRATCH/sleep.log" ST="$ST" \
292
+ bash "${LCS:-$LC}" issues --create --target "$R" --facts "$FACTS" --judged "$JUD" --plan "$PLAN" --confirm-repo acme/demo --confirm-count "$(plan_n)" > "$SCRATCH/pause.out" 2>&1; RC=$?
293
+ PW=$(n_writes)
294
+ check "pause: the run with no test seam completed (rc 0) and made at least 5 writes (anti-vacuous)" bash -c '[ "$1" = 0 ] && [ "$2" -ge 5 ]' _ "$RC" "$PW"
295
+ check "pause: N writes -> exactly N-1 sleeps, each of 1 second, the k-th taken after k writes (so none before the first)" bash -c 'n=$1; [ "$(wc -l < "$2" | tr -d " ")" = $((n - 1)) ] && [ "$(cut -f2 "$2" | sort -u)" = 1 ] && [ "$(cut -f1 "$2" | paste -s -d, -)" = "$(seq 1 $((n - 1)) | paste -s -d, -)" ]' _ "$PW" "$SCRATCH/sleep.log"
296
+
297
+ # ---------------------------------------------------------------- 8. Guard 4: epic edits are confined to the marked section
298
+ custom_epic() { # customer text before and after the markers, using the words begin and end without the marker syntax
299
+ tracker_edit '(.[] | select(.labels|map(.name)|index("lc:epic")) | .body) |= ("CUSTOMER-TOP begin and end are just words here\n" + . + "\nCUSTOMER-BOTTOM\n")'
300
+ }
301
+ full_case 7; with GH_STUB_FAIL_AFTER=3 -- create; custom_epic; epic_body_to "$SCRATCH/e.before"; calls_reset; create; epic_body_to "$SCRATCH/e.after"
302
+ check "G4.1: customer text before and after the markers is byte-identical after a re-run that rewrote the section" bash -c 'outside "$1" > "$3"; outside "$2" > "$4"; cmp -s "$3" "$4" && grep -q CUSTOMER-TOP "$4" && grep -q CUSTOMER-BOTTOM "$4"' _ "$SCRATCH/e.before" "$SCRATCH/e.after" "$SCRATCH/o1" "$SCRATCH/o2"
303
+ check "G4.1 harness row: the re-run really rewrote the section (a PATCH was recorded and the body changed)" bash -c '[ "$1" -ge 1 ] && ! cmp -s "$2" "$3"' _ "$(n_post PATCH 'issues/[0-9]+$')" "$SCRATCH/e.before" "$SCRATCH/e.after"
304
+ check "G4 must-PASS: customer text containing the words begin and end (without marker syntax) survives" grep -q "CUSTOMER-TOP begin and end are just words here" "$SCRATCH/e.after"
305
+ order=$(cj '[.[]|select(.path|test("issues/[0-9]+$"))|.method]|join(",")')
306
+ check "G4: the call order on the epic is GET then PATCH (the body is read just before the splice)" bash -c 'case "$1" in *GET*PATCH*) exit 0 ;; esac; exit 1' _ "$order"
307
+ for mode in get write; do
308
+ full_case 7; with GH_STUB_FAIL_AFTER=3 -- create; custom_epic; calls_reset; with GH_STUB_EDIT_EPIC_BETWEEN=$mode -- create; epic_body_to "$SCRATCH/e.mid"
309
+ check "G4.2: a customer edit made mid-run ($mode) survives the splice (the epic body is re-read just before it)" bash -c 'grep -q CUSTOMER-EDIT-MIDRUN "$1" && [ -s "$2/events.log" ]' _ "$SCRATCH/e.mid" "$ST"
310
+ done
311
+ full_case 7; with GH_STUB_FAIL_AFTER=3 -- create
312
+ tracker_edit '(.[] | select(.labels|map(.name)|index("lc:epic")) | .body) |= sub("<!-- launch-check:end -->"; "")'
313
+ calls_reset; create
314
+ check "G4.3: a deleted end marker -> no PATCH is recorded and the summary says epic-section=markers-damaged" bash -c '[ "$1" = 0 ] && [ "$(kv "$2" SOLEUR_LAUNCH_CHECK_ISSUES created)" != "" ] && [ "$(kv "$2" SOLEUR_LAUNCH_CHECK_ISSUES epic-section)" = markers-damaged ]' _ "$(n_post PATCH 'issues/[0-9]+$')" "$OUT"
315
+ full_case 7; with GH_STUB_FAIL_AFTER=3 -- create
316
+ tracker_edit '(.[] | select(.labels|map(.name)|index("lc:epic")) | .body) |= (. + "\n<!-- launch-check:begin -->\n")'
317
+ calls_reset; create
318
+ check "G4.4: a duplicated begin marker -> no PATCH is recorded (the run itself created the items)" bash -c '[ "$1" = 0 ] && [ "$2" = 7 ]' _ "$(n_post PATCH 'issues/[0-9]+$')" "$(items_n)"
319
+ full_case 7; calls_reset; with GH_STUB_FAIL_AFTER=3 GH_STUB_CRLF=1 -- create; custom_epic
320
+ tracker_edit '(.[] | select(.labels|map(.name)|index("lc:epic")) | .body) |= gsub("\r?\n"; "\r\n")'
321
+ epic_body_to "$SCRATCH/c.before"; create; epic_body_to "$SCRATCH/c.after"
322
+ check "G4.5: an epic stored with CRLF: the section is rewritten and the CRLF bytes outside it are preserved" bash -c 'outside "$1" > "$3"; outside "$2" > "$4"; cmp -s "$3" "$4" && grep -q "$(printf "\r")" "$4" && ! cmp -s "$1" "$2"' _ "$SCRATCH/c.before" "$SCRATCH/c.after" "$SCRATCH/o3" "$SCRATCH/o4"
323
+ full_case 4; with GH_STUB_SUBISSUE=404 -- create
324
+ tracker_edit '(.[] | select(.labels|map(.name)|index("lc:epic")) | .body) |= sub("- \\[ \\] #"; "- [x] #")'
325
+ calls_reset; with GH_STUB_SUBISSUE=404 -- create; epic_body_to "$SCRATCH/t.after"
326
+ check "G4.9: a task line the customer ticked stays ticked after a re-run" bash -c '[ "$(grep -c "^- \[x\] #" "$1")" -ge 1 ]' _ "$SCRATCH/t.after"
327
+ check "G4: the marked section carries the last run's counts (the record that outlives the terminal)" bash -c 'grep -qiE "created|skipped|failed" < <(awk "/<!-- launch-check:begin -->/{f=1;next} /<!-- launch-check:end -->/{f=0} f" "$1")' _ "$SCRATCH/t.after"
328
+ full_case 7; with GH_STUB_FAIL_AFTER=3 -- create; custom_epic
329
+ tracker_edit '(.[] | select(.labels|map(.name)|index("lc:epic")) | .body) |= (. + "\ncustomer pasted '"$(gl_only_secret)"'\n")'
330
+ calls_reset; : > "$GL_ON"; with LAUNCH_CHECK_GITLEAKS="$SCRATCH/gl-toggle.sh" -- create; rm -f "$GL_ON"
331
+ check "G4 carve-out: customer-owned bytes outside the markers are carried unchanged and not re-judged (rc 0, the text is still in the epic)" bash -c '[ "$1" = 0 ] && grep -qF "customer pasted" < <(jq -r "[.[]|select(.labels|map(.name)|index(\"lc:epic\"))][0].body" "$2")' _ "$RC" "$ST/issues.json"
332
+ cat > "$SCRATCH/splice-mut.sh" <<'EOF'
333
+ lc_epic_splice() { cat "$2"; }
334
+ EOF
335
+ SB1=$(mk_sbx splice); inject "$SB1" "$SCRATCH/seams.sh"; inject "$SB1" "$SCRATCH/splice-mut.sh"
336
+ check "G4.6 mutation landed (the sandbox differs from the pristine copy and still parses)" bash -c 'bash -n "$1" && ! cmp -s "$1" "$2"' _ "$SB1" "$SB0"
337
+ splice_scn() { # splice_scn <lc script>: customer text outside the markers survives a rewrite (return 0 = the property holds)
338
+ LCS="$1"; full_case 7; with GH_STUB_FAIL_AFTER=3 -- create; custom_epic; create; epic_body_to "$SCRATCH/s.after"; grep -q CUSTOMER-BOTTOM "$SCRATCH/s.after"
339
+ }
340
+ splice_scn "$SB0"; rc=$?
341
+ check "G4.6 control: the pristine copy keeps the customer text" test "$rc" = 0
342
+ splice_scn "$SB1"; rc=$?
343
+ check "G4.6 mutation: a splice that replaces the whole body loses the customer text (caught)" test "$rc" != 0
344
+ LCS="$SB0"
345
+
346
+ # ---------------------------------------------------------------- 9. the exit-code table: every fail_loud reason this half owns was exercised by a row above
347
+ check "every fail_loud abort reason owned by this half (resume and epic) was exercised by a marker-and-exit-code row" bash -c 'miss=""; for r in confirm-public-required epic-closed epic-ambiguous issue-ambiguous issues-incomplete; do case " $1 " in *" $r "*) ;; *) miss="$miss $r" ;; esac; done; [ -z "$miss" ]' _ "$SEEN_REASONS"
348
+ finish 184
@@ -15,7 +15,7 @@ trap 'rm -rf "${SCRATCH:?}"' EXIT
15
15
  passes=0; fails=0
16
16
  pass() { printf 'ok - %s\n' "$1"; passes=$((passes + 1)); }
17
17
  fail() { printf 'FAIL - %s\n' "$1"; fails=$((fails + 1)); }
18
- check() { local d=$1; shift; if "$@"; then pass "$d"; else fail "$d"; fi }
18
+ check() { local d=$1; shift; if "$@"; then pass "$d"; else fail "$d"; return 1; fi } # rc = the assertion's verdict
19
19
 
20
20
  # git under a constructed environment: no inherited GIT_* location variables, pinned identity.
21
21
  gitq() {
@@ -69,6 +69,9 @@ scan_to() { # scan_to <repo> <facts-out> [extra args]
69
69
  local r=$1 out=$2; shift 2
70
70
  lc scan --target "$r" --facts "$out" --files-out "$out.files" "$@" > "$out.stdout" 2> "$out.stderr"
71
71
  }
72
+ # autolink shapes outside code spans: a user mention, owner/repo#N, an issue URL, a bare #N, GH-N, a 7-40 hex run.
73
+ autolink_hits() { sed -e 's/`[^`]*`//g' "$@" | grep -nE '(^|[^A-Za-z0-9_./-])@[A-Za-z0-9_-]|[A-Za-z0-9._-]+/[A-Za-z0-9._-]+#[0-9]+|https?://[^ ]*/(issues|pull)/[0-9]+|(^|[^A-Za-z0-9&])#[0-9]+|GH-[0-9]+|(^|[^A-Za-z0-9_-])[0-9a-f]{7,40}($|[^A-Za-z0-9_-])'; }
74
+ autolink_clean() { local f; [ $# -gt 0 ] || return 1; for f in "$@"; do [ -f "$f" ] || return 1; done; ! autolink_hits "$@" >/dev/null; } # any argument that is not a regular file fails (grep over a missing file reads as clean)
72
75
  finish() { # finish <minimum assertion count>
73
76
  if [ $((passes + fails)) -lt "$1" ]; then printf 'FAIL - assertion floor: %d ran, %d required\n' $((passes + fails)) "$1"; exit 1; fi
74
77
  printf '%d passed, %d failed\n' "$passes" "$fails"
@@ -70,4 +70,21 @@ check "destination resolving outside LC_DEST_ROOT: rc 2 write-failed, nothing cr
70
70
  # Source scan: every use of the report path is a read or the single chokepoint call.
71
71
  stray=$(grep -n 'TARGET/\$REPORT_REL' "$SKILL/scripts/lib/render.sh" "$SKILL/scripts/launch-check.sh" | grep -vE 'lc_emit_checked|lc_prev_state|\[ -f|2>/dev/null' || true)
72
72
  check "no use of the report path other than a read or lc_emit_checked" test -z "$stray"
73
- finish 23
73
+ # --- PR-B: the scans run from the gate's own scratch directory, so a .gitleaksignore in the caller's directory is never read ---
74
+ # gitleaks reads .gitleaksignore from its working directory; a customer's repository or a plan directory must not be that place.
75
+ mkdir -p "$SCRATCH/gi/cwd" "$SCRATCH/gi/src"; GIF="$SCRATCH/gi/src/x.md"
76
+ printf 'value: %s%s\n' 'npm_' 'aB3dE5gH7jK9mN1pQ3sT5vW7yZ9bD1fH3jK5' > "$GIF"
77
+ gitleaks detect --source "$GIF" --no-git --report-format json --report-path "$SCRATCH/gi/r.json" --redact --exit-code 1 >/dev/null 2>&1
78
+ sed -n 's/^ *"Fingerprint": *"\(.*\)",\{0,1\}$/\1/p' "$SCRATCH/gi/r.json" | head -n 1 > "$SCRATCH/gi/cwd/.gitleaksignore"
79
+ check "gitleaksignore setup: the planted ignore entry names the secret (anti-vacuous)" test -s "$SCRATCH/gi/cwd/.gitleaksignore"
80
+ ( cd "$SCRATCH/gi/cwd" && gitleaks detect --source "$GIF" --no-git --report-format json --report-path "$SCRATCH/gi/r2.json" --redact --exit-code 1 >/dev/null 2>&1 ); rc=$?
81
+ check "gitleaksignore control: run from the directory holding the ignore file, gitleaks stays silent (the ignore bites)" test "$rc" = 0
82
+ ( cd "$SCRATCH/gi/cwd" && export LAUNCH_CHECK_REDACT_SENTINEL="$SCRATCH/s0.sh" && run_gate "$GATE" "$GIF" "$SCRATCH/out13/x.md" ); rc=$?
83
+ check "a .gitleaksignore in the caller's directory does not suppress the gate: rc 1 layer=gitleaks, nothing written" bash -c '[ "$1" = 1 ] && grep -q "layer=gitleaks" "$2" && [ ! -e "$3" ]' _ "$rc" "$SCRATCH/g.out" "$SCRATCH/out13/x.md"
84
+ sed '/^ cd "\$scratch" ||/d' "$GATE" > "$SCRATCH/mut/gate-nocd.sh"
85
+ check "mutation landed (the cd into the scratch directory is gone from the sandbox copy)" bash -c '! cmp -s "$1" "$2"' _ "$GATE" "$SCRATCH/mut/gate-nocd.sh"
86
+ ( cd "$SCRATCH/gi/cwd" && export LAUNCH_CHECK_REDACT_SENTINEL="$SCRATCH/s0.sh" && run_gate "$SCRATCH/mut/gate-nocd.sh" "$GIF" "$SCRATCH/out14/x.md" ); rc=$?
87
+ check "mutation (scans not run from the scratch directory): the planted ignore entry now hides the secret, so the row is sensitive" test "$rc" = 0 -a -f "$SCRATCH/out14/x.md"
88
+ ( cd "$SCRATCH/gi" && export LAUNCH_CHECK_REDACT_SENTINEL="$SCRATCH/s0.sh" && run_gate "$GATE" "src/x.md" "$SCRATCH/out15/rel.md" ); rc=$?
89
+ check "a relative source path still resolves (made absolute before the scans move)" bash -c '[ "$1" = 1 ] && grep -q "layer=gitleaks" "$2"' _ "$rc" "$SCRATCH/g.out"
90
+ finish 29
@@ -61,6 +61,8 @@ bad_j "unknown id" 'JDG-NOPE\tgap\thigh\tCI-03\n'
61
61
  bad_j "non-judged id" 'CI-01\tgap\thigh\tCI-03\n'
62
62
  bad_j "severity outside the enum" 'JDG-AUTH\tgap\tcritical\tCI-03\n'
63
63
  bad_j "evidence id absent from the facts" 'JDG-AUTH\tgap\thigh\tZZ-99\n'
64
+ bad_j "evidence names the facts header line, which is not a check" 'JDG-AUTH\tgap\thigh\t# stack=node\n'
65
+ bad_j "evidence names a judged item, which is not a deterministic fact" 'JDG-AUTH\tgap\thigh\tJDG-ARCH\n'
64
66
  bad_j "status outside the enum" 'JDG-AUTH\tmaybe\thigh\tCI-03\n'
65
67
 
66
68
  # verify-report negatives and the committed fixture.
@@ -37,4 +37,26 @@ check "a render with a judged gap is clean" lint "$SCRATCH/repj.out"
37
37
  check "a rendered report is clean" lint "$SCRATCH/rep.out"
38
38
  check "a rendered report carries the banner" grep -q "How to read this report" "$SCRATCH/rep.out"
39
39
  check "render.sh has no echo/printf of sentence-length prose (all prose lives in references/)" bash -c '! grep -nE "(echo|printf) .*[A-Za-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+" "$1" | grep -vE "^[0-9]+:[[:space:]]*#"' _ "$SKILL/scripts/lib/render.sh"
40
- finish 25
40
+ # --- PR-B: the issue writer (scripts/lib/issues.sh, references/issue-body.template) and the autolink shapes ---
41
+ # A missing file must FAIL (a grep over a missing file reads as clean), so every row below requires the file first.
42
+ lint_file() { [ -f "$1" ] && lint "$1"; }
43
+ ISSUES_SH="$SKILL/scripts/lib/issues.sh"; TPL="$SKILL/references/issue-body.template"
44
+ check "issues.sh exists and carries no banned word of its own" lint_file "$ISSUES_SH"
45
+ check "issue-body.template exists and is clean" lint_file "$TPL"
46
+ check "the plan-sample fixture (issue body and epic) is clean" bash -c 'for f in "$1"/issues/*.md "$1"/epic.md; do [ -f "$f" ] || exit 1; ! grep -iwFf "$2" "$f" >/dev/null 2>&1 || exit 1; done' _ "$SKILL/test/fixtures/plan-sample" "$BW"
47
+ check "issues.sh has no echo/printf of sentence-length prose (all prose lives in references/)" bash -c '[ -f "$1" ] && ! grep -nE "(echo|printf) .*[A-Za-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+" "$1" | grep -vE "^[0-9]+:[[:space:]]*#"' _ "$ISSUES_SH"
48
+ check "issues.sh has no \${var//pat/repl} substitution (render.sh and checks.sh already carry some; the ban is scoped to issues.sh)" bash -c '[ -f "$1" ] && ! grep -nE "\$\{[^}]*//" "$1" | grep -vE "^[0-9]+:[[:space:]]*#"' _ "$ISSUES_SH"
49
+ # Autolink shapes outside code spans: a user mention, owner/repo#N, an issue URL, a bare #N, GH-N, a 7-40 hex run.
50
+ # autolink_hits and autolink_clean come from lib.sh (one copy)
51
+ awk -F'\t' '!/^#/ && $1!="id" {print $5; print $11; print $12}' "$SKILL/references/checks.tsv" > "$SCRATCH/prose3.txt"
52
+ check "autolink lint: checks.tsv titles, commands and remedies carry no autolink shape" autolink_clean "$SCRATCH/prose3.txt"
53
+ check "autolink lint: phrases.txt, banner.txt and footer.txt carry no autolink shape" autolink_clean "$SKILL/references/phrases.txt" "$SKILL/references/banner.txt" "$SKILL/references/footer.txt"
54
+ tpl_clean() { [ -f "$TPL" ] && autolink_clean "$TPL"; }
55
+ check "autolink lint: issue-body.template exists and carries no autolink shape" tpl_clean
56
+ printf '%s\n' 'see owner/repo#12' 'ping @someone' 'item #7' 'related GH-9' 'commit deadbeef1' 'https://example.invalid/o/r/issues/3' > "$SCRATCH/al-bad.txt"
57
+ check "autolink lint canary: each of the six shapes is caught by the lint helper itself" test "$(autolink_hits "$SCRATCH/al-bad.txt" | wc -l | tr -d ' ')" = 6
58
+ printf 'path `node_modules/@types/node/index.d.ts` only\n' > "$SCRATCH/al-ok.txt"
59
+ check "autolink lint canary: a code span is exempt (an @scope/pkg path inside backticks is not a mention)" autolink_clean "$SCRATCH/al-ok.txt"
60
+ ctl_alc() { autolink_clean "$SCRATCH/al-ok.txt" && ! autolink_clean "$SCRATCH/al-ok.txt" "$SCRATCH/no-such-file" && ! autolink_clean "$SCRATCH/no-such-file" && ! autolink_clean "$SCRATCH" && ! autolink_clean && ! autolink_clean "$SCRATCH/al-ok.txt" "$SCRATCH/al-bad.txt"; }
61
+ check "control (autolink_clean): a missing file, a directory, no argument or one bad file among good ones fails it; a clean file passes" ctl_alc
62
+ finish 36