@soleur/opencode 3.387.8 → 3.388.0

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,352 @@
1
+ #!/usr/bin/env bash
2
+ # host-state.sh - read what Better Stack knows about Soleur's production hosts, with no SSH.
3
+ #
4
+ # doppler run -p soleur -c prd_terraform -- "${CLAUDE_PLUGIN_ROOT}/skills/cve-exposure/scripts/host-state.sh"
5
+ # doppler run -p soleur -c prd_terraform -- "${CLAUDE_PLUGIN_ROOT}/skills/cve-exposure/scripts/host-state.sh" image-findings CVE-YYYY-NNNN
6
+ #
7
+ # One line per host role, tab separated:
8
+ # host_role marker_state kernel_state age_hours kernel uptime_s kernel_age_hours source_marker
9
+ # then ONE verdict line: SOLEUR_CVE_HOST_STATE hosts=<n> fresh=<n> stale=<n> silent=<n> unknown=<n>
10
+ #
11
+ # FAIL-CLOSED CONTRACT (ADR-322, ADR-197, ADR-214). Every host line flows through classify_host, the
12
+ # single chokepoint, and every field is re-validated against an anchored shape there, so a decoded value
13
+ # cannot forge an extra host line or a kernel string. Anything not positively observed prints `unknown`,
14
+ # `silent` or `stale`, never an empty result and never a reassuring one.
15
+ # exit 0 rows parsed, positive control passed (some hosts may still be unknown)
16
+ # exit 2 the positive control returned no host rows: the source is dark, every host is unknown
17
+ # exit 3 Better Stack credentials were not injected (nothing was queried)
18
+ # exit 4 transport failure, unparseable output, an unverified reader, jq missing, or the reader tree is
19
+ # missing; every host is unknown
20
+ # exit 64 bad arguments
21
+ # exit 78 refused to run under shell tracing (xtrace) with a live credential set
22
+ #
23
+ # The query script is resolved from `git rev-parse --show-toplevel` after every GIT_* variable is cleared,
24
+ # and is NOT run until the reader files are proven byte-identical to upstream main (ADR-322 amendment,
25
+ # CTO ruling on the review of #12343): the checkout the shell sits in is attacker-controllable, and the
26
+ # reader runs with the operator's injected Doppler credentials. The two reader files are downloaded from
27
+ # upstream main by explicit raw URL (never via the operator's repo, remotes or hooks); a failed download or
28
+ # any difference makes every host unknown and exits 4 BEFORE anything runs, with a distinct
29
+ # `reader-unverified-<reason>` token (no-curl, not-a-regular-file, download-failed, empty-download,
30
+ # differs-from-upstream). A branch that edits the reader is refused by design. What RUNS is the downloaded,
31
+ # verified copy in the helper's private scratch directory, never the checkout path, so a change made to the
32
+ # checkout between the check and the run cannot execute; if upstream ever makes the reader source another
33
+ # file, the scratch copy lacks it and the reader fails closed. The credentials travel only through the
34
+ # environment `doppler run` provides, never argv.
35
+ #
36
+ # uptime_s comes from the newest row that carries it within the freshness window and can be older than the
37
+ # row `age_hours` describes (the state/age row may be a different marker of the same role).
38
+ #
39
+ # marker_state fresh a decoded periodic marker row for the host is at most 48 hours old
40
+ # stale only an older periodic row, or only a failed-deploy kernel diag row, exists
41
+ # silent the host ships logs (the global positive control saw it) but no marker row exists
42
+ # unknown not observable: source not read, host not seen, or the read failed
43
+ # kernel_state observed only when a decoded SOLEUR_CANARY_SANDBOX_DIAG section=kernel row inside the
44
+ # 7-day window carries a kernel matching the anchored kernel shape; that row is emitted
45
+ # by FAILED deploys only, so its age is reported separately in kernel_age_hours and is
46
+ # never treated as a periodic report.
47
+ set -uo pipefail
48
+
49
+ case "$-" in
50
+ *x*)
51
+ if [ -n "${BETTERSTACK_QUERY_PASSWORD:+x}" ]; then
52
+ printf '[FATAL] host-state.sh refuses to run under xtrace with a live credential set (#7797)\n' >&2
53
+ exit 78
54
+ fi
55
+ ;;
56
+ esac
57
+ export LC_ALL=C
58
+ # The shell's own GIT_DIR / GIT_WORK_TREE / GIT_COMMON_DIR would redirect --show-toplevel to a repository of
59
+ # the caller's choosing. Clear every GIT_* variable before git is ever invoked.
60
+ unset "${!GIT_@}"
61
+
62
+ readonly FRESH_HOURS=48
63
+ readonly CONTROL_WINDOW='2 HOUR'
64
+ readonly MARKER_WINDOW='7 DAY'
65
+
66
+ # The role table: ONE place. host_role|better-stack host_name (or - when the role is not attributed by host_name).
67
+ # web is for_each over var.web_hosts (web-1, web-2); git-data ships to a separate Better Stack source
68
+ # that this reader does not query, so it is always printed unknown with source_marker=source-not-read.
69
+ readonly ROLE_TABLE='web-1|soleur-web-platform
70
+ web-2|soleur-web-2
71
+ git-data|-
72
+ inngest|soleur-inngest-prd
73
+ registry|-
74
+ grok-dogfood|soleur-grok-dogfood'
75
+
76
+ readonly UPSTREAM_RAW='https://raw.githubusercontent.com/jikig-ai/soleur/main'
77
+ # The reader plus the classifier library this helper sources on a failed read. The reader itself sources and
78
+ # execs nothing (host-state.test.sh pins that against the real files, so a new dependency is RED there).
79
+ readonly READER_FILES='scripts/betterstack-query.sh scripts/lib/betterstack-read-classify.sh'
80
+ # Identity the registry's SOLEUR_ZOT_DISK rows carry in their message (host=); not a Better Stack host_name.
81
+ readonly REGISTRY_HOST_ID='soleur-registry'
82
+ # The image report's marker name, split so the public-claim tripwire (scripts/image-cve-public-claim-guard.test.sh) does not read a
83
+ # protocol literal as a claim about what the pipeline does. The value equals the producer's MARKER_NAME (pinned in host-state.test.sh).
84
+ readonly IMG_MARKER='SOLEUR_IMAGE_CVE''_SCAN'
85
+
86
+ readonly KERNEL_RE='^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-[a-z0-9-]+$'
87
+ readonly UINT_RE='^[0-9]{1,12}$'
88
+
89
+ command -v jq > /dev/null 2>&1 || { printf 'host-state.sh: jq is required (not installed); every host is unknown\n' >&2; JQ_MISSING=1; }
90
+ MODE="hosts"
91
+ IMAGE_IDS='[]'
92
+ if [ "$#" -ge 1 ]; then
93
+ case "$1" in
94
+ image-findings)
95
+ MODE="image-findings"
96
+ shift
97
+ if [ "$#" -lt 1 ] || [ "$#" -gt 6 ]; then
98
+ printf 'host-state.sh: image-findings needs 1 to 6 CVE or GHSA ids (the id and its aliases)\n' >&2
99
+ exit 64
100
+ fi
101
+ for _id in "$@"; do
102
+ if ! [[ "$_id" =~ ^(CVE-[0-9]{4}-[0-9]{4,}|GHSA(-[a-z0-9]{4}){3})$ ]]; then
103
+ printf 'host-state.sh: image-findings ids must be CVE or GHSA ids\n' >&2
104
+ exit 64
105
+ fi
106
+ done
107
+ IMAGE_IDS="$(printf '%s\n' "$@" | jq -R . | jq -s -c .)" || IMAGE_IDS='[]'
108
+ ;;
109
+ *)
110
+ printf 'host-state.sh: unknown argument (usage: host-state.sh | host-state.sh image-findings <CVE>)\n' >&2
111
+ exit 64
112
+ ;;
113
+ esac
114
+ fi
115
+
116
+ SCRATCH="$(mktemp -d -t soleur-cve-host-state.XXXXXXXX)" || { echo "host-state.sh: mktemp failed" >&2; exit 4; }
117
+ trap 'rm -rf "$SCRATCH"' EXIT
118
+
119
+ # --- counters live INSIDE classify_host so a second print path cannot be counted ---------------------
120
+ N_HOSTS=0; N_FRESH=0; N_STALE=0; N_SILENT=0; N_UNKNOWN=0
121
+ FACTS="$SCRATCH/facts.json"
122
+ printf '{}\n' > "$FACTS"
123
+
124
+ classify_host() { # $1 = role. Reads $FACTS (jq-validated), re-validates, prints exactly one line.
125
+ local role="$1" ms ks age kernel up kage src
126
+ ms=unknown; ks=unknown; age=unknown; kernel=unknown; up=unknown; kage=unknown; src=none
127
+ if IFS=$'\t' read -r ms ks age kernel up kage src < <(
128
+ jq -r --arg r "$role" '.[$r] // {} | [(.marker_state // "unknown"), (.kernel_state // "unknown"),
129
+ (.age_hours // "unknown"|tostring), (.kernel // "unknown"), (.uptime_s // "unknown"|tostring),
130
+ (.kernel_age_hours // "unknown"|tostring), (.source_marker // "none")] | @tsv' "$FACTS" 2>/dev/null); then :; fi
131
+ case "$ms" in fresh|stale|silent|unknown) : ;; *) ms=unknown ;; esac
132
+ case "$ks" in observed|unknown) : ;; *) ks=unknown ;; esac
133
+ [[ "$age" =~ ^[0-9]{1,6}$ ]] || age=unknown
134
+ [[ "$kage" =~ ^[0-9]{1,6}$ ]] || kage=unknown
135
+ [[ "$up" =~ $UINT_RE ]] || up=unknown
136
+ [[ "$kernel" =~ $KERNEL_RE ]] || { kernel=unknown; ks=unknown; kage=unknown; }
137
+ [ "$ks" = observed ] || { kernel=unknown; kage=unknown; }
138
+ [[ "$src" =~ ^[A-Za-z0-9_,-]{1,80}$ ]] || src=none
139
+ [[ "$role" =~ ^[a-z0-9-]{1,32}$ ]] || role=unmapped
140
+ N_HOSTS=$((N_HOSTS + 1))
141
+ case "$ms" in fresh) N_FRESH=$((N_FRESH + 1)) ;; stale) N_STALE=$((N_STALE + 1)) ;;
142
+ silent) N_SILENT=$((N_SILENT + 1)) ;; *) N_UNKNOWN=$((N_UNKNOWN + 1)) ;; esac
143
+ printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$role" "$ms" "$ks" "$age" "$kernel" "$up" "$kage" "$src"
144
+ }
145
+
146
+ print_all_roles() {
147
+ local line role
148
+ while IFS= read -r line; do
149
+ role="${line%%|*}"
150
+ classify_host "$role"
151
+ done <<< "$ROLE_TABLE"
152
+ if [ "$(jq -r 'has("unmapped")' "$FACTS" 2>/dev/null)" = "true" ]; then classify_host unmapped; fi
153
+ }
154
+
155
+ finish() { # $1 = exit code. Prints the verdict line. hosts=0 cannot happen while ROLE_TABLE is non-empty;
156
+ # the guard is defensive so that an emptied table fails instead of printing a clean-looking zero.
157
+ local code="$1"
158
+ printf 'SOLEUR_CVE_HOST_STATE hosts=%s fresh=%s stale=%s silent=%s unknown=%s\n' \
159
+ "$N_HOSTS" "$N_FRESH" "$N_STALE" "$N_SILENT" "$N_UNKNOWN"
160
+ if [ "$N_HOSTS" -eq 0 ] && [ "$code" -eq 0 ]; then code=4; fi
161
+ exit "$code"
162
+ }
163
+
164
+ degraded() { # $1 = exit code, $2 = reason token. Every host unknown.
165
+ printf '{}\n' > "$FACTS"
166
+ printf 'host-state.sh: degraded reason=%s; every host is unknown\n' "$2" >&2
167
+ if [ "$MODE" = "image-findings" ]; then
168
+ printf 'image_findings unknown unknown yes unknown\n'
169
+ printf 'SOLEUR_CVE_HOST_STATE mode=image-findings state=unknown match=unknown\n'
170
+ exit "$1"
171
+ fi
172
+ print_all_roles
173
+ finish "$1"
174
+ }
175
+
176
+ TOP="$(git rev-parse --show-toplevel 2>/dev/null)" || TOP=""
177
+ case "$TOP" in /*) : ;; *) degraded 4 not-in-a-git-tree ;; esac
178
+ QUERY="$TOP/scripts/betterstack-query.sh"
179
+ CLASSIFY_LIB="$TOP/scripts/lib/betterstack-read-classify.sh"
180
+ [ -f "$QUERY" ] || degraded 4 reader-missing
181
+ [ -z "${JQ_MISSING:-}" ] || degraded 4 jq-missing
182
+
183
+ # The reader runs with the operator's injected credentials, so it must be upstream's reader. Download each
184
+ # file the reader executes from upstream main over HTTPS (the reader's own curl hardening: no ~/.curlrc, no
185
+ # proxy, https only, TLS 1.2+) into a private scratch tree, compare it byte for byte with the checkout's copy,
186
+ # and then RUN THE DOWNLOADED COPY (not the checkout path). Offline, a failed download, an empty file or any
187
+ # difference: every host unknown, exit 4, nothing run. (A full `git fetch` of this repository was measured at
188
+ # 40+ s and timing out; the two raw files are a few KB.)
189
+ READER_DIR="$SCRATCH/reader"
190
+ VERIFY_FAIL=unspecified
191
+ verify_reader() {
192
+ local f
193
+ command -v curl > /dev/null 2>&1 || { VERIFY_FAIL=no-curl; return 1; }
194
+ for f in $READER_FILES; do
195
+ if [ ! -f "$TOP/$f" ] || [ -L "$TOP/$f" ]; then VERIFY_FAIL=not-a-regular-file; return 1; fi
196
+ mkdir -p "$READER_DIR/$(dirname "$f")" || { VERIFY_FAIL=scratch; return 1; }
197
+ rm -f "$READER_DIR/$f"
198
+ ( unset SSLKEYLOGFILE CURL_CA_BUNDLE SSL_CERT_FILE SSL_CERT_DIR CURL_HOME HOSTALIASES LOCALDOMAIN RES_OPTIONS
199
+ curl --disable --noproxy '*' --proto '=https' --tlsv1.2 -fsS --max-time 30 -o "$READER_DIR/$f" "$UPSTREAM_RAW/$f" 2> /dev/null ) || { VERIFY_FAIL=download-failed; return 1; }
200
+ [ -s "$READER_DIR/$f" ] || { VERIFY_FAIL=empty-download; return 1; }
201
+ cmp -s "$READER_DIR/$f" "$TOP/$f" || { VERIFY_FAIL=differs-from-upstream; return 1; }
202
+ done
203
+ }
204
+ verify_reader || degraded 4 "reader-unverified-$VERIFY_FAIL"
205
+ QUERY="$READER_DIR/scripts/betterstack-query.sh"
206
+ CLASSIFY_LIB="$READER_DIR/scripts/lib/betterstack-read-classify.sh"
207
+
208
+ # run_query <name> <sql>: stdout -> $SCRATCH/<name>.rows, rc recorded. Never trusts stdout over rc.
209
+ run_query() {
210
+ local name="$1" sql="$2" rc=0 token=unclassified
211
+ bash "$QUERY" "$sql" > "$SCRATCH/$name.rows" 2> "$SCRATCH/$name.err" || rc=$?
212
+ if [ "$rc" -ne 0 ]; then
213
+ if [ -f "$CLASSIFY_LIB" ]; then
214
+ # shellcheck source=/dev/null
215
+ token="$( . "$CLASSIFY_LIB" 2>/dev/null && bs_read_classify "$rc" "$SCRATCH/$name.rows" 2>/dev/null )" || token=unclassified
216
+ fi
217
+ printf 'host-state.sh: query %s failed rc=%s class=%s\n' "$name" "$rc" "${token:-unclassified}" >&2
218
+ if [ "$rc" -eq 3 ]; then degraded 3 credentials-absent; fi
219
+ degraded 4 "query-failed-$name"
220
+ fi
221
+ # EVERY line must be a JSON object: valid rows followed by a `Code: ...` exception line, or an HTML body,
222
+ # exit 0 from the reader and are still not an answer.
223
+ if ! jq -se 'all(.[]; type == "object")' "$SCRATCH/$name.rows" > /dev/null 2>&1; then
224
+ degraded 4 "unparseable-$name"
225
+ fi
226
+ }
227
+
228
+ # Each marker predicate requires the marker at the START of the decoded message (a log line that merely
229
+ # mentions a marker name, such as a request path, is not a marker row) and, for the failed-deploy diag, the
230
+ # kernel section only (the other ~15 sections must not crowd the kernel row out of LIMIT BY).
231
+ MARKERS="(position(raw,'SOLEUR_INNGEST_SERVER_PROBE')>0 AND startsWith(JSONExtractString(raw,'message'),'SOLEUR_INNGEST_SERVER_PROBE ')) OR (position(raw,'SOLEUR_CANARY_SANDBOX_DIAG')>0 AND position(raw,'section=kernel')>0 AND startsWith(JSONExtractString(raw,'message'),'SOLEUR_CANARY_SANDBOX_DIAG: ')) OR (position(raw,'SOLEUR_PRIVATE_NIC')>0 AND startsWith(JSONExtractString(raw,'message'),'SOLEUR_PRIVATE_NIC ')) OR (position(raw,'SOLEUR_ZOT_DISK')>0 AND startsWith(JSONExtractString(raw,'message'),'SOLEUR_ZOT_DISK '))"
232
+
233
+ union_sql() { # $1 = window, $2 = extra predicate, prints the inner hot+archive union (archive arm ALWAYS included)
234
+ printf "SELECT dt, raw FROM remote(\$BS_TABLE) WHERE dt > now() - INTERVAL %s AND (%s) UNION ALL SELECT dt, raw FROM s3Cluster(primary, \$BS_TABLE_S3) WHERE _row_type = 1 AND dt > now() - INTERVAL %s AND (%s)" \
235
+ "$1" "$2" "$1" "$2"
236
+ }
237
+
238
+ if [ "$MODE" = "image-findings" ]; then
239
+ SQL="SELECT dt, raw FROM ($(union_sql "$MARKER_WINDOW" "position(raw,'${IMG_MARKER}')>0")) ORDER BY dt DESC LIMIT 5 FORMAT JSONEachRow"
240
+ run_query image "$SQL"
241
+ jq -n -r --arg marker "$IMG_MARKER" --argjson ids "$IMAGE_IDS" --argjson fresh "$FRESH_HOURS" '
242
+ def valid_dt: type == "string" and test("\\A[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?\\z");
243
+ def ts: sub("\\.[0-9]+\\z"; "") | strptime("%Y-%m-%d %H:%M:%S") | mktime;
244
+ [ inputs | select(type == "object" and (.dt | valid_dt) and (.raw | type == "string"))
245
+ | (.dt | ts) as $t | select($t <= now + 300)
246
+ | (.raw | try fromjson catch null) as $d | select($d | type == "object")
247
+ | select(($d.SYSLOG_IDENTIFIER // "") == "" and ($d.host_name // "") == "")
248
+ | ($d.message // "") as $m | select($m | type == "string")
249
+ | (if $m == $marker and ($d.message_json | type) == "object" then $d.message_json
250
+ elif $m == $marker and ($d.message_json | type) == "string" then ($d.message_json | try fromjson catch null)
251
+ elif ($m | startswith($marker + " ")) then ($m | ltrimstr($marker + " ") | try fromjson catch null)
252
+ else empty end) as $j
253
+ | select($j | type == "object" and .marker == $marker and .schema == 2)
254
+ | {t: $t, j: $j} ] | sort_by(.t) | last // null
255
+ | if . == null then "image_findings unknown unknown yes unknown\nSOLEUR_CVE_HOST_STATE mode=image-findings state=unknown match=unknown"
256
+ else
257
+ ([(((now - .t) / 3600) | floor), 0] | max) as $age
258
+ | (if .j.status != "measured" then "unknown" elif (now - .t) <= ($fresh * 3600) then "fresh" else "stale" end) as $state
259
+ | (.j.findings // []) as $f
260
+ | ($f | if type == "array" then . else [] end) as $fl
261
+ # capped means the findings list reached the producer cap of 50 entries (truncated). The list holds only
262
+ # fixable critical/high matches, so even an uncapped list never proves absence; informational column only.
263
+ | (if ($fl | length) >= 50 then "yes" else "no" end) as $capped
264
+ | ([$fl[] | select(type == "object") | .id as $x | select($ids | index($x) != null)] | length > 0) as $hit
265
+ # The findings list holds only fixable critical/high matches, so absence from it never establishes
266
+ # absence from the image: a hit is `yes`, everything else is `unknown` (never `no`).
267
+ | (if $hit then "yes" else "unknown" end) as $match
268
+ | "image_findings \($state) \($age) \($capped) \($match)\nSOLEUR_CVE_HOST_STATE mode=image-findings state=\($state) match=\($match)"
269
+ end' "$SCRATCH/image.rows" > "$SCRATCH/image.out" 2>/dev/null || degraded 4 image-decode-failed
270
+ # Re-validate: two lines, anchored shapes, nothing else may reach the session.
271
+ L1="$(sed -n 1p "$SCRATCH/image.out")"; L2="$(sed -n 2p "$SCRATCH/image.out")"
272
+ [[ "$L1" =~ ^image_findings\ (fresh|stale|unknown)\ ([0-9]{1,6}|unknown)\ (yes|no)\ (yes|unknown)$ ]] || degraded 4 image-shape
273
+ [[ "$L2" =~ ^SOLEUR_CVE_HOST_STATE\ mode=image-findings\ state=(fresh|stale|unknown)\ match=(yes|unknown)$ ]] || degraded 4 image-shape
274
+ printf '%s\n%s\n' "$L1" "$L2"
275
+ exit 0
276
+ fi
277
+
278
+ # --- POSITIVE CONTROL: some host must have shipped a row recently, else the source is dark (ADR-197) ----
279
+ CONTROL_SQL="SELECT JSONExtractString(raw,'host_name') AS h, count() AS n FROM ($(union_sql "$CONTROL_WINDOW" "1=1")) GROUP BY h ORDER BY n DESC LIMIT 50 FORMAT JSONEachRow"
280
+ run_query control "$CONTROL_SQL"
281
+ if ! jq -se 'any(.[]; (.h | type == "string") and (.h | length) > 0 and ((.n | tonumber? // 0) > 0))' "$SCRATCH/control.rows" > /dev/null 2>&1; then
282
+ degraded 2 control-returned-no-host-rows
283
+ fi
284
+
285
+ MARKER_SQL="SELECT dt, raw, multiIf(position(raw,'SOLEUR_INNGEST_SERVER_PROBE')>0,'probe',position(raw,'SOLEUR_CANARY_SANDBOX_DIAG')>0,'canary',position(raw,'SOLEUR_PRIVATE_NIC')>0,'nic','zot') AS k FROM ($(union_sql "$MARKER_WINDOW" "$MARKERS")) ORDER BY dt DESC LIMIT 6 BY k, JSONExtractString(raw,'host_name'), JSONExtractString(raw,'SYSLOG_IDENTIFIER') FORMAT JSONEachRow"
286
+ run_query marker "$MARKER_SQL"
287
+
288
+ ROLES_JSON="$(printf '%s\n' "$ROLE_TABLE" | jq -R -s -c 'split("\n") | map(select(length > 0) | split("|") | {role: .[0], host: .[1]})')" || degraded 4 role-table
289
+ HOSTS_SEEN="$(jq -s -c '[.[] | select(.h | type == "string") | select((.h | length) > 0 and ((.n | tonumber? // 0) > 0)) | .h]' "$SCRATCH/control.rows" 2>/dev/null)" || degraded 4 control-decode
290
+
291
+ jq -n -c --argjson roles "$ROLES_JSON" --argjson seen "$HOSTS_SEEN" --argjson fresh "$FRESH_HOURS" --arg regid "$REGISTRY_HOST_ID" \
292
+ '
293
+ def valid_dt: type == "string" and test("\\A[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?\\z");
294
+ def ts: sub("\\.[0-9]+\\z"; "") | strptime("%Y-%m-%d %H:%M:%S") | mktime;
295
+ def hrs($t): ([(((now - $t) / 3600) | floor), 0] | max);
296
+ def fresh_row($t): (now - $t) <= ($fresh * 3600);
297
+ def hostof($r): ([ $roles[] | select(.role == $r) | .host ][0]);
298
+ def kv($m; $k): ([$m | capture("(?:\\A| )" + $k + "=(?<v>[^ ]+)") | .v][0]);
299
+ def uptime($m): (kv($m; "uptime_s") | select(. != null and test("\\A[0-9]{1,12}\\z")));
300
+ def roleof($hn): ([ $roles[] | select(.host == $hn and .host != "-") | .role ][0] // "unmapped");
301
+ [ inputs | select(type == "object" and (.dt | valid_dt) and (.raw | type == "string"))
302
+ | (.dt | ts) as $t | select($t <= now + 300)
303
+ | (.raw | try fromjson catch null) as $d | select($d | type == "object")
304
+ | {t: $t, si: ($d.SYSLOG_IDENTIFIER // ""), hn: ($d.host_name // ""), msg: ($d.message // "")}
305
+ | select((.si | type == "string") and (.hn | type == "string") and (.msg | type == "string")) ]
306
+ | map(
307
+ if .si == "inngest-server-probe" and (.msg | startswith("SOLEUR_INNGEST_SERVER_PROBE ")) then
308
+ (kv(.msg; "host_role")) as $hr
309
+ | { marker: "probe", t: .t, up: (uptime(.msg) // null),
310
+ role: (if $hr == "web" and .hn == hostof("web-1") then "web-1"
311
+ elif $hr == "dedicated" and .hn == hostof("inngest") then "inngest"
312
+ else "unmapped" end) }
313
+ elif .si == "ci-deploy" and (.msg | startswith("SOLEUR_CANARY_SANDBOX_DIAG: ")) and (.msg | test(" section=kernel val=\"kernel=")) then
314
+ { marker: "canary", t: .t, role: roleof(.hn),
315
+ kernel: ([.msg | capture(" section=kernel val=\"kernel=(?<k>[^ \"]+) ") | .k][0]) }
316
+ elif .si == "" and .hn == "" and (.msg | startswith("SOLEUR_PRIVATE_NIC ")) then
317
+ { marker: "nic", t: .t, role: "registry", up: (uptime(.msg) // null) }
318
+ elif .si == "" and .hn == "" and (.msg | startswith("SOLEUR_ZOT_DISK ")) then
319
+ { marker: "zot", t: .t, role: (if kv(.msg; "host") == $regid then "registry" else "unmapped" end) }
320
+ else empty end)
321
+ | . as $c
322
+ | ($c | map(select(.role == "unmapped")) | length) as $unm_rows
323
+ | ([ $seen[] | select(. as $h | ([$roles[] | .host] | index($h)) == null) ] | length) as $unm_hosts
324
+ | ( reduce $roles[] as $r ({};
325
+ . + { ($r.role): (
326
+ ($c | map(select(.role == $r.role))) as $mine
327
+ | ($mine | map(select(.marker != "canary")) | sort_by(.t) | last // null) as $per
328
+ | ($mine | map(select(.marker == "canary" and .kernel != null and (.kernel | test("\\A[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+-[a-z0-9-]+\\z"))))
329
+ | sort_by(.t) | last // null) as $kern
330
+ | ($mine | map(select(.marker == "canary")) | length > 0) as $anycanary
331
+ | ($mine | map(select(.up != null and fresh_row(.t))) | sort_by(.t) | last // null) as $upr
332
+ | ($r.host != "-" and ($seen | index($r.host)) != null) as $seen_host
333
+ | (if $r.role == "git-data" then {marker_state: "unknown", source_marker: "source-not-read"}
334
+ elif $per != null then
335
+ {marker_state: (if fresh_row($per.t) then "fresh" else "stale" end), age_hours: hrs($per.t),
336
+ source_marker: ($mine | map(.marker) | unique | join(","))}
337
+ elif $anycanary then
338
+ {marker_state: "stale", age_hours: hrs(($mine | map(select(.marker == "canary")) | sort_by(.t) | last).t), source_marker: "canary"}
339
+ elif $seen_host then {marker_state: "silent", source_marker: "none"}
340
+ else {marker_state: "unknown", source_marker: "none"} end)
341
+ + (if $kern != null and $r.role != "git-data" then {kernel_state: "observed", kernel: $kern.kernel, kernel_age_hours: hrs($kern.t)} else {} end)
342
+ + (if $upr != null then {uptime_s: $upr.up} else {} end)
343
+ ) })
344
+ ) as $facts
345
+ | if ($unm_rows + $unm_hosts) > 0
346
+ then $facts + {unmapped: {marker_state: "unknown", source_marker: "unlisted-hosts"}}
347
+ else $facts end
348
+ ' "$SCRATCH/marker.rows" > "$FACTS.new" 2> "$SCRATCH/decode.err" || degraded 4 marker-decode-failed
349
+ mv "$FACTS.new" "$FACTS"
350
+
351
+ print_all_roles
352
+ finish 0
@@ -0,0 +1,256 @@
1
+ #!/usr/bin/env bash
2
+ # file-gap-issue.test.sh - behavioural suite for skills/cve-exposure/scripts/file-gap-issue.sh (Guard 3, #12006).
3
+ #
4
+ # `gh` is shadowed on PATH by a stub that records every call (argv, one line each) and serves fixtures.
5
+ # Final line: `file-gap-issue: PASS` or `file-gap-issue: FAIL`.
6
+ #
7
+ # FILE_GAP_SUT_OVERRIDE runs the suite against a mutated COPY of the script (the plan's mutation matrix).
8
+ set -uo pipefail
9
+ export LC_ALL=C
10
+
11
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+ SUT="${FILE_GAP_SUT_OVERRIDE:-$HERE/../scripts/file-gap-issue.sh}"
13
+
14
+ PASSES=0; FAILS=0; QUIET=0
15
+ ok() { PASSES=$((PASSES + 1)); }
16
+ bad() { FAILS=$((FAILS + 1)); [ "$QUIET" -eq 1 ] || printf 'FAIL: %s\n' "$1" >&2; }
17
+ eq() { if [ "$2" = "$3" ]; then ok; else bad "$1 (want [$3] got [$2])"; fi; }
18
+ has() { if grep -qF -- "$3" <<< "$2"; then ok; else bad "$1 (missing [$3])"; fi; }
19
+ hasnt() { if grep -qF -- "$3" <<< "$2"; then bad "$1 (unexpected [$3])"; else ok; fi; }
20
+
21
+ SP0=$PASSES; SF0=$FAILS
22
+ QUIET=1
23
+ ok; bad "selftest-bad"
24
+ eq "selftest-eq" "a" "b"
25
+ has "selftest-has" "abc" "zzz"
26
+ hasnt "selftest-hasnt" "abc" "abc"
27
+ hasnt "selftest-hasnt-ok" "abc" "zzz"
28
+ QUIET=0
29
+ if [ "$PASSES" -ne $((SP0 + 2)) ] || [ "$FAILS" -ne $((SF0 + 4)) ]; then
30
+ printf 'file-gap-issue: FAIL (instrument self-test: ok/bad/eq/has/hasnt did not each move their counter)\n'; exit 1
31
+ fi
32
+ FAILS=$SF0
33
+
34
+ [ -f "$SUT" ] || { printf 'file-gap-issue: FAIL (script missing: %s)\n' "$SUT"; exit 1; }
35
+ command -v jq > /dev/null || { printf 'file-gap-issue: FAIL (jq required)\n'; exit 1; }
36
+
37
+ WORK="$(mktemp -d -t soleur-cve-gap-test.XXXXXXXX)"
38
+ trap 'rm -rf "$WORK"' EXIT
39
+ BIN="$WORK/bin"; FX="$WORK/fx"; mkdir -p "$BIN" "$FX"
40
+
41
+ cat > "$BIN/gh" <<'STUB'
42
+ #!/usr/bin/env bash
43
+ FX="$(cd "$(dirname "$0")/.." && pwd)/fx"
44
+ printf '%s\n' "$*" >> "$FX/calls"
45
+ case "${1:-} ${2:-}" in
46
+ "issue list")
47
+ [ -f "$FX/list.raw" ] && { cat "$FX/list.raw"; exit 0; }
48
+ [ -f "$FX/list.rc" ] && rc="$(cat "$FX/list.rc")" || rc=0
49
+ [ "$rc" -eq 0 ] && { [ -f "$FX/list.json" ] && cat "$FX/list.json" || echo '[]'; }
50
+ exit "$rc" ;;
51
+ "issue create")
52
+ [ -f "$FX/create.rc" ] && rc="$(cat "$FX/create.rc")" || rc=0
53
+ [ "$rc" -eq 0 ] && echo "https://example.invalid/issues/1"
54
+ exit "$rc" ;;
55
+ *) echo "stub gh: unexpected call: $*" >&2; exit 99 ;;
56
+ esac
57
+ STUB
58
+ chmod +x "$BIN/gh"
59
+
60
+ RUN_OUT=""; RUN_RC=0
61
+ run_gap() {
62
+ RUN_RC=0
63
+ RUN_OUT="$(env -u CI -u GITHUB_ACTIONS -u HEADLESS_MODE PATH="$BIN:$PATH" bash "$SUT" "$@" 2>&1)" || RUN_RC=$?
64
+ }
65
+ reset() { rm -f "$FX"/*; : > "$FX/calls"; }
66
+ creates() { grep -c '^issue create' "$FX/calls" 2> /dev/null || true; }
67
+ nonlist_calls() { grep -vc '^issue list' "$FX/calls" 2> /dev/null || true; }
68
+
69
+ CID=CVE-2099-0001
70
+ # ---- baseline: draft by default, nothing filed, no gh call at all ----------------------------------------
71
+ reset; run_gap --cve $CID --class infra --exploitation none-found
72
+ eq "draft exits 0" "$RUN_RC" 0
73
+ has "draft shows the fixed title" "$RUN_OUT" "title: [cve-exposure] $CID infra"
74
+ has "draft carries the single status" "$RUN_OUT" "Status: exposure-review-needed"
75
+ has "draft disclaims a security representation" "$RUN_OUT" "not a security representation"
76
+ eq "draft makes no create call" "$(creates)" 0
77
+
78
+ # ---- Guard 3 row 1: a version and a hostname are refused as --class ---------------------------------------
79
+ for v in 6.8.0-90-generic web-1 'infra;x' ''; do
80
+ reset; run_gap --cve $CID --class "$v" --exploitation none-found --create
81
+ eq "class [$v] exits 64" "$RUN_RC" 64
82
+ eq "class [$v] files nothing" "$(creates)" 0
83
+ done
84
+ # free text cannot arrive through any other door either
85
+ for extra in "--title x" "--body y" "--version 6.8.0-90-generic" "positional"; do
86
+ reset; # shellcheck disable=SC2086
87
+ run_gap --cve $CID --class infra --exploitation none-found $extra
88
+ eq "extra argument [$extra] exits 64" "$RUN_RC" 64
89
+ done
90
+ reset; run_gap --cve 'CVE-2099-0001; touch x' --class infra --exploitation none-found
91
+ eq "a CVE with a shell fragment exits 64" "$RUN_RC" 64
92
+ reset; run_gap --cve $CID --class infra
93
+ eq "missing --exploitation exits 64" "$RUN_RC" 64
94
+ reset; run_gap --cve $CID --class infra --exploitation maybe
95
+ eq "unknown exploitation value exits 64" "$RUN_RC" 64
96
+
97
+ # ---- row 2: --create with unknown is draft-only; present is non-zero and files nothing --------------------
98
+ reset; run_gap --cve $CID --class infra --exploitation unknown --create
99
+ eq "unknown + --create is refused" "$RUN_RC" 7
100
+ eq "unknown + --create creates nothing" "$(creates)" 0
101
+ has "unknown + --create prints the draft" "$RUN_OUT" "draft issue"
102
+ reset; run_gap --cve $CID --class infra --exploitation present --create
103
+ eq "present exits 5" "$RUN_RC" 5
104
+ eq "present makes no gh call at all" "$(wc -l < "$FX/calls" | tr -d ' ')" 0
105
+ has "present hands off to the breach register" "$RUN_OUT" "breach-register.md"
106
+ reset; run_gap --cve $CID --class infra --exploitation present
107
+ eq "present without --create also exits 5" "$RUN_RC" 5
108
+
109
+ # ---- row 3: dedupe over closed AND open; never comment/edit/reopen -----------------------------------------
110
+ reset
111
+ printf '%s\n' "[{\"number\":7,\"title\":\"[cve-exposure] $CID infra\",\"url\":\"https://example.invalid/issues/7\"}]" > "$FX/list.json"
112
+ run_gap --cve $CID --class infra --exploitation none-found --create
113
+ eq "an existing (closed or open) match exits 0" "$RUN_RC" 0
114
+ eq "an existing match creates nothing" "$(creates)" 0
115
+ has "an existing match is reported by URL" "$RUN_OUT" "https://example.invalid/issues/7"
116
+ eq "the only gh call is the dedupe listing" "$(nonlist_calls)" 0
117
+ has "the dedupe query spans all states" "$(cat "$FX/calls")" "--state all"
118
+ has "the dedupe query searches the title" "$(cat "$FX/calls")" "in:title [cve-exposure] $CID infra"
119
+ reset
120
+ printf '%s\n' "[{\"number\":8,\"title\":\"[cve-exposure] $CID runtime\",\"url\":\"https://example.invalid/issues/8\"}]" > "$FX/list.json"
121
+ run_gap --cve $CID --class infra --exploitation none-found --create
122
+ eq "a different-class title is not a duplicate (create proceeds)" "$(creates)" 1
123
+
124
+ # ---- row 5: unauthenticated gh prints the draft and exits non-zero -----------------------------------------
125
+ reset; printf '4\n' > "$FX/list.rc"
126
+ run_gap --cve $CID --class infra --exploitation none-found --create
127
+ eq "unauthenticated gh exits 6" "$RUN_RC" 6
128
+ eq "unauthenticated gh creates nothing" "$(creates)" 0
129
+ has "unauthenticated gh still prints the draft" "$RUN_OUT" "draft issue"
130
+ has "unauthenticated gh names the cause (not the unreadable-output branch)" "$RUN_OUT" "gh unavailable or unauthenticated (rc=4)"
131
+
132
+ # ---- happy path: the one create call is exactly the fixed shape -------------------------------------------
133
+ reset; run_gap --cve $CID --class infra --exploitation none-found --create
134
+ eq "create path exits 0" "$RUN_RC" 0
135
+ eq "exactly one create call" "$(creates)" 1
136
+ CALL="$(grep '^issue create' "$FX/calls")"
137
+ has "create uses the fixed title" "$CALL" "--title [cve-exposure] $CID infra"
138
+ has "create passes the body by file" "$CALL" "--body-file"
139
+ has "create labels type/security" "$CALL" "--label type/security"
140
+ has "create carries a milestone" "$CALL" "--milestone"
141
+ # ---- row 6: the recorded argv has no free text beyond the fixed title and --body-file -----------------------
142
+ EXTRA="$(sed -E 's/^issue create -R jikig-ai\/soleur --title \[cve-exposure\] [A-Za-z0-9-]+ [a-z]+ --body-file [^ ]+ --label type\/security --milestone Post-MVP \/ Later$//' <<< "$CALL")"
143
+ eq "no argv beyond the fixed shape" "$EXTRA" ""
144
+ # the create call keeps working when create fails: draft and non-zero
145
+ reset; printf '1\n' > "$FX/create.rc"
146
+ run_gap --cve $CID --class dependency --exploitation none-found --create
147
+ eq "a failed create exits 6 with a draft" "$RUN_RC" 6
148
+
149
+ # headless never creates
150
+ reset; env -u CI -u GITHUB_ACTIONS PATH="$BIN:$PATH" HEADLESS_MODE=true bash "$SUT" --cve $CID --class infra --exploitation none-found --create > "$WORK/o" 2>&1; RUN_RC=$?
151
+ eq "headless --create is refused" "$RUN_RC" 7
152
+ eq "headless --create files nothing" "$(creates)" 0
153
+
154
+ # ---- the unattended-run detector: the repo exports HEADLESS_MODE as 1/0 (not "true"), CI runs set CI -------------------
155
+ for hv in 1 true yes; do
156
+ reset; env -u CI -u GITHUB_ACTIONS PATH="$BIN:$PATH" HEADLESS_MODE=$hv bash "$SUT" --cve $CID --class infra --exploitation none-found --create > "$WORK/o" 2>&1; RUN_RC=$?
157
+ eq "HEADLESS_MODE=$hv refuses --create" "$RUN_RC" 7
158
+ eq "HEADLESS_MODE=$hv files nothing" "$(creates)" 0
159
+ done
160
+ for hv in 0 false ""; do
161
+ reset; env -u CI -u GITHUB_ACTIONS PATH="$BIN:$PATH" HEADLESS_MODE=$hv bash "$SUT" --cve $CID --class infra --exploitation none-found --create > "$WORK/o" 2>&1; RUN_RC=$?
162
+ eq "HEADLESS_MODE='$hv' allows --create" "$RUN_RC" 0
163
+ eq "HEADLESS_MODE='$hv' files exactly one issue" "$(creates)" 1
164
+ done
165
+ reset; env -u GITHUB_ACTIONS -u HEADLESS_MODE CI=1 PATH="$BIN:$PATH" bash "$SUT" --cve $CID --class infra --exploitation none-found --create > "$WORK/o" 2>&1; RUN_RC=$?
166
+ eq "CI=1 refuses --create" "$RUN_RC" 7
167
+ reset; env -u CI -u HEADLESS_MODE GITHUB_ACTIONS=true PATH="$BIN:$PATH" bash "$SUT" --cve $CID --class infra --exploitation none-found --create > "$WORK/o" 2>&1; RUN_RC=$?
168
+ eq "GITHUB_ACTIONS=true refuses --create" "$RUN_RC" 7
169
+ eq "the refusal says the yes is not verifiable here" "$(grep -c 'not verifiable here' "$WORK/o")" 1
170
+
171
+ # ---- dedupe is exact-title over a REAL list: second element, superstring, unreadable output ----------------------
172
+ reset
173
+ printf '%s\n' "[{\"number\":1,\"title\":\"[cve-exposure] $CID runtime\",\"url\":\"https://example.invalid/issues/1\"},{\"number\":2,\"title\":\"[cve-exposure] $CID infra\",\"url\":\"https://example.invalid/issues/2\"}]" > "$FX/list.json"
174
+ run_gap --cve $CID --class infra --exploitation none-found --create
175
+ eq "a duplicate that is the SECOND list element is found" "$(creates)" 0
176
+ has "and its URL is reported" "$RUN_OUT" "https://example.invalid/issues/2"
177
+ reset
178
+ printf '%s\n' "[{\"number\":3,\"title\":\"[cve-exposure] $CID infra (follow-up)\",\"url\":\"https://example.invalid/issues/3\"}]" > "$FX/list.json"
179
+ run_gap --cve $CID --class infra --exploitation none-found --create
180
+ eq "a longer title is not a duplicate (create proceeds)" "$(creates)" 1
181
+ reset; printf '<html>502 Bad Gateway</html>\n' > "$FX/list.raw"
182
+ run_gap --cve $CID --class infra --exploitation none-found --create
183
+ eq "an unreadable duplicate check exits 6" "$RUN_RC" 6
184
+ eq "an unreadable duplicate check files nothing" "$(creates)" 0
185
+ reset; : > "$FX/list.raw"
186
+ run_gap --cve $CID --class infra --exploitation none-found --create
187
+ eq "an EMPTY list output is unreadable, not 'no duplicate' (exit 6)" "$RUN_RC" 6
188
+ eq "an empty list output files nothing" "$(creates)" 0
189
+ reset; printf '{"message":"rate limited"}\n' > "$FX/list.raw"
190
+ run_gap --cve $CID --class infra --exploitation none-found --create
191
+ eq "a JSON object (not an array) from gh is unreadable too" "$(creates)" 0
192
+ reset; printf '{"x":{"title":"[cve-exposure] %s infra","url":"https://example.invalid/issues/9"}}\n' "$CID" > "$FX/list.raw"
193
+ run_gap --cve $CID --class infra --exploitation none-found --create
194
+ eq "an OBJECT whose value looks like a duplicate is unreadable, not a duplicate (exit 6)" "$RUN_RC" 6
195
+ reset; run_gap --cve $CID --class infra --exploitation none-found --create
196
+ LISTCALL="$(grep '^issue list' "$FX/calls")"
197
+ has "the duplicate check is pinned to the upstream repo" "$LISTCALL" "-R jikig-ai/soleur"
198
+ has "the duplicate check is not capped at 50" "$LISTCALL" "--limit 200"
199
+
200
+ # ---- draft content: exact body, label and milestone lines ------------------------------------------------------------
201
+ reset; run_gap --cve $CID --class dependency --exploitation none-found
202
+ has "draft names the label" "$RUN_OUT" "label: type/security"
203
+ has "draft names the milestone" "$RUN_OUT" "milestone: Post-MVP / Later"
204
+ BODY_ACTUAL="$(sed -n '/^Status: exposure-review-needed$/,$p' <<< "$RUN_OUT")"
205
+ BODY_WANT="$(printf 'Status: exposure-review-needed\n\nSoleur has not been able to establish its exposure to %s (component class: dependency) from the sources it reads.\n\nThis is not a security representation and does not establish the presence or absence of exposure.\nDetails are not recorded in this repository.' "$CID")"
206
+ eq "the body is EXACTLY the fixed template (no appended line can ride along)" "$BODY_ACTUAL" "$BODY_WANT"
207
+
208
+ # ---- id shapes ---------------------------------------------------------------------------------------------------------
209
+ for badid in cve-2099-0001 CVE-2099-1 GHSA-ABCD-EF12-3456 GHSA-abcd-ef12 CVE-99-0001; do
210
+ reset; run_gap --cve "$badid" --class infra --exploitation none-found
211
+ eq "id [$badid] exits 64" "$RUN_RC" 64
212
+ done
213
+
214
+ # ---- row 7: must-PASS non-canonical input -----------------------------------------------------------------
215
+ reset; run_gap --cve GHSA-abcd-ef12-3456 --class dependency --exploitation none-found --create
216
+ eq "a GHSA id with --class dependency is accepted" "$RUN_RC" 0
217
+ eq "a GHSA id files one issue" "$(creates)" 1
218
+ has "a GHSA id appears in the title" "$(cat "$FX/calls")" "[cve-exposure] GHSA-abcd-ef12-3456 dependency"
219
+
220
+ # ---- the rendered body can carry no version or host: it is a fixed template ---------------------------------
221
+ reset; run_gap --cve $CID --class runtime --exploitation none-found
222
+ hasnt "body names no kernel-shaped version" "$RUN_OUT" "-generic"
223
+ if grep -qE '[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-' <<< "$RUN_OUT"; then bad "body contains a kernel-shaped version"; else ok; fi
224
+ if grep -qiE 'not affected|patched|not vulnerable|mitigated' <<< "$RUN_OUT"; then bad "body asserts a safe status"; else ok; fi
225
+
226
+ # ---- the documented enums and the status literal match the script (they are replicated in the docs) -------------------
227
+ DOC="$HERE/../references/disclosure-and-verdicts.md"
228
+ for w in "infra|runtime|dependency" "none-found|unknown|present" "exposure-review-needed"; do
229
+ if grep -qF -- "$w" "$DOC"; then ok; else bad "disclosure reference lacks [$w]"; fi
230
+ done
231
+ if grep -qF 'exposure-review-needed' "$SUT"; then ok; else bad "script lacks the status literal"; fi
232
+ for w in infra runtime dependency none-found unknown present; do
233
+ if grep -qE "(^|[^a-z-])$w([^a-z-]|$)" "$SUT"; then ok; else bad "script does not mention enum value [$w]"; fi
234
+ done
235
+
236
+ # ---- the script is the only writer: no other file in the skill creates issues or PRs -------------------------
237
+ SKILL_DIR="$(cd "$HERE/.." && pwd)"
238
+ STRAY="$(grep -nE 'gh (issue|pr) (create|comment|edit|close|reopen)|gh api' "$SKILL_DIR/SKILL.md" "$SKILL_DIR"/references/*.md "$SKILL_DIR/scripts/host-state.sh" 2> /dev/null || true)"
239
+ eq "no other skill file calls gh issue/pr create" "$STRAY" ""
240
+ if grep -qE '(^|[^-])set -x' "$SUT"; then bad "script enables tracing"; else ok; fi
241
+
242
+ # ---- floor and verdict -------------------------------------------------------------------------------------
243
+ SELFTEST_PASSES=1
244
+ REAL=$((PASSES - SELFTEST_PASSES))
245
+ MIN_CASES=97
246
+ if [ "$REAL" -lt "$MIN_CASES" ]; then
247
+ printf 'file-gap-issue: FAIL (only %s assertions ran; floor %s - the suite may have been truncated)\n' "$REAL" "$MIN_CASES"
248
+ exit 1
249
+ fi
250
+ if [ "$FAILS" -gt 0 ]; then
251
+ printf '%s assertions, %s failed\n' "$((REAL + FAILS))" "$FAILS"
252
+ printf 'file-gap-issue: FAIL\n'
253
+ exit 1
254
+ fi
255
+ printf '%s assertions passed\n' "$REAL"
256
+ printf 'file-gap-issue: PASS\n'