2026-02-18 18:02:42 +09:00
|
|
|
declare const require: (name: string) => any
|
|
|
|
|
const { describe, expect, test } = require("bun:test")
|
|
|
|
|
|
|
|
|
|
import { injectContinuation } from "./continuation-injection"
|
2026-02-18 21:54:20 +02:00
|
|
|
import { OMO_INTERNAL_INITIATOR_MARKER } from "../../shared/internal-initiator-marker"
|
2026-02-18 18:02:42 +09:00
|
|
|
|
|
|
|
|
describe("injectContinuation", () => {
|
2026-04-06 11:44:11 +09:00
|
|
|
test("normalizes built-in display names to config keys before promptAsync", async () => {
|
|
|
|
|
// given
|
|
|
|
|
let capturedAgent: string | undefined
|
|
|
|
|
const ctx = {
|
|
|
|
|
directory: "/tmp/test",
|
|
|
|
|
client: {
|
|
|
|
|
session: {
|
|
|
|
|
todo: async () => ({ data: [{ id: "1", content: "todo", status: "pending", priority: "high" }] }),
|
|
|
|
|
promptAsync: async (input: {
|
|
|
|
|
body: {
|
|
|
|
|
agent?: string
|
|
|
|
|
}
|
|
|
|
|
}) => {
|
|
|
|
|
capturedAgent = input.body.agent
|
|
|
|
|
return {}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
const sessionStateStore = {
|
|
|
|
|
getExistingState: () => ({ inFlight: false, lastInjectedAt: 0, consecutiveFailures: 0 }),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
await injectContinuation({
|
|
|
|
|
ctx: ctx as never,
|
|
|
|
|
sessionID: "ses_display_name_agent",
|
|
|
|
|
resolvedInfo: {
|
|
|
|
|
agent: "Sisyphus (Ultraworker)",
|
|
|
|
|
model: { providerID: "anthropic", modelID: "claude-sonnet-4-20250514" },
|
|
|
|
|
},
|
|
|
|
|
sessionStateStore: sessionStateStore as never,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
expect(capturedAgent).toBe("sisyphus")
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-18 18:02:42 +09:00
|
|
|
test("inherits tools from resolved message info when reinjecting", async () => {
|
|
|
|
|
// given
|
|
|
|
|
let capturedTools: Record<string, boolean> | undefined
|
2026-02-18 21:54:20 +02:00
|
|
|
let capturedText: string | undefined
|
2026-02-18 18:02:42 +09:00
|
|
|
const ctx = {
|
|
|
|
|
directory: "/tmp/test",
|
|
|
|
|
client: {
|
|
|
|
|
session: {
|
|
|
|
|
todo: async () => ({ data: [{ id: "1", content: "todo", status: "pending", priority: "high" }] }),
|
2026-02-18 21:54:20 +02:00
|
|
|
promptAsync: async (input: {
|
|
|
|
|
body: {
|
|
|
|
|
tools?: Record<string, boolean>
|
|
|
|
|
parts?: Array<{ type: string; text: string }>
|
|
|
|
|
}
|
|
|
|
|
}) => {
|
2026-02-18 18:02:42 +09:00
|
|
|
capturedTools = input.body.tools
|
2026-02-18 21:54:20 +02:00
|
|
|
capturedText = input.body.parts?.[0]?.text
|
2026-02-18 18:02:42 +09:00
|
|
|
return {}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
const sessionStateStore = {
|
|
|
|
|
getExistingState: () => ({ inFlight: false, lastInjectedAt: 0, consecutiveFailures: 0 }),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
await injectContinuation({
|
|
|
|
|
ctx: ctx as never,
|
|
|
|
|
sessionID: "ses_continuation_tools",
|
|
|
|
|
resolvedInfo: {
|
|
|
|
|
agent: "Hephaestus",
|
|
|
|
|
model: { providerID: "openai", modelID: "gpt-5.3-codex" },
|
|
|
|
|
tools: { question: "deny", bash: "allow" },
|
|
|
|
|
},
|
|
|
|
|
sessionStateStore: sessionStateStore as never,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
expect(capturedTools).toEqual({ question: false, bash: true })
|
2026-02-18 21:54:20 +02:00
|
|
|
expect(capturedText).toContain(OMO_INTERNAL_INITIATOR_MARKER)
|
2026-02-18 18:02:42 +09:00
|
|
|
})
|
2026-03-16 10:24:57 +09:00
|
|
|
|
|
|
|
|
test("skips injection when agent is plan (prevents Plan Mode infinite loop)", async () => {
|
|
|
|
|
// given
|
|
|
|
|
let injected = false
|
|
|
|
|
const ctx = {
|
|
|
|
|
directory: "/tmp/test",
|
|
|
|
|
client: {
|
|
|
|
|
session: {
|
|
|
|
|
todo: async () => ({ data: [{ id: "1", content: "todo", status: "pending", priority: "high" }] }),
|
|
|
|
|
promptAsync: async () => {
|
|
|
|
|
injected = true
|
|
|
|
|
return {}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
const sessionStateStore = {
|
|
|
|
|
getExistingState: () => ({ inFlight: false, lastInjectedAt: 0, consecutiveFailures: 0 }),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
await injectContinuation({
|
|
|
|
|
ctx: ctx as never,
|
|
|
|
|
sessionID: "ses_plan_skip",
|
|
|
|
|
resolvedInfo: {
|
|
|
|
|
agent: "plan",
|
|
|
|
|
model: { providerID: "anthropic", modelID: "claude-sonnet-4-20250514" },
|
|
|
|
|
},
|
|
|
|
|
sessionStateStore: sessionStateStore as never,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
expect(injected).toBe(false)
|
|
|
|
|
})
|
2026-02-18 18:02:42 +09:00
|
|
|
})
|