mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
test(core): simplify subagent recovery coverage
This commit is contained in:
parent
89c6eb67a9
commit
695a2b2133
3 changed files with 83 additions and 85 deletions
|
|
@ -24,7 +24,12 @@ import { fromRow } from "@opencode/core/session/info"
|
|||
import { SessionInbox } from "@opencode/core/session/inbox"
|
||||
import { SessionStore } from "@opencode/core/session/store"
|
||||
import { Shell } from "@opencode/schema/shell"
|
||||
import { InstructionStateTable, SessionInboxTable, SessionMessageTable, SessionTable } from "@opencode/core/session/sql"
|
||||
import {
|
||||
InstructionStateTable,
|
||||
SessionInboxTable,
|
||||
SessionMessageTable,
|
||||
SessionTable,
|
||||
} from "@opencode/core/session/sql"
|
||||
import { testEffect } from "./lib/effect"
|
||||
import { Snapshot } from "@opencode/core/snapshot"
|
||||
|
||||
|
|
@ -122,16 +127,12 @@ describe("SessionProjector", () => {
|
|||
id: "call-linked",
|
||||
metadata: { internal: "live-only" },
|
||||
})
|
||||
expect(yield* store.context(sessionID)).toMatchObject([
|
||||
{
|
||||
content: [
|
||||
{
|
||||
id: "call-linked",
|
||||
state: { status: "running", metadata: { sessionID: childSessionID, status: "running" } },
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
const assistant = (yield* store.context(sessionID)).find((message) => message.type === "assistant")
|
||||
expect(assistant?.content.find((part) => part.type === "tool")?.state).toEqual({
|
||||
status: "running",
|
||||
input: { agent: "general" },
|
||||
metadata: { sessionID: childSessionID, status: "running" },
|
||||
})
|
||||
expect(
|
||||
(yield* db.select().from(EventTable).where(eq(EventTable.aggregate_id, sessionID)).all()).map(
|
||||
(event) => event.type,
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ import { Location } from "@opencode/core/location"
|
|||
import { Provider } from "@opencode/core/provider"
|
||||
import { Cause, Context, DateTime, Deferred, Effect, Exit, Fiber, Layer, Queue, Schema, Scope, Stream } from "effect"
|
||||
import { TestClock } from "effect/testing"
|
||||
import { asc, desc, eq, sql } from "drizzle-orm"
|
||||
import { asc, desc, eq } from "drizzle-orm"
|
||||
import { testEffect } from "./lib/effect"
|
||||
import { promptLocationNode } from "./fixture/prompt-location"
|
||||
import { LocationServiceMap } from "@opencode/core/location-service-map"
|
||||
|
|
@ -4564,6 +4564,7 @@ describe("SessionRunnerLLM", () => {
|
|||
id: "call-interrupted-subagent",
|
||||
metadata: { sessionID: "ses_existing_child", status: "running", internal: "private" },
|
||||
})
|
||||
yield* replaySessionProjection(sessionID)
|
||||
s.requests.length = 0
|
||||
yield* s.llm.push([])
|
||||
yield* s.resume
|
||||
|
|
|
|||
|
|
@ -466,83 +466,79 @@ describe("SubagentTool", () => {
|
|||
it.live(
|
||||
`persists the ${continued ? "continued" : "new"} child link before admitting a foreground subagent prompt`,
|
||||
() =>
|
||||
Effect.acquireRelease(
|
||||
Effect.promise(() => tmpdir()),
|
||||
(dir) => Effect.promise(() => dir[Symbol.asyncDispose]()),
|
||||
).pipe(
|
||||
Effect.flatMap((dir) =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* Effect.acquireRelease(
|
||||
Effect.promise(() => tmpdir()),
|
||||
(dir) => Effect.promise(() => dir[Symbol.asyncDispose]()),
|
||||
)
|
||||
const sessions = yield* Session.Service
|
||||
const parent = yield* sessions.create({
|
||||
location: Location.Ref.make({ directory: AbsolutePath.make(dir.path) }),
|
||||
model: parentModel,
|
||||
})
|
||||
yield* withSubagent(parent.location)
|
||||
const locations = yield* LocationServiceMap.Service
|
||||
const registry = yield* Tool.Service.pipe(Effect.provide(locations.get(parent.location)))
|
||||
const bus = yield* Bus.Service
|
||||
const assistantMessageID = SessionMessage.ID.create()
|
||||
const child = continued
|
||||
? yield* sessions.create({ parentID: parent.id, title: "existing review" })
|
||||
: undefined
|
||||
const call = {
|
||||
type: "tool-call" as const,
|
||||
id: "call-durable-child-link",
|
||||
name: SubagentTool.name,
|
||||
input: {
|
||||
agent: "reviewer",
|
||||
description: "linked review",
|
||||
prompt: "review",
|
||||
...(child ? { sessionID: child.id } : {}),
|
||||
},
|
||||
}
|
||||
yield* bus.publish(SessionEvent.Step.Started, {
|
||||
sessionID: parent.id,
|
||||
assistantMessageID,
|
||||
agent: toolIdentity.agent,
|
||||
model: parentModel,
|
||||
started: 0,
|
||||
})
|
||||
yield* bus.publish(SessionEvent.Tool.Input.Started, {
|
||||
sessionID: parent.id,
|
||||
assistantMessageID,
|
||||
id: call.id,
|
||||
name: call.name,
|
||||
})
|
||||
yield* bus.publish(SessionEvent.Tool.Called, {
|
||||
sessionID: parent.id,
|
||||
assistantMessageID,
|
||||
id: call.id,
|
||||
input: call.input,
|
||||
executed: false,
|
||||
})
|
||||
const admitted = yield* Deferred.make<Session.ID>()
|
||||
yield* bus.project(SessionEvent.InboxEnqueued, (event) =>
|
||||
Effect.gen(function* () {
|
||||
const sessions = yield* Session.Service
|
||||
const parent = yield* sessions.create({
|
||||
location: Location.Ref.make({ directory: AbsolutePath.make(dir.path) }),
|
||||
model: parentModel,
|
||||
})
|
||||
yield* withSubagent(parent.location)
|
||||
const locations = yield* LocationServiceMap.Service
|
||||
const registry = yield* Tool.Service.pipe(Effect.provide(locations.get(parent.location)))
|
||||
const bus = yield* Bus.Service
|
||||
const assistantMessageID = SessionMessage.ID.create()
|
||||
const call = {
|
||||
type: "tool-call" as const,
|
||||
id: "call-durable-child-link",
|
||||
name: SubagentTool.name,
|
||||
input: { agent: "reviewer", description: "linked review", prompt: "review" },
|
||||
}
|
||||
yield* bus.publish(SessionEvent.Step.Started, {
|
||||
sessionID: parent.id,
|
||||
assistantMessageID,
|
||||
agent: toolIdentity.agent,
|
||||
model: parentModel,
|
||||
started: 0,
|
||||
})
|
||||
yield* bus.publish(SessionEvent.Tool.Input.Started, {
|
||||
sessionID: parent.id,
|
||||
assistantMessageID,
|
||||
id: call.id,
|
||||
name: call.name,
|
||||
})
|
||||
yield* bus.publish(SessionEvent.Tool.Called, {
|
||||
sessionID: parent.id,
|
||||
assistantMessageID,
|
||||
id: call.id,
|
||||
input: call.input,
|
||||
executed: false,
|
||||
})
|
||||
const admitted = yield* Deferred.make<Session.ID>()
|
||||
yield* bus.project(SessionEvent.InboxEnqueued, (event) =>
|
||||
Effect.gen(function* () {
|
||||
if (event.data.item.type !== "user" || event.data.sessionID === parent.id) return
|
||||
const assistant = (yield* sessions.context(parent.id).pipe(Effect.orDie)).find(
|
||||
(message) => message.id === assistantMessageID,
|
||||
)
|
||||
expect(assistant).toMatchObject({
|
||||
content: [
|
||||
{
|
||||
id: call.id,
|
||||
state: {
|
||||
status: "running",
|
||||
metadata: { sessionID: event.data.sessionID, status: "running" },
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
yield* Deferred.succeed(admitted, event.data.sessionID)
|
||||
}),
|
||||
if (event.data.item.type !== "user" || event.data.sessionID === parent.id) return
|
||||
const assistant = (yield* sessions.context(parent.id).pipe(Effect.orDie)).find(
|
||||
(message) => message.type === "assistant",
|
||||
)
|
||||
const child = continued
|
||||
? yield* sessions.create({ parentID: parent.id, title: "existing review" })
|
||||
: undefined
|
||||
const result = yield* executeTool(registry, {
|
||||
sessionID: parent.id,
|
||||
agent: toolIdentity.agent,
|
||||
messageID: assistantMessageID,
|
||||
call: { ...call, input: { ...call.input, ...(child ? { sessionID: child.id } : {}) } },
|
||||
expect(assistant?.content.find((part) => part.type === "tool")?.state).toEqual({
|
||||
status: "running",
|
||||
input: call.input,
|
||||
metadata: { sessionID: event.data.sessionID, status: "running" },
|
||||
})
|
||||
expect(result.metadata).toEqual({ sessionID: yield* Deferred.await(admitted), status: "completed" })
|
||||
if (child) expect(outputSessionID(result.metadata)).toBe(child.id)
|
||||
yield* Deferred.succeed(admitted, event.data.sessionID)
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
const result = yield* executeTool(registry, {
|
||||
sessionID: parent.id,
|
||||
agent: toolIdentity.agent,
|
||||
messageID: assistantMessageID,
|
||||
call,
|
||||
})
|
||||
expect(result.metadata).toEqual({ sessionID: yield* Deferred.await(admitted), status: "completed" })
|
||||
if (child) expect(outputSessionID(result.metadata)).toBe(child.id)
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue