From d8cf24f63810c8baada720fb9fa33655446bad72 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 27 Sep 2026 19:46:58 -0700 Subject: [PATCH 1/3] Keep a Folded if: Condition Visible to the Interface Audit's Token Check _code_view() dropped every block-scalar body, so a requireTokensInJob token carried in a multi-line `if: >-` condition was reported missing. An `if:` value is an expression rather than prose, so its body is now kept, while `name: |` and `run: |` bodies are still dropped. Closes on promotion: #1901 Co-Authored-By: Claude Opus 5.5 (1M context) --- spec/audit.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/spec/audit.py b/spec/audit.py index 8a0e8011d..b6f6391e5 100755 --- a/spec/audit.py +++ b/spec/audit.py @@ -1918,6 +1918,7 @@ def split_jobs(text): _BARE_BLOCK_SCALAR = re.compile(r"^(&\S+\s+)?[|>][0-9+-]*\s*(#.*)?$") # A step's `- key: |` sequence-item prefix, stripped before matching the two patterns above. _SEQUENCE_ITEM_PREFIX = re.compile(r"^-[ \t]+") +_IF_KEY = re.compile(r"^if\s*:") def _code_view(text): @@ -1928,6 +1929,7 @@ def _code_view(text): both false-pass a missing handoff and false-flag a forbidden token that appears only in a comment. A block-scalar string value (`name: |` followed by indented text) can hide or fake a token the same way, so its body is dropped too, keeping only the `key:` line itself. + An `if:` body is kept, since its value is always an expression and a multi-line one is written `if: >-`. """ out = [] skip_indent = None @@ -1949,7 +1951,8 @@ def _code_view(text): key_col += dash.end() stripped = stripped[dash.end() :] if _BLOCK_SCALAR_KEY.match(stripped): - skip_indent = key_col + if not _IF_KEY.match(stripped): + skip_indent = key_col elif dash and _BARE_BLOCK_SCALAR.match(stripped): # A bare `- |` has no key, so its own boundary is the dash's column, not a key past it. skip_indent = dash_col @@ -3495,6 +3498,26 @@ def _selftest(): publish_contract, 1, ), + ( + "publish-release.yml stub carrying its publish condition in a folded if: >-", + publish_stub.replace( + " if: ${{ needs.plan.outputs.publish == 'true' && needs.validate.result == 'success' }}\n", + " if: >-\n" + " ${{ needs.plan.outputs.publish == 'true'\n" + " && needs.validate.result == 'success' }}\n", + ), + publish_contract, + 0, + ), + ( + "publish-release.yml stub naming the validation token only in a name: | body", + publish_stub.replace( + " name: Publish project release job\n", + " name: |\n needs.validate.result == 'success'\n", + ).replace(" && needs.validate.result == 'success'", ""), + publish_contract, + 1, + ), ( "publish-release.yml stub whose publish job ignores failed validation", publish_stub.replace(" && needs.validate.result == 'success'", ""), @@ -3745,6 +3768,16 @@ def _selftest(): " include:\n - |\n TOKEN\n", " include:\n - |", ), + ( + "a folded `if: >-` keeps its body, an expression rather than prose", + " publish:\n if: >-\n ${{ a\n && b }}\n uses: x\n", + " publish:\n if: >-\n ${{ a\n && b }}\n uses: x", + ), + ( + "a step's folded `- if: >-` keeps its body too", + " - if: >-\n ${{ a }}\n run: echo\n", + " - if: >-\n ${{ a }}\n run: echo", + ), ] for label, text, want in code_view_cases: got = _code_view(text) From a0173c1d606c49d8aecada959de9c29f67eea961 Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 27 Sep 2026 19:48:35 -0700 Subject: [PATCH 2/3] Fold a Kept if: Body Onto Its Key Line So a Wrapped Token Still Matches A folded scalar joins its lines with a space, so a condition wrapped inside the required token is still correct YAML. Keeping the body as separate lines left such a token unmatched. Co-Authored-By: Claude Opus 5.5 (1M context) --- spec/audit.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/spec/audit.py b/spec/audit.py index b6f6391e5..369507a3a 100755 --- a/spec/audit.py +++ b/spec/audit.py @@ -1930,12 +1930,21 @@ def _code_view(text): A block-scalar string value (`name: |` followed by indented text) can hide or fake a token the same way, so its body is dropped too, keeping only the `key:` line itself. An `if:` body is kept, since its value is always an expression and a multi-line one is written `if: >-`. + It is folded onto the key line, so a token the condition wraps across two lines still matches whole. """ out = [] skip_indent = None + fold_indent = None for ln in text.splitlines(): if ln.lstrip().startswith("#"): continue + if fold_indent is not None: + if not ln.strip(): + continue + if (len(ln) - len(ln.lstrip())) > fold_indent: + out[-1] += " " + ln.strip() + continue + fold_indent = None if skip_indent is not None: if ln.strip() and (len(ln) - len(ln.lstrip())) <= skip_indent: skip_indent = None # a dedent back to (or past) the key column ends the block body @@ -1951,7 +1960,9 @@ def _code_view(text): key_col += dash.end() stripped = stripped[dash.end() :] if _BLOCK_SCALAR_KEY.match(stripped): - if not _IF_KEY.match(stripped): + if _IF_KEY.match(stripped): + fold_indent = key_col + else: skip_indent = key_col elif dash and _BARE_BLOCK_SCALAR.match(stripped): # A bare `- |` has no key, so its own boundary is the dash's column, not a key past it. @@ -3509,6 +3520,17 @@ def _selftest(): publish_contract, 0, ), + ( + "publish-release.yml stub whose folded if: >- wraps inside the required token", + publish_stub.replace( + " if: ${{ needs.plan.outputs.publish == 'true' && needs.validate.result == 'success' }}\n", + " if: >-\n" + " ${{ needs.plan.outputs.publish == 'true' && needs.validate.result\n" + " == 'success' }}\n", + ), + publish_contract, + 0, + ), ( "publish-release.yml stub naming the validation token only in a name: | body", publish_stub.replace( @@ -3769,14 +3791,14 @@ def _selftest(): " include:\n - |", ), ( - "a folded `if: >-` keeps its body, an expression rather than prose", - " publish:\n if: >-\n ${{ a\n && b }}\n uses: x\n", - " publish:\n if: >-\n ${{ a\n && b }}\n uses: x", + "a folded `if: >-` keeps its body, folded onto the key line", + " publish:\n if: >-\n ${{ a\n\n && b }}\n uses: x\n", + " publish:\n if: >- ${{ a && b }}\n uses: x", ), ( "a step's folded `- if: >-` keeps its body too", " - if: >-\n ${{ a }}\n run: echo\n", - " - if: >-\n ${{ a }}\n run: echo", + " - if: >- ${{ a }}\n run: echo", ), ] for label, text, want in code_view_cases: From 71554faa4b7e69d4ef038b6f5c3627a66da3022e Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Sun, 27 Sep 2026 19:50:15 -0700 Subject: [PATCH 3/3] Scope the Code View Docstring to a Block-Scalar if: Body Co-Authored-By: Claude Opus 5.5 (1M context) --- spec/audit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/audit.py b/spec/audit.py index 369507a3a..318ea205c 100755 --- a/spec/audit.py +++ b/spec/audit.py @@ -1929,7 +1929,8 @@ def _code_view(text): both false-pass a missing handoff and false-flag a forbidden token that appears only in a comment. A block-scalar string value (`name: |` followed by indented text) can hide or fake a token the same way, so its body is dropped too, keeping only the `key:` line itself. - An `if:` body is kept, since its value is always an expression and a multi-line one is written `if: >-`. + A block-scalar `if:` body, the form the Workflow YAML convention sets for a multi-line condition, is kept, + since an `if:` value is always an expression. It is folded onto the key line, so a token the condition wraps across two lines still matches whole. """ out = []