Skip to content

test(harness): fail a unit test on any msw request no handler served; serve the merge-queue state and base-branch tip the exposed tests were falling back from - #571

Open
hivecommons-hive[bot] wants to merge 1 commit into
mainfrom
quality/test-unhandled-request-assertion
Open

hivecommons-hive[bot] wants to merge 1 commit into
mainfrom
quality/test-unhandled-request-assertion

Conversation

@hivecommons-hive

@hivecommons-hive hivecommons-hive Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Test Improvement

failOnUnhandledRequest only rejects a request no handler serves; code under test that catches the rejection lets the test pass with the request silently unserved. This PR adds the missing end-of-test assertion for the unit suite and fixes the 158 tests (15 files) it exposed on main@e3119ad.

__tests__/testUtils.ts

  • failTestOnUnhandledRequests(server): records msw's request:unhandled per test (listener re-attached in beforeEach, so an afterEach that calls server.events.removeAllListeners() cannot disarm it), fails in afterEach listing the requests; .allow() is the explicit per-test allowance for a deliberate probe; seen()/check() expose the state for the self-test.
  • noMergeQueue: mergeQueueGraphql({ enabled: false }).handler, the isMergeQueueEnabled: false GitHub reports for a base branch without a merge queue.

__tests__/unhandledRequests.test.ts (new): pins the helper — a swallowed unserved request is recorded and fails check(), a served request and a deliberate Response.error() are not counted, allow() lasts one test, and the listener is re-armed after removeAllListeners().

58 msw-backed unit files (every file outside __tests__/bundle/ except plugins/tide.test.ts and cronJobTest/sweep.test.ts, see Related Issue): one line, utils.failTestOnUnhandledRequests(server), after setupServer(...).

What the assertion exposed, and how each is served now

  • POST /graphql merge-queue state query, unserved in every tide/sweep/lgtm merge-path test and reaching the direct merge via readQueueState's warning fallback (src/utils/mergeQueue.ts:88-93) → utils.noMergeQueue as the file-level default in 11 files (cronJobTest/lgtm, issueCommentTest/approve, label/lgtm, issueCommentTest/trigger, cronJobTest/handleCronJob, plugins/approveReview, plugins/approveEvents, pullReqTest/onPrLgtm, cronJobTest/labelSync, plugins/requireMatchingLabel, utils/ownersAuth). queue?.enabled === true (src/plugins/tide.ts:194) is the only consumer, so the outcome is unchanged; only the fallback warning disappears.
  • GET /branches/master, unserved and falling back to pull.base.sha (src/utils/pullRequestOwners.ts:83-86) → branchHandler() in the ownersAuth / pullRequestOwners tree-failure probes.
  • trigger.test.ts "/test › refuses an outsider" → ...utils.noOrgOrRepoConfigExcept(), as its /retest sibling already has.
  • ownersLabel.test.ts error probe → utils.defaultBranchTree() for the approve handler's concurrent OWNERS-presence read.

The fallback branches keep their dedicated tests (utils/mergeQueue.test.ts:116-124, plugins/tideMergeQueue.test.ts:261, utils/pullRequestOwners.test.ts:290); no .allow() was needed in the existing suite.

Coverage evidence

Related Issue

Fixes #570 (remaining: wiring __tests__/plugins/tide.test.ts and __tests__/cronJobTest/sweep.test.ts, left untouched because held PRs #557 and #558 occupy those files — the hive refuses an overlapping-files PR; one-line follow-up once they land)
Refs #554 (umbrella: this is the unit-suite half of "Record unexpected API traffic and assert on it"; the bundle half is #569, the other sections stay open there)


Filed by quality agent (hold-gated mode). Human review required.

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

failOnUnhandledRequest only rejects the request; code under test that
catches the rejection (readQueueState's direct-merge fallback,
baseBranchTip's base.sha fallback, the configuration probes) let the
test pass with the request silently unserved. failTestOnUnhandledRequests
records every request:unhandled event and fails the test in afterEach,
with .allow() for a test that leaves one unserved on purpose.

Wiring it into the msw-backed unit files surfaced tests that ran through
those fallbacks: the merge queue state query was unserved in every
merge-path test (now answered by noMergeQueue, the
isMergeQueueEnabled: false GitHub reports for a branch without a queue),
the base branch tip was unserved in two tree-failure probes (now
branchHandler()), one /test outsider test skipped the configuration
probes and one ownersLabel error probe left the approve handler's
default-branch tree read unserved.

__tests__/plugins/tide.test.ts and __tests__/cronJobTest/sweep.test.ts
are not wired yet; see #570.

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 23, 2026 02:51
@hivecommons-hive hivecommons-hive Bot added the hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 23, 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

Copy link
Copy Markdown
Contributor Author

/kind cleanup


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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hold Indicates that a PR should not merge because someone has issued a /hold command. 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] Unit msw servers reject unhandled requests but no test fails when the code under test swallows the rejection (158 tests run through fallbacks)

0 participants