fix(core): enforce V2 tool permissions (#31061)
This commit is contained in:
parent
747b8daafc
commit
4814ab3a3d
10 changed files with 180 additions and 10 deletions
|
|
@ -37,6 +37,26 @@ const contextual = (contexts: Tool.Context[]) =>
|
|||
})
|
||||
|
||||
describe("ApplicationTools", () => {
|
||||
it.effect("filters an application tool by its name without adding execution authorization", () =>
|
||||
Effect.gen(function* () {
|
||||
const applications = yield* ApplicationTools.Service
|
||||
const registry = yield* ToolRegistry.Service
|
||||
const contexts: Tool.Context[] = []
|
||||
yield* applications.attach({ application_context: contextual(contexts) })
|
||||
|
||||
expect(yield* registry.definitions([{ action: "application_context", resource: "*", effect: "deny" }])).toEqual(
|
||||
[],
|
||||
)
|
||||
expect(
|
||||
yield* registry.settle({
|
||||
sessionID,
|
||||
call: { type: "tool-call", id: "call-denied", name: "application_context", input: { query: "hello" } },
|
||||
}),
|
||||
).toMatchObject({ result: { type: "content" } })
|
||||
expect(contexts).toEqual([{ sessionID, id: "call-denied", name: "application_context" }])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("advertises and executes a scoped application tool with Session context", () =>
|
||||
Effect.gen(function* () {
|
||||
const applications = yield* ApplicationTools.Service
|
||||
|
|
@ -169,13 +189,18 @@ describe("ApplicationTools", () => {
|
|||
yield* transform((editor) =>
|
||||
editor.set("shared", {
|
||||
tool: location.definition,
|
||||
permission: { action: "question", resource: "*" },
|
||||
execute: ({ parameters, sessionID, call }) =>
|
||||
location.execute(parameters, { sessionID, id: call.id, name: call.name }),
|
||||
}),
|
||||
)
|
||||
yield* applications.attach({ shared: contextual(applicationContexts) })
|
||||
|
||||
expect((yield* registry.definitions()).map((definition) => definition.name)).toEqual(["shared"])
|
||||
expect(
|
||||
(yield* registry.definitions([{ action: "question", resource: "*", effect: "deny" }])).map(
|
||||
(definition) => definition.name,
|
||||
),
|
||||
).toEqual([])
|
||||
expect(
|
||||
yield* registry.settle({
|
||||
sessionID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue