@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,182 @@
1
+ #!/usr/bin/env bash
2
+ # Shared setup for the two issues suites (issues-guards.test.sh, issues-resume.test.sh): sourced, not itself a suite.
3
+ # It holds the stub harness, the tracker views, the run helpers, the rendered base report, the sandbox-copy builder and the
4
+ # gitleaks wrapper. Every assertion lives in one of the two suites (split because one suite took 6-8 minutes).
5
+ #
6
+ # issues: the only part of launch-check that writes to a customer's tracker. Four guards (ADR-314, amendment 2026-11-03):
7
+ # 1 saved-plan-only writes · 2 authored bytes are scanned bytes · 3 idempotency and resume · 4 epic edits confined to the marked section.
8
+ # Every case runs against test/gh-stub.sh (a stateful fake gh on PATH); no real gh, no network. The independent witnesses are the
9
+ # stub's append-only call log and the fake tracker's contents, never the script's own counters.
10
+ #
11
+ # THE INTERFACE THIS SUITE PINS (a change to issues.sh that alters it amends the line here in the same commit):
12
+ # launch-check.sh issues --preview --target R --facts F --judged J [--plan-out D] [--exclude-domain X] [--exclude-class X] [--host H] [--repo S]
13
+ # stdout: SOLEUR_LAUNCH_CHECK_ISSUES_PLAN repo=<o/n> visibility=<V> create=<n> exists=<n> closed=<n> accepted=<n> excluded=<n> capped=<n> plan=<dir>
14
+ # (the plan directory is created inside D; report-only: SOLEUR_LAUNCH_CHECK_ISSUES mode=report-only reason=<cause>, exit 0, no plan)
15
+ # launch-check.sh issues --create --target R --facts F --judged J --plan P --confirm-repo S --confirm-count N [--confirm-public] [--repo S] [--host H] [--dry-run]
16
+ # stdout: SOLEUR_LAUNCH_CHECK_ISSUES created= linked= skipped= failed=<ids> fallback= epic=#N epic-section= plan=<dir> phase=<..>
17
+ # launch-check.sh issues --check-plan --plan P stdout: SOLEUR_LAUNCH_CHECK_PLAN_OK
18
+ # plan.tsv: key=value header lines (repo host visibility catalog_hash report_hash created), then a header row and one row per item:
19
+ # id<TAB>severity<TAB>domain<TAB>class<TAB>action<TAB>title (see test/fixtures/plan-sample)
20
+ # Sourced-library names: lc_gh_write, lc_gh_read, lc__gh_exec, lc_issues_live (writes $WORK/live.tsv), lc_epic_splice <old-body-file> <new-section-file>
21
+ # (new body on stdout), lc_emit_checked; globals ISSUES_REPO (plan-bound slug) and ISSUES_PLAN_DIR; env LC_DRY=1; seam LAUNCH_CHECK_PAUSE=0.
22
+ # Rows tagged UNVERIFIED-STUB-ONLY depend on a stub shape nobody has checked against GitHub yet (live check: follow-up #11956).
23
+
24
+ # shellcheck disable=SC2034 # ISS, SAMPLE and the other names below are read by the two suites that source this file
25
+ set -uo pipefail
26
+ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
27
+ command -v gitleaks >/dev/null 2>&1 || { echo "FAIL - gitleaks is required for this suite"; exit 1; }
28
+ command -v jq >/dev/null 2>&1 || { echo "FAIL - jq is required for this suite (the stub runs real jq)"; exit 1; }
29
+ REPORT_REL=$(bash "$LC" report-path)
30
+ ISS="$SKILL/scripts/lib/issues.sh"
31
+ TAB=$(printf '\t')
32
+ export LAUNCH_CHECK_PAUSE=0
33
+ # ---------------------------------------------------------------- harness: stub, tracker views, run helpers
34
+ BIN="$SCRATCH/bin"; mkdir -p "$BIN"; cp "$SKILL/test/gh-stub.sh" "$BIN/gh"; chmod +x "$BIN/gh"
35
+ export PATH="$BIN:$PATH"
36
+ ST="$SCRATCH/st"
37
+ stub_reset() { # stub_reset <slug> [visibility] [fork true|false]
38
+ rm -rf "${ST:?}"; mkdir -p "$ST"
39
+ jq -n --arg s "$1" --arg v "${2:-private}" --argjson f "${3:-false}" \
40
+ '{full_name:$s,name:($s|split("/")[1]),owner:{login:($s|split("/")[0])},visibility:$v,archived:false,has_issues:true,fork:$f,permissions:{push:true}}' > "$ST/repo.json"
41
+ printf '[]\n' > "$ST/labels.json"; printf '[]\n' > "$ST/issues.json"
42
+ export GH_STUB_STATE="$ST"
43
+ }
44
+ calls_reset() { rm -f "$ST/calls.log" "$ST/pages.log" "$ST/violations.log" "$ST/refused.log"; }
45
+ cj() { local f=$1; if [ -s "$ST/calls.log" ]; then jq -sr "$f" "$ST/calls.log"; else printf '[]' | jq -r "$f"; fi; }
46
+ n_calls() { cj 'length'; }
47
+ n_writes() { cj '[.[]|select(.class=="write")]|length'; }
48
+ n_post() { cj "[.[]|select(.method==\"$1\" and (.path|test(\"$2\")))]|length"; }
49
+ tr_q() { jq -r "$1" "$ST/issues.json"; }
50
+ EPICSEL='select(.labels|map(.name)|index("lc:epic"))'
51
+ items_n() { tr_q "[.[]|select(.labels|map(.name)|index(\"lc:epic\")|not)]|length"; }
52
+ epics_n() { tr_q "[.[]|$EPICSEL]|length"; }
53
+ epic_body_to() { jq -j "[.[]|$EPICSEL][0].body" "$ST/issues.json" > "$1"; }
54
+ marker_n() { tr_q "[.[]|select((.body // \"\")|contains(\"<!-- launch-check:gap=$1 -->\"))]|length"; }
55
+ max_dup() { tr_q '[.[]|(.body // "")|scan("<!-- launch-check:gap=[A-Z]+-[A-Za-z0-9-]+ -->")]|group_by(.)|map(length)|max // 0'; }
56
+ linked_n() { tr_q '[.[]|select(.parent != null)]|length'; }
57
+ seed() { # seed <number> <state> <login> <labels-csv> <body-text|NULL>
58
+ local lj
59
+ lj=$(printf '%s' "$4" | jq -R 'split(",")|map(select(.!=""))|map({name:.})')
60
+ jq -c --argjson n "$1" --arg st "$2" --arg login "$3" --argjson l "$lj" --arg b "$5" \
61
+ '. + [{number:$n,id:(4000000000+$n*13),state:$st,title:"seeded",body:(if $b=="NULL" then null else $b end),labels:$l,user:{login:$login},parent:null}]' "$ST/issues.json" > "$ST/i.new" && mv "$ST/i.new" "$ST/issues.json"
62
+ }
63
+ seed_label() { jq -c --arg n "$1" --arg c "$2" '. + [{name:$n,color:$c,description:"seeded"}]' "$ST/labels.json" > "$ST/l.new" && mv "$ST/l.new" "$ST/labels.json"; }
64
+ tracker_edit() { jq -c "$1" "$ST/issues.json" > "$ST/i.new" && mv "$ST/i.new" "$ST/issues.json"; }
65
+ kv() { awk -v m="$2" -v k="$3" '$1==m { for (i = 2; i <= NF; i++) if (index($i, k "=") == 1) { print substr($i, length(k) + 2); exit } }' "$1"; }
66
+ lcs() { # like lc(), but against the script in LCS (a sandbox copy for the mutation battery)
67
+ env -u GIT_DIR -u GIT_INDEX_FILE -u GIT_WORK_TREE -u GIT_OBJECT_DIRECTORY -u GIT_COMMON_DIR -u GIT_NAMESPACE \
68
+ GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid \
69
+ bash "${LCS:-$LC}" "$@"
70
+ }
71
+ # with NAME=value... -- command...: run a function in THIS shell with variables exported, then restore them (a subshell would lose RC and OUT)
72
+ with() {
73
+ local -a names=() olds=() was=(); local n i
74
+ while [ "$1" != "--" ]; do
75
+ n=${1%%=*}; names+=("$n")
76
+ if [ -n "${!n+x}" ]; then was+=(1); olds+=("${!n}"); else was+=(0); olds+=(""); fi
77
+ # shellcheck disable=SC2163 # $1 is a NAME=value word on purpose
78
+ export "$1"; shift
79
+ done
80
+ shift; "$@"
81
+ local rc=$?
82
+ for i in "${!names[@]}"; do if [ "${was[$i]}" = 1 ]; then export "${names[$i]}=${olds[$i]}"; else unset "${names[$i]}"; fi; done
83
+ return $rc
84
+ }
85
+ RC=0; OUT=""; SEEN_REASONS=""; N=0; CRN=0
86
+ runi() { local name=$1; shift; OUT="$SCRATCH/$name.out"; lcs issues "$@" > "$OUT" 2>&1; RC=$?; }
87
+ abort_is() { # abort_is <rc> <reason> [file]: exit code AND marker, both (the report-only exit 0 path can never pass as an abort)
88
+ # The reason is recorded for the exit-code table only after the assertion held: a row that failed proves nothing about its reason.
89
+ local f=${3:-$OUT}
90
+ [ "$RC" = "$1" ] && grep -q "^SOLEUR_LAUNCH_CHECK_ABORT reason=$2\( \|\$\)" "$f" || return 1
91
+ SEEN_REASONS="$SEEN_REASONS $2"
92
+ }
93
+ seen() { SEEN_REASONS="$SEEN_REASONS $1"; } # call only after the assertion that exercised the reason passed (check returns its verdict)
94
+ lacks() { ! grep -qF -- "$1" "$OUT"; }
95
+ # autolink_hits / autolink_clean live in lib.sh (one copy, shared with wording.test.sh)
96
+ file_and_clean() { [ -f "$1" ] && autolink_clean "$1"; }
97
+ gl_only_secret() { printf '%s%s' 'glpat-' 'aB3dE5gH7jK9mN1pQ3sT'; } # matched by gitleaks (gitlab-pat) and NOT by the sentinel (checked: sentinel rc 0, gitleaks rc 1; the npm_ shape the first draft used IS a sentinel hit)
98
+ stub_secret() { printf '%s%s' 'ghp_' 'Q3nW8tY1kD6vB2xM9cL5hZ7pR4aE0sJ2fG1u'; } # what the stub prints on stderr for GH_STUB_FAIL_KIND=secret
99
+ outside() { awk 'BEGIN { s = 0 } { l = $0; sub(/\r$/, "", l) } l == "<!-- launch-check:begin -->" { s = 1; next } l == "<!-- launch-check:end -->" { s = 0; next } !s { print }' "$1"; }
100
+ export -f outside
101
+ # tree_has <fixed-string> <dir>: some file under <dir> holds the string (find + grep, no recursive grep: the orphan-suite census reads that idiom as a corpus walk)
102
+ tree_has() { [ -n "$(find "$2" -type f -exec grep -lF -- "$1" {} + 2>/dev/null)" ]; }
103
+ export -f tree_has
104
+ export ST; export -f kv cj # used inside `bash -c` check bodies
105
+
106
+ # ---------------------------------------------------------------- shared fixtures, sandbox builder, gitleaks wrapper
107
+ SAMPLE="$SKILL/test/fixtures/plan-sample"
108
+ BASE=$(fx_minimal base); gitq "$BASE" remote add origin https://github.com/acme/demo.git
109
+ FACTS="$SCRATCH/facts.tsv"; scan_to "$BASE" "$FACTS"
110
+ JUD="$SCRATCH/judged.tsv"; printf '# judged\n' > "$JUD"
111
+ lc render --target "$BASE" --facts "$FACTS" --judged "$JUD" > "$SCRATCH/base.render" 2>&1
112
+ newcase() { N=$((N + 1)); R="$SCRATCH/case$N"; cp -R "$BASE" "$R"; stub_reset acme/demo private; PLAN=""; }
113
+ only_first() { # only_first <repo> <K>: accept every open finding after the first K, so exactly K remain to file
114
+ local rep="$1/$REPORT_REL"
115
+ awk -v k="$2" '/^```launch-check-state$/ {f=1} /^```$/ && f {f=0} f && /^finding [A-Z]+-[A-Za-z0-9-]+ open$/ { if (++n > k) { print $1 " " $2 " accepted 2026-11-03 fixture-accept"; next } } {print}' "$rep" > "$rep.new" && mv "$rep.new" "$rep"
116
+ }
117
+ only_ids() { # only_ids <repo> <ID...>: accept every open finding except the named ones
118
+ local rep="$1/$REPORT_REL" keep; shift; keep=" $* "
119
+ awk -v keep="$keep" '/^```launch-check-state$/ {f=1} /^```$/ && f {f=0} f && /^finding [A-Z]+-[A-Za-z0-9-]+ open$/ { if (index(keep, " " $2 " ") == 0) { print $1 " " $2 " accepted 2026-11-03 fixture-accept"; next } } {print}' "$rep" > "$rep.new" && mv "$rep.new" "$rep"
120
+ }
121
+ prev() { runi "pv$N" --preview --target "$R" --facts "$FACTS" --judged "$JUD" --plan-out "$SCRATCH/po$N" "$@"; PLAN=$(kv "$OUT" SOLEUR_LAUNCH_CHECK_ISSUES_PLAN plan); }
122
+ plan_n() { awk -F'\t' 'NF == 6 && $1 != "id" && $5 == "create"' "$PLAN/plan.tsv" 2>/dev/null | wc -l | tr -d ' '; }
123
+ create_ids() { awk -F'\t' 'NF == 6 && $1 != "id" && $5 == "create" {print $1}' "$PLAN/plan.tsv" 2>/dev/null; }
124
+ create() { CRN=$((CRN + 1)); runi "cr$N.$CRN" --create --target "$R" --facts "$FACTS" --judged "$JUD" --plan "$PLAN" --confirm-repo "${CREPO:-acme/demo}" --confirm-count "${CCOUNT:-$(plan_n)}" "$@"; }
125
+ cmd_line() { grep -E '^bash .* issues --create ' "$1"; } # the printed --create command, as one line
126
+ export -f cmd_line
127
+ banner_line() { cat "$SKILL/references/banner.txt"; }
128
+ mode700() { [ "$(ls -ld "$1" 2>/dev/null | cut -c1-10)" = "drwx------" ]; }
129
+ table_rows_present() { # every create row of the plan appears in the preview output as "ID | severity | title"
130
+ local out=$1 plan=$2 n=0 id sev title
131
+ while IFS="$TAB" read -r id sev _ _ _ title; do
132
+ grep -qF -- "$id | $sev | $title" "$out" || return 1; n=$((n + 1))
133
+ done < <(awk -F'\t' 'NF == 6 && $1 != "id" && $5 == "create"' "$plan")
134
+ [ "$n" -ge 1 ]
135
+ }
136
+ bodies_clean() { local f n=0; for f in "$1"/issues/*.md; do [ -f "$f" ] || return 1; autolink_clean "$f" || return 1; n=$((n + 1)); done; [ "$n" -ge 1 ]; }
137
+ sent_bodies_match() { # every body the stub received on an issue create is byte-identical to a file of the plan that was scanned
138
+ local n=0 seq b ok f
139
+ while IFS= read -r seq; do
140
+ b="$ST/bodies/$seq-body"; ok=0
141
+ for f in "$PLAN"/issues/*.md "$PLAN/epic.md"; do cmp -s "$b" "$f" && { ok=1; break; }; done
142
+ [ "$ok" = 1 ] || return 1; n=$((n + 1))
143
+ done < <(cj '.[]|select(.method=="POST" and (.path|test("/issues$")))|.seq')
144
+ [ "$n" -ge 1 ]
145
+ }
146
+ # Sandbox copy of the skill for the mutation battery, with seams injected before main: a gate bypass and a live-lookup bypass, both inert unless set.
147
+ mk_sbx() { # mk_sbx <name> -> prints the sandbox launch-check.sh
148
+ local d="$SCRATCH/sbx-$1/plugins/soleur" s
149
+ mkdir -p "$d/skills/launch-check"; ln -s "$PLUGIN/.claude-plugin" "$d/.claude-plugin"
150
+ for s in incident verification-scaffold; do ln -s "$PLUGIN/skills/$s" "$d/skills/$s"; done
151
+ cp -R "$SKILL/scripts" "$SKILL/references" "$d/skills/launch-check/"
152
+ printf '%s' "$d/skills/launch-check/scripts/launch-check.sh"
153
+ }
154
+ inject() { awk -v f="$2" '/^main "\$@"$/ { while ((getline l < f) > 0) print l } { print }' "$1" > "$1.new" && mv "$1.new" "$1"; }
155
+ cat > "$SCRATCH/seams.sh" <<'EOF'
156
+ # test seams, inert unless their variable is set
157
+ if declare -F lc_emit_checked >/dev/null; then
158
+ eval "$(declare -f lc_emit_checked | sed '1s/^lc_emit_checked/lc__real_emit_checked/')"
159
+ lc_emit_checked() { if [ -n "${LC_TEST_NOGATE:-}" ]; then return 0; fi; lc__real_emit_checked "$@"; }
160
+ fi
161
+ if declare -F lc_issues_live >/dev/null; then
162
+ eval "$(declare -f lc_issues_live | sed '1s/^lc_issues_live/lc__real_issues_live/')"
163
+ lc_issues_live() { if [ -n "${LC_TEST_NOLIVE:-}" ]; then : > "$WORK/live.tsv"; return 0; fi; lc__real_issues_live "$@"; }
164
+ fi
165
+ EOF
166
+ SB0=$(mk_sbx pristine); inject "$SB0" "$SCRATCH/seams.sh"
167
+ LCS="$SB0"
168
+ # A PATH-shimmed awk that exits 2 for any program whose text contains $AWK_DIE (a dead awk must stop a run, never read as an empty result)
169
+ SHIM="$SCRATCH/awkshim"; mkdir -p "$SHIM"
170
+ printf '#!/usr/bin/env bash\nif [ -n "${AWK_DIE:-}" ]; then case "$*" in *"$AWK_DIE"*) exit 2 ;; esac; fi\nexec "%s" "$@"\n' "$(command -v awk)" > "$SHIM/awk"; chmod +x "$SHIM/awk"
171
+ # a pattern only gitleaks matches, with a gitleaks wrapper that passes everything until the real one is switched on
172
+ cat > "$SCRATCH/gl-toggle.sh" <<'EOF'
173
+ #!/usr/bin/env bash
174
+ # passes everything until $GL_ON exists, then delegates to the real gitleaks; records its working directory and argv
175
+ printf '%s\t%s\n' "$PWD" "$*" >> "${GL_LOG:-/dev/null}"
176
+ if [ -e "${GL_ON:-/nonexistent}" ]; then exec "$GL_REAL" "$@"; fi
177
+ case "${1:-}" in version) echo 8.24.2; exit 0 ;; esac
178
+ exit 0
179
+ EOF
180
+ chmod +x "$SCRATCH/gl-toggle.sh"
181
+ export GL_REAL; GL_REAL=$(command -v gitleaks); export GL_LOG="$SCRATCH/gl.calls" GL_ON="$SCRATCH/gl-on"
182
+ rm -f "$GL_ON" "$GL_LOG"