Skip to content

Commit 10095bf

Browse files
chore: generate
1 parent 6a3b2f3 commit 10095bf

2 files changed

Lines changed: 63 additions & 44 deletions

File tree

packages/opencode/src/cli/cmd/run/session-replay.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ export function replaySession(input: ReplayInput): SessionReplay {
187187
}
188188
}
189189

190-
export function replayLocalRows(messages: SessionMessages, commits: StreamCommit[], rows: LocalReplayRow[]): StreamCommit[] {
190+
export function replayLocalRows(
191+
messages: SessionMessages,
192+
commits: StreamCommit[],
193+
rows: LocalReplayRow[],
194+
): StreamCommit[] {
191195
const persisted = new Set(messages.map((message) => message.info.id))
192196
return rows.reduce((out, local) => {
193197
const row = local.commit

packages/opencode/test/cli/run/session-replay.test.ts

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,9 @@ describe("run session replay", () => {
180180
messageID: "msg-user-1",
181181
} as const
182182

183-
expect(replayLocalRows([userMessage("msg-user-2", "successful")], [persisted], [{ commit: failed }, { commit: error }])).toEqual([
184-
failed,
185-
error,
186-
persisted,
187-
])
183+
expect(
184+
replayLocalRows([userMessage("msg-user-2", "successful")], [persisted], [{ commit: failed }, { commit: error }]),
185+
).toEqual([failed, error, persisted])
188186
})
189187

190188
test("retains local errors but not duplicate local prompts once a prompt persists", () => {
@@ -203,10 +201,13 @@ describe("run session replay", () => {
203201
messageID: "msg-user-1",
204202
} as const
205203

206-
expect(replayLocalRows([userMessage("msg-user-1", "failed after persistence")], [persisted], [{ commit: persisted }, { commit: error }])).toEqual([
207-
persisted,
208-
error,
209-
])
204+
expect(
205+
replayLocalRows(
206+
[userMessage("msg-user-1", "failed after persistence")],
207+
[persisted],
208+
[{ commit: persisted }, { commit: error }],
209+
),
210+
).toEqual([persisted, error])
210211
})
211212

212213
test("keeps a local turn failure below assistant output already visible for that turn", () => {
@@ -308,19 +309,23 @@ describe("run session replay", () => {
308309
} as const
309310

310311
expect(
311-
replayLocalRows([userMessage("msg-user-1", "start")], [first, complete], [
312-
{
313-
commit: error,
314-
after: {
315-
kind: "assistant",
316-
text: "before ",
317-
phase: "progress",
318-
messageID: "msg-assistant-1",
319-
partID: "part-1",
320-
visible: "before ",
312+
replayLocalRows(
313+
[userMessage("msg-user-1", "start")],
314+
[first, complete],
315+
[
316+
{
317+
commit: error,
318+
after: {
319+
kind: "assistant",
320+
text: "before ",
321+
phase: "progress",
322+
messageID: "msg-assistant-1",
323+
partID: "part-1",
324+
visible: "before ",
325+
},
321326
},
322-
},
323-
]),
327+
],
328+
),
324329
).toEqual([first, { ...complete, text: "before " }, error, { ...complete, text: "after" }])
325330
})
326331

@@ -348,13 +353,17 @@ describe("run session replay", () => {
348353
} as const
349354

350355
expect(
351-
replayLocalRows([], [answer], [
352-
{ commit: prompt },
353-
{
354-
commit: error,
355-
after: { kind: "assistant", text: "partial answer", phase: "progress", messageID: "msg-2" },
356-
},
357-
]),
356+
replayLocalRows(
357+
[],
358+
[answer],
359+
[
360+
{ commit: prompt },
361+
{
362+
commit: error,
363+
after: { kind: "assistant", text: "partial answer", phase: "progress", messageID: "msg-2" },
364+
},
365+
],
366+
),
358367
).toEqual([prompt, answer, error])
359368
})
360369

@@ -393,19 +402,23 @@ describe("run session replay", () => {
393402
} as const
394403

395404
expect(
396-
replayLocalRows([userMessage("msg-user-1", "run ls")], [prompt, running, completed], [
397-
{
398-
commit: error,
399-
after: {
400-
kind: "tool",
401-
text: "running bash",
402-
phase: "start",
403-
messageID: "msg-assistant-1",
404-
partID: "part-tool-1",
405-
toolState: "running",
405+
replayLocalRows(
406+
[userMessage("msg-user-1", "run ls")],
407+
[prompt, running, completed],
408+
[
409+
{
410+
commit: error,
411+
after: {
412+
kind: "tool",
413+
text: "running bash",
414+
phase: "start",
415+
messageID: "msg-assistant-1",
416+
partID: "part-tool-1",
417+
toolState: "running",
418+
},
406419
},
407-
},
408-
]),
420+
],
421+
),
409422
).toEqual([prompt, running, error, completed])
410423
})
411424

@@ -433,9 +446,11 @@ describe("run session replay", () => {
433446
} as const
434447

435448
expect(
436-
replayLocalRows([userMessage("msg-user-1", "before"), userMessage("msg-user-3", "after")], [first, second], [
437-
{ commit: error },
438-
]),
449+
replayLocalRows(
450+
[userMessage("msg-user-1", "before"), userMessage("msg-user-3", "after")],
451+
[first, second],
452+
[{ commit: error }],
453+
),
439454
).toEqual([first, error, second])
440455
})
441456
})

0 commit comments

Comments
 (0)