From 2a07d88aefe5b73df0e9720d441be3fa052d7b51 Mon Sep 17 00:00:00 2001 From: abrichr Date: Sat, 10 Oct 2026 00:11:02 -0400 Subject: [PATCH 1/2] fix(ci): make the weekly-digest dry_run input actually dry run The workflow_dispatch input `dry_run` is declared `type: boolean`, so `inputs.dry_run` is a real boolean. The publish step compared it with the string 'true'. GitHub's expression engine converts both sides to numbers for that comparison (true is 1, 'true' is NaN), so it was always false. A manual run with "Dry run (preview only)" checked ran `herald publish` without `--dry-run` and posted to Discord, and to X and LinkedIn when those secrets are set. Pass the flag from the boolean directly, and also set HERALD_DRY_RUN from it so the CLI's own setting enforces the dry run if the flag is ever lost. Scheduled runs have no inputs, so they still post the weekly digest. Add tests/test_workflows.py, which fails if any workflow compares a boolean input with a quoted string, and checks that the publish step passes dry run to herald both ways. Ledger: B249 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-announce.yml | 5 +- tests/test_workflows.py | 92 ++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/test_workflows.py diff --git a/.github/workflows/release-announce.yml b/.github/workflows/release-announce.yml index dce6b68..faddafe 100644 --- a/.github/workflows/release-announce.yml +++ b/.github/workflows/release-announce.yml @@ -77,9 +77,12 @@ jobs: HERALD_LINKEDIN_ACCESS_TOKEN: ${{ secrets.HERALD_LINKEDIN_ACCESS_TOKEN }} HERALD_REPOS: "OpenAdaptAI/OpenAdapt,OpenAdaptAI/openadapt-evals,OpenAdaptAI/openadapt-ml" HERALD_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # inputs.dry_run is a boolean, so use it directly. Comparing it with the + # string 'true' is always false. Scheduled runs have no inputs, so this is 'false'. + HERALD_DRY_RUN: ${{ inputs.dry_run && 'true' || 'false' }} run: | herald publish \ --content-type ${{ steps.params.outputs.type }} \ --days ${{ steps.params.outputs.days }} \ --embed-title "Weekly Digest" \ - ${{ inputs.dry_run == 'true' && '--dry-run' || '' }} + ${{ inputs.dry_run && '--dry-run' || '' }} diff --git a/tests/test_workflows.py b/tests/test_workflows.py new file mode 100644 index 0000000..475b55c --- /dev/null +++ b/tests/test_workflows.py @@ -0,0 +1,92 @@ +"""Tests for the GitHub Actions workflows. + +A ``workflow_dispatch`` input declared ``type: boolean`` reaches expressions as +a real boolean through the ``inputs`` context. Comparing it with a quoted +string such as ``'true'`` is always false: the expression engine converts both +sides to numbers, so ``true`` becomes 1 and ``'true'`` becomes NaN. A check +written that way silently ignores the input. + +These tests read the workflow files as text so they need no YAML parser. +""" + +import re +from pathlib import Path + +import pytest + +WORKFLOWS_DIR = Path(__file__).resolve().parents[1] / ".github" / "workflows" +WORKFLOW_FILES = sorted(WORKFLOWS_DIR.glob("*.y*ml")) +RELEASE_ANNOUNCE = WORKFLOWS_DIR / "release-announce.yml" + +_EXPRESSION = re.compile(r"\$\{\{(.*?)\}\}", re.DOTALL) +_KEY = re.compile(r"([A-Za-z0-9_-]+)\s*:") +_BOOLEAN_TYPE = re.compile(r"""type\s*:\s*["']?boolean["']?\s*(#.*)?$""") + + +def _boolean_inputs(text: str) -> set[str]: + """Return the names of the inputs declared ``type: boolean``. + + Walks the file by indentation. The input name is the closest key above the + ``type: boolean`` line with less indentation, and that key's own parent + must be ``inputs``. + """ + names: set[str] = set() + stack: list[tuple[int, str]] = [] + for line in text.splitlines(): + stripped = line.strip() + if not stripped or stripped.startswith("#"): + continue + indent = len(line) - len(line.lstrip(" ")) + while stack and stack[-1][0] >= indent: + stack.pop() + if _BOOLEAN_TYPE.fullmatch(stripped) and len(stack) >= 2 and stack[-2][1] == "inputs": + names.add(stack[-1][1]) + key = _KEY.match(stripped) + if key: + stack.append((indent, key.group(1))) + return names + + +def _string_comparisons(text: str, name: str) -> list[str]: + """Return the expressions that compare ``inputs.`` with a quoted string.""" + ref = rf"(? str: + """Return the text of the "Publish announcements" step.""" + match = re.search(r"- name: Publish announcements\n(.*?)(?=\n\s*- name:|\Z)", text, re.DOTALL) + assert match, "release-announce.yml has no 'Publish announcements' step" + return match.group(1) + + +def test_release_announce_declares_dry_run_as_boolean(): + # Guards the text walker below: if it stops finding this input, the + # comparison test would pass without checking anything. + assert "dry_run" in _boolean_inputs(RELEASE_ANNOUNCE.read_text()) + + +@pytest.mark.parametrize("workflow", WORKFLOW_FILES, ids=lambda p: p.name) +def test_boolean_inputs_are_not_compared_with_strings(workflow): + text = workflow.read_text() + offending = [ + expr for name in sorted(_boolean_inputs(text)) for expr in _string_comparisons(text, name) + ] + assert offending == [], ( + f"{workflow.name} compares a boolean input with a string, which is always false. " + f"Use the input directly, for example `inputs.dry_run && '--dry-run' || ''`: {offending}" + ) + + +def test_publish_step_passes_dry_run_to_herald(): + step = _publish_step(RELEASE_ANNOUNCE.read_text()) + # The command-line flag. + assert re.search(r"\$\{\{\s*inputs\.dry_run\s*&&\s*'--dry-run'\s*\|\|\s*''\s*\}\}", step) + # The HERALD_DRY_RUN setting, so a dry run stays a dry run even if the flag is lost. + assert re.search( + r"HERALD_DRY_RUN:\s*\$\{\{\s*inputs\.dry_run\s*&&\s*'true'\s*\|\|\s*'false'\s*\}\}", step + ) From 455427f2624dcdcac16af107eac97fef04e6122e Mon Sep 17 00:00:00 2001 From: abrichr Date: Sat, 10 Oct 2026 00:19:50 -0400 Subject: [PATCH 2/2] test(ci): also catch bare if: conditions that compare a boolean input GitHub evaluates an `if:` value as an expression even without `${{ }}` around it, so `if: inputs.dry_run == 'true'` has the same always-false bug. The workflow check only scanned `${{ }}` blocks and missed it. Scan bare `if:` values too, and add a test that runs the finder on an inline workflow with each comparison form, so the check cannot silently stop detecting them. Ledger: B249 Co-Authored-By: Claude Opus 5.5 --- tests/test_workflows.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 475b55c..6e80223 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -19,6 +19,8 @@ RELEASE_ANNOUNCE = WORKFLOWS_DIR / "release-announce.yml" _EXPRESSION = re.compile(r"\$\{\{(.*?)\}\}", re.DOTALL) +# An `if:` condition is an expression even without `${{ }}` around it. +_BARE_IF = re.compile(r"^[ \t]*(?:-[ \t]+)?if[ \t]*:[ \t]*(.+)$", re.MULTILINE) _KEY = re.compile(r"([A-Za-z0-9_-]+)\s*:") _BOOLEAN_TYPE = re.compile(r"""type\s*:\s*["']?boolean["']?\s*(#.*)?$""") @@ -54,7 +56,9 @@ def _string_comparisons(text: str, name: str) -> list[str]: rf"{ref}\s*[!=]=\s*['\"]|['\"]\s*[!=]=\s*{ref}", re.IGNORECASE, ) - return [m.group(0).strip() for m in _EXPRESSION.finditer(text) if compare.search(m.group(1))] + expressions = [m.group(0) for m in _EXPRESSION.finditer(text)] + expressions += [m.group(1) for m in _BARE_IF.finditer(text) if "${{" not in m.group(1)] + return [expr.strip() for expr in expressions if compare.search(expr)] def _publish_step(text: str) -> str: @@ -70,6 +74,31 @@ def test_release_announce_declares_dry_run_as_boolean(): assert "dry_run" in _boolean_inputs(RELEASE_ANNOUNCE.read_text()) +def test_string_comparison_check_covers_every_expression_form(): + # Guards the comparison finder: each of these forms ignores a boolean input. + workflow = """\ +on: + workflow_dispatch: + inputs: + dry_run: + type: boolean +jobs: + a: + steps: + - if: inputs.dry_run == 'true' + - if: ${{ 'true' != inputs.dry_run }} + - run: echo ${{ inputs.dry_run == "true" && 'x' || '' }} + - if: github.event.inputs.dry_run == 'true' + - if: inputs.dry_run +""" + assert _boolean_inputs(workflow) == {"dry_run"} + assert _string_comparisons(workflow, "dry_run") == [ + "${{ 'true' != inputs.dry_run }}", + "${{ inputs.dry_run == \"true\" && 'x' || '' }}", + "inputs.dry_run == 'true'", + ] + + @pytest.mark.parametrize("workflow", WORKFLOW_FILES, ids=lambda p: p.name) def test_boolean_inputs_are_not_compared_with_strings(workflow): text = workflow.read_text()