Compare commits

..

1 Commits

Author SHA1 Message Date
Kit Langton 3f30203b72 test(core): stabilize shell integration timing (#40084) 2026-08-02 14:45:36 -04:00
3 changed files with 13 additions and 59 deletions
+9 -22
View File
@@ -191,31 +191,22 @@ export const layer = Layer.effect(
const messages = stepLimitReached ? [...history, Message.assistant(MAX_STEPS_PROMPT)] : history
const toolDefinitions = tools.definitions
const toolsByName = new Map(toolDefinitions.map((tool) => [tool.name, tool]))
// Object identity preserves registry provenance when a hook moves a definition to a new key.
const toolNamesByDefinition = new Map<object, string>()
// Hooks may reshape available definitions but cannot advertise tools omitted by permissions or the Step limit.
const hookTools = Object.fromEntries(
toolDefinitions.map((tool) => {
const definition = { description: tool.description, input: { ...tool.inputSchema } }
toolNamesByDefinition.set(definition, tool.name)
return [tool.name, definition]
}),
)
const contextEvent = yield* hooks.trigger("session", "context", {
sessionID: session.id,
agent: agent.id,
model: resolved.ref,
system,
messages,
tools: hookTools,
tools: Object.fromEntries(
toolDefinitions.map((tool) => [tool.name, { description: tool.description, input: { ...tool.inputSchema } }]),
),
})
const executableTools = new Map<string, string>()
const hookedTools = Object.entries(contextEvent.tools).flatMap(([name, tool]) => {
const registeredName = toolNamesByDefinition.get(tool)
const registered = registeredName ? toolsByName.get(registeredName) : undefined
if (!registered || !registeredName) return []
executableTools.set(name, registeredName)
return [{ ...registered, name, description: tool.description, inputSchema: tool.input }]
const registered = toolsByName.get(name)
return registered
? [{ ...registered, description: tool.description, inputSchema: tool.input }]
: []
})
const request = LLM.request({
model,
@@ -268,14 +259,10 @@ export const layer = Layer.effect(
const executeTool: Prepared["executeTool"] = (executeInput) => {
if (stepLimitReached)
return new Tool.Error({ message: "Tools are disabled after the maximum agent steps" })
const registeredName = executableTools.get(executeInput.call.name)
if (!registeredName && toolsByName.has(executeInput.call.name))
if (toolsByName.has(executeInput.call.name) && !Object.hasOwn(contextEvent.tools, executeInput.call.name))
return new Tool.Error({ message: `Tool is not available for this request: ${executeInput.call.name}` })
return tools
.execute({
...executeInput,
call: { ...executeInput.call, name: registeredName ?? executeInput.call.name },
})
.execute(executeInput)
.pipe(Effect.catchCauseFilter(declineDefect, (decline) => Effect.fail(decline)))
}
return {
-36
View File
@@ -887,42 +887,6 @@ describe("SessionRunnerLLM", () => {
}),
)
it.effect("advertises and executes a tool renamed by a session context hook", () =>
Effect.gen(function* () {
const session = yield* setup
const hooks = yield* PluginHooks.Service
yield* hooks.register("session", "context", (event) =>
Effect.sync(() => {
const tool = event.tools.echo
if (!tool) return
event.tools.renamed_echo = tool
delete event.tools.echo
}),
)
yield* admit(session, "Use the renamed tool")
yield* TestLLM.push(TestLLM.tool("call-renamed", "renamed_echo", { text: "renamed" }), [])
yield* session.resume(sessionID)
expect(requests[0]?.tools.map((tool) => tool.name)).toContain("renamed_echo")
expect(requests[0]?.tools.map((tool) => tool.name)).not.toContain("echo")
expect(executions).toEqual(["renamed"])
expect(yield* session.context(sessionID)).toMatchObject([
{ type: "user", text: "Use the renamed tool" },
{
type: "assistant",
content: [
{
type: "tool",
id: "call-renamed",
state: { status: "completed", content: [{ type: "text", text: "renamed" }] },
},
],
},
])
}),
)
it.effect("advertises and executes a location registered tool", () =>
Effect.gen(function* () {
const session = yield* setup
+4 -1
View File
@@ -301,6 +301,7 @@ describe("ShellTool", () => {
},
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]().then(() => undefined)),
),
{ timeout: 15_000 },
)
it.live("rejects a workdir that stops being a directory during approval", () =>
@@ -472,6 +473,7 @@ describe("ShellTool", () => {
},
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]().then(() => undefined)),
),
{ timeout: 15_000 },
)
it.live(
@@ -538,7 +540,7 @@ describe("ShellTool", () => {
(tmp) => {
reset()
return withSession(tmp.path, (registry) =>
executeTool(registry, call({ command: timeoutOutputCommand, timeout: isWindows ? 500 : 50 })),
executeTool(registry, call({ command: timeoutOutputCommand, timeout: isWindows ? 3_000 : 50 })),
).pipe(
Effect.andThen((settled) =>
Effect.sync(() => {
@@ -557,6 +559,7 @@ describe("ShellTool", () => {
},
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]().then(() => undefined)),
),
{ timeout: 15_000 },
)
it.live("returns the shell id for a background command", () =>