From 0fac5b115cd6651d1796b1e31bad40e1b5a5eded Mon Sep 17 00:00:00 2001 From: CLAUDE <355856132+HoTT-stuff@users.noreply.github.com> Date: Sun, 22 Nov 2026 17:31:14 +0000 Subject: [PATCH] Add squabbler training corpus v4 Adds a first training corpus under corpus/: 15 structured cases of CI failures, a JSON schema, an offline checker and fire/silence tests. Only verbatim log text is quoted. Python files are a flagged stopgap; a follow-up will rewrite them in shell or Rust. --- corpus/README.adoc | 45 ++++++++++++++++ corpus/cases/SQ-CASE-0001.json | 43 +++++++++++++++ corpus/cases/SQ-CASE-0002.json | 42 +++++++++++++++ corpus/cases/SQ-CASE-0003.json | 43 +++++++++++++++ corpus/cases/SQ-CASE-0004.json | 41 +++++++++++++++ corpus/cases/SQ-CASE-0005.json | 44 ++++++++++++++++ corpus/cases/SQ-CASE-0006.json | 44 ++++++++++++++++ corpus/cases/SQ-CASE-0007.json | 39 ++++++++++++++ corpus/cases/SQ-CASE-0008.json | 39 ++++++++++++++ corpus/cases/SQ-CASE-0009.json | 39 ++++++++++++++ corpus/cases/SQ-CASE-0010.json | 44 ++++++++++++++++ corpus/cases/SQ-CASE-0011.json | 41 +++++++++++++++ corpus/cases/SQ-CASE-0012.json | 45 ++++++++++++++++ corpus/cases/SQ-CASE-0013.json | 43 +++++++++++++++ corpus/cases/SQ-CASE-0014.json | 41 +++++++++++++++ corpus/cases/SQ-CASE-0015.json | 44 ++++++++++++++++ corpus/schema/case.schema.json | 57 ++++++++++++++++++++ corpus/tests/run-tests.py | 70 +++++++++++++++++++++++++ corpus/validate.py | 95 ++++++++++++++++++++++++++++++++++ 19 files changed, 899 insertions(+) create mode 100644 corpus/README.adoc create mode 100644 corpus/cases/SQ-CASE-0001.json create mode 100644 corpus/cases/SQ-CASE-0002.json create mode 100644 corpus/cases/SQ-CASE-0003.json create mode 100644 corpus/cases/SQ-CASE-0004.json create mode 100644 corpus/cases/SQ-CASE-0005.json create mode 100644 corpus/cases/SQ-CASE-0006.json create mode 100644 corpus/cases/SQ-CASE-0007.json create mode 100644 corpus/cases/SQ-CASE-0008.json create mode 100644 corpus/cases/SQ-CASE-0009.json create mode 100644 corpus/cases/SQ-CASE-0010.json create mode 100644 corpus/cases/SQ-CASE-0011.json create mode 100644 corpus/cases/SQ-CASE-0012.json create mode 100644 corpus/cases/SQ-CASE-0013.json create mode 100644 corpus/cases/SQ-CASE-0014.json create mode 100644 corpus/cases/SQ-CASE-0015.json create mode 100644 corpus/schema/case.schema.json create mode 100644 corpus/tests/run-tests.py create mode 100644 corpus/validate.py diff --git a/corpus/README.adoc b/corpus/README.adoc new file mode 100644 index 0000000..4ff9e94 --- /dev/null +++ b/corpus/README.adoc @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) += Squabbler training corpus (draft) + +One JSON file per observed CI failure, under `cases/`. Each is a structured case: +what failed, how it was classified, whether the default branch has the same failure, +what fix is proposed, who owns it, and how to retry. + +== Files + +* `schema/case.schema.json`: the case shape. +* `cases/SQ-CASE-NNNN.json`: the cases (this patch adds 15). +* `validate.py`: offline checker (standard library only). Silent means the case is valid and scrubbed. +* `tests/run-tests.py`: fire and silence tests for the validator, offline. + +== Rules the validator enforces + +[cols="1,4"] +|=== +| Code | Meaning +| V001 | Top-level fields differ from the schema. +| V002 | A field has the wrong type or an unknown enum value. +| V003 | File name differs from the case id. +| V004 | `log_excerpt` is longer than 30 lines. +| V005 | Possible secret or token. +| V006 | Email address. +| V007 | Internal hostname or private address. +| V009 | Confidence `proven` without a verbatim error string. +| V010 | A fix with an owner does not require the owner's go. +| V011 | `observed_at` is not UTC `YYYY-MM-DDThh:mm:ssZ` or null. +| V012 | An error string is not in the log excerpt. +|=== + +== Honesty conventions + +* `error_strings` hold only text that was read verbatim. Where it was not retained the list is empty and confidence is `likely` or `hypothesis`, never `proven`. +* `null` means not known or not retained, never a guess. +* A case with confidence `hypothesis` states a cause that the log does not show. + +== Run + +---- +python3 -I tests/run-tests.py +python3 -I validate.py cases/*.json +---- diff --git a/corpus/cases/SQ-CASE-0001.json b/corpus/cases/SQ-CASE-0001.json new file mode 100644 index 0000000..1e9b394 --- /dev/null +++ b/corpus/cases/SQ-CASE-0001.json @@ -0,0 +1,43 @@ +{ + "attempt": null, + "classification": { + "confidence": "proven", + "group": "rate-limit" + }, + "evidence": { + "error_strings": [ + "NO VERDICT WAS PRODUCED" + ], + "exit_code": null, + "log_excerpt": null + }, + "fix": { + "description": "Shared installation API budget is exhausted; no single-workflow fix. Cut API calls per push (skip statuses already posted, narrow the workflow_run trigger, add per-SHA concurrency), retry with backoff honouring Retry-After, then re-run once after the window.", + "files": [ + ".github/workflows/ci-gate.yml" + ], + "owner": "ci-gate-owner", + "requires_owner_go": true, + "risk": "medium" + }, + "id": "SQ-CASE-0001", + "job": "gate-pr / CI gate", + "main_comparison": { + "note": "Commit status CI/gate on the same head was re-evaluated to success at 13:15Z; the 12:00Z check-run stayed red.", + "state": "unknown" + }, + "observed_at": "2026-11-20T11:59:46Z", + "pr": 469, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/rsr-template-repo", + "retry_policy": { + "action": "rerun-after-window", + "note": "One re-run after the installation budget has recovered." + }, + "run_id": null, + "schema_version": "1", + "step": null +} diff --git a/corpus/cases/SQ-CASE-0002.json b/corpus/cases/SQ-CASE-0002.json new file mode 100644 index 0000000..c895dbf --- /dev/null +++ b/corpus/cases/SQ-CASE-0002.json @@ -0,0 +1,42 @@ +{ + "attempt": 1, + "classification": { + "confidence": "proven", + "group": "rate-limit" + }, + "evidence": { + "error_strings": [ + "API rate limit exceeded for installation", + "Error: Failed to fetch url https://api.github.com/repos/oven-sh/bun/git/refs/tags. (status code: 403, status text: Forbidden)" + ], + "exit_code": 1, + "log_excerpt": null + }, + "fix": { + "description": "Fetch the Bun release without the GitHub API, or cache it; retry with backoff.", + "files": [], + "owner": "ci-gate-owner", + "requires_owner_go": true, + "risk": "low" + }, + "id": "SQ-CASE-0002", + "job": "Proven 3-outcome test & bench suite", + "main_comparison": { + "note": "This is the main commit bf64192f itself.", + "state": "fails" + }, + "observed_at": "2026-11-19T22:26:35Z", + "pr": null, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/rsr-template-repo", + "retry_policy": { + "action": "rerun-after-window", + "note": "Re-run after the window; the failure is not content-related." + }, + "run_id": 44628578926, + "schema_version": "1", + "step": "Set up Bun" +} diff --git a/corpus/cases/SQ-CASE-0003.json b/corpus/cases/SQ-CASE-0003.json new file mode 100644 index 0000000..c6571c6 --- /dev/null +++ b/corpus/cases/SQ-CASE-0003.json @@ -0,0 +1,43 @@ +{ + "attempt": 1, + "classification": { + "confidence": "hypothesis", + "group": "rate-limit" + }, + "evidence": { + "error_strings": [ + "release not found" + ], + "exit_code": 1, + "log_excerpt": null + }, + "fix": { + "description": "Make install.sh show the real gh error and retry the release lookup once with backoff; confirm whether the 404 comes from the token or from rate limiting.", + "files": [ + ".github/actions/squabble/install.sh" + ], + "owner": "repo-owner", + "requires_owner_go": true, + "risk": "low" + }, + "id": "SQ-CASE-0003", + "job": "Squabble CI chains & required-context gate", + "main_comparison": { + "note": "This is the main commit bf64192f itself. The v0.1.0 release exists, is not a draft and carries the pinned asset, so the lookup error is not a missing release.", + "state": "fails" + }, + "observed_at": "2026-11-19T22:27:11Z", + "pr": null, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/rsr-template-repo", + "retry_policy": { + "action": "rerun-after-window", + "note": "Cause not visible in the log; the failure sits inside a known rate-limit window." + }, + "run_id": 44628578862, + "schema_version": "1", + "step": "Install pinned & SLSA-attested squabble v0.1.0" +} diff --git a/corpus/cases/SQ-CASE-0004.json b/corpus/cases/SQ-CASE-0004.json new file mode 100644 index 0000000..e23d540 --- /dev/null +++ b/corpus/cases/SQ-CASE-0004.json @@ -0,0 +1,41 @@ +{ + "attempt": null, + "classification": { + "confidence": "hypothesis", + "group": "rate-limit" + }, + "evidence": { + "error_strings": [], + "exit_code": 1, + "log_excerpt": null + }, + "fix": { + "description": "Same as the rsr-template-repo squabble install case.", + "files": [ + ".github/actions/squabble/install.sh" + ], + "owner": "repo-owner", + "requires_owner_go": true, + "risk": "low" + }, + "id": "SQ-CASE-0004", + "job": "Squabble CI chains & required-context gate", + "main_comparison": { + "note": "resource-algebra main itself was green.", + "state": "passes" + }, + "observed_at": "2026-11-18T12:29:01Z", + "pr": 54, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/resource-algebra", + "retry_policy": { + "action": "rerun-after-window", + "note": "No rate-limit text in this job; the timing matches a known exhaustion window." + }, + "run_id": null, + "schema_version": "1", + "step": "Install pinned & SLSA-attested squabble v0.1.0" +} diff --git a/corpus/cases/SQ-CASE-0005.json b/corpus/cases/SQ-CASE-0005.json new file mode 100644 index 0000000..3954ac5 --- /dev/null +++ b/corpus/cases/SQ-CASE-0005.json @@ -0,0 +1,44 @@ +{ + "attempt": null, + "classification": { + "confidence": "proven", + "group": "rate-limit" + }, + "evidence": { + "error_strings": [ + "API rate limit exceeded for installation", + "Error: Failed to fetch url https://api.github.com/repos/oven-sh/bun/git/refs/tags. (status code: 403, status text: Forbidden)" + ], + "exit_code": 1, + "log_excerpt": null + }, + "fix": { + "description": "Shared installation API budget is exhausted; no single-workflow fix. Cut API calls per push (skip statuses already posted, narrow the workflow_run trigger, add per-SHA concurrency), retry with backoff honouring Retry-After, then re-run once after the window.", + "files": [ + ".github/workflows/ci-gate.yml" + ], + "owner": "ci-gate-owner", + "requires_owner_go": true, + "risk": "medium" + }, + "id": "SQ-CASE-0005", + "job": "Proven 3-outcome test & bench suite", + "main_comparison": { + "note": "resource-algebra main itself was green.", + "state": "passes" + }, + "observed_at": "2026-11-18T12:29:01Z", + "pr": 54, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/resource-algebra", + "retry_policy": { + "action": "rerun-after-window", + "note": "Re-run after the window." + }, + "run_id": null, + "schema_version": "1", + "step": "Set up Bun" +} diff --git a/corpus/cases/SQ-CASE-0006.json b/corpus/cases/SQ-CASE-0006.json new file mode 100644 index 0000000..bc20dd5 --- /dev/null +++ b/corpus/cases/SQ-CASE-0006.json @@ -0,0 +1,44 @@ +{ + "attempt": null, + "classification": { + "confidence": "likely", + "group": "rate-limit" + }, + "evidence": { + "error_strings": [ + "API rate limit exceeded for installation", + "no resource-algebra_chora.deed at c4e5729 — this repo cannot declare a canon pin" + ], + "exit_code": null, + "log_excerpt": null + }, + "fix": { + "description": "Shared installation API budget is exhausted; no single-workflow fix. Cut API calls per push (skip statuses already posted, narrow the workflow_run trigger, add per-SHA concurrency), retry with backoff honouring Retry-After, then re-run once after the window.", + "files": [ + ".github/workflows/ci-gate.yml" + ], + "owner": "ci-gate-owner", + "requires_owner_go": true, + "risk": "medium" + }, + "id": "SQ-CASE-0006", + "job": "Canon lockstep", + "main_comparison": { + "note": "Canon lockstep passes on resource-algebra main.", + "state": "passes" + }, + "observed_at": "2026-11-18T12:29:01Z", + "pr": 54, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/resource-algebra", + "retry_policy": { + "action": "rerun-after-window", + "note": "The canon message is a consequence of a failed API call earlier in the job." + }, + "run_id": null, + "schema_version": "1", + "step": null +} diff --git a/corpus/cases/SQ-CASE-0007.json b/corpus/cases/SQ-CASE-0007.json new file mode 100644 index 0000000..c40e71c --- /dev/null +++ b/corpus/cases/SQ-CASE-0007.json @@ -0,0 +1,39 @@ +{ + "attempt": null, + "classification": { + "confidence": "likely", + "group": "infra-flake" + }, + "evidence": { + "error_strings": [], + "exit_code": null, + "log_excerpt": null + }, + "fix": { + "description": "Re-run once; the Ubuntu package mirror returned HTTP 503. Consider a retry around apt-get.", + "files": [], + "owner": "none", + "requires_owner_go": false, + "risk": "low" + }, + "id": "SQ-CASE-0007", + "job": "guile-3.0 install", + "main_comparison": { + "note": "main was green over about 35 runs.", + "state": "passes" + }, + "observed_at": null, + "pr": 153, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "log" + }, + "repo": "hyperpolymath/proven-cicd-and-workflows", + "retry_policy": { + "action": "rerun", + "note": "Transient mirror failure." + }, + "run_id": null, + "schema_version": "1", + "step": null +} diff --git a/corpus/cases/SQ-CASE-0008.json b/corpus/cases/SQ-CASE-0008.json new file mode 100644 index 0000000..6d536e4 --- /dev/null +++ b/corpus/cases/SQ-CASE-0008.json @@ -0,0 +1,39 @@ +{ + "attempt": 2, + "classification": { + "confidence": "likely", + "group": "infra-flake" + }, + "evidence": { + "error_strings": [], + "exit_code": null, + "log_excerpt": null + }, + "fix": { + "description": "Re-run once more after the mirror recovers; attempt 2 was already a re-run.", + "files": [], + "owner": "none", + "requires_owner_go": false, + "risk": "low" + }, + "id": "SQ-CASE-0008", + "job": "capnproto/protobuf install", + "main_comparison": { + "note": "Main is red on other jobs; this mirror failure is separate.", + "state": "fails" + }, + "observed_at": null, + "pr": 524, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "log" + }, + "repo": "hyperpolymath/echidna", + "retry_policy": { + "action": "rerun-after-window", + "note": "Ubuntu mirror returned HTTP 503 on two attempts." + }, + "run_id": null, + "schema_version": "1", + "step": null +} diff --git a/corpus/cases/SQ-CASE-0009.json b/corpus/cases/SQ-CASE-0009.json new file mode 100644 index 0000000..fcf5e05 --- /dev/null +++ b/corpus/cases/SQ-CASE-0009.json @@ -0,0 +1,39 @@ +{ + "attempt": null, + "classification": { + "confidence": "likely", + "group": "cancelled-timeout" + }, + "evidence": { + "error_strings": [], + "exit_code": null, + "log_excerpt": null + }, + "fix": { + "description": "Run was cancelled after about 60 minutes during toolchain install; gate-pr then waited 30 minutes on Language Gates Self-Test. Re-run once.", + "files": [], + "owner": "none", + "requires_owner_go": false, + "risk": "low" + }, + "id": "SQ-CASE-0009", + "job": "Language gate (agda/coq/ocaml install)", + "main_comparison": { + "note": "main was green over about 35 runs.", + "state": "passes" + }, + "observed_at": null, + "pr": 138, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "log" + }, + "repo": "hyperpolymath/proven-cicd-and-workflows", + "retry_policy": { + "action": "rerun", + "note": "Cancellation, not a test failure." + }, + "run_id": null, + "schema_version": "1", + "step": null +} diff --git a/corpus/cases/SQ-CASE-0010.json b/corpus/cases/SQ-CASE-0010.json new file mode 100644 index 0000000..b392fce --- /dev/null +++ b/corpus/cases/SQ-CASE-0010.json @@ -0,0 +1,44 @@ +{ + "attempt": null, + "classification": { + "confidence": "likely", + "group": "lock-drift" + }, + "evidence": { + "error_strings": [ + "PASS=27 FAIL=1" + ], + "exit_code": null, + "log_excerpt": null + }, + "fix": { + "description": "main-estate-audit.yml pins recipes-set-check at c519c452, which differs from HEAD; update the pin and the lock together.", + "files": [ + ".github/workflows/main-estate-audit.yml", + "actions.lock" + ], + "owner": "pr-author", + "requires_owner_go": true, + "risk": "low" + }, + "id": "SQ-CASE-0010", + "job": "lock-transitive-closure", + "main_comparison": { + "note": "The branch is 3 commits behind main.", + "state": "passes" + }, + "observed_at": null, + "pr": 140, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "log" + }, + "repo": "hyperpolymath/proven-cicd-and-workflows", + "retry_policy": { + "action": "fix-then-rerun", + "note": "A re-run alone will not clear a pin mismatch." + }, + "run_id": null, + "schema_version": "1", + "step": null +} diff --git a/corpus/cases/SQ-CASE-0011.json b/corpus/cases/SQ-CASE-0011.json new file mode 100644 index 0000000..cbed0e0 --- /dev/null +++ b/corpus/cases/SQ-CASE-0011.json @@ -0,0 +1,41 @@ +{ + "attempt": null, + "classification": { + "confidence": "likely", + "group": "lock-drift" + }, + "evidence": { + "error_strings": [], + "exit_code": null, + "log_excerpt": null + }, + "fix": { + "description": "actions/upload-artifact@v7.0.2 is used by a workflow but missing from actions.lock; regenerate the lock.", + "files": [ + "actions.lock" + ], + "owner": "repo-owner", + "requires_owner_go": true, + "risk": "low" + }, + "id": "SQ-CASE-0011", + "job": "actions.lock in sync", + "main_comparison": { + "note": "Seen on main and on #74 and #76.", + "state": "fails" + }, + "observed_at": null, + "pr": null, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "log" + }, + "repo": "hyperpolymath/scaffoldia", + "retry_policy": { + "action": "fix-then-rerun", + "note": "Lock must change first." + }, + "run_id": null, + "schema_version": "1", + "step": null +} diff --git a/corpus/cases/SQ-CASE-0012.json b/corpus/cases/SQ-CASE-0012.json new file mode 100644 index 0000000..08d8217 --- /dev/null +++ b/corpus/cases/SQ-CASE-0012.json @@ -0,0 +1,45 @@ +{ + "attempt": null, + "classification": { + "confidence": "proven", + "group": "lock-drift" + }, + "evidence": { + "error_strings": [ + "lockfile entry for a workflow file that does not exist", + "actions.lock is OUT OF SYNC with the workflow YAML, or is not transitively closed", + "FAIL: the current lock must be in sync and closed" + ], + "exit_code": 1, + "log_excerpt": null + }, + "fix": { + "description": "actions.lock lists .github/workflows/codeql.yml, which no longer exists; prune or regenerate the lock (gh actions-lock --no-migrate-local-actions).", + "files": [ + "actions.lock" + ], + "owner": "pr-author", + "requires_owner_go": true, + "risk": "low" + }, + "id": "SQ-CASE-0012", + "job": "actions.lock is in sync with the workflow YAML", + "main_comparison": { + "note": "The same stale entry also fails the estate-rules control job.", + "state": "unknown" + }, + "observed_at": "2026-11-18T14:29:07Z", + "pr": 38, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/resource-algebra", + "retry_policy": { + "action": "fix-then-rerun", + "note": "Re-running without a lock change fails again." + }, + "run_id": null, + "schema_version": "1", + "step": "Verify lockfile synchronisation" +} diff --git a/corpus/cases/SQ-CASE-0013.json b/corpus/cases/SQ-CASE-0013.json new file mode 100644 index 0000000..bfce476 --- /dev/null +++ b/corpus/cases/SQ-CASE-0013.json @@ -0,0 +1,43 @@ +{ + "attempt": null, + "classification": { + "confidence": "proven", + "group": "infra-flake" + }, + "evidence": { + "error_strings": [ + "Could not connect", + "E: Package 'ca-certificates' has no installation candidate", + "Unable to locate package curl" + ], + "exit_code": 100, + "log_excerpt": null + }, + "fix": { + "description": "Runner could not reach the Ubuntu mirrors; re-run once the network recovers.", + "files": [], + "owner": "none", + "requires_owner_go": false, + "risk": "low" + }, + "id": "SQ-CASE-0013", + "job": "Lean recheck leg", + "main_comparison": { + "note": "Proofs verdict failed only as a consequence: Proofs verdict: required job did not succeed: lean-leg=failure", + "state": "unknown" + }, + "observed_at": "2026-11-19T12:19:02Z", + "pr": 40, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/resource-algebra", + "retry_policy": { + "action": "rerun", + "note": "Not a proof failure." + }, + "run_id": null, + "schema_version": "1", + "step": "Install the pinned Lean" +} diff --git a/corpus/cases/SQ-CASE-0014.json b/corpus/cases/SQ-CASE-0014.json new file mode 100644 index 0000000..86b3fca --- /dev/null +++ b/corpus/cases/SQ-CASE-0014.json @@ -0,0 +1,41 @@ +{ + "attempt": null, + "classification": { + "confidence": "likely", + "group": "stale-generated-file" + }, + "evidence": { + "error_strings": [], + "exit_code": null, + "log_excerpt": null + }, + "fix": { + "description": "Regenerate the receipt with: bash scripts/grade-receipt.sh --write, and commit it.", + "files": [ + "verification receipt" + ], + "owner": "pr-author", + "requires_owner_go": true, + "risk": "low" + }, + "id": "SQ-CASE-0014", + "job": "verification receipt", + "main_comparison": { + "note": "lintel main does not have this job.", + "state": "absent" + }, + "observed_at": null, + "pr": 28, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "log" + }, + "repo": "hyperpolymath/lintel", + "retry_policy": { + "action": "fix-then-rerun", + "note": "Receipt is stale against the code." + }, + "run_id": null, + "schema_version": "1", + "step": null +} diff --git a/corpus/cases/SQ-CASE-0015.json b/corpus/cases/SQ-CASE-0015.json new file mode 100644 index 0000000..95c903e --- /dev/null +++ b/corpus/cases/SQ-CASE-0015.json @@ -0,0 +1,44 @@ +{ + "attempt": 1, + "classification": { + "confidence": "proven", + "group": "stale-generated-file" + }, + "evidence": { + "error_strings": [ + "index.json is out of sync with scans/.", + "Run 'bash scripts/regen-index.sh' locally and commit the result." + ], + "exit_code": 1, + "log_excerpt": null + }, + "fix": { + "description": "Regenerate index.json on main in one small change. Open question: whether last_updated is wall-clock, which would make the check fail again.", + "files": [ + "index.json" + ], + "owner": "repo-owner", + "requires_owner_go": true, + "risk": "low" + }, + "id": "SQ-CASE-0015", + "job": "index.json matches scans/", + "main_comparison": { + "note": "This is main; open pull requests fail the same way, so it is not caused by them.", + "state": "fails" + }, + "observed_at": "2026-11-19T15:18:24Z", + "pr": null, + "provenance": { + "note": "Read-only inspection of public CI logs and check data; no run was re-run.", + "read_by": "api" + }, + "repo": "hyperpolymath/verisimdb-data", + "retry_policy": { + "action": "fix-then-rerun", + "note": "A re-run fails identically." + }, + "run_id": 44553279791, + "schema_version": "1", + "step": "Fail if index.json drifted" +} diff --git a/corpus/schema/case.schema.json b/corpus/schema/case.schema.json new file mode 100644 index 0000000..e017459 --- /dev/null +++ b/corpus/schema/case.schema.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Squabbler corpus case", + "description": "One observed CI failure and its classification. validate.py enforces this plus the scrub rules.", + "type": "object", + "additionalProperties": false, + "required": ["id","schema_version","repo","pr","run_id","job","step","attempt","observed_at","evidence","classification","main_comparison","fix","retry_policy","provenance"], + "properties": { + "id": {"type": "string", "pattern": "^SQ-CASE-[0-9]{4}$"}, + "schema_version": {"const": "1"}, + "repo": {"type": "string", "pattern": "^[\\w.-]+/[\\w.-]+$"}, + "pr": {"type": ["integer", "null"], "description": "null means the default branch"}, + "run_id": {"type": ["integer", "null"]}, + "job": {"type": "string", "minLength": 1}, + "step": {"type": ["string", "null"]}, + "attempt": {"type": ["integer", "null"]}, + "observed_at": {"type": ["string", "null"], "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"}, + "evidence": { + "type": "object", "additionalProperties": false, + "required": ["log_excerpt", "exit_code", "error_strings"], + "properties": { + "log_excerpt": {"type": ["string", "null"], "description": "Verbatim, at most 30 lines, scrubbed. null when not retained."}, + "exit_code": {"type": ["integer", "null"]}, + "error_strings": {"type": "array", "items": {"type": "string", "minLength": 1}, "description": "Verbatim strings from the log. Empty when none were retained."} + } + }, + "classification": { + "type": "object", "additionalProperties": false, "required": ["group", "confidence"], + "properties": { + "group": {"enum": ["rate-limit","infra-flake","cancelled-timeout","lock-drift","stale-generated-file","real-failure","missing-tool","quality-gate"]}, + "confidence": {"enum": ["proven","likely","hypothesis"], "description": "proven requires at least one verbatim error string"} + } + }, + "main_comparison": { + "type": "object", "additionalProperties": false, "required": ["state", "note"], + "properties": {"state": {"enum": ["passes","fails","absent","unknown"]}, "note": {"type": "string"}} + }, + "fix": { + "type": "object", "additionalProperties": false, "required": ["description","owner","files","risk","requires_owner_go"], + "properties": { + "description": {"type": "string"}, + "owner": {"enum": ["ci-gate-owner","pr-author","repo-owner","estate-owner","none"]}, + "files": {"type": "array", "items": {"type": "string"}}, + "risk": {"enum": ["low","medium","high"]}, + "requires_owner_go": {"type": "boolean"} + } + }, + "retry_policy": { + "type": "object", "additionalProperties": false, "required": ["action", "note"], + "properties": {"action": {"enum": ["none","rerun","rerun-after-window","fix-then-rerun"]}, "note": {"type": "string"}} + }, + "provenance": { + "type": "object", "additionalProperties": false, "required": ["read_by", "note"], + "properties": {"read_by": {"enum": ["log","api"]}, "note": {"type": "string"}} + } + } +} diff --git a/corpus/tests/run-tests.py b/corpus/tests/run-tests.py new file mode 100644 index 0000000..16d0a9a --- /dev/null +++ b/corpus/tests/run-tests.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MPL-2.0 +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) +"""Fire and silence tests for validate.py. Offline. Exit 0 only if every test behaves as expected.""" +import copy, glob, json, os, sys +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.dirname(HERE)) +from validate import check + +BASE = json.load(open(os.path.join(HERE, "..", "cases", "SQ-CASE-0012.json"), encoding="utf-8")) +def mut(fn): + c = copy.deepcopy(BASE); fn(c); return c +def setp(path, value): + def fn(c): + o = c + for k in path[:-1]: o = o[k] + o[path[-1]] = value + return fn + +FIRE = { # rule -> (mutation, must fire exactly this rule) + "V001": lambda c: c.pop("job"), + "V002": setp(["classification","group"], "nonsense"), + "V003": None, # handled below (file name) + "V004": lambda c: c["evidence"].update(log_excerpt="\n".join(["x"]*31), error_strings=["x"]), + "V005": setp(["fix","description"], "use ghp_" + "A"*24 + " to push"), + "V006": setp(["fix","description"], "ask someone@example.org"), + "V007": setp(["fix","description"], "runner build01.internal is slow"), + "V009": lambda c: (c["evidence"].update(error_strings=[]), c["classification"].update(confidence="proven")), + "V010": setp(["fix","requires_owner_go"], False), + "V011": setp(["observed_at"], "20 Nov 2026"), + "V012": lambda c: c["evidence"].update(log_excerpt="unrelated line", error_strings=["not in the excerpt"]), +} +SILENT = { # near-misses that must stay silent + "plain case": lambda c: None, + "hash-like text, no token prefix": setp(["fix","description"], "see commit c519c452 and sha256 6cbeb457"), + "ghp inside a word": setp(["fix","description"], "ghpath is a variable name"), + "private-looking but public host": setp(["fix","description"], "archive.ubuntu.com timed out"), + "version number, not an address": setp(["fix","description"], "upload-artifact v7.0.2 and 10.2 seconds"), + "none owner without owner go": lambda c: c["fix"].update(owner="none", requires_owner_go=False), + "null observed_at": setp(["observed_at"], None), + "hypothesis without strings": lambda c: (c["evidence"].update(error_strings=[]), c["classification"].update(confidence="hypothesis")), + "30-line excerpt": lambda c: c["evidence"].update(log_excerpt="\n".join(["x"]*30), error_strings=["x"]), + "action@version is not an email": setp(["fix","description"], "actions/upload-artifact@v7.0.2 is missing"), + "pr null (main)": setp(["pr"], None), +} +fails = []; n = 0 +for code, fn in FIRE.items(): + n += 1 + if code == "V003": + got = [x[0] for x in check(copy.deepcopy(BASE), "SQ-CASE-9999.json")] + else: + got = [x[0] for x in check(mut(fn), None)] + if got != [code]: + fails.append(f"FIRE {code}: expected exactly [{code}], got {got}") +for name, fn in SILENT.items(): + n += 1 + got = [x[0] for x in check(mut(fn), None)] + if got: + fails.append(f"SILENT '{name}': expected no findings, got {got}") +real = sorted(glob.glob(os.path.join(HERE, "..", "cases", "*.json"))) +for p in real: + n += 1 + got = [x[0] for x in check(json.load(open(p, encoding="utf-8")), p)] + if got: + fails.append(f"SILENT {os.path.basename(p)}: expected no findings, got {got}") +n += 1 +if len(real) != 15: fails.append(f"expected 15 cases, found {len(real)}") +for f in fails: print("FAIL", f) +print(f"{n - len(fails)}/{n} tests behaved as expected ({len(FIRE)} fire, {len(SILENT)} near-miss silence, {len(real)} real cases silent)") +sys.exit(1 if fails else 0) diff --git a/corpus/validate.py b/corpus/validate.py new file mode 100644 index 0000000..47fbeff --- /dev/null +++ b/corpus/validate.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MPL-2.0 +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) +"""Offline validator for squabbler corpus cases. Standard library only. +Usage: validate.py FILE.json [FILE.json ...] (exit 0 = silent, 1 = findings)""" +import json, os, re, sys + +TOP = {"id","schema_version","repo","pr","run_id","job","step","attempt","observed_at", + "evidence","classification","main_comparison","fix","retry_policy","provenance"} +GROUPS = {"rate-limit","infra-flake","cancelled-timeout","lock-drift","stale-generated-file", + "real-failure","missing-tool","quality-gate"} +CONF = {"proven","likely","hypothesis"} +MAIN = {"passes","fails","absent","unknown"} +OWNERS = {"ci-gate-owner","pr-author","repo-owner","estate-owner","none"} +RISK = {"low","medium","high"} +RETRY = {"none","rerun","rerun-after-window","fix-then-rerun"} +READBY = {"log","api"} +SECRET = re.compile(r"(gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|AKIA[0-9A-Z]{16}|" + r"-----BEGIN [A-Z ]*PRIVATE KEY-----|(?i:bearer)\s+[A-Za-z0-9._~+/=-]{20,}|" + r"(?i:(?:token|secret|password|apikey)\s*[:=]\s*[^\s\"']{8,}))") +EMAIL = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}\b") +INTERNAL = re.compile(r"(\b[\w-]+\.(?:internal|corp|local|lan|intranet)\b|\b(?:10|192\.168)\.\d+\.\d+(?:\.\d+)?\b|\b172\.(?:1[6-9]|2\d|3[01])\.\d+\.\d+\b)", re.I) +TS = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$") + +def texts(o): + if isinstance(o, str): yield o + elif isinstance(o, dict): + for v in o.values(): yield from texts(v) + elif isinstance(o, list): + for v in o: yield from texts(v) + +def isint(v): return isinstance(v, int) and not isinstance(v, bool) + +def check(c, filename=None): + out = [] + def f(code, msg): out.append((code, msg)) + if not isinstance(c, dict): return [("V001", "case is not an object")] + if set(c) != TOP: + f("V001", f"fields differ: missing {sorted(TOP-set(c))} extra {sorted(set(c)-TOP)}") + return out + ev, cl, mc, fx, rp, pv = (c["evidence"], c["classification"], c["main_comparison"], + c["fix"], c["retry_policy"], c["provenance"]) + ok = True + def need(cond, msg): + nonlocal ok + if not cond: ok = False; f("V002", msg) + need(c["schema_version"] == "1", "schema_version must be \"1\"") + need(isinstance(c["id"], str) and re.fullmatch(r"SQ-CASE-\d{4}", c["id"] or ""), "id must match SQ-CASE-NNNN") + need(isinstance(c["repo"], str) and re.fullmatch(r"[\w.-]+/[\w.-]+", c["repo"] or ""), "repo must be owner/name") + need(c["pr"] is None or isint(c["pr"]), "pr must be integer or null (null = main)") + need(c["run_id"] is None or isint(c["run_id"]), "run_id must be integer or null") + need(c["attempt"] is None or isint(c["attempt"]), "attempt must be integer or null") + need(isinstance(c["job"], str) and c["job"], "job must be a non-empty string") + need(c["step"] is None or isinstance(c["step"], str), "step must be string or null") + need(isinstance(ev, dict) and set(ev) == {"log_excerpt","exit_code","error_strings"}, "evidence fields") + need(isinstance(cl, dict) and cl.get("group") in GROUPS and cl.get("confidence") in CONF, "classification group/confidence") + need(isinstance(mc, dict) and mc.get("state") in MAIN and isinstance(mc.get("note"), str), "main_comparison") + need(isinstance(fx, dict) and fx.get("owner") in OWNERS and fx.get("risk") in RISK and + isinstance(fx.get("files"), list) and isinstance(fx.get("requires_owner_go"), bool) and + isinstance(fx.get("description"), str), "fix fields") + need(isinstance(rp, dict) and rp.get("action") in RETRY, "retry_policy.action") + need(isinstance(pv, dict) and pv.get("read_by") in READBY, "provenance.read_by must be log or api") + if not ok: return out + if c["observed_at"] is not None and not (isinstance(c["observed_at"], str) and TS.match(c["observed_at"])): + f("V011", "observed_at must be UTC YYYY-MM-DDThh:mm:ssZ or null") + if filename and os.path.splitext(os.path.basename(filename))[0] != c["id"]: + f("V003", "file name must equal the case id") + ex = ev["log_excerpt"] + if ex is not None and (not isinstance(ex, str) or len(ex.splitlines()) > 30): + f("V004", "log_excerpt must be a string of at most 30 lines, or null") + strings = ev["error_strings"] + if not isinstance(strings, list) or not all(isinstance(s, str) and s for s in strings): + f("V002", "error_strings must be a list of non-empty strings"); return out + blob = list(texts(c)) + if any(SECRET.search(t) for t in blob): f("V005", "possible secret or token") + if any(EMAIL.search(t) for t in blob): f("V006", "email address") + if any(INTERNAL.search(t) for t in blob): f("V007", "internal hostname or private address") + if cl["confidence"] == "proven" and not strings: f("V009", "proven needs at least one verbatim error string") + if ex is not None and any(s not in ex for s in strings): f("V012", "error string not present in log_excerpt") + if fx["owner"] != "none" and not fx["requires_owner_go"]: f("V010", "a fix owned by someone needs requires_owner_go true") + return out + +def main(argv): + bad = 0 + for p in argv: + try: + with open(p, encoding="utf-8") as fh: c = json.load(fh) + except (OSError, ValueError) as e: + print(f"{p}: V000 unreadable: {e}"); bad += 1; continue + for code, msg in check(c, p): + print(f"{p}: {code} {msg}"); bad += 1 + return 1 if bad else 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:]))