Skip to content

fix(test): patch the server class workflows main() actually constructs - #9683

Closed
CrysisDeu wants to merge 1 commit into
mainfrom
fix/workflows-boot-test-patches-real-server
Closed

CrysisDeu wants to merge 1 commit into
mainfrom
fix/workflows-boot-test-patches-real-server

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Main has been red on Backend Tests (3.12, 4) and Backend Tests (Windows) (4) since #9066 landed (ebf9ffb55, "fix(workflows): bootstrap the platform context"): main's own run on 67716d722 fails the same two shards plus Coverage Gate, and so does every PR rebased onto it (e.g. #8947).

The culprit is a test that patches the wrong name. test_main_boots_platform_before_binding_server does

monkeypatch.setattr(server, "ThreadingHTTPServer", _FakeServer)

but server.main() instantiates the module's own subclass:

class _Server(ThreadingHTTPServer): ...
server = _Server(("127.0.0.1", PORT), _Handler)
server.serve_forever()

_Server is bound at import time, so replacing the imported ThreadingHTTPServer name changes nothing — the test binds a real socket on PORT and serve_forever() never returns. On Linux that is Failed: Timeout >120.0s; on Windows the xdist worker (gw3) crashes.

Fix

Patch server._Server in both tests. The fail-closed sibling (test_main_fails_closed_when_platform_cannot_compose) had the same wrong target and only passed because boot_platform raises before the server line; it is corrected too so it keeps guarding the right thing.

Test-only change; no production code touched.

Evidence

Local gates

ruff check test/test_workflows_app.py clean. Tests not run locally (CI is the gate).

Pattern harvest

  • Pattern: a test monkeypatches the imported base-class name (server.ThreadingHTTPServer) while the code under test instantiates a module-level subclass (_Server) that captured the base at import time. The patch is silently inert; the test then does the real thing (bind a socket, block in serve_forever()), which shows up as a 120 s timeout on Linux and an xdist worker crash on Windows rather than an assertion failure — so it reads like flakiness, not a wrong patch target.
  • Detection gap: the failure mode (hang) hid the cause; the test passed locally for the author only if PORT happened to be free and nobody waited 120 s. CI ran it in a sharded job where a single hang takes the whole shard.
  • Guard going forward: when patching what main() builds, patch the name main() reads (_Server), not what that name was built from. A cheap tripwire for this family: any test that stubs a server/loop should assert the stub was called (calls == [...] here does that — it just never got to run).

Rule candidate: a test that monkeypatches a class the code under test inherits from (rather than the name it instantiates) is a dead patch — flag monkeypatch.setattr(<module>, "<BaseClass>", …) where <module> defines a subclass of <BaseClass> that the tested entrypoint constructs. Reviewers/AutoSDE: require the patched name to appear in the entrypoint's body.

  • Sibling swept: test_main_fails_closed_when_platform_cannot_compose had the identical wrong target and only passed because boot_platform raised first; fixed in the same commit so it keeps guarding the right thing.

@CrysisDeu
CrysisDeu requested review from a team and pepmach September 9, 2026 09:26
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 466fcb14bb098f099e6a251915b423c1818af4a9 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Verified against src/kiro_crew/apps/builtins/workflows/server.py: main() constructs the module-level _Server subclass (line 272), so the old patch of the imported ThreadingHTTPServer name was indeed inert, and the sibling Windows test already pins that construction shape. The fix is the root cause, minimal, and test-only.

Design-Verdict: PASS

Correct root-cause fix for a dead patch target that hung two CI shards; minimal, test-only, and consistent with the existing _Server construction pin.

[DESIGN-REVIEWED] 466fcb1

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 466fcb14bb098f099e6a251915b423c1818af4a9 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 466fcb1

Verdict parsed from the review's SHA-scoped output markers for commit 466fcb14bb098f099e6a251915b423c1818af4a9.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 466fcb14bb098f099e6a251915b423c1818af4a9: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 466fcb14bb098f099e6a251915b423c1818af4a9 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 466fcb1

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 466fcb14bb098f099e6a251915b423c1818af4a9: <one-sentence reason>

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Superseded by #9682 (same fix for #9675, opened a minute earlier). #9682 is a strict superset: same _Server retarget in both tests, plus a name-independent TCPServer.server_bind tripwire and a class-shaped fake in the fail-closed test.

@CrysisDeu CrysisDeu closed this Sep 9, 2026
@CrysisDeu
CrysisDeu deleted the fix/workflows-boot-test-patches-real-server branch September 9, 2026 09:44
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 9, 2026
@CrysisDeu
CrysisDeu restored the fix/workflows-boot-test-patches-real-server branch September 9, 2026 09:45
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Reopened: #9682 went red on Backend Lint & Type Check (its own change); this PR is the same fix with 0 red, kept as the alternate so whichever is fully green first can merge.

@CrysisDeu CrysisDeu reopened this Sep 9, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 9, 2026
test_main_boots_platform_before_binding_server (from #9066) monkeypatches
server.ThreadingHTTPServer, but main() instantiates the module's _Server
subclass, bound at import time, so the patch is inert: the test binds a
real socket on PORT and serve_forever() never returns. Every PR on main has
been red on Backend Tests (3.12, 4) (Timeout >120s) and Backend Tests
(Windows) (4) (xdist worker crash) since it landed.

Patch _Server in both tests; the fail-closed sibling only passed because
boot_platform raises before the server line.
@CrysisDeu
CrysisDeu force-pushed the fix/workflows-boot-test-patches-real-server branch from 85efe39 to 466fcb1 Compare September 9, 2026 10:49
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 9, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 9, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Superseded by #9682, which merged at 11:04Z with the same _Server retarget plus a bind tripwire.

@CrysisDeu CrysisDeu closed this Sep 9, 2026
@CrysisDeu
CrysisDeu deleted the fix/workflows-boot-test-patches-real-server branch September 9, 2026 11:09
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant