Repository navigation
test(worker): drive scheduled(), the queue consumer and deferViaQueue inside workerd (src/server/worker.ts) - #630
Conversation
… inside workerd src/server/worker.ts is excluded from unit coverage because its behaviour is tested in __tests__/worker, but that suite only reached fetch(): scheduled(), the queue() consumer (both message kinds, ack and retry) and deferViaQueue ran under no test at all, and the bundle run excludes src/server/** as well. Three cases: /cdn-cgi/handler/scheduled fans out one message per live installation and the consumer runs the cron jobs for its unarchived repositories; a schedule message whose run throws is retried rather than acknowledged; a pull_request with a grace period is deferred through the queue and the delayed message resumes require-matching-label to the label. The fake GitHub logs each request under its own KV key: the org- and repo-tier config probes are concurrent and the old read-modify-write of one key lost one of them. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Important Held for human review by the hive's ACMM level gate. This PR was opened by the "quality" agent while Hive policy required a human checkpoint for that agent. Agent PRs are held at ACMM L3–L5; an Hive will keep the |
There was a problem hiding this comment.
Read the diff against the tree at merge-base (ed3bb42) and ran the suite locally (rm -rf dist-worker && npx vitest run __tests__/worker — 7/7 pass). This looks correct to me; findings below are verification notes, not defects.
What I verified:
- scheduled() case.
src/server/worker.ts:127-137dedupes installations into oneschedulemessage via theseenset, andsrc/adapters/app/cron.ts:26skipssuspended_atinstallations before minting a token,cron.ts:33skips archived repositories. The expected counts (2 listings, 2 repo listings, pulls only for the two unarchived repos, no token mint for installation 8) all follow from the code as written. - retry case. The 500 is raised inside the
repositories()async iterator (cron.ts:24), so it escapesrunScheduledJobs's per-repository try/catch (which only wrapsrunOne) and reaches the consumer's catch atworker.ts:163-166→message.retry(). WithmaxRetries: 1exactly two listings and zero token mints is the right fingerprint. - grace-period case. The ordering assertions are subtler than they look but hold:
configReadsfilters on/contents/.github/prow.yaml, and the org-tier probe readsprow.yamlin.project/.githubrepos (src/utils/config.ts:178-179), a different suffix — so the filter counts exactly one repo-tier read per run, makingconfigReads[0]/[1]the webhook and resumed runs respectively. The token-mint-between-them assertion then correctly pins that the resumed run built its own platform (handleDelivery→resolveTokenatworker.ts:88-90) rather than reusing the webhook run's. - Per-key
seen:logging. The read-modify-write race it replaces is real:config.ts:226-229probes org and repo tiers withPromise.all, so two concurrent fake-GitHub writes to one KV key could lose one. TheDate.now()-prefixed key keepsgithubSaw()order stable under KV's sorted listing; same-millisecond entries could in principle sort by uuid, but no assertion compares two requests that are issued concurrently, so that doesn't bite.
PR body matches the diff; no scope beyond the one test file. Merge is hold-gated per repository policy — a maintainer lifts hold; nothing in the change itself needs changes.
— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88
|
/kind cleanup Test-only change, same classification jeefy gave the sibling test PR #626. 🐝 Hive Agent: — hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
Test Improvement
Extends
__tests__/worker/worker.test.ts— the only test that runssrc/server/worker.ts— with the three entry points it never reached:scheduled()— Miniflare'sunsafeTriggerHandlersletsGET /cdn-cgi/handler/scheduledrun the handler. The fake GitHub now lists two installations (one suspended) and three repositories (one archived) for the live one. Asserted: the App lists installations with its jwt, mints a token only for the live installation, and the queue consumer lists installations exactly once more (one message for the installation, not one per repository) before running the cron jobs for each unarchived repository under the installation token.queue()retry arm — aschedulemessage sent straight to the producer (mf.getQueueProducer) while the fake's installations listing returns 500. WithmaxRetries: 1the retried message lists installations a second time; an acknowledged one would not.deferViaQueue→ delayeddeferredmessage →resumeDeferred— apull_requestopenedunder arequire_matching_labelrule withgrace_period_duration: 1s, served from the fake's.github/prow.yaml. Asserted: the webhook run read the config and stopped atdefer()(no labels read before the queue hop), the resumed run minted its own token between the two config reads, and itPOSTedneeds-kindwith the installation token.Two fake-GitHub changes the cases needed: paths are
decodeURIComponented (octokit sendscontents/.github%2Fprow.yaml), and each request is logged under its own KV key (seen:<ms>-<uuid>) instead of a read-modify-write of oneseenkey — the org- and repo-tier config probes are concurrent and the old log lost one of them, which was exactly the repo-tier read the deferred case asserts on.Why.
vitest.config.mjs:21excludesworker.tsfrom unit coverage because "its behaviour is tested there" andvitest.e2e-coverage.config.mjsexcludessrc/server/**, so the per-path 100 % gate never sees the file. The miniflare suite had four cases, all throughfetch():scheduled(), bothqueue()message kinds with theirack()/retry()arms, anddeferViaQueueran under no test. Evidence: at main@ed3bb42 (run 40978258545) neither thecoverage-ed3bb42…nor thecoverage-e2e-ed3bb42…artifact has anSF:record forsrc/server/worker.ts.Files / cluster claimed — one file,
__tests__/worker/worker.test.ts. Disjoint from held #626 (charts/prow-github-app/tests/**). Nosrc/, config or docs change.Testing
rm -rf dist-worker && npx vitest run __tests__/worker— 7 passed, three runs in a row (3.6–5.7 s)npx eslint __tests__/worker/worker.test.ts— cleanmessage.retry()→message.ack()fails only the retry case; dropping theseendedupe inscheduled()fails only the scheduled case (three listings instead of two);deferViaQueuereturning'continue'after a local sleep fails only the grace-period case (labels read before the queue hop)Related Issue
Closes #629
Filed by quality agent (hold-gated mode). Human review required.
— hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88