-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-test-shards.sh
More file actions
263 lines (252 loc) · 27.8 KB
/
Copy pathtest-test-shards.sh
File metadata and controls
263 lines (252 loc) · 27.8 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
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
WORKFLOW="${ROOT}/.github/workflows/ci.yml"
tmp="$(mktemp -d)"
trap 'rm -rf "${tmp}"' EXIT
cat > "${tmp}/inventory.json" <<'JSON'
{"schema":"homeboy/test-inventory/v1","runner":"fixture","runner_fingerprint":"runner-a","workspace_fingerprint":"workspace-a","inventory_fingerprint":"inventory-a","tests":[{"id":"slow","duration_ms":900},{"id":"medium","duration_ms":500},{"id":"unknown"},{"id":"fast","duration_ms":100}]}
JSON
mkdir -p "${tmp}/bin"
cat > "${tmp}/bin/homeboy" <<'SH'
#!/usr/bin/env bash
set -euo pipefail
if [ "${HOMEBOY_TEST_INVENTORY_ONLY:-}" = 1 ]; then
cp "${FIXTURE_INVENTORY}" "${HOMEBOY_TEST_INVENTORY_FILE}"
exit 0
fi
output=""
printf '%s\n' "$@" > "${FAKE_HOMEBOY_ARGS}"
while [ "$#" -gt 0 ]; do
case "$1" in
--output) output="$2"; shift 2 ;;
*) shift ;;
esac
done
[ -n "${HOMEBOY_TEST_SHARD_MANIFEST:-}" ] && [ -s "${HOMEBOY_TEST_SHARD_MANIFEST}" ] || exit 98
[ "${HOMEBOY_TEST_SHARD_MANIFEST}" = "${FAKE_EXPECTED_SHARD_MANIFEST}" ] || exit 96
total="$(jq '.tests | length' "${HOMEBOY_TEST_SHARD_MANIFEST}")"
[ "${total}" -gt 0 ] || exit 97
mkdir -p "$(dirname "${output}")"
jq -n --argjson total "${total}" '{schema:"homeboy/command-result/v3",command:"review",success:true,status:"succeeded",exit_code:0,data:{test_counts:{passed:$total,failed:0,skipped:0,total:$total}}}' > "${output}"
SH
chmod +x "${tmp}/bin/homeboy"
PATH="${tmp}/bin:${PATH}" FIXTURE_INVENTORY="${tmp}/inventory.json" HOMEBOY_TEST_INVENTORY_ONLY=1 HOMEBOY_TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" homeboy review test fixture
[ -s "${tmp}/captured-inventory.json" ] || { printf 'FAIL: inventory-only Homeboy contract did not materialize an inventory\n'; exit 1; }
for output in one two; do
TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PLAN_FILE="${tmp}/${output}.json" TEST_SHARD_COUNT=2 \
bash "${ROOT}/scripts/core/shard-tests.sh" plan
done
cmp "${tmp}/one.json" "${tmp}/two.json" || { printf 'FAIL: identical inventories must produce byte-identical plans\n'; exit 1; }
jq -e '[.shards[].tests[]] | sort == ["fast","medium","slow","unknown"]' "${tmp}/one.json" >/dev/null || { printf 'FAIL: plan membership is not exact\n'; exit 1; }
if TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PLAN_FILE="${tmp}/too-many.json" TEST_SHARD_COUNT=5 bash "${ROOT}/scripts/core/shard-tests.sh" plan >/dev/null 2>&1; then
printf 'FAIL: empty shard plans must be rejected\n'; exit 1
fi
jq -e 'all(.shards[]; .schema == "homeboy/test-shard-manifest/v1" and (.runner == "fixture") and (.tests | all(type == "string")))' "${tmp}/one.json" >/dev/null || { printf 'FAIL: emitted shard manifests do not match the extension contract\n'; exit 1; }
jq -n '{schema:"homeboy/test-inventory/v1",runner:"fixture",runner_fingerprint:"runner-a",workspace_fingerprint:"workspace-a",inventory_fingerprint:"large-inventory-a",tests:[range(0; 12000) | {id:("test-" + tostring + ("x" * 160)),duration_ms:1}]}' > "${tmp}/large-inventory.json"
[ "$(wc -c < "${tmp}/large-inventory.json")" -gt 1048576 ] || { printf 'FAIL: large inventory must exceed a conservative argv-sized payload\n'; exit 1; }
for output in large-one large-two; do
TEST_INVENTORY_FILE="${tmp}/large-inventory.json" TEST_SHARD_PLAN_FILE="${tmp}/${output}.json" TEST_SHARD_COUNT=2 \
bash "${ROOT}/scripts/core/shard-tests.sh" plan
done
cmp "${tmp}/large-one.json" "${tmp}/large-two.json" || { printf 'FAIL: large inventories must produce byte-identical plans\n'; exit 1; }
jq -e '[.shards[].tests[]] | length == 12000' "${tmp}/large-one.json" >/dev/null || { printf 'FAIL: large plan membership is not exact\n'; exit 1; }
large_plan_digest="$(jq -r .plan_digest "${tmp}/large-one.json")"
large_inventory_digest="$(jq -r .inventory_digest "${tmp}/large-one.json")"
for shard in shard-1 shard-2; do
mkdir -p "${tmp}/large-artifacts/${shard}/candidate/homeboy-ci-results"
jq -cn --arg shard "${shard}" --arg inventory "${large_inventory_digest}" --arg plan "${large_plan_digest}" \
'{phase:"candidate",command:"review test",shard_id:$shard,inventory_digest:$inventory,plan_digest:$plan,run_attempt:2,results:{"review test":"pass"}}' > "${tmp}/large-artifacts/${shard}/candidate/manifest.json"
total="$(jq -r --arg id "${shard}" '.shards[] | select(.id == $id) | .tests | length' "${tmp}/large-one.json")"
jq -n --arg id "${shard}" --argjson total "${total}" --slurpfile plan "${tmp}/large-one.json" '
{schema:"homeboy/command-result/v3",command:"review",success:true,status:"succeeded",exit_code:0,
data:{test_counts:{passed:$total,failed:0,skipped:0,total:$total},test_ids:($plan[0].shards[] | select(.id == $id) | .tests)}}
' > "${tmp}/large-artifacts/${shard}/candidate/homeboy-ci-results/review-test.json"
done
large_payload_bytes=$(( $(wc -c < "${tmp}/large-artifacts/shard-1/candidate/homeboy-ci-results/review-test.json") + $(wc -c < "${tmp}/large-artifacts/shard-2/candidate/homeboy-ci-results/review-test.json") ))
[ "${large_payload_bytes}" -gt 1048576 ] || { printf 'FAIL: aggregate payloads must exceed a conservative argv-sized payload\n'; exit 1; }
for output in large-aggregate-one large-aggregate-two; do
TEST_SHARD_ARTIFACT_ROOT="${tmp}/large-artifacts" TEST_SHARD_PLAN_FILE="${tmp}/large-one.json" TEST_INVENTORY_FILE="${tmp}/large-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/${output}" RUN_ATTEMPT=2 \
bash "${ROOT}/scripts/core/shard-tests.sh" aggregate
done
cmp "${tmp}/large-aggregate-one/review-test.json" "${tmp}/large-aggregate-two/review-test.json" || { printf 'FAIL: large shard payloads must produce byte-identical aggregates\n'; exit 1; }
jq -e '.data.test_counts.total == 12000 and .data.shard_count == 2' "${tmp}/large-aggregate-one/review-test.json" >/dev/null || { printf 'FAIL: large shard payloads did not aggregate completely\n'; exit 1; }
jq -n '{schema:"homeboy/test-inventory/v1",runner:"fixture",runner_fingerprint:"runner-a",workspace_fingerprint:"workspace-a",inventory_fingerprint:"many-shard-inventory-a",tests:[range(0; 32) | {id:("test-" + tostring),duration_ms:1}]}' > "${tmp}/many-shard-inventory.json"
TEST_INVENTORY_FILE="${tmp}/many-shard-inventory.json" TEST_SHARD_PLAN_FILE="${tmp}/many-shard-plan.json" TEST_SHARD_COUNT=32 bash "${ROOT}/scripts/core/shard-tests.sh" plan
many_plan_digest="$(jq -r .plan_digest "${tmp}/many-shard-plan.json")"
many_inventory_digest="$(jq -r .inventory_digest "${tmp}/many-shard-plan.json")"
while IFS= read -r shard; do
mkdir -p "${tmp}/many-shard-artifacts/${shard}/candidate/homeboy-ci-results"
jq -cn --arg shard "${shard}" --arg inventory "${many_inventory_digest}" --arg plan "${many_plan_digest}" \
'{phase:"candidate",command:"review test",shard_id:$shard,inventory_digest:$inventory,plan_digest:$plan,run_attempt:2,results:{"review test":"pass"}}' > "${tmp}/many-shard-artifacts/${shard}/candidate/manifest.json"
jq -n '{schema:"homeboy/command-result/v3",command:"review",success:true,status:"succeeded",exit_code:0,data:{test_counts:{passed:1,failed:0,skipped:0,total:1}}}' > "${tmp}/many-shard-artifacts/${shard}/candidate/homeboy-ci-results/review-test.json"
done < <(jq -r '.shards[].id' "${tmp}/many-shard-plan.json")
real_jq="$(command -v jq)"
cat > "${tmp}/bin/jq" <<'SH'
#!/usr/bin/env bash
printf '%s\n' "$#" >> "${JQ_ARGC_LOG}"
exec "${REAL_JQ}" "$@"
SH
chmod +x "${tmp}/bin/jq"
PATH="${tmp}/bin:${PATH}" REAL_JQ="${real_jq}" JQ_ARGC_LOG="${tmp}/jq-argc.log" TEST_SHARD_ARTIFACT_ROOT="${tmp}/many-shard-artifacts" TEST_SHARD_PLAN_FILE="${tmp}/many-shard-plan.json" TEST_INVENTORY_FILE="${tmp}/many-shard-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/many-shard-output" RUN_ATTEMPT=2 \
bash "${ROOT}/scripts/core/shard-tests.sh" aggregate
max_jq_argc=0
while IFS= read -r jq_argc; do
if [ "${jq_argc}" -gt "${max_jq_argc}" ]; then max_jq_argc="${jq_argc}"; fi
done < "${tmp}/jq-argc.log"
[ "${max_jq_argc}" -lt 32 ] || { printf 'FAIL: aggregate jq argv contains one pathname per shard\n'; exit 1; }
rm "${tmp}/bin/jq"
jq -e '.data.test_counts.total == 32 and .data.shard_count == 32' "${tmp}/many-shard-output/review-test.json" >/dev/null || { printf 'FAIL: many-shard aggregate did not preserve complete evidence\n'; exit 1; }
jq '.workspace_fingerprint = "workspace-base"' "${tmp}/captured-inventory.json" > "${tmp}/base-inventory.json"
TEST_INVENTORY_FILE="${tmp}/base-inventory.json" TEST_SHARD_PLAN_FILE="${tmp}/base-plan.json" TEST_SHARD_COUNT=2 bash "${ROOT}/scripts/core/shard-tests.sh" plan
[ "$(jq -r .plan_digest "${tmp}/one.json")" != "$(jq -r .plan_digest "${tmp}/base-plan.json")" ] || { printf 'FAIL: candidate and baseline inventories must produce distinct plans\n'; exit 1; }
printf 'PASS: deterministic duration-balanced plan has exact membership\n'
plan_digest="$(jq -r .plan_digest "${tmp}/one.json")"
inventory_digest="$(jq -r .inventory_digest "${tmp}/one.json")"
shard_manifest="${tmp}/shard-1.json"
jq --arg id shard-1 '.shards[] | select(.id == $id)' "${tmp}/one.json" > "${shard_manifest}"
mkdir -p "${tmp}/replay-workspace"
PATH="${tmp}/bin:${PATH}" GITHUB_ACTION_PATH="${ROOT}" GITHUB_WORKSPACE="${tmp}/replay-workspace" GITHUB_OUTPUT="${tmp}/replay-output" GITHUB_ENV="${tmp}/replay-env" RESOLVED_COMMANDS='review test' COMPONENT_NAME=fixture HOMEBOY_TEST_SHARD_MANIFEST="${shard_manifest}" FAKE_EXPECTED_SHARD_MANIFEST="${shard_manifest}" FAKE_HOMEBOY_ARGS="${tmp}/replay-args" \
bash "${ROOT}/scripts/core/run-homeboy-commands.sh"
replay_result="${tmp}/replay-workspace/homeboy-ci-results/review-test.json"
replay_total="$(jq '.data.test_counts.total' "${replay_result}")"
[ "${replay_total}" -gt 0 ] || { printf 'FAIL: non-empty shard manifest replay did not execute tests\n'; exit 1; }
[ "${replay_total}" = "$(jq '.tests | length' "${shard_manifest}")" ] || { printf 'FAIL: replay total does not match assigned shard membership\n'; exit 1; }
if grep -Fx -- "$(jq -r '.tests[0]' "${shard_manifest}")" "${tmp}/replay-args" >/dev/null; then
printf 'FAIL: action expanded an assigned test ID into the Homeboy command argv\n'; exit 1
fi
printf 'PASS: non-empty shard manifest is passed by path and replays assigned tests through the action command wrapper\n'
for phase in candidate baseline; do
for shard in shard-1 shard-2; do
mkdir -p "${tmp}/artifacts/${phase}-${shard}/${phase}/homeboy-ci-results"
jq -cn --arg phase "${phase}" --arg command 'review test' --arg shard "${shard}" --arg inventory "${inventory_digest}" --arg plan "${plan_digest}" \
'{phase:$phase,command:$command,shard_id:$shard,inventory_digest:$inventory,plan_digest:$plan,run_attempt:2,results:{"review test":"pass"}}' > "${tmp}/artifacts/${phase}-${shard}/${phase}/manifest.json"
total="$(jq -r --arg id "${shard}" '.shards[] | select(.id == $id) | .tests | length' "${tmp}/one.json")"
jq -cn --argjson total "${total}" '{schema:"homeboy/command-result/v3",command:"review",success:true,status:"succeeded",exit_code:0,data:{test_counts:{passed:$total,failed:0,skipped:0,total:$total}}}' > "${tmp}/artifacts/${phase}-${shard}/${phase}/homeboy-ci-results/review-test.json"
done
TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE="${phase}" TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/${phase}-output" RUN_ATTEMPT=2 \
bash "${ROOT}/scripts/core/shard-tests.sh" aggregate
done
cp "${replay_result}" "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/candidate-replay-output" RUN_ATTEMPT=2 \
bash "${ROOT}/scripts/core/shard-tests.sh" aggregate
jq -e '.data.test_counts.total == 4' "${tmp}/candidate-replay-output/review-test.json" >/dev/null || { printf 'FAIL: aggregate did not include replayed shard evidence\n'; exit 1; }
jq -e '.data.shard_plan_digest == $digest' --arg digest "${plan_digest}" "${tmp}/candidate-replay-output/review-test.json" >/dev/null || { printf 'FAIL: aggregation did not preserve immutable plan identity\n'; exit 1; }
jq -e '."review test" == "pass"' "${tmp}/candidate-output/results.json" >/dev/null
jq -e '.data.test_counts.total == 4' "${tmp}/candidate-output/review-test.json" >/dev/null || { printf 'FAIL: aggregation did not sum actual structured shard counts\n'; exit 1; }
cp "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json" "${tmp}/passing-shard.json"
jq '.data.test_counts.failed = 1 | .data.test_counts.passed -= 1' "${tmp}/passing-shard.json" > "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
mkdir "${tmp}/payload-stream-tmp"
if TMPDIR="${tmp}/payload-stream-tmp" TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/false-pass-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate >/dev/null 2>&1; then
printf 'FAIL: passing shard evidence with failed counts must fail closed\n'; exit 1
fi
rmdir "${tmp}/payload-stream-tmp" || { printf 'FAIL: aggregate leaked a payload stream after validation failure\n'; exit 1; }
cp "${tmp}/passing-shard.json" "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
cp "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json" "${tmp}/valid-passing-shard.json"
jq '.status = "failed"' "${tmp}/valid-passing-shard.json" > "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
if TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/incoherent-status-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate >/dev/null 2>&1; then
printf 'FAIL: passing shard evidence with failed status must fail closed\n'; exit 1
fi
jq '.data.test_counts.passed = 0.5 | .data.test_counts.total = 0.5' "${tmp}/valid-passing-shard.json" > "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
if TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/fractional-count-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate >/dev/null 2>&1; then
printf 'FAIL: fractional structured counts must fail closed\n'; exit 1
fi
cp "${tmp}/valid-passing-shard.json" "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
total="$(jq -r '.data.test_counts.total' "${tmp}/passing-shard.json")"
jq --argjson total "$((total - 1))" '.data.test_counts.passed = $total | .data.test_counts.total = $total' "${tmp}/passing-shard.json" > "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
if TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/incomplete-pass-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate >/dev/null 2>&1; then
printf 'FAIL: passing shard evidence with incomplete planned membership must fail closed\n'; exit 1
fi
cp "${tmp}/passing-shard.json" "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
for phase in candidate baseline; do
jq '.results["review test"] = "fail"' "${tmp}/artifacts/${phase}-shard-1/${phase}/manifest.json" > "${tmp}/bad.json"
mv "${tmp}/bad.json" "${tmp}/artifacts/${phase}-shard-1/${phase}/manifest.json"
jq '.success = false | .status = "failed" | .exit_code = 1 | .data.test_counts.failed = 1 | .data.test_counts.passed -= 1' "${tmp}/artifacts/${phase}-shard-1/${phase}/homeboy-ci-results/review-test.json" > "${tmp}/bad.json"
mv "${tmp}/bad.json" "${tmp}/artifacts/${phase}-shard-1/${phase}/homeboy-ci-results/review-test.json"
TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE="${phase}" TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/${phase}-failed-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate
jq -e '."review test" == "fail"' "${tmp}/${phase}-failed-output/results.json" >/dev/null || { printf 'FAIL: failed shard did not retain a failure result\n'; exit 1; }
done
printf 'PASS: complete provenance-bound shard sets aggregate into Test\n'
jq '.results["review test"] = "fail"' "${tmp}/artifacts/candidate-shard-1/candidate/manifest.json" > "${tmp}/bad.json"
mv "${tmp}/bad.json" "${tmp}/artifacts/candidate-shard-1/candidate/manifest.json"
jq '{schema,command,success:false,status:"failed",exit_code:1,data:{test_counts:{passed:0,failed:0,skipped:0,total:0}}}' "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json" > "${tmp}/bad.json"
mv "${tmp}/bad.json" "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/zero-count-failed-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate
jq -e '."review test" == "fail"' "${tmp}/zero-count-failed-output/results.json" >/dev/null || { printf 'FAIL: failed zero-count shard did not retain a failure result\n'; exit 1; }
jq -e '.schema == "homeboy/command-result/v3" and .success == false and .status == "failed" and .exit_code == 1 and (.data.test_counts.passed + .data.test_counts.failed + .data.test_counts.skipped == .data.test_counts.total)' "${tmp}/zero-count-failed-output/review-test.json" >/dev/null || { printf 'FAIL: failed zero-count shard did not emit an aggregate failed v3 result\n'; exit 1; }
cp "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json" "${tmp}/valid-failed-shard.json"
jq '.exit_code = 0' "${tmp}/valid-failed-shard.json" > "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
if TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/incoherent-exit-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate >/dev/null 2>&1; then
printf 'FAIL: failed shard evidence with zero exit code must fail closed\n'; exit 1
fi
cp "${tmp}/valid-failed-shard.json" "${tmp}/artifacts/candidate-shard-1/candidate/homeboy-ci-results/review-test.json"
printf 'PASS: failed zero-count v3 shard aggregates without obsolete errors counts\n'
jq '.results["review test"] = "timeout"' "${tmp}/artifacts/candidate-shard-2/candidate/manifest.json" > "${tmp}/bad.json"
mv "${tmp}/bad.json" "${tmp}/artifacts/candidate-shard-2/candidate/manifest.json"
rm "${tmp}/artifacts/candidate-shard-2/candidate/homeboy-ci-results/review-test.json"
TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/timeout-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate
jq -e '."review test" == "timeout"' "${tmp}/timeout-output/results.json" >/dev/null || { printf 'FAIL: timeout without payload must not pass\n'; exit 1; }
jq -n '{schema:"homeboy/command-result/v3",command:"review",success:false,status:"failed",exit_code:124,summary:"test phase timed out before reporting test counts",data:{failure:{category:"infrastructure",phase:"test"}}}' > "${tmp}/artifacts/candidate-shard-2/candidate/homeboy-ci-results/review-test.json"
TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=candidate TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/structured-timeout-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate
jq -e '.schema == "homeboy/command-result/v3" and .success == false and .status == "failed" and .exit_code == 124 and .data.test_counts == {passed:0,failed:0,skipped:0,total:0}' "${tmp}/structured-timeout-output/review-test.json" >/dev/null || { printf 'FAIL: structured timeout without completed counts did not aggregate deterministically\n'; exit 1; }
jq -e '."review test" == "timeout"' "${tmp}/structured-timeout-output/results.json" >/dev/null || { printf 'FAIL: structured timeout did not retain its timeout result\n'; exit 1; }
jq '.data.test_counts.total = 999' "${tmp}/artifacts/baseline-shard-2/baseline/homeboy-ci-results/review-test.json" > "${tmp}/bad.json"
mv "${tmp}/bad.json" "${tmp}/artifacts/baseline-shard-2/baseline/homeboy-ci-results/review-test.json"
if TEST_SHARD_ARTIFACT_ROOT="${tmp}/artifacts" TEST_SHARD_PLAN_FILE="${tmp}/one.json" TEST_INVENTORY_FILE="${tmp}/captured-inventory.json" TEST_SHARD_PHASE=baseline TEST_SHARD_COMMAND='review test' TEST_SHARD_OUTPUT_DIR="${tmp}/bad-output" RUN_ATTEMPT=2 bash "${ROOT}/scripts/core/shard-tests.sh" aggregate >/dev/null 2>&1; then
printf 'FAIL: false structured counts must fail closed\n'; exit 1
fi
printf 'PASS: missing, mismatched, failed, and timed-out shards fail closed\n'
grep -F 'needs: [reconcile, reconcile-test-shards, plan]' "${WORKFLOW}" >/dev/null || { printf 'FAIL: policy does not wait for the sharded Test verdict and pinned plan\n'; exit 1; }
grep -F "inputs.test-shards == '1' || needs.reconcile-test-shards.result == 'success'" "${WORKFLOW}" >/dev/null || { printf 'FAIL: policy can bypass a failed sharded Test verdict\n'; exit 1; }
if [ "$(grep -c 'uses: taiki-e/install-action@nextest' "${WORKFLOW}")" -ne 4 ]; then
printf 'FAIL: Rust candidate and baseline plan/replay jobs do not all install cargo-nextest\n'; exit 1
fi
if [ "$(grep -c "continue-on-error: true" "${WORKFLOW}")" -lt 6 ]; then
printf 'FAIL: inventory planning transport is not isolated from normal Test verdict enforcement\n'; exit 1
fi
if [ "$(grep -c "HOMEBOY_RUST_NEXTEST_FALLBACK: '0'" "${WORKFLOW}")" -ne 4 ] || [ "$(grep -c 'NEXTEST_PROFILE: ci' "${WORKFLOW}")" -ne 4 ]; then
printf 'FAIL: Rust shard jobs do not require nextest with the CI profile\n'; exit 1
fi
if [ "$(grep -c 'HOMEBOY_RUST_TEST_RUNNER: nextest' "${WORKFLOW}")" -ne 4 ]; then
printf 'FAIL: Rust shard jobs do not explicitly select nextest\n'; exit 1
fi
if [ "$(grep -c 'prepare-test-shard-workspace.sh' "${WORKFLOW}")" -ne 10 ]; then
printf 'FAIL: candidate binary and Test shard jobs do not reserve and restore action-owned paths symmetrically\n'; exit 1
fi
if [ "$(grep -c 'Refusing to overwrite consumer path reserved for the Homeboy Action checkout' "${WORKFLOW}")" -ne 4 ]; then
printf 'FAIL: candidate and baseline Test shard jobs do not reject action checkout collisions symmetrically\n'; exit 1
fi
# The literal workflow expression is the contract.
# shellcheck disable=SC2016
grep -F 'baseline_result="$(jq -r --arg command "${COMMAND}"' "${WORKFLOW}" >/dev/null || { printf 'FAIL: differential baseline metadata is not derived from its aggregate result\n'; exit 1; }
# shellcheck disable=SC2016
grep -F 'result_filename="$(command_result_filename "${COMMAND}")"' "${WORKFLOW}" >/dev/null || { printf 'FAIL: differential baseline lookup does not use the canonical result filename\n'; exit 1; }
# shellcheck disable=SC2016
grep -F '[ -f "homeboy-baseline-results/${result_filename}" ] && structured_output=true' "${WORKFLOW}" >/dev/null || { printf 'FAIL: differential baseline lookup does not fail closed when its declared result is absent\n'; exit 1; }
candidate_inventory="$(sed -n '/name: Configure candidate Test shards/,/name: Plan candidate Test shards/p' "${WORKFLOW}")"
baseline_inventory="$(sed -n '/name: Configure baseline Test shards/,/name: Plan baseline Test shards/p' "${WORKFLOW}")"
printf '%s\n' "${candidate_inventory}" | grep -F 'scope: ${{ inputs.scope }}' >/dev/null || { printf 'FAIL: candidate Test inventory does not forward caller scope\n'; exit 1; }
printf '%s\n' "${baseline_inventory}" | grep -F 'scope: full' >/dev/null || { printf 'FAIL: immutable baseline Test inventory is not full scope\n'; exit 1; }
if [ "$(grep -c 'scope: full' "${WORKFLOW}")" -lt 3 ]; then
printf 'FAIL: immutable baseline inventory and shard replays do not use full scope\n'; exit 1
fi
grep -F 'prepare-test-shard-workspace.sh prepare .homeboy-action' "${WORKFLOW}" >/dev/null || { printf 'FAIL: candidate binary setup does not isolate the action checkout\n'; exit 1; }
grep -F "steps.prepare-binary-workspace.outcome == 'success'" "${WORKFLOW}" >/dev/null || { printf 'FAIL: candidate binary setup does not always restore its exact Git exclusions\n'; exit 1; }
grep -F 'name: Write candidate Test inventory failure provenance' "${WORKFLOW}" >/dev/null || { printf 'FAIL: candidate inventory failures do not preserve provenance\n'; exit 1; }
# shellcheck disable=SC2016
grep -F 'name: homeboy-test-inventory-failure-${{ github.run_attempt }}' "${WORKFLOW}" >/dev/null || { printf 'FAIL: candidate inventory failure provenance is not artifact-scoped\n'; exit 1; }
grep -F "needs.candidate-test-plan.result == 'success'" "${WORKFLOW}" >/dev/null || { printf 'FAIL: candidate shard work can start without a successful inventory plan\n'; exit 1; }
grep -F 'name: Report candidate Test inventory generation failure' "${WORKFLOW}" >/dev/null || { printf 'FAIL: Test does not report candidate inventory generation failures\n'; exit 1; }
grep -F "if: needs.candidate-test-plan.result == 'success'" "${WORKFLOW}" >/dev/null || { printf 'FAIL: Test artifact downloads are not gated on a successful candidate plan\n'; exit 1; }
grep -F "Candidate Test inventory generation failed; shard execution was not started" "${WORKFLOW}" >/dev/null || { printf 'FAIL: candidate inventory producer is not terminal\n'; exit 1; }
grep -F "::error::Test inventory generation failed for" "${WORKFLOW}" >/dev/null || { printf 'FAIL: Test does not emit the inventory generation diagnostic\n'; exit 1; }
if grep -A4 'name: Report candidate Test inventory generation failure' "${WORKFLOW}" | grep -F 'homeboy-test-shard-plan-' >/dev/null; then
printf 'FAIL: inventory failure reporting attempts to read a missing shard plan artifact\n'; exit 1
fi
grep -F 'bootstrap-baseline-red: ${{ steps.bootstrap-baseline-red.outputs.value }}' "${WORKFLOW}" >/dev/null || { printf 'FAIL: baseline inventory failures are not classified for reconciliation\n'; exit 1; }
grep -F 'name: homeboy-baseline-test-inventory-failure-${{ github.run_attempt }}' "${WORKFLOW}" >/dev/null || { printf 'FAIL: classified baseline inventory failures are not retained as artifacts\n'; exit 1; }
grep -F 'Test bootstrap_baseline_red: immutable baseline inventory failed' "${WORKFLOW}" >/dev/null || { printf 'FAIL: Test does not publish the baseline bootstrap warning\n'; exit 1; }
grep -F "needs.baseline-test-plan.outputs.bootstrap-baseline-red == 'true'" "${WORKFLOW}" >/dev/null || { printf 'FAIL: Test does not restrict the nonblocking path to classified baseline inventory failures\n'; exit 1; }
grep -F 'name: Enforce candidate Test result after bootstrap baseline red' "${WORKFLOW}" >/dev/null || { printf 'FAIL: bootstrap baseline warning can bypass candidate Test enforcement\n'; exit 1; }
grep -F "needs.baseline-test-plan.result == 'success'" "${WORKFLOW}" >/dev/null || { printf 'FAIL: baseline shards can run without a successful baseline inventory plan\n'; exit 1; }
printf 'PASS: policy waits for sharded Test reconciliation while preserving unsharded behavior\n'