Skip to content

refactor(ci): move PR E2E gate polling and download into the controller - #6995

Merged
cv merged 7 commits into
mainfrom
refactor/pr-e2e-gate-wait-download-modes
Jul 16, 2026
Merged

cv merged 7 commits into
mainfrom
refactor/pr-e2e-gate-wait-download-modes

Conversation

@laitingsheng

@laitingsheng laitingsheng commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The PR E2E gate controller workflow still ran a run-state polling loop and an evidence download wrapper as inline shell in its coordinate job. Both move into the already-testable controller as --mode wait and --mode download entrypoints, following the #6952 effort to keep executable logic out of Actions YAML. The workflow keeps triggers, permissions, concurrency, artifact upload, step conditions, and always-run finalization. Behaviour is preserved end to end.

Related Issue

Resolves #6960
Part of #6952

Changes

  • tools/e2e/pr-e2e-gate.mts: add --mode wait, which polls the child run through the existing REST client, logs each state change once, reports the child-run URL, treats the nine terminal conclusions as completion, fails closed on an unknown state or query error, and returns after a 105-minute budget so finalization cancels and reports. Add --mode download, which runs gh run download into the private evidence workspace under a Node-enforced 10-minute timeout (SIGTERM then SIGKILL), failing when the download times out or exits non-zero. Both parse and dispatch through the existing command model; the timeout and destination are the current requirement carried over from the shell steps, covered by the direct controller tests below.
  • .github/workflows/pr-e2e-gate.yaml: replace the inline polling loop and download wrapper with the two controller invocations. Workspace creation, risk-plan upload, evidence verification, incomplete-check finalization, and workspace removal stay in YAML.
  • Tests: direct controller coverage for the poll state machine and bounded download in pr-e2e-gate.test.ts; wait/download parsing in pr-e2e-gate-command.test.ts; a step-ordering and always-run finalization contract in pr-e2e-gate-workflow.test.ts (registered in the source-shape budget).

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: internal CI controller relocation with no user-facing behaviour or documented interface change.
  • Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging)
  • Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: the write-capable E2E gate controller is a trust boundary; this change relocates polling and download logic without altering permissions, run states, timeouts, evidence destination, or finalization, and every path is covered by the controller and workflow contract tests — awaiting maintainer sensitive-path review.
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • Normal pre-commit, commit-msg, and pre-push hooks passed, or npm run check:diff passed when hooks were skipped or unavailable
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — command/result: npx vitest run on the pr-e2e-gate command/controller/workflow/lifecycle/shards and source-shape-scanner suites → 110 passed; npm run typecheck:cli → pass; node find-source-shape-tests.mts --check → pass; Biome check → clean (Node 22.22).
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result:
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Tinson Lai [email protected]

Summary by CodeRabbit

  • New Features
    • Added dedicated controller coordination modes for waiting on child run completion and downloading child run evidence.
  • Bug Fixes
    • Improved CI e2e gate robustness with stronger run-id validation, clearer terminal-state handling, and safer evidence workspace cleanup.
    • Enhanced timeout and process termination behavior during evidence download.
  • Tests
    • Expanded command parsing and end-to-end coverage for wait/download flows, including timeout, error, and permission scenarios.
  • Chores
    • Updated CI workflow to use shared coordination tooling for consistency.

Signed-off-by: Carlos Villela [email protected]

The coordinate job embedded a run-state polling loop and an evidence
download wrapper in shell. Both now run as dedicated `--mode wait` and
`--mode download` controller entrypoints, leaving the workflow
responsible for triggers, permissions, artifact upload, step
conditions, and always-run finalization.

Behaviour is unchanged: the same active and terminal run states, the
105-minute wait budget that defers to finalization, a 10-minute bounded
evidence download into the private workspace, and check finalization on
every failure or cancellation path.

Signed-off-by: Tinson Lai <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR moves PR E2E child-run polling and evidence downloading from workflow shell scripts into pr-e2e-gate.mts, adds controller modes and direct tests, and updates workflow tests for delegation, ordering, always-run finalization, and private-workspace cleanup.

Changes

PR E2E gate coordination

Layer / File(s) Summary
Controller modes and path validation
tools/e2e/pr-e2e-gate.mts, test/pr-e2e-gate-command.test.ts
Adds validated wait and download command modes, including private workspace path parsing and validation tests.
Child-run polling and evidence download
tools/e2e/pr-e2e-gate.mts, tools/advisors/github.mts, test/pr-e2e-gate-run-wait.test.ts
Implements GitHub status polling and bounded gh run download execution with abort, terminal-state, timeout, process, and exit handling, with direct tests.
Workflow delegation and finalization coverage
.github/workflows/pr-e2e-gate.yaml, test/pr-e2e-gate-workflow.test.ts, ci/source-shape-test-budget.json
Replaces inline wait/download scripts with controller invocations and verifies step ordering, always-run finalization, cleanup, and updated workflow contracts.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Workflow as pr-e2e-gate.yaml
  participant Controller as pr-e2e-gate.mts
  participant GitHubAPI as GitHub Actions API
  participant GHCLI as gh run download
  Workflow->>Controller: invoke wait with controller run_id
  Controller->>GitHubAPI: poll child run status
  GitHubAPI-->>Controller: return status and conclusion
  Workflow->>Controller: invoke download with run_id and work_dir
  Controller->>GHCLI: download evidence
  GHCLI-->>Controller: return completion or exit status
Loading

Suggested labels: area: e2e

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR moves polling/download into the controller, removes inline polling, adds tests, and preserves timeout, error, and cleanup behavior.
Out of Scope Changes check ✅ Passed The GitHub abort-signal support and test-budget tweak directly support the new controller polling/download work.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: moving PR E2E gate polling and evidence download into the controller.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/pr-e2e-gate-wait-download-modes

Comment @coderabbitai help to get the list of available commands.

@github-code-quality

github-code-quality Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage remains at 96%, unchanged from the main branch.

TypeScript / code-coverage/cli

The overall coverage in the refactor/pr-e2e-gate... branch remains at 80%, unchanged from the main branch.

Show a code coverage summary of the most impacted files.
File main c1bda80 refactor/pr-e2e-gate... 71a7a33 +/-
src/lib/state/gateway.ts 93% 91% -2%
src/lib/securit...ntial-filter.ts 98% 99% +1%

Updated July 16, 2026 08:14 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

Comment thread test/pr-e2e-gate-run-wait.test.ts Fixed
@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Review Advisor — Informational

Advisor assessment: Informational / high confidence
Next action: No advisor follow-up needed.
Findings: 0 blockers · 0 warnings · 0 suggestions
Status: No actionable findings remain in the canonical review ledger.

Model lanes

  • GPT-5.6 Terra (primary): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Model comparison: normalized findings match; normalized E2E selections differ; severity counts match.

Nemotron output stays in workflow artifacts and does not change the assessment above.

E2E guidance

Advisory only. E2E / PR Gate selects and runs jobs independently.

Recommended E2E: cloud-onboard, credential-sanitization, security-posture

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

@laitingsheng laitingsheng added the refactor PR restructures code without intended behavior change label Jul 16, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
test/pr-e2e-gate-workflow.test.ts (1)

650-662: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the required relative ordering, not the entire step inventory.

This exact eleven-element array makes unrelated setup-step additions or renames break the security contract test. Locate the relevant steps and assert wait < evidence < finish < abandon < cleanup, leaving the existing always() assertions to enforce finalization.

As per path instructions, prefer observable outcomes through the public boundary over implementation lock-in.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/pr-e2e-gate-workflow.test.ts` around lines 650 - 662, Replace the exact
full-array assertion in the coordinate step test with assertions that locate the
relevant steps by name and verify the required relative ordering: “Wait for E2E
run” before “Download evidence,” then “Verify evidence,” “Close incomplete
check,” and “Remove private workspace.” Preserve the existing always()
assertions for finalization and avoid asserting unrelated step inventory or
exact names beyond these contract steps.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/pr-e2e-gate-run-wait.test.ts`:
- Around line 147-166: Update the timeout and non-zero evidence-download tests
around downloadChildRunEvidence to exercise the real process lifecycle rather
than mocking its final run result. Inject or mock the underlying spawn/process
runner while preserving timeout, SIGTERM/SIGKILL escalation, spawn-error,
close-event, and timer-cleanup behavior, and assert the relevant lifecycle
actions and non-zero closure.

In `@tools/e2e/pr-e2e-gate.mts`:
- Around line 1756-1764: Update the status request in the child-run polling flow
around githubApi and childRunId so each request receives an abort signal or
timeout capped by the remaining 105-minute deadline (deadline minus the current
time). Ensure a stalled fetch is aborted when the budget expires while
preserving the existing controllerErrorMessage handling for request failures.

---

Nitpick comments:
In `@test/pr-e2e-gate-workflow.test.ts`:
- Around line 650-662: Replace the exact full-array assertion in the coordinate
step test with assertions that locate the relevant steps by name and verify the
required relative ordering: “Wait for E2E run” before “Download evidence,” then
“Verify evidence,” “Close incomplete check,” and “Remove private workspace.”
Preserve the existing always() assertions for finalization and avoid asserting
unrelated step inventory or exact names beyond these contract steps.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0387a8d3-b05a-4a47-80c3-229714ec545f

📥 Commits

Reviewing files that changed from the base of the PR and between 3bc9620 and bda354f.

📒 Files selected for processing (6)
  • .github/workflows/pr-e2e-gate.yaml
  • ci/source-shape-test-budget.json
  • test/pr-e2e-gate-command.test.ts
  • test/pr-e2e-gate-run-wait.test.ts
  • test/pr-e2e-gate-workflow.test.ts
  • tools/e2e/pr-e2e-gate.mts

Comment thread test/pr-e2e-gate-run-wait.test.ts Resolved
Comment thread tools/e2e/pr-e2e-gate.mts Resolved
Bounds each child-run status request to the remaining wait budget via
an abort signal instead of letting a stalled fetch outlive the
controller deadline. Exercises the evidence download's real
SIGTERM/SIGKILL timeout escalation, timer cleanup, and spawn-error
handling in tests instead of stubbing the process runner outright.
Replaces a substring URL check in the wait-budget test with an exact
log-line match to avoid an incomplete-URL-sanitization pattern.

Signed-off-by: Tinson Lai <[email protected]>

@cv cv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at exact head 71a7a33600e7ad093e22a061cd0320ddc6ce83b2 against base c1bda8069d95a84a9e16b0d292a5fe20ce7cea7d. All 51 current checks are green; exact credentialed E2E controller run 29482793330 and child run 29482821192 succeeded; DCO and all seven commits are GitHub Verified; security review and focused controller/E2E-support tests found no blocking issue. The final empty commit only refreshed evidence and has the same tree as its parent.

@cv
cv merged commit b528371 into main Jul 16, 2026
52 checks passed
@cv
cv deleted the refactor/pr-e2e-gate-wait-download-modes branch July 16, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor PR restructures code without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move PR E2E gate polling and evidence handling into tools/e2e

3 participants