-
Notifications
You must be signed in to change notification settings - Fork 0
335 lines (304 loc) · 13.9 KB
/
Copy pathfable5-dogfood.yml
File metadata and controls
335 lines (304 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
name: FABLE5 Informational Dogfood
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read
jobs:
dogfood:
name: Published-verifier informational dogfood
runs-on: ubuntu-latest
steps:
- name: Check out repository with base history
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v7
with:
python-version: "3.11"
- name: Install the published FABLE5 verifier
shell: bash
run: |
set -euo pipefail
evidence_dir="$RUNNER_TEMP/fable5-dogfood-evidence"
mkdir -p "$evidence_dir"
python -m pip install --disable-pip-version-check fable5-assurance-toolkit==0.3.0rc6
installed_version="$(python -c 'from importlib.metadata import version; print(version("fable5-assurance-toolkit"))')"
test "$installed_version" = "0.3.0rc6"
{
assurance --version
printf 'python-distribution-version: %s\n' "$installed_version"
} > "$evidence_dir/identity.txt"
- name: Execute informational base-to-head dogfood
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
EVENT_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
EVENT_PUSH_BEFORE: ${{ github.event.before }}
EVENT_GITHUB_SHA: ${{ github.sha }}
run: |
set -euo pipefail
evidence_dir="$RUNNER_TEMP/fable5-dogfood-evidence"
manifest="$RUNNER_TEMP/fable5-task236-base-manifest.jsonl"
workspace_path="$GITHUB_WORKSPACE"
event="$EVENT_NAME"
mkdir -p "$evidence_dir"
case "$event" in
pull_request)
base_sha="$EVENT_PR_BASE_SHA"
head_sha="$EVENT_PR_HEAD_SHA"
;;
push)
base_sha="$EVENT_PUSH_BEFORE"
head_sha="$EVENT_GITHUB_SHA"
;;
workflow_dispatch)
head_sha="$EVENT_GITHUB_SHA"
base_sha="$(git show -s --format=%P "$head_sha" | awk '{print $1}')"
;;
*)
printf 'unsupported event: %s\n' "$event" >&2
exit 1
;;
esac
if [[ -z "$head_sha" ]] || [[ -z "$base_sha" ]] || [[ "$base_sha" =~ ^0{40}$ ]]; then
python - "$evidence_dir/decision.json" "$event" "$base_sha" "$head_sha" <<'PY'
import json
import sys
path, event, base_sha, head_sha = sys.argv[1:]
payload = {
"task_id": "TASK236",
"mode": "informational_nonblocking",
"event": event,
"base_sha": base_sha,
"head_sha": head_sha,
"tool": "fable5-assurance-toolkit==0.3.0rc6",
"positive_control_pass": False,
"canary": {"landed_proven": False, "ci10_observed": False, "process_exit": None},
"ordinary_tests": {"executed": False, "exit": None, "count": None},
"head_observation": {
"structured_json_parsed": False,
"process_exit": None,
"result": "BASE_UNAVAILABLE",
"finding_codes": [],
"finding_severities": [],
},
"observed_decision": "BASE_UNAVAILABLE",
"human_review_required": True,
"same_workspace_path_used": True,
"enforced": False,
}
with open(path, "w", encoding="utf-8") as handle:
json.dump(payload, handle, sort_keys=True, indent=2)
handle.write("\n")
PY
printf '%s\n' 'FABLE5_TASK236=BASE_UNAVAILABLE' >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
git cat-file -e "$base_sha^{commit}"
git cat-file -e "$head_sha^{commit}"
git checkout --detach "$base_sha"
test "$(pwd -P)" = "$workspace_path"
base_tree="$(git rev-parse "$base_sha^{tree}")"
source_path="$workspace_path/src"
test -d "$source_path"
assurance corpus freeze "$source_path" --manifest "$manifest" --format json > /dev/null
manifest_sha256="$(sha256sum "$manifest" | awk '{print $1}')"
set +e
assurance corpus verify "$manifest" --accepted-manifest-sha256 "$manifest_sha256" --expected-root "$source_path" --detect-new --format json > "$evidence_dir/base-positive.json"
base_positive_exit=$?
set -e
python - "$evidence_dir/base-positive.json" "$base_positive_exit" <<'PY'
import json
import sys
path, process_exit = sys.argv[1:]
with open(path, encoding="utf-8") as handle:
payload = json.load(handle)
if int(process_exit) != 0 or payload.get("result") != "PASS" or payload.get("findings") != []:
raise SystemExit("Task236 positive control is not clean")
PY
canary_path="$source_path/.fable5_task236_canary.py"
expected_canary_sha256="49851d4c1e906efa99c03b0127c32197490a0d72be438f188d0dcaf67b32a5ac"
printf '%s\n' \
'# Task236 ephemeral runner-only canary' \
'TASK236_CANARY = "fable5-dogfood"' > "$canary_path"
actual_canary_sha256="$(sha256sum "$canary_path" | awk '{print $1}')"
test "$actual_canary_sha256" = "$expected_canary_sha256"
test -f "$canary_path"
{
printf 'CANARY_PATH=%s\n' "$canary_path"
printf 'CANARY_SHA256=%s\n' "$actual_canary_sha256"
printf 'CANARY_PRESENT=YES\n'
printf '%s\n' 'CANARY_MACHINE_DECISION=ROUTE_TO_HUMAN_REVIEW'
} > "$evidence_dir/canary-proof.txt"
set +e
assurance corpus verify "$manifest" --accepted-manifest-sha256 "$manifest_sha256" --expected-root "$source_path" --detect-new --format json > "$evidence_dir/canary.json"
canary_exit=$?
set -e
python - "$evidence_dir/canary.json" "$evidence_dir/canary-decision.json" "$canary_exit" <<'PY'
import json
import sys
path, decision_path, process_exit = sys.argv[1:]
with open(path, encoding="utf-8") as handle:
payload = json.load(handle)
findings = [(item.get("code"), item.get("severity")) for item in payload.get("findings", [])]
if int(process_exit) != 0 or payload.get("result") != "PASS" or findings != [("CI10_NEW_SOURCE_DETECTED", "WARN")]:
raise SystemExit("Task236 canary did not produce its expected structured result")
with open(decision_path, "w", encoding="utf-8") as handle:
json.dump(
{
"observed_decision": "ROUTE_TO_HUMAN_REVIEW",
"human_review_required": True,
"process_exit": int(process_exit),
"finding_codes": ["CI10_NEW_SOURCE_DETECTED"],
},
handle,
sort_keys=True,
indent=2,
)
handle.write("\n")
PY
rm -f "$canary_path"
test ! -e "$canary_path"
test -z "$(git status --porcelain)"
git checkout --detach "$head_sha"
test "$(pwd -P)" = "$workspace_path"
head_tree="$(git rev-parse "$head_sha^{tree}")"
set +e
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=src python -m unittest discover -s tests -v > "$evidence_dir/ordinary-tests.log" 2>&1
ordinary_tests_exit=$?
set -e
ordinary_tests_count="$(sed -nE 's/^Ran ([0-9]+) tests?.*/\1/p' "$evidence_dir/ordinary-tests.log" | tail -n 1)"
failed_test_count="$(grep -c '_FailedTest' "$evidence_dir/ordinary-tests.log" || true)"
set +e
assurance corpus verify "$manifest" --accepted-manifest-sha256 "$manifest_sha256" --expected-root "$source_path" --detect-new --format json > "$evidence_dir/head-observation.json" 2> "$evidence_dir/head-observation.stderr"
head_verify_exit=$?
set -e
python - \
"$evidence_dir/decision.json" \
"$evidence_dir/head-observation.json" \
"$event" "$base_sha" "$head_sha" "$base_tree" "$head_tree" "$manifest_sha256" \
"$base_positive_exit" "$canary_exit" "$ordinary_tests_exit" "$ordinary_tests_count" "$failed_test_count" "$head_verify_exit" <<'PY'
import json
import sys
(
decision_path,
observation_path,
event,
base_sha,
head_sha,
base_tree,
head_tree,
manifest_sha256,
base_positive_exit,
canary_exit,
ordinary_tests_exit,
ordinary_tests_count,
failed_test_count,
head_verify_exit,
) = sys.argv[1:]
with open(observation_path, encoding="utf-8") as handle:
observation = json.load(handle)
findings = observation.get("findings")
if not isinstance(findings, list):
raise SystemExit("Task236 head observation is not a ModuleResult JSON payload")
codes = [item.get("code") for item in findings]
severities = [item.get("severity") for item in findings]
if not all(isinstance(code, str) for code in codes) or not all(isinstance(severity, str) for severity in severities):
raise SystemExit("Task236 head observation has malformed findings")
ordinary_count = int(ordinary_tests_count) if ordinary_tests_count else None
ordinary_green = int(ordinary_tests_exit) == 0 and int(failed_test_count) == 0
if not ordinary_green:
observed_decision = "ORDINARY_TESTS_NONGREEN"
human_review_required = True
elif any(severity in {"ERROR", "HOLD"} for severity in severities):
observed_decision = "BLOCKING_ACCEPTANCE_EVIDENCE"
human_review_required = True
elif "CI10_NEW_SOURCE_DETECTED" in codes:
observed_decision = "ROUTE_TO_HUMAN_REVIEW"
human_review_required = True
elif int(head_verify_exit) != 0 or observation.get("result") != "PASS":
observed_decision = "INVESTIGATE_NONGREEN"
human_review_required = True
else:
observed_decision = "CONTINUE"
human_review_required = False
payload = {
"task_id": "TASK236",
"mode": "informational_nonblocking",
"event": event,
"base_sha": base_sha,
"head_sha": head_sha,
"base_tree": base_tree,
"head_tree": head_tree,
"manifest_sha256": manifest_sha256,
"tool": "fable5-assurance-toolkit==0.3.0rc6",
"positive_control_pass": int(base_positive_exit) == 0,
"canary": {
"landed_proven": True,
"ci10_observed": "CI10_NEW_SOURCE_DETECTED" in [
item.get("code") for item in json.load(open(decision_path.replace("decision.json", "canary.json"), encoding="utf-8")).get("findings", [])
],
"process_exit": int(canary_exit),
},
"ordinary_tests": {
"executed": True,
"exit": int(ordinary_tests_exit),
"count": ordinary_count,
"failed_test_count": int(failed_test_count),
},
"head_observation": {
"structured_json_parsed": True,
"process_exit": int(head_verify_exit),
"result": observation.get("result", ""),
"finding_codes": codes,
"finding_severities": severities,
},
"observed_decision": observed_decision,
"human_review_required": human_review_required,
"same_workspace_path_used": True,
"enforced": False,
}
with open(decision_path, "w", encoding="utf-8") as handle:
json.dump(payload, handle, sort_keys=True, indent=2)
handle.write("\n")
PY
python - "$evidence_dir/subject.json" "$event" "$base_sha" "$head_sha" "$base_tree" "$head_tree" "$manifest_sha256" <<'PY'
import json
import sys
path, event, base_sha, head_sha, base_tree, head_tree, manifest_sha256 = sys.argv[1:]
payload = {
"event": event,
"base_sha": base_sha,
"head_sha": head_sha,
"base_tree": base_tree,
"head_tree": head_tree,
"manifest_sha256": manifest_sha256,
"same_workspace_path_used": True,
}
with open(path, "w", encoding="utf-8") as handle:
json.dump(payload, handle, sort_keys=True, indent=2)
handle.write("\n")
PY
{
printf '%s\n' '## FABLE5 informational dogfood'
printf '%s\n' "- Event: \`$event\`"
printf '%s\n' "- Base: \`$base_sha\`"
printf '%s\n' "- Head: \`$head_sha\`"
printf '%s\n' "- Manifest SHA-256: \`$manifest_sha256\`"
printf '%s\n' "- Ordinary tests: exit \`$ordinary_tests_exit\`, count \`${ordinary_tests_count:-unparsed}\`"
printf '%s\n' "- Observed decision: \`$(python -c 'import json; print(json.load(open("'"$evidence_dir"'/decision.json", encoding="utf-8"))["observed_decision"])')\`"
printf '%s\n' '- Enforcement: `false` (informational only)'
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload bounded dogfood evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: fable5-dogfood-evidence
path: ${{ runner.temp }}/fable5-dogfood-evidence
if-no-files-found: error