d5fbada13d
Move test coercion out of a hidden global and require each test to import the helper so review tools and runtime scripts can see the unsafe boundary. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
const { describe, test, expect } = require("bun:test")
|
|
|
|
import { executeBackgroundTask } from "./executor"
|
|
import type { DelegateTaskArgs, ToolContextWithMetadata } from "./types"
|
|
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
|
|
|
describe("task tool metadata awaiting", () => {
|
|
test("executeBackgroundTask awaits ctx.metadata before returning", async () => {
|
|
// given
|
|
let metadataResolved = false
|
|
const abort = new AbortController()
|
|
|
|
const ctx: ToolContextWithMetadata = {
|
|
sessionID: "ses_parent",
|
|
messageID: "msg_parent",
|
|
agent: "sisyphus",
|
|
abort: abort.signal,
|
|
metadata: async () => {
|
|
await new Promise<void>((resolve) => setTimeout(resolve, 50))
|
|
metadataResolved = true
|
|
},
|
|
}
|
|
|
|
const args: DelegateTaskArgs = {
|
|
load_skills: [],
|
|
description: "Test task",
|
|
prompt: "Do something",
|
|
run_in_background: true,
|
|
subagent_type: "explore",
|
|
}
|
|
|
|
const executorCtx = unsafeTestValue({
|
|
manager: {
|
|
launch: async () => ({
|
|
id: "task_1",
|
|
description: "Test task",
|
|
prompt: "Do something",
|
|
agent: "explore",
|
|
status: "pending",
|
|
sessionId: "ses_child",
|
|
}),
|
|
getTask: () => undefined,
|
|
},
|
|
})
|
|
|
|
const parentContext = {
|
|
sessionID: "ses_parent",
|
|
messageID: "msg_parent",
|
|
}
|
|
|
|
// when
|
|
const result = await executeBackgroundTask(
|
|
args,
|
|
ctx,
|
|
executorCtx,
|
|
parentContext,
|
|
"explore",
|
|
undefined,
|
|
undefined,
|
|
)
|
|
|
|
// then
|
|
expect(result).toContain("Background task launched")
|
|
expect(metadataResolved).toBe(true)
|
|
})
|
|
})
|