Skip to content

test: add strict managed workflow expression evaluator - #1960

Merged
gerchowl merged 11 commits into
devfrom
feature/1959-expression-evaluator
Oct 29, 2026
Merged

gerchowl merged 11 commits into
devfrom
feature/1959-expression-evaluator

Conversation

@gerchowl

@gerchowl gerchowl commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a strict GitHub Actions expression evaluator so test tooling can execute the managed workflows' runner wiring. Unknown syntax raises with the whole expression and position, even in short-circuited branches. Case-insensitive lookup closes a fork-safety regression that previously went undetected.

Type of Change

  • test -- Adding or updating tests

Modifiers

  • Breaking change (!)

Changes Made

  • Add evaluate(expression, context), typed render(value, context) for runs-on, and string-valued render_input(value, context) for step/reusable-job with values. The JSON CLI is python -m tests.github_expression --context ctx.json --expr '...'; --input stringifies its result. Context-file errors exit 2 without a traceback.
  • Place the helper in tests/ beside workflow_scaffold.py and nix_helpers.py: shared pytest/bats infrastructure belongs here; packages/vig-utils ships consumer utilities. Document usage and strict limits in the module docstring.
  • Support the managed subset: context/property lookups, literal string indexing with runner array conversion/floor/bounds semantics, double-valued literals, grouping, logical/equality operators, interpolation, and case-insensitive fromJSON/toJSON function names. Other functions, numeric/dynamic indexing, and filters raise.
  • Resolve property names case-insensitively and reject ambiguous object keys. Reject non-standard JSON constants; treat context NaN as falsy; use per-character simple uppercase mappings for OrdinalIgnoreCase equality and property matching. Keep keyword literals lowercase per the runner lexer. Use one number parser for hex literals and coercion, rejecting invalid/overflowing hex literals and preserving signed Int32 values. Match double precision, G15 formatting and negative zero. Reject non-finite numeric CLI results (exit 2) to keep stdout valid JSON; name unsupported YAML scalar types accurately.
  • Match toJSON output with two-space indentation, LF newlines, compact empty collections, G15 scalar numbers, and Newtonsoft string escaping. Tests cite GitHub documentation and the runner/Newtonsoft source used for exact formatting.
  • Evaluate every shipped runs-on, resolve-step with, and reusable-job with value for fork PR, same-repo PR, and push contexts, with runner variables set/unset. Mutation tests copy workflows and prove that the exact mixed-case fork escape and a reusable-input contains call fail the gate.
  • Audit of runs-on/with/env (including reusable jobs and devkit-upgrade step env) at origin/dev and 1.18.0 found bracket indexing only in origin/dev release-core.yml runs-on. Keep literal string indexes and implement the runner Index.cs array behavior; numeric/dynamic indexes and filters stay outside the managed subset.
  • No workflow/action or S8 consumer-matrix changes; lane-mapping assertions remain S8's responsibility.

Changelog Entry

No changelog needed: internal test tooling with no user-visible impact; CLAUDE.md requires test changelog entries for user-visible impact.

Testing

  • Touched tests pass locally
  • Manual testing performed

Manual Testing Details

  • TDD history retains the original RED commits. Round-two RED: 33 failed, 63 passed (exit 1), committed as dbe30e27 before implementation. Authorized toJSON RED: 53 failed, 95 passed (exit 1). A tokenizer quote regression separately failed twice before its fix.
  • Round-three RED: 23 failed, 154 passed (exit 1), committed before implementation; regressions cover hex literals, string array indexes, Unicode ordinal mapping, double precision, negative zero, CLI JSON and YAML date diagnostics.
  • Final uv run --with pytest-xdist pytest tests/test_github_expression.py -n 4 --basetemp=$HOME/.cache/devkit-pytest/1959-r3: 177 passed, exit 0.
  • ruff check, ruff format --check, and git diff --check: exit 0. Commits run inside nix develop with hooks enabled.
  • Exact-output tests cover nested objects, arrays, empty collections, quoted Unicode strings, Unicode line separators, null, booleans, numbers, and mixed-case function names. Subprocess tests cover both CLI output modes and missing/unreadable/invalid/non-object context files.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (module docstring; generated docs unaffected)
  • I have updated CHANGELOG.md (internal test tooling; see above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing touched unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Prerequisite for S8 (#1935 / #1958). The expanded review requirements bring the helper and tests to 764 lines, exceeding the approximately 450-line target; coverage has been retained as directed by the review briefs. No full-suite local run on the shared host; pushed-head CI is the final gate.

Refs: #1959

Keep shared test tooling beside workflow_scaffold.py and expose a JSON CLI for bats. Support literal string indexes and secrets lookups required by shipped workflows.

Refs: #1959
Resolve context and JSON properties without case sensitivity and reject ambiguous keys. Add exact toJSON serialization, strict JSON constants, input strings, whole-value diagnostics, and clean CLI context errors.

Refs: #1959
Share the runner number parser between literals and coercion, preserve doubles and signed zero, and apply string array indexes with conversion and bounds checks. Use simple uppercase mappings for equality and properties, reject non-finite CLI JSON, and name unsupported input types.

Refs: #1959
@gerchowl
gerchowl merged commit ff96ee4 into dev Oct 29, 2026
16 checks passed
@gerchowl
gerchowl deleted the feature/1959-expression-evaluator branch October 29, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant