Skip to content

fix: move CI workflow validation out of Worker (#472) - #493

Merged
neuromechanist merged 3 commits into
devfrom
feature/issue-472-cli-poll-ci-validation
May 14, 2026
Merged

neuromechanist merged 3 commits into
devfrom
feature/issue-472-cli-poll-ci-validation

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Move the post-deploy parseability check out of the Cloudflare Worker. The previous design slept 2.5 s inside deployWorkflows() and retried once after another 5 s, burning ~7.5 s of wall-clock budget per call and requiring a --no-validate workaround for fleet deploys.

  • backend
    • deployWorkflows() commits and returns immediately. Drops validate / validateDelayMs options and validationErrors from the return.
    • New validateDeployedWorkflows() helper does a single GET against /actions/workflows (no sleep).
    • New endpoint POST /admin/datasets/:id/ci/validate exposes the helper.
    • POST /admin/datasets/:id/ci no longer surfaces validation_warnings in its response or audit log; the legacy ?validate=false query param is accepted but ignored for old-CLI compatibility.
  • CLI
    • After addCi() returns, poll validateCi() with [2.5 s, 5 s] backoff (the old worker timing, now client-side).
    • New nemar admin ci validate <id> subcommand for an explicit re-probe.
    • --all fleet deploys skip the poll by default — the per-dataset wait was the original motivation for --no-validate. --no-validate flag stays for the single-dataset path (no-ops when set).
  • tests
    • tree-batched-commit.test.ts now asserts deployWorkflows() makes exactly 4 GitHub calls (no listing). The three former in-Worker validation tests moved to a new describe('validateDeployedWorkflows', ...) block that exercises the helper directly (all-listed, partial listing, 500 error path).

Closes #472. (Follow-up from PR #469.)

Test plan

  • bun test test/tree-batched-commit.test.ts — 24/24 pass
  • bun test test/tree-batched-commit.test.ts test/config-migrate-api-url.test.ts test/publish-progress.test.ts — 37/37 pass
  • cd backend && bun test — 74/74 pass
  • bun run build — green
  • tsc --noEmit for CLI and backend — green
  • CLI smoke: bun dist/index.js admin ci --help shows the new validate subcommand

deployWorkflows() ran a 2.5 s sleep + GET /actions/workflows inside the
Cloudflare Worker and retried once after another 5 s if anything was
missing. That burned ~7.5 s of wall-clock budget per call and forced a
--no-validate workaround for fleet deploys.

Split the responsibilities:

- backend: deployWorkflows() commits and returns immediately. New
  validateDeployedWorkflows() helper does one parseability probe with
  no sleep. New POST /admin/datasets/:id/ci/validate endpoint exposes
  it. POST /admin/datasets/:id/ci no longer accepts ?validate=false
  (silently ignored for old CLIs) and no longer surfaces
  validation_warnings in the response or audit log.
- CLI: after addCi() returns, poll validateCi() with 2.5 s then 5 s
  backoff. Same surface area as before, sleep on the user's machine
  now. Added 'nemar admin ci validate <id>' for an explicit re-probe.
  --all fleet deploys skip the poll by default (the per-dataset wait
  was the original motivation for the --no-validate flag).
- tests: tree-batched-commit.test.ts now asserts deployWorkflows()
  makes exactly 4 calls (no listing) and exercises the new
  validateDeployedWorkflows() helper independently.

Closes #472
@github-actions

github-actions Bot commented May 14, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR493

Version: 0.8.15-PR493.0692d29
Commit: 0692d29


🤖 Updated on each push.

- admin.ts (fleet path): replace the misleading 'Pass --validate to
  override' comment. The --all path always skips the parseability
  poll; --no-validate is a no-op on that path. The help text and a
  new dim UI line make this explicit.
- admin.ts (poll helper): rename loop var to use for...of; extract
  pollCiValidation into an exported function with an injected
  ValidationProbe so the polling state machine is unit-testable
  without a fake backend. Default probe wraps validateCi(); existing
  call site uses the default.
- admin.ts (single-dataset path): distinguish the warn message
  between 'workflows missing' and 'GitHub API error' — they are
  independent conditions and the previous wording falsely implied
  missing when only errors were populated.
- backend/services/github.ts: amend validateDeployedWorkflows JSDoc.
  'No retries' was misleading — githubFetchWithRetry retries 5xx up
  to 3 times internally; only the outer indexing-lag retry is gone.
- backend/routes/admin.ts: document the conscious POST verb choice
  on /ci/validate. Strict REST would favor GET but the rest of the
  ci/* family is POST (deploy, sync) and a mixed-verb family would
  surprise admin tooling that scripts these endpoints.
- test/admin-restructure.test.ts: assert the new 'validate'
  subcommand appears in 'admin ci --help' so future refactors can't
  silently drop it.
- test/poll-ci-validation.test.ts: 6 new unit tests covering early
  stop on all-clear, early stop on errors, retry on missing-only,
  loop exhaustion, network-throw → null, and backoff cadence.
  Uses a queued probe injected via the new optional parameter; no
  fake server.

Review findings: #493
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review triage (from /pr-review-toolkit:review-pr + single-reviewer pass)

Severity Finding Action
Important Misleading "Pass --validate to override" comment on fleet path; skipValidate was computed but never consulted Fixed in 4b60099 — comment rewritten; help text updated; --all path now prints a dim "poll skipped for --all" line so behavior is explicit
Important POST /ci/validate should arguably be GET (read-only) Decision: keep POST. Added route-level doc explaining the conscious choice — ci/* family is POST (deploy, sync) and a mixed-verb family would surprise admin tooling scripting these endpoints
Important admin ci --help test doesn't assert validate subcommand Fixed in 4b60099 — admin-restructure.test.ts now also asserts sync and validate
Suggestion validateSpinner.warn imprecise when only errors populated Fixed — distinguish "workflows missing" vs "GitHub API error" wording
Suggestion pollCiValidation for-loop index i unused Fixed — switched to for...of
Suggestion JSDoc on validateDeployedWorkflows says "no retries" but githubFetchWithRetry has internal 5xx retries Fixed — JSDoc now distinguishes outer (gone) vs transport (internal) retries
Suggestion pollCiValidation polling state machine untested Added test/poll-ci-validation.test.ts — 6 tests covering early-stop on all-clear, early-stop on errors, retry on missing-only, loop exhaustion, throw→null, backoff cadence. Uses injected probe (new exported ValidationProbe type) so no fake backend needed
Pre-existing Old CLIs read validation_warnings from response; field is now absent Already analyzed in review: old CLI does r.validation_warnings && r.validation_warnings.length > 0 — undefined short-circuits, silent acceptable degradation. New CLIs hitting an old backend that lacks /ci/validate get 404 → pollCiValidation catches → returns null → "Could not verify" warning. Graceful both ways
Pre-existing Audit-log validation_warnings dropped No audit consumer reads it (best-effort annotation). Non-critical

@neuromechanist
neuromechanist merged commit b6b953d into dev May 14, 2026
9 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-472-cli-poll-ci-validation branch May 18, 2026 11:11

This branch was previously deployed

1 inactive deployment
npm — 0692d295 Deployed May 14, 2026 by neuromechanist via publish #892
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