From 9887c146a3bcc6f6ba80bcb5f91484223d8af3ff Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 2 Nov 2026 18:43:23 +0100 Subject: [PATCH] test(push-guard): T62 rtk read twins census, T63 phase 2 rule lock (red until settings land) --- lib/tests/push-guard.test.sh | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/lib/tests/push-guard.test.sh b/lib/tests/push-guard.test.sh index d5ffa29..db91b24 100644 --- a/lib/tests/push-guard.test.sh +++ b/lib/tests/push-guard.test.sh @@ -365,4 +365,61 @@ check T46b-auto-silent "$(grep -c 'push : manual' <<<"$out")" 0 out=$(banner "$WORK/bad") check T57-banner-invalid "$(grep -c 'push : manual (autopush bad)' <<<"$out")" 1 +# T62 rtk read twins: rtk rewrites cat/head/tail to `rtk read [flags]` +# (rc 0), so every Bash(cat|head|tail X) deny (X without a space) needs +# Bash(rtk read X*) and the absolute Bash(*/rtk read X*). X keeps one *. +twins_missing() { # twins_missing -> missing twin rules + local x t w + jq -r '.permissions.deny[]' "$1" \ + | sed -nE 's/^Bash\((cat|head|tail) ([^ ]*)\)$/\2/p' | sort -u \ + | while IFS= read -r x; do + t="rtk read ${x%\*}*" + for w in "Bash($t)" "Bash(*/$t)"; do + jq -e --arg w "$w" '.permissions.deny | index($w)' "$1" \ + >/dev/null || echo "$w" + done + done +} +check T62-twins-present "$(twins_missing "$S")" "" +T62F="$(mktemp)" +jq '.permissions.deny += ["Bash(cat */ghost.key)"]' "$S" > "$T62F" +check T62b-flip-missing-twin "$(twins_missing "$T62F" | /usr/bin/grep -F ghost.key | sort | paste -sd' ' -)" "Bash(*/rtk read */ghost.key*) Bash(rtk read */ghost.key*)" +rm -f "$T62F" + +# T63 phase 2 rules present (adding is free; a removal is the user's edit) +missing="" +while IFS= read -r e; do + jq -e --arg e "$e" '(.permissions.ask + .permissions.deny) | index($e)' \ + "$S" >/dev/null || missing="$missing [$e]" +done <<'EOF' +Bash(git merge *) +Bash(bash *gitflow.sh finish*) +Bash(sh *gitflow.sh finish*) +Bash(sh -c *) +Bash(sh -*c *) +Bash(bash -*c *) +Bash(dash -c *) +Bash(bash) +Bash(sh) +Bash(bash <(*) +Bash(/bin/sh *) +Bash(/bin/bash *) +Bash(/usr/bin/bash *) +Bash(/usr/bin/sh *) +Bash(/usr/bin/env bash*) +Bash(/usr/bin/env sh*) +Bash(awk *system(*) +Bash(head * .env*) +Bash(tail * .env*) +Bash(head * */.env*) +Bash(tail * */.env*) +Bash(cat * .env*) +Bash(cat * */.env*) +EOF +check T63-phase2-rules-present "$missing" "" +check T63b-no-root-glob "$(jq -r '(.permissions.ask + .permissions.deny)[]' \ + "$S" | grep -cxF 'Bash(/*)')" 0 +check T63c-parens-balanced "$(jq -r '(.permissions.ask + .permissions.deny)[] + | select(test("^[A-Za-z]+\\(") and (endswith(")") | not))' "$S")" "" + printf 'PASS=%s FAIL=%s\n' "$pass" "$fail"; [ "$fail" -eq 0 ]