@tekyzinc/gsd-t 3.10.13 → 3.10.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -176,6 +176,15 @@ test("tool_use / tool_result pairing by tool_use_id preserved in order", async (
176
176
 
177
177
  test("tool_result with array content (text blocks) is normalized", async () => {
178
178
  const { dir, file } = mkTmpFile([
179
+ {
180
+ type: "assistant",
181
+ message: {
182
+ role: "assistant",
183
+ content: [
184
+ { type: "tool_use", id: "toolu_02", name: "Read", input: { file_path: "/tmp/x" } },
185
+ ],
186
+ },
187
+ },
179
188
  {
180
189
  type: "user",
181
190
  message: {
@@ -196,8 +205,8 @@ test("tool_result with array content (text blocks) is normalized", async () => {
196
205
  ]);
197
206
  try {
198
207
  const got = await parseTranscript(file);
199
- assert.equal(got.messages.length, 1);
200
- const tr = got.messages[0].content[0];
208
+ const userMsg = got.messages.find(m => m.role === "user");
209
+ const tr = userMsg.content[0];
201
210
  assert.equal(tr.type, "tool_result");
202
211
  assert.deepEqual(tr.content, [
203
212
  { type: "text", text: "line 1" },
@@ -210,6 +219,15 @@ test("tool_result with array content (text blocks) is normalized", async () => {
210
219
 
211
220
  test("tool_result with is_error:true preserved", async () => {
212
221
  const { dir, file } = mkTmpFile([
222
+ {
223
+ type: "assistant",
224
+ message: {
225
+ role: "assistant",
226
+ content: [
227
+ { type: "tool_use", id: "toolu_03", name: "Bash", input: { command: "false" } },
228
+ ],
229
+ },
230
+ },
213
231
  {
214
232
  type: "user",
215
233
  message: {
@@ -222,7 +240,8 @@ test("tool_result with is_error:true preserved", async () => {
222
240
  ]);
223
241
  try {
224
242
  const got = await parseTranscript(file);
225
- assert.equal(got.messages[0].content[0].is_error, true);
243
+ const userMsg = got.messages.find(m => m.role === "user");
244
+ assert.equal(userMsg.content[0].is_error, true);
226
245
  } finally {
227
246
  cleanup(dir);
228
247
  }
@@ -318,3 +337,34 @@ test("message with content array but no recognized blocks → message skipped",
318
337
  cleanup(dir);
319
338
  }
320
339
  });
340
+
341
+ test("orphaned tool_use without matching tool_result is stripped", async () => {
342
+ const { dir, file } = mkTmpFile([
343
+ { type: "user", message: { role: "user", content: "hello" } },
344
+ {
345
+ type: "assistant",
346
+ message: {
347
+ role: "assistant",
348
+ content: [
349
+ { type: "text", text: "I will read a file" },
350
+ { type: "tool_use", id: "toolu_orphan", name: "Read", input: { file_path: "/tmp/x" } },
351
+ ],
352
+ },
353
+ },
354
+ { type: "user", message: { role: "user", content: "thanks" } },
355
+ ]);
356
+ try {
357
+ const got = await parseTranscript(file);
358
+ const assistantMsg = got.messages.find(
359
+ (m) => m.role === "assistant" && m.content.some((b) => b.type === "text")
360
+ );
361
+ assert.ok(assistantMsg, "assistant message preserved");
362
+ assert.ok(
363
+ !assistantMsg.content.some((b) => b.type === "tool_use"),
364
+ "orphaned tool_use stripped"
365
+ );
366
+ assert.equal(assistantMsg.content[0].text, "I will read a file");
367
+ } finally {
368
+ cleanup(dir);
369
+ }
370
+ });