The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { ComposerContextId } from "@t3tools/contracts"; |
| 2 | import { formatAssistantCitationHref } from "@t3tools/shared/assistantCitations"; |
| 3 | import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences"; |
| 4 | import { describe, expect, it } from "vite-plus/test"; |
| 5 | |
| 6 | import { resolveThreadQueueRowControls } from "./threadQueueControlPresentation"; |
| 7 | |
| 8 | describe("threadQueueControlPresentation", () => { |
| 9 | it.each([ |
| 10 | { busy: false, isEditing: false, expected: true }, |
| 11 | { busy: true, isEditing: false, expected: false }, |
| 12 | { busy: false, isEditing: true, expected: false }, |
| 13 | ])( |
| 14 | "gates sending a stopped thread's queued message with $busy busy and $isEditing editing", |
| 15 | ({ busy, isEditing, expected }) => { |
| 16 | const controls = resolveThreadQueueRowControls({ |
| 17 | busy, |
| 18 | isEditing, |
| 19 | canPromoteToSteer: false, |
| 20 | canSendNow: true, |
| 21 | text: "Queued message", |
| 22 | }); |
| 23 | |
| 24 | expect(controls.canSend).toBe(expected); |
| 25 | }, |
| 26 | ); |
| 27 | |
| 28 | it("shows an assistant quote as its quoted text", () => { |
| 29 | const href = formatAssistantCitationHref({ |
| 30 | version: 1, |
| 31 | environmentId: "environment:test" as never, |
| 32 | threadId: "thread:test" as never, |
| 33 | messageId: "message:assistant" as never, |
| 34 | text: "Retry the sync after the lock clears.", |
| 35 | start: 0, |
| 36 | end: 37, |
| 37 | prefix: "", |
| 38 | suffix: "", |
| 39 | }); |
| 40 | const controls = resolveThreadQueueRowControls({ |
| 41 | busy: false, |
| 42 | canPromoteToSteer: true, |
| 43 | canSendNow: false, |
| 44 | text: `[Assistant quote](${href}) Can we add a backoff here?`, |
| 45 | }); |
| 46 | |
| 47 | expect(controls.displayText).toBe( |
| 48 | "Retry the sync after the lock clears. Can we add a backoff here?", |
| 49 | ); |
| 50 | }); |
| 51 | |
| 52 | it("shows context chips by their labels", () => { |
| 53 | const environment = formatComposerContextReference({ |
| 54 | kind: "environment", |
| 55 | contextId: ComposerContextId.make("environment_mac"), |
| 56 | label: "MacBook", |
| 57 | }); |
| 58 | const file = formatComposerContextReference({ |
| 59 | kind: "file", |
| 60 | contextId: ComposerContextId.make("report"), |
| 61 | label: "report.pdf", |
| 62 | }); |
| 63 | const image = formatComposerContextReference({ |
| 64 | kind: "image", |
| 65 | contextId: ComposerContextId.make("screenshot"), |
| 66 | label: "screenshot.png", |
| 67 | }); |
| 68 | |
| 69 | expect( |
| 70 | resolveThreadQueueRowControls({ |
| 71 | busy: false, |
| 72 | canPromoteToSteer: true, |
| 73 | canSendNow: false, |
| 74 | text: `Check ${environment} for ${file} ${image} `, |
| 75 | }).displayText, |
| 76 | ).toBe("Check MacBook for report.pdf screenshot.png"); |
| 77 | }); |
| 78 | |
| 79 | it("keeps the row already open in the composer from being reopened or steered", () => { |
| 80 | const editing = resolveThreadQueueRowControls({ |
| 81 | busy: false, |
| 82 | canPromoteToSteer: true, |
| 83 | canSendNow: false, |
| 84 | isEditing: true, |
| 85 | text: "Being edited", |
| 86 | }); |
| 87 | |
| 88 | expect(editing.isEditing).toBe(true); |
| 89 | expect(editing.canEdit).toBe(false); |
| 90 | expect(editing.canSend).toBe(false); |
| 91 | expect(editing.canDismiss).toBe(true); |
| 92 | }); |
| 93 | |
| 94 | it("lets the owner cancel a guest's queued message but not rewrite it", () => { |
| 95 | const guest = resolveThreadQueueRowControls({ |
| 96 | busy: false, |
| 97 | canPromoteToSteer: true, |
| 98 | canSendNow: false, |
| 99 | isGuestMessage: true, |
| 100 | text: "Why?", |
| 101 | }); |
| 102 | |
| 103 | expect(guest.canEdit).toBe(false); |
| 104 | expect(guest.canDismiss).toBe(true); |
| 105 | }); |
| 106 | }); |