Skip to content

fix(components): inject tauri calls into useResponseActions#62

Merged
saagpatel merged 1 commit into
masterfrom
codex/fix/response-actions-purity
Apr 22, 2026
Merged

fix(components): inject tauri calls into useResponseActions#62
saagpatel merged 1 commit into
masterfrom
codex/fix/response-actions-purity

Conversation

@saagpatel
Copy link
Copy Markdown
Owner

What

Small purity fix for `useResponseActions` — the last Wave 5.7 hook that was calling tauri's `invoke` directly from inside its body. The 12 other extracted hooks take their side-effect dependencies as injected options; this PR brings `useResponseActions` onto the same contract.

Why

Caught by the post-Wave-5 verification audit. The hook mixed pure React state with two direct tauri calls (`audit_response_copy_override` and `export_draft`). That meant:

  • The hook couldn't be tested without a `vi.mock("@tauri-apps/api/core")` call at the top of the test file.
  • The shell couldn't substitute test doubles for the two commands if it wanted to.
  • The pattern diverged from the 12 other hooks, making future hook extractions less obvious.

How

  1. New `src/components/Draft/draftTauriCommands.ts` module with two stable function exports, `auditResponseCopyOverride` and `exportDraft`, that wrap the tauri `invoke` calls.
  2. `useResponseActions` now accepts both as required options.
  3. `DraftTab.tsx` imports the two functions from the new module and passes them through at the hook call site.
  4. `useResponseActions.test.ts` drops the `vi.mock("@tauri-apps/api/core")` block and its `invokeMock`; tests now assert directly on the injected `options.auditResponseCopyOverride` / `options.exportDraft` spies.

Testing

  • `pnpm tsc --noEmit` — clean.
  • `pnpm test` — 241 pass, unchanged count (the same 7 tests on this hook, same behavior coverage, just a cleaner mocking strategy).
  • `pnpm ui:gate:static` — exit 0.

Risk / Notes

  • Runtime behavior unchanged. `draftTauriCommands.ts` calls the exact same tauri commands with the exact same argument shapes.
  • No consumer contract changes. `DraftTabHandle` unchanged (still pinned by `DraftTab.handle.test.tsx`).

The useResponseActions hook was calling invoke() directly from tauri
for audit_response_copy_override and export_draft, breaking the
pure-hook contract that the other 12 Wave 5.7 hooks follow. Move
the two invoke wrappers into a new draftTauriCommands module and
inject them as hook options. Test no longer needs to vi.mock the
entire @tauri-apps/api/core module.
@saagpatel saagpatel merged commit d36c62e into master Apr 22, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants