Skip to content

test(worker): drive scheduled(), the queue consumer and deferViaQueue inside workerd (src/server/worker.ts) - #630

Merged
mrbobbytables merged 1 commit into
mainfrom
quality/test-worker-queue-and-scheduled
Oct 31, 2026
Merged

mrbobbytables merged 1 commit into
mainfrom
quality/test-worker-queue-and-scheduled

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Extends __tests__/worker/worker.test.ts — the only test that runs src/server/worker.ts — with the three entry points it never reached:

  • scheduled() — Miniflare's unsafeTriggerHandlers lets GET /cdn-cgi/handler/scheduled run 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 — a schedule message sent straight to the producer (mf.getQueueProducer) while the fake's installations listing returns 500. With maxRetries: 1 the retried message lists installations a second time; an acknowledged one would not.
  • deferViaQueue → delayed deferred message → resumeDeferred — a pull_request opened under a require_matching_label rule with grace_period_duration: 1s, served from the fake's .github/prow.yaml. Asserted: the webhook run read the config and stopped at defer() (no labels read before the queue hop), the resumed run minted its own token between the two config reads, and it POSTed needs-kind with the installation token.

Two fake-GitHub changes the cases needed: paths are decodeURIComponented (octokit sends contents/.github%2Fprow.yaml), and each request is logged under its own KV key (seen:<ms>-<uuid>) instead of a read-modify-write of one seen key — 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:21 excludes worker.ts from unit coverage because "its behaviour is tested there" and vitest.e2e-coverage.config.mjs excludes src/server/**, so the per-path 100 % gate never sees the file. The miniflare suite had four cases, all through fetch(): scheduled(), both queue() message kinds with their ack()/retry() arms, and deferViaQueue ran under no test. Evidence: at main@ed3bb42 (run 40978258545) neither the coverage-ed3bb42… nor the coverage-e2e-ed3bb42… artifact has an SF: record for src/server/worker.ts.

Files / cluster claimed — one file, __tests__/worker/worker.test.ts. Disjoint from held #626 (charts/prow-github-app/tests/**). No src/, 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 — clean
  • Each new case fails against the mutation it claims to pin, with the bundle rebuilt each time: message.retry() → message.ack() fails only the retry case; dropping the seen dedupe in scheduled() fails only the scheduled case (three listings instead of two); deferViaQueue returning '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

… 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>
@hivecommons-hive
hivecommons-hive Bot requested a review from jpmcb as a code owner October 30, 2026 01:26
@hivecommons-hive hivecommons-hive Bot added the hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 30, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

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 outreach PR that targets a repository this hive does not manage is held at every level because it publishes project-facing communication into someone else's project.

Hive will keep the hold label until a human removes it. Operators can make a deliberate one-off release during an ACMM level change with release_level_holds=true, but level changes never release this hold automatically.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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-137 dedupes installations into one schedule message via the seen set, and src/adapters/app/cron.ts:26 skips suspended_at installations before minting a token, cron.ts:33 skips 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 escapes runScheduledJobs's per-repository try/catch (which only wraps runOne) and reaches the consumer's catch at worker.ts:163-166 → message.retry(). With maxRetries: 1 exactly two listings and zero token mints is the right fingerprint.
  • grace-period case. The ordering assertions are subtler than they look but hold: configReads filters on /contents/.github/prow.yaml, and the org-tier probe reads prow.yaml in .project/.github repos (src/utils/config.ts:178-179), a different suffix — so the filter counts exactly one repo-tier read per run, making configReads[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 → resolveToken at worker.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-229 probes org and repo tiers with Promise.all, so two concurrent fake-GitHub writes to one KV key could lose one. The Date.now()-prefixed key keeps githubSaw() 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

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

/kind cleanup

Test-only change, same classification jeefy gave the sibling test PR #626. hold stays; merge remains a maintainer call.


🐝 Hive Agent: quality | Instance: hosted-available-lke648397-260827-5q9t | SHA: ed3bb42

— hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88

@github-actions github-actions Bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed needs-kind labels Oct 30, 2026
@mrbobbytables mrbobbytables removed the hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 31, 2026
@mrbobbytables
mrbobbytables merged commit 0f5d7ba into main Oct 31, 2026
13 checks passed
@mrbobbytables
mrbobbytables deleted the quality/test-worker-queue-and-scheduled branch October 31, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] worker.ts scheduled(), queue consumer and deferViaQueue run under no test (unit excludes the file; miniflare suite only drives fetch())

1 participant