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

session-logic.command-output.test.ts

172 lines4.7 KB

1import { EventId, TurnId, type OrchestrationThreadActivity } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { deriveWorkLogEntries } from "./session-logic";
5​
6function makeCommandActivity(
7 id: string,
8 payload: Record<string, unknown>,
9): OrchestrationThreadActivity {
10 return {
11 id: EventId.make(id),
12 createdAt: "2026-07-17T10:00:00.000Z",
13 kind: "tool.completed",
14 summary: "Ran command",
15 tone: "tool",
16 payload,
17 turnId: TurnId.make("turn-1"),
18 };
20​
21describe("deriveWorkLogEntries command output", () => {
22 it("uses Codex aggregated output instead of repeating the command", () => {
23 const [entry] = deriveWorkLogEntries([
24 makeCommandActivity("codex-command", {
25 itemType: "command_execution",
26 title: "Ran command",
27 detail: "/bin/zsh -lc \"printf 'hello\\n'\"",
28 data: {
29 item: {
30 type: "commandExecution",
31 command: "/bin/zsh -lc \"printf 'hello\\n'\"",
32 commandActions: [{ command: "printf 'hello\\n'", type: "unknown" }],
33 aggregatedOutput: "hello\n<exited with exit code 0>",
34 status: "completed",
35 },
36 },
37 }),
38 ]);
39​
40 expect(entry).toMatchObject({
41 command: "printf 'hello\\n'",
42 rawCommand: "/bin/zsh -lc \"printf 'hello\\n'\"",
43 detail: "hello",
44 });
45 });
46​
47 it("uses a projected Claude output summary instead of repeating the command", () => {
48 const [entry] = deriveWorkLogEntries([
49 makeCommandActivity("claude-command", {
50 itemType: "command_execution",
51 title: "Ran command",
52 detail: "printf hello",
53 data: {
54 kind: "execute",
55 command: "printf hello",
56 rawOutput: {
57 content: "hello from claude",
58 },
59 },
60 }),
61 ]);
62​
63 expect(entry).toMatchObject({
64 command: "printf hello",
65 detail: "hello from claude",
66 });
67 });
68​
69 it("keeps command output that equals the command text", () => {
70 const [entry] = deriveWorkLogEntries([
71 makeCommandActivity("matching-output", {
72 itemType: "command_execution",
73 title: "Ran command",
74 detail: "printf hello",
75 data: {
76 command: "printf hello",
77 rawOutput: { content: "printf hello" },
78 },
79 }),
80 ]);
81​
82 expect(entry).toMatchObject({
83 command: "printf hello",
84 detail: "printf hello",
85 });
86 });
87​
88 it("keeps OpenCode detail-only output when it equals the command", () => {
89 const [entry] = deriveWorkLogEntries([
90 makeCommandActivity("opencode-detail-output", {
91 itemType: "command_execution",
92 title: "bash",
93 detail: "printf hello",
94 data: { command: "printf hello" },
95 }),
96 ]);
97​
98 expect(entry).toMatchObject({
99 command: "printf hello",
100 detail: "printf hello",
101 });
102 });
103​
104 it("drops a Claude tool-name detail when there is no output", () => {
105 const [entry] = deriveWorkLogEntries([
106 makeCommandActivity("claude-no-output", {
107 itemType: "command_execution",
108 title: "Command run",
109 detail: "Bash: printf hello",
110 data: {
111 toolName: "Bash",
112 command: "printf hello",
113 },
114 }),
115 ]);
116​
117 expect(entry?.command).toBe("printf hello");
118 expect(entry?.detail).toBeUndefined();
119 });
120​
121 it("drops a truncated Claude tool-name detail for a long command", () => {
122 const command = `git add -A && git commit -m "${"x".repeat(200)}"`;
123 const [entry] = deriveWorkLogEntries([
124 makeCommandActivity("claude-long-command", {
125 itemType: "command_execution",
126 title: "Command run",
127 detail: `Bash: ${command}`.slice(0, 177) + "...",
128 data: {
129 toolName: "Bash",
130 command,
131 },
132 }),
133 ]);
134​
135 expect(entry?.command).toBe(command);
136 expect(entry?.detail).toBeUndefined();
137 });
138​
139 it("drops an ACP command echo when the update omits the tool kind", () => {
140 const [entry] = deriveWorkLogEntries([
141 makeCommandActivity("acp-no-kind", {
142 itemType: "command_execution",
143 title: "Terminal",
144 detail: "pnpm test",
145 data: {
146 toolCallId: "tool-1",
147 command: "pnpm test",
148 },
149 }),
150 ]);
151​
152 expect(entry?.command).toBe("pnpm test");
153 expect(entry?.detail).toBeUndefined();
154 });
155​
156 it("drops duplicated command detail when the command has no output", () => {
157 const [entry] = deriveWorkLogEntries([
158 makeCommandActivity("empty-command", {
159 itemType: "command_execution",
160 title: "Ran command",
161 detail: "true",
162 data: {
163 kind: "execute",
164 command: "true",
165 },
166 }),
167 ]);
168​
169 expect(entry?.command).toBe("true");
170 expect(entry?.detail).toBeUndefined();
171 });
172});