From e50df177cafeb167ac733f8fc9ea141efea90542 Mon Sep 17 00:00:00 2001 From: hyperpolymath <6759885+hyperpolymath@users.noreply.github.com> Date: Sun, 22 Nov 2026 22:10:24 +0000 Subject: [PATCH 1/8] ci: harden scanner gates and validation receipts Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com> --- .githooks/validate-a2ml.sh | 29 +- .githooks/validate-k9.sh | 29 +- .github/workflows/README.adoc | 10 +- .github/workflows/dogfood-gate.yml | 82 +----- .github/workflows/quality.yml | 9 +- .github/workflows/static-analysis-gate.yml | 325 ++++++++------------- docs/ci-gates/REGISTER.adoc | 156 ++++++++++ scripts/check-invisible-characters.sh | 57 ++++ scripts/validate-static-analysis-json.sh | 105 +++++++ tests/check-invisible-characters.sh | 28 ++ tests/static-analysis-json.sh | 104 +++++++ tests/workflow-annotation-escaping.sh | 30 ++ 12 files changed, 688 insertions(+), 276 deletions(-) create mode 100644 docs/ci-gates/REGISTER.adoc create mode 100644 scripts/check-invisible-characters.sh create mode 100644 scripts/validate-static-analysis-json.sh create mode 100644 tests/check-invisible-characters.sh create mode 100644 tests/static-analysis-json.sh create mode 100644 tests/workflow-annotation-escaping.sh diff --git a/.githooks/validate-a2ml.sh b/.githooks/validate-a2ml.sh index b053676..d8777de 100755 --- a/.githooks/validate-a2ml.sh +++ b/.githooks/validate-a2ml.sh @@ -62,9 +62,27 @@ WARNINGS=0 # --------------------------------------------------------------------------- # Usage: annotate # level: error | warning | notice +escape_data() { + local value="$1" + value="${value//'%'/'%25'}" + value="${value//$'\r'/'%0D'}" + value="${value//$'\n'/'%0A'}" + printf '%s' "$value" +} + +escape_property() { + local value + value="$(escape_data "$1")" + value="${value//':'/'%3A'}" + value="${value//','/'%2C'}" + printf '%s' "$value" +} + annotate() { local level="$1" file="$2" line="$3" message="$4" - echo "::${level} file=${file},line=${line}::${message}" + printf '::%s file=%s,line=%s::%s\n' \ + "$level" "$(escape_property "$file")" \ + "$(escape_property "$line")" "$(escape_data "$message")" } # --------------------------------------------------------------------------- @@ -288,8 +306,11 @@ echo "::group::A2ML Manifest Validation" echo "Scanning ${SCAN_PATH} for .a2ml files..." echo "" -# Find all .a2ml files, excluding .git directory -mapfile -t a2ml_candidates < <(find "$SCAN_PATH" -name '*.a2ml' -not -path '*/.git/*' -type f | sort) +# Null-delimited discovery preserves unusual paths; a broken find/sort must fail. +discovery_tmp="$(mktemp)" +trap 'rm -f "$discovery_tmp"' EXIT +find "$SCAN_PATH" -name '*.a2ml' -not -path '*/.git/*' -type f -print0 | sort -z > "$discovery_tmp" +mapfile -d '' -t a2ml_candidates < "$discovery_tmp" # Apply paths-ignore filter a2ml_files=() @@ -319,7 +340,7 @@ echo "Found ${#a2ml_files[@]} .a2ml file(s)" echo "" for file in "${a2ml_files[@]}"; do - echo " Validating: ${file}" + printf ' Validating: %s\n' "$(escape_data "$file")" validate_a2ml "$file" done diff --git a/.githooks/validate-k9.sh b/.githooks/validate-k9.sh index c83e290..6dd3f2b 100755 --- a/.githooks/validate-k9.sh +++ b/.githooks/validate-k9.sh @@ -64,9 +64,27 @@ VALID_LEVELS="kennel yard hunt" # --------------------------------------------------------------------------- # Helper: emit GitHub annotation # --------------------------------------------------------------------------- +escape_data() { + local value="$1" + value="${value//'%'/'%25'}" + value="${value//$'\r'/'%0D'}" + value="${value//$'\n'/'%0A'}" + printf '%s' "$value" +} + +escape_property() { + local value + value="$(escape_data "$1")" + value="${value//':'/'%3A'}" + value="${value//','/'%2C'}" + printf '%s' "$value" +} + annotate() { local level="$1" file="$2" line="$3" message="$4" - echo "::${level} file=${file},line=${line}::${message}" + printf '::%s file=%s,line=%s::%s\n' \ + "$level" "$(escape_property "$file")" \ + "$(escape_property "$line")" "$(escape_data "$message")" } # --------------------------------------------------------------------------- @@ -295,8 +313,11 @@ echo "::group::K9 Configuration Validation" echo "Scanning ${SCAN_PATH} for K9 files (.k9, .k9.ncl)..." echo "" -# Find all K9 files, excluding .git directory -mapfile -t k9_candidates < <(find "$SCAN_PATH" \( -name '*.k9' -o -name '*.k9.ncl' \) -not -path '*/.git/*' -type f | sort) +# Null-delimited discovery preserves unusual paths; a broken find/sort must fail. +discovery_tmp="$(mktemp)" +trap 'rm -f "$discovery_tmp"' EXIT +find "$SCAN_PATH" \( -name '*.k9' -o -name '*.k9.ncl' \) -not -path '*/.git/*' -type f -print0 | sort -z > "$discovery_tmp" +mapfile -d '' -t k9_candidates < "$discovery_tmp" # Apply paths-ignore filter k9_files=() @@ -326,7 +347,7 @@ echo "Found ${#k9_files[@]} K9 file(s)" echo "" for file in "${k9_files[@]}"; do - echo " Validating: ${file}" + printf ' Validating: %s\n' "$(escape_data "$file")" validate_k9 "$file" done diff --git a/.github/workflows/README.adoc b/.github/workflows/README.adoc index a9c4f11..406d6ab 100644 --- a/.github/workflows/README.adoc +++ b/.github/workflows/README.adoc @@ -40,7 +40,13 @@ a step-level action with a record in `actions.lock`. * `sonarqube.yml` — SonarCloud (shell / JS surface; see `sonar-project.properties`). With no `SONAR_TOKEN` secret, the job says that the scan is not configured and passes. The SonarCloud app still analyses each pull request. -* `static-analysis-gate.yml` — panic-attack + Hypatia gate (see above). +* `static-analysis-gate.yml` — panic-attack + Hypatia critical-finding gate, + with validated scanner receipts (see `docs/ci-gates/REGISTER.adoc`). Both + scanner sources are full-commit pinned and scanner/build/schema failures are + fatal; the collector refuses to invent empty reports. Patch Bridge is an + explicitly advisory, conditional triage signal, not a blocking security + status. This gate is still awaiting a live Actions run of its pinned builds. Each targets a different language/surface; together they cover what no single -analyser does. +analyser does. A green status is only evidence for the specifically documented +threshold and applicable scan scope; it is not a proof of absence of all bugs. diff --git a/.github/workflows/dogfood-gate.yml b/.github/workflows/dogfood-gate.yml index 5646a37..f533feb 100644 --- a/.github/workflows/dogfood-gate.yml +++ b/.github/workflows/dogfood-gate.yml @@ -40,11 +40,11 @@ jobs: COUNT=$(find . \( -name '*.a2ml' -o -name '*.deed' \) -not -path './.git/*' | wc -l) echo "count=$COUNT" >> "$GITHUB_OUTPUT" if [ "$COUNT" -eq 0 ]; then - echo "::warning::No .a2ml/.deed manifest files found. Every RSR repo should have a repo deed (_chora.deed); legacy 0-AI-MANIFEST.a2ml accepted mid-migration — standards #837" + echo "::error::No .a2ml/.deed manifests found; this repository requires machine-readable manifests." + exit 1 fi - name: Validate A2ML manifests - if: steps.detect.outputs.count > 0 run: bash .githooks/validate-a2ml.sh - name: Write summary run: | @@ -53,9 +53,7 @@ jobs: cat <<'EOF' >> "$GITHUB_STEP_SUMMARY" ## A2ML Validation - :warning: **No .a2ml/.deed manifest files found.** Every RSR-compliant repo should have a repo deed (`_chora.deed`) at its root. - - Copy it from [rsr-template-repo](https://github.com/hyperpolymath/rsr-template-repo). + **Blocked:** no .a2ml/.deed manifests were found, but this repository requires machine-readable manifests. EOF else echo "## A2ML Validation" >> "$GITHUB_STEP_SUMMARY" @@ -85,7 +83,11 @@ jobs: echo "k9_count=$COUNT" >> "$GITHUB_OUTPUT" echo "config_count=$CONFIG_COUNT" >> "$GITHUB_OUTPUT" if [ "$COUNT" -eq 0 ] && [ "$CONFIG_COUNT" -gt 0 ]; then - echo "::warning::Found $CONFIG_COUNT config files but no K9 contracts. Run k9iser to generate contracts." + echo "::error::Found $CONFIG_COUNT config files but no K9 contracts; contract coverage is required." + exit 1 + fi + if [ "$COUNT" -eq 0 ]; then + echo "::notice::No K9 files and no covered configs; K9 check is not applicable." fi - name: Validate K9 contracts @@ -95,13 +97,11 @@ jobs: run: | K9_COUNT="${{ steps.detect.outputs.k9_count }}" CFG_COUNT="${{ steps.detect.outputs.config_count }}" - if [ "$K9_COUNT" -eq 0 ]; then + if [ "$K9_COUNT" -eq 0 ] && [ "$CFG_COUNT" -eq 0 ]; then cat <<'EOF' >> "$GITHUB_STEP_SUMMARY" ## K9 Contract Validation - :warning: **No .a2ml/.deed manifest files found.** Every RSR-compliant repo should have a repo deed (`_chora.deed`) at its root. - - Generate contracts with: `k9iser generate .` + Not applicable: no covered configuration files are present. EOF else echo "## K9 Contract Validation" >> "$GITHUB_STEP_SUMMARY" @@ -121,58 +121,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v7.0.1 - - name: Scan for invisible characters - id: lint - run: | - # Inline invisible character detection (from empty-linter's core patterns). - # Checks for: zero-width spaces, zero-width joiners, BOM, soft hyphens, - # non-breaking spaces, null bytes, and other invisible Unicode in source files. - set +e - PATTERNS='(*UTF)[\x00-\x08\x0B\x0C\x0E-\x1F\x{a0}\x{ad}\x{200b}-\x{200f}\x{202a}-\x{202f}\x{2060}\x{2066}-\x{2069}\x{feff}]' - find "$GITHUB_WORKSPACE" \ - -not -path '*/.git/*' -not -path '*/node_modules/*' \ - -not -path '*/.deno/*' -not -path '*/target/*' \ - -not -path '*/_build/*' -not -path '*/deps/*' \ - -not -path '*/external_corpora/*' -not -path '*/.lake/*' \ - -type f \( -name '*.rs' -o -name '*.ex' -o -name '*.exs' -o -name '*.res' \ - -o -name '*.js' -o -name '*.ts' -o -name '*.json' -o -name '*.toml' \ - -o -name '*.yml' -o -name '*.yaml' -o -name '*.md' -o -name '*.adoc' \ - -o -name '*.idr' -o -name '*.zig' -o -name '*.v' -o -name '*.jl' \ - -o -name '*.gleam' -o -name '*.hs' -o -name '*.ml' -o -name '*.sh' \) \ - -exec grep -alP "$PATTERNS" {} + > /tmp/empty-lint-results.txt - EL_EXIT=$? - set -e - - FINDINGS=$(wc -l < /tmp/empty-lint-results.txt 2>/dev/null || echo 0) - echo "findings=$FINDINGS" >> "$GITHUB_OUTPUT" - echo "exit_code=$EL_EXIT" >> "$GITHUB_OUTPUT" - echo "ready=true" >> "$GITHUB_OUTPUT" - - # Emit annotations for each file with invisible chars - while IFS= read -r filepath; do - [ -z "$filepath" ] && continue - REL_PATH="${filepath#$GITHUB_WORKSPACE/}" - echo "::warning file=${REL_PATH}::Invisible Unicode characters detected (zero-width space, BOM, NBSP, etc.)" - done < /tmp/empty-lint-results.txt - - - name: Write summary - run: | - if [ "${{ steps.lint.outputs.ready }}" = "true" ]; then - FINDINGS="${{ steps.lint.outputs.findings }}" - if [ "$FINDINGS" -gt 0 ] 2>/dev/null; then - echo "## Empty-Linter Results" >> "$GITHUB_STEP_SUMMARY" - echo "" >> "$GITHUB_STEP_SUMMARY" - echo "Found **${FINDINGS}** invisible character issue(s). See annotations above." >> "$GITHUB_STEP_SUMMARY" - else - echo "## Empty-Linter Results" >> "$GITHUB_STEP_SUMMARY" - echo "" >> "$GITHUB_STEP_SUMMARY" - echo ":white_check_mark: No invisible character issues found." >> "$GITHUB_STEP_SUMMARY" - fi - else - echo "## Empty-Linter" >> "$GITHUB_STEP_SUMMARY" - echo "" >> "$GITHUB_STEP_SUMMARY" - echo "Skipped: empty-linter not available." >> "$GITHUB_STEP_SUMMARY" - fi + - name: Enforce invisible-character policy + run: bash scripts/check-invisible-characters.sh . # --------------------------------------------------------------------------- # Job 4: Groove manifest check (for repos that should expose services) @@ -196,11 +146,9 @@ jobs: if [ -f ".well-known/groove/manifest.json" ]; then HAS_MANIFEST="true" # Validate the manifest JSON - if ! jq empty .well-known/groove/manifest.json 2>/dev/null; then - echo "::error file=.well-known/groove/manifest.json::Invalid JSON in Groove manifest" - else - SVC_ID=$(jq -r '.service_id // "unknown"' .well-known/groove/manifest.json) - echo "service_id=$SVC_ID" >> "$GITHUB_OUTPUT" + if ! jq -e 'type == "object" and (.service_id | type == "string" and length > 0)' .well-known/groove/manifest.json >/dev/null; then + echo "::error file=.well-known/groove/manifest.json::Groove manifest must be a JSON object with a non-empty service_id" + exit 1 fi fi diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 941a8f3..f637014 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -35,9 +35,16 @@ jobs: - name: Check for large files run: | find . -type f -size +1M -not -path "./.git/*" | head -10 || echo "No large files" - - name: EditorConfig check + # Advisory only: continue-on-error means this result is never a gate. + - name: EditorConfig advisory (non-blocking) uses: editorconfig-checker/action-editorconfig-checker@v3.0.0 continue-on-error: true + - name: Static-analysis report contract regressions + run: bash tests/static-analysis-json.sh + - name: Invisible-character scanner controls + run: bash tests/check-invisible-characters.sh + - name: Workflow annotation escaping controls + run: bash tests/workflow-annotation-escaping.sh docs: runs-on: ubuntu-latest timeout-minutes: 15 diff --git a/.github/workflows/static-analysis-gate.yml b/.github/workflows/static-analysis-gate.yml index 3170817..f7a1acf 100644 --- a/.github/workflows/static-analysis-gate.yml +++ b/.github/workflows/static-analysis-gate.yml @@ -2,8 +2,8 @@ # This workflow is managed by gh actions-lock. # This workflow is managed by gh actions-lock. # This workflow is managed by gh actions-lock. -# Static Analysis Gate — Required by branch protection rules. -# Runs panic-attack and hypatia, deposits findings for gitbot-fleet learning. +# Static Analysis Gate — scanner absence, malformed evidence, or execution failure is a failure. +# Runs pinned panic-attack and Hypatia sources, then deposits only validated findings. name: Static Analysis Gate on: pull_request: @@ -22,86 +22,54 @@ jobs: panic-attack-assail: name: panic-attack assail runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 45 steps: - name: Checkout repository uses: actions/checkout@v7.0.1 with: fetch-depth: 0 - - name: Install panic-attack (if available) - id: install + - name: Build panic-attack from the pinned source revision + env: + PANIC_ATTACK_SHA: 7b9f145c2194eb0d46ace82a5a4518db5db38a5e run: | - # Try to fetch the latest release binary from the org - PA_URL="https://github.com/hyperpolymath/panic-attack/releases/latest/download/panic-attack-linux-x86_64" - if curl -fsSL --head "$PA_URL" >/dev/null 2>&1; then - curl -fsSL -o /usr/local/bin/panic-attack "$PA_URL" - chmod +x /usr/local/bin/panic-attack - echo "installed=true" >> "$GITHUB_OUTPUT" - else - echo "::notice::panic-attack binary not available — skipping assail" - echo "installed=false" >> "$GITHUB_OUTPUT" - fi + set -euo pipefail + command -v rustup >/dev/null 2>&1 || { echo "::error::rustup is required to build pinned panic-attack"; exit 1; } + rustup toolchain install 1.90.0 --profile minimal + src="$RUNNER_TEMP/panic-attack" + git init "$src" + git -C "$src" remote add origin https://github.com/hyperpolymath/panic-attack.git + git -C "$src" fetch --depth=1 origin "$PANIC_ATTACK_SHA" + git -C "$src" checkout --detach FETCH_HEAD + actual="$(git -C "$src" rev-parse HEAD)" + [[ "$actual" == "$PANIC_ATTACK_SHA" ]] || { echo "::error::panic-attack source revision mismatch"; exit 1; } + cargo +1.90.0 build --locked --release --features http --manifest-path "$src/Cargo.toml" --bin panic-attack + install -m 0755 "$src/target/release/panic-attack" "$RUNNER_TEMP/panic-attack" + echo "$RUNNER_TEMP" >> "$GITHUB_PATH" - name: Run panic-attack assail id: assail - if: steps.install.outputs.installed == 'true' run: | - set +e - panic-attack assail --format json . > panic-attack-findings.json - PA_EXIT=$? - set -e - - # Same defect class as the Hypatia job below: `2>&1` folded the - # scanner's stderr into the JSON payload, so every jq parse failed, - # every count silently became 0 via `|| echo 0`, and "Fail on critical - # findings" could never fire on any input. Keep stderr on the log. - if [ ! -s panic-attack-findings.json ]; then - echo "[]" > panic-attack-findings.json - fi - - # Deliberately a WARNING, not a failure. panic-attack is a downloaded - # release binary whose exit-code and output contract are not verified - # here, and it has no confirmed --exit-zero equivalent, so we surface a - # malformed payload in the log rather than block on an unverified tool. - # Promote to `exit 1` (as the Hypatia job does) once that contract is - # confirmed -- see the follow-up issue linked from this PR. - if ! jq -e 'type == "array"' panic-attack-findings.json >/dev/null 2>&1; then - echo "::warning::panic-attack output is not a JSON array (exit ${PA_EXIT}); counts below are unreliable" - fi - - # Parse finding counts - TOTAL=$(jq '. | length' panic-attack-findings.json 2>/dev/null || echo 0) - CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' panic-attack-findings.json 2>/dev/null || echo 0) - HIGH=$(jq '[.[] | select(.severity == "high")] | length' panic-attack-findings.json 2>/dev/null || echo 0) - MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' panic-attack-findings.json 2>/dev/null || echo 0) - LOW=$(jq '[.[] | select(.severity == "low")] | length' panic-attack-findings.json 2>/dev/null || echo 0) - - echo "total=$TOTAL" >> "$GITHUB_OUTPUT" - echo "critical=$CRITICAL" >> "$GITHUB_OUTPUT" - echo "high=$HIGH" >> "$GITHUB_OUTPUT" - echo "medium=$MEDIUM" >> "$GITHUB_OUTPUT" - echo "low=$LOW" >> "$GITHUB_OUTPUT" - echo "exit_code=$PA_EXIT" >> "$GITHUB_OUTPUT" + set -euo pipefail + panic-attack --quiet assail . --headless --fail-on-incomplete > panic-attack-findings.json + bash scripts/validate-static-analysis-json.sh assail panic-attack-findings.json "$GITHUB_OUTPUT" - name: Emit check annotations - if: steps.install.outputs.installed == 'true' run: | # Convert JSON findings into GitHub Actions annotations - # Findings carry no `.message` (keys: action,file,line,reason,rule_module, - # severity,type), so every annotation read "null". `.file` is an absolute - # runner path, which GitHub cannot anchor to the diff, so it is made - # workspace-relative here. - jq -r --arg ws "$GITHUB_WORKSPACE" '.[] | select(.file != null) | - (.file | ltrimstr($ws + "/")) as $f | - (.reason // .message // .type // "finding") as $m | - if .severity == "critical" then - "::error file=\($f),line=\(.line // 1)::[panic-attack] \($m)" - elif .severity == "high" then - "::error file=\($f),line=\(.line // 1)::[panic-attack] \($m)" + # Escape untrusted scanner fields before emitting workflow commands. + # AssailReport is an object with `weak_points`, not a top-level array. + jq -r --arg ws "$GITHUB_WORKSPACE" ' + def msg: tostring | gsub("%"; "%25") | gsub("\r"; "%0D") | gsub("\n"; "%0A"); + def prop: msg | gsub(":"; "%3A") | gsub(","; "%2C"); + .weak_points[] | select(.suppressed != true) | + ((.file // .location // "unknown") | sub("^" + $ws + "/"; "") | prop) as $f | + ((.description // "finding") | msg) as $m | + ((.line // 1) | tostring | prop) as $line | + if .severity == "Critical" or .severity == "High" then + "::error file=\($f),line=\($line)::[panic-attack] \($m)" else - "::warning file=\($f),line=\(.line // 1)::[panic-attack] \($m)" + "::warning file=\($f),line=\($line)::[panic-attack] \($m)" end - ' panic-attack-findings.json || true + ' panic-attack-findings.json - name: Write step summary - if: steps.install.outputs.installed == 'true' run: | cat <> "$GITHUB_STEP_SUMMARY" ## panic-attack assail Results @@ -114,13 +82,6 @@ jobs: | Low | ${{ steps.assail.outputs.low }} | | **Total**| ${{ steps.assail.outputs.total }} | EOF - - name: Create stub findings (when panic-attack unavailable) - if: steps.install.outputs.installed != 'true' - run: | - echo "[]" > panic-attack-findings.json - echo "## panic-attack assail" >> "$GITHUB_STEP_SUMMARY" - echo "" >> "$GITHUB_STEP_SUMMARY" - echo "Skipped: panic-attack not available in this environment." >> "$GITHUB_STEP_SUMMARY" - name: Upload panic-attack findings uses: actions/upload-artifact@v7.0.2 with: @@ -128,7 +89,7 @@ jobs: path: panic-attack-findings.json retention-days: 90 - name: Fail on critical findings - if: steps.install.outputs.installed == 'true' && steps.assail.outputs.critical > 0 + if: steps.assail.outputs.critical > 0 run: | echo "::error::panic-attack found ${{ steps.assail.outputs.critical }} critical issue(s) — blocking merge" exit 1 @@ -146,7 +107,7 @@ jobs: hypatia-scan: name: Hypatia neurosymbolic scan runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 30 steps: - name: Checkout repository uses: actions/checkout@v7.0.1 @@ -154,36 +115,32 @@ jobs: fetch-depth: 0 - name: Setup Elixir for Hypatia scanner id: beam - continue-on-error: true uses: erlef/setup-beam@v1.24.1 with: elixir-version: '1.19.4' otp-version: '28.3' - - name: Clone and build Hypatia - id: build - continue-on-error: true + - name: Clone and build Hypatia at a fixed revision + env: + HYPATIA_SHA: d158aed87f76b93e4f291e995bef9f26559c7fb2 run: | - git clone https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia" 2>/dev/null || true - if [ -f "$HOME/hypatia/mix.exs" ]; then - cd "$HOME/hypatia" - # Build escript if neither hypatia nor hypatia-v2 exists - if [ ! -f hypatia ] && [ ! -f hypatia-v2 ]; then - mix deps.get - mix escript.build - fi - echo "ready=true" >> "$GITHUB_OUTPUT" - else - echo "::notice::Hypatia scanner not available — skipping scan" - echo "ready=false" >> "$GITHUB_OUTPUT" - fi + set -euo pipefail + src="$RUNNER_TEMP/hypatia" + git init "$src" + git -C "$src" remote add origin https://github.com/hyperpolymath/hypatia.git + git -C "$src" fetch --depth=1 origin "$HYPATIA_SHA" + git -C "$src" checkout --detach FETCH_HEAD + actual="$(git -C "$src" rev-parse HEAD)" + [[ "$actual" == "$HYPATIA_SHA" ]] || { echo "::error::Hypatia source revision mismatch"; exit 1; } + [[ -f "$src/mix.exs" && -f "$src/mix.lock" ]] || { echo "::error::pinned Hypatia source lacks its project or dependency lock"; exit 1; } + cd "$src" + mix deps.get --check-locked + mix escript.build + install -m 0755 hypatia "$RUNNER_TEMP/hypatia" - name: Run Hypatia scan id: scan - if: steps.build.outputs.ready == 'true' run: | - set +e - HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . --exit-zero > hypatia-findings.json - HYP_EXIT=$? - set -e + set -euo pipefail + HYPATIA_FORMAT=json "$RUNNER_TEMP/hypatia" scan . --exit-zero > hypatia-findings.json # --exit-zero is Hypatia's own documented CI recipe (lib/hypatia/cli.ex), # for exactly this case: "use in CI when a downstream step gates on @@ -194,48 +151,27 @@ jobs: # summary line into the JSON, so every parse fails, the old `[]` # fallback substituted a clean result, CRITICAL was always 0, and the # gate below could never fire on any input. Keep stderr on the log. - if [ "$HYP_EXIT" -ne 0 ]; then - echo "::error::Hypatia scanner execution failed with exit ${HYP_EXIT}" - exit "$HYP_EXIT" - fi - # `jq empty` is NOT sufficient -- it succeeds on any valid JSON, - # including a bare string, object or null. Assert the array. - if [ ! -s hypatia-findings.json ] || ! jq -e 'type == "array"' hypatia-findings.json >/dev/null; then - echo "::error::Hypatia did not produce a valid JSON findings array" - exit 1 - fi - - TOTAL=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0) - CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' hypatia-findings.json 2>/dev/null || echo 0) - HIGH=$(jq '[.[] | select(.severity == "high")] | length' hypatia-findings.json 2>/dev/null || echo 0) - MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' hypatia-findings.json 2>/dev/null || echo 0) - LOW=$(jq '[.[] | select(.severity == "low")] | length' hypatia-findings.json 2>/dev/null || echo 0) - - echo "total=$TOTAL" >> "$GITHUB_OUTPUT" - echo "critical=$CRITICAL" >> "$GITHUB_OUTPUT" - echo "high=$HIGH" >> "$GITHUB_OUTPUT" - echo "medium=$MEDIUM" >> "$GITHUB_OUTPUT" - echo "low=$LOW" >> "$GITHUB_OUTPUT" + bash scripts/validate-static-analysis-json.sh hypatia hypatia-findings.json "$GITHUB_OUTPUT" - name: Emit check annotations - if: steps.build.outputs.ready == 'true' run: | # Findings carry no `.message` (keys: action,file,line,reason,rule_module, # severity,type), so every annotation read "null". `.file` is an absolute # runner path, which GitHub cannot anchor to the diff, so it is made # workspace-relative here. - jq -r --arg ws "$GITHUB_WORKSPACE" '.[] | select(.file != null) | - (.file | ltrimstr($ws + "/")) as $f | - (.reason // .message // .type // "finding") as $m | - if .severity == "critical" then - "::error file=\($f),line=\(.line // 1)::[hypatia] \($m)" - elif .severity == "high" then - "::error file=\($f),line=\(.line // 1)::[hypatia] \($m)" + jq -r --arg ws "$GITHUB_WORKSPACE" ' + def msg: tostring | gsub("%"; "%25") | gsub("\r"; "%0D") | gsub("\n"; "%0A"); + def prop: msg | gsub(":"; "%3A") | gsub(","; "%2C"); + .[] | + ((if .file == "" then "unknown" else .file end) | sub("^" + $ws + "/"; "") | prop) as $f | + ((.reason // .message // .type) | msg) as $m | + ((.line // 1) | tostring | prop) as $line | + if .severity == "critical" or .severity == "high" then + "::error file=\($f),line=\($line)::[hypatia] \($m)" else - "::warning file=\($f),line=\(.line // 1)::[hypatia] \($m)" + "::warning file=\($f),line=\($line)::[hypatia] \($m)" end - ' hypatia-findings.json || true + ' hypatia-findings.json - name: Write step summary - if: steps.build.outputs.ready == 'true' run: | cat <> "$GITHUB_STEP_SUMMARY" ## Hypatia Scan Results @@ -248,13 +184,6 @@ jobs: | Low | ${{ steps.scan.outputs.low }} | | **Total**| ${{ steps.scan.outputs.total }} | EOF - - name: Create stub findings (when Hypatia unavailable) - if: steps.build.outputs.ready != 'true' - run: | - echo "[]" > hypatia-findings.json - echo "## Hypatia Scan" >> "$GITHUB_STEP_SUMMARY" - echo "" >> "$GITHUB_STEP_SUMMARY" - echo "Skipped: Hypatia scanner not available in this environment." >> "$GITHUB_STEP_SUMMARY" - name: Upload hypatia findings uses: actions/upload-artifact@v7.0.2 with: @@ -262,7 +191,7 @@ jobs: path: hypatia-findings.json retention-days: 90 - name: Fail on critical security findings - if: steps.build.outputs.ready == 'true' && steps.scan.outputs.critical > 0 + if: steps.scan.outputs.critical > 0 run: | echo "::error::Hypatia found ${{ steps.scan.outputs.critical }} critical security issue(s) — blocking merge" exit 1 @@ -270,80 +199,80 @@ jobs: # Job 3: patch-bridge triage (CVE contextual assessment) # --------------------------------------------------------------------------- patch-bridge-triage: - name: Patch Bridge CVE triage + name: Patch Bridge CVE triage (advisory) runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 45 steps: - name: Checkout repository uses: actions/checkout@v7.0.1 with: fetch-depth: 0 - - name: Install panic-attack (if available) - id: install + - name: Detect supported dependency lockfiles + id: applicability run: | - PA_URL="https://github.com/hyperpolymath/panic-attack/releases/latest/download/panic-attack-linux-x86_64" - if curl -fsSL --head "$PA_URL" >/dev/null 2>&1; then - curl -fsSL -o /usr/local/bin/panic-attack "$PA_URL" - chmod +x /usr/local/bin/panic-attack - echo "installed=true" >> "$GITHUB_OUTPUT" + set -euo pipefail + if git ls-files | grep -Eq '(^|/)(Cargo\.lock|mix\.lock|package-lock\.json|requirements\.txt)$'; then + echo 'applicable=true' >> "$GITHUB_OUTPUT" else - echo "::notice::panic-attack binary not available — skipping Patch Bridge" - echo "installed=false" >> "$GITHUB_OUTPUT" + echo 'applicable=false' >> "$GITHUB_OUTPUT" fi + - name: Build panic-attack from the pinned source revision + if: steps.applicability.outputs.applicable == 'true' + env: + PANIC_ATTACK_SHA: 7b9f145c2194eb0d46ace82a5a4518db5db38a5e + run: | + set -euo pipefail + command -v rustup >/dev/null 2>&1 || { echo "::error::rustup is required to build pinned panic-attack"; exit 1; } + rustup toolchain install 1.90.0 --profile minimal + src="$RUNNER_TEMP/panic-attack" + git init "$src" + git -C "$src" remote add origin https://github.com/hyperpolymath/panic-attack.git + git -C "$src" fetch --depth=1 origin "$PANIC_ATTACK_SHA" + git -C "$src" checkout --detach FETCH_HEAD + actual="$(git -C "$src" rev-parse HEAD)" + [[ "$actual" == "$PANIC_ATTACK_SHA" ]] || { echo "::error::panic-attack source revision mismatch"; exit 1; } + cargo +1.90.0 build --locked --release --features http --manifest-path "$src/Cargo.toml" --bin panic-attack + install -m 0755 "$src/target/release/panic-attack" "$RUNNER_TEMP/panic-attack" + echo "$RUNNER_TEMP" >> "$GITHUB_PATH" - name: Run Patch Bridge triage id: triage - if: steps.install.outputs.installed == 'true' + if: steps.applicability.outputs.applicable == 'true' run: | - set +e - panic-attack bridge triage --format json . > bridge-report.json 2>&1 - PB_EXIT=$? - set -e - - if [ ! -s bridge-report.json ] || ! jq empty bridge-report.json 2>/dev/null; then - echo '{"cves":[],"mitigated":0,"unmitigable":0,"concatenative":0,"informational":0}' > bridge-report.json - fi - - UNMITIGABLE=$(jq '.unmitigable // 0' bridge-report.json) - MITIGATED=$(jq '.mitigated // 0' bridge-report.json) - CONCATENATIVE=$(jq '.concatenative // 0' bridge-report.json) - INFORMATIONAL=$(jq '.informational // 0' bridge-report.json) - - echo "unmitigable=$UNMITIGABLE" >> "$GITHUB_OUTPUT" - echo "mitigated=$MITIGATED" >> "$GITHUB_OUTPUT" - echo "concatenative=$CONCATENATIVE" >> "$GITHUB_OUTPUT" - echo "informational=$INFORMATIONAL" >> "$GITHUB_OUTPUT" + set -euo pipefail + panic-attack --quiet bridge triage . --output bridge-report.json + bash scripts/validate-static-analysis-json.sh bridge bridge-report.json "$GITHUB_OUTPUT" + - name: Record Patch Bridge as explicitly not applicable + id: not_applicable + if: steps.applicability.outputs.applicable != 'true' + run: | + set -euo pipefail + printf '%s\n' '{"status":"not_applicable","reason":"no supported dependency lockfile is present"}' > bridge-report.json + bash scripts/validate-static-analysis-json.sh bridge bridge-report.json "$GITHUB_OUTPUT" - name: Write step summary - if: steps.install.outputs.installed == 'true' run: | cat <> "$GITHUB_STEP_SUMMARY" ## Patch Bridge CVE Triage | Classification | Count | |----------------|-------| - | Unmitigable | ${{ steps.triage.outputs.unmitigable }} | - | Mitigated | ${{ steps.triage.outputs.mitigated }} | - | Concatenative | ${{ steps.triage.outputs.concatenative }} | - | Informational | ${{ steps.triage.outputs.informational }} | + | Applicability | ${{ steps.triage.outputs.bridge_status || steps.not_applicable.outputs.bridge_status || 'unknown' }} | + | Unmitigable | ${{ steps.triage.outputs.unmitigable || steps.not_applicable.outputs.unmitigable || 'n/a' }} | + | Mitigated | ${{ steps.triage.outputs.mitigated || steps.not_applicable.outputs.mitigated || 'n/a' }} | + | Concatenative | ${{ steps.triage.outputs.concatenative || steps.not_applicable.outputs.concatenative || 'n/a' }} | + | Informational | ${{ steps.triage.outputs.informational || steps.not_applicable.outputs.informational || 'n/a' }} | Unmitigable CVEs require dependency replacement or rearchitecture. Mitigated CVEs have active controls with soundness proofs. Concatenative risks are CVE combinations that multiply severity. EOF - - name: Create stub report (when unavailable) - if: steps.install.outputs.installed != 'true' - run: | - echo '{"cves":[],"mitigated":0,"unmitigable":0,"concatenative":0,"informational":0}' > bridge-report.json - echo "## Patch Bridge CVE Triage" >> "$GITHUB_STEP_SUMMARY" - echo "" >> "$GITHUB_STEP_SUMMARY" - echo "Skipped: panic-attack not available in this environment." >> "$GITHUB_STEP_SUMMARY" - name: Upload bridge report uses: actions/upload-artifact@v7.0.2 with: name: bridge-report path: bridge-report.json retention-days: 90 - - name: Fail on unmitigable CVEs in critical paths - if: steps.install.outputs.installed == 'true' && steps.triage.outputs.unmitigable > 0 + - name: Report unmitigable CVEs for human review + if: steps.applicability.outputs.applicable == 'true' && steps.triage.outputs.unmitigable > 0 run: | echo "::warning::Patch Bridge found ${{ steps.triage.outputs.unmitigable }} unmitigable CVE(s) — review required" # Warning only, not blocking. Unmitigable means the developer needs @@ -358,6 +287,10 @@ jobs: needs: [panic-attack-assail, hypatia-scan, patch-bridge-triage] if: always() steps: + - name: Checkout repository for report validation + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false - name: Download panic-attack findings uses: actions/download-artifact@v8.0.2 with: @@ -379,22 +312,18 @@ jobs: PA_FILE="findings/panic-attack-findings.json" HYP_FILE="findings/hypatia-findings.json" - # Ensure both files exist and are valid JSON arrays - for f in "$PA_FILE" "$HYP_FILE"; do - if [ ! -s "$f" ] || ! jq empty "$f" 2>/dev/null; then - echo "[]" > "$f" - fi - done + # These files are evidence from successful, schema-validated scanner jobs. + # Missing, empty, or malformed artifacts are an infrastructure failure. + bash scripts/validate-static-analysis-json.sh assail "$PA_FILE" "$RUNNER_TEMP/pa-counts" + bash scripts/validate-static-analysis-json.sh hypatia "$HYP_FILE" "$RUNNER_TEMP/hyp-counts" # Tag each finding with its source scanner - jq '[.[] | . + {"scanner": "panic-attack"}]' "$PA_FILE" > /tmp/pa-tagged.json + jq '[.weak_points[] | . + {"scanner": "panic-attack"}]' "$PA_FILE" > /tmp/pa-tagged.json jq '[.[] | . + {"scanner": "hypatia"}]' "$HYP_FILE" > /tmp/hyp-tagged.json # Read bridge report (CVE triage, not findings array) BRIDGE_FILE="findings/bridge-report.json" - if [ ! -s "$BRIDGE_FILE" ] || ! jq empty "$BRIDGE_FILE" 2>/dev/null; then - echo '{"cves":[],"mitigated":0,"unmitigable":0,"concatenative":0,"informational":0}' > "$BRIDGE_FILE" - fi + bash scripts/validate-static-analysis-json.sh bridge "$BRIDGE_FILE" "$RUNNER_TEMP/bridge-counts" # Build unified report envelope jq -n \ @@ -417,11 +346,11 @@ jobs: patch_bridge: $bridge[0] }' > findings/unified-findings.json - TOTAL=$(jq '.findings | length' findings/unified-findings.json) - CRITICAL=$(jq '[.findings[] | select(.severity == "critical")] | length' findings/unified-findings.json) - HIGH=$(jq '[.findings[] | select(.severity == "high")] | length' findings/unified-findings.json) - MEDIUM=$(jq '[.findings[] | select(.severity == "medium")] | length' findings/unified-findings.json) - LOW=$(jq '[.findings[] | select(.severity == "low")] | length' findings/unified-findings.json) + TOTAL=$(jq '[.findings[] | select(.suppressed != true)] | length' findings/unified-findings.json) + CRITICAL=$(jq '[.findings[] | select(.suppressed != true) | select(.severity == "critical" or .severity == "Critical")] | length' findings/unified-findings.json) + HIGH=$(jq '[.findings[] | select(.suppressed != true) | select(.severity == "high" or .severity == "High")] | length' findings/unified-findings.json) + MEDIUM=$(jq '[.findings[] | select(.suppressed != true) | select(.severity == "medium" or .severity == "Medium")] | length' findings/unified-findings.json) + LOW=$(jq '[.findings[] | select(.suppressed != true) | select(.severity == "low" or .severity == "Low")] | length' findings/unified-findings.json) echo "total=$TOTAL" >> "$GITHUB_OUTPUT" echo "critical=$CRITICAL" >> "$GITHUB_OUTPUT" diff --git a/docs/ci-gates/REGISTER.adoc b/docs/ci-gates/REGISTER.adoc new file mode 100644 index 0000000..96b59da --- /dev/null +++ b/docs/ci-gates/REGISTER.adoc @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 += CI Gate Safety Register +:revdate: 2026-11-22 + +This register records the CI controls reviewed for this change. *Safe* means the +check has a bounded, explicit subject; missing tools, invalid output and API or +scanner errors cannot turn into a pass; and a green result means the stated +check actually ran. An advisory or not-applicable result is not a pass for a +mandatory check. + +== Scope and GitHub visibility + +The repository has no open pull requests at the time of this review, so there +was no open PR checklist or check list to update. GitHub branch-protection API +access returned HTTP 403 (`Resource not accessible by integration`); required +contexts could not be read or changed. The latest historical `Static Analysis +Gate` and `Dogfood Gate` runs in the available run list were green, but that +alone did not establish that their tools had run or their output had been +validated. + +== Decisions + +== Trust boundary still open + +The changed jobs use the pull-request checkout. A pull request that can change a +workflow or one of its scripts can change the check implementation too; these +local changes improve honest-run correctness but do not make the check's own +source tamper-proof. The central suite's current tamper guard protects its +`ci-gate*` paths, not this repository's `static-analysis-gate.yml` or +`dogfood-gate.yml`. We could not inspect this repository's active ruleset or +required contexts (the branch-protection API returned 403), so no claim is made +that code-owner review or required checks close this trust boundary. The checks +below are therefore *implementation-hardened, not yet qualified as an +independent security boundary*. + + +[cols="2,2,1,4",options="header"] +|=== +|Workflow / control |Classification |State |Safety decision + +|`static-analysis-gate.yml` — panic-attack +|Blocking on critical; advisory annotations below threshold +|*Changed; live CI pending* +|Builds from a fixed full commit, checks out that exact commit, uses the pinned +Rust toolchain and lockfile, and runs the documented machine-readable command. +The previous latest-release URL could return no asset and silently skip. Missing +source/compiler, incomplete coverage, scanner failure, malformed or unknown +report schema now fails. The validator understands the pinned `AssailReport` +2.6 object (`weak_points`, PascalCase severities, complete coverage), rather +than treating it as a findings array. Suppressed entries remain in the saved +report but do not count toward blocking thresholds, as the scanner contract +specifies. + +|`static-analysis-gate.yml` — Hypatia +|Blocking on critical; advisory annotations below threshold +|*Changed; live CI pending* +|Builds at a fixed full commit with the committed dependency lock; clone, +build, or scan failures are fatal. A finding array must have recognized +severity, source file and description for every item. No empty-array fallback +or zero-count substitution remains. Untrusted annotation fields are escaped. + +|`static-analysis-gate.yml` — Patch Bridge +|Advisory and conditionally applicable +|*Changed; live CI pending* +|The scanner supports four named lockfile kinds; no supported tracked lockfile +now produces an explicit `not_applicable` receipt, not a fabricated clean +report. Applicable scans use the fixed panic-attack build, fail on command or +schema errors, and reject `offline-unavailable` output. Unmitigable CVEs are +still a human-review warning, not a blocking policy; the step is named +accordingly. + +|`static-analysis-gate.yml` — finding deposit +|Required evidence aggregation +|*Changed; live CI pending* +|The collector now checks out the validator and refuses missing or malformed +scanner artifacts instead of manufacturing `[]` or zero-count Bridge data. +The unified report consumes the actual AssailReport `weak_points` list. + +|`dogfood-gate.yml` — A2ML / K9 +|Required when applicable +|*Changed; local checks pass* +|A missing A2ML manifest fails for this repository. Config-bearing repositories +with no K9 contracts fail; absence of covered configuration is explicitly +not-applicable. Both existing validators pass locally (103 A2ML files, 17 K9 +files; A2ML reported six SPDX warnings). + +|`dogfood-gate.yml` — invisible-character scanner +|Blocking +|*Changed; local negative and positive controls pass* +|Moved the scan to a tested helper. A no-match exit from `grep` is handled as a +normal clean file, but grep/find errors fail; findings now fail the check. It +reports paths without emitting unescaped user-controlled workflow annotations. + +|`dogfood-gate.yml` — Groove manifest +|Conditional +|*Changed; live CI pending* +|A present manifest must be a JSON object with non-empty `service_id`; malformed +or structurally incomplete JSON fails instead of emitting an annotation and +continuing. No manifest is not applicable unless a service is detected; the +existing missing-endpoint recommendation remains advisory. + +|`dogfood-gate.yml` — energy manifest and scorecard +|Advisory / optional +|*Existing; not a required assurance claim* +|These signals remain informational. A missing optional energy manifest does +not certify energy compliance; the summary score is not a security or build +verdict. + +|`.githooks/validate-a2ml.sh`, `.githooks/validate-k9.sh` annotations +|Output safety +|*Changed; syntax and local validators pass* +|Null-delimited file discovery handles newlines; file names and messages are +escaped for GitHub workflow-command delimiters before annotation emission. + +|`quality.yml` — static report, invisible scan and annotation controls +|Regression controls +|*Added; local tests pass* +|Positive and negative JSON/report controls, invisible-character fixtures, and +newline-based workflow-command injection controls run in the quality job. The +separate EditorConfig action still has `continue-on-error: true`; it is advisory +and must not be counted as a required gate until that is removed and the action +is witnessed failing on bad input. + +|`proven-cicd-and-workflows` `CI/gate` reusable +|Not adopted +|*Not qualified for this consumer* +|The upstream suite's own README says its operational Idris2/GitHub adapter is +unpromoted after a duplicate-field false-pass was reproduced, and its required +profile for `hyperpolymath/system-et` is absent. Its documented +`Assurance.Verdict` kernel is a pure decision model; the unverified adapter, +observation admission and completeness are outside the proof. Calling that +workflow or copying its profile would not make this consumer safe. No new +Idris2 gate was invented here because there is no proven operational adapter +that can bind GitHub's real run evidence to the kernel without trusting the +same unverified boundary. +|=== + +== Verification performed locally + +* `bash tests/static-analysis-json.sh` — pass; positive cases and malformed, + missing, unknown-severity, incomplete-coverage, and offline cases. +* `bash tests/check-invisible-characters.sh` — pass; clean and NBSP fixtures, + plus missing-root failure. +* `bash tests/workflow-annotation-escaping.sh` — pass; crafted newline filenames + cannot inject GitHub workflow commands through A2ML/K9 annotations. +* `bash scripts/check-invisible-characters.sh .` — pass; repository clean. +* `bash .githooks/validate-a2ml.sh` — pass (six warnings; see above). +* `bash .githooks/validate-k9.sh` — pass (17 files, zero warnings). +* YAML parsing, Bash syntax and `git diff --check` — pass. + +The workspace has no `rustup`/`cargo` installation, so the two upstream scanner +builds and the end-to-end GitHub Actions run were not executed locally. The +changed gates remain *live-CI pending*, not certified safe, until their pinned +builds, real scan outputs, artifact round-trip and failure controls are +witnessed on the PR head. The Idris2 assurance kernel is intentionally not +represented as evidence for that unverified runtime boundary. diff --git a/scripts/check-invisible-characters.sh b/scripts/check-invisible-characters.sh new file mode 100644 index 0000000..bf55165 --- /dev/null +++ b/scripts/check-invisible-characters.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Check tracked-source/document extensions for invisible control/format characters. +# Exit: 0 = scan completed and clean; 1 = findings or scanner/infrastructure error. +set -euo pipefail +root="${1:-.}" +[[ -d "$root" ]] || { echo "::error::invisible-character scan path is not a directory: $root"; exit 1; } + +patterns='(*UTF)[\x00-\x08\x0B\x0C\x0E-\x1F\x{a0}\x{ad}\x{200b}-\x{200f}\x{202a}-\x{202f}\x{2060}\x{2066}-\x{2069}\x{feff}]' +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +# Capture discovery errors distinctly from grep's normal "no match" exit 1. +find "$root" \ + -not -path '*/.git/*' -not -path '*/node_modules/*' \ + -not -path '*/.deno/*' -not -path '*/target/*' \ + -not -path '*/_build/*' -not -path '*/deps/*' \ + -not -path '*/external_corpora/*' -not -path '*/.lake/*' \ + -type f \( -name '*.rs' -o -name '*.ex' -o -name '*.exs' -o -name '*.res' \ + -o -name '*.js' -o -name '*.ts' -o -name '*.json' -o -name '*.toml' \ + -o -name '*.yml' -o -name '*.yaml' -o -name '*.md' -o -name '*.adoc' \ + -o -name '*.idr' -o -name '*.zig' -o -name '*.v' -o -name '*.jl' \ + -o -name '*.gleam' -o -name '*.hs' -o -name '*.ml' -o -name '*.sh' \) \ + -print0 > "$tmp/candidates" + +: > "$tmp/findings" +while IFS= read -r -d '' file; do + if grep -aPl -- "$patterns" "$file" >/dev/null; then + printf '%s\0' "$file" >> "$tmp/findings" + else + status=$? + if [[ $status -ne 1 ]]; then + echo "::error::invisible-character scanner failed on a candidate file (grep exit $status)" + exit 1 + fi + fi +done < "$tmp/candidates" + +mapfile -d '' -t findings < "$tmp/findings" +if [[ ${#findings[@]} -gt 0 ]]; then + echo "::error::invisible-character scan found ${#findings[@]} file(s) with prohibited characters" + printf ' %s\n' "${findings[@]}" + if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then + { + echo '## Invisible-character scan — blocked' + echo + echo "Found **${#findings[@]}** affected file(s):" + for file in "${findings[@]}"; do printf -- '- `%s`\n' "$file"; done + } >> "$GITHUB_STEP_SUMMARY" + fi + exit 1 +fi + +echo 'invisible-character scan completed: no prohibited characters found' +if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then + printf '%s\n' '## Invisible-character scan' '' 'No prohibited characters found.' >> "$GITHUB_STEP_SUMMARY" +fi diff --git a/scripts/validate-static-analysis-json.sh b/scripts/validate-static-analysis-json.sh new file mode 100644 index 0000000..7d67e14 --- /dev/null +++ b/scripts/validate-static-analysis-json.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Validate scanner output before any severity count can influence a gate. +# Usage: validate-static-analysis-json.sh hypatia|assail|bridge FILE [GITHUB_OUTPUT] +set -euo pipefail + +mode="${1:-}" +file="${2:-}" +output="${3:-${GITHUB_OUTPUT:-}}" + +fail() { + echo "::error::static-analysis output rejected: $*" >&2 + exit 1 +} + +case "$mode" in hypatia|assail|bridge) ;; *) fail "unknown report mode: $mode" ;; esac +[[ -n "$file" && -s "$file" ]] || fail "missing or empty report: ${file:-}" +command -v jq >/dev/null 2>&1 || fail "jq is required; no report was evaluated" +jq -e . "$file" >/dev/null 2>&1 || fail "invalid JSON in $file" +[[ -n "$output" ]] || fail "GITHUB_OUTPUT is not set" + +write_findings_counts() { + local total critical high medium low informational + total="$(jq 'length' "$file")" + critical="$(jq '[.[] | select(.severity == "critical" or .severity == "Critical") ] | length' "$file")" + high="$(jq '[.[] | select(.severity == "high" or .severity == "High") ] | length' "$file")" + medium="$(jq '[.[] | select(.severity == "medium" or .severity == "Medium") ] | length' "$file")" + low="$(jq '[.[] | select(.severity == "low" or .severity == "Low") ] | length' "$file")" + informational="$(jq '[.[] | select(.severity == "info" or .severity == "informational") ] | length' "$file")" + { + printf 'total=%s\n' "$total" + printf 'critical=%s\n' "$critical" + printf 'high=%s\n' "$high" + printf 'medium=%s\n' "$medium" + printf 'low=%s\n' "$low" + printf 'informational=%s\n' "$informational" + } >> "$output" +} + +case "$mode" in + hypatia) + # Hypatia's documented JSON contract is an array of findings. Unknown or + # absent severities are rejected instead of vanishing from a jq select(). + jq -e ' + type == "array" and + all(.[]; + type == "object" and + (.severity | type == "string" and + IN("critical", "high", "medium", "low", "info", "informational")) and + (.file | type == "string") and + ((.reason? // .message? // .type?) | type == "string" and length > 0) + ) + ' "$file" >/dev/null || fail "expected Hypatia array of findings with recognized severity, file, and description" + write_findings_counts + ;; + assail) + # The pinned panic-attack 2.6 report is an AssailReport object, not an array. + # Require the exact schema generation and complete coverage; otherwise a + # tool/schema upgrade or partial scan cannot be mistaken for zero findings. + jq -e ' + type == "object" and .schema_version == "2.6" and + (.coverage | type == "object" and .status == "complete" and + (.candidate_files | type == "number" and . >= 0) and + (.analyzed_files | type == "number" and . >= 0)) and + (.weak_points | type == "array") and + all(.weak_points[]; + type == "object" and + (.severity | type == "string" and IN("Critical", "High", "Medium", "Low")) and + (.description | type == "string" and length > 0) and + ((.file? == null) or (.file | type == "string" and length > 0)) and + ((.location? == null) or (.location | type == "string" and length > 0)) and + ((.suppressed? == null) or (.suppressed | type == "boolean")) + ) + ' "$file" >/dev/null || fail "expected complete panic-attack AssailReport schema 2.6" + # Suppressed findings remain in the report for review but do not contribute + # to scanner blocking counts, per the pinned tool's documented contract. + jq '[.weak_points[] | select(.suppressed != true)]' "$file" > "${file}.active" + file="${file}.active" + write_findings_counts + rm -f "${file}" + ;; + bridge) + # The Patch Bridge contract distinguishes a real no-dependency scan from an + # offline/unknown result. The latter is never a clean report. + if jq -e 'type == "object" and .status == "not_applicable" and (.reason | type == "string" and length > 0)' "$file" >/dev/null; then + printf 'bridge_status=not_applicable\n' >> "$output" + else + jq -e ' + type == "object" and + (.schema_version | type == "string" and length > 0) and + (.vulnerability_data | IN("queried", "no-dependencies")) and + (.cves | type == "array") and + ([.mitigated, .unmitigable, .concatenative, .informational] | + all(.[]; type == "number" and . >= 0 and floor == .)) + ' "$file" >/dev/null || fail "expected online or confirmed no-dependencies Patch Bridge report" + printf 'bridge_status=completed\n' >> "$output" + { + jq -r '"unmitigable=" + (.unmitigable|tostring)' "$file" + jq -r '"mitigated=" + (.mitigated|tostring)' "$file" + jq -r '"concatenative=" + (.concatenative|tostring)' "$file" + jq -r '"informational=" + (.informational|tostring)' "$file" + } >> "$output" + fi + ;; +esac diff --git a/tests/check-invisible-characters.sh b/tests/check-invisible-characters.sh new file mode 100644 index 0000000..7e5f20e --- /dev/null +++ b/tests/check-invisible-characters.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +set -euo pipefail +root="$(cd "$(dirname "$0")/.." && pwd)" +scanner="$root/scripts/check-invisible-characters.sh" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +mkdir -p "$tmp/clean" "$tmp/dirty" +printf 'ordinary text\n' > "$tmp/clean/ok.adoc" +printf 'ordinary source\n' > "$tmp/clean/ok.rs" +bash "$scanner" "$tmp/clean" > "$tmp/clean.log" +grep -Fq 'no prohibited characters' "$tmp/clean.log" + +# NBSP is intentionally a literal U+00A0 character in this fixture. +printf 'a\302\240b\n' > "$tmp/dirty/bad.rs" +if bash "$scanner" "$tmp/dirty" > "$tmp/dirty.log" 2>&1; then + echo 'FAIL: scanner accepted a source file containing NBSP' >&2 + exit 1 +fi +grep -Fq 'found 1 file(s)' "$tmp/dirty.log" +grep -Fq 'bad.rs' "$tmp/dirty.log" + +if bash "$scanner" "$tmp/missing" > "$tmp/missing.log" 2>&1; then + echo 'FAIL: scanner accepted a missing scan root' >&2 + exit 1 +fi +grep -Fq 'not a directory' "$tmp/missing.log" +echo 'invisible-character scanner tests passed' diff --git a/tests/static-analysis-json.sh b/tests/static-analysis-json.sh new file mode 100644 index 0000000..45abdb0 --- /dev/null +++ b/tests/static-analysis-json.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +set -euo pipefail +root="$(cd "$(dirname "$0")/.." && pwd)" +validator="$root/scripts/validate-static-analysis-json.sh" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +pass() { + local mode="$1" input="$2" expected="$3" + : > "$tmp/out" + bash "$validator" "$mode" "$input" "$tmp/out" + grep -Fqx "$expected" "$tmp/out" +} +reject() { + local mode="$1" input="$2" + if bash "$validator" "$mode" "$input" "$tmp/out" >"$tmp/stdout" 2>"$tmp/stderr"; then + echo "FAIL: accepted unsafe $mode report: $input" >&2 + exit 1 + fi + grep -Fq 'output rejected' "$tmp/stderr" +} + +cat > "$tmp/hypatia.json" <<'JSON' +[ + {"severity":"critical","file":"src/a.rs","reason":"unsafe input"}, + {"severity":"high","file":"src/b.rs","type":"tainted source"}, + {"severity":"informational","file":"docs/a.adoc","message":"note"} +] +JSON +pass hypatia "$tmp/hypatia.json" 'critical=1' +grep -Fqx 'total=3' "$tmp/out" +grep -Fqx 'high=1' "$tmp/out" +grep -Fqx 'informational=1' "$tmp/out" + +cat > "$tmp/empty.json" <<'JSON' +[] +JSON +pass hypatia "$tmp/empty.json" 'total=0' + +cat > "$tmp/missing-severity.json" <<'JSON' +[{"file":"src/a.rs","reason":"unknown severity must not vanish"}] +JSON +reject hypatia "$tmp/missing-severity.json" +cat > "$tmp/unknown-severity.json" <<'JSON' +[{"severity":"blocker","file":"src/a.rs","reason":"unrecognized"}] +JSON +reject hypatia "$tmp/unknown-severity.json" +cat > "$tmp/no-location.json" <<'JSON' +[{"severity":"critical","reason":"location missing"}] +JSON +reject hypatia "$tmp/no-location.json" +cat > "$tmp/non-array.json" <<'JSON' +{"severity":"critical"} +JSON +reject hypatia "$tmp/non-array.json" +cat > "$tmp/invalid.json" <<'JSON' +{"truncated": +JSON +reject hypatia "$tmp/invalid.json" + +cat > "$tmp/assail.json" <<'JSON' +{"schema_version":"2.6","coverage":{"status":"complete","candidate_files":10,"analyzed_files":10},"weak_points":[{"severity":"Critical","description":"unsafe path","file":"src/a.rs","suppressed":false},{"severity":"High","description":"suppressed finding","file":"src/b.rs","suppressed":true}]} +JSON +pass assail "$tmp/assail.json" 'critical=1' +grep -Fqx 'total=1' "$tmp/out" + +cat > "$tmp/assail-incomplete.json" <<'JSON' +{"schema_version":"2.6","coverage":{"status":"partial","candidate_files":10,"analyzed_files":1},"weak_points":[]} +JSON +reject assail "$tmp/assail-incomplete.json" +cat > "$tmp/assail-old-schema.json" <<'JSON' +{"schema_version":"2.5","coverage":{"status":"complete","candidate_files":1,"analyzed_files":1},"weak_points":[]} +JSON +reject assail "$tmp/assail-old-schema.json" +cat > "$tmp/assail-unknown-severity.json" <<'JSON' +{"schema_version":"2.6","coverage":{"status":"complete","candidate_files":1,"analyzed_files":1},"weak_points":[{"severity":"Blocker","description":"unknown"}]} +JSON +reject assail "$tmp/assail-unknown-severity.json" + +cat > "$tmp/bridge.json" <<'JSON' +{"schema_version":"0.3.0","vulnerability_data":"queried","cves":[],"mitigated":1,"unmitigable":2,"concatenative":0,"informational":3} +JSON +pass bridge "$tmp/bridge.json" 'unmitigable=2' +grep -Fqx 'bridge_status=completed' "$tmp/out" + +cat > "$tmp/bridge-no-dependencies.json" <<'JSON' +{"schema_version":"0.3.0","vulnerability_data":"no-dependencies","cves":[],"mitigated":0,"unmitigable":0,"concatenative":0,"informational":0} +JSON +pass bridge "$tmp/bridge-no-dependencies.json" 'bridge_status=completed' +cat > "$tmp/bridge-offline.json" <<'JSON' +{"schema_version":"0.3.0","vulnerability_data":"offline-unavailable","cves":[],"mitigated":0,"unmitigable":0,"concatenative":0,"informational":0} +JSON +reject bridge "$tmp/bridge-offline.json" +cat > "$tmp/bridge-missing.json" <<'JSON' +{"schema_version":"0.3.0","vulnerability_data":"Queried","cves":[],"mitigated":1,"unmitigable":0,"concatenative":0} +JSON +reject bridge "$tmp/bridge-missing.json" +cat > "$tmp/bridge-na.json" <<'JSON' +{"status":"not_applicable","reason":"no supported dependency lockfile is present"} +JSON +pass bridge "$tmp/bridge-na.json" 'bridge_status=not_applicable' + +echo 'static-analysis JSON contract tests passed' diff --git a/tests/workflow-annotation-escaping.sh b/tests/workflow-annotation-escaping.sh new file mode 100644 index 0000000..1798568 --- /dev/null +++ b/tests/workflow-annotation-escaping.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Ensure paths controlled by a PR cannot inject additional workflow commands. +set -euo pipefail +root="$(cd "$(dirname "$0")/.." && pwd)" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +for format in a2ml k9.ncl; do + dir="$tmp/$format" + mkdir -p "$dir" + file="$dir/ordinary"$'\n'"::error::forged-command.$format" + printf 'invalid fixture\n' > "$file" + set +e + if [[ "$format" == a2ml ]]; then + INPUT_PATH="$dir" GITHUB_OUTPUT=/dev/null bash "$root/.githooks/validate-a2ml.sh" > "$tmp/$format.log" 2>&1 + else + INPUT_PATH="$dir" GITHUB_OUTPUT=/dev/null bash "$root/.githooks/validate-k9.sh" > "$tmp/$format.log" 2>&1 + fi + status=$? + set -e + [[ $status -ne 0 ]] || { echo "FAIL: invalid $format fixture passed" >&2; exit 1; } + grep -Fq '%0A%3A%3Aerror%3A%3Aforged-command' "$tmp/$format.log" + if grep -Fqx '::error::forged-command' "$tmp/$format.log"; then + echo "FAIL: $format file path injected a workflow command" >&2 + exit 1 + fi +done + +echo 'workflow annotation escaping tests passed' From d199853839ef558bfca00621f0efa3e7b856c3cd Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:41:34 +0000 Subject: [PATCH 2/8] fix(ci): resolve scanner install path conflicts, tighten JSON validation, and escape filenames in scan output --- .github/workflows/dogfood-gate.yml | 2 +- .github/workflows/static-analysis-gate.yml | 39 ++++++++++++++-------- scripts/check-invisible-characters.sh | 5 +-- scripts/validate-static-analysis-json.sh | 17 ++++++---- tests/check-invisible-characters.sh | 15 ++++++++- tests/static-analysis-json.sh | 19 ++++++++++- tests/workflow-annotation-escaping.sh | 2 +- 7 files changed, 73 insertions(+), 26 deletions(-) diff --git a/.github/workflows/dogfood-gate.yml b/.github/workflows/dogfood-gate.yml index f533feb..b978cdc 100644 --- a/.github/workflows/dogfood-gate.yml +++ b/.github/workflows/dogfood-gate.yml @@ -146,7 +146,7 @@ jobs: if [ -f ".well-known/groove/manifest.json" ]; then HAS_MANIFEST="true" # Validate the manifest JSON - if ! jq -e 'type == "object" and (.service_id | type == "string" and length > 0)' .well-known/groove/manifest.json >/dev/null; then + if ! jq -es 'length == 1 and (.[0] | type == "object" and (.service_id | type == "string" and length > 0))' .well-known/groove/manifest.json >/dev/null; then echo "::error file=.well-known/groove/manifest.json::Groove manifest must be a JSON object with a non-empty service_id" exit 1 fi diff --git a/.github/workflows/static-analysis-gate.yml b/.github/workflows/static-analysis-gate.yml index f7a1acf..1911ed6 100644 --- a/.github/workflows/static-analysis-gate.yml +++ b/.github/workflows/static-analysis-gate.yml @@ -35,7 +35,7 @@ jobs: set -euo pipefail command -v rustup >/dev/null 2>&1 || { echo "::error::rustup is required to build pinned panic-attack"; exit 1; } rustup toolchain install 1.90.0 --profile minimal - src="$RUNNER_TEMP/panic-attack" + src="$RUNNER_TEMP/panic-attack-src" git init "$src" git -C "$src" remote add origin https://github.com/hyperpolymath/panic-attack.git git -C "$src" fetch --depth=1 origin "$PANIC_ATTACK_SHA" @@ -43,8 +43,9 @@ jobs: actual="$(git -C "$src" rev-parse HEAD)" [[ "$actual" == "$PANIC_ATTACK_SHA" ]] || { echo "::error::panic-attack source revision mismatch"; exit 1; } cargo +1.90.0 build --locked --release --features http --manifest-path "$src/Cargo.toml" --bin panic-attack - install -m 0755 "$src/target/release/panic-attack" "$RUNNER_TEMP/panic-attack" - echo "$RUNNER_TEMP" >> "$GITHUB_PATH" + mkdir -p "$RUNNER_TEMP/static-analysis-bin" + install -m 0755 "$src/target/release/panic-attack" "$RUNNER_TEMP/static-analysis-bin/panic-attack" + echo "$RUNNER_TEMP/static-analysis-bin" >> "$GITHUB_PATH" - name: Run panic-attack assail id: assail run: | @@ -124,7 +125,7 @@ jobs: HYPATIA_SHA: d158aed87f76b93e4f291e995bef9f26559c7fb2 run: | set -euo pipefail - src="$RUNNER_TEMP/hypatia" + src="$RUNNER_TEMP/hypatia-src" git init "$src" git -C "$src" remote add origin https://github.com/hyperpolymath/hypatia.git git -C "$src" fetch --depth=1 origin "$HYPATIA_SHA" @@ -135,12 +136,13 @@ jobs: cd "$src" mix deps.get --check-locked mix escript.build - install -m 0755 hypatia "$RUNNER_TEMP/hypatia" + mkdir -p "$RUNNER_TEMP/static-analysis-bin" + install -m 0755 hypatia "$RUNNER_TEMP/static-analysis-bin/hypatia" - name: Run Hypatia scan id: scan run: | set -euo pipefail - HYPATIA_FORMAT=json "$RUNNER_TEMP/hypatia" scan . --exit-zero > hypatia-findings.json + HYPATIA_FORMAT=json "$RUNNER_TEMP/static-analysis-bin/hypatia" scan . --exit-zero > hypatia-findings.json # --exit-zero is Hypatia's own documented CI recipe (lib/hypatia/cli.ex), # for exactly this case: "use in CI when a downstream step gates on @@ -211,11 +213,19 @@ jobs: id: applicability run: | set -euo pipefail - if git ls-files | grep -Eq '(^|/)(Cargo\.lock|mix\.lock|package-lock\.json|requirements\.txt)$'; then - echo 'applicable=true' >> "$GITHUB_OUTPUT" - else - echo 'applicable=false' >> "$GITHUB_OUTPUT" + tracked="$(mktemp)" + trap 'rm -f "$tracked"' EXIT + if ! git ls-files -z > "$tracked"; then + echo "::error::failed to list tracked files for Patch Bridge" + exit 1 fi + applicable=false + while IFS= read -r -d '' path; do + case "${path##*/}" in + Cargo.lock|mix.lock|package-lock.json|requirements.txt) applicable=true ;; + esac + done < "$tracked" + printf 'applicable=%s\n' "$applicable" >> "$GITHUB_OUTPUT" - name: Build panic-attack from the pinned source revision if: steps.applicability.outputs.applicable == 'true' env: @@ -224,7 +234,7 @@ jobs: set -euo pipefail command -v rustup >/dev/null 2>&1 || { echo "::error::rustup is required to build pinned panic-attack"; exit 1; } rustup toolchain install 1.90.0 --profile minimal - src="$RUNNER_TEMP/panic-attack" + src="$RUNNER_TEMP/panic-attack-src" git init "$src" git -C "$src" remote add origin https://github.com/hyperpolymath/panic-attack.git git -C "$src" fetch --depth=1 origin "$PANIC_ATTACK_SHA" @@ -232,8 +242,9 @@ jobs: actual="$(git -C "$src" rev-parse HEAD)" [[ "$actual" == "$PANIC_ATTACK_SHA" ]] || { echo "::error::panic-attack source revision mismatch"; exit 1; } cargo +1.90.0 build --locked --release --features http --manifest-path "$src/Cargo.toml" --bin panic-attack - install -m 0755 "$src/target/release/panic-attack" "$RUNNER_TEMP/panic-attack" - echo "$RUNNER_TEMP" >> "$GITHUB_PATH" + mkdir -p "$RUNNER_TEMP/static-analysis-bin" + install -m 0755 "$src/target/release/panic-attack" "$RUNNER_TEMP/static-analysis-bin/panic-attack" + echo "$RUNNER_TEMP/static-analysis-bin" >> "$GITHUB_PATH" - name: Run Patch Bridge triage id: triage if: steps.applicability.outputs.applicable == 'true' @@ -243,7 +254,7 @@ jobs: bash scripts/validate-static-analysis-json.sh bridge bridge-report.json "$GITHUB_OUTPUT" - name: Record Patch Bridge as explicitly not applicable id: not_applicable - if: steps.applicability.outputs.applicable != 'true' + if: steps.applicability.outputs.applicable == 'false' run: | set -euo pipefail printf '%s\n' '{"status":"not_applicable","reason":"no supported dependency lockfile is present"}' > bridge-report.json diff --git a/scripts/check-invisible-characters.sh b/scripts/check-invisible-characters.sh index bf55165..b1c473f 100644 --- a/scripts/check-invisible-characters.sh +++ b/scripts/check-invisible-characters.sh @@ -39,13 +39,14 @@ done < "$tmp/candidates" mapfile -d '' -t findings < "$tmp/findings" if [[ ${#findings[@]} -gt 0 ]]; then echo "::error::invisible-character scan found ${#findings[@]} file(s) with prohibited characters" - printf ' %s\n' "${findings[@]}" + # %q keeps control characters on one line; the fixed prefix keeps paths as data. + printf ' file: %q\n' "${findings[@]}" if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then { echo '## Invisible-character scan — blocked' echo echo "Found **${#findings[@]}** affected file(s):" - for file in "${findings[@]}"; do printf -- '- `%s`\n' "$file"; done + for file in "${findings[@]}"; do printf -- '- `%q`\n' "$file"; done } >> "$GITHUB_STEP_SUMMARY" fi exit 1 diff --git a/scripts/validate-static-analysis-json.sh b/scripts/validate-static-analysis-json.sh index 7d67e14..c91d803 100644 --- a/scripts/validate-static-analysis-json.sh +++ b/scripts/validate-static-analysis-json.sh @@ -16,7 +16,7 @@ fail() { case "$mode" in hypatia|assail|bridge) ;; *) fail "unknown report mode: $mode" ;; esac [[ -n "$file" && -s "$file" ]] || fail "missing or empty report: ${file:-}" command -v jq >/dev/null 2>&1 || fail "jq is required; no report was evaluated" -jq -e . "$file" >/dev/null 2>&1 || fail "invalid JSON in $file" +jq -es 'length == 1' "$file" >/dev/null 2>&1 || fail "invalid JSON in $file" [[ -n "$output" ]] || fail "GITHUB_OUTPUT is not set" write_findings_counts() { @@ -60,8 +60,8 @@ case "$mode" in jq -e ' type == "object" and .schema_version == "2.6" and (.coverage | type == "object" and .status == "complete" and - (.candidate_files | type == "number" and . >= 0) and - (.analyzed_files | type == "number" and . >= 0)) and + (.candidate_files | type == "number" and isfinite and . >= 0 and floor == .) and + (.analyzed_files | type == "number" and isfinite and . > 0 and floor == .)) and (.weak_points | type == "array") and all(.weak_points[]; type == "object" and @@ -86,12 +86,17 @@ case "$mode" in printf 'bridge_status=not_applicable\n' >> "$output" else jq -e ' - type == "object" and - (.schema_version | type == "string" and length > 0) and + def classified($kind): [.cves[] | select(.classification == $kind)] | length; + type == "object" and .schema_version == "0.3.0" and (.vulnerability_data | IN("queried", "no-dependencies")) and (.cves | type == "array") and ([.mitigated, .unmitigable, .concatenative, .informational] | - all(.[]; type == "number" and . >= 0 and floor == .)) + all(.[]; type == "number" and isfinite and . >= 0 and floor == .)) and + all(.cves[]; type == "object" and + (.classification | IN("mitigable", "unmitigable", "informational"))) and + .mitigated == classified("mitigable") and + .unmitigable == classified("unmitigable") and + .informational == classified("informational") ' "$file" >/dev/null || fail "expected online or confirmed no-dependencies Patch Bridge report" printf 'bridge_status=completed\n' >> "$output" { diff --git a/tests/check-invisible-characters.sh b/tests/check-invisible-characters.sh index 7e5f20e..541be32 100644 --- a/tests/check-invisible-characters.sh +++ b/tests/check-invisible-characters.sh @@ -5,7 +5,7 @@ root="$(cd "$(dirname "$0")/.." && pwd)" scanner="$root/scripts/check-invisible-characters.sh" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT -mkdir -p "$tmp/clean" "$tmp/dirty" +mkdir -p "$tmp/clean" "$tmp/dirty" "$tmp/forged" printf 'ordinary text\n' > "$tmp/clean/ok.adoc" printf 'ordinary source\n' > "$tmp/clean/ok.rs" bash "$scanner" "$tmp/clean" > "$tmp/clean.log" @@ -20,6 +20,19 @@ fi grep -Fq 'found 1 file(s)' "$tmp/dirty.log" grep -Fq 'bad.rs' "$tmp/dirty.log" +forged="$tmp/forged/ordinary"$'\n'"::warning::forged-command.rs"$'\n'"::stop-commands::forged.rs" +printf 'a\302\240b\n' > "$forged" +if GITHUB_STEP_SUMMARY="$tmp/summary" bash "$scanner" "$tmp/forged" > "$tmp/forged.log" 2>&1; then + echo 'FAIL: scanner missed the finding in a file with a newline in its name' >&2 + exit 1 +fi +grep -Fq '::warning::forged-command.rs' "$tmp/forged.log" +if [[ "$(grep -E '^[[:space:]]*(::|##\[)' "$tmp/forged.log")" != '::error::invisible-character scan found 1 file(s) with prohibited characters' ]] || + grep -Eq '^[[:space:]]*(::|##\[)' "$tmp/summary"; then + echo 'FAIL: file path injected a workflow command' >&2 + exit 1 +fi + if bash "$scanner" "$tmp/missing" > "$tmp/missing.log" 2>&1; then echo 'FAIL: scanner accepted a missing scan root' >&2 exit 1 diff --git a/tests/static-analysis-json.sh b/tests/static-analysis-json.sh index 45abdb0..56f569b 100644 --- a/tests/static-analysis-json.sh +++ b/tests/static-analysis-json.sh @@ -14,11 +14,13 @@ pass() { } reject() { local mode="$1" input="$2" + : > "$tmp/out" if bash "$validator" "$mode" "$input" "$tmp/out" >"$tmp/stdout" 2>"$tmp/stderr"; then echo "FAIL: accepted unsafe $mode report: $input" >&2 exit 1 fi grep -Fq 'output rejected' "$tmp/stderr" + [[ ! -s "$tmp/out" ]] } cat > "$tmp/hypatia.json" <<'JSON' @@ -38,6 +40,13 @@ cat > "$tmp/empty.json" <<'JSON' JSON pass hypatia "$tmp/empty.json" 'total=0' +printf '[]\n[]\n' > "$tmp/multiple.json" +reject hypatia "$tmp/multiple.json" +grep -Fq 'invalid JSON' "$tmp/stderr" +printf ' \n\t' > "$tmp/whitespace.json" +reject hypatia "$tmp/whitespace.json" +grep -Fq 'invalid JSON' "$tmp/stderr" + cat > "$tmp/missing-severity.json" <<'JSON' [{"file":"src/a.rs","reason":"unknown severity must not vanish"}] JSON @@ -69,6 +78,10 @@ cat > "$tmp/assail-incomplete.json" <<'JSON' {"schema_version":"2.6","coverage":{"status":"partial","candidate_files":10,"analyzed_files":1},"weak_points":[]} JSON reject assail "$tmp/assail-incomplete.json" +for change in '.coverage.candidate_files = 10.5' '.coverage.analyzed_files = 1.5' '.coverage.analyzed_files = 0'; do + jq "$change" "$tmp/assail.json" > "$tmp/assail-invalid-coverage.json" + reject assail "$tmp/assail-invalid-coverage.json" +done cat > "$tmp/assail-old-schema.json" <<'JSON' {"schema_version":"2.5","coverage":{"status":"complete","candidate_files":1,"analyzed_files":1},"weak_points":[]} JSON @@ -79,10 +92,14 @@ JSON reject assail "$tmp/assail-unknown-severity.json" cat > "$tmp/bridge.json" <<'JSON' -{"schema_version":"0.3.0","vulnerability_data":"queried","cves":[],"mitigated":1,"unmitigable":2,"concatenative":0,"informational":3} +{"schema_version":"0.3.0","vulnerability_data":"queried","cves":[{"classification":"mitigable"},{"classification":"unmitigable"},{"classification":"unmitigable"},{"classification":"informational"}],"mitigated":1,"unmitigable":2,"concatenative":0,"informational":1} JSON pass bridge "$tmp/bridge.json" 'unmitigable=2' grep -Fqx 'bridge_status=completed' "$tmp/out" +for change in '.schema_version = "0.4.0"' '.cves = []' '.mitigated = 0' '.unmitigable = 0' '.informational = 0'; do + jq "$change" "$tmp/bridge.json" > "$tmp/bridge-invalid.json" + reject bridge "$tmp/bridge-invalid.json" +done cat > "$tmp/bridge-no-dependencies.json" <<'JSON' {"schema_version":"0.3.0","vulnerability_data":"no-dependencies","cves":[],"mitigated":0,"unmitigable":0,"concatenative":0,"informational":0} diff --git a/tests/workflow-annotation-escaping.sh b/tests/workflow-annotation-escaping.sh index 1798568..0273933 100644 --- a/tests/workflow-annotation-escaping.sh +++ b/tests/workflow-annotation-escaping.sh @@ -21,7 +21,7 @@ for format in a2ml k9.ncl; do set -e [[ $status -ne 0 ]] || { echo "FAIL: invalid $format fixture passed" >&2; exit 1; } grep -Fq '%0A%3A%3Aerror%3A%3Aforged-command' "$tmp/$format.log" - if grep -Fqx '::error::forged-command' "$tmp/$format.log"; then + if grep -Fqx "::error::forged-command.$format" "$tmp/$format.log"; then echo "FAIL: $format file path injected a workflow command" >&2 exit 1 fi From 104c318cb2012f79ba3260d190f831a0ce12292b Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:41:36 +0000 Subject: [PATCH 3/8] fix(pre-commit): use local A2ML and K9 validators and resolve shell lint findings --- .githooks/validate-a2ml.sh | 2 ++ .githooks/validate-k9.sh | 4 +-- .pre-commit-config.yaml | 31 ++++++++++++------------ scripts/check-invisible-characters.sh | 2 +- scripts/validate-static-analysis-json.sh | 6 ++--- tests/check-invisible-characters.sh | 2 +- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.githooks/validate-a2ml.sh b/.githooks/validate-a2ml.sh index d8777de..869fe86 100755 --- a/.githooks/validate-a2ml.sh +++ b/.githooks/validate-a2ml.sh @@ -285,6 +285,8 @@ validate_a2ml() { # --- Check 4: Section heading syntax --- # Validate that [section] headings are well-formed (no unclosed brackets) line_num=0 + # report_issue uses the file path as an annotation label; it writes to stdout. + # shellcheck disable=SC2094 while IFS= read -r line; do line_num=$((line_num + 1)) # Lines starting with [ should have a matching ] diff --git a/.githooks/validate-k9.sh b/.githooks/validate-k9.sh index 6dd3f2b..19f739f 100755 --- a/.githooks/validate-k9.sh +++ b/.githooks/validate-k9.sh @@ -228,13 +228,13 @@ validate_k9() { # closed in one line, never reaching the ^[[:space:]]+ check on # a subsequent iteration.) if [[ "$line" =~ ^[[:space:]]+name[[:space:]]*= ]] || \ - [[ "$line" =~ [[:space:]]name[[:space:]]*= ]]; then + [[ "$line" =~ [[:space:]]name[[:space:]]*= ]]; then has_pedigree_name=true fi # Check for version field if [[ "$line" =~ ^[[:space:]]+(version|schema_version)[[:space:]]*= ]] || \ - [[ "$line" =~ [[:space:]](version|schema_version)[[:space:]]*= ]]; then + [[ "$line" =~ [[:space:]](version|schema_version)[[:space:]]*= ]]; then has_pedigree_version=true fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bf6892f..4988c96 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,20 +18,6 @@ repos: - id: check-added-large-files args: ['--maxkb=1024'] - # --- A2ML manifest validation --- - - repo: https://github.com/hyperpolymath/a2ml-pre-commit - rev: main - hooks: - - id: validate-a2ml - name: Validate A2ML manifests - - # --- K9 contract validation --- - - repo: https://github.com/hyperpolymath/k9-pre-commit - rev: main - hooks: - - id: validate-k9 - name: Validate K9 contracts - # --- Shell linting --- - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.10.0.1 @@ -51,9 +37,24 @@ repos: hooks: - id: gitleaks - # --- Arrival pack drift: CLAUDE.md must stay in sync with a2ml --- - repo: local hooks: + # The Dogfood Gate uses these validators. They discover their own inputs. + - id: validate-a2ml + name: Validate A2ML manifests + entry: bash .githooks/validate-a2ml.sh + language: system + pass_filenames: false + files: '\.a2ml$' + + - id: validate-k9 + name: Validate K9 contracts + entry: bash .githooks/validate-k9.sh + language: system + pass_filenames: false + files: '\.k9(\.ncl)?$' + + # Arrival pack drift: CLAUDE.md must stay in sync with a2ml. - id: validate-claude-md name: CLAUDE.md arrival pack in sync with a2ml entry: bash .machine_readable/arrival-pack/verify.sh diff --git a/scripts/check-invisible-characters.sh b/scripts/check-invisible-characters.sh index b1c473f..2b7215a 100644 --- a/scripts/check-invisible-characters.sh +++ b/scripts/check-invisible-characters.sh @@ -46,7 +46,7 @@ if [[ ${#findings[@]} -gt 0 ]]; then echo '## Invisible-character scan — blocked' echo echo "Found **${#findings[@]}** affected file(s):" - for file in "${findings[@]}"; do printf -- '- `%q`\n' "$file"; done + for file in "${findings[@]}"; do printf -- "- \`%q\`\n" "$file"; done } >> "$GITHUB_STEP_SUMMARY" fi exit 1 diff --git a/scripts/validate-static-analysis-json.sh b/scripts/validate-static-analysis-json.sh index c91d803..36fb141 100644 --- a/scripts/validate-static-analysis-json.sh +++ b/scripts/validate-static-analysis-json.sh @@ -46,7 +46,7 @@ case "$mode" in all(.[]; type == "object" and (.severity | type == "string" and - IN("critical", "high", "medium", "low", "info", "informational")) and + IN("critical", "high", "medium", "low", "info", "informational")) and (.file | type == "string") and ((.reason? // .message? // .type?) | type == "string" and length > 0) ) @@ -60,8 +60,8 @@ case "$mode" in jq -e ' type == "object" and .schema_version == "2.6" and (.coverage | type == "object" and .status == "complete" and - (.candidate_files | type == "number" and isfinite and . >= 0 and floor == .) and - (.analyzed_files | type == "number" and isfinite and . > 0 and floor == .)) and + (.candidate_files | type == "number" and isfinite and . >= 0 and floor == .) and + (.analyzed_files | type == "number" and isfinite and . > 0 and floor == .)) and (.weak_points | type == "array") and all(.weak_points[]; type == "object" and diff --git a/tests/check-invisible-characters.sh b/tests/check-invisible-characters.sh index 541be32..aed83d6 100644 --- a/tests/check-invisible-characters.sh +++ b/tests/check-invisible-characters.sh @@ -28,7 +28,7 @@ if GITHUB_STEP_SUMMARY="$tmp/summary" bash "$scanner" "$tmp/forged" > "$tmp/forg fi grep -Fq '::warning::forged-command.rs' "$tmp/forged.log" if [[ "$(grep -E '^[[:space:]]*(::|##\[)' "$tmp/forged.log")" != '::error::invisible-character scan found 1 file(s) with prohibited characters' ]] || - grep -Eq '^[[:space:]]*(::|##\[)' "$tmp/summary"; then + grep -Eq '^[[:space:]]*(::|##\[)' "$tmp/summary"; then echo 'FAIL: file path injected a workflow command' >&2 exit 1 fi From 584c3663e7e53d94d395145279d17cb397d35f82 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:43:56 +0000 Subject: [PATCH 4/8] fix(pre-commit): run local A2ML and K9 validators and resolve shell lint findings --- .githooks/validate-a2ml.sh | 2 ++ .githooks/validate-k9.sh | 4 ++-- .pre-commit-config.yaml | 18 ++++++++++-------- scripts/check-invisible-characters.sh | 2 +- scripts/validate-static-analysis-json.sh | 6 +++--- tests/check-invisible-characters.sh | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.githooks/validate-a2ml.sh b/.githooks/validate-a2ml.sh index d8777de..128252f 100755 --- a/.githooks/validate-a2ml.sh +++ b/.githooks/validate-a2ml.sh @@ -285,6 +285,8 @@ validate_a2ml() { # --- Check 4: Section heading syntax --- # Validate that [section] headings are well-formed (no unclosed brackets) line_num=0 + # report_issue uses the path as a label and writes only to stdout. + # shellcheck disable=SC2094 while IFS= read -r line; do line_num=$((line_num + 1)) # Lines starting with [ should have a matching ] diff --git a/.githooks/validate-k9.sh b/.githooks/validate-k9.sh index 6dd3f2b..19f739f 100755 --- a/.githooks/validate-k9.sh +++ b/.githooks/validate-k9.sh @@ -228,13 +228,13 @@ validate_k9() { # closed in one line, never reaching the ^[[:space:]]+ check on # a subsequent iteration.) if [[ "$line" =~ ^[[:space:]]+name[[:space:]]*= ]] || \ - [[ "$line" =~ [[:space:]]name[[:space:]]*= ]]; then + [[ "$line" =~ [[:space:]]name[[:space:]]*= ]]; then has_pedigree_name=true fi # Check for version field if [[ "$line" =~ ^[[:space:]]+(version|schema_version)[[:space:]]*= ]] || \ - [[ "$line" =~ [[:space:]](version|schema_version)[[:space:]]*= ]]; then + [[ "$line" =~ [[:space:]](version|schema_version)[[:space:]]*= ]]; then has_pedigree_version=true fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bf6892f..51415e2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,19 +18,21 @@ repos: - id: check-added-large-files args: ['--maxkb=1024'] - # --- A2ML manifest validation --- - - repo: https://github.com/hyperpolymath/a2ml-pre-commit - rev: main + # --- A2ML manifest and K9 contract validation --- + - repo: local hooks: - id: validate-a2ml name: Validate A2ML manifests - - # --- K9 contract validation --- - - repo: https://github.com/hyperpolymath/k9-pre-commit - rev: main - hooks: + entry: bash .githooks/validate-a2ml.sh + language: system + files: '\.a2ml$' + pass_filenames: false - id: validate-k9 name: Validate K9 contracts + entry: bash .githooks/validate-k9.sh + language: system + files: '\.k9(\.ncl)?$' + pass_filenames: false # --- Shell linting --- - repo: https://github.com/shellcheck-py/shellcheck-py diff --git a/scripts/check-invisible-characters.sh b/scripts/check-invisible-characters.sh index b1c473f..6375e97 100644 --- a/scripts/check-invisible-characters.sh +++ b/scripts/check-invisible-characters.sh @@ -46,7 +46,7 @@ if [[ ${#findings[@]} -gt 0 ]]; then echo '## Invisible-character scan — blocked' echo echo "Found **${#findings[@]}** affected file(s):" - for file in "${findings[@]}"; do printf -- '- `%q`\n' "$file"; done + printf -- "- \`%q\`\n" "${findings[@]}" } >> "$GITHUB_STEP_SUMMARY" fi exit 1 diff --git a/scripts/validate-static-analysis-json.sh b/scripts/validate-static-analysis-json.sh index c91d803..36fb141 100644 --- a/scripts/validate-static-analysis-json.sh +++ b/scripts/validate-static-analysis-json.sh @@ -46,7 +46,7 @@ case "$mode" in all(.[]; type == "object" and (.severity | type == "string" and - IN("critical", "high", "medium", "low", "info", "informational")) and + IN("critical", "high", "medium", "low", "info", "informational")) and (.file | type == "string") and ((.reason? // .message? // .type?) | type == "string" and length > 0) ) @@ -60,8 +60,8 @@ case "$mode" in jq -e ' type == "object" and .schema_version == "2.6" and (.coverage | type == "object" and .status == "complete" and - (.candidate_files | type == "number" and isfinite and . >= 0 and floor == .) and - (.analyzed_files | type == "number" and isfinite and . > 0 and floor == .)) and + (.candidate_files | type == "number" and isfinite and . >= 0 and floor == .) and + (.analyzed_files | type == "number" and isfinite and . > 0 and floor == .)) and (.weak_points | type == "array") and all(.weak_points[]; type == "object" and diff --git a/tests/check-invisible-characters.sh b/tests/check-invisible-characters.sh index 541be32..aed83d6 100644 --- a/tests/check-invisible-characters.sh +++ b/tests/check-invisible-characters.sh @@ -28,7 +28,7 @@ if GITHUB_STEP_SUMMARY="$tmp/summary" bash "$scanner" "$tmp/forged" > "$tmp/forg fi grep -Fq '::warning::forged-command.rs' "$tmp/forged.log" if [[ "$(grep -E '^[[:space:]]*(::|##\[)' "$tmp/forged.log")" != '::error::invisible-character scan found 1 file(s) with prohibited characters' ]] || - grep -Eq '^[[:space:]]*(::|##\[)' "$tmp/summary"; then + grep -Eq '^[[:space:]]*(::|##\[)' "$tmp/summary"; then echo 'FAIL: file path injected a workflow command' >&2 exit 1 fi From 33ab0d97e65098dbbe81294551ab174a51c8f273 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:42:30 +0000 Subject: [PATCH 5/8] ci(pre-commit): use local A2ML and K9 validators and clean up shell lint findings --- .pre-commit-config.yaml | 4 ++-- scripts/check-invisible-characters.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4988c96..db6937c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -45,14 +45,14 @@ repos: entry: bash .githooks/validate-a2ml.sh language: system pass_filenames: false - files: '\.a2ml$' + files: '(\.a2ml$|^\.githooks/validate-a2ml\.sh$)' - id: validate-k9 name: Validate K9 contracts entry: bash .githooks/validate-k9.sh language: system pass_filenames: false - files: '\.k9(\.ncl)?$' + files: '(\.k9(\.ncl)?$|^\.githooks/validate-k9\.sh$)' # Arrival pack drift: CLAUDE.md must stay in sync with a2ml. - id: validate-claude-md diff --git a/scripts/check-invisible-characters.sh b/scripts/check-invisible-characters.sh index 2b7215a..6375e97 100644 --- a/scripts/check-invisible-characters.sh +++ b/scripts/check-invisible-characters.sh @@ -46,7 +46,7 @@ if [[ ${#findings[@]} -gt 0 ]]; then echo '## Invisible-character scan — blocked' echo echo "Found **${#findings[@]}** affected file(s):" - for file in "${findings[@]}"; do printf -- "- \`%q\`\n" "$file"; done + printf -- "- \`%q\`\n" "${findings[@]}" } >> "$GITHUB_STEP_SUMMARY" fi exit 1 From 802968009078d8f99efa31d3519f33894a0caa5e Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:29:18 +0000 Subject: [PATCH 6/8] fix(ci): parse K9 pedigree fields outside comments and escape legacy workflow commands in filenames --- .githooks/validate-k9.sh | 109 ++++++++++---------------- .github/workflows/quality.yml | 2 + scripts/check-invisible-characters.sh | 12 ++- tests/check-invisible-characters.sh | 9 ++- tests/validate-k9.sh | 36 +++++++++ 5 files changed, 94 insertions(+), 74 deletions(-) create mode 100644 tests/validate-k9.sh diff --git a/.githooks/validate-k9.sh b/.githooks/validate-k9.sh index 19f739f..99a392b 100755 --- a/.githooks/validate-k9.sh +++ b/.githooks/validate-k9.sh @@ -116,13 +116,9 @@ normalise_level() { raw="${raw#*=}" # Remove everything before = raw="${raw//\"/}" # Remove double quotes raw="${raw//\'/}" # Remove single quotes (Nickel tick) - raw="${raw//,/}" # Remove trailing commas - raw="${raw## }" # Trim leading space - raw="${raw%% }" # Trim trailing space - raw="${raw%%#*}" # Remove inline comments - raw="${raw## }" # Trim again - raw="${raw%% }" - echo "${raw,,}" # Lowercase + raw="${raw#"${raw%%[![:space:]]*}"}" # Trim leading whitespace + raw="${raw%"${raw##*[![:space:]]}"}" # Trim trailing whitespace + echo "${raw,,}" # Lowercase } # --------------------------------------------------------------------------- @@ -183,77 +179,54 @@ validate_k9() { local in_pedigree=false local pedigree_depth=0 + # Split each line at record delimiters outside quoted strings. A comment + # ends the line, so its contents cannot count as assignments or braces. + local segment_re='^(([^"#,{}]|"([^"\\]|\\.)*")*)([#{},]|$)' + local field_re='^[[:space:]]*(name|version|schema_version|leash|security_level|signature|signature_required)[[:space:]]*=(.*)$' + local remaining segment delimiter + line_num=0 - while IFS= read -r line; do + while IFS= read -r line || [[ -n "$line" ]]; do line_num=$((line_num + 1)) - # Detect pedigree block start. Note: do NOT `continue` here — the - # `pedigree = {` line itself contains the opening brace that - # establishes the block. Falling through to the brace counter - # below makes depth start at 1, so a subsequent `security = {…},` - # closing brace correctly takes depth to 1 (not 0), keeping us - # inside the pedigree block when later fields (name/version/leash) - # are checked. Previously the `continue` skipped this opening - # brace, depth started at 0, and the first nested block's close - # prematurely terminated the validator's view of the pedigree — - # making `pedigree.metadata.name` invisible. if [[ "$line" =~ ^[[:space:]]*pedigree[[:space:]]*= ]]; then has_pedigree=true in_pedigree=true pedigree_depth=0 - # fall through fi if [[ "$in_pedigree" == "true" ]]; then - # Track brace depth to know when pedigree block ends - local opens closes - opens="${line//[^\{]/}" - closes="${line//[^\}]/}" - pedigree_depth=$(( pedigree_depth + ${#opens} - ${#closes} )) - - if [[ $pedigree_depth -le 0 && "$has_pedigree" == "true" ]]; then - # Check this final line too before leaving - : - fi - - # Check for name field within pedigree.metadata or pedigree directly. - # Two patterns cover both multi-line and single-line pedigrees: - # 1. ^[[:space:]]+name[[:space:]]*= — the normal multi-line case where - # `name = "..."` appears on its own indented line. - # 2. [[:space:]]name[[:space:]]*= — inline within a single-line - # pedigree assignment such as: - # pedigree = component_pedigree & { name = "foo" } - # (root cause: developer-ecosystem@baab1534 — single-line form - # was missed entirely because the pedigree block opened and - # closed in one line, never reaching the ^[[:space:]]+ check on - # a subsequent iteration.) - if [[ "$line" =~ ^[[:space:]]+name[[:space:]]*= ]] || \ - [[ "$line" =~ [[:space:]]name[[:space:]]*= ]]; then - has_pedigree_name=true - fi - - # Check for version field - if [[ "$line" =~ ^[[:space:]]+(version|schema_version)[[:space:]]*= ]] || \ - [[ "$line" =~ [[:space:]](version|schema_version)[[:space:]]*= ]]; then - has_pedigree_version=true - fi - - # Check for security level (leash field) - if [[ "$line" =~ ^[[:space:]]+(leash|security_level)[[:space:]]*= ]]; then - has_security_level=true - security_level_value="$(normalise_level "$line")" - security_level_line=$line_num - fi - - # Check for signature fields - if [[ "$line" =~ ^[[:space:]]+(signature|signature_required)[[:space:]]*= ]]; then - has_signature_field=true - fi - - # End of pedigree block - if [[ $pedigree_depth -le 0 && "$has_pedigree" == "true" && "$line" == *"}"* ]]; then - in_pedigree=false - fi + remaining="$line" + while [[ -n "$remaining" && "$remaining" =~ $segment_re ]]; do + segment="${BASH_REMATCH[1]}" + delimiter="${BASH_REMATCH[4]}" + remaining="${remaining:"${#BASH_REMATCH[0]}"}" + + if [[ "$segment" =~ $field_re ]]; then + case "${BASH_REMATCH[1]}" in + name) has_pedigree_name=true ;; + version|schema_version) has_pedigree_version=true ;; + leash|security_level) + has_security_level=true + security_level_value="$(normalise_level "$segment")" + security_level_line=$line_num + ;; + signature|signature_required) has_signature_field=true ;; + esac + fi + + case "$delimiter" in + '{') pedigree_depth=$((pedigree_depth + 1)) ;; + '}') + pedigree_depth=$((pedigree_depth - 1)) + if [[ $pedigree_depth -le 0 ]]; then + in_pedigree=false + break + fi + ;; + '#'|'') break ;; + esac + done fi # Also check for signature fields outside pedigree (top-level) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index f637014..435afd0 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -43,6 +43,8 @@ jobs: run: bash tests/static-analysis-json.sh - name: Invisible-character scanner controls run: bash tests/check-invisible-characters.sh + - name: K9 pedigree validation controls + run: bash tests/validate-k9.sh - name: Workflow annotation escaping controls run: bash tests/workflow-annotation-escaping.sh docs: diff --git a/scripts/check-invisible-characters.sh b/scripts/check-invisible-characters.sh index 6375e97..48e042d 100644 --- a/scripts/check-invisible-characters.sh +++ b/scripts/check-invisible-characters.sh @@ -39,14 +39,20 @@ done < "$tmp/candidates" mapfile -d '' -t findings < "$tmp/findings" if [[ ${#findings[@]} -gt 0 ]]; then echo "::error::invisible-character scan found ${#findings[@]} file(s) with prohibited characters" - # %q keeps control characters on one line; the fixed prefix keeps paths as data. - printf ' file: %q\n' "${findings[@]}" + # The runner searches anywhere on the line for the legacy prefix. + # Encode it before using %q to keep control characters on one line. + rendered=() + for file in "${findings[@]}"; do + printf -v path '%q' "${file//"##["/"%23%23%5B"}" + rendered+=("$path") + done + printf ' file: %s\n' "${rendered[@]}" if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then { echo '## Invisible-character scan — blocked' echo echo "Found **${#findings[@]}** affected file(s):" - printf -- "- \`%q\`\n" "${findings[@]}" + printf -- "- \`%s\`\n" "${rendered[@]}" } >> "$GITHUB_STEP_SUMMARY" fi exit 1 diff --git a/tests/check-invisible-characters.sh b/tests/check-invisible-characters.sh index aed83d6..1e1d3c7 100644 --- a/tests/check-invisible-characters.sh +++ b/tests/check-invisible-characters.sh @@ -20,15 +20,18 @@ fi grep -Fq 'found 1 file(s)' "$tmp/dirty.log" grep -Fq 'bad.rs' "$tmp/dirty.log" -forged="$tmp/forged/ordinary"$'\n'"::warning::forged-command.rs"$'\n'"::stop-commands::forged.rs" +forged="$tmp/forged/ordinary"$'\n'"::warning::forged-command.rs"$'\n'"::stop-commands::forged"$'\n'"##[warning]legacy.rs" printf 'a\302\240b\n' > "$forged" if GITHUB_STEP_SUMMARY="$tmp/summary" bash "$scanner" "$tmp/forged" > "$tmp/forged.log" 2>&1; then echo 'FAIL: scanner missed the finding in a file with a newline in its name' >&2 exit 1 fi grep -Fq '::warning::forged-command.rs' "$tmp/forged.log" -if [[ "$(grep -E '^[[:space:]]*(::|##\[)' "$tmp/forged.log")" != '::error::invisible-character scan found 1 file(s) with prohibited characters' ]] || - grep -Eq '^[[:space:]]*(::|##\[)' "$tmp/summary"; then +grep -Eq '^ file: .*legacy\.rs' "$tmp/forged.log" +if [[ "$(wc -l < "$tmp/forged.log")" -ne 2 || + "$(grep -E '^[[:space:]]*::' "$tmp/forged.log")" != '::error::invisible-character scan found 1 file(s) with prohibited characters' ]] || + grep -Eq '^[[:space:]]*::' "$tmp/summary" || + grep -Fq '##[' "$tmp/forged.log" "$tmp/summary"; then echo 'FAIL: file path injected a workflow command' >&2 exit 1 fi diff --git a/tests/validate-k9.sh b/tests/validate-k9.sh new file mode 100644 index 0000000..ab5baa1 --- /dev/null +++ b/tests/validate-k9.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +set -euo pipefail +root="$(cd "$(dirname "$0")/.." && pwd)" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +mkdir "$tmp/input" + +check_pedigree() { + local expected="$1" message="$2" status=0 + shift 2 + printf 'K9!\n# SPDX-License-Identifier: MPL-2.0\n%s' "$*" > "$tmp/input/fixture.k9.ncl" + INPUT_STRICT=true INPUT_PATH="$tmp/input" INPUT_PATHS_IGNORE= GITHUB_OUTPUT=/dev/null \ + bash "$root/.githooks/validate-k9.sh" > "$tmp/result" || status=$? + if [[ "$status" != "$expected" ]] || ! grep -Fq "$message" "$tmp/result"; then + cat "$tmp/result" >&2 + return 1 + fi +} + +check_pedigree 0 'K9 validation passed' \ + "pedigree = component_pedigree & { name = \"test, # example\", schema_version = \"1\", leash = 'YaRd }" +check_pedigree 0 'K9 validation passed' \ + 'pedigree = { name = "test", version = "1", leash = "Hunt", signature_required = true }' +check_pedigree 1 'Hunt-level K9 file must include' \ + 'pedigree = { name = "test", version = "1", leash = "Hunt" } # signature = "absent"' +check_pedigree 1 "Invalid security level 'unknown'" \ + 'pedigree = { name = "test", version = "1", leash = "Unknown" }' +check_pedigree 1 "missing 'name' field" \ + $'pedigree = {\n # name = "comment"\n version = "1",\n leash = "Kennel",\n}' +check_pedigree 1 "missing 'version' or 'schema_version'" \ + $'pedigree = {\n name = "test", # version = "comment"\n leash = "Kennel",\n}' +check_pedigree 0 'K9 validation passed' \ + $'pedigree = {\n security = {\n leash = "Kennel",\n }, # }\n metadata = {\n name = "test",\n version = "1",\n },\n}' + +echo 'K9 pedigree validation tests passed' From 464afdc363c7797fa8d0d38c133c94303e1e8968 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:32:01 +0000 Subject: [PATCH 7/8] Fix Stapeln TOML validation and repository lint failures (#110) - Make the Stapeln compose template and example parseable TOML. Replace the generic TOML check for the Stapeln manifest with a pre-commit hook that substitutes a sample numeric port and checks that `listen_tcp` contains integers. - Make the devcontainer config strict JSON and move its SPDX metadata to a license sidecar. Add EditorConfig exceptions for files that use custom alignment and trim whitespace in documentation, licenses, manifests, and an Agda proof. - Restore shell line continuations in the maintenance script, preserve multiline proof and template diagnostics, quote the template test's line count, and make the empty K9 ignore value explicit. Remove unused benchmark timing setup and color variables, and annotate the direnv and E2E scripts for ShellCheck. - Refresh the generated `CLAUDE.md` DEED provenance hash. Validation: `git diff --check` passed on the pinned diff. Pre-commit hooks and tests were not run. [View coding task](https://app.coderabbit.ai/code/tasks/21d10894-48ae-5a68-a9db-7ec88215b64b?source=coding_agent_github_pr_description) Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .devcontainer/devcontainer.json | 6 --- .devcontainer/devcontainer.json.license | 2 + .editorconfig | 22 +++++++++++ .envrc | 1 + .githooks/validate-stapeln-manifest.py | 15 ++++++++ .github/CODE_OF_CONDUCT.md | 2 +- .../descriptiles/0-AI-MANIFEST.a2ml | 1 - .machine_readable/descriptiles/README.adoc | 1 - .../descriptiles/anchors/0-AI-MANIFEST.a2ml | 1 - .../descriptiles/anchors/README.adoc | 1 - .../scripts/maintenance/maint-assault.sh | 8 ++-- .pre-commit-config.yaml | 10 +++++ CLAUDE.md | 4 +- LICENSE | 2 +- LICENSES/CC-BY-SA-4.0.txt | 1 - benches/template_bench.sh | 9 ----- container/stapeln/compose.example.toml | 38 ++++++++----------- container/stapeln/compose.toml | 34 +++++++---------- scripts/check-proofs.sh | 4 +- tests/e2e.sh | 4 ++ tests/e2e/template_instantiation_test.sh | 5 +-- tests/validate-k9.sh | 2 +- verification/coverage/0.2-AI-MANIFEST.a2ml | 2 +- .../proofs/agda/Wager/L2/UsageLaws.agda | 1 - verification/safety_case/0.2-AI-MANIFEST.a2ml | 2 +- .../traceability/0.2-AI-MANIFEST.a2ml | 2 +- 26 files changed, 100 insertions(+), 80 deletions(-) create mode 100644 .devcontainer/devcontainer.json.license create mode 100644 .githooks/validate-stapeln-manifest.py diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5268c1c..bba51df 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,9 +1,3 @@ -// SPDX-License-Identifier: MPL-2.0 -// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) -// -// Dev Container configuration for systemet -// Works with: VS Code Dev Containers, GitHub Codespaces, Gitpod -// Container runtime: Podman (recommended) or any OCI-compliant runtime { "name": "systemet", diff --git a/.devcontainer/devcontainer.json.license b/.devcontainer/devcontainer.json.license new file mode 100644 index 0000000..296665a --- /dev/null +++ b/.devcontainer/devcontainer.json.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell (hyperpolymath) +SPDX-License-Identifier: MPL-2.0 diff --git a/.editorconfig b/.editorconfig index a466807..ff8de6c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -69,3 +69,25 @@ indent_size = 2 indent_style = space indent_size = 4 +# Prose, legal text and proofs use alignment within paragraphs and expressions. +[*.{md,adoc,agda,lean}] +indent_size = unset + +[LICENSES/CC-BY-SA-4.0.txt] +indent_size = unset + +[docs/legal/EXHIBIT-{A-ETHICAL-USE,B-QUANTUM-SAFE}.txt] +indent_size = unset + +# Embedded shell/JQ and aligned template data use a different indent width. +[{Justfile,.machine_readable/contractiles/Justfile,.github/scripts/classify-issue.jq}] +indent_size = unset + +[.github/workflows/{label-triage,labels,openssf-compliance,secret-scanner}.yml] +indent_size = unset + +[{scripts/scan-dangerous.sh,scripts/validate-template.sh,tests/e2e/template_instantiation_test.sh}] +indent_size = unset + +[{.machine_readable/contractiles/trust/Trustfile.a2ml,machine-readable-design/canonical-directory-structure/Trustfile.a2ml,.machine_readable/contractiles/intend/intend.k9.ncl,systemet_chora.deed,verification/proofs/lean4/lake-manifest.json}] +indent_size = unset diff --git a/.envrc b/.envrc index aef1a86..72c9bb4 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,5 @@ # SPDX-License-Identifier: MPL-2.0 +# shellcheck shell=bash # Activate development environment # Install direnv: https://direnv.net/ diff --git a/.githooks/validate-stapeln-manifest.py b/.githooks/validate-stapeln-manifest.py new file mode 100644 index 0000000..fbab4b7 --- /dev/null +++ b/.githooks/validate-stapeln-manifest.py @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: MPL-2.0 +"""Validate the Cerro Torre manifest using a sample numeric template port.""" + +import sys +import tomllib +from pathlib import Path + +path = Path(sys.argv[1]) +try: + manifest = tomllib.loads(path.read_text(encoding="utf-8").replace("{{PORT}}", "8080")) + ports = manifest["security"]["network"]["listen_tcp"] + if not isinstance(ports, list) or any(type(port) is not int for port in ports): + raise ValueError("security.network.listen_tcp must be an array of integers") +except (OSError, KeyError, ValueError) as exc: + sys.exit(f"{path}: {exc}") diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 83a1028..832dd2d 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -4,7 +4,7 @@ Copyright (c) Jonathan D.A. Jewell --> # Code of Conduct - - + # You are in the hyperpolymath estate — orient before acting @@ -67,4 +67,4 @@ Deny: **Nix, TypeScript, Python, Go, AGPL**. JS runtimes in preference order **B - **Golden path** (ANCHOR) — `just test && just quality` → Core tests pass; Quality gates pass; No unresolved critical security findings. - **State** — lifecycle active; maturity experimental. Phase, blockers and next action: `docs/status/JOURNAL.adoc`. - + diff --git a/LICENSE b/LICENSE index 14e2f77..a612ad9 100644 --- a/LICENSE +++ b/LICENSE @@ -35,7 +35,7 @@ Mozilla Public License Version 2.0 means any form of the work other than Source Code Form. 1.7. "Larger Work" - means a work that combines Covered Software with other material, in + means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. 1.8. "License" diff --git a/LICENSES/CC-BY-SA-4.0.txt b/LICENSES/CC-BY-SA-4.0.txt index 2d58298..7d4f96c 100644 --- a/LICENSES/CC-BY-SA-4.0.txt +++ b/LICENSES/CC-BY-SA-4.0.txt @@ -425,4 +425,3 @@ the avoidance of doubt, this paragraph does not form part of the public licenses. Creative Commons may be contacted at creativecommons.org. - diff --git a/benches/template_bench.sh b/benches/template_bench.sh index 5fb58a8..35f5693 100755 --- a/benches/template_bench.sh +++ b/benches/template_bench.sh @@ -13,7 +13,6 @@ OUTPUT_FORMAT="${2:-human}" # human | json | csv # ANSI colors BLUE='\033[0;34m' GREEN='\033[0;32m' -YELLOW='\033[1;33m' NC='\033[0m' # No Color log_info() { @@ -24,14 +23,6 @@ log_pass() { echo -e "${GREEN}✓${NC} $*" } -# Ensure we have required commands -command -v /usr/bin/time >/dev/null 2>&1 || { - echo "Warning: /usr/bin/time not available, using built-in time" - TIME_CMD="time" -} - -TIME_CMD="/usr/bin/time -f %e" 2>/dev/null || TIME_CMD="time" - echo "" echo "═══════════════════════════════════════════════════════════════════════════════" echo "Template Benchmarks" diff --git a/container/stapeln/compose.example.toml b/container/stapeln/compose.example.toml index d8d717c..81ad7ea 100644 --- a/container/stapeln/compose.example.toml +++ b/container/stapeln/compose.example.toml @@ -28,13 +28,11 @@ ports = ["8080:8080"] # Environment variables passed into the container at startup. # These override defaults in the Containerfile ENV directives. -environment = { - RUST_LOG = "info", # Rust log level (trace, debug, info, warn, error) - APP_HOST = "[::]", # Listen on all interfaces (IPv4 + IPv6) - APP_PORT = "8080", # Internal container port - APP_LOG_FORMAT = "json", # Structured logging for selur/vordr - APP_DATA_DIR = "/data", # Persistent data directory (matches VOLUME) -} +environment.RUST_LOG = "info" # Rust log level (trace, debug, info, warn, error) +environment.APP_HOST = "[::]" # Listen on all interfaces (IPv4 + IPv6) +environment.APP_PORT = "8080" # Internal container port +environment.APP_LOG_FORMAT = "json" # Structured logging for selur/vordr +environment.APP_DATA_DIR = "/data" # Persistent data directory (matches VOLUME) # Bind-mount a named volume for persistent data. # Format: "volume-name:/container/path" @@ -60,12 +58,10 @@ ports = ["4000:4000"] # The worker connects to the Rust API over the internal selur network. # Service names resolve as hostnames within the compose network. -environment = { - API_URL = "http://rust-api:8080/api/v1", # Internal service discovery - MIX_ENV = "prod", # Elixir release mode - APP_LOG_FORMAT = "json", # Match structured logging format - POOL_SIZE = "10", # DB connection pool size -} +environment.API_URL = "http://rust-api:8080/api/v1" # Internal service discovery +environment.MIX_ENV = "prod" # Elixir release mode +environment.APP_LOG_FORMAT = "json" # Match structured logging format +environment.POOL_SIZE = "10" # DB connection pool size # depends_on ensures the Rust API starts before the worker. # Note: This only waits for the container to start, not for the health check. @@ -90,17 +86,15 @@ image = "ghcr.io/hyperpolymath/svalinn:latest.ctp" # External-facing ports: HTTPS (443) and HTTP->HTTPS redirect (80). ports = ["443:443", "80:80"] -environment = { - # Backend routing: svalinn proxies to internal services. - SVALINN_BACKEND = "http://rust-api:8080", - SVALINN_WORKER_BACKEND = "http://elixir-worker:4000", +# Backend routing: svalinn proxies to internal services. +environment.SVALINN_BACKEND = "http://rust-api:8080" +environment.SVALINN_WORKER_BACKEND = "http://elixir-worker:4000" - # Policy file: mounted from the svalinn-config volume. - SVALINN_POLICY_FILE = "/etc/svalinn/gatekeeper.yaml", +# Policy file: mounted from the svalinn-config volume. +environment.SVALINN_POLICY_FILE = "/etc/svalinn/gatekeeper.yaml" - # Auto-provision TLS certificates (Let's Encrypt). - SVALINN_TLS_AUTO = "true", -} +# Auto-provision TLS certificates (Let's Encrypt). +environment.SVALINN_TLS_AUTO = "true" # Mount .gatekeeper.yaml as read-only policy configuration. volumes = ["svalinn-config:/etc/svalinn:ro"] diff --git a/container/stapeln/compose.toml b/container/stapeln/compose.toml index 6c33ce4..bd5e97a 100644 --- a/container/stapeln/compose.toml +++ b/container/stapeln/compose.toml @@ -25,15 +25,13 @@ version = "1.0" # ============================================================================ # Primary application service -[services.{{SERVICE_NAME}}] +[services."{{SERVICE_NAME}}"] image = "{{REGISTRY}}/{{SERVICE_NAME}}:latest.ctp" ports = ["{{PORT}}:{{PORT}}"] -environment = { - APP_HOST = "[::]", - APP_PORT = "{{PORT}}", - APP_LOG_FORMAT = "json", - APP_DATA_DIR = "/data", -} +environment.APP_HOST = "[::]" +environment.APP_PORT = "{{PORT}}" +environment.APP_LOG_FORMAT = "json" +environment.APP_DATA_DIR = "/data" volumes = ["{{SERVICE_NAME}}-data:/data"] restart = "always" healthcheck = { test = "curl -sf http://localhost:{{PORT}}/health", interval = "30s", timeout = "5s", retries = 3 } @@ -44,13 +42,11 @@ healthcheck = { test = "curl -sf http://localhost:{{PORT}}/health", interval = " [services.rokur] image = "ghcr.io/hyperpolymath/rokur:latest.ctp" ports = ["8081:8081"] -environment = { - ROKUR_BACKEND = "http://{{SERVICE_NAME}}:{{PORT}}", - ROKUR_LISTEN = "[::]:8081", - ROKUR_REQUIRED_SECRETS = "", - ROKUR_AUDIT_LOG = "/var/log/rokur/audit.jsonl", - ROKUR_LOG_FORMAT = "json", -} +environment.ROKUR_BACKEND = "http://{{SERVICE_NAME}}:{{PORT}}" +environment.ROKUR_LISTEN = "[::]:8081" +environment.ROKUR_REQUIRED_SECRETS = "" +environment.ROKUR_AUDIT_LOG = "/var/log/rokur/audit.jsonl" +environment.ROKUR_LOG_FORMAT = "json" volumes = ["rokur-audit:/var/log/rokur"] depends_on = ["{{SERVICE_NAME}}"] restart = "always" @@ -61,11 +57,9 @@ healthcheck = { test = "curl -sf http://localhost:8081/health", interval = "30s" [services.svalinn] image = "ghcr.io/hyperpolymath/svalinn:latest.ctp" ports = ["443:443", "80:80"] -environment = { - SVALINN_BACKEND = "http://rokur:8081", - SVALINN_POLICY_FILE = "/etc/svalinn/gatekeeper.yaml", - SVALINN_TLS_AUTO = "true", -} +environment.SVALINN_BACKEND = "http://rokur:8081" +environment.SVALINN_POLICY_FILE = "/etc/svalinn/gatekeeper.yaml" +environment.SVALINN_TLS_AUTO = "true" volumes = ["svalinn-config:/etc/svalinn:ro"] depends_on = ["rokur"] restart = "always" @@ -75,7 +69,7 @@ healthcheck = { test = "curl -sf http://localhost:80/health", interval = "30s", # Volumes # ============================================================================ -[volumes.{{SERVICE_NAME}}-data] +[volumes."{{SERVICE_NAME}}-data"] driver = "local" [volumes.rokur-audit] diff --git a/scripts/check-proofs.sh b/scripts/check-proofs.sh index 31a8539..a70b050 100755 --- a/scripts/check-proofs.sh +++ b/scripts/check-proofs.sh @@ -173,13 +173,13 @@ missing="$(comm -23 <(printf '%s\n' "$listed") <(printf '%s\n' "$found") || true if [ -n "${unlisted//[[:space:]]/}" ]; then echo "FAIL: .$EXT proofs on disk but absent from $MANIFEST_FILE:" - printf ' %s\n' $unlisted + printf ' %s\n' "${unlisted//$'\n'/$'\n '}" echo " List each as 'gated' or 'quarantine'; new proofs are gated by default." fails=$((fails + 1)) fi if [ -n "${missing//[[:space:]]/}" ]; then echo "FAIL: MANIFEST lists modules that do not exist (stale entries):" - printf ' %s\n' $missing + printf ' %s\n' "${missing//$'\n'/$'\n '}" fails=$((fails + 1)) fi [ -z "${unlisted//[[:space:]]/}${missing//[[:space:]]/}" ] && \ diff --git a/tests/e2e.sh b/tests/e2e.sh index 11143fc..08762bd 100755 --- a/tests/e2e.sh +++ b/tests/e2e.sh @@ -17,6 +17,7 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck disable=SC2034 # Used by the example preflight below. PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" PASS=0 @@ -32,6 +33,7 @@ bold() { printf '\033[1m%s\033[0m\n' "$*"; } # ─── Assertion helpers ─────────────────────────────────────────────── # check