diff --git a/.github/scripts/check-ci-policy-agreement.sh b/.github/scripts/check-ci-policy-agreement.sh index 812f3ede45..6fd4ac7843 100755 --- a/.github/scripts/check-ci-policy-agreement.sh +++ b/.github/scripts/check-ci-policy-agreement.sh @@ -107,10 +107,12 @@ triggers_of() { exit } /^"?on"?:[[:space:]]*$/ { inblock = 1; next } - inblock && /^ [a-z_]+:/ { + inblock && /^ ["\047]?[a-z_]+["\047]?[[:space:]]*:/ { key = $0 sub(/^ /, "", key) sub(/:.*/, "", key) + gsub(/["\047]/, "", key) + sub(/[[:space:]]+$/, "", key) print key next } @@ -118,6 +120,637 @@ triggers_of() { ' "$file" } +# push_targets_main : print "yes" when the workflow +# declares a push trigger that runs on main, "no" when it declares a +# push trigger that cannot run on main, and "absent" when it declares +# no push trigger at all. The main tier's contract is a push on +# branches: [main] (ci-policy.md), so the trigger *name* is not +# enough (#7950): a bare/unfiltered push counts; an explicit +# branches: filter must match main as a pattern (an ordered list, +# so a later '!main' negation unmatches it); branches-ignore: with +# any pattern matching main, a branches: list whose patterns do not +# match main, and a tags-only push (tags: or tags-ignore:, with no +# branch filter) never run on main and do not satisfy the leg. +# Trailing YAML comments on filter lines are not filter entries. +# Path gates do not affect the verdict ("path gates as before"). +push_targets_main() { + local file="$1" + awk ' + function hexval(str, v, i, d) { + v = 0 + for (i = 1; i <= length(str); i++) { + d = index("0123456789abcdef", tolower(substr(str, i, 1))) - 1 + if (d < 0) return -1 + v = v * 16 + d + } + return v + } + function codepoint_char(cp, b1, b2, b3, b4) { + if (cp < 128) return sprintf("%c", cp) + if (cp < 2048) return sprintf("%c%c", 192 + int(cp / 64), 128 + (cp % 64)) + if (cp < 65536) return sprintf("%c%c%c", 224 + int(cp / 4096), 128 + (int(cp / 64) % 64), 128 + (cp % 64)) + return sprintf("%c%c%c%c", 240 + int(cp / 262144), 128 + (int(cp / 4096) % 64), 128 + (int(cp / 64) % 64), 128 + (cp % 64)) + } + function decode_dq(str, out, i, c, n, dn, cp) { + # Decode the escapes of a YAML double-quoted scalar: the simple + # escapes and the \xXX / \uXXXX / \UXXXXXXXX forms. An + # unrecognized or truncated escape keeps its backslash; + # decoding never invents characters. + out = "" + for (i = 1; i <= length(str); i++) { + c = substr(str, i, 1) + if (c != "\\") { out = out c; continue } + if (i == length(str)) { out = out "\\"; break } + n = substr(str, i + 1, 1) + if (n == "0") { out = out sprintf("%c", 0); i++ } + else if (n == "a") { out = out sprintf("%c", 7); i++ } + else if (n == "b") { out = out sprintf("%c", 8); i++ } + else if (n == "t") { out = out "\t"; i++ } + else if (n == "n") { out = out "\n"; i++ } + else if (n == "v") { out = out sprintf("%c", 11); i++ } + else if (n == "f") { out = out sprintf("%c", 12); i++ } + else if (n == "r") { out = out "\r"; i++ } + else if (n == "e") { out = out sprintf("%c", 27); i++ } + else if (n == " ") { out = out " "; i++ } + else if (n == "\"") { out = out "\""; i++ } + else if (n == "/") { out = out "/"; i++ } + else if (n == "\\") { out = out "\\"; i++ } + else if (n == "N") { out = out codepoint_char(133); i++ } + else if (n == "_") { out = out codepoint_char(160); i++ } + else if (n == "L") { out = out codepoint_char(8232); i++ } + else if (n == "P") { out = out codepoint_char(8233); i++ } + else if (n == "x" || n == "u" || n == "U") { + dn = (n == "x") ? 2 : (n == "u") ? 4 : 8 + if (i + 1 + dn <= length(str) && (cp = hexval(substr(str, i + 2, dn))) >= 0) { out = out codepoint_char(cp); i += 1 + dn } + else out = out "\\" + } + else out = out "\\" + } + return out + } + function clean(tok) { + sub(/^[[:space:]]+/, "", tok) + sub(/[[:space:]]+$/, "", tok) + if (length(tok) >= 2) { + if (substr(tok, 1, 1) == "\047" && substr(tok, length(tok), 1) == "\047") { tok = substr(tok, 2, length(tok) - 2); gsub(/\047\047/, "\047", tok) } + else if (substr(tok, 1, 1) == "\"" && substr(tok, length(tok), 1) == "\"") tok = decode_dq(substr(tok, 2, length(tok) - 2)) + } + return tok + } + function add_tokens(str, i, c, q, tok, seg, out) { + sub(/^[[:space:]]*\[/, "", str) + sub(/\][[:space:]]*$/, "", str) + out = "" + tok = "" + seg = "" + q = "" + for (i = 1; i <= length(str); i++) { + c = substr(str, i, 1) + if (q == "\"") { + if (c == "\"") { tok = tok decode_dq(seg); seg = ""; q = "" } + else if (c == "\\" && i < length(str)) { seg = seg c substr(str, i + 1, 1); i++ } + else seg = seg c + } else if (q != "") { + # Single-quoted scalar: a doubled '' is one literal + # apostrophe (Codex P2, PR #8513 round 16); dropping + # both rewrites an apostrophe pattern as plain main. + if (c == q && substr(str, i + 1, 1) == q) { tok = tok q; i++ } + else if (c == q) q = "" + else tok = tok c + } else if (c == "\047" || c == "\"") { + q = c + } else if (c ~ /[[:space:],]/) { + if (tok != "") { out = out " " tok; tok = "" } + } else { + tok = tok c + } + } + if (q == "\"") tok = tok decode_dq(seg) + if (tok != "") out = out " " tok + return out + } + # Quote discipline for the structural scanners (Codex P2, PR + # #8513 round 12): inside a double-quoted scalar a backslash + # escapes the next character, so \" does not end the scalar; + # inside a single-quoted scalar a doubled '' is an escaped + # quote, not the end. The scalar decoder (decode_dq) already + # honors the escapes — the scanners that decide where scalars + # and structures end must honor them too, or a delimiter inside + # a quoted scalar is mistaken for structure. + # A YAML comment starts at an unquoted # that begins the line + # or follows whitespace (Codex P2, PR #8513 round 13): braces + # and brackets inside comments are not structure, so every + # structural scanner stops there. + function unquoted_close(str, j, c, q) { + q = "" + for (j = 1; j <= length(str); j++) { + c = substr(str, j, 1) + if (q == "\"") { + if (c == "\\") j++ + else if (c == "\"") q = "" + } else if (q == "\047") { + if (c == "\047" && substr(str, j + 1, 1) == "\047") j++ + else if (c == "\047") q = "" + } + else if (c == "\047" || c == "\"") q = c + else if (c == "#" && (j == 1 || substr(str, j - 1, 1) ~ /[[:space:]]/)) return 0 + else if (c == "]") return j + } + return 0 + } + # strip_comment: the text of a line up to (not including) an + # unquoted comment start, with the same quote discipline as + # unquoted_close. Joining physical lines into one logical line + # (inline_collect) must strip each line first (Codex P2, PR + # #8513 round 14): flattening first puts a closing bracket + # that follows a comment inside that comment, and the filter + # it closes is silently discarded. Every filter-value path + # strips through this helper, never a quote-naive substitution + # (Codex P2, round 15): a # inside a quoted pattern is data, + # not a comment, and truncating there discards the rest of + # the filter. + function strip_comment(str, j, c, q) { + q = "" + for (j = 1; j <= length(str); j++) { + c = substr(str, j, 1) + if (q == "\"") { + if (c == "\\") j++ + else if (c == "\"") q = "" + } else if (q == "\047") { + if (c == "\047" && substr(str, j + 1, 1) == "\047") j++ + else if (c == "\047") q = "" + } + else if (c == "\047" || c == "\"") q = c + else if (c == "#" && (j == 1 || substr(str, j - 1, 1) ~ /[[:space:]]/)) return substr(str, 1, j - 1) + } + return str + } + function flow_unclosed(str, j, c, q, open) { + q = "" + open = 0 + for (j = 1; j <= length(str); j++) { + c = substr(str, j, 1) + if (q == "\"") { + if (c == "\\") j++ + else if (c == "\"") q = "" + } else if (q == "\047") { + if (c == "\047" && substr(str, j + 1, 1) == "\047") j++ + else if (c == "\047") q = "" + } + else if (c == "\047" || c == "\"") q = c + else if (c == "#" && (j == 1 || substr(str, j - 1, 1) ~ /[[:space:]]/)) return open + else if (c == "[") open = 1 + else if (c == "]" && open) open = 0 + } + return open + } + function has_unquoted_brace(str, j, c, q) { + q = "" + for (j = 1; j <= length(str); j++) { + c = substr(str, j, 1) + if (q == "\"") { + if (c == "\\") j++ + else if (c == "\"") q = "" + } else if (q == "\047") { + if (c == "\047" && substr(str, j + 1, 1) == "\047") j++ + else if (c == "\047") q = "" + } + else if (c == "\047" || c == "\"") q = c + else if (c == "#" && (j == 1 || substr(str, j - 1, 1) ~ /[[:space:]]/)) return 0 + else if (c == "}") return 1 + } + return 0 + } + function flow_key_colon(str, key, i, j, c, q, prev, word) { + q = "" + for (i = 1; i <= length(str); i++) { + c = substr(str, i, 1) + if (q == "\"") { + if (c == "\\") i++ + else if (c == "\"") q = "" + continue + } + if (q == "\047") { + if (c == "\047" && substr(str, i + 1, 1) == "\047") i++ + else if (c == "\047") q = "" + continue + } + if (c == "#" && (i == 1 || substr(str, i - 1, 1) ~ /[[:space:]]/)) return 0 + if (c == "\"" || c == "\047") { + q = c + j = i + 1 + word = "" + while (j <= length(str)) { + c = substr(str, j, 1) + if (q == "\"" && c == "\\") { j++; word = word substr(str, j, 1); j++; continue } + if (c == q) { + if (q == "\047" && substr(str, j + 1, 1) == q) { word = word q; j += 2; continue } + break + } + word = word c + j++ + } + if (word == key && j <= length(str)) { + j++ + while (substr(str, j, 1) ~ /[[:space:]]/) j++ + if (substr(str, j, 1) == ":") return j + } + i = j + q = "" + continue + } + prev = (i == 1) ? "" : substr(str, i - 1, 1) + if ((prev == "" || prev == "{" || prev == "," || prev ~ /[[:space:]]/) && substr(str, i, length(key)) == key) { + j = i + length(key) + while (substr(str, j, 1) ~ /[[:space:]]/) j++ + if (substr(str, j, 1) == ":") return j + } + } + return 0 + } + function flow_span(str, key, colon, start, seg, i) { + colon = flow_key_colon(str, key) + if (colon == 0) return "" + start = colon + 1 + while (substr(str, start, 1) ~ /[[:space:]]/) start++ + if (substr(str, start, 1) != "[") return "" + seg = substr(str, start) + i = unquoted_close(seg) + if (i == 0) return "" + return substr(seg, 1, i) + } + function resolve_sequence_value(val, name) { + sub(/^[[:space:]]+/, "", val) + sub(/[[:space:]]+$/, "", val) + if (val !~ /^\*[A-Za-z0-9_-]+$/) return val + name = substr(val, 2) + if (name in sequence_anchor) return sequence_anchor[name] + alias_unknown = 1 + return "" + } + function apply_inline_filters(str, seg, colon) { + seg = flow_span(str, "branches-ignore") + if (seg == "") { + colon = flow_key_colon(str, "branches-ignore") + if (colon) seg = resolve_sequence_value(substr(str, colon + 1)) + } + if (seg != "") { + seen_branch_filter = 1 + ignore_list = ignore_list add_tokens(seg) + } + seg = flow_span(str, "branches") + if (seg == "") { + colon = flow_key_colon(str, "branches") + if (colon) seg = resolve_sequence_value(substr(str, colon + 1)) + } + if (seg != "") { + seen_branches = 1 + seen_branch_filter = 1 + branches_list = branches_list add_tokens(seg) + } + if (flow_key_colon(str, "tags-ignore") || flow_key_colon(str, "tags")) seen_tags = 1 + } + function resolve_push_alias(name) { + # An aliased push inherits the anchored mapping filters + # (Codex P2, PR #8513 round 13). An alias that resolves to + # no recorded filter is unsupported syntax: mark it so the + # verdict never certifies it as an unfiltered push. + if (name in anchor_body) { + apply_inline_filters(anchor_body[name]) + } else if ((name in anchor_mapping_seen) || (name in anchor_seen_branches) || (name in anchor_seen_ignore) || (name in anchor_seen_tags)) { + if (name in anchor_seen_ignore) { + seen_branch_filter = 1 + ignore_list = ignore_list anchor_ignore[name] + } + if (name in anchor_seen_branches) { + seen_branches = 1 + seen_branch_filter = 1 + branches_list = branches_list anchor_branches[name] + } + if (name in anchor_seen_tags) seen_tags = 1 + } else { + alias_unknown = 1 + } + } + function glob_regex(pat, out, i, c, cls) { + # GitHub filter-pattern syntax (workflow-syntax cheat sheet), + # not shell glob: ? and + quantify the preceding character, + # * matches within a path segment, ** across segments. + out = "^" + for (i = 1; i <= length(pat); i++) { + c = substr(pat, i, 1) + if (c == "*") { + if (substr(pat, i + 1, 1) == "*") { + if (substr(pat, i + 2, 1) == "/") { out = out "(.*/)?"; i += 2 } + else { out = out ".*"; i++ } + } + else out = out "[^/]*" + } + else if (c == "?" || c == "+") out = out c + else if (c == "[") { + cls = "[" + i++ + if (substr(pat, i, 1) == "!") { cls = cls "^"; i++ } + for (; i <= length(pat); i++) { + cls = cls substr(pat, i, 1) + if (substr(pat, i, 1) == "]") break + } + out = out cls + } + else if (c ~ /[.^$()|{}]/) out = out "\\" c + else out = out c + } + return out "$" + } + function list_matches_main(list, n, parts, i, tok) { + n = split(list, parts, /[[:space:]]+/) + for (i = 1; i <= n; i++) { + tok = parts[i] + if (tok != "" && ("main" ~ glob_regex(tok))) return 1 + } + return 0 + } + function branches_allow_main(list, n, parts, i, tok, allow) { + allow = 0 + n = split(list, parts, /[[:space:]]+/) + for (i = 1; i <= n; i++) { + tok = parts[i] + if (tok == "") continue + if (substr(tok, 1, 1) == "!") { + if ("main" ~ glob_regex(substr(tok, 2))) allow = 0 + } else if ("main" ~ glob_regex(tok)) { + allow = 1 + } + } + return allow + } + /^"?on"?:[[:space:]]*\[/ { + line = $0 + sub(/^"?on"?:[[:space:]]*\[/, "", line) + sub(/\].*/, "", line) + if (line ~ /(^|,)[[:space:]]*push[[:space:]]*(,|$)/) verdict = "yes" + else verdict = "absent" + done = 1 + exit + } + /^"?on"?:[[:space:]]*[a-z_]/ { + line = $0 + sub(/^"?on"?:[[:space:]]*/, "", line) + sub(/[[:space:]].*/, "", line) + verdict = (line == "push") ? "yes" : "absent" + done = 1 + exit + } + /^"?on"?:[[:space:]]*$/ { inblock = 1; next } + inblock && /^ ["\047]?[a-z_]+["\047]?[[:space:]]*:/ { + key = $0 + sub(/^ /, "", key) + sub(/:.*/, "", key) + gsub(/["\047]/, "", key) + sub(/[[:space:]]+$/, "", key) + inpush = (key == "push") + if (!inpush) child_indent = 0 + rest = $0 + sub(/^ ["\047]?[a-z_]+["\047]?[[:space:]]*:[[:space:]]*/, "", rest) + # YAML anchors (Codex P2, PR #8513 round 13): a mapping + # value may carry &name and be referenced later as *name. + # Record anchored bodies so an aliased push resolves to + # its filters instead of looking like an unfiltered push. + anchor_here = "" + if (rest ~ /^&[A-Za-z0-9_-]+([[:space:]]|$)/) { + anchor_here = rest + sub(/^&/, "", anchor_here) + sub(/[[:space:]].*/, "", anchor_here) + sub(/^&[A-Za-z0-9_-]+[[:space:]]*/, "", rest) + if (rest ~ /^\{/) anchor_body[anchor_here] = rest + } + cur_anchor = anchor_here + anchor_child_indent = 0 + anchor_flow_key = "" + anchor_seq_indent = 0 + if (inpush) { + seen_push = 1 + if (rest ~ /^\*[A-Za-z0-9_-]+/) { + alias = substr(rest, 2) + sub(/[^A-Za-z0-9_-].*/, "", alias) + resolve_push_alias(alias) + } else if (rest ~ /^\{/) { + if (has_unquoted_brace(rest)) apply_inline_filters(rest) + else { inline_collect = 1; inline_buf = strip_comment(rest); inline_anchor = anchor_here } + } + } + subkey = "" + next + } + inblock && !inpush && cur_anchor == "" && /^ +["\047]?[a-z_-]+["\047]?[[:space:]]*:/ { + line = $0 + match(line, /^ +/) + sequence_key_indent = RLENGTH + keyval = substr(line, sequence_key_indent + 1) + sub(/:.*/, "", keyval) + gsub(/["\047]/, "", keyval) + val = substr(line, sequence_key_indent + 1) + sub(/^[^:]*:[[:space:]]*/, "", val) + sequence_anchor_pending = "" + if (val ~ /^&[A-Za-z0-9_-]+([[:space:]]|$)/) { + sequence_anchor_pending = val + sub(/^&/, "", sequence_anchor_pending) + sub(/[[:space:]].*/, "", sequence_anchor_pending) + sub(/^&[A-Za-z0-9_-]+[[:space:]]*/, "", val) + if (val ~ /^\[/) { + sequence_anchor[sequence_anchor_pending] = add_tokens(val) + sequence_anchor_pending = "" + } + } + next + } + inblock && !inpush && cur_anchor == "" && sequence_anchor_pending != "" && /^ +-[[:space:]]/ { + item = $0 + match(item, /^ +/) + if (RLENGTH > sequence_key_indent) { + sub(/^ +-[[:space:]]*/, "", item) + sequence_anchor[sequence_anchor_pending] = sequence_anchor[sequence_anchor_pending] " " clean(item) + next + } + sequence_anchor_pending = "" + } + inblock && /^[^[:space:]#]/ { inblock = 0; inpush = 0; child_indent = 0; cur_anchor = "" } + inline_collect { + if ($0 ~ /^[^[:space:]#]/) { + apply_inline_filters(inline_buf) + if (inline_anchor != "") { anchor_body[inline_anchor] = inline_buf; inline_anchor = "" } + inline_collect = 0 + } else { + inline_line = strip_comment($0) + inline_buf = inline_buf " " inline_line + if (has_unquoted_brace(inline_line)) { + apply_inline_filters(inline_buf) + if (inline_anchor != "") { anchor_body[inline_anchor] = inline_buf; inline_anchor = "" } + inline_collect = 0 + } + next + } + } + + !inpush && cur_anchor != "" && /^ +["\047]?[a-z-]+["\047]?[[:space:]]*:/ { + line = $0 + match(line, /^ +/) + ind = RLENGTH + if (anchor_child_indent == 0) anchor_child_indent = ind + if (ind != anchor_child_indent) next + anchor_seq_key_indent = ind + anchor_seq_indent = 0 + subkey_a = substr(line, ind + 1) + sub(/:.*/, "", subkey_a) + gsub(/["\047]/, "", subkey_a) + sub(/[[:space:]]+$/, "", subkey_a) + anchor_mapping_seen[cur_anchor] = 1 + val = substr(line, ind + 1) + sub(/^[^:]*:[[:space:]]*/, "", val) + if (subkey_a == "branches" || subkey_a == "branches-ignore" || subkey_a == "tags" || subkey_a == "tags-ignore") val = strip_comment(val) + if ((subkey_a == "branches" || subkey_a == "branches-ignore") && flow_unclosed(val)) anchor_flow_key = subkey_a + if (subkey_a == "branches") { + anchor_seen_branches[cur_anchor] = 1 + anchor_branches[cur_anchor] = add_tokens(val) + } else if (subkey_a == "branches-ignore") { + anchor_seen_ignore[cur_anchor] = 1 + anchor_ignore[cur_anchor] = add_tokens(val) + } else if (subkey_a == "tags" || subkey_a == "tags-ignore") { + anchor_seen_tags[cur_anchor] = 1 + } + next + } + !inpush && cur_anchor != "" && anchor_flow_key != "" { + seg = strip_comment($0) + k = unquoted_close(seg) + if (k > 0) { + seg = substr(seg, 1, k - 1) + if (anchor_flow_key == "branches") anchor_branches[cur_anchor] = anchor_branches[cur_anchor] add_tokens(seg) + else if (anchor_flow_key == "branches-ignore") anchor_ignore[cur_anchor] = anchor_ignore[cur_anchor] add_tokens(seg) + anchor_flow_key = "" + } else if (anchor_flow_key == "branches") { + anchor_branches[cur_anchor] = anchor_branches[cur_anchor] add_tokens(seg) + } else if (anchor_flow_key == "branches-ignore") { + anchor_ignore[cur_anchor] = anchor_ignore[cur_anchor] add_tokens(seg) + } + next + } + !inpush && cur_anchor != "" && /^ +-[[:space:]]/ { + item = $0 + match(item, /^ +/) + ind = RLENGTH + if (anchor_seq_indent == 0) { + if (ind < anchor_seq_key_indent) next + anchor_seq_indent = ind + } + if (ind != anchor_seq_indent) next + sub(/^ +-[[:space:]]*/, "", item) + if (subkey_a == "branches" || subkey_a == "branches-ignore" || subkey_a == "tags" || subkey_a == "tags-ignore") item = strip_comment(item) + if (subkey_a == "branches") { + anchor_seen_branches[cur_anchor] = 1 + anchor_branches[cur_anchor] = anchor_branches[cur_anchor] " " clean(item) + } else if (subkey_a == "branches-ignore") { + anchor_seen_ignore[cur_anchor] = 1 + anchor_ignore[cur_anchor] = anchor_ignore[cur_anchor] " " clean(item) + } else if (subkey_a == "tags" || subkey_a == "tags-ignore") { + anchor_seen_tags[cur_anchor] = 1 + } + next + } + inpush && /^ +["\047]?[a-z-]+["\047]?[[:space:]]*:/ { + line = $0 + match(line, /^ +/) + ind = RLENGTH + if (child_indent == 0) child_indent = ind + if (ind != child_indent) next + seq_key_indent = ind + seq_indent = 0 + subkey = substr(line, ind + 1) + sub(/:.*/, "", subkey) + gsub(/["\047]/, "", subkey) + sub(/[[:space:]]+$/, "", subkey) + val = substr(line, ind + 1) + sub(/^[^:]*:[[:space:]]*/, "", val) + if (subkey == "branches" || subkey == "branches-ignore" || subkey == "tags" || subkey == "tags-ignore") val = strip_comment(val) + if ((subkey == "branches" || subkey == "branches-ignore") && flow_unclosed(val)) flow_key = subkey + if (subkey == "branches" || subkey == "branches-ignore") val = resolve_sequence_value(val) + if (subkey == "branches") { + seen_branches = 1 + seen_branch_filter = 1 + branches_list = add_tokens(val) + } else if (subkey == "branches-ignore") { + seen_branch_filter = 1 + ignore_list = add_tokens(val) + } else if (subkey == "tags" || subkey == "tags-ignore") { + seen_tags = 1 + } + next + } + inpush && flow_key != "" { + seg = strip_comment($0) + k = unquoted_close(seg) + if (k > 0) { + seg = substr(seg, 1, k - 1) + if (flow_key == "branches") branches_list = branches_list add_tokens(seg) + else if (flow_key == "branches-ignore") ignore_list = ignore_list add_tokens(seg) + flow_key = "" + } else if (flow_key == "branches") { + branches_list = branches_list add_tokens(seg) + } else if (flow_key == "branches-ignore") { + ignore_list = ignore_list add_tokens(seg) + } + next + } + inpush && /^ +-[[:space:]]/ { + item = $0 + match(item, /^ +/) + ind = RLENGTH + if (seq_indent == 0) { + if (ind < seq_key_indent) next + seq_indent = ind + } + if (ind != seq_indent) next + sub(/^ +-[[:space:]]*/, "", item) + if (subkey == "branches" || subkey == "branches-ignore" || subkey == "tags" || subkey == "tags-ignore") item = strip_comment(item) + if (subkey == "branches") { + seen_branches = 1 + seen_branch_filter = 1 + branches_list = branches_list " " clean(item) + } else if (subkey == "branches-ignore") { + seen_branch_filter = 1 + ignore_list = ignore_list " " clean(item) + } else if (subkey == "tags" || subkey == "tags-ignore") { + seen_tags = 1 + } + next + } + END { + if (done) { + print verdict + exit + } + if (!seen_push) { + print "absent" + exit + } + if (alias_unknown) { + print "no" + } else if (list_matches_main(ignore_list)) { + print "no" + } else if (seen_branches) { + if (branches_allow_main(branches_list)) print "yes" + else print "no" + } else if (seen_branch_filter) { + print "yes" + } else if (seen_tags) { + print "no" + } else { + print "yes" + } + } + ' "$file" +} + waiver_for() { # waiver_for -> issue or empty local entry for entry in "${WAIVERS[@]}"; do @@ -162,7 +795,20 @@ for row in "${REGISTRY[@]}"; do IFS=',' read -ra tier_list <<<"$tiers" for tier in "${tier_list[@]}"; do req="$(required_trigger "$tier")" - if printf '%s\n' "$triggers" | grep -qx "$req"; then + agrees=0 + mistargeted=0 + if [ "$tier" = "main" ]; then + # The main leg agrees only when the push trigger targets main + # (#7950): a mis-filtered push keeps the leg in disagreement, + # so a waiver for it is recorded, never stale. + case "$(push_targets_main "$wf")" in + yes) agrees=1 ;; + no) mistargeted=1 ;; + esac + elif printf '%s\n' "$triggers" | grep -qx "$req"; then + agrees=1 + fi + if [ "$agrees" -eq 1 ]; then if [ -n "$(waiver_for "$file" "$tier")" ]; then echo "::error::STALE WAIVER $file: $tier leg now agrees (trigger '$req' declared) — delete the waiver for issue #$(waiver_for "$file" "$tier") in this PR" fail=1 @@ -172,9 +818,17 @@ for row in "${REGISTRY[@]}"; do if [ -n "$issue" ]; then SEEN_WAIVER["$file|$tier"]=1 waived=$((waived + 1)) - echo "::warning::WAIVED $file: $tier tier requires trigger '$req', not declared — disagreement recorded against issue #$issue (Phase 2-3 of #7089, awaiting Drew's ruling)" + if [ "$mistargeted" -eq 1 ]; then + echo "::warning::WAIVED $file: $tier tier requires a push trigger on branches: [main]; the declared push does not target main — disagreement recorded against issue #$issue (Phase 2-3 of #7089, awaiting Drew's ruling)" + else + echo "::warning::WAIVED $file: $tier tier requires trigger '$req', not declared — disagreement recorded against issue #$issue (Phase 2-3 of #7089, awaiting Drew's ruling)" + fi else - echo "::error::DISAGREEMENT $file: $tier tier requires trigger '$req', not declared and no waiver records it — restore the trigger, strike the tier from ci-policy.md, or record a waiver naming its phase issue (#7089)" + if [ "$mistargeted" -eq 1 ]; then + echo "::error::DISAGREEMENT $file: $tier tier requires a push trigger on branches: [main]; the declared push does not target main and no waiver records it — retarget the push to main, strike the tier from ci-policy.md, or record a waiver naming its phase issue (#7089)" + else + echo "::error::DISAGREEMENT $file: $tier tier requires trigger '$req', not declared and no waiver records it — restore the trigger, strike the tier from ci-policy.md, or record a waiver naming its phase issue (#7089)" + fi fail=1 fi fi diff --git a/.github/scripts/check-ci-policy-agreement.test.sh b/.github/scripts/check-ci-policy-agreement.test.sh index 0ebc2e89c1..4734311bea 100755 --- a/.github/scripts/check-ci-policy-agreement.test.sh +++ b/.github/scripts/check-ci-policy-agreement.test.sh @@ -23,6 +23,17 @@ wf() { # wf } >"$root/.github/workflows/$file" } +wf_raw() { # wf_raw : workflow whose on: block is stdin + local root="$1" file="$2" + mkdir -p "$root/.github/workflows" + { + echo "name: $file" + echo "on:" + cat + echo "jobs: {}" + } >"$root/.github/workflows/$file" +} + policy() { # policy : a ci-policy.md naming every registry row local root="$1" mkdir -p "$root/.github" @@ -83,6 +94,131 @@ fi grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/stale.out" echo "pass: a waiver whose leg now agrees fails as stale" +# Main-tier branch filters (#7950): a push that cannot run on main +# does NOT satisfy the main leg. mcpx-nixbuild's main leg is waived +# (#6981), so a mis-filtered push keeps the waiver recorded — the +# tree still passes and the verdict is WAIVED, never STALE. +for case in release ignore_main tags_only; do + build_tree "$TMP/filter-$case" +done +wf_raw "$TMP/filter-release" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: [release] +EOF +bash "$SCRIPT" "$TMP/filter-release" >"$TMP/filter-release.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-release.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-release.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-release.out"; then + echo "FAIL: branches: [release] was certified as main-tier agreement" >&2 + exit 1 +fi +echo "pass: push branches: [release] keeps the main leg waived, not stale" + +wf_raw "$TMP/filter-ignore_main" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: [main] +EOF +bash "$SCRIPT" "$TMP/filter-ignore_main" >"$TMP/filter-ignore_main.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-ignore_main.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-ignore_main.out" +echo "pass: push branches-ignore: [main] keeps the main leg waived, not stale" + +wf_raw "$TMP/filter-tags_only" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + tags: ["v*"] +EOF +bash "$SCRIPT" "$TMP/filter-tags_only" >"$TMP/filter-tags_only.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-tags_only.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-tags_only.out" +echo "pass: tags-only push keeps the main leg waived, not stale" + +# A push that does target main satisfies the leg: the #6981 waiver +# for mcpx-nixbuild's main leg is stale and must be deleted. Both +# the flow-list and the block-sequence branches: forms agree. +build_tree "$TMP/filter-main" +wf_raw "$TMP/filter-main" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: [main] +EOF +if bash "$SCRIPT" "$TMP/filter-main" >"$TMP/filter-main.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a main-targeting push" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-main.out" +echo "pass: push branches: [main] satisfies the main leg (waiver stale)" + +build_tree "$TMP/filter-main-list" +wf_raw "$TMP/filter-main-list" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: + - release + - main +EOF +if bash "$SCRIPT" "$TMP/filter-main-list" >"$TMP/filter-main-list.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a block-sequence branches: [main]" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-main-list.out" +echo "pass: block-sequence branches including main satisfies the main leg" + +# An unwaived main leg with a mis-filtered push is a disagreement, +# never an agreement: mcpx-fix-test-guard's main leg has no waiver. +build_tree "$TMP/filter-unwaived" +wf_raw "$TMP/filter-unwaived" mcpx-fix-test-guard.yml <<'EOF' + pull_request: + workflow_dispatch: + push: + branches-ignore: + - main +EOF +if bash "$SCRIPT" "$TMP/filter-unwaived" >"$TMP/filter-unwaived.out" 2>&1; then + echo "FAIL: checker certified an unwaived main leg whose push excludes main" >&2 + exit 1 +fi +grep -q "DISAGREEMENT mcpx-fix-test-guard.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-unwaived.out" +echo "pass: unwaived main leg with branches-ignore: [main] fails as disagreement" + +# Codex P2 (PR #8513): block-sequence items indented deeper than +# key+2 are valid YAML and must still be read — a branches-ignore +# key at four spaces with its item at eight excludes main exactly +# like the six-space form above. +build_tree "$TMP/filter-unwaived-deep" +wf_raw "$TMP/filter-unwaived-deep" mcpx-fix-test-guard.yml <<'EOF' + pull_request: + workflow_dispatch: + push: + branches-ignore: + - main +EOF +if bash "$SCRIPT" "$TMP/filter-unwaived-deep" >"$TMP/filter-unwaived-deep.out" 2>&1; then + echo "FAIL: checker certified an unwaived main leg whose deep-indented branches-ignore excludes main" >&2 + exit 1 +fi +grep -q "DISAGREEMENT mcpx-fix-test-guard.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-unwaived-deep.out" +echo "pass: deep-indented block-sequence branches-ignore item still excludes main" + +# And the mirror image: a deep-indented branches block list that +# includes main satisfies the main leg (the waiver goes stale). +build_tree "$TMP/filter-main-list-deep" +wf_raw "$TMP/filter-main-list-deep" mcpx-nixbuild.yml <<'EOF' + pull_request: + workflow_dispatch: + push: + branches: + - main +EOF +if bash "$SCRIPT" "$TMP/filter-main-list-deep" >"$TMP/filter-main-list-deep.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a deep-indented block-sequence branches: [main]" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-main-list-deep.out" +echo "pass: deep-indented block-sequence branches including main satisfies the main leg" + # Missing policy row: production-line guard's row vanishes. build_tree "$TMP/norow" grep -v "production-line guard" "$TMP/norow/.github/ci-policy.md" >"$TMP/norow/policy.tmp" @@ -104,4 +240,985 @@ fi grep -q "DISAGREEMENT map-build.yml: workflow file missing" "$TMP/nofile.out" echo "pass: a missing workflow file fails naming it" + +# Codex P2 regressions on #8513: pattern, comment and tags-ignore +# semantics of the same main-tier question. A tags-ignore-only push +# never runs for branch pushes, including main. +build_tree "$TMP/filter-tags_ignore" +wf_raw "$TMP/filter-tags_ignore" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + tags-ignore: ["v*"] +EOF +bash "$SCRIPT" "$TMP/filter-tags_ignore" >"$TMP/filter-tags_ignore.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-tags_ignore.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-tags_ignore.out" +echo "pass: tags-ignore-only push keeps the main leg waived, not stale" + +# A trailing YAML comment is not a filter entry: the word main in a +# comment must not certify a branches: [release] push. +build_tree "$TMP/filter-comment_branches" +wf_raw "$TMP/filter-comment_branches" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: [release] # main is intentionally excluded +EOF +bash "$SCRIPT" "$TMP/filter-comment_branches" >"$TMP/filter-comment_branches.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-comment_branches.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-comment_branches.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-comment_branches.out"; then + echo "FAIL: a YAML comment was treated as a branches entry" >&2 + exit 1 +fi +echo "pass: trailing comment on branches: is not a filter entry" + +# ...and the mirror image: a comment must not turn an agreeing +# branches-ignore into a disagreement either. +build_tree "$TMP/filter-comment_ignore" +wf_raw "$TMP/filter-comment_ignore" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: [release] # main remains enabled +EOF +if bash "$SCRIPT" "$TMP/filter-comment_ignore" >"$TMP/filter-comment_ignore.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a comment-bearing branches-ignore" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-comment_ignore.out" +echo "pass: trailing comment on branches-ignore: is not a filter entry" + +# Branch filters are patterns evaluated in order: a later '!main' +# unmatches an earlier literal main. +build_tree "$TMP/filter-negated" +wf_raw "$TMP/filter-negated" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: [main, '!main'] +EOF +bash "$SCRIPT" "$TMP/filter-negated" >"$TMP/filter-negated.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-negated.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-negated.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-negated.out"; then + echo "FAIL: branches: [main, '!main'] was certified as main-tier agreement" >&2 + exit 1 +fi +echo "pass: branches: [main, '!main'] keeps the main leg waived, not stale" + +# branches-ignore patterns match as globs: '*' excludes main too. +build_tree "$TMP/filter-ignore_star" +wf_raw "$TMP/filter-ignore_star" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: ['*'] +EOF +bash "$SCRIPT" "$TMP/filter-ignore_star" >"$TMP/filter-ignore_star.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-ignore_star.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-ignore_star.out" +echo "pass: branches-ignore: ['*'] keeps the main leg waived, not stale" + +# A glob that matches main satisfies the leg like a literal listing. +build_tree "$TMP/filter-pattern_main" +wf_raw "$TMP/filter-pattern_main" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: ['m*'] +EOF +if bash "$SCRIPT" "$TMP/filter-pattern_main" >"$TMP/filter-pattern_main.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a pattern-matched main push" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-pattern_main.out" +echo "pass: branches: ['m*'] satisfies the main leg (waiver stale)" + + +# Codex P2 regressions on #8513 round 2: indentless block sequences +# are valid YAML — items aligned with the filter key still count. +build_tree "$TMP/filter-indentless" +wf_raw "$TMP/filter-indentless" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: + - main +EOF +if bash "$SCRIPT" "$TMP/filter-indentless" >"$TMP/filter-indentless.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for an indentless branches sequence" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-indentless.out" +echo "pass: indentless branches sequence including main satisfies the main leg" + +# A branch filter that does not exclude main means branch pushes +# run, even when a tag filter is also declared (the tag filter +# governs tag pushes separately) — not a tags-only push. +build_tree "$TMP/filter-ignore_plus_tags" +wf_raw "$TMP/filter-ignore_plus_tags" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: [release] + tags: ['v*'] +EOF +if bash "$SCRIPT" "$TMP/filter-ignore_plus_tags" >"$TMP/filter-ignore_plus_tags.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a branches-ignore + tags push" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-ignore_plus_tags.out" +echo "pass: branches-ignore (not main) plus tags still satisfies the main leg" + + +# Codex P2 regressions on #8513 round 3: GitHub filter patterns use +# quantifiers, not shell glob — 'main?' excludes main (the ? makes +# the preceding n optional), and 'ma+in' matches it. +build_tree "$TMP/filter-ignore_quantifier" +wf_raw "$TMP/filter-ignore_quantifier" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: ['main?'] +EOF +bash "$SCRIPT" "$TMP/filter-ignore_quantifier" >"$TMP/filter-ignore_quantifier.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-ignore_quantifier.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-ignore_quantifier.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-ignore_quantifier.out"; then + echo "FAIL: branches-ignore: ['main?'] was certified as main-tier agreement" >&2 + exit 1 +fi +echo "pass: branches-ignore: ['main?'] keeps the main leg waived, not stale" + +build_tree "$TMP/filter-plus_quantifier" +wf_raw "$TMP/filter-plus_quantifier" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: ['ma+in'] +EOF +if bash "$SCRIPT" "$TMP/filter-plus_quantifier" >"$TMP/filter-plus_quantifier.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a ma+in pattern push" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-plus_quantifier.out" +echo "pass: branches: ['ma+in'] satisfies the main leg (waiver stale)" + +# Multiline flow sequences: the entries live on their own lines +# between the [ and ] lines and must all be collected. +build_tree "$TMP/filter-flow_multiline" +wf_raw "$TMP/filter-flow_multiline" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: [ + release, + main + ] +EOF +if bash "$SCRIPT" "$TMP/filter-flow_multiline" >"$TMP/filter-flow_multiline.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a multiline flow branches list" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-flow_multiline.out" +echo "pass: multiline flow branches list including main satisfies the main leg" + + +# Codex P2 regression on #8513 round 4: character classes inside a +# pattern are pattern syntax, not YAML delimiters — '[a-z]ain' +# matches main, in both the positive and the ignore list. +build_tree "$TMP/filter-class_main" +wf_raw "$TMP/filter-class_main" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: ['[a-z]ain'] +EOF +if bash "$SCRIPT" "$TMP/filter-class_main" >"$TMP/filter-class_main.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a character-class main push" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-class_main.out" +echo "pass: branches: ['[a-z]ain'] satisfies the main leg (waiver stale)" + +build_tree "$TMP/filter-class_ignore" +wf_raw "$TMP/filter-class_ignore" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: ['[a-z]ain'] +EOF +bash "$SCRIPT" "$TMP/filter-class_ignore" >"$TMP/filter-class_ignore.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-class_ignore.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-class_ignore.out" +echo "pass: branches-ignore: ['[a-z]ain'] keeps the main leg waived, not stale" + + +# Codex P2 regressions on #8513 round 5. A **/ component matches +# zero directories: '**/main' excludes main. +build_tree "$TMP/filter-globstar_ignore" +wf_raw "$TMP/filter-globstar_ignore" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: ['**/main'] +EOF +bash "$SCRIPT" "$TMP/filter-globstar_ignore" >"$TMP/filter-globstar_ignore.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-globstar_ignore.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-globstar_ignore.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-globstar_ignore.out"; then + echo "FAIL: branches-ignore: ['**/main'] was certified as main-tier agreement" >&2 + exit 1 +fi +echo "pass: branches-ignore: ['**/main'] keeps the main leg waived, not stale" + +# A comma inside a quoted scalar is content, not a separator: +# 'release,main' is one branch pattern that is not main. +build_tree "$TMP/filter-quoted_comma" +wf_raw "$TMP/filter-quoted_comma" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: ['release,main'] +EOF +bash "$SCRIPT" "$TMP/filter-quoted_comma" >"$TMP/filter-quoted_comma.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-quoted_comma.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-quoted_comma.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-quoted_comma.out"; then + echo "FAIL: a quoted comma manufactured a main branch entry" >&2 + exit 1 +fi +echo "pass: branches: ['release,main'] keeps the main leg waived, not stale" + +# An inline push mapping carries its filters on the same line. +build_tree "$TMP/filter-inline_map" +wf_raw "$TMP/filter-inline_map" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {branches: [release]} +EOF +bash "$SCRIPT" "$TMP/filter-inline_map" >"$TMP/filter-inline_map.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-inline_map.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-inline_map.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-inline_map.out"; then + echo "FAIL: an inline push mapping was treated as an unfiltered push" >&2 + exit 1 +fi +echo "pass: inline push mapping with branches: [release] keeps the main leg waived" + +build_tree "$TMP/filter-inline_map_main" +wf_raw "$TMP/filter-inline_map_main" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {branches: [main]} +EOF +if bash "$SCRIPT" "$TMP/filter-inline_map_main" >"$TMP/filter-inline_map_main.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for an inline main push mapping" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-inline_map_main.out" +echo "pass: inline push mapping with branches: [main] satisfies the main leg" + + +# Codex P2 regression on #8513 round 5b: a quoted character class +# contains its own ] — that bracket is not the flow-list terminator, +# in multiline sequences or inline mappings. +build_tree "$TMP/filter-flow_class" +wf_raw "$TMP/filter-flow_class" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: [ + '[a-z]ain', + release + ] +EOF +if bash "$SCRIPT" "$TMP/filter-flow_class" >"$TMP/filter-flow_class.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a flow list with a quoted class" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-flow_class.out" +echo "pass: multiline flow list with a quoted character class satisfies the main leg" + +build_tree "$TMP/filter-inline_class" +wf_raw "$TMP/filter-inline_class" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {branches: ['[a-z]ain']} +EOF +if bash "$SCRIPT" "$TMP/filter-inline_class" >"$TMP/filter-inline_class.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for an inline mapping with a quoted class" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-inline_class.out" +echo "pass: inline push mapping with a quoted character class satisfies the main leg" + + + +# Codex P2 regression on #8513 round 6: push children may sit at +# any consistent indentation depth, not only four spaces. +build_tree "$TMP/filter-deep_indent" +wf_raw "$TMP/filter-deep_indent" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: [release] +EOF +bash "$SCRIPT" "$TMP/filter-deep_indent" >"$TMP/filter-deep_indent.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-deep_indent.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-deep_indent.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-deep_indent.out"; then + echo "FAIL: a six-space branches filter was treated as an unfiltered push" >&2 + exit 1 +fi +echo "pass: six-space-deep branches: [release] keeps the main leg waived" + +build_tree "$TMP/filter-deep_indent_list" +wf_raw "$TMP/filter-deep_indent_list" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: + - main +EOF +if bash "$SCRIPT" "$TMP/filter-deep_indent_list" >"$TMP/filter-deep_indent_list.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a deep-indented branches list" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-deep_indent_list.out" +echo "pass: deep-indented branches list including main satisfies the main leg" + + +# Codex P2 regressions on #8513 round 7: a quoted block item with a +# trailing comment still unquotes, and quoted filter keys name the +# same filters as bare keys. +build_tree "$TMP/filter-quoted_item_comment" +wf_raw "$TMP/filter-quoted_item_comment" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: + - 'main' # main branch +EOF +bash "$SCRIPT" "$TMP/filter-quoted_item_comment" >"$TMP/filter-quoted_item_comment.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-quoted_item_comment.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-quoted_item_comment.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-quoted_item_comment.out"; then + echo "FAIL: a quoted block item with a trailing comment was not unquoted" >&2 + exit 1 +fi +echo "pass: quoted branches-ignore item with trailing comment keeps the main leg waived" + +build_tree "$TMP/filter-quoted_key" +wf_raw "$TMP/filter-quoted_key" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + "branches": [release] +EOF +bash "$SCRIPT" "$TMP/filter-quoted_key" >"$TMP/filter-quoted_key.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-quoted_key.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-quoted_key.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-quoted_key.out"; then + echo "FAIL: a quoted branches key was treated as an unfiltered push" >&2 + exit 1 +fi +echo "pass: quoted branches key with [release] keeps the main leg waived" + +build_tree "$TMP/filter-quoted_key_ignore" +wf_raw "$TMP/filter-quoted_key_ignore" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + 'branches-ignore': [main] +EOF +bash "$SCRIPT" "$TMP/filter-quoted_key_ignore" >"$TMP/filter-quoted_key_ignore.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-quoted_key_ignore.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-quoted_key_ignore.out" +echo "pass: quoted branches-ignore key with [main] keeps the main leg waived" + + +# Codex P2 regressions on #8513 round 8: a quoted push key still +# yields its inline mapping, and a tags: substring inside a path +# scalar is not a tag filter. +build_tree "$TMP/filter-quoted_push_inline" +wf_raw "$TMP/filter-quoted_push_inline" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + "push": {branches: [release]} +EOF +bash "$SCRIPT" "$TMP/filter-quoted_push_inline" >"$TMP/filter-quoted_push_inline.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-quoted_push_inline.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-quoted_push_inline.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-quoted_push_inline.out"; then + echo "FAIL: a quoted push key hid its inline branch filter" >&2 + exit 1 +fi +echo "pass: quoted push key with inline branches: [release] keeps the main leg waived" + +build_tree "$TMP/filter-paths_tags_substring" +wf_raw "$TMP/filter-paths_tags_substring" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {paths: ['docs/tags:/**']} +EOF +if bash "$SCRIPT" "$TMP/filter-paths_tags_substring" >"$TMP/filter-paths_tags_substring.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a paths-only inline push" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-paths_tags_substring.out" +echo "pass: a tags: substring inside a path scalar is not a tag filter (waiver stale)" + + +# Codex P2 regression on #8513 round 9: an inline push mapping may +# span lines — the whole mapping is collected before its filters +# are evaluated. +build_tree "$TMP/filter-inline_split" +wf_raw "$TMP/filter-inline_split" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {branches: [ + release]} +EOF +bash "$SCRIPT" "$TMP/filter-inline_split" >"$TMP/filter-inline_split.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-inline_split.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-inline_split.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-inline_split.out"; then + echo "FAIL: a split inline push mapping was treated as an unfiltered push" >&2 + exit 1 +fi +echo "pass: split inline push mapping with branches: [release] keeps the main leg waived" + +build_tree "$TMP/filter-inline_split_main" +wf_raw "$TMP/filter-inline_split_main" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {branches: [ + main]} +EOF +if bash "$SCRIPT" "$TMP/filter-inline_split_main" >"$TMP/filter-inline_split_main.out" 2>&1; then + echo "FAIL: checker accepted a stale waiver for a split inline main mapping" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-inline_split_main.out" +echo "pass: split inline push mapping with branches: [main] satisfies the main leg" + +# Codex P2 regression on #8513 round 11: a double-quoted YAML +# scalar's escapes decode before pattern matching -- "ma\u0069n" +# is the branch main, in flow lists and block items alike. A +# single-quoted scalar keeps its backslashes literally. +build_tree "$TMP/filter-dq_escape_flow" +wf_raw "$TMP/filter-dq_escape_flow" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: ["ma\u0069n"] +EOF +if bash "$SCRIPT" "$TMP/filter-dq_escape_flow" >"$TMP/filter-dq_escape_flow.out" 2>&1; then + echo "FAIL: checker missed a \u-escaped main in a flow list" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-dq_escape_flow.out" +echo "pass: double-quoted \u escape in a flow list satisfies the main leg" + +build_tree "$TMP/filter-dq_escape_block" +wf_raw "$TMP/filter-dq_escape_block" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: + - "ma\u0069n" +EOF +if bash "$SCRIPT" "$TMP/filter-dq_escape_block" >"$TMP/filter-dq_escape_block.out" 2>&1; then + echo "FAIL: checker missed a \u-escaped main in a block item" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-dq_escape_block.out" +echo "pass: double-quoted \u escape in a block item satisfies the main leg" + +build_tree "$TMP/filter-dq_escape_hex" +wf_raw "$TMP/filter-dq_escape_hex" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: ["m\x61in", 'lit\u0065ral'] +EOF +if bash "$SCRIPT" "$TMP/filter-dq_escape_hex" >"$TMP/filter-dq_escape_hex.out" 2>&1; then + echo "FAIL: checker missed a \x-escaped main in a flow list" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-dq_escape_hex.out" +echo "pass: double-quoted \x escape in a flow list satisfies the main leg" + +# Codex P2 regressions on #8513 round 12: a brace inside a quoted +# scalar does not end an inline mapping, and an escaped quote does +# not end a double-quoted scalar for the structural scanners. In +# both cases branches-ignore: [main] must be seen — main is +# excluded, so the main leg stays waived. +build_tree "$TMP/filter-inline_quoted_brace" +wf_raw "$TMP/filter-inline_quoted_brace" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {paths: ['docs/}file'], + branches-ignore: [main]} +EOF +bash "$SCRIPT" "$TMP/filter-inline_quoted_brace" >"$TMP/filter-inline_quoted_brace.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-inline_quoted_brace.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-inline_quoted_brace.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-inline_quoted_brace.out"; then + echo "FAIL: a quoted brace ended the inline mapping early and hid branches-ignore" >&2 + exit 1 +fi +echo "pass: quoted brace inside an inline mapping does not hide the continuation's branches-ignore" + +build_tree "$TMP/filter-flow_escaped_quote" +wf_raw "$TMP/filter-flow_escaped_quote" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {branches-ignore: ["release\"x", "main"]} +EOF +bash "$SCRIPT" "$TMP/filter-flow_escaped_quote" >"$TMP/filter-flow_escaped_quote.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-flow_escaped_quote.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-flow_escaped_quote.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-flow_escaped_quote.out"; then + echo "FAIL: an escaped quote broke flow scanning and discarded branches-ignore" >&2 + exit 1 +fi +echo "pass: escaped quote in a flow list does not discard the branch filter" + +# Codex P2 regressions on #8513 round 13: a brace inside a YAML +# comment does not terminate an inline mapping, and YAML anchors / +# aliases on trigger mappings resolve to their filters instead of +# looking like unfiltered pushes. +build_tree "$TMP/filter-inline_comment_brace" +wf_raw "$TMP/filter-inline_comment_brace" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: { # closing brace } in comment + branches-ignore: [main]} +EOF +bash "$SCRIPT" "$TMP/filter-inline_comment_brace" >"$TMP/filter-inline_comment_brace.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-inline_comment_brace.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-inline_comment_brace.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-inline_comment_brace.out"; then + echo "FAIL: a brace in a YAML comment ended the inline mapping early and hid branches-ignore" >&2 + exit 1 +fi +echo "pass: brace in a YAML comment does not hide the continuation's branches-ignore" + +build_tree "$TMP/filter-inline_comment_brace_main" +wf_raw "$TMP/filter-inline_comment_brace_main" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: { # } comment + branches: [main]} +EOF +if bash "$SCRIPT" "$TMP/filter-inline_comment_brace_main" >"$TMP/filter-inline_comment_brace_main.out" 2>&1; then + echo "FAIL: checker missed branches: [main] after a comment brace" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-inline_comment_brace_main.out" +echo "pass: branches: [main] after a comment brace satisfies the main leg" + +build_tree "$TMP/filter-anchor_alias_block" +wf_raw "$TMP/filter-anchor_alias_block" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: &release_only + branches: [release] + push: *release_only +EOF +bash "$SCRIPT" "$TMP/filter-anchor_alias_block" >"$TMP/filter-anchor_alias_block.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-anchor_alias_block.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-anchor_alias_block.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-anchor_alias_block.out"; then + echo "FAIL: an aliased release-only push was certified as targeting main" >&2 + exit 1 +fi +echo "pass: push aliased to an anchored block mapping inherits its branches filter" + +build_tree "$TMP/filter-anchor_inline_push" +wf_raw "$TMP/filter-anchor_inline_push" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: &release_only {branches: [release]} +EOF +bash "$SCRIPT" "$TMP/filter-anchor_inline_push" >"$TMP/filter-anchor_inline_push.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-anchor_inline_push.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-anchor_inline_push.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-anchor_inline_push.out"; then + echo "FAIL: an anchored inline release-only push was certified as targeting main" >&2 + exit 1 +fi +echo "pass: anchored inline push mapping applies its branches filter" + +build_tree "$TMP/filter-anchor_alias_inline" +wf_raw "$TMP/filter-anchor_alias_inline" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: &release_only {branches: [release]} + push: *release_only +EOF +bash "$SCRIPT" "$TMP/filter-anchor_alias_inline" >"$TMP/filter-anchor_alias_inline.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-anchor_alias_inline.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-anchor_alias_inline.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-anchor_alias_inline.out"; then + echo "FAIL: an aliased inline-anchored push was certified as targeting main" >&2 + exit 1 +fi +echo "pass: push aliased to an anchored inline mapping inherits its branches filter" + +build_tree "$TMP/filter-anchor_unknown_alias" +wf_raw "$TMP/filter-anchor_unknown_alias" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: *never_defined +EOF +bash "$SCRIPT" "$TMP/filter-anchor_unknown_alias" >"$TMP/filter-anchor_unknown_alias.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-anchor_unknown_alias.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-anchor_unknown_alias.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-anchor_unknown_alias.out"; then + echo "FAIL: an unresolvable alias was certified as an unfiltered push" >&2 + exit 1 +fi +echo "pass: an unresolvable push alias is never certified as targeting main" + +# A resolved mapping anchor with only non-branch filters is still a +# recognized push mapping; it has no main-excluding filter, so the +# main-tier leg agrees just like a bare push. +build_tree "$TMP/filter-anchor_paths_only" +wf_raw "$TMP/filter-anchor_paths_only" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: &paths_only + paths: [docs/**] + push: *paths_only +EOF +if bash "$SCRIPT" "$TMP/filter-anchor_paths_only" >"$TMP/filter-anchor_paths_only.out" 2>&1; then + echo "FAIL: a resolved paths-only anchor was not treated as a push mapping" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-anchor_paths_only.out" +echo "pass: resolved paths-only block anchor is not mistaken for an unknown alias" + +build_tree "$TMP/filter-inline_quoted_key_spaced_colon" +wf_raw "$TMP/filter-inline_quoted_key_spaced_colon" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {"branches-ignore" : [main]} +EOF +bash "$SCRIPT" "$TMP/filter-inline_quoted_key_spaced_colon" >"$TMP/filter-inline_quoted_key_spaced_colon.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-inline_quoted_key_spaced_colon.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \\[main\\]" "$TMP/filter-inline_quoted_key_spaced_colon.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-inline_quoted_key_spaced_colon.out"; then + echo "FAIL: quoted inline branches-ignore key with spaced colon was missed" >&2 + exit 1 +fi +echo "pass: quoted inline branches-ignore key with arbitrary colon spacing is recognized" + +build_tree "$TMP/filter-inline_quoted_fake_key" +wf_raw "$TMP/filter-inline_quoted_fake_key" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {paths: ["{branches: [main]} {tags: [v*]}"]} +EOF +if bash "$SCRIPT" "$TMP/filter-inline_quoted_fake_key" >"$TMP/filter-inline_quoted_fake_key.out" 2>&1; then + echo "FAIL: key-like text inside a quoted path scalar was treated as filters" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-inline_quoted_fake_key.out" +echo "pass: branch/tag-like text inside a quoted path scalar is ignored" + +build_tree "$TMP/filter-sequence_alias" +wf_raw "$TMP/filter-sequence_alias" opencode-config-guard.yml <<'EOF' + pull_request: + branches: &release_branches [release] +EOF +wf_raw "$TMP/filter-sequence_alias" mcpx-nixbuild.yml <<'EOF' + push: + branches: *release_branches +EOF +bash "$SCRIPT" "$TMP/filter-sequence_alias" >"$TMP/filter-sequence_alias.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-sequence_alias.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \\[main\\]" "$TMP/filter-sequence_alias.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-sequence_alias.out"; then + echo "FAIL: a sequence alias was not expanded before branch matching" >&2 + exit 1 +fi +echo "pass: branch sequence aliases contribute their resolved patterns" + +build_tree "$TMP/filter-sequence_alias_unknown" +wf_raw "$TMP/filter-sequence_alias_unknown" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: *not_defined +EOF +bash "$SCRIPT" "$TMP/filter-sequence_alias_unknown" >"$TMP/filter-sequence_alias_unknown.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \\[main\\]" "$TMP/filter-sequence_alias_unknown.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-sequence_alias_unknown.out"; then + echo "FAIL: an unresolved filter alias was treated as a pattern or unfiltered push" >&2 + exit 1 +fi +echo "pass: unresolved filter aliases fail closed" + +# Round-14 (Codex P2): a comment that ends the first physical line +# of a split inline mapping must not swallow the closing bracket +# on the continuation line — the comment ends at the newline, so +# the release-only filter survives and the leg stays waived. +build_tree "$TMP/filter-inline_comment_split" +wf_raw "$TMP/filter-inline_comment_split" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {branches: [ # release only + release]} +EOF +bash "$SCRIPT" "$TMP/filter-inline_comment_split" >"$TMP/filter-inline_comment_split.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-inline_comment_split.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-inline_comment_split.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-inline_comment_split.out"; then + echo "FAIL: a comment on a split inline mapping line swallowed its branch filter" >&2 + exit 1 +fi +echo "pass: a comment ending a split inline mapping line does not swallow the closing bracket" + +# Round-14 (Codex P2): YAML allows whitespace before a mapping +# colon — branches : [release] is the same filter as +# branches: [release], and branches-ignore : [main] still +# excludes main; neither may be read as an unfiltered push. +build_tree "$TMP/filter-spaced_colon" +wf_raw "$TMP/filter-spaced_colon" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches : [release] +EOF +bash "$SCRIPT" "$TMP/filter-spaced_colon" >"$TMP/filter-spaced_colon.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-spaced_colon.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-spaced_colon.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-spaced_colon.out"; then + echo "FAIL: a spaced-colon branches filter was read as an unfiltered push" >&2 + exit 1 +fi +echo "pass: branches with a spaced colon keeps the main leg waived" + +build_tree "$TMP/filter-spaced_colon_ignore" +wf_raw "$TMP/filter-spaced_colon_ignore" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore : [main] +EOF +bash "$SCRIPT" "$TMP/filter-spaced_colon_ignore" >"$TMP/filter-spaced_colon_ignore.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-spaced_colon_ignore.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-spaced_colon_ignore.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-spaced_colon_ignore.out"; then + echo "FAIL: a spaced-colon branches-ignore filter was read as an unfiltered push" >&2 + exit 1 +fi +echo "pass: branches-ignore with a spaced colon keeps the main leg waived" + +build_tree "$TMP/filter-spaced_colon_inline" +wf_raw "$TMP/filter-spaced_colon_inline" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: {branches : [release]} +EOF +bash "$SCRIPT" "$TMP/filter-spaced_colon_inline" >"$TMP/filter-spaced_colon_inline.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-spaced_colon_inline.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-spaced_colon_inline.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-spaced_colon_inline.out"; then + echo "FAIL: a spaced-colon inline branches filter was read as an unfiltered push" >&2 + exit 1 +fi +echo "pass: inline branches with a spaced colon keeps the main leg waived" + +# Round-15 (Codex P2): a # inside a quoted filter pattern is +# data, not a comment — truncating the value there discards the +# rest of the filter, including a main entry that excludes or +# includes main. +build_tree "$TMP/filter-quoted_hash_ignore" +wf_raw "$TMP/filter-quoted_hash_ignore" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: ['release # marker', main] +EOF +bash "$SCRIPT" "$TMP/filter-quoted_hash_ignore" >"$TMP/filter-quoted_hash_ignore.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-quoted_hash_ignore.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-quoted_hash_ignore.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-quoted_hash_ignore.out"; then + echo "FAIL: a quoted # in branches-ignore discarded the main exclusion" >&2 + exit 1 +fi +echo "pass: a quoted hash in branches-ignore does not discard the main exclusion" + +build_tree "$TMP/filter-quoted_hash_branches" +wf_raw "$TMP/filter-quoted_hash_branches" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: ["release # marker", main] +EOF +if bash "$SCRIPT" "$TMP/filter-quoted_hash_branches" >"$TMP/filter-quoted_hash_branches.out" 2>&1; then + echo "FAIL: checker missed branches including main after a quoted hash" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-quoted_hash_branches.out" +echo "pass: a quoted hash in branches does not discard the main inclusion" + +build_tree "$TMP/filter-quoted_hash_anchor" +wf_raw "$TMP/filter-quoted_hash_anchor" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: &excl + branches-ignore: ['release # marker', main] + push: *excl +EOF +bash "$SCRIPT" "$TMP/filter-quoted_hash_anchor" >"$TMP/filter-quoted_hash_anchor.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-quoted_hash_anchor.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-quoted_hash_anchor.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-quoted_hash_anchor.out"; then + echo "FAIL: a quoted # in an anchored branches-ignore discarded the main exclusion" >&2 + exit 1 +fi +echo "pass: a quoted hash in an anchored branches-ignore does not discard the main exclusion" + +# Round-16 (Codex P2): a doubled '' inside a single-quoted +# scalar is one literal apostrophe — 'ma''in' targets ma'in, +# not main. Dropping both apostrophes rewrites the pattern as +# main and certifies coverage that does not exist. +build_tree "$TMP/filter-doubled_apostrophe" +wf_raw "$TMP/filter-doubled_apostrophe" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches: ['ma''in'] +EOF +bash "$SCRIPT" "$TMP/filter-doubled_apostrophe" >"$TMP/filter-doubled_apostrophe.out" +grep -q "ci-policy-agreement: OK" "$TMP/filter-doubled_apostrophe.out" +grep -q "WAIVED mcpx-nixbuild.yml: main tier requires a push trigger on branches: \[main\]" "$TMP/filter-doubled_apostrophe.out" +if grep -q "STALE WAIVER mcpx-nixbuild.yml" "$TMP/filter-doubled_apostrophe.out"; then + echo "FAIL: a doubled apostrophe in branches was rewritten as main" >&2 + exit 1 +fi +echo "pass: a doubled apostrophe in branches is a literal apostrophe, not main" + +build_tree "$TMP/filter-doubled_apostrophe_ignore" +wf_raw "$TMP/filter-doubled_apostrophe_ignore" mcpx-nixbuild.yml <<'EOF' + workflow_dispatch: + push: + branches-ignore: ['ma''in'] +EOF +if bash "$SCRIPT" "$TMP/filter-doubled_apostrophe_ignore" >"$TMP/filter-doubled_apostrophe_ignore.out" 2>&1; then + echo "FAIL: checker treated 'ma''in' in branches-ignore as excluding main" >&2 + exit 1 +fi +grep -q "STALE WAIVER mcpx-nixbuild.yml: main leg now agrees" "$TMP/filter-doubled_apostrophe_ignore.out" +echo "pass: a doubled apostrophe in branches-ignore does not exclude main" + +# Codex P1 regression on #8513: generated coverage for the parser. +# Equivalent YAML representations of the same logical push filter +# must yield the same verdict. Oracle: an independent Python +# reference for GitHub filter-pattern semantics over the single +# branch name "main" (ordered branches evaluation with negation, +# any-match branches-ignore, branch-filter presence beats the +# tags-only rule) — expectations are computed by the oracle from +# the case definitions, never copied from the awk implementation. +# Representations generated per case: flow list, indented block +# sequence, indentless block sequence, multiline flow list. +python3 - "$SCRIPT" "$TMP" <<'PYEOF' +import os, re, subprocess, sys + +script, tmp = sys.argv[1], sys.argv[2] + +def translate(pat): + out, i = [], 0 + while i < len(pat): + c = pat[i] + if c == '*': + if pat[i:i+2] == '**': + if pat[i+2:i+3] == '/': + out.append('(?:.*/)?'); i += 3 + else: + out.append('.*'); i += 2 + else: + out.append('[^/]*'); i += 1 + elif c in '?+': + out.append(c); i += 1 + elif c == '[': + j = i + 1 + if pat[j:j+1] == '!': + j += 1 + while j < len(pat) and pat[j] != ']': + j += 1 + cls = pat[i+1:j] + if cls.startswith('!'): + cls = '^' + cls[1:] + out.append('[' + cls + ']'); i = j + 1 + else: + out.append(re.escape(c)); i += 1 + return '^' + ''.join(out) + '$' + +def matches(pat): + return re.match(translate(pat), 'main') is not None + +def verdict(branches=None, ignore=None, tags=False): + if ignore and any(matches(p) for p in ignore): + return 'no' + if branches is not None: + allow = False + for p in branches: + if p.startswith('!'): + if matches(p[1:]): + allow = False + elif matches(p): + allow = True + return 'yes' if allow else 'no' + if ignore is not None: + return 'yes' + return 'no' if tags else 'yes' + +def q(p): + if any(ch in p for ch in ',#[] ') or p.startswith(('!', '*')): + return "'" + p + "'" + return p + +def render(kind, pats, style): + if style == 'flow': + return [f" {kind}: [{', '.join(q(x) for x in pats)}]"] + if style == 'block': + return [f" {kind}:"] + [f" - {q(x)}" for x in pats] + if style == 'indentless': + return [f" {kind}:"] + [f" - {q(x)}" for x in pats] + if style == 'multiline': + lines = [f" {kind}: ["] + lines += [f" {q(x)}," for x in pats[:-1]] + if pats: + lines.append(f" {q(pats[-1])}") + lines.append(" ]") + return lines + raise ValueError(style) + +POLICY = """| workflow-lint | basic | — | — | +| proxy-port-fallbacks | basic | — | — | +| fleet-search-parity-guard | basic | — | — | +| opencode-config-guard | basic | main | — | +| mcpx fix-test guard (#1969) | basic | main | — | +| production-line guard (#1411) | basic | — | — | +| go modules build / identity build / map build / mcpx nix build | class-3 | main | — | +""" +BASE = { + 'workflow-lint.yml': ['pull_request', 'workflow_dispatch'], + 'proxy-port-fallbacks.yml': ['pull_request'], + 'fleet-search-parity-guard.yml': ['pull_request', 'workflow_dispatch'], + 'opencode-config-guard.yml': ['pull_request', 'workflow_dispatch'], + 'mcpx-fix-test-guard.yml': ['pull_request', 'push', 'workflow_dispatch'], + 'production-line-guard.yml': ['workflow_dispatch'], + 'go-modules-build.yml': ['workflow_dispatch'], + 'identity-build.yml': ['workflow_dispatch'], + 'map-build.yml': ['workflow_dispatch'], +} + +def build(case_root, push_lines): + os.makedirs(case_root + '/.github/workflows', exist_ok=True) + with open(case_root + '/.github/ci-policy.md', 'w') as f: + f.write(POLICY) + for name, triggers in BASE.items(): + with open(f'{case_root}/.github/workflows/{name}', 'w') as f: + f.write(f'name: {name}\non:\n') + for tr in triggers: + f.write(f' {tr}:\n') + f.write('jobs: {}\n') + with open(case_root + '/.github/workflows/mcpx-nixbuild.yml', 'w') as f: + f.write('name: mcpx-nixbuild.yml\non:\n workflow_dispatch:\n push:\n') + f.write('\n'.join(push_lines) + '\njobs: {}\n') + +BRANCH_CASES = [ + ['main'], ['release'], ['main', '!main'], ['!main', 'main'], + ['m*'], ['*'], ['**/main'], ['ma+in'], ['main?'], ['[a-z]ain'], + ['[!a]ain'], ['release,main'], ['mai'], [], +] +IGNORE_CASES = [ + ['main'], ['release'], ['*'], ['**/main'], ['main?'], ['[a-z]ain'], +] +STYLES = ['flow', 'block', 'indentless', 'multiline'] + +cases = [] +for pats in BRANCH_CASES: + cases.append((f'branches {pats}', render('branches', pats, 'flow'), verdict(branches=pats))) + for style in STYLES[1:]: + cases.append((f'branches {pats} [{style}]', render('branches', pats, style), verdict(branches=pats))) +for pats in IGNORE_CASES: + for style in STYLES: + cases.append((f'branches-ignore {pats} [{style}]', render('branches-ignore', pats, style), verdict(ignore=pats))) +cases.append(('tags only', render('tags', ['v*'], 'flow'), verdict(tags=True))) +cases.append(('ignore + tags', render('branches-ignore', ['release'], 'flow') + render('tags', ['v*'], 'flow'), verdict(ignore=['release'], tags=True))) + +failures = 0 +for idx, (name, push_lines, want) in enumerate(cases): + root = f'{tmp}/gen-{idx}' + build(root, push_lines) + proc = subprocess.run(['bash', script, root], capture_output=True, text=True) + out = proc.stdout + proc.stderr + if want == 'yes': + ok = proc.returncode != 0 and 'STALE WAIVER mcpx-nixbuild.yml: main leg now agrees' in out + else: + ok = proc.returncode == 0 and 'WAIVED mcpx-nixbuild.yml: main tier' in out and 'STALE WAIVER mcpx-nixbuild.yml' not in out + if not ok: + failures += 1 + print(f'GEN FAIL {name}: want verdict {want}, rc={proc.returncode}') + print(out[:600]) +print(f'generated coverage: {len(cases)} cases, {failures} failures') +sys.exit(1 if failures else 0) +PYEOF +echo "pass: generated representation/pattern coverage agrees with the oracle" + echo "check-ci-policy-agreement.test: all contract tests passed"