test(webhook): expand test depth — fetch spy, CI gate, fallback timer, session resume #43
No reviewers
Labels
No labels
area:agents
area:dashboard
area:database
area:design
area:design-review
area:flows
area:infra
area:meta
area:security
area:sessions
area:webhook
area:workdir
security
type:bug
type:chore
type:meta
type:user-story
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
charles/claude-hooks!43
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "dev/37"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
globalThis.fetchmock inwebhook.test.ts; tests register URL-pattern → response handlers and assert exact call sequences; existing no-op tests gain explicitfetchSpy.toHaveLength(0)assertions so stray network calls fail immediatelyrequestReviewIfFresh(5 cases: reviewer-already-requested dedup, verdict-at-head dedup, happy-path POST, PR-author==reviewer no-op, unknown-author no-op);handleStatusEvent(success/failure/pending routing);handleActionRunEvent(failure→fix-ci, success+green→review, success+non-green→no-op)repoHasWorkflows: new exported utility that checks.forgejo/workflows/and.github/workflows/via the Forgejo Contents API; 5 tests covering entries-found, fallback-to-github, empty, 404, and network errorarmReviewFallback/cancelReviewFallback): armed byhandlePullRequestSynchronizewhen head SHA is known, cancelled by terminal CI events; 7 timer tests including cancel-by-CI-event integration; wired intohandleStatusEventandhandleActionRunEventrunWithSessionResumefromWorker.runAgentas a standalone exported helper;session-resume.test.tstests 5 states (fresh, resume-success, resume-fail-and-retry, fresh-failure propagation, stateless) with no module mocks — pure logic against the real sessions store in a temp dirTest plan
bun test— 146 tests, 0 failuresbun x tsc --noEmit— no type errorsbun x biome check src/— no lint/format errorsCloses #37
Review
CI: ✅ green — run #1538,
success, 53 s on head5b56b5d.Acceptance criteria (issue #37)
resetFetchSpy()inbeforeEachfetchSpy.toHaveLength(0)requestReviewIfFresh— 5 cases (dedup existing reviewer, verdict-at-head APPROVED & REQUEST_CHANGES, happy-path POST with correct body{reviewers:["reviewer"]}, author==reviewer no-op, unknown-author no-op)handleStatusEvent— success→review, failure→fix-ci, pending→no-ophandleActionRunEvent— failure→fix-ci, success+green→review, success+non-green→no-oprepoHasWorkflows— 5 tests (entries, github fallback, empty, 404, network error)armReviewFallback/cancelReviewFallbackwith mockedsetTimeout/clearTimeoutrunWithSessionResume— fresh, resume-success, resume-fail-retry, fresh-failure propagation, statelessjust qa/ CI passesNotes (non-blocking)
repoHasWorkflowsis currently dead code (src/webhook.ts).It is defined, exported, and thoroughly tested, but
handlePullRequestSynchronizearms the fallback unconditionally — it never callsrepoHasWorkflowsto decide whether to arm. The utility is correct and the tests are good; if it's a building block for a follow-up PR that uses it as a guard, that's fine. Worth a comment so it doesn't get mistaken for an oversight later.dispatchFixCiinvocation is not verified in the failure-routing tests (handleStatusEvent failure,handleActionRunEvent action_run_failure).Both tests confirm the review path was not taken (no POST to
/requested_reviewers) and that the PR list was fetched. The acceptance criterion says "dispatches fix-ci with the failing workflow_id in the prompt" — the tests don't register a handler for the task API endpoint, so that POST goes unobserved. The routing is correct (CI is green, code is correct), but a future regression that silently drops the fix-ci dispatch would not be caught. AregisterFetchHandler("localhost:4500/task", …)+expect(fetchSpy.some(…))in a follow-up would close the gap.Both are informational — neither blocks merge.
5b56b5d1c23d90dcd0ef