Skip to content

fix(mockups): report Therapy Compass clipboard copy only on success#667

Merged
BigSimmo merged 2 commits into
mainfrom
claude/therapy-compass-pages-rz0m5l
Jul 14, 2026
Merged

fix(mockups): report Therapy Compass clipboard copy only on success#667
BigSimmo merged 2 commits into
mainfrom
claude/therapy-compass-pages-rz0m5l

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #664 (merged) addressing a Codex review finding that landed after auto-merge — Codex and CodeRabbit are advisory here, so the squash merge didn't wait for the auto-resolve pass to commit a fix.

In src/components/therapy-compass/use-clipboard.ts, copyText fired navigator.clipboard.writeText and returned true synchronously, so a rejected write (permission denied, lost focus, blocked gesture) still flipped the button to "Copied" and left the promise rejection unhandled.

  • copyText is now async: it awaits the write and resolves false on rejection (no throw), so callers never signal a copy that didn't happen.
  • useClipboard sets copied only after a successful write, and guards against a state update after unmount.
  • No caller changes: copyText was only consumed internally by useClipboard; the screens use the hook's copy (still fire-and-forget void).

Dev-only mockup route (/mockups/therapy-compass, production 404 + robots disallow); no production surface, data, schema, or governance change. 2 files (+105/−14).

Verification

  • New test tests/therapy-compass-clipboard.dom.test.tsx (jsdom) — 5/5 pass: copyText resolves true/false for accept/reject and never throws; copied is set on success and stays unset when writeText rejects.
  • npm run verify:pr-local — not run to completion in this sandbox (optional deps). Instead ran typecheck, lint (--max-warnings 0), Prettier --check, and the new test directly — all green. CI Build / Static PR checks / Unit coverage cover the full install.
  • npm run verify:ui — CI Critical UI smoke / UI regression cover the Chromium suite; the change is clipboard-behavior only (no visual change).
  • npm run eval:retrieval:qualityN/A. No retrieval, ranking, selection, chunking, or scoring change.
  • npm run check:production-readinessN/A. No clinical workflow, privacy, environment, Supabase, source-governance, or deployment change.

Clinical Governance Preflight

N/A for production surfaces — static, dev-only mockup. It does not touch ingestion, answer generation, search/ranking of live documents, document access, privacy, production env, Supabase, or clinical output. No schema, RLS, or service-role changes.

Notes

The finding was a valid P2 from Codex on #664; auto-merge (which only gates on required checks, not advisory reviews) merged before the Codex auto-resolve pass could commit. This PR is that fix, with a behavioral test guarding the copy-success contract.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TJaXJntdH7Q98ejoSZF46K


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Copy actions now confirm clipboard writes before showing “Copied” feedback.
    • Failed clipboard writes no longer appear successful or cause errors.
    • Copy status remains accurate when multiple copy actions complete out of order.
    • Prevented stale feedback after leaving the page.
  • Tests

    • Added coverage for successful, failed, empty, and overlapping copy operations.

Addresses a Codex review finding on #664's `use-clipboard.ts`: `copyText` fired
`navigator.clipboard.writeText` and returned `true` synchronously, so a rejected
write (permission denied, lost focus, blocked gesture) still flipped the button
to "Copied" and left the promise rejection unhandled.

- `copyText` is now async: it awaits the write and resolves `false` on rejection
  instead of throwing, so callers never signal a copy that didn't happen.
- `useClipboard` sets `copied` only after a successful write, and guards against
  a state update after unmount.
- Adds tests that mock `writeText` resolving/rejecting: `copyText` reports real
  success/failure without throwing, and `copied` stays unset when the write
  rejects.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TJaXJntdH7Q98ejoSZF46K
@supabase

supabase Bot commented Jul 14, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c330a65d-6ffa-4105-a6db-82d9f87ae97a

📥 Commits

Reviewing files that changed from the base of the PR and between 922ae76 and 5a89a52.

📒 Files selected for processing (2)
  • src/components/therapy-compass/use-clipboard.ts
  • tests/therapy-compass-clipboard.dom.test.tsx

📝 Walkthrough

Walkthrough

Clipboard copying is now asynchronous, reports actual write success, and handles rejected writes. The hook coordinates successful feedback, unmount cleanup, timeout cleanup, and out-of-order requests. New DOM tests cover utility and hook behavior.

Changes

Clipboard async safety

Layer / File(s) Summary
Async clipboard write contract
src/components/therapy-compass/use-clipboard.ts, tests/therapy-compass-clipboard.dom.test.tsx
copyText awaits navigator.clipboard.writeText and returns a success boolean; tests cover successful, rejected, unavailable, and empty-input writes.
Hook lifecycle and stale request handling
src/components/therapy-compass/use-clipboard.ts, tests/therapy-compass-clipboard.dom.test.tsx
useClipboard updates feedback only after successful writes, prevents post-unmount updates, clears timers, and preserves the newest request result.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant useClipboard
  participant ClipboardAPI
  Caller->>useClipboard: copy(key)
  useClipboard->>ClipboardAPI: writeText(key)
  ClipboardAPI-->>useClipboard: resolve success or failure
  useClipboard-->>Caller: update copied feedback for latest request
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Clear and concise title that matches the clipboard success-only behavior change.
Description check ✅ Passed The description covers summary, verification, governance preflight, and notes, with only some template checks marked N/A.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/therapy-compass-pages-rz0m5l

Comment @coderabbitai help to get the list of available commands.

@BigSimmo
BigSimmo marked this pull request as ready for review July 14, 2026 14:34
@BigSimmo
BigSimmo enabled auto-merge (squash) July 14, 2026 14:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be05af92f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/components/therapy-compass/use-clipboard.ts
@BigSimmo

Copy link
Copy Markdown
Owner Author

@codex resolve actionable Codex review findings for this pull request and current head using the repository instructions. This is the pull request's single automatic repair pass: do not perform a fresh review, create new standalone findings, or request another review. Work only the existing unresolved Codex threads on the current head. Always fix P0 and P1 findings. For P2 and lower findings, fix only clear, scoped, low-risk issues; otherwise disposition them with a concise reason. After fixing or dispositioning a thread, reply in that thread with as the first line, followed by a concise summary; that marker authorizes the workflow to close that exact thread. If human input or new authorization is required, do not use the marker and leave the thread open with the blocker. Finish only after every actionable thread is fixed or dispositioned and closed, or explicitly left open for a human decision. Do not update the branch from main, address unrelated reviews, broaden scope, or create more than one scoped fix commit. Do not use external APIs, paid services, credentials, dependency changes, or broad refactors unless explicitly authorized. Add targeted tests where behavior changes and run the narrowest relevant validation.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: be05af92f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Addresses a second Codex review finding on #667: useClipboard is shared across
multiple copy controls (e.g. Brief's per-step buttons plus the intervention
copy action), so if two writes are in flight and their promises resolve out of
order, an older completion could overwrite the newer copy's feedback with the
wrong key.

- Tag each copy with a monotonic request id; a completion only updates `copied`
  when it is still the latest request, so stale / out-of-order successes are
  ignored and the hook contract (copied reflects the most recent copy) holds.
- Adds a test that resolves two in-flight writes out of order and asserts the
  latest key wins and the stale completion does not overwrite it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TJaXJntdH7Q98ejoSZF46K
@BigSimmo
BigSimmo merged commit c1b6c70 into main Jul 14, 2026
16 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