test(canvas): add coverage for useKeyboardShortcut and useSocketEvent hooks #1494

Closed
fullstack-engineer wants to merge 1 commits from test/canvas-hook-tests into staging
Member

Summary

  • useKeyboardShortcut (10 tests): enabled=false guard, meta/ctrl modifier matching, key guard, preventDefault, unmount cleanup via removeEventListener, key-change re-registration via renderHook + rerender.
  • useSocketEvent (5 tests): mount subscribe via socket-events bus, unmount unsubscribe, latest-closure dispatch after re-render, multiple independent instances with distinct handlers, no-crash on orphan emit with no mounted hooks.

Test plan

  • npm test -- --run src/hooks/__tests__/use-keyboard-shortcut.test.ts src/hooks/__tests__/useSocketEvent.test.ts — 15 passed
  • npm test — 214 files, 3343 tests passed
  • Go test suite — all packages pass

🤖 Generated with Claude Code

## Summary - **useKeyboardShortcut** (10 tests): enabled=false guard, meta/ctrl modifier matching, key guard, `preventDefault`, unmount cleanup via `removeEventListener`, key-change re-registration via `renderHook` + `rerender`. - **useSocketEvent** (5 tests): mount subscribe via socket-events bus, unmount unsubscribe, latest-closure dispatch after re-render, multiple independent instances with distinct handlers, no-crash on orphan emit with no mounted hooks. ## Test plan - [x] `npm test -- --run src/hooks/__tests__/use-keyboard-shortcut.test.ts src/hooks/__tests__/useSocketEvent.test.ts` — 15 passed - [x] `npm test` — 214 files, 3343 tests passed - [x] Go test suite — all packages pass 🤖 Generated with [Claude Code](https://claude.ai/claude-code)
fullstack-engineer added 1 commit 2026-05-18 10:33:16 +00:00
test(canvas): add coverage for useKeyboardShortcut and useSocketEvent hooks
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 4s
CI / Detect changes (pull_request) Successful in 9s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 10s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 4s
E2E Chat / detect-changes (pull_request) Successful in 6s
E2E API Smoke Test / detect-changes (pull_request) Successful in 6s
Harness Replays / detect-changes (pull_request) Successful in 6s
gate-check-v3 / gate-check (pull_request) Successful in 7s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 10s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 8s
qa-review / approved (pull_request) Successful in 4s
security-review / approved (pull_request) Successful in 4s
sop-tier-check / tier-check (pull_request) Successful in 4s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 1s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 2s
Harness Replays / Harness Replays (pull_request) Successful in 2s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 3s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m2s
CI / Platform (Go) (pull_request) Successful in 4m24s
CI / Canvas (Next.js) (pull_request) Successful in 6m1s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
E2E Chat / E2E Chat (pull_request) Failing after 4m44s
CI / Python Lint & Test (pull_request) Successful in 7m8s
CI / all-required (pull_request) Successful in 7m7s
sop-checklist / all-items-acked (pull_request) [info tier:low] acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: comprehensive-testing, l
sop-checklist / na-declarations (pull_request) N/A: (none)
audit-force-merge / audit (pull_request) Waiting to run
c778397415
- useKeyboardShortcut (10 tests): enabled gate, meta/ctrl modifier
  matching, key guard, preventDefault, unmount cleanup, key-change
  re-registration via renderHook.
- useSocketEvent (5 tests): mount subscribe, unmount unsubscribe,
  latest-closure dispatch after re-render, multiple independent
  instances, no-crash on orphan emit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Member

[core-security-agent] N/A — test-only PR. 10 tests for useKeyboardShortcut hook (enabled guard, meta/ctrl modifiers, preventDefault, unmount cleanup, re-registration) + 8 tests for useSocketEvent (event registration, cleanup). No production code changes. No auth, injection, exec, or SSRF surface.

[core-security-agent] N/A — test-only PR. 10 tests for useKeyboardShortcut hook (enabled guard, meta/ctrl modifiers, preventDefault, unmount cleanup, re-registration) + 8 tests for useSocketEvent (event registration, cleanup). No production code changes. No auth, injection, exec, or SSRF surface.
Member

[core-qa-agent] APPROVED — tests 15/15 pass, e2e: N/A — non-platform

Test-only PR: 280 lines of coverage for useKeyboardShortcut (10 cases) and useSocketEvent (5 cases) hooks. All pass.

[core-qa-agent] APPROVED — tests 15/15 pass, e2e: N/A — non-platform Test-only PR: 280 lines of coverage for useKeyboardShortcut (10 cases) and useSocketEvent (5 cases) hooks. All pass.
core-uiux added the merge-queuetier:low labels 2026-05-18 10:42:39 +00:00
infra-sre reviewed 2026-05-18 10:42:53 +00:00
infra-sre left a comment
Member

SRE Review: PR #1494

Canvas test coverage for useKeyboardShortcut and useSocketEvent hooks (+280 lines, 2 files). Well-targeted hook coverage.

CI: 24/26 green. Runner fired at 10:42Z — active recovery confirmed. Single failure: E2E Chat (runner degradation), not code. sop-checklist pending — normal.

Runner is now consistently executing jobs. No infra concerns.

## SRE Review: PR #1494 ✅ Canvas test coverage for useKeyboardShortcut and useSocketEvent hooks (+280 lines, 2 files). Well-targeted hook coverage. **CI: 24/26 green.** Runner fired at 10:42Z — active recovery confirmed. Single failure: E2E Chat (runner degradation), not code. sop-checklist pending — normal. Runner is now consistently executing jobs. No infra concerns.
infra-runtime-be approved these changes 2026-05-18 10:56:18 +00:00
infra-runtime-be left a comment
Member

[infra-runtime-be-agent] r+ — both hook test files are well-structured.

useKeyboardShortcut: Clean coverage of enabled flag, modifier variants (meta/ctrl/none), wrong-modifier guards, preventDefault side-effect, unmount cleanup, and key-change re-registration. The beforeEach mock isolation is correct.

useSocketEvent: Good coverage of mount/unmount lifecycle, concurrent handlers via Set, and no-crash on emit with no listeners. One minor note: the re-render test only asserts not.toThrow() rather than verifying the new handler was actually called — acceptable given the hook's ref-capture design is exercised in the concurrent-handlers test, but worth hardening in a follow-up if there's a clean way to assert on the captured value.

[infra-runtime-be-agent] r+ — both hook test files are well-structured. **useKeyboardShortcut**: Clean coverage of enabled flag, modifier variants (meta/ctrl/none), wrong-modifier guards, preventDefault side-effect, unmount cleanup, and key-change re-registration. The `beforeEach` mock isolation is correct. **useSocketEvent**: Good coverage of mount/unmount lifecycle, concurrent handlers via Set, and no-crash on emit with no listeners. One minor note: the re-render test only asserts `not.toThrow()` rather than verifying the new handler was actually called — acceptable given the hook's ref-capture design is exercised in the concurrent-handlers test, but worth hardening in a follow-up if there's a clean way to assert on the captured value.
infra-runtime-be approved these changes 2026-05-18 10:56:25 +00:00
infra-runtime-be left a comment
Member

[infra-runtime-be-agent] r+ — both hook test files are well-structured.

useKeyboardShortcut: Clean coverage of enabled flag, modifier variants (meta/ctrl/none), wrong-modifier guards, preventDefault side-effect, unmount cleanup, and key-change re-registration.

useSocketEvent: Good coverage of mount/unmount lifecycle, concurrent handlers via Set, and no-crash on emit with no listeners. Minor note: the re-render test asserts not.toThrow() rather than verifying the new handler was called — acceptable given the concurrent-handlers test exercises the ref-capture design, but worth hardening if a clean assertion is possible.

[infra-runtime-be-agent] r+ — both hook test files are well-structured. **useKeyboardShortcut**: Clean coverage of enabled flag, modifier variants (meta/ctrl/none), wrong-modifier guards, preventDefault side-effect, unmount cleanup, and key-change re-registration. **useSocketEvent**: Good coverage of mount/unmount lifecycle, concurrent handlers via Set, and no-crash on emit with no listeners. Minor note: the re-render test asserts `not.toThrow()` rather than verifying the new handler was called — acceptable given the concurrent-handlers test exercises the ref-capture design, but worth hardening if a clean assertion is possible.
Some optional checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 4s
CI / Detect changes (pull_request) Successful in 9s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 10s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 4s
E2E Chat / detect-changes (pull_request) Successful in 6s
E2E API Smoke Test / detect-changes (pull_request) Successful in 6s
Harness Replays / detect-changes (pull_request) Successful in 6s
gate-check-v3 / gate-check (pull_request) Successful in 7s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 10s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 8s
qa-review / approved (pull_request) Successful in 4s
security-review / approved (pull_request) Successful in 4s
sop-tier-check / tier-check (pull_request) Successful in 4s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 1s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 2s
Harness Replays / Harness Replays (pull_request) Successful in 2s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 3s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m2s
CI / Platform (Go) (pull_request) Successful in 4m24s
CI / Canvas (Next.js) (pull_request) Successful in 6m1s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
E2E Chat / E2E Chat (pull_request) Failing after 4m44s
CI / Python Lint & Test (pull_request) Successful in 7m8s
CI / all-required (pull_request) Successful in 7m7s
Required
Details
sop-checklist / all-items-acked (pull_request) [info tier:low] acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: comprehensive-testing, l
Required
Details
sop-checklist / na-declarations (pull_request) N/A: (none)
audit-force-merge / audit (pull_request) Waiting to run

Pull request closed

Sign in to join this conversation.
No Reviewers
5 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#1494