|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +expected_head="${1:?expected head is required}" |
| 5 | +expected_base="${2:?expected merge base is required}" |
| 6 | +output_dir="${AUTOMERGE_QUOTA_PROOF_OUTPUT:-.artifacts/fix-automerge-quota-fixture}" |
| 7 | + |
| 8 | +actual_head="$(git rev-parse HEAD)" |
| 9 | +head_tree="$(git rev-parse "${actual_head}^{tree}")" |
| 10 | +merge_base="$(git merge-base HEAD origin/main)" |
| 11 | + |
| 12 | +test "$actual_head" = "$expected_head" |
| 13 | +test "$merge_base" = "$expected_base" |
| 14 | +git cat-file -e "${actual_head}^{commit}" |
| 15 | +git cat-file -e "${head_tree}^{tree}" |
| 16 | +git cat-file -e "${merge_base}^{commit}" |
| 17 | + |
| 18 | +echo CRABBOX_PHASE:install |
| 19 | +corepack prepare [email protected] --activate |
| 20 | +pnpm install --frozen-lockfile |
| 21 | + |
| 22 | +echo CRABBOX_PHASE:build |
| 23 | +pnpm run build:node |
| 24 | + |
| 25 | +echo CRABBOX_PHASE:quota_fixture |
| 26 | +mkdir -p "$output_dir" |
| 27 | +node scripts/e2e/automerge.mjs \ |
| 28 | + --scenario github-api-quota-fail-fast \ |
| 29 | + --fixture tiny \ |
| 30 | + --output "$output_dir/automerge" |
| 31 | + |
| 32 | +summary="$output_dir/automerge/tiny/github-api-quota-fail-fast/summary.json" |
| 33 | +jq -e ' |
| 34 | + .status == "passed" and |
| 35 | + .fixture == "tiny" and |
| 36 | + .scenario == "github-api-quota-fail-fast" and |
| 37 | + .container == true and |
| 38 | + .transport == "actual gh HTTP over an owned Unix socket" and |
| 39 | + [.results[].http_status] == [403, 429] and |
| 40 | + (.results | all( |
| 41 | + .requests == 1 and |
| 42 | + .request.method == "GET" and |
| 43 | + (.request.path | endswith("/repos/openclaw/openclaw/issues/42")) and |
| 44 | + .request.authenticated == true and |
| 45 | + .publisher_exit == 1 and |
| 46 | + .completion_kind == "retryable_failure" and |
| 47 | + .failure_kind == "github_rate_limit" and |
| 48 | + .batch_kind == "retryable_failure" and |
| 49 | + .cleanup_deletes == 0 |
| 50 | + )) |
| 51 | +' "$summary" >/dev/null |
| 52 | + |
| 53 | +echo CRABBOX_PHASE:full_gate |
| 54 | +pnpm run check |
| 55 | + |
| 56 | +echo CRABBOX_PHASE:receipt |
| 57 | +jq -n \ |
| 58 | + --arg head_sha "$actual_head" \ |
| 59 | + --arg head_tree "$head_tree" \ |
| 60 | + --arg base_sha "$merge_base" \ |
| 61 | + --arg node_version "$(node --version)" \ |
| 62 | + --arg pnpm_version "$(pnpm --version)" \ |
| 63 | + --slurpfile result "$summary" \ |
| 64 | + '{ |
| 65 | + schema_version: 1, |
| 66 | + tested_head_sha: $head_sha, |
| 67 | + tested_head_tree: $head_tree, |
| 68 | + base_sha: $base_sha, |
| 69 | + cat_file_cross_check: { |
| 70 | + head_commit: true, |
| 71 | + head_tree: true, |
| 72 | + base_commit: true |
| 73 | + }, |
| 74 | + runtime: { |
| 75 | + node: $node_version, |
| 76 | + pnpm: $pnpm_version, |
| 77 | + transport: $result[0].transport |
| 78 | + }, |
| 79 | + quota_fixture: { |
| 80 | + statuses: [$result[0].results[].http_status], |
| 81 | + requests: [$result[0].results[].requests], |
| 82 | + publisher_exits: [$result[0].results[].publisher_exit], |
| 83 | + completion_kinds: [$result[0].results[].completion_kind], |
| 84 | + failure_kinds: [$result[0].results[].failure_kind], |
| 85 | + batch_kinds: [$result[0].results[].batch_kind], |
| 86 | + cleanup_deletes: [$result[0].results[].cleanup_deletes] |
| 87 | + }, |
| 88 | + full_gate: { |
| 89 | + command: "pnpm run check", |
| 90 | + exit_code: 0 |
| 91 | + }, |
| 92 | + limits: [ |
| 93 | + "The GitHub API was a deterministic Unix-socket loopback fixture with synthetic credentials.", |
| 94 | + "No production GitHub, Worker, queue, deployment, or workflow state was mutated.", |
| 95 | + "The receipt commit adds proof metadata only after the tested runtime tree." |
| 96 | + ] |
| 97 | + }' > "$output_dir/container-receipt.json" |
| 98 | + |
| 99 | +jq -e ' |
| 100 | + .schema_version == 1 and |
| 101 | + (.tested_head_sha | test("^[0-9a-f]{40}$")) and |
| 102 | + (.tested_head_tree | test("^[0-9a-f]{40}$")) and |
| 103 | + (.base_sha | test("^[0-9a-f]{40}$")) and |
| 104 | + .cat_file_cross_check == {head_commit:true, head_tree:true, base_commit:true} and |
| 105 | + .quota_fixture.statuses == [403, 429] and |
| 106 | + .quota_fixture.requests == [1, 1] and |
| 107 | + .quota_fixture.publisher_exits == [1, 1] and |
| 108 | + .quota_fixture.completion_kinds == ["retryable_failure", "retryable_failure"] and |
| 109 | + .quota_fixture.failure_kinds == ["github_rate_limit", "github_rate_limit"] and |
| 110 | + .quota_fixture.batch_kinds == ["retryable_failure", "retryable_failure"] and |
| 111 | + .quota_fixture.cleanup_deletes == [0, 0] and |
| 112 | + .full_gate.exit_code == 0 |
| 113 | +' "$output_dir/container-receipt.json" >/dev/null |
| 114 | + |
| 115 | +cat "$output_dir/container-receipt.json" |
| 116 | +echo "AUTOMERGE_QUOTA_FIXTURE_PROOF_OK head=$actual_head base=$merge_base" |
0 commit comments