@exulu/backend 5.14.0 → 5.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-QU67ANL5.js → chunk-2FDGX6WH.js} +2152 -1393
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-UT7TOLLD.js → convert-exulu-tools-to-ai-sdk-tools-UYF2OK7F.js} +1 -1
- package/dist/index.cjs +1990 -1146
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +41 -3
- package/ee/invoke-skills/artifact-filter.test.ts +42 -1
- package/ee/invoke-skills/artifact-filter.ts +37 -0
- package/ee/invoke-skills/create-sandbox.env.test.ts +7 -1
- package/ee/invoke-skills/create-sandbox.readonly-skills.sandbox.test.ts +221 -0
- package/ee/invoke-skills/create-sandbox.readonly-skills.test.ts +290 -0
- package/ee/invoke-skills/create-sandbox.run-command.test.ts +135 -0
- package/ee/invoke-skills/create-sandbox.skill-actions.test.ts +176 -0
- package/ee/invoke-skills/create-sandbox.ts +268 -88
- package/ee/invoke-skills/safe-fs.test.ts +59 -1
- package/ee/invoke-skills/safe-fs.ts +61 -2
- package/ee/invoke-skills/skill-actions/load.test.ts +88 -0
- package/ee/invoke-skills/skill-actions/load.ts +107 -0
- package/ee/invoke-skills/skill-actions/schema.test.ts +72 -0
- package/ee/invoke-skills/skill-actions/schema.ts +97 -0
- package/ee/invoke-skills/skill-actions/tool.test.ts +464 -0
- package/ee/invoke-skills/skill-actions/tool.ts +415 -0
- package/package.json +2 -1
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { findContextItems, readContextItem } from "@SRC/templates/tools/context-read-tools";
|
|
5
|
+
import { deriveContextBudget } from "@SRC/exulu/context-budget";
|
|
6
|
+
import { guardToolOutput } from "@SRC/exulu/tool-output-offload";
|
|
7
|
+
import { truncateToolOutput } from "@SRC/utils/truncate-tool-output";
|
|
8
|
+
import { appendArtifactsBlock } from "../artifact-filter";
|
|
9
|
+
import { createRunSkillActionTool, deriveConnectedContextIds, RUN_SKILL_ACTION_TOOL_ID } from "./tool";
|
|
10
|
+
import type { LoadedSkillActions } from "./load";
|
|
11
|
+
import type { SkillAction } from "./schema";
|
|
12
|
+
|
|
13
|
+
jest.mock("@SRC/uppy", () => ({ uploadFile: jest.fn(async () => "key") }));
|
|
14
|
+
jest.mock("@SRC/templates/tools/context-read-tools", () => ({
|
|
15
|
+
readContextItem: jest.fn(),
|
|
16
|
+
findContextItems: jest.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const readMock = readContextItem as jest.Mock;
|
|
20
|
+
const findMock = findContextItems as jest.Mock;
|
|
21
|
+
|
|
22
|
+
// The read function's own not-found sentence (missing and unreadable are the same).
|
|
23
|
+
const NOT_FOUND = 'Item not found in "Pitches", or you do not have access to it.';
|
|
24
|
+
const ROWS = [{ id: "r1" }, { id: "r2" }, { id: "r3" }];
|
|
25
|
+
|
|
26
|
+
const action = (a: Partial<SkillAction>): SkillAction => ({
|
|
27
|
+
description: "d",
|
|
28
|
+
run: "true",
|
|
29
|
+
timeoutSeconds: 60,
|
|
30
|
+
inputs: {},
|
|
31
|
+
...a,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
let root: string;
|
|
35
|
+
let sessionDir: string;
|
|
36
|
+
let seen: {
|
|
37
|
+
command?: string;
|
|
38
|
+
extraEnv?: Record<string, string>;
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
files: Record<string, unknown>;
|
|
41
|
+
mode?: number;
|
|
42
|
+
runDir?: string;
|
|
43
|
+
};
|
|
44
|
+
let runResult: () => Promise<any>;
|
|
45
|
+
let tool: ReturnType<typeof createRunSkillActionTool>;
|
|
46
|
+
let truncate: jest.Mock;
|
|
47
|
+
const CONTEXT_WINDOW = 128_000;
|
|
48
|
+
// The guard's cap in characters, exactly as the registration passes it.
|
|
49
|
+
const LIMIT = deriveContextBudget(CONTEXT_WINDOW).toolOutputCapTokens * 4;
|
|
50
|
+
|
|
51
|
+
const loadedFor = (dir: string): LoadedSkillActions => ({
|
|
52
|
+
bySkill: {
|
|
53
|
+
a: {
|
|
54
|
+
skillDir: join(dir, "skills", "a"),
|
|
55
|
+
actions: {
|
|
56
|
+
export: action({
|
|
57
|
+
description: "Writes the workbook.",
|
|
58
|
+
run: 'python3 "$EXULU_SKILL_DIR/scripts/export.py"',
|
|
59
|
+
timeoutSeconds: 30,
|
|
60
|
+
inputs: { pitch: { type: "item", context: "pitches", fields: ["felder"] } },
|
|
61
|
+
}),
|
|
62
|
+
note: action({ run: "python3 note.py", inputs: { note: { type: "text", required: true } } }),
|
|
63
|
+
opt: action({
|
|
64
|
+
inputs: {
|
|
65
|
+
title: { type: "text", required: true },
|
|
66
|
+
extra: { type: "text", required: false },
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
list: action({
|
|
70
|
+
inputs: { rows: { type: "items", context: "rows", where: { status: { eq: "open" } } } },
|
|
71
|
+
}),
|
|
72
|
+
two: action({
|
|
73
|
+
inputs: {
|
|
74
|
+
pitch: { type: "item", context: "pitches" },
|
|
75
|
+
rows: { type: "items", context: "rows" },
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
other_ctx: action({ inputs: { it: { type: "item", context: "secret" } } }),
|
|
79
|
+
ghost_ctx: action({ inputs: { it: { type: "item", context: "ghost" } } }),
|
|
80
|
+
bad_args: action({ inputs: { args: { type: "item", context: "pitches" } } }),
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
problems: [{ skill: "b", error: "version: Invalid literal value" }],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const contexts = [
|
|
88
|
+
{ id: "pitches", name: "Pitches" },
|
|
89
|
+
{ id: "rows", name: "Rows" },
|
|
90
|
+
{ id: "secret", name: "Secret" },
|
|
91
|
+
] as never;
|
|
92
|
+
|
|
93
|
+
const run = (input: Record<string, unknown>) =>
|
|
94
|
+
(tool as any).tool.execute({ ...input, user: { id: 1 }, req: { r: 1 } }, {}) as Promise<{ result: string }>;
|
|
95
|
+
|
|
96
|
+
beforeEach(async () => {
|
|
97
|
+
root = await fs.mkdtemp(join(os.tmpdir(), "skill-action-tool-"));
|
|
98
|
+
sessionDir = join(root, "session");
|
|
99
|
+
await fs.mkdir(join(sessionDir, "skills", "a"), { recursive: true });
|
|
100
|
+
seen = { files: {} };
|
|
101
|
+
runResult = async () => ({ stdout: "out", stderr: "err", exitCode: 0, timedOut: false, artifacts: [] });
|
|
102
|
+
readMock.mockReset().mockImplementation(async (_ctx: unknown, args: { id?: string; external_id?: string }) => {
|
|
103
|
+
if (args.id === "forbidden") return { ok: false, message: NOT_FOUND };
|
|
104
|
+
return { ok: true, item: { id: args.id ?? `ext:${args.external_id}`, felder: {} } };
|
|
105
|
+
});
|
|
106
|
+
findMock.mockReset().mockImplementation(async (_ctx: unknown, args: { limit: number }) => ({
|
|
107
|
+
ok: true,
|
|
108
|
+
items: ROWS.slice(0, args.limit),
|
|
109
|
+
limit: args.limit,
|
|
110
|
+
truncated: ROWS.length > args.limit,
|
|
111
|
+
}));
|
|
112
|
+
// The registration's real truncation, wrapped so calls can be checked.
|
|
113
|
+
truncate = jest.fn((text: string, kind: string, charLimit: number) =>
|
|
114
|
+
truncateToolOutput(text, CONTEXT_WINDOW, kind, kind === "stdout" ? 0.1 : 0.4, charLimit),
|
|
115
|
+
);
|
|
116
|
+
tool = createRunSkillActionTool({
|
|
117
|
+
handle: {
|
|
118
|
+
sessionDir,
|
|
119
|
+
runCommand: async (command, options) => {
|
|
120
|
+
seen.command = command;
|
|
121
|
+
seen.extraEnv = options?.extraEnv;
|
|
122
|
+
seen.timeoutMs = options?.timeoutMs;
|
|
123
|
+
const dir = options!.extraEnv!.EXULU_INPUTS_DIR!;
|
|
124
|
+
seen.runDir = dir;
|
|
125
|
+
seen.mode = (await fs.stat(dir)).mode & 0o777;
|
|
126
|
+
for (const name of await fs.readdir(dir)) {
|
|
127
|
+
seen.files[name] = JSON.parse(await fs.readFile(join(dir, name), "utf8"));
|
|
128
|
+
}
|
|
129
|
+
return runResult();
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
loaded: loadedFor(sessionDir),
|
|
133
|
+
contexts,
|
|
134
|
+
connectedContextIds: new Set(["pitches", "rows"]),
|
|
135
|
+
truncate,
|
|
136
|
+
resultCharLimit: LIMIT,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
afterEach(async () => {
|
|
141
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const exists = (p: string) => fs.lstat(p).then(() => true, () => false);
|
|
145
|
+
|
|
146
|
+
test("item input lands as a file, ids never in the command", async () => {
|
|
147
|
+
await run({ skill: "a", action: "export", inputs: { pitch: "id-1" } });
|
|
148
|
+
expect(seen.command).toBe('python3 "$EXULU_SKILL_DIR/scripts/export.py"');
|
|
149
|
+
expect(seen.extraEnv!.EXULU_SKILL_DIR).toBe(join(sessionDir, "skills", "a"));
|
|
150
|
+
expect(seen.files["pitch.json"]).toEqual({ id: "id-1", felder: {} });
|
|
151
|
+
expect(seen.extraEnv!.EXULU_INPUTS_DIR.startsWith(join(sessionDir, ".exulu-inputs") + "/")).toBe(true);
|
|
152
|
+
expect(Object.keys(seen.files)).toEqual(["pitch.json"]); // no args.json without text inputs
|
|
153
|
+
expect(seen.timeoutMs).toBe(30_000);
|
|
154
|
+
expect(seen.mode).toBe(0o700);
|
|
155
|
+
expect(readMock).toHaveBeenCalledWith(
|
|
156
|
+
expect.objectContaining({ id: "pitches" }),
|
|
157
|
+
{ id: "id-1", fields: ["felder"] },
|
|
158
|
+
{ user: { id: 1 }, req: { r: 1 } },
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("item input by external_id", async () => {
|
|
163
|
+
await run({ skill: "a", action: "export", inputs: { pitch: { external_id: "X-9" } } });
|
|
164
|
+
expect(readMock.mock.calls[0][1]).toEqual({ external_id: "X-9", fields: ["felder"] });
|
|
165
|
+
expect(seen.files["pitch.json"]).toEqual({ id: "ext:X-9", felder: {} });
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("hostile text is data only", async () => {
|
|
169
|
+
const evil = '"; rm -rf . #\n$(id) `id`';
|
|
170
|
+
await run({ skill: "a", action: "note", inputs: { note: evil } });
|
|
171
|
+
expect(seen.files["args.json"]).toEqual({ note: evil });
|
|
172
|
+
expect(seen.command).toBe("python3 note.py");
|
|
173
|
+
expect(seen.command).not.toContain("rm -rf");
|
|
174
|
+
expect(JSON.stringify(seen.extraEnv)).not.toContain("rm -rf");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("an omitted optional text input is absent from args.json", async () => {
|
|
178
|
+
await run({ skill: "a", action: "opt", inputs: { title: "T" } });
|
|
179
|
+
expect(seen.files["args.json"]).toEqual({ title: "T" });
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("items envelope and truncation warning", async () => {
|
|
183
|
+
const r = await run({ skill: "a", action: "list", inputs: { rows: { limit: 2 } } }); // 3 rows match
|
|
184
|
+
expect(seen.files["rows.json"]).toEqual({ items: [expect.anything(), expect.anything()], limit: 2, truncated: true });
|
|
185
|
+
expect(r.result).toContain('warning: input "rows" was cut at 2 items');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("items defaults to 50 with a ceiling of 500 and no warning when complete", async () => {
|
|
189
|
+
const r = await run({ skill: "a", action: "list" });
|
|
190
|
+
expect(findMock.mock.calls[0][1]).toMatchObject({ limit: 50, maxLimit: 500 });
|
|
191
|
+
expect(seen.files["rows.json"]).toEqual({ items: ROWS, limit: 50, truncated: false });
|
|
192
|
+
expect(r.result).not.toContain("warning:");
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("yaml where is AND-ed with the caller's where", async () => {
|
|
196
|
+
await run({ skill: "a", action: "list", inputs: { rows: { where: { kunde: { eq: "ACME" } } } } });
|
|
197
|
+
expect(findMock).toHaveBeenCalledTimes(1);
|
|
198
|
+
expect(findMock.mock.calls[0][1].where).toEqual({ status: { eq: "open" }, kunde: { eq: "ACME" } });
|
|
199
|
+
expect(findMock.mock.calls[0][2]).toEqual({ user: { id: 1 }, req: { r: 1 } });
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("a small result carries exit code, stdout and stderr unchanged", async () => {
|
|
203
|
+
runResult = async () => ({ stdout: "hello", stderr: "oops", exitCode: 3, timedOut: false, artifacts: [] });
|
|
204
|
+
const r = await run({ skill: "a", action: "export", inputs: { pitch: "id-1" } });
|
|
205
|
+
expect(r.result).toBe("exit_code: 3\nstdout:\nhello\nstderr:\noops");
|
|
206
|
+
expect(truncate).not.toHaveBeenCalled();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const ARTIFACTS = Array.from({ length: 50 }, (_, i) => ({
|
|
210
|
+
path: `/s/out-${i}.xlsx`,
|
|
211
|
+
relativePath: `out-${i}.xlsx`,
|
|
212
|
+
key: `k${i}`,
|
|
213
|
+
url: `https://signed.example/out-${i}.xlsx?X-Amz-Signature=${"f".repeat(64)}`,
|
|
214
|
+
}));
|
|
215
|
+
const BLOCK_LINES = ARTIFACTS.map((a) => ` ${a.relativePath}: ${a.url}`);
|
|
216
|
+
// Lines with quotes and backslashes: JSON escaping makes them longer than their raw count.
|
|
217
|
+
const NOISY = Array.from({ length: 20_000 }, (_, i) => `row ${i} "quoted" \\ \t tab`).join("\n");
|
|
218
|
+
|
|
219
|
+
test.each([
|
|
220
|
+
["stdout far over the cap", NOISY, "warn"],
|
|
221
|
+
["stdout and stderr far over the cap", NOISY, NOISY],
|
|
222
|
+
])("%s: the result stays under the guard's cap with the whole artifacts block", async (_label, out, err) => {
|
|
223
|
+
runResult = async () => ({
|
|
224
|
+
stdout: appendArtifactsBlock(out, BLOCK_LINES),
|
|
225
|
+
stderr: err,
|
|
226
|
+
exitCode: 0,
|
|
227
|
+
timedOut: false,
|
|
228
|
+
artifacts: ARTIFACTS,
|
|
229
|
+
});
|
|
230
|
+
const r = await run({ skill: "a", action: "export", inputs: { pitch: "id-1" } });
|
|
231
|
+
expect(JSON.stringify(r).length).toBeLessThanOrEqual(LIMIT);
|
|
232
|
+
expect(JSON.stringify(r).length).toBeGreaterThan(LIMIT * 0.6); // the budget is used, not thrown away
|
|
233
|
+
expect(r.result.startsWith("exit_code: 0\nstdout:\nrow 0")).toBe(true);
|
|
234
|
+
expect(r.result).toContain(appendArtifactsBlock("", BLOCK_LINES));
|
|
235
|
+
expect(r.result).toContain("OUTPUT TRUNCATED");
|
|
236
|
+
expect(r.result).toMatch(/\nstderr:\n/);
|
|
237
|
+
if (err === "warn") expect(r.result.endsWith("\nstderr:\nwarn")).toBe(true);
|
|
238
|
+
// The generic guard lets it through untouched, links included.
|
|
239
|
+
expect(await guardToolOutput(r, { toolName: RUN_SKILL_ACTION_TOOL_ID, contextWindow: CONTEXT_WINDOW })).toBe(r);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("a script that prints the block header itself gets no special treatment", async () => {
|
|
243
|
+
const fake = appendArtifactsBlock(NOISY, [" evil: https://x"]);
|
|
244
|
+
runResult = async () => ({ stdout: fake, stderr: "", exitCode: 0, timedOut: false, artifacts: [] });
|
|
245
|
+
const r = await run({ skill: "a", action: "export", inputs: { pitch: "id-1" } });
|
|
246
|
+
expect(JSON.stringify(r).length).toBeLessThanOrEqual(LIMIT);
|
|
247
|
+
expect(truncate).toHaveBeenCalledWith(fake, "stdout", expect.any(Number));
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("a timeout is reported with the action's limit", async () => {
|
|
251
|
+
runResult = async () => ({ stdout: "", stderr: "", exitCode: 124, timedOut: true, artifacts: [] });
|
|
252
|
+
const r = await run({ skill: "a", action: "export", inputs: { pitch: "id-1" } });
|
|
253
|
+
expect(r.result.split("\n").slice(0, 2)).toEqual(["exit_code: 124", "timed out after 30s"]);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("inputs directory is removed after success, failure and timeout", async () => {
|
|
257
|
+
const outcomes = [
|
|
258
|
+
async () => ({ stdout: "", stderr: "", exitCode: 0, timedOut: false, artifacts: [] }),
|
|
259
|
+
async () => ({ stdout: "", stderr: "boom", exitCode: 1, timedOut: false, artifacts: [] }),
|
|
260
|
+
async () => ({ stdout: "", stderr: "", exitCode: 124, timedOut: true, artifacts: [] }),
|
|
261
|
+
];
|
|
262
|
+
for (const outcome of outcomes) {
|
|
263
|
+
runResult = outcome;
|
|
264
|
+
seen.runDir = undefined;
|
|
265
|
+
await run({ skill: "a", action: "export", inputs: { pitch: "id-1" } });
|
|
266
|
+
expect(seen.runDir).toBeDefined();
|
|
267
|
+
expect(await exists(seen.runDir!)).toBe(false);
|
|
268
|
+
}
|
|
269
|
+
expect(await fs.readdir(join(sessionDir, ".exulu-inputs"))).toEqual([]);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test("inputs directory is removed when the runner throws, and the error propagates", async () => {
|
|
273
|
+
runResult = async () => {
|
|
274
|
+
throw new Error("sandbox gone");
|
|
275
|
+
};
|
|
276
|
+
await expect(run({ skill: "a", action: "export", inputs: { pitch: "id-1" } })).rejects.toThrow("sandbox gone");
|
|
277
|
+
expect(await exists(seen.runDir!)).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("a link planted at .exulu-inputs does not redirect the input files", async () => {
|
|
281
|
+
const outside = join(root, "outside");
|
|
282
|
+
await fs.mkdir(outside);
|
|
283
|
+
await fs.symlink(outside, join(sessionDir, ".exulu-inputs"));
|
|
284
|
+
await run({ skill: "a", action: "export", inputs: { pitch: "id-1" } });
|
|
285
|
+
expect(seen.files["pitch.json"]).toEqual({ id: "id-1", felder: {} });
|
|
286
|
+
expect(await fs.readdir(outside)).toEqual([]);
|
|
287
|
+
expect((await fs.lstat(join(sessionDir, ".exulu-inputs"))).isDirectory()).toBe(true);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test.each([
|
|
291
|
+
["unknown skill", { skill: "zzz", action: "export" }, "Available:"],
|
|
292
|
+
["prototype skill name", { skill: "__proto__", action: "export" }, "Available:"],
|
|
293
|
+
["unknown action", { skill: "a", action: "zzz" }, "Available:"],
|
|
294
|
+
["prototype action name", { skill: "a", action: "constructor" }, "Available:"],
|
|
295
|
+
["missing input", { skill: "a", action: "export", inputs: {} }, 'input "pitch" is required'],
|
|
296
|
+
["surplus input", { skill: "a", action: "export", inputs: { pitch: "1", x: "y" } }, 'unknown input "x"'],
|
|
297
|
+
["item of wrong shape", { skill: "a", action: "export", inputs: { pitch: { id: "1" } } }, 'input "pitch" must be'],
|
|
298
|
+
["empty item id", { skill: "a", action: "export", inputs: { pitch: "" } }, 'input "pitch" must be'],
|
|
299
|
+
["items of wrong shape", { skill: "a", action: "list", inputs: { rows: "all" } }, 'input "rows" must be'],
|
|
300
|
+
["items with unknown key", { skill: "a", action: "list", inputs: { rows: { order: "x" } } }, 'unknown key "order"'],
|
|
301
|
+
["items with bad limit", { skill: "a", action: "list", inputs: { rows: { limit: 0 } } }, '"limit" must be'],
|
|
302
|
+
["where clash with the yaml", { skill: "a", action: "list", inputs: { rows: { where: { status: { eq: "x" } } } } }, '"status"'],
|
|
303
|
+
["context not connected", { skill: "a", action: "other_ctx", inputs: { it: "1" } }, "not connected to this agent"],
|
|
304
|
+
["context not resolvable", { skill: "a", action: "ghost_ctx", inputs: { it: "1" } }, "not connected to this agent"],
|
|
305
|
+
["unreadable item", { skill: "a", action: "export", inputs: { pitch: "forbidden" } }, NOT_FOUND],
|
|
306
|
+
["text not a string", { skill: "a", action: "note", inputs: { note: 5 } }, 'input "note" must be a string'],
|
|
307
|
+
["text too long", { skill: "a", action: "note", inputs: { note: "x".repeat(10001) } }, "10000"],
|
|
308
|
+
["missing required text", { skill: "a", action: "note", inputs: {} }, 'input "note" is required'],
|
|
309
|
+
["args collision", { skill: "a", action: "bad_args", inputs: { args: "1" } }, "args.json"],
|
|
310
|
+
])("refuses without running: %s", async (_n, input, part) => {
|
|
311
|
+
const r = await run(input as any);
|
|
312
|
+
expect(r.result).toContain(part);
|
|
313
|
+
expect(seen.command).toBeUndefined();
|
|
314
|
+
expect(await exists(join(sessionDir, ".exulu-inputs"))).toBe(false);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test("refusal names the context id", async () => {
|
|
318
|
+
const r = await run({ skill: "a", action: "other_ctx", inputs: { it: "1" } });
|
|
319
|
+
expect(r.result).toContain('"secret"');
|
|
320
|
+
expect(readMock).not.toHaveBeenCalled();
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("a later failing input stops the run after an earlier one was read", async () => {
|
|
324
|
+
findMock.mockResolvedValueOnce({ ok: false, message: "bad filter" });
|
|
325
|
+
const r = await run({ skill: "a", action: "two", inputs: { pitch: "id-1" } });
|
|
326
|
+
expect(r.result).toContain('input "rows": bad filter');
|
|
327
|
+
expect(seen.command).toBeUndefined();
|
|
328
|
+
expect(await exists(join(sessionDir, ".exulu-inputs"))).toBe(false);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("the tool description lists actions and problems", () => {
|
|
332
|
+
expect(tool.id).toBe(RUN_SKILL_ACTION_TOOL_ID);
|
|
333
|
+
expect(tool.needsApproval).toBe(false);
|
|
334
|
+
expect(tool.description).toContain("a / export —");
|
|
335
|
+
expect(tool.description).toContain('skill "b": actions.yaml ignored — version: Invalid literal value');
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
describe("deriveConnectedContextIds", () => {
|
|
339
|
+
const ALL = ["docs", "rows", "pitches", "mem"];
|
|
340
|
+
const kb = (row: Record<string, unknown>) => ({
|
|
341
|
+
config: { id: "agentic_context_search", type: "context", config: [{ name: "knowledge_bases", ...row }] } as never,
|
|
342
|
+
});
|
|
343
|
+
const sorted = (set: Set<string>) => [...set].sort();
|
|
344
|
+
|
|
345
|
+
test.each<[string, Parameters<typeof deriveConnectedContextIds>[0], string[]]>([
|
|
346
|
+
["editor only", { contextIds: ALL, editorContextIds: ["pitches"] }, ["pitches"]],
|
|
347
|
+
[
|
|
348
|
+
"agentic search with no config entry → all but memory",
|
|
349
|
+
{ contextIds: ALL, memoryContextId: "mem", editorContextIds: [], agenticSearch: {} },
|
|
350
|
+
["docs", "pitches", "rows"],
|
|
351
|
+
],
|
|
352
|
+
[
|
|
353
|
+
"agentic search with default \"{}\" → all but memory",
|
|
354
|
+
{ contextIds: ALL, memoryContextId: "mem", editorContextIds: [], agenticSearch: kb({ type: "json", variable: "{}" }) },
|
|
355
|
+
["docs", "pitches", "rows"],
|
|
356
|
+
],
|
|
357
|
+
[
|
|
358
|
+
"agentic search with an empty hydrated value → all but memory",
|
|
359
|
+
{ contextIds: ALL, memoryContextId: "mem", editorContextIds: [], agenticSearch: kb({ type: "json", value: "" }) },
|
|
360
|
+
["docs", "pitches", "rows"],
|
|
361
|
+
],
|
|
362
|
+
[
|
|
363
|
+
"one context disabled (object variable)",
|
|
364
|
+
{
|
|
365
|
+
contextIds: ALL,
|
|
366
|
+
memoryContextId: "mem",
|
|
367
|
+
editorContextIds: [],
|
|
368
|
+
agenticSearch: kb({ type: "json", variable: { docs: { enabled: false }, rows: { kind: "records" } } }),
|
|
369
|
+
},
|
|
370
|
+
["pitches", "rows"],
|
|
371
|
+
],
|
|
372
|
+
[
|
|
373
|
+
"one context disabled (JSON string variable)",
|
|
374
|
+
{
|
|
375
|
+
contextIds: ALL,
|
|
376
|
+
memoryContextId: "mem",
|
|
377
|
+
editorContextIds: [],
|
|
378
|
+
agenticSearch: kb({ type: "json", variable: JSON.stringify({ rows: { enabled: false } }) }),
|
|
379
|
+
},
|
|
380
|
+
["docs", "pitches"],
|
|
381
|
+
],
|
|
382
|
+
[
|
|
383
|
+
"all disabled → none from search (no fall back to all)",
|
|
384
|
+
{
|
|
385
|
+
contextIds: ["docs", "rows"],
|
|
386
|
+
editorContextIds: [],
|
|
387
|
+
agenticSearch: kb({ type: "json", variable: { docs: { enabled: false }, rows: { enabled: false } } }),
|
|
388
|
+
},
|
|
389
|
+
[],
|
|
390
|
+
],
|
|
391
|
+
[
|
|
392
|
+
"unparsable config → none from search, editor still applies",
|
|
393
|
+
{ contextIds: ALL, editorContextIds: ["pitches"], agenticSearch: kb({ type: "json", variable: "{not json" }) },
|
|
394
|
+
["pitches"],
|
|
395
|
+
],
|
|
396
|
+
[
|
|
397
|
+
"config that is not an object → none from search",
|
|
398
|
+
{ contextIds: ALL, editorContextIds: [], agenticSearch: kb({ type: "json", variable: "[1,2]" }) },
|
|
399
|
+
[],
|
|
400
|
+
],
|
|
401
|
+
[
|
|
402
|
+
"profile with a non-boolean enabled → none from search",
|
|
403
|
+
{ contextIds: ALL, editorContextIds: [], agenticSearch: kb({ type: "json", variable: { docs: { enabled: "no" } } }) },
|
|
404
|
+
[],
|
|
405
|
+
],
|
|
406
|
+
[
|
|
407
|
+
"variable reference only hydration resolves → none from search",
|
|
408
|
+
{ contextIds: ALL, editorContextIds: [], agenticSearch: kb({ type: "variable", variable: "KB_PROFILES" }) },
|
|
409
|
+
[],
|
|
410
|
+
],
|
|
411
|
+
[
|
|
412
|
+
"memory context always excluded, even when granted to the editor",
|
|
413
|
+
{ contextIds: ALL, memoryContextId: "mem", editorContextIds: ["mem", "pitches"], agenticSearch: {} },
|
|
414
|
+
["docs", "pitches", "rows"],
|
|
415
|
+
],
|
|
416
|
+
[
|
|
417
|
+
"agentic search present but disabled this turn (caller passes no agenticSearch)",
|
|
418
|
+
{ contextIds: ALL, memoryContextId: "mem", editorContextIds: ["pitches"] },
|
|
419
|
+
["pitches"],
|
|
420
|
+
],
|
|
421
|
+
[
|
|
422
|
+
"no agentic search + project scope",
|
|
423
|
+
{ contextIds: ALL, memoryContextId: "mem", editorContextIds: [], projectSearchContextIds: ["docs"] },
|
|
424
|
+
["docs"],
|
|
425
|
+
],
|
|
426
|
+
["no agentic search, no project, no editor → empty", { contextIds: ALL, editorContextIds: [] }, []],
|
|
427
|
+
[
|
|
428
|
+
"editor context with both read tools disabled → excluded",
|
|
429
|
+
{
|
|
430
|
+
contextIds: ALL,
|
|
431
|
+
editorContextIds: ["pitches", "rows"],
|
|
432
|
+
disabledToolIds: new Set(["get_pitches_item", "find_pitches_items"]),
|
|
433
|
+
},
|
|
434
|
+
["rows"],
|
|
435
|
+
],
|
|
436
|
+
[
|
|
437
|
+
"editor context with both read tools disabled is still included when the search reaches it",
|
|
438
|
+
{
|
|
439
|
+
contextIds: ALL,
|
|
440
|
+
memoryContextId: "mem",
|
|
441
|
+
editorContextIds: ["pitches"],
|
|
442
|
+
disabledToolIds: new Set(["get_pitches_item", "find_pitches_items"]),
|
|
443
|
+
agenticSearch: {},
|
|
444
|
+
},
|
|
445
|
+
["docs", "pitches", "rows"],
|
|
446
|
+
],
|
|
447
|
+
[
|
|
448
|
+
"editor context with only one read tool disabled → included",
|
|
449
|
+
{ contextIds: ALL, editorContextIds: ["pitches"], disabledToolIds: new Set(["find_pitches_items"]) },
|
|
450
|
+
["pitches"],
|
|
451
|
+
],
|
|
452
|
+
[
|
|
453
|
+
"editor context with write tools disabled but read tools enabled → included",
|
|
454
|
+
{
|
|
455
|
+
contextIds: ALL,
|
|
456
|
+
editorContextIds: ["pitches"],
|
|
457
|
+
disabledToolIds: new Set(["create_pitches_item", "update_pitches_item"]),
|
|
458
|
+
},
|
|
459
|
+
["pitches"],
|
|
460
|
+
],
|
|
461
|
+
])("%s", (_name, args, expected) => {
|
|
462
|
+
expect(sorted(deriveConnectedContextIds(args))).toEqual(expected);
|
|
463
|
+
});
|
|
464
|
+
});
|