@pixlcore/xycli 1.2.5 → 1.2.7
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/docs/mcp.md +96 -6
- package/lib/mcp/context.js +23 -2
- package/lib/mcp/definition-tools.js +52 -0
- package/lib/mcp/job-output.js +86 -0
- package/lib/mcp/registry.js +17 -14
- package/lib/mcp/server.js +1 -0
- package/lib/mcp/tools/definitions.js +112 -0
- package/lib/mcp/tools/get-job-log.js +10 -0
- package/lib/mcp/tools/get-job.js +1 -1
- package/lib/mcp/tools/get-workflow-job-outputs.js +48 -0
- package/lib/mcp/tools/list-active-jobs.js +19 -0
- package/lib/mcp/tools/lookups.js +74 -0
- package/lib/mcp/tools/tail-job-log.js +16 -0
- package/package.json +1 -1
- package/test/mcp-http-unit.test.js +49 -3
- package/test/mcp-stdio-unit.test.js +317 -3
- package/test/mcp-tools-unit.test.js +101 -1
- package/test/mcp.test.js +38 -2
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const S = require('../schemas.js');
|
|
2
|
+
const definitionTools = require('../definition-tools.js');
|
|
3
|
+
|
|
4
|
+
const tagFields = ['id', 'title', 'icon'];
|
|
5
|
+
const destinationFields = ['id', 'title', 'enabled'];
|
|
6
|
+
const common = { title: { ...S.text, pattern: '\\S' }, icon: S.text, notes: S.text };
|
|
7
|
+
const bool = { type: 'boolean' };
|
|
8
|
+
const nonnegative = { type: 'integer', minimum: 0 };
|
|
9
|
+
const optionalId = { ...S.text, pattern: '^[a-z0-9_]*$', description: 'Exact xyOps ID, or an empty string to clear the link.' };
|
|
10
|
+
|
|
11
|
+
const channelProperties = {
|
|
12
|
+
...common, enabled: bool,
|
|
13
|
+
users: { type: 'array', items: { ...S.text, pattern: '^\\S+$' }, description: 'Subscribed usernames. Replaces the entire list on update.' },
|
|
14
|
+
email: { ...S.text, description: 'Comma-separated email addresses, or an empty string to clear them.' },
|
|
15
|
+
web_hook: optionalId, run_event: optionalId,
|
|
16
|
+
sound: { ...S.text, pattern: '^(?:[a-zA-Z0-9_.-]+\\.[mM][pP]3)?$', description: 'MP3 filename, or an empty string to clear it.' },
|
|
17
|
+
max_per_day: { ...nonnegative, description: 'Daily notification limit. Use 0 for unlimited.' }
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const webHookProperties = {
|
|
21
|
+
...common, enabled: bool,
|
|
22
|
+
url: { ...S.text, pattern: '^(?:[hH][tT][tT][pP][sS]?://\\S|\\{\\{)', description: 'HTTP(S) URL or an xyOps URL template.' },
|
|
23
|
+
method: { ...S.text, pattern: '^[A-Z]+$', description: 'HTTP method in uppercase, such as GET or POST.' },
|
|
24
|
+
headers: {
|
|
25
|
+
type: 'array', description: 'HTTP request headers. Replaces the entire list on update.',
|
|
26
|
+
items: S.input({
|
|
27
|
+
name: { ...S.text, pattern: "^[A-Za-z0-9!#$%&'*+.^_`|~-]+$" },
|
|
28
|
+
value: { ...S.text, pattern: '^[\\t\\x20-\\x7E\\x80-\\xFF]*$' }
|
|
29
|
+
}, ['name', 'value'])
|
|
30
|
+
},
|
|
31
|
+
body: { ...S.text, description: 'Request body template, or an empty string to clear it.' },
|
|
32
|
+
timeout: { ...nonnegative, description: 'Request timeout in seconds.' },
|
|
33
|
+
retries: { ...nonnegative, maximum: 999 }, follow: bool, ssl_cert_bypass: bool,
|
|
34
|
+
max_per_day: { ...nonnegative, maximum: 9999999, description: 'Daily request limit. Use 0 for unlimited.' }
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function listTool(collection, description, fields) {
|
|
38
|
+
return {
|
|
39
|
+
describe: () => S.describe('list_' + collection, description + ' Title matches a case-insensitive substring.', { ...S.pagination, title: S.text }),
|
|
40
|
+
async run(args, context) {
|
|
41
|
+
const { rows } = await context.callAPI('get_' + collection);
|
|
42
|
+
const title = args.title?.toLowerCase();
|
|
43
|
+
const matches = rows.filter(row => !title || (row.title || '').toLowerCase().includes(title))
|
|
44
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
45
|
+
const { offset, limit } = S.page(args, context);
|
|
46
|
+
|
|
47
|
+
// The API returns full records. Only expose the fields needed for discovery,
|
|
48
|
+
// since destinations can contain credentials and recipient information.
|
|
49
|
+
return { rows: matches.slice(offset, offset + limit).map(row => S.pick(row, fields)), total: matches.length, offset, limit };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = [
|
|
55
|
+
listTool('tags', 'Find tag IDs for events, jobs and tickets.', tagFields),
|
|
56
|
+
listTool('web_hooks', 'Find existing Web Hook IDs for actions. Returns ID, title and enabled status.', destinationFields),
|
|
57
|
+
listTool('channels', 'Find existing notification Channel IDs for actions. Returns ID, title and enabled status.', destinationFields),
|
|
58
|
+
...definitionTools({
|
|
59
|
+
name: 'tag', label: 'tag', properties: common, required: ['title'],
|
|
60
|
+
summaryFields: tagFields, readFields: [...tagFields, 'notes', 'revision']
|
|
61
|
+
}),
|
|
62
|
+
...definitionTools({
|
|
63
|
+
name: 'web_hook', label: 'Web Hook', properties: webHookProperties,
|
|
64
|
+
required: ['title', 'url', 'method'], summaryFields: [...destinationFields, 'revision'],
|
|
65
|
+
// URLs, headers and bodies can contain credentials. Accept them on writes
|
|
66
|
+
// while keeping them out of both create responses and detail responses.
|
|
67
|
+
readFields: ['id', 'title', 'enabled', 'icon', 'notes', 'revision', 'method', 'timeout', 'retries', 'follow', 'ssl_cert_bypass', 'max_per_day']
|
|
68
|
+
}),
|
|
69
|
+
...definitionTools({
|
|
70
|
+
name: 'channel', label: 'notification Channel', properties: channelProperties,
|
|
71
|
+
required: ['title'], defaults: () => ({ enabled: true, users: [] }),
|
|
72
|
+
summaryFields: [...destinationFields, 'revision'], readFields: ['id', 'revision', ...Object.keys(channelProperties)]
|
|
73
|
+
})
|
|
74
|
+
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const S = require('../schemas.js');
|
|
2
|
+
const O = require('../job-output.js');
|
|
3
|
+
|
|
4
|
+
exports.describe = () => S.describe('tail_job_log', 'Read recent console output from a running job immediately. Repeat to inspect progress; tails may overlap and are not a lossless stream. Returns job state and bounded text. Once final is true, use get_job_log for the completed log.', {
|
|
5
|
+
id: S.id, max_bytes: O.maxBytes
|
|
6
|
+
}, ['id']);
|
|
7
|
+
|
|
8
|
+
exports.run = async function(args, context) {
|
|
9
|
+
const bytes = args.max_bytes ?? 32768;
|
|
10
|
+
const { text } = await context.callAPI('tail_live_job_log', { id: args.id, bytes });
|
|
11
|
+
// Read state after the tail to handle a job completing between calls. An
|
|
12
|
+
// empty tail alone does not mean the job has finished or produced no log.
|
|
13
|
+
const { job } = await context.callAPI('get_job', { id: args.id });
|
|
14
|
+
// Active job records may omit final instead of explicitly setting false.
|
|
15
|
+
return { ...S.pick(job, ['id', 'state']), final: !!job.final, ...O.textOutput(text, bytes), tail_only: true, requested_bytes: bytes };
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixlcore/xycli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "A complete command-line interface for the xyOps workflow automation system.",
|
|
5
5
|
"author": "Joseph Huckaby <jhuckaby@pixlcore.com>",
|
|
6
6
|
"homepage": "https://github.com/pixlcore/xycli",
|
|
@@ -25,7 +25,7 @@ test('HTTP advertises a static tool catalog for modern and legacy clients', asyn
|
|
|
25
25
|
}, { headers });
|
|
26
26
|
for (const reply of [modern, legacy]) assert.deepEqual(reply.result.capabilities.tools, { listChanged: false });
|
|
27
27
|
const listing = await httpRPC(url, 'tools/list', {}, { headers, modern: true });
|
|
28
|
-
assert.equal(listing.result.tools.length, read_only ?
|
|
28
|
+
assert.equal(listing.result.tools.length, read_only ? 28 : tools.size);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -141,7 +141,7 @@ test('HTTP serves both protocol generations, validates calls and rejects unautho
|
|
|
141
141
|
|
|
142
142
|
for (const modern of [false, true]) {
|
|
143
143
|
const listing = await httpRPC(url, 'tools/list', {}, { headers, modern });
|
|
144
|
-
assert.equal(listing.result.tools.length,
|
|
144
|
+
assert.equal(listing.result.tools.length, 28);
|
|
145
145
|
assert.ok(listing.result.tools.every(tool => tool.annotations.readOnlyHint));
|
|
146
146
|
const response = await httpRPC(url, 'tools/call', { name: 'get_event', arguments: { id: 'e1' } }, { headers, modern });
|
|
147
147
|
assert.equal(response.result.structuredContent.event.id, 'e1');
|
|
@@ -291,7 +291,13 @@ test('new HTTP mutations use each client key and read-only mode rejects every wr
|
|
|
291
291
|
const readonlyURL = 'http://127.0.0.1:' + readonlyService.address.port + '/mcp';
|
|
292
292
|
const headers = { Authorization: 'Bearer readonly-key' };
|
|
293
293
|
const listing = await httpRPC(readonlyURL, 'tools/list', {}, { headers });
|
|
294
|
-
assert.deepEqual(listing.result.tools.map(tool => tool.name).sort(), [
|
|
294
|
+
assert.deepEqual(listing.result.tools.map(tool => tool.name).sort(), [
|
|
295
|
+
'get_alert', 'get_channel', 'get_event', 'get_event_options', 'get_group', 'get_job', 'get_job_log',
|
|
296
|
+
'get_monitor', 'get_plugin', 'get_tag', 'get_web_hook', 'get_workflow_job_outputs', 'list_active_jobs', 'list_alerts',
|
|
297
|
+
'list_channels', 'list_events', 'list_groups', 'list_monitors', 'list_plugins', 'list_servers',
|
|
298
|
+
'list_tags', 'list_web_hooks', 'search_alerts', 'search_jobs', 'search_snapshots',
|
|
299
|
+
'tail_job_log', 'test_alert', 'test_monitor'
|
|
300
|
+
]);
|
|
295
301
|
for (const tool of tools.values()) {
|
|
296
302
|
if (tool.description.annotations.readOnlyHint) continue;
|
|
297
303
|
const reply = await httpRPC(readonlyURL, 'tools/call', { name: tool.description.name, arguments: {} }, { headers });
|
|
@@ -299,3 +305,43 @@ test('new HTTP mutations use each client key and read-only mode rejects every wr
|
|
|
299
305
|
}
|
|
300
306
|
assert.equal(forbiddenCalls, 0);
|
|
301
307
|
});
|
|
308
|
+
|
|
309
|
+
test('HTTP job output tools scope raw downloads and every child lookup to the caller key', async t => {
|
|
310
|
+
const calls = [];
|
|
311
|
+
const context = createContext({
|
|
312
|
+
get_job_log: async (params, options) => {
|
|
313
|
+
const key = options.headers['X-API-Key'];
|
|
314
|
+
calls.push({ method: 'log', id: params.id, key });
|
|
315
|
+
assert.equal(options.retries, 0);
|
|
316
|
+
if (key === 'denied-key') return { err: 'Permission denied denied-key' };
|
|
317
|
+
await new Promise(resolve => setTimeout(resolve, key === 'slow-key' ? 20 : 1));
|
|
318
|
+
options.download.end('Log for ' + key);
|
|
319
|
+
return { resp: { statusCode: 200 } };
|
|
320
|
+
},
|
|
321
|
+
get_job: async (params, options) => {
|
|
322
|
+
const key = options.headers['X-API-Key'];
|
|
323
|
+
calls.push({ method: 'job', id: params.id, key });
|
|
324
|
+
return { data: { code: 0, token: 'private-token', job: params.id === 'parent' ? {
|
|
325
|
+
id: 'parent', type: 'workflow', final: true, workflow: { jobs: { node: [{ id: 'child' }] } }
|
|
326
|
+
} : { id: params.id, final: true, output: key } } };
|
|
327
|
+
}
|
|
328
|
+
}, { api_key: 'server-key', read_only: true });
|
|
329
|
+
const service = await start(factory(tools, context), { ...configuration({}, {}), port: 0, log() {} });
|
|
330
|
+
t.after(() => service.close());
|
|
331
|
+
const url = 'http://127.0.0.1:' + service.address.port + '/mcp';
|
|
332
|
+
const replies = await Promise.all(['slow-key', 'fast-key', 'denied-key'].map(key => httpRPC(url, 'tools/call', {
|
|
333
|
+
name: 'get_job_log', arguments: { id: 'log' }
|
|
334
|
+
}, { modern: true, headers: { Authorization: 'Bearer ' + key } })));
|
|
335
|
+
assert.equal(replies[0].result.structuredContent.text, 'Log for slow-key');
|
|
336
|
+
assert.equal(replies[1].result.structuredContent.text, 'Log for fast-key');
|
|
337
|
+
assert.equal(replies[2].result.isError, true);
|
|
338
|
+
assert.doesNotMatch(JSON.stringify(replies[2]), /denied-key|server-key/);
|
|
339
|
+
const workflow = await httpRPC(url, 'tools/call', { name: 'get_workflow_job_outputs', arguments: { id: 'parent' } }, {
|
|
340
|
+
headers: { Authorization: 'Bearer reader-key' }
|
|
341
|
+
});
|
|
342
|
+
assert.equal(workflow.result.structuredContent.rows[0].output, 'reader-key');
|
|
343
|
+
assert.doesNotMatch(JSON.stringify(workflow), /private-token|server-key/);
|
|
344
|
+
assert.deepEqual(calls.slice(-2), [
|
|
345
|
+
{ method: 'job', id: 'parent', key: 'reader-key' }, { method: 'job', id: 'child', key: 'reader-key' }
|
|
346
|
+
]);
|
|
347
|
+
});
|
|
@@ -37,7 +37,7 @@ test('STDIO uses the real CLI and SDK with protocol-only stdout and clean EOF',
|
|
|
37
37
|
const client = stdioClient(t, { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_RETRIES: '4' }, ['mcp', 'stdio', '--verbose', '--debug', '--read-only']);
|
|
38
38
|
assert.deepEqual((await client.initialize()).result.capabilities.tools, { listChanged: false });
|
|
39
39
|
const listing = await client.request('tools/list');
|
|
40
|
-
assert.equal(listing.result.tools.length,
|
|
40
|
+
assert.equal(listing.result.tools.length, 28);
|
|
41
41
|
assert.equal((await client.call('get_event', { id: 'fixture' })).result.structuredContent.event.revision, 2);
|
|
42
42
|
assert.equal(calls, 1);
|
|
43
43
|
const rejected = await client.call('run_event', { id: 'fixture' });
|
|
@@ -104,7 +104,7 @@ for (const { host, urlHost } of [{ host: '127.0.0.1', urlHost: '127.0.0.1' }, {
|
|
|
104
104
|
const listing = await httpRPC(url, 'tools/list', {}, {
|
|
105
105
|
modern: true, headers: { Authorization: 'Bearer fixture-token' }
|
|
106
106
|
});
|
|
107
|
-
assert.equal(listing.result.tools.length,
|
|
107
|
+
assert.equal(listing.result.tools.length, 28);
|
|
108
108
|
assert.equal((await fetch(url)).status, 401);
|
|
109
109
|
// Binding IPv6 must not weaken the Host allowlist.
|
|
110
110
|
const rejectedHost = await new Promise((resolve, reject) => {
|
|
@@ -172,7 +172,7 @@ test('ticket and monitoring tools use real SDK routes and validated STDIO inputs
|
|
|
172
172
|
const client = stdioClient(t, { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_MCP: '{}' });
|
|
173
173
|
await client.initialize();
|
|
174
174
|
const listing = await client.request('tools/list');
|
|
175
|
-
assert.equal(listing.result.tools.length,
|
|
175
|
+
assert.equal(listing.result.tools.length, 59);
|
|
176
176
|
const invoke = async (name, args) => {
|
|
177
177
|
const reply = await client.call(name, args);
|
|
178
178
|
assert.ok(reply.result && !reply.result.isError, JSON.stringify(reply));
|
|
@@ -211,3 +211,317 @@ test('ticket and monitoring tools use real SDK routes and validated STDIO inputs
|
|
|
211
211
|
client.child.stdin.end();
|
|
212
212
|
assert.equal((await client.exit)[0], 0);
|
|
213
213
|
});
|
|
214
|
+
|
|
215
|
+
test('definition tools use exact IDs and the caller key through the real SDK', async t => {
|
|
216
|
+
const definitions = {
|
|
217
|
+
plugin: { title: 'Queue collector', type: 'monitor', enabled: false, command: '/bin/sh', script: 'echo 0', groups: ['mail'] },
|
|
218
|
+
monitor: { title: 'Queue length', source: 'commands.queue', data_type: 'integer', groups: ['mail'] },
|
|
219
|
+
alert: { title: 'Queue too long', expression: 'monitors.queue > 10', message: 'Queue is too long', enabled: false, groups: ['mail'] },
|
|
220
|
+
group: { title: 'Mail servers' },
|
|
221
|
+
tag: { title: 'Needs Review', icon: 'flag' },
|
|
222
|
+
web_hook: {
|
|
223
|
+
title: 'Operations Web Hook', enabled: false, method: 'POST', url: 'https://example.test/private-token',
|
|
224
|
+
headers: [{ name: 'Authorization', value: 'private-header' }], body: 'private-body'
|
|
225
|
+
},
|
|
226
|
+
channel: { title: 'Operations Channel', users: ['operator'], email: 'ops@example.test', web_hook: 'ops_hook' }
|
|
227
|
+
};
|
|
228
|
+
const requests = [];
|
|
229
|
+
const backend = http.createServer(async (request, response) => {
|
|
230
|
+
let body = '';
|
|
231
|
+
for await (const chunk of request) body += chunk;
|
|
232
|
+
const url = new URL(request.url, 'http://fixture');
|
|
233
|
+
const name = url.pathname.split('/')[3];
|
|
234
|
+
const params = body ? JSON.parse(body) : Object.fromEntries(url.searchParams);
|
|
235
|
+
const key = request.headers['x-api-key'];
|
|
236
|
+
requests.push({ name, params, key });
|
|
237
|
+
const split = name.indexOf('_');
|
|
238
|
+
const verb = name.slice(0, split);
|
|
239
|
+
const kind = name.slice(split + 1);
|
|
240
|
+
const record = { ...definitions[kind.replace(/s$/, '')], id: params.id || 'exact_id', revision: 2, notes: 'Full definition' };
|
|
241
|
+
let result = { code: 0 };
|
|
242
|
+
if (key === 'restricted-key' && verb !== 'get') {
|
|
243
|
+
response.statusCode = 403;
|
|
244
|
+
result = { code: 'access', description: 'Permission denied' };
|
|
245
|
+
}
|
|
246
|
+
else if (name === 'test_monitor') result.value = 0;
|
|
247
|
+
else if (name === 'test_alert') Object.assign(result, { result: false, message: params.message });
|
|
248
|
+
else if (verb === 'get' && kind.endsWith('s')) result.rows = [record, { id: 'other_id', title: 'Other' }];
|
|
249
|
+
else if (verb === 'get' || verb === 'create') result[kind] = record;
|
|
250
|
+
response.setHeader('Content-Type', 'application/json');
|
|
251
|
+
response.end(JSON.stringify(result));
|
|
252
|
+
});
|
|
253
|
+
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
254
|
+
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
255
|
+
const connect = async key => {
|
|
256
|
+
const client = stdioClient(t, { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: key, XYOPS_MCP: '{}' });
|
|
257
|
+
await client.initialize();
|
|
258
|
+
return client;
|
|
259
|
+
};
|
|
260
|
+
const client = await connect('editor-key');
|
|
261
|
+
const restricted = await connect('restricted-key');
|
|
262
|
+
const invoke = async (name, args) => {
|
|
263
|
+
const reply = await client.call(name, args);
|
|
264
|
+
assert.ok(reply.result && !reply.result.isError, JSON.stringify(reply));
|
|
265
|
+
assert.deepEqual(JSON.parse(reply.result.content[0].text), reply.result.structuredContent);
|
|
266
|
+
return reply.result.structuredContent;
|
|
267
|
+
};
|
|
268
|
+
const denied = async (name, args) => {
|
|
269
|
+
const { result } = await restricted.call(name, args);
|
|
270
|
+
assert.equal(result.isError, true, name);
|
|
271
|
+
assert.equal(result.content[0].text, 'Permission denied');
|
|
272
|
+
assert.equal(requests.at(-1).key, 'restricted-key');
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
for (const [kind, definition] of Object.entries(definitions)) {
|
|
276
|
+
const id = 'exact_id';
|
|
277
|
+
const listing = await invoke('list_' + kind + 's', { title: definition.title.toUpperCase(), limit: 1 });
|
|
278
|
+
assert.equal(listing.total, 1);
|
|
279
|
+
assert.equal(listing.rows[0].id, id);
|
|
280
|
+
assert.ok(!('notes' in listing.rows[0]));
|
|
281
|
+
const read = await invoke('get_' + kind, { id, fields: ['notes'] });
|
|
282
|
+
assert.deepEqual(read[kind], { id, revision: 2, notes: 'Full definition' });
|
|
283
|
+
const create = { [kind]: definition };
|
|
284
|
+
const created = await invoke('create_' + kind, create);
|
|
285
|
+
assert.equal(created[kind].id, id);
|
|
286
|
+
assert.equal(requests.at(-1).key, 'editor-key');
|
|
287
|
+
if (kind === 'plugin') assert.deepEqual(requests.at(-1).params, { format: 'text', quick: false, ...definition });
|
|
288
|
+
if (kind === 'group') assert.equal(requests.at(-1).params.hostname_match, '(?!)');
|
|
289
|
+
if (kind === 'channel') assert.deepEqual(requests.at(-1).params, { enabled: true, ...definition });
|
|
290
|
+
if (kind === 'web_hook') {
|
|
291
|
+
assert.deepEqual(requests.at(-1).params, definition);
|
|
292
|
+
assert.deepEqual(created.web_hook, { id, revision: 2, title: definition.title, enabled: false });
|
|
293
|
+
assert.deepEqual(await invoke('get_web_hook', { id }), {
|
|
294
|
+
web_hook: { id, revision: 2, title: definition.title, enabled: false, notes: 'Full definition', method: 'POST' }
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
await denied('create_' + kind, create);
|
|
298
|
+
|
|
299
|
+
const update = 'update_' + kind;
|
|
300
|
+
const remove = 'delete_' + kind;
|
|
301
|
+
let changes = { notes: '' };
|
|
302
|
+
if (kind === 'web_hook') changes = { headers: [], body: '' };
|
|
303
|
+
if (kind === 'channel') changes = { users: [], email: '', web_hook: '', run_event: '', enabled: false };
|
|
304
|
+
const stale = await client.call(update, { id, revision: 1, changes });
|
|
305
|
+
assert.equal(stale.result.isError, true);
|
|
306
|
+
assert.match(stale.result.content[0].text, /Revision mismatch/);
|
|
307
|
+
assert.equal(requests.at(-1).name, 'get_' + kind);
|
|
308
|
+
assert.deepEqual(await invoke(update, { id, revision: 2, changes }), { id, updated: true });
|
|
309
|
+
assert.deepEqual(requests.at(-1), { name: update, params: { id, ...changes }, key: 'editor-key' });
|
|
310
|
+
await denied(update, { id, revision: 2, changes });
|
|
311
|
+
assert.deepEqual(requests.at(-1).params, { id, ...changes });
|
|
312
|
+
assert.deepEqual(await invoke(remove, { id }), { id, deleted: true });
|
|
313
|
+
assert.deepEqual(requests.at(-1), { name: remove, params: { id }, key: 'editor-key' });
|
|
314
|
+
await denied(remove, { id });
|
|
315
|
+
assert.deepEqual(requests.at(-1).params, { id });
|
|
316
|
+
|
|
317
|
+
// Invalid selectors and attempts to replace the ID inside a patch never reach xyOps.
|
|
318
|
+
const count = requests.length;
|
|
319
|
+
for (const [name, args] of [[update, { id, changes: { id: 'other_id', ...changes } }], [remove, { id: 'Display Title' }]]) {
|
|
320
|
+
const reply = await client.call(name, args);
|
|
321
|
+
assert.ok(reply.error || reply.result.isError, name);
|
|
322
|
+
}
|
|
323
|
+
assert.equal(requests.length, count);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const count = requests.length;
|
|
327
|
+
for (const [name, args] of [
|
|
328
|
+
['get_web_hook', { id: 'exact_id', fields: ['url', 'headers', 'body'] }],
|
|
329
|
+
['update_web_hook', { id: 'exact_id', changes: { headers: [{ name: 'Bad Name', value: 'test' }] } }],
|
|
330
|
+
['update_web_hook', { id: 'exact_id', changes: { url: 'file:///test' } }],
|
|
331
|
+
['update_channel', { id: 'exact_id', changes: { users: 'operator' } }]
|
|
332
|
+
]) {
|
|
333
|
+
const reply = await client.call(name, args);
|
|
334
|
+
assert.ok(reply.error || reply.result.isError, name);
|
|
335
|
+
}
|
|
336
|
+
assert.equal(requests.length, count);
|
|
337
|
+
|
|
338
|
+
const assignment = { id: 'server1', groups: ['existing', 'mail'] };
|
|
339
|
+
await invoke('set_server_groups', assignment);
|
|
340
|
+
assert.deepEqual(requests.at(-1), { name: 'update_server', params: { ...assignment, autoGroup: false }, key: 'editor-key' });
|
|
341
|
+
await denied('set_server_groups', assignment);
|
|
342
|
+
for (const [name, args, expected] of [
|
|
343
|
+
['test_monitor', { server: 'server1', source: 'commands.queue', data_type: 'integer' }, { value: 0 }],
|
|
344
|
+
['test_alert', { server: 'server1', expression: 'monitors.queue > 10', message: 'Queue is too long' }, { result: false, message: 'Queue is too long' }]
|
|
345
|
+
]) {
|
|
346
|
+
assert.deepEqual(await invoke(name, args), expected);
|
|
347
|
+
assert.deepEqual(requests.at(-1), { name, params: args, key: 'editor-key' });
|
|
348
|
+
await denied(name, args);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('lookup tools project safe summaries, page active jobs upstream and respect tag creation privileges', async t => {
|
|
353
|
+
const requests = [];
|
|
354
|
+
const job = { id: 'j1', event: 'e1', category: 'c1', state: 'queued', position: 2 };
|
|
355
|
+
const rows = {
|
|
356
|
+
get_tags: [{ id: 'urgent', title: 'Urgent', icon: 'flag', username: 'admin' }, { id: 'normal', title: 'Normal' }],
|
|
357
|
+
get_web_hooks: [{ id: 'hook1', title: 'Alerts Hook', enabled: true, url: 'https://example.test/token', headers: [{ name: 'Authorization', value: 'private' }], body: 'private body' }],
|
|
358
|
+
get_channels: [{ id: 'channel1', title: 'Ops Alerts', enabled: false, email: ['private@example.test'], users: ['private'], web_hook: 'hook1', run_event: 'e1' }],
|
|
359
|
+
get_active_jobs: [{ ...job, params: { password: 'private' }, env: { TOKEN: 'private' }, log_file: 'internal', secrets: ['private'] }]
|
|
360
|
+
};
|
|
361
|
+
const backend = http.createServer(async (request, response) => {
|
|
362
|
+
let body = '';
|
|
363
|
+
for await (const chunk of request) body += chunk;
|
|
364
|
+
const url = new URL(request.url, 'http://fixture');
|
|
365
|
+
const path = url.pathname;
|
|
366
|
+
const name = path.split('/')[3];
|
|
367
|
+
const params = body ? JSON.parse(body) : Object.fromEntries(url.searchParams);
|
|
368
|
+
const key = request.headers['x-api-key'];
|
|
369
|
+
requests.push({ path, method: request.method, params, key });
|
|
370
|
+
let result;
|
|
371
|
+
if (name === 'create_tag' && key === 'editor-key') result = { code: 0, tag: { ...params, id: params.id || 'generated_tag', username: 'admin' } };
|
|
372
|
+
else if (name === 'create_tag') {
|
|
373
|
+
response.statusCode = 403;
|
|
374
|
+
result = { code: 'access', description: 'Permission denied' };
|
|
375
|
+
}
|
|
376
|
+
else result = { code: 0, rows: rows[name], list: { length: name === 'get_active_jobs' ? 7 : rows[name].length } };
|
|
377
|
+
response.setHeader('Content-Type', 'application/json');
|
|
378
|
+
response.end(JSON.stringify(result));
|
|
379
|
+
});
|
|
380
|
+
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
381
|
+
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
382
|
+
const env = { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_MCP: '{"max_page_size":2}' };
|
|
383
|
+
const client = stdioClient(t, { ...env, XYOPS_API_KEY: 'editor-key' });
|
|
384
|
+
await client.initialize();
|
|
385
|
+
const invoke = async (name, args) => {
|
|
386
|
+
const { result } = await client.call(name, args);
|
|
387
|
+
assert.ok(result && !result.isError, name);
|
|
388
|
+
assert.deepEqual(JSON.parse(result.content[0].text), result.structuredContent);
|
|
389
|
+
return result.structuredContent;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
assert.deepEqual(await invoke('list_tags', { offset: 1, limit: 1 }), {
|
|
393
|
+
rows: [{ id: 'urgent', title: 'Urgent', icon: 'flag' }], total: 2, offset: 1, limit: 1
|
|
394
|
+
});
|
|
395
|
+
assert.deepEqual((await invoke('list_web_hooks', { title: 'ALERTS' })).rows, [{ id: 'hook1', title: 'Alerts Hook', enabled: true }]);
|
|
396
|
+
assert.deepEqual((await invoke('list_channels', { title: 'OPS' })).rows, [{ id: 'channel1', title: 'Ops Alerts', enabled: false }]);
|
|
397
|
+
assert.deepEqual(await invoke('list_active_jobs', { state: 'queued', event: 'e1', category: 'c1', offset: 2, limit: 10 }), {
|
|
398
|
+
rows: [job], total: 7, offset: 2, limit: 2
|
|
399
|
+
});
|
|
400
|
+
assert.deepEqual(requests.at(-1), {
|
|
401
|
+
path: '/api/app/get_active_jobs/v1', method: 'GET', key: 'editor-key',
|
|
402
|
+
params: { state: 'queued', event: 'e1', category: 'c1', offset: '2', limit: '2' }
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
const tag = { title: 'Follow up', icon: 'flag', notes: 'Check tomorrow' };
|
|
406
|
+
assert.deepEqual(await invoke('create_tag', { tag }), { tag: { id: 'generated_tag', title: tag.title, icon: tag.icon } });
|
|
407
|
+
assert.deepEqual(requests.at(-1), { path: '/api/app/create_tag/v1', method: 'POST', params: tag, key: 'editor-key' });
|
|
408
|
+
const restricted = stdioClient(t, { ...env, XYOPS_API_KEY: 'restricted-key' });
|
|
409
|
+
await restricted.initialize();
|
|
410
|
+
const denied = await restricted.call('create_tag', { tag });
|
|
411
|
+
assert.equal(denied.result.isError, true);
|
|
412
|
+
assert.match(denied.result.content[0].text, /Permission denied/);
|
|
413
|
+
assert.equal(requests.at(-1).key, 'restricted-key');
|
|
414
|
+
|
|
415
|
+
// Lookup callers cannot request extra fields or pass arbitrary job criteria.
|
|
416
|
+
const count = requests.length;
|
|
417
|
+
for (const [name, args] of [
|
|
418
|
+
['list_web_hooks', { fields: ['headers'] }], ['list_channels', { fields: ['email'] }],
|
|
419
|
+
['list_active_jobs', { state: 'complete' }], ['list_active_jobs', { env: {} }],
|
|
420
|
+
['create_tag', { tag: { title: ' ', username: 'admin' } }]
|
|
421
|
+
]) {
|
|
422
|
+
const reply = await client.call(name, args);
|
|
423
|
+
assert.ok(reply.error || reply.result.isError, name);
|
|
424
|
+
}
|
|
425
|
+
assert.equal(requests.length, count);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
test('job output tools use real SDK downloads, gzip, byte pages and read-only STDIO', async t => {
|
|
429
|
+
const { gzipSync } = require('node:zlib');
|
|
430
|
+
const text = 'abc😀é\n' + 'Archived output\n'.repeat(10000);
|
|
431
|
+
const requests = [];
|
|
432
|
+
const backend = http.createServer((request, response) => {
|
|
433
|
+
const url = new URL(request.url, 'http://fixture');
|
|
434
|
+
const name = url.pathname.split('/')[3];
|
|
435
|
+
const id = url.searchParams.get('id');
|
|
436
|
+
requests.push({ name, id });
|
|
437
|
+
assert.equal(request.headers['x-api-key'], 'fixture-key');
|
|
438
|
+
if (name === 'get_job_log') {
|
|
439
|
+
if (id === 'empty') { response.writeHead(204); response.end(); return; }
|
|
440
|
+
if (id === 'denied') { response.writeHead(403); response.end('Permission denied '.repeat(100)); return; }
|
|
441
|
+
response.setHeader('Content-Type', 'text/plain');
|
|
442
|
+
if (id === 'plain') { response.end('plain output'); return; }
|
|
443
|
+
response.setHeader('Content-Encoding', 'gzip');
|
|
444
|
+
response.end(id === 'broken' ? 'not gzip' : gzipSync(text));
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
response.setHeader('Content-Type', 'application/json');
|
|
448
|
+
if (name === 'tail_live_job_log') {
|
|
449
|
+
// This API accepts POST JSON. Collect the body to check the SDK route.
|
|
450
|
+
let body = '';
|
|
451
|
+
request.on('data', chunk => { body += chunk; });
|
|
452
|
+
request.on('end', () => {
|
|
453
|
+
assert.deepEqual(JSON.parse(body), { id: 'running', bytes: 32768 });
|
|
454
|
+
response.end(JSON.stringify({ code: 0, text: 'live output' }));
|
|
455
|
+
});
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const job = id === 'parent' ? { id, type: 'workflow', final: true, workflow: { jobs: { node: [{ id: 'child' }] } } } : { id, final: id !== 'running', output: 'child output', data: { answer: 42 } };
|
|
459
|
+
response.end(JSON.stringify({ code: 0, token: 'private-token', job }));
|
|
460
|
+
});
|
|
461
|
+
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
462
|
+
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
463
|
+
const client = stdioClient(t, {
|
|
464
|
+
XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_MCP: '{}'
|
|
465
|
+
}, ['mcp', 'stdio', '--read-only']);
|
|
466
|
+
await client.initialize();
|
|
467
|
+
async function invoke(name, args) {
|
|
468
|
+
const reply = await client.call(name, args);
|
|
469
|
+
assert.ok(reply.result && !reply.result.isError, JSON.stringify(reply));
|
|
470
|
+
return reply.result.structuredContent;
|
|
471
|
+
}
|
|
472
|
+
const first = await invoke('get_job_log', { id: 'archive', max_bytes: 4 });
|
|
473
|
+
assert.deepEqual(first, { id: 'archive', text: 'abc', offset: 0, next_offset: 3, truncated: true });
|
|
474
|
+
const second = await invoke('get_job_log', { id: 'archive', offset: first.next_offset, max_bytes: 4 });
|
|
475
|
+
assert.equal(second.text, '😀');
|
|
476
|
+
assert.equal(second.next_offset, 7);
|
|
477
|
+
const complete = await invoke('get_job_log', { id: 'archive', max_bytes: 262144 });
|
|
478
|
+
assert.equal(complete.text, text);
|
|
479
|
+
assert.equal(complete.truncated, false);
|
|
480
|
+
assert.equal(complete.next_offset, Buffer.byteLength(text));
|
|
481
|
+
assert.equal((await invoke('get_job_log', { id: 'archive', offset: complete.next_offset })).text, '');
|
|
482
|
+
assert.equal((await invoke('get_job_log', { id: 'plain' })).text, 'plain output');
|
|
483
|
+
assert.equal((await invoke('get_job_log', { id: 'empty' })).text, '');
|
|
484
|
+
for (const id of ['denied', 'broken']) {
|
|
485
|
+
const reply = await client.call('get_job_log', { id, max_bytes: 4 });
|
|
486
|
+
assert.equal(reply.result.isError, true, id);
|
|
487
|
+
}
|
|
488
|
+
const tail = await invoke('tail_job_log', { id: 'running' });
|
|
489
|
+
assert.equal(tail.text, 'live output');
|
|
490
|
+
assert.equal(tail.final, false);
|
|
491
|
+
const workflow = await invoke('get_workflow_job_outputs', { id: 'parent' });
|
|
492
|
+
assert.equal(workflow.rows[0].output, 'child output');
|
|
493
|
+
assert.deepEqual(workflow.rows[0].data, { answer: 42 });
|
|
494
|
+
assert.ok(!JSON.stringify(workflow).includes('private-token'));
|
|
495
|
+
assert.deepEqual(requests.slice(-2), [{ name: 'get_job', id: 'parent' }, { name: 'get_job', id: 'child' }]);
|
|
496
|
+
client.child.stdin.end();
|
|
497
|
+
assert.equal((await client.exit)[0], 0);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
test('cancelling a log download closes its upstream socket and permits clean shutdown', { timeout: 10000 }, async t => {
|
|
501
|
+
let started;
|
|
502
|
+
const starting = new Promise(resolve => { started = resolve; });
|
|
503
|
+
let closed;
|
|
504
|
+
const closing = new Promise(resolve => { closed = resolve; });
|
|
505
|
+
const backend = http.createServer((request, response) => {
|
|
506
|
+
response.on('close', closed);
|
|
507
|
+
response.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
508
|
+
response.write('Still downloading\n');
|
|
509
|
+
started();
|
|
510
|
+
});
|
|
511
|
+
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
512
|
+
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
513
|
+
const client = stdioClient(t, {
|
|
514
|
+
XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_MCP: '{}'
|
|
515
|
+
});
|
|
516
|
+
await client.initialize();
|
|
517
|
+
// Write a known request ID directly so cancellation targets the exact
|
|
518
|
+
// invocation without adding a pending call to the small test client.
|
|
519
|
+
client.child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id: 999, method: 'tools/call', params: {
|
|
520
|
+
name: 'get_job_log', arguments: { id: 'large' }
|
|
521
|
+
} }) + '\n');
|
|
522
|
+
await starting;
|
|
523
|
+
client.child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/cancelled', params: { requestId: 999 } }) + '\n');
|
|
524
|
+
await closing;
|
|
525
|
+
client.child.stdin.end();
|
|
526
|
+
assert.equal((await client.exit)[0], 0);
|
|
527
|
+
});
|
|
@@ -10,7 +10,7 @@ const tools = require('../lib/mcp/registry.js')();
|
|
|
10
10
|
|
|
11
11
|
test('tool schemas reject unsafe or ambiguous mutation inputs', async () => {
|
|
12
12
|
const validate = (name, args) => tools.get(name).inputSchema['~standard'].validate(args);
|
|
13
|
-
assert.equal(tools.size,
|
|
13
|
+
assert.equal(tools.size, 59);
|
|
14
14
|
assert.ok((await validate('create_event', { event: { title: 'Test', category: 'general', enabled: false } })).issues);
|
|
15
15
|
assert.ok((await validate('update_event', { id: 'test', changes: { title: 'New' } })).issues);
|
|
16
16
|
assert.ok((await validate('update_event', { id: 'test', revision: 0, changes: {} })).issues);
|
|
@@ -210,3 +210,103 @@ test('take_snapshot dispatches server and group requests without starting watche
|
|
|
210
210
|
assert.deepEqual(await tools.get('take_snapshot').run({ server: 's1' }, context), { id: 'sn1', type: 'server', server: 's1' });
|
|
211
211
|
assert.deepEqual(await tools.get('take_snapshot').run({ group: 'main' }, context), { id: 'sn2', type: 'group', group: 'main' });
|
|
212
212
|
});
|
|
213
|
+
|
|
214
|
+
test('job output schemas validate byte bounds, pagination and exact job IDs', async () => {
|
|
215
|
+
for (const name of ['get_job_log', 'tail_job_log', 'get_workflow_job_outputs']) {
|
|
216
|
+
assert.equal(tools.get(name).description.annotations.readOnlyHint, true);
|
|
217
|
+
const validate = args => tools.get(name).inputSchema['~standard'].validate(args);
|
|
218
|
+
assert.ok(!(await validate({ id: 'j1' })).issues);
|
|
219
|
+
for (const args of [{}, { id: '../j1' }, { id: 'j1', max_bytes: 0 }, { id: 'j1', max_bytes: 262145 }, { id: 'j1', token: 'private' }]) {
|
|
220
|
+
assert.ok((await validate(args)).issues, name + ': ' + JSON.stringify(args));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const offset of [-1, 1.5, Number.MAX_SAFE_INTEGER]) {
|
|
224
|
+
assert.ok((await tools.get('get_job_log').inputSchema['~standard'].validate({ id: 'j1', offset })).issues);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('live tails use the caller key and report completion races without claiming a lossless stream', async () => {
|
|
229
|
+
const requests = [];
|
|
230
|
+
const api = {
|
|
231
|
+
tail_live_job_log: async (params, options) => {
|
|
232
|
+
requests.push(params);
|
|
233
|
+
assert.equal(options.headers['X-API-Key'], 'reader-key');
|
|
234
|
+
return { data: { code: 0, text: 'abc😀end' } };
|
|
235
|
+
},
|
|
236
|
+
get_job: async (params, options) => {
|
|
237
|
+
assert.equal(options.headers['X-API-Key'], 'reader-key');
|
|
238
|
+
return { data: { code: 0, token: 'private-token', job: { id: params.id, state: 'complete', final: true } } };
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const context = createContext(api, { api_key: 'server-key', read_only: true }).withApiKey('reader-key');
|
|
242
|
+
const tail = await tools.get('tail_job_log').run({ id: 'j1', max_bytes: 4 }, context);
|
|
243
|
+
assert.deepEqual(requests, [{ id: 'j1', bytes: 4 }]);
|
|
244
|
+
assert.deepEqual(tail, { id: 'j1', state: 'complete', final: true, text: 'abc', truncated: true, tail_only: true, requested_bytes: 4 });
|
|
245
|
+
api.tail_live_job_log = async () => ({ data: { code: 0, text: '' } });
|
|
246
|
+
assert.equal((await tools.get('tail_job_log').run({ id: 'j1' }, context)).final, true);
|
|
247
|
+
api.get_job = async () => ({ data: { code: 0, job: { id: 'j1', state: 'active' } } });
|
|
248
|
+
assert.equal((await tools.get('tail_job_log').run({ id: 'j1' }, context)).final, false);
|
|
249
|
+
api.tail_live_job_log = async () => ({ data: { code: 'access', description: 'Permission denied' } });
|
|
250
|
+
await assert.rejects(tools.get('tail_job_log').run({ id: 'j1' }, context), /Permission denied/);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('workflow output pages preserve attempts, bound text/data and isolate inaccessible children', async () => {
|
|
254
|
+
const requests = [];
|
|
255
|
+
const parent = { id: 'parent', type: 'workflow', final: true, workflow: { jobs: {
|
|
256
|
+
z: [{ id: 'nested' }], a: [{ id: 'first' }, { id: 'retry' }, { id: 'denied' }, { id: 'large' }]
|
|
257
|
+
} } };
|
|
258
|
+
const context = createContext({ get_job: async (params, options) => {
|
|
259
|
+
requests.push(params.id);
|
|
260
|
+
assert.equal(options.headers['X-API-Key'], 'reader-key');
|
|
261
|
+
if (params.id === 'denied') return { data: { code: 'access', description: 'Permission denied' } };
|
|
262
|
+
const job = params.id === 'parent' ? parent : (params.id === 'nested' ? { id: 'nested', type: 'workflow', final: true } : {
|
|
263
|
+
id: params.id, final: true, output: params.id === 'large' ? undefined : 'abc😀end', log_file_size: 100,
|
|
264
|
+
data: params.id === 'first' ? { ok: 1 } : { big: 'x'.repeat(100) }
|
|
265
|
+
});
|
|
266
|
+
return { data: { code: 0, token: 'private-token', job } };
|
|
267
|
+
} }, { read_only: true, api_key: 'reader-key', max_page_size: 4 });
|
|
268
|
+
const tool = tools.get('get_workflow_job_outputs');
|
|
269
|
+
const page = await tool.run({ id: 'parent', max_bytes: 8, limit: 50 }, context);
|
|
270
|
+
assert.deepEqual(requests, ['parent', 'first', 'retry', 'denied', 'large']);
|
|
271
|
+
assert.deepEqual(page.rows.map(row => row.node), ['a', 'a', 'a', 'a']);
|
|
272
|
+
assert.equal(page.total, 5);
|
|
273
|
+
assert.equal(page.limit, 4);
|
|
274
|
+
assert.equal(page.next_offset, 4);
|
|
275
|
+
assert.equal(page.rows[0].output, 'abc😀e');
|
|
276
|
+
assert.equal(page.rows[0].output_truncated, true);
|
|
277
|
+
assert.deepEqual(page.rows[0].data, { ok: 1 });
|
|
278
|
+
assert.equal(page.rows[1].data_truncated, true);
|
|
279
|
+
assert.ok(Buffer.byteLength(page.rows[1].data_preview) <= 8);
|
|
280
|
+
assert.deepEqual(page.rows[2], { node: 'a', id: 'denied', error: 'Permission denied' });
|
|
281
|
+
assert.equal(page.rows[3].log_available, true);
|
|
282
|
+
assert.equal(page.rows[3].log_inline, false);
|
|
283
|
+
assert.ok(!JSON.stringify(page).includes('private-token'));
|
|
284
|
+
const nested = await tool.run({ id: 'parent', offset: page.next_offset }, context);
|
|
285
|
+
assert.equal(nested.rows[0].id, 'nested');
|
|
286
|
+
assert.equal(nested.rows[0].type, 'workflow');
|
|
287
|
+
assert.equal(nested.next_offset, 5);
|
|
288
|
+
assert.equal((await tool.run({ id: 'parent', offset: 10 }, context)).rows.length, 0);
|
|
289
|
+
parent.final = false;
|
|
290
|
+
await assert.rejects(tool.run({ id: 'parent' }, context), /still running/);
|
|
291
|
+
parent.final = true;
|
|
292
|
+
parent.workflow.jobs = {};
|
|
293
|
+
assert.equal((await tool.run({ id: 'parent' }, context)).total, 0);
|
|
294
|
+
parent.type = 'event';
|
|
295
|
+
await assert.rejects(tool.run({ id: 'parent' }, context), /not a workflow/);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('workflow output cancellation stops before reading another child', async () => {
|
|
299
|
+
const controller = new AbortController();
|
|
300
|
+
let calls = 0;
|
|
301
|
+
const context = {
|
|
302
|
+
limits: { max_page_size: 100 }, signal: controller.signal,
|
|
303
|
+
async callAPI() {
|
|
304
|
+
calls++;
|
|
305
|
+
if (calls === 1) return { job: { type: 'workflow', final: true, workflow: { jobs: { a: [{ id: 'first' }, { id: 'second' }] } } } };
|
|
306
|
+
controller.abort();
|
|
307
|
+
throw new Error('Request cancelled');
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
await assert.rejects(tools.get('get_workflow_job_outputs').run({ id: 'parent' }, context), /cancelled/);
|
|
311
|
+
assert.equal(calls, 2);
|
|
312
|
+
});
|