diff --git a/packages/core/test/lib/session-message.ts b/packages/core/test/lib/session-message.ts new file mode 100644 index 00000000000..30f01d54170 --- /dev/null +++ b/packages/core/test/lib/session-message.ts @@ -0,0 +1,26 @@ +export * as Expected from "./session-message.js" + +// Partial expected values, not input fixtures. Keep each assertion's matcher and fields explicit. +export const user = (text: Text) => ({ type: "user" as const, text }) + +export const text = (text: Text) => ({ type: "text" as const, text }) + +export const reasoning = (text: Text) => ({ type: "reasoning" as const, text }) + +export const assistant = (fields: Fields, content: Content) => ({ + ...fields, + type: "assistant" as const, + content, +}) + +export const completedTool = (identity: Identity, fields: Fields) => ({ + ...identity, + type: "tool" as const, + state: { ...fields, status: "completed" as const }, +}) + +export const failedTool = (identity: Identity, fields: Fields) => ({ + ...identity, + type: "tool" as const, + state: { ...fields, status: "error" as const }, +}) diff --git a/packages/core/test/session-create.test.ts b/packages/core/test/session-create.test.ts index b6e70ddd88a..8ab7af02401 100644 --- a/packages/core/test/session-create.test.ts +++ b/packages/core/test/session-create.test.ts @@ -32,6 +32,7 @@ import { SessionTable } from "@opencode-ai/core/session/sql" import { SessionStore } from "@opencode-ai/core/session/store" import { SessionTransfer } from "@opencode-ai/core/session/transfer" import { Workspace } from "@opencode-ai/core/workspace" +import { Expected } from "./lib/session-message" import { testEffect } from "./lib/effect" import { LocationServiceMap } from "@opencode-ai/core/location-service-map" import { promptLocationLayer } from "./fixture/prompt-location" @@ -186,7 +187,7 @@ describe("Session.create", () => { "session.inbox.enqueued", ]) expect(yield* session.messages({ sessionID: created.id })).toMatchObject([ - { id: expect.any(String), type: "user", text: "Preserved history" }, + { id: expect.any(String), ...Expected.user("Preserved history") }, ]) expect(yield* SessionInbox.find(db, pending.id)).toMatchObject({ payload: { text: "Preserved inbox" } }) expect( @@ -449,10 +450,7 @@ describe("Session.create", () => { expect(forked).toMatchObject({ title: "Parent (fork #1)", fork: { sessionID: parent.id } }) expect(forked.parentID).toBeUndefined() - expect(forkContext).toMatchObject([ - { type: "user", text: "First" }, - { type: "synthetic", text: "parent note" }, - ]) + expect(forkContext).toMatchObject([Expected.user("First"), { type: "synthetic", text: "parent note" }]) expect(forkContext.map((message) => message.id)).not.toEqual(parentContext.map((message) => message.id)) expect(history).toHaveLength(1) expect(history[0]).toMatchObject({ @@ -637,13 +635,10 @@ describe("Session.create", () => { const forked = yield* session.fork({ sessionID: parent.id, boundary: { type: "through" } }) expect(yield* session.context(parent.id)).toMatchObject([ - { type: "user", text: "Run both tools" }, - { - type: "assistant", - content: [{ type: "tool", id: "call_running", state: { status: "running" } }], - }, + Expected.user("Run both tools"), + Expected.assistant({}, [{ type: "tool", id: "call_running", state: { status: "running" } }]), ]) - expect(yield* session.context(forked.id)).toMatchObject([{ type: "user", text: "Run both tools" }]) + expect(yield* session.context(forked.id)).toMatchObject([Expected.user("Run both tools")]) }), ) @@ -670,10 +665,10 @@ describe("Session.create", () => { const running = yield* session.fork({ sessionID: parent.id, boundary: { type: "through" } }) expect(yield* session.context(parent.id)).toMatchObject([ - { type: "user", text: "Run a shell" }, + Expected.user("Run a shell"), { type: "shell", command: "sleep 10", status: "running" }, ]) - expect(yield* session.context(running.id)).toMatchObject([{ type: "user", text: "Run a shell" }]) + expect(yield* session.context(running.id)).toMatchObject([Expected.user("Run a shell")]) yield* bus.publish(SessionEvent.Shell.Ended, { sessionID: parent.id, @@ -682,9 +677,9 @@ describe("Session.create", () => { }) const completed = yield* session.fork({ sessionID: parent.id, boundary: { type: "through" } }) - expect(yield* session.context(running.id)).toMatchObject([{ type: "user", text: "Run a shell" }]) + expect(yield* session.context(running.id)).toMatchObject([Expected.user("Run a shell")]) expect(yield* session.context(completed.id)).toMatchObject([ - { type: "user", text: "Run a shell" }, + Expected.user("Run a shell"), { type: "shell", command: "sleep 10", status: "exited", output: { output: "complete" } }, ]) }), @@ -760,8 +755,8 @@ describe("Session.create", () => { expect(yield* session.context(beforeFirst.id)).toEqual([]) expect(beforeFirst).toMatchObject({ cost: 0, tokens: { input: 0, output: 0, reasoning: 0 } }) expect(yield* session.context(complete.id)).toMatchObject([ - { type: "user", text: "First" }, - { type: "user", text: "Second" }, + Expected.user("First"), + Expected.user("Second"), { type: "assistant", finish: "stop" }, ]) expect(complete).toMatchObject({ @@ -936,7 +931,7 @@ describe("Session.create", () => { yield* Effect.forEach(serialized.slice(2), (event) => bus.replay(event), { discard: true }) expect(yield* SessionInbox.find(db, admitted.id)).toBeUndefined() expect(yield* store.context(created.id)).toMatchObject([ - { id: admitted.id, type: "user", text: "Replay lifecycle" }, + { id: admitted.id, ...Expected.user("Replay lifecycle") }, ]) expect( (yield* db @@ -1160,9 +1155,7 @@ describe("SessionTransfer", () => { recent: "pending", }) - expect((yield* transfer.export({ sessionID: source.id })).messages).toMatchObject([ - { type: "user", text: "Settled" }, - ]) + expect((yield* transfer.export({ sessionID: source.id })).messages).toMatchObject([Expected.user("Settled")]) }), ) @@ -1307,7 +1300,7 @@ describe("SessionTransfer", () => { expect(imported).toMatchObject({ id: sessionID, title: "Exported", location }) expect(imported.time).toMatchObject({ idle: DateTime.makeUnsafe(200), viewed: DateTime.makeUnsafe(150) }) expect(messages).toMatchObject([ - { id: sourceMessageID, type: "user", text: "Imported message" }, + { id: sourceMessageID, ...Expected.user("Imported message") }, { id: errorMessageID, type: "compaction", error: { type: "test_error", message: "Original error" } }, ]) expect(yield* Bus.latestSequence(db, sessionID)).toBe(2) diff --git a/packages/core/test/session-runner.test.ts b/packages/core/test/session-runner.test.ts index 5c96f381ded..ef75a0f2fc0 100644 --- a/packages/core/test/session-runner.test.ts +++ b/packages/core/test/session-runner.test.ts @@ -83,6 +83,7 @@ import { asc, desc, eq, sql } from "drizzle-orm" import { testEffect } from "./lib/effect" import { promptLocationLayer } from "./fixture/prompt-location" import { LocationServiceMap } from "@opencode-ai/core/location-service-map" +import { Expected } from "./lib/session-message" import { permissionLayer } from "./lib/permission" import { agentHost, catalogHost, host } from "./plugin/host" import { CodeModeInstructions } from "@opencode-ai/core/codemode/instructions" @@ -847,24 +848,15 @@ const verifyPartialFlushOnFailure = (kind: FragmentKind) => expect(yield* session.resume(sessionID).pipe(Effect.flip)).toBe(failure) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: prompt }, - { - type: "assistant", - finish: "error", - error: { type: "provider.transport", message: "Provider unavailable" }, - content: [ - kind === "tool input" - ? { - type: "tool", - id: fragmentID(kind, "partial"), - state: { - status: "error", - error: { type: "provider.transport", message: "Provider unavailable" }, - }, - } - : fixture.expectedContent, - ], - }, + Expected.user(prompt), + Expected.assistant({ finish: "error", error: { type: "provider.transport", message: "Provider unavailable" } }, [ + kind === "tool input" + ? Expected.failedTool( + { id: fragmentID(kind, "partial") }, + { error: { type: "provider.transport", message: "Provider unavailable" } }, + ) + : fixture.expectedContent, + ]), ]) expect(requests).toHaveLength(1) }) @@ -888,17 +880,12 @@ const verifyPartialFlushOnInterruption = (kind: FragmentKind) => yield* Deferred.await(streamed) yield* Fiber.interrupt(fiber) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: prompt }, - { - type: "assistant", - finish: "error", - error: { type: "aborted", message: "Step interrupted" }, - content: [ - kind === "tool input" - ? { type: "tool", id: fragmentID(kind, "interrupted"), state: { status: "error" } } - : fixture.expectedContent, - ], - }, + Expected.user(prompt), + Expected.assistant({ finish: "error", error: { type: "aborted", message: "Step interrupted" } }, [ + kind === "tool input" + ? Expected.failedTool({ id: fragmentID(kind, "interrupted") }, {}) + : fixture.expectedContent, + ]), ]) }) @@ -1064,17 +1051,8 @@ describe("SessionRunnerLLM", () => { expect(requests[0]?.providerOptions).toEqual({ reasoningEffort: "high" }) expect(executions).toEqual([]) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Original message" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-removed", - state: { status: "error", error: { type: "tool.execution" } }, - }, - ], - }, + Expected.user("Original message"), + Expected.assistant({}, [Expected.failedTool({ id: "call-removed" }, { error: { type: "tool.execution" } })]), ]) }), ) @@ -1233,17 +1211,10 @@ describe("SessionRunnerLLM", () => { ]) expect(Array.from(yield* Fiber.join(progressFiber))[0]?.data.metadata).toEqual({ phase: "reading" }) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Use application context" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-location", - state: { status: "completed", content: [{ type: "text", text: '{"answer":"HELLO"}' }] }, - }, - ], - }, + Expected.user("Use application context"), + Expected.assistant({}, [ + Expected.completedTool({ id: "call-location" }, { content: [Expected.text('{"answer":"HELLO"}')] }), + ]), ]) }), ) @@ -1294,17 +1265,10 @@ describe("SessionRunnerLLM", () => { expect(executions).toEqual(["advertised"]) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Use the reloaded tool" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-reloaded", - state: { status: "completed", content: [{ type: "text", text: '{"value":"advertised"}' }] }, - }, - ], - }, + Expected.user("Use the reloaded tool"), + Expected.assistant({}, [ + Expected.completedTool({ id: "call-reloaded" }, { content: [Expected.text('{"value":"advertised"}')] }), + ]), ]) }), ) @@ -1792,7 +1756,7 @@ describe("SessionRunnerLLM", () => { [defaultSystem, "Initial context"], ]) expect(messageRoles(requests[1])).toEqual(["user", "system", "user"]) - expect(requests[1]?.messages.at(1)?.content).toEqual([{ type: "text", text: "Changed context" }]) + expect(requests[1]?.messages.at(1)?.content).toEqual([Expected.text("Changed context")]) // The chronological update is a durable client-visible system message. const messages = yield* session.messages({ sessionID }) expect(messages).toHaveLength(3) @@ -2081,7 +2045,7 @@ describe("SessionRunnerLLM", () => { expect(messageRoles(requests[1])).toEqual(["user", "system", "user"]) expect(requests[1]?.messages.at(1)?.content).toEqual([ - { type: "text", text: "System context source removed: test/context" }, + Expected.text("System context source removed: test/context"), ]) expect(yield* session.messages({ sessionID })).toHaveLength(3) }), @@ -2106,9 +2070,8 @@ describe("SessionRunnerLLM", () => { expect(messageRoles(requests[1])).toEqual(["user", "system", "user"]) expect(requests[1]?.messages.at(1)?.content).toEqual([ - { - type: "text", - text: [ + Expected.text( + [ 'The context under "deploy-target" changed and supersedes the previous value:', '', "{", @@ -2116,7 +2079,7 @@ describe("SessionRunnerLLM", () => { "}", "", ].join("\n"), - }, + ), ]) expect(yield* contextEntries.list(sessionID)).toEqual([{ key: "deploy-target", value: { region: "us-east-1" } }]) @@ -2126,7 +2089,7 @@ describe("SessionRunnerLLM", () => { expect(messageRoles(requests[2])).toEqual(["user", "system", "user", "system", "user"]) expect(requests[2]?.messages.at(-2)?.content).toEqual([ - { type: "text", text: 'The context under "deploy-target" no longer applies. Disregard it.' }, + Expected.text('The context under "deploy-target" no longer applies. Disregard it.'), ]) expect(yield* contextEntries.list(sessionID)).toEqual([]) }), @@ -2143,15 +2106,14 @@ describe("SessionRunnerLLM", () => { yield* runPrompt(session, "Second") expect(requests[1]?.messages.at(1)?.content).toEqual([ - { - type: "text", - text: [ + Expected.text( + [ 'The context under "nullable" changed and supersedes the previous value:', '', "null", "", ].join("\n"), - }, + ), ]) expect(yield* entries.list(sessionID)).toEqual([{ key: "nullable", value: null }]) }), @@ -2254,7 +2216,7 @@ describe("SessionRunnerLLM", () => { [defaultSystem, "Initial context"], ]) expect(messageRoles(requests[1])).toEqual(["user", "system", "user"]) - expect(requests[1]?.messages.at(1)?.content).toEqual([{ type: "text", text: "Replacement context" }]) + expect(requests[1]?.messages.at(1)?.content).toEqual([Expected.text("Replacement context")]) yield* replaySessionProjection(sessionID) yield* runPrompt(session, "Third") }), @@ -2868,7 +2830,7 @@ describe("SessionRunnerLLM", () => { }), ) expect(context.slice(-3)).toMatchObject([ - { type: "user", text: "Continue" }, + Expected.user("Continue"), { type: "compaction", status: "failed", reason: "auto" }, { type: "assistant", finish: "error", error: { message: "prompt too long" } }, ]) @@ -2986,40 +2948,34 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(1) expect(requests[0]?.tools.map((tool) => tool.name)).toEqual(["defect", "echo", "storefail"]) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Use tools" }, + Expected.user("Use tools"), { type: "assistant", finish: "tool-calls", cost: 0, tokens: { input: 8, output: 3, reasoning: 1, cache: { read: 2, write: 0 } }, content: [ - { type: "reasoning", text: "Think" }, - { - type: "tool", - id: "call-error", - name: "write", - state: { - status: "error", - input: { path: "README.md" }, - error: { type: "tool.execution", message: "Denied" }, + Expected.reasoning("Think"), + Expected.failedTool( + { id: "call-error", name: "write" }, + { input: { path: "README.md" }, error: { type: "tool.execution", message: "Denied" } }, + ), + Expected.completedTool( + { + id: "call-provider", + name: "web_search", + executed: true, + providerState: { source: "provider" }, + providerResultState: { source: "provider" }, }, - }, - { - type: "tool", - id: "call-provider", - name: "web_search", - executed: true, - providerState: { source: "provider" }, - providerResultState: { source: "provider" }, - state: { - status: "completed", + { input: { query: "hello" }, content: [ - { type: "text", text: "Hello" }, + Expected.text("Hello"), { type: "file", mime: "image/png", uri: "data:image/png;base64,aGVsbG8=", name: "hello.png" }, ], }, - }, + ), ], }, ]) @@ -3041,24 +2997,14 @@ describe("SessionRunnerLLM", () => { expect(executions).toEqual(["hello"]) const context = yield* session.context(sessionID) expect(context).toMatchObject([ - { type: "user", text: "Echo this" }, - { - type: "assistant", - finish: "tool-calls", - content: [ - { - type: "tool", - id: "call-echo", - name: "echo", - state: { - status: "completed", - input: { text: "hello" }, - content: [{ type: "text", text: "hello" }], - }, - }, - ], - }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Done" }] }, + Expected.user("Echo this"), + Expected.assistant({ finish: "tool-calls" }, [ + Expected.completedTool( + { id: "call-echo", name: "echo" }, + { input: { text: "hello" }, content: [Expected.text("hello")] }, + ), + ]), + Expected.assistant({ finish: "stop" }, [Expected.text("Done")]), ]) const assistant = requireAssistant(context) expect(yield* recordedStepSettlementTypes(sessionID, assistant.id)).toEqual([ @@ -3180,22 +3126,19 @@ describe("SessionRunnerLLM", () => { yield* replaySessionProjection(sessionID) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Think first" }, - { - type: "assistant", - content: [ - { - type: "reasoning", - text: "Signed thought", - state: { signature: "sig_1" }, - }, - { - type: "reasoning", - text: "Encrypted thought", - state: { itemId: "rs_1", reasoningEncryptedContent: "encrypted-state" }, - }, - ], - }, + Expected.user("Think first"), + Expected.assistant({}, [ + { + type: "reasoning", + text: "Signed thought", + state: { signature: "sig_1" }, + }, + { + type: "reasoning", + text: "Encrypted thought", + state: { itemId: "rs_1", reasoningEncryptedContent: "encrypted-state" }, + }, + ]), ]) yield* admit(session, "Continue") @@ -3242,11 +3185,10 @@ describe("SessionRunnerLLM", () => { yield* replaySessionProjection(sessionID) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Check first" }, - { - type: "assistant", - content: [{ type: "text", text: "Checking.", state: { itemId: "msg_commentary", phase: "commentary" } }], - }, + Expected.user("Check first"), + Expected.assistant({}, [ + { type: "text", text: "Checking.", state: { itemId: "msg_commentary", phase: "commentary" } }, + ]), ]) yield* admit(session, "Continue") @@ -3343,7 +3285,7 @@ describe("SessionRunnerLLM", () => { expect(executions).toHaveLength(5) expect(yield* tools.maxActive).toBe(5) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Echo five times" }, + Expected.user("Echo five times"), { type: "assistant", content: Array.from({ length: 5 }, (_, index) => ({ @@ -3381,27 +3323,9 @@ describe("SessionRunnerLLM", () => { yield* session.resume(sessionID) const expected = [ - { type: "user", text: "Echo twice" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "tool_0", - state: { status: "completed", content: [{ type: "text", text: "first" }] }, - }, - ], - }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "tool_0", - state: { status: "completed", content: [{ type: "text", text: "second" }] }, - }, - ], - }, + Expected.user("Echo twice"), + Expected.assistant({}, [Expected.completedTool({ id: "tool_0" }, { content: [Expected.text("first")] })]), + Expected.assistant({}, [Expected.completedTool({ id: "tool_0" }, { content: [Expected.text("second")] })]), ] expect(executions).toEqual(["first", "second"]) expect(requests).toHaveLength(3) @@ -3433,8 +3357,8 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(1) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Run once" }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Once" }] }, + Expected.user("Run once"), + Expected.assistant({ finish: "stop" }, [Expected.text("Once")]), ]) }), ) @@ -3858,20 +3782,13 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(1) expect(messageRoles(requests[0])).toEqual(["user", "assistant", "tool"]) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Recover interrupted tool" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-interrupted", - state: { - status: "error", - error: { type: "aborted", message: "Tool execution interrupted: echo" }, - }, - }, - ], - }, + Expected.user("Recover interrupted tool"), + Expected.assistant({}, [ + Expected.failedTool( + { id: "call-interrupted" }, + { error: { type: "aborted", message: "Tool execution interrupted: echo" } }, + ), + ]), ]) }), ) @@ -3926,24 +3843,19 @@ describe("SessionRunnerLLM", () => { yield* session.resume(sessionID) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Recover interrupted subagent" }, - { - type: "assistant", - content: [ + Expected.user("Recover interrupted subagent"), + Expected.assistant({}, [ + Expected.failedTool( + { id: "call-interrupted-subagent" }, { - type: "tool", - id: "call-interrupted-subagent", - state: { - status: "error", - error: { - type: "aborted", - message: "Tool execution interrupted: subagent (sessionID: ses_existing_child)", - }, - metadata: { sessionID: "ses_existing_child", status: "running", internal: "private" }, + error: { + type: "aborted", + message: "Tool execution interrupted: subagent (sessionID: ses_existing_child)", }, + metadata: { sessionID: "ses_existing_child", status: "running", internal: "private" }, }, - ], - }, + ), + ]), ]) const modelResult = JSON.stringify(requests[0]?.messages.at(-1)) expect(modelResult).toContain("ses_existing_child") @@ -4028,8 +3940,8 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(1) expect(messageRoles(requests[0])).toEqual(["user", "assistant", "tool"]) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Recover interrupted tool input" }, - { type: "assistant", content: [{ type: "tool", id: "call-pending-interrupted", state: { status: "error" } }] }, + Expected.user("Recover interrupted tool input"), + Expected.assistant({}, [Expected.failedTool({ id: "call-pending-interrupted" }, {})]), ]) }), ) @@ -4214,21 +4126,14 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(2) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Call missing" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-missing", - state: { - status: "error", - error: { type: "tool.execution", message: "Unknown tool: missing" }, - }, - }, - ], - }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.user("Call missing"), + Expected.assistant({}, [ + Expected.failedTool( + { id: "call-missing" }, + { error: { type: "tool.execution", message: "Unknown tool: missing" } }, + ), + ]), + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) }), ) @@ -4246,21 +4151,11 @@ describe("SessionRunnerLLM", () => { expect(messageRoles(requests[1])).toEqual(["user", "assistant", "tool"]) const context = yield* session.context(sessionID) expect(context).toMatchObject([ - { type: "user", text: "Call defect" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-defect", - state: { - status: "error", - error: { type: "unknown", message: "unexpected tool defect" }, - }, - }, - ], - }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.user("Call defect"), + Expected.assistant({}, [ + Expected.failedTool({ id: "call-defect" }, { error: { type: "unknown", message: "unexpected tool defect" } }), + ]), + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) const assistant = requireAssistant(context) expect(yield* recordedStepSettlementTypes(sessionID, assistant.id)).toEqual([ @@ -4300,13 +4195,10 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(2) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Call blocked" }, - { - type: "assistant", - content: [ - { type: "tool", id: "call-blocked", state: { status: "error", error: { message: "Permission blocked" } } }, - ], - }, + Expected.user("Call blocked"), + Expected.assistant({}, [ + Expected.failedTool({ id: "call-blocked" }, { error: { message: "Permission blocked" } }), + ]), { type: "assistant", finish: "stop" }, ]) }), @@ -4339,17 +4231,13 @@ describe("SessionRunnerLLM", () => { if (exit._tag === "Failure") expect(Cause.hasInterruptsOnly(exit.cause)).toBe(true) expect(requests).toHaveLength(1) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Call declined" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-declined", - state: { status: "error", error: { type: "aborted", message: "The user declined this tool call" } }, - }, - ], - }, + Expected.user("Call declined"), + Expected.assistant({}, [ + Expected.failedTool( + { id: "call-declined" }, + { error: { type: "aborted", message: "The user declined this tool call" } }, + ), + ]), ]) }), ) @@ -4382,13 +4270,10 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(2) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Call corrected" }, - { - type: "assistant", - content: [ - { type: "tool", id: "call-corrected", state: { status: "error", error: { message: "Use another tool" } } }, - ], - }, + Expected.user("Call corrected"), + Expected.assistant({}, [ + Expected.failedTool({ id: "call-corrected" }, { error: { message: "Use another tool" } }), + ]), { type: "assistant", finish: "stop" }, ]) }), @@ -4410,22 +4295,17 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(2) expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { - type: "assistant", - content: [ + Expected.assistant({}, [ + Expected.failedTool( + { id: "call-permission" }, { - type: "tool", - id: "call-permission", - state: { - status: "error", - error: { - type: "permission.rejected", - message: "Permission denied: edit", - }, + error: { + type: "permission.rejected", + message: "Permission denied: edit", }, }, - ], - }, + ), + ]), { type: "assistant", finish: "stop" }, ]) expect(yield* recordedEventTypes(sessionID)).not.toContain("session.step.failed.1") @@ -4460,17 +4340,13 @@ describe("SessionRunnerLLM", () => { if (exit._tag === "Failure") expect(Cause.hasInterruptsOnly(exit.cause)).toBe(true) expect(requests).toHaveLength(1) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Ask then stop" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-question", - state: { status: "error", error: { type: "aborted", message: "The user dismissed this question" } }, - }, - ], - }, + Expected.user("Ask then stop"), + Expected.assistant({}, [ + Expected.failedTool( + { id: "call-question" }, + { error: { type: "aborted", message: "The user dismissed this question" } }, + ), + ]), ]) }), ) @@ -4496,17 +4372,10 @@ describe("SessionRunnerLLM", () => { const context = yield* session.context(sessionID) expect(context).toMatchObject([ - { type: "user", text: "Settle before failing" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-before-failure", - state: { status: "completed", content: [{ type: "text", text: "settle" }] }, - }, - ], - }, + Expected.user("Settle before failing"), + Expected.assistant({}, [ + Expected.completedTool({ id: "call-before-failure" }, { content: [Expected.text("settle")] }), + ]), ]) const assistant = requireAssistant(context) expect(yield* recordedStepSettlementTypes(sessionID, assistant.id)).toEqual([ @@ -4538,17 +4407,13 @@ describe("SessionRunnerLLM", () => { yield* session.interrupt(sessionID) const context = yield* session.context(sessionID) expect(context).toMatchObject([ - { type: "user", text: "Interrupt blocked tool" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-before-interrupt", - state: { status: "error", error: { type: "aborted", message: "Tool execution interrupted" } }, - }, - ], - }, + Expected.user("Interrupt blocked tool"), + Expected.assistant({}, [ + Expected.failedTool( + { id: "call-before-interrupt" }, + { error: { type: "aborted", message: "Tool execution interrupted" } }, + ), + ]), ]) const assistant = requireAssistant(context) expect(yield* recordedStepSettlementTypes(sessionID, assistant.id)).toEqual([ @@ -4561,8 +4426,8 @@ describe("SessionRunnerLLM", () => { yield* replaySessionProjection(sessionID) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Interrupt blocked tool" }, - { type: "assistant", content: [{ type: "tool", id: "call-before-interrupt", state: { status: "error" } }] }, + Expected.user("Interrupt blocked tool"), + Expected.assistant({}, [Expected.failedTool({ id: "call-before-interrupt" }, {})]), ]) requests.length = 0 yield* TestLLM.push([]) @@ -4585,7 +4450,7 @@ describe("SessionRunnerLLM", () => { expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBeTrue() expect(requests).toHaveLength(1) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Interrupt provider" }, + Expected.user("Interrupt provider"), { type: "assistant", finish: "error", error: { type: "aborted", message: "Step interrupted" } }, ]) expect(yield* recordedEventTypes(sessionID)).toContain("session.step.failed.1") @@ -4615,19 +4480,13 @@ describe("SessionRunnerLLM", () => { const exit = yield* Fiber.await(run) expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBe(true) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Interrupt tool settlement" }, - { - type: "assistant", - finish: "error", - error: { type: "aborted", message: "Step interrupted" }, - content: [ - { - type: "tool", - id: "call-await-interrupt", - state: { status: "error", error: { type: "aborted", message: "Tool execution interrupted" } }, - }, - ], - }, + Expected.user("Interrupt tool settlement"), + Expected.assistant({ finish: "error", error: { type: "aborted", message: "Step interrupted" } }, [ + Expected.failedTool( + { id: "call-await-interrupt" }, + { error: { type: "aborted", message: "Tool execution interrupted" } }, + ), + ]), ]) const eventTypes = yield* recordedEventTypes(sessionID) expect(eventTypes.filter((type) => type === "session.tool.failed.2")).toHaveLength(1) @@ -4667,9 +4526,9 @@ describe("SessionRunnerLLM", () => { }) expect(executions).toEqual(["done"]) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Finish at the limit" }, - { type: "assistant", content: [{ type: "tool", id: "call-terminal", state: { status: "completed" } }] }, - { type: "assistant", content: [{ type: "tool", id: "call-forbidden", state: { status: "error" } }] }, + Expected.user("Finish at the limit"), + Expected.assistant({}, [Expected.completedTool({ id: "call-terminal" }, {})]), + Expected.assistant({}, [Expected.failedTool({ id: "call-forbidden" }, {})]), ]) }), ) @@ -4718,7 +4577,7 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(1) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Fail durably" }, + Expected.user("Fail durably"), { type: "assistant", finish: "error", error: { type: "provider.unknown", message: "Provider unavailable" } }, ]) }), @@ -4733,7 +4592,7 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(1) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Fail before step" }, + Expected.user("Fail before step"), { type: "assistant", finish: "error", error: { type: "provider.unknown", message: "Provider unavailable" } }, ]) }), @@ -4763,7 +4622,7 @@ describe("SessionRunnerLLM", () => { finish: "stop", rawFinish: "end_turn", providerState: { responseId: "response-1", serviceTier: "priority" }, - content: [{ type: "text", text: "Complete" }], + content: [Expected.text("Complete")], }, ]) }), @@ -4805,7 +4664,7 @@ describe("SessionRunnerLLM", () => { error: { type: "provider.content-filter" }, cost: 0, tokens: { input: 8, output: 2, reasoning: 1, cache: { read: 0, write: 0 } }, - content: [{ type: "text", text: "Partial" }], + content: [Expected.text("Partial")], }, ]) expect(yield* session.get(sessionID)).toMatchObject({ @@ -4861,13 +4720,8 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(1) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Fail after output" }, - { - type: "assistant", - finish: "error", - error: { message: "prompt too long" }, - content: [{ type: "text", text: "Partial" }], - }, + Expected.user("Fail after output"), + Expected.assistant({ finish: "error", error: { message: "prompt too long" } }, [Expected.text("Partial")]), ]) }), ) @@ -4881,7 +4735,7 @@ describe("SessionRunnerLLM", () => { expect(yield* runPrompt(session, "Fail raw stream durably").pipe(Effect.flip)).toBe(failure) yield* replaySessionProjection(sessionID) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Fail raw stream durably" }, + Expected.user("Fail raw stream durably"), { type: "assistant", finish: "error", error: { type: "provider.invalid-request", message: "Invalid request" } }, ]) }), @@ -4907,7 +4761,7 @@ describe("SessionRunnerLLM", () => { expect(eventTypes.filter((type) => type === "session.step.started.1")).toHaveLength(2) expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) yield* replaySessionProjection(sessionID) expect((yield* session.context(sessionID)).filter((message) => message.type === "assistant")).toHaveLength(1) @@ -4950,7 +4804,7 @@ describe("SessionRunnerLLM", () => { expect(yield* recordedEventTypes(sessionID)).not.toContain("session.retry.scheduled.1") expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) }), ) @@ -4983,7 +4837,7 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(2) expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) }), ) @@ -5008,7 +4862,7 @@ describe("SessionRunnerLLM", () => { expect(yield* recordedEventTypes(sessionID)).toContain("session.retry.scheduled.1") expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) }), ) @@ -5066,18 +4920,13 @@ describe("SessionRunnerLLM", () => { }) const context = yield* session.context(sessionID) expect(context).toMatchObject([ - { type: "user", text: "Continue partial output" }, - { - type: "assistant", - finish: "error", - error: { type: "provider.invalid-output" }, - content: [{ type: "text", text: "Partial" }], - }, + Expected.user("Continue partial output"), + Expected.assistant({ finish: "error", error: { type: "provider.invalid-output" } }, [Expected.text("Partial")]), { type: "synthetic", text: INCOMPLETE_STREAM_CONTINUATION, }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: " continuation" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text(" continuation")]), ]) const assistants = context.filter((message) => message.type === "assistant") expect(new Set(assistants.map((message) => message.id)).size).toBe(2) @@ -5114,9 +4963,9 @@ describe("SessionRunnerLLM", () => { }) expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { type: "assistant", finish: "error", content: [{ type: "text", text: "Partial" }] }, + Expected.assistant({ finish: "error" }, [Expected.text("Partial")]), { type: "synthetic", text: INCOMPLETE_STREAM_CONTINUATION }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: " continuation" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text(" continuation")]), ]) }), ) @@ -5155,9 +5004,9 @@ describe("SessionRunnerLLM", () => { }) expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { type: "assistant", finish: "error", content: [{ type: "reasoning", text: "Partial thought" }] }, + Expected.assistant({ finish: "error" }, [Expected.reasoning("Partial thought")]), { type: "synthetic" }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) }), ) @@ -5193,19 +5042,15 @@ describe("SessionRunnerLLM", () => { ]) expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { - type: "assistant", - finish: "error", - content: [ - { - type: "reasoning", - text: "", - state: { itemId: "rs_disconnected", reasoningEncryptedContent: "encrypted-state" }, - }, - ], - }, + Expected.assistant({ finish: "error" }, [ + { + type: "reasoning", + text: "", + state: { itemId: "rs_disconnected", reasoningEncryptedContent: "encrypted-state" }, + }, + ]), { type: "synthetic", text: INCOMPLETE_STREAM_CONTINUATION }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) }), ) @@ -5271,18 +5116,14 @@ describe("SessionRunnerLLM", () => { expect(messageRoles(requests[1])).toEqual(["user", "assistant", "tool", "user"]) expect(yield* session.context(sessionID)).toMatchObject([ { type: "user" }, - { - type: "assistant", - content: [ - { - type: "tool", - id: "call-defect-before-close", - state: { status: "error", error: { type: "unknown", message: "unexpected tool defect" } }, - }, - ], - }, + Expected.assistant({}, [ + Expected.failedTool( + { id: "call-defect-before-close" }, + { error: { type: "unknown", message: "unexpected tool defect" } }, + ), + ]), { type: "synthetic", text: INCOMPLETE_STREAM_CONTINUATION }, - { type: "assistant", finish: "stop", content: [{ type: "text", text: "Recovered" }] }, + Expected.assistant({ finish: "stop" }, [Expected.text("Recovered")]), ]) }), ) @@ -5553,19 +5394,16 @@ describe("SessionRunnerLLM", () => { ) expect(failed).toMatchObject({ content: [ - { - type: "tool", - id: "call-malformed", - executed: false, - state: { - status: "error", + Expected.failedTool( + { id: "call-malformed", executed: false }, + { input: {}, error: { type: "tool.input-json", message: "Tool call arguments were malformed JSON and were not executed. Retry with valid JSON.", }, }, - }, + ), ], }) if (!failed) throw new Error("Malformed tool assistant missing") @@ -5656,15 +5494,11 @@ describe("SessionRunnerLLM", () => { expect(yield* Fiber.await(run)).toMatchObject({ _tag: "Failure" }) expect(requests).toHaveLength(1) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Interrupt malformed recovery" }, - { - type: "assistant", - error: { type: "aborted", message: "Step interrupted" }, - content: [ - { type: "tool", id: "call-valid", state: { status: "error", error: { type: "aborted" } } }, - { type: "tool", id: "call-malformed", state: { status: "error" } }, - ], - }, + Expected.user("Interrupt malformed recovery"), + Expected.assistant({ error: { type: "aborted", message: "Step interrupted" } }, [ + Expected.failedTool({ id: "call-valid" }, { error: { type: "aborted" } }), + Expected.failedTool({ id: "call-malformed" }, {}), + ]), ]) }), ) @@ -5690,12 +5524,7 @@ describe("SessionRunnerLLM", () => { expect(requireAssistant(yield* session.context(sessionID))).toMatchObject({ error: { type: "provider.invalid-output", message: "Invalid hosted tool input" }, content: [ - { - type: "tool", - id: "call-hosted", - executed: true, - state: { status: "error", error: { type: "provider.invalid-output" } }, - }, + Expected.failedTool({ id: "call-hosted", executed: true }, { error: { type: "provider.invalid-output" } }), ], }) }), @@ -5725,12 +5554,7 @@ describe("SessionRunnerLLM", () => { expect(requireAssistant(yield* session.context(sessionID))).toMatchObject({ error: { type: "provider.invalid-output", message: "Provider failed after malformed input" }, content: [ - { - type: "tool", - id: "call-malformed", - executed: false, - state: { status: "error", error: { type: "tool.input-json" } }, - }, + Expected.failedTool({ id: "call-malformed", executed: false }, { error: { type: "tool.input-json" } }), ], }) expect(requests).toHaveLength(1) @@ -5836,11 +5660,8 @@ describe("SessionRunnerLLM", () => { expect(requests).toHaveLength(1) const context = yield* session.context(sessionID) expect(context).toMatchObject([ - { type: "user", text: "Fail hosted tool durably" }, - { - type: "assistant", - content: [{ type: "tool", id: "call-hosted-provider-error", state: { status: "error" } }], - }, + Expected.user("Fail hosted tool durably"), + Expected.assistant({}, [Expected.failedTool({ id: "call-hosted-provider-error" }, {})]), ]) const assistant = requireAssistant(context) expect(yield* recordedStepSettlementTypes(sessionID, assistant.id)).toEqual([ @@ -5920,13 +5741,10 @@ describe("SessionRunnerLLM", () => { yield* replaySessionProjection(sessionID) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Fail hosted tool at EOF" }, - { - type: "assistant", - finish: "error", - error: { type: "tool.result-missing" }, - content: [{ type: "tool", id: "call-hosted-eof", state: { status: "error" } }], - }, + Expected.user("Fail hosted tool at EOF"), + Expected.assistant({ finish: "error", error: { type: "tool.result-missing" } }, [ + Expected.failedTool({ id: "call-hosted-eof" }, {}), + ]), ]) }), ) @@ -6019,13 +5837,11 @@ describe("SessionRunnerLLM", () => { ).toHaveLength(1) yield* replaySessionProjection(sessionID) expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Fail hosted tool on raw failure" }, - { - type: "assistant", - finish: "error", - error: { type: "provider.transport", message: "Provider unavailable" }, - content: [{ type: "tool", id: "call-hosted-raw-failure", state: { status: "error" } }], - }, + Expected.user("Fail hosted tool on raw failure"), + Expected.assistant( + { finish: "error", error: { type: "provider.transport", message: "Provider unavailable" } }, + [Expected.failedTool({ id: "call-hosted-raw-failure" }, {})], + ), ]) }), ) @@ -6063,14 +5879,8 @@ describe("SessionRunnerLLM", () => { yield* runPrompt(session, "Two blocks") expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Two blocks" }, - { - type: "assistant", - content: [ - { type: "text", text: "First" }, - { type: "text", text: "Second" }, - ], - }, + Expected.user("Two blocks"), + Expected.assistant({}, [Expected.text("First"), Expected.text("Second")]), ]) }), ) @@ -6117,11 +5927,8 @@ describe("SessionRunnerLLM", () => { yield* runPrompt(session, "Call provider tool") expect(yield* session.context(sessionID)).toMatchObject([ - { type: "user", text: "Call provider tool" }, - { - type: "assistant", - content: [{ type: "tool", id: "call-parsed", state: { status: "error", input: { query: "hello" } } }], - }, + Expected.user("Call provider tool"), + Expected.assistant({}, [Expected.failedTool({ id: "call-parsed" }, { input: { query: "hello" } })]), ]) }), ) diff --git a/packages/core/test/tool-shell.test.ts b/packages/core/test/tool-shell.test.ts index 3548333bbeb..9a62fc6c920 100644 --- a/packages/core/test/tool-shell.test.ts +++ b/packages/core/test/tool-shell.test.ts @@ -42,6 +42,7 @@ import { tmpdir } from "./fixture/tmpdir" import { tempGlobalLayer } from "./fixture/global" import { testEffect } from "./lib/effect" import { permissionLayer } from "./lib/permission" +import { Expected } from "./lib/session-message" import { toolIdentity, executeTool, registerToolPlugin, toolDefinitions } from "./lib/tool" const sessionID = Session.ID.make("ses_shell_tool_test") @@ -654,10 +655,7 @@ describe("ShellTool ordinary shell syntax", () => { value: { status: "completed", metadata: { exit: 0 } }, }) if (Exit.isSuccess(result.exit)) - expect(result.exit.value.content?.[0]).toEqual({ - type: "text", - text: isWindows ? "hello\r\n" : "hello\n", - }) + expect(result.exit.value.content?.[0]).toEqual(Expected.text(isWindows ? "hello\r\n" : "hello\n")) }), pwsh ?? "pwsh", )) @@ -728,10 +726,9 @@ describe("ShellTool", () => { expect(settled.status).toBe("completed") expect(settled.metadata).toMatchObject({ exit: 0, truncated: false }) expect(settled.content?.[0]).toEqual({ type: "text", text: "hello" }) - expect(settled.content?.[1]).toMatchObject({ - type: "text", - text: expect.stringContaining("Command exited with code 0."), - }) + expect(settled.content?.[1]).toMatchObject( + Expected.text(expect.stringContaining("Command exited with code 0.")), + ) expect(assertions).toMatchObject([ { sessionID, @@ -789,10 +786,9 @@ describe("ShellTool", () => { ), Effect.andThen((settled) => Effect.sync(() => - expect(settled.content?.[0]).toMatchObject({ - type: "text", - text: expect.stringContaining(realpathSync(path.join(tmp.path, "src"))), - }), + expect(settled.content?.[0]).toMatchObject( + Expected.text(expect.stringContaining(realpathSync(path.join(tmp.path, "src")))), + ), ), ), ) @@ -1121,10 +1117,9 @@ describe("ShellTool", () => { expect(settled.status).toBe("completed") expect(settled.metadata).toMatchObject({ exit: 7, truncated: false }) expect(settled.content?.[0]).toEqual({ type: "text", text: "body" }) - expect(settled.content?.[1]).toMatchObject({ - type: "text", - text: expect.stringContaining("Command exited with code 7"), - }) + expect(settled.content?.[1]).toMatchObject( + Expected.text(expect.stringContaining("Command exited with code 7")), + ) }), ), ) @@ -1151,10 +1146,9 @@ describe("ShellTool", () => { if (!content || content.type !== "text") throw new Error("Expected text content") expect(content.text.includes("output-start")).toBe(false) expect(content.text.includes("output-end")).toBe(true) - expect(content).toMatchObject({ - type: "text", - text: expect.stringContaining("output truncated; full output saved to:"), - }) + expect(content).toMatchObject( + Expected.text(expect.stringContaining("output truncated; full output saved to:")), + ) }), ), ) @@ -1260,14 +1254,8 @@ describe("ShellTool", () => { Effect.andThen((settled) => Effect.sync(() => { expect(settled.metadata).toMatchObject({ timeout: true, truncated: false }) - expect(settled.content?.[0]).toMatchObject({ - type: "text", - text: expect.stringContaining("before timeout"), - }) - expect(settled.content?.[1]).toMatchObject({ - type: "text", - text: expect.stringContaining("Command timed out"), - }) + expect(settled.content?.[0]).toMatchObject(Expected.text(expect.stringContaining("before timeout"))) + expect(settled.content?.[1]).toMatchObject(Expected.text(expect.stringContaining("Command timed out"))) }), ), ) diff --git a/packages/tui/test/cli/tui/data.test.tsx b/packages/tui/test/cli/tui/data.test.tsx index 29bf5952bec..bc6dd58f266 100644 --- a/packages/tui/test/cli/tui/data.test.tsx +++ b/packages/tui/test/cli/tui/data.test.tsx @@ -5,6 +5,7 @@ import type { OpenCodeEvent } from "@opencode-ai/client" import { SessionMessage } from "@opencode-ai/core/session/message" import { Bus } from "@opencode-ai/core/bus" import { Event } from "@opencode-ai/schema/event" +import { Expected } from "../../../../core/test/lib/session-message" import { createEffect, onMount, type ParentProps } from "solid-js" import { ConfigProvider } from "../../../src/config" import { ClientProvider, useClient } from "../../../src/context/client" @@ -2825,7 +2826,7 @@ test("renders admitted prompts immediately and tracks them until promoted", asyn }) await wait(() => sync.session.message.list(sessionID)?.length === 1) const admitted = sync.session.message.list(sessionID)?.[0] - expect(admitted).toMatchObject({ id: messageID, type: "user", text: "hello" }) + expect(admitted).toMatchObject({ id: messageID, ...Expected.user("hello") }) expect(admitted?.metadata).toBeUndefined() expect(sync.session.pending.list(sessionID)).toEqual([ { @@ -3250,7 +3251,7 @@ test("hydrates durable pending prompts into the visible transcript", async () => await mounted await sync.session.pending.sync(sessionID) expect(sync.session.message.list(sessionID)).toEqual([ - { id: item.id, type: "user", text: "waiting", time: { created: 5 } }, + { id: item.id, ...Expected.user("waiting"), time: { created: 5 } }, ]) await sync.session.message.sync(sessionID)