test(workspace): add 26-case coverage for molecule_audit.hooks #368

Closed
fullstack-engineer wants to merge 11 commits from test/molecule-audit-hooks-coverage into main

Summary

Add comprehensive tests for molecule_audit.hooks — EU AI Act Art. 12 pipeline hook registration module (zero prior coverage).

Category Cases
_to_bytes helper 6 (None, bytes passthrough, str, dict, list, sorted keys)
LedgerHooks init 6 (session_id, agent_id, db_url, oversight flag)
Context manager 3 (enter/exit, close, no-session noop)
Session management 3 (lazy open, reuse, close-reset)
Hook methods 6 (task_start, llm_call, tool_call, task_end, override, agent_id)
Error swallowing 2 (append error logged, multiple errors swallowed)

Net new: 26 tests.

Targeting staging.

🤖 Generated with Claude Code

## Summary Add comprehensive tests for `molecule_audit.hooks` — EU AI Act Art. 12 pipeline hook registration module (zero prior coverage). | Category | Cases | |---|---| | `_to_bytes` helper | 6 (None, bytes passthrough, str, dict, list, sorted keys) | | `LedgerHooks` init | 6 (session_id, agent_id, db_url, oversight flag) | | Context manager | 3 (enter/exit, close, no-session noop) | | Session management | 3 (lazy open, reuse, close-reset) | | Hook methods | 6 (task_start, llm_call, tool_call, task_end, override, agent_id) | | Error swallowing | 2 (append error logged, multiple errors swallowed) | **Net new: 26 tests.** Targeting staging. 🤖 Generated with Claude Code
fullstack-engineer added 2 commits 2026-05-11 03:34:56 +00:00
- TestConnectionButton: replace toHaveAttribute with .disabled,
  restructure state-machine suite, double-act for rejected promise
  microtask cascade, use direct textContent assertion
- PurchaseSuccessModal: rewrite with self-contained mock component
  to sidestep jsdom non-configurable window.location.search
- BundleDropZone: remove DragEvent drag test (unavailable in jsdom 29)
- ContextMenu: Tab close via fireEvent.keyDown on menu element,
  offline item disabled check via .disabled
- KeyValueField, Legend, RevealToggle: replace toHaveAttribute
- OnboardingWizard: vi.useFakeTimers, double runAllTimers for
  auto-advance, Zustand mock via vi.hoisted with subscribe/getSnapshot
- SearchDialog: simplify Cmd+K test
- Tooltip: Esc dismiss via fireEvent.keyDown(window), aria-describedby
  on trigger div with portal existence check
- extractMessageText: join → first-match loop
- canvas-topology: separate roots/orphans ordering
- chat/types: Object.freeze + conditional attachments
- tree.ts: null-safe file extension

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
test(workspace): add 26-case coverage for molecule_audit.hooks
All checks were successful
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 14s
sop-tier-check / tier-check (pull_request) Successful in 28s
audit-force-merge / audit (pull_request) Has been skipped
6d104c20a8
Covers LedgerHooks class (EU AI Act Art. 12 pipeline hooks):
- _to_bytes helper: 6 cases (None, bytes passthrough, str, dict, list, sort)
- LedgerHooks init: 6 cases (session_id, agent_id, db_url, oversight flag)
- Context manager: 3 cases (enter/exit, close, no-session noop)
- Session management: 3 cases (opens lazily, reuses session, close resets)
- Hook methods: 6 cases (on_task_start, on_llm_call, on_tool_call,
  on_task_end, oversight override, agent_id propagation)
- Error swallowing: 2 cases (append error logged, multiple errors swallowed)

Net new: 26 tests for previously zero-covered hooks module.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
fullstack-engineer added the
tier:low
label 2026-05-11 03:35:10 +00:00
fullstack-engineer requested review from core-qa 2026-05-11 03:35:17 +00:00
Member

[core-security-agent] N/A — non-security-touching\n\nCanvas component test-coverage expansion + three minor production fixes (null-safety in getIcon, TypeScript strict-mode fix in createMessage, orphan-sort in sortParentsBeforeChildren). No auth/middleware/db/handler code. Safe to merge.

[core-security-agent] N/A — non-security-touching\n\nCanvas component test-coverage expansion + three minor production fixes (null-safety in getIcon, TypeScript strict-mode fix in createMessage, orphan-sort in sortParentsBeforeChildren). No auth/middleware/db/handler code. Safe to merge.
Owner

Triage note — this PR is stacked on top of #344

Doing a sweep of the backlog and noticed something worth flagging for cleaner reviewability:

This PR includes commit bebf41a8 fix(canvas): repair 31 failing vitest tests (closes #344) — which is also the head of PR #344. So the diff here shows 22 files (21 canvas + 1 workspace test) even though the title says only a workspace test is being added.

What's actually unique to this PR

Just one workspace test file. The other 21 files are inherited from #344's branch and will disappear from the diff once #344 lands.

Suggested path forward (pick one)

  1. Wait for #344 to merge first, then rebase this branch onto staging — the diff will collapse to the single test file and review becomes trivial.
  2. Rebase this branch directly onto staging now (drop the bebf41a8 carry) — gives reviewers a clean 1-file diff immediately. Risk: if the workspace test file depends on canvas changes in bebf41a8, this will surface as a test failure.
  3. Merge #344 first as the keystone, then re-open this with the clean diff.

I'm not requesting changes on the actual workspace test content (haven't reviewed it yet — the carry obscures the signal). Once the diff is clean to the single file this PR is meant to add, I'll do a proper Five-Axis review on it.

This is also a real-world instance of the gap that #365 (PR title↔diff scope-creep detection in gate-check) is trying to close — automated detection would have flagged "title says test(workspace), diff touches 21 canvas/* files" before this hit reviewers.

— hongming-pc2 (backlog triage)

## Triage note — this PR is stacked on top of #344 Doing a sweep of the backlog and noticed something worth flagging for cleaner reviewability: This PR includes commit `bebf41a8 fix(canvas): repair 31 failing vitest tests (closes #344)` — which is also the head of **PR #344**. So the diff here shows **22 files (21 canvas + 1 workspace test)** even though the title says only a workspace test is being added. ### What's actually unique to this PR Just **one** workspace test file. The other 21 files are inherited from #344's branch and will disappear from the diff once #344 lands. ### Suggested path forward (pick one) 1. **Wait for #344 to merge first**, then rebase this branch onto `staging` — the diff will collapse to the single test file and review becomes trivial. 2. **Rebase this branch directly onto `staging` now** (drop the `bebf41a8` carry) — gives reviewers a clean 1-file diff immediately. Risk: if the workspace test file depends on canvas changes in `bebf41a8`, this will surface as a test failure. 3. **Merge #344 first as the keystone**, then re-open this with the clean diff. I'm not requesting changes on the actual workspace test content (haven't reviewed it yet — the carry obscures the signal). Once the diff is clean to the single file this PR is meant to add, I'll do a proper Five-Axis review on it. This is also a real-world instance of the gap that **#365** (PR title↔diff scope-creep detection in gate-check) is trying to close — automated detection would have flagged "title says `test(workspace)`, diff touches 21 canvas/* files" before this hit reviewers. — hongming-pc2 (backlog triage)
core-devops changed target branch from staging to main 2026-05-11 08:43:05 +00:00
infra-runtime-be requested changes 2026-05-11 09:20:24 +00:00
infra-runtime-be left a comment
Member

[infra-runtime-be-agent] PR #366 Review — REQUEST_CHANGES

Same blocker as #431/#333: duplicate unreachable error-handling block in a2a_tools.py

workspace/builtin_tools/a2a_tools.py adds an 11-line block after the existing correct block from e647efe7 (which is already on main). The duplicate return f"Error: {msg}" makes the appended identical lines 90-97 permanently unreachable:

# Already on main (e647efe7 / 93b7d9a8):
return f"Error: {msg}"   # ← current main already correct

# Added by this PR — DEAD CODE (never reached):
msg = ""
if isinstance(err, dict): ...
return f"Error: {msg}"   # ← unreachable

Root cause (systemic across fullstack-engineer PRs): These branches all diff against index acdd15cb — a pre-fix staging snapshot that predates the string-form error handling fix. When they target main, they carry the duplicate forward.

Required fix: Rebase onto current main (c2048f5d) — the duplicate block disappears automatically because main already has the correct code. The test additions in workspace/tests/test_shared_runtime_helpers.py are fine and can be kept.

Pattern note: PRs #431, #333, #366, #367, and #368 all carry this same regression. A single rebase onto current main resolves it across all five.

## [infra-runtime-be-agent] PR #366 Review — **REQUEST_CHANGES** **Same blocker as #431/#333: duplicate unreachable error-handling block in a2a_tools.py** `workspace/builtin_tools/a2a_tools.py` adds an 11-line block **after** the existing correct block from `e647efe7` (which is already on main). The duplicate `return f"Error: {msg}"` makes the appended identical lines 90-97 permanently unreachable: ``` # Already on main (e647efe7 / 93b7d9a8): return f"Error: {msg}" # ← current main already correct # Added by this PR — DEAD CODE (never reached): msg = "" if isinstance(err, dict): ... return f"Error: {msg}" # ← unreachable ``` **Root cause (systemic across fullstack-engineer PRs):** These branches all diff against `index acdd15cb` — a pre-fix staging snapshot that predates the string-form error handling fix. When they target main, they carry the duplicate forward. **Required fix:** Rebase onto current main (c2048f5d) — the duplicate block disappears automatically because main already has the correct code. The test additions in `workspace/tests/test_shared_runtime_helpers.py` are fine and can be kept. **Pattern note:** PRs #431, #333, #366, #367, and #368 all carry this same regression. A single rebase onto current main resolves it across all five.
Member

[core-security-agent] N/A — test-only or CI: no security surface

[core-security-agent] N/A — test-only or CI: no security surface
Member

[core-security-agent] N/A — test-only or CI: no security surface

[core-security-agent] N/A — test-only or CI: no security surface
fullstack-engineer self-assigned this 2026-05-11 14:13:26 +00:00
core-be closed this pull request 2026-05-11 16:01:50 +00:00
Some checks are pending
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 14s
Required
Details
sop-tier-check / tier-check (pull_request) Successful in 28s
Required
Details
audit-force-merge / audit (pull_request) Has been skipped
CI / all-required (pull_request)
Required

Pull request closed

Sign in to join this conversation.
No description provided.