Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadQueueControlPresentation.test.ts

96 lines2.9 KB

1import { formatAssistantCitationHref } from "@t3tools/shared/assistantCitations";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { resolveThreadQueueRowControls } from "./threadQueueControlPresentation";
5​
6describe("threadQueueControlPresentation", () => {
7 it.each([
8 { busy: false, isEditing: false, expected: true },
9 { busy: true, isEditing: false, expected: false },
10 { busy: false, isEditing: true, expected: false },
11 ])(
12 "gates sending a stopped thread's queued message with $busy busy and $isEditing editing",
13 ({ busy, isEditing, expected }) => {
14 const controls = resolveThreadQueueRowControls({
15 busy,
16 isEditing,
17 canPromoteToSteer: false,
18 canSendNow: true,
19 steerRejectionReason: "Context compaction must run as a separate turn.",
20 text: "/compact",
21 });
22​
23 expect(controls.canSend).toBe(expected);
24 },
25 );
26​
27 it.each([false, true])(
28 "gates a queued /compact with compaction skip %s",
29 (promoteSkipsCompaction) => {
30 const controls = resolveThreadQueueRowControls({
31 busy: false,
32 canPromoteToSteer: true,
33 canSendNow: false,
34 steerRejectionReason: "Context compaction must run as a separate turn.",
35 text: "/compact",
36 promoteSkipsCompaction,
37 });
38 expect(controls.canSend).toBe(promoteSkipsCompaction);
39 },
40 );
41​
42 it("shows an assistant quote as its quoted text", () => {
43 const href = formatAssistantCitationHref({
44 version: 1,
45 environmentId: "environment:test" as never,
46 threadId: "thread:test" as never,
47 messageId: "message:assistant" as never,
48 text: "Retry the sync after the lock clears.",
49 start: 0,
50 end: 37,
51 prefix: "",
52 suffix: "",
53 });
54 const controls = resolveThreadQueueRowControls({
55 busy: false,
56 canPromoteToSteer: true,
57 canSendNow: false,
58 steerRejectionReason: null,
59 text: `[Assistant quote](${href}) Can we add a backoff here?`,
60 });
61​
62 expect(controls.displayText).toBe(
63 "Retry the sync after the lock clears. Can we add a backoff here?",
64 );
65 });
66​
67 it("keeps the row already open in the composer from being reopened or steered", () => {
68 const editing = resolveThreadQueueRowControls({
69 busy: false,
70 canPromoteToSteer: true,
71 canSendNow: false,
72 isEditing: true,
73 steerRejectionReason: null,
74 text: "Being edited",
75 });
76​
77 expect(editing.isEditing).toBe(true);
78 expect(editing.canEdit).toBe(false);
79 expect(editing.canSend).toBe(false);
80 expect(editing.canDismiss).toBe(true);
81 });
82​
83 it("lets the owner cancel a guest's queued message but not rewrite it", () => {
84 const guest = resolveThreadQueueRowControls({
85 busy: false,
86 canPromoteToSteer: true,
87 canSendNow: false,
88 isGuestMessage: true,
89 steerRejectionReason: null,
90 text: "Why?",
91 });
92​
93 expect(guest.canEdit).toBe(false);
94 expect(guest.canDismiss).toBe(true);
95 });
96});