@pixlcore/xycli 1.2.5 → 1.2.6
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 +30 -3
- package/lib/mcp/context.js +10 -1
- package/lib/mcp/job-output.js +86 -0
- package/lib/mcp/server.js +1 -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/tail-job-log.js +16 -0
- package/package.json +1 -1
- package/test/mcp-http-unit.test.js +43 -3
- package/test/mcp-stdio-unit.test.js +104 -3
- package/test/mcp-tools-unit.test.js +101 -1
- package/test/mcp.test.js +38 -2
package/docs/mcp.md
CHANGED
|
@@ -166,6 +166,9 @@ This opens only the HTTPS listener. Restart after replacing certificate files. U
|
|
|
166
166
|
| `delete_event` | Delete an event while retaining historical jobs. Active jobs prevent deletion. |
|
|
167
167
|
| `run_event` | Launch an enabled event with a manual trigger, optionally supplying parameters and input data. |
|
|
168
168
|
| `get_job` | Inspect job state, completion and output. Optional `fields` selects other job properties. |
|
|
169
|
+
| `get_job_log` | Read a completed job's console log, including archived logs, in bounded byte ranges. |
|
|
170
|
+
| `tail_job_log` | Read recent console output from a running job, along with its current state. |
|
|
171
|
+
| `get_workflow_job_outputs` | Inspect paginated direct child results, console output and output data from a completed workflow. |
|
|
169
172
|
| `search_jobs` | Search completed jobs with query, pagination and sorting. |
|
|
170
173
|
| `create_ticket` | Create a ticket with a subject, Markdown body and optional classification/assignment. |
|
|
171
174
|
| `update_ticket` | Apply only supplied fields to a ticket by exact ID. |
|
|
@@ -184,6 +187,30 @@ Event updates preserve omitted top-level fields. Supplied objects and arrays rep
|
|
|
184
187
|
|
|
185
188
|
`run_event` returns immediately with a job ID. Use `get_job` until `final` is true, or search with `event:EVENT_ID` or `tags:_error`. Launches accept parameter overrides and `input.data`, but not arbitrary event overrides, test-mode bypasses or local-file uploads.
|
|
186
189
|
|
|
190
|
+
### Job output
|
|
191
|
+
|
|
192
|
+
`get_job` includes structured output `data` and any console `output` stored inline with the job. Use the log tools when you need live console text or a completed log that was archived separately. All three tools are available in read-only mode and use the caller's API-key permissions. Download tokens and generated download URLs are not returned.
|
|
193
|
+
|
|
194
|
+
For a completed job, call `get_job_log` with `{"id":"JOB_ID"}`. The result includes `text`, the requested byte `offset`, a byte `next_offset`, and `truncated`. The default `max_bytes` is 32768 (32 KiB). If `truncated` is `true`, call again using the returned `next_offset`:
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
{ "id": "JOB_ID", "offset": 32768, "max_bytes": 32768 }
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Offsets count bytes in the uncompressed log. Pages preserve UTF-8 character boundaries, so please use the actual `next_offset` from each response. Archived gzip logs are decompressed automatically. The tool retains only the requested range and stops downloading when it detects more text; later pages reread the log from the beginning to reach their offset. A job with no available log returns empty text. Running jobs should use `tail_job_log` instead.
|
|
201
|
+
|
|
202
|
+
For live output, call `tail_job_log` with `{"id":"JOB_ID","max_bytes":32768}`. This returns immediately with recent `text`, `state`, `final`, `requested_bytes`, and `tail_only: true`. xyOps aligns the tail to log lines, so it can return less text than requested. The `truncated` flag describes additional clipping of this returned tail; a `false` value does not mean the text contains the entire log. An empty tail can mean the job is queued or has not produced output yet. When `final` is `true`, switch to `get_job_log` for the completed log.
|
|
203
|
+
|
|
204
|
+
You can repeat live-tail calls to inspect progress. Successive tails may overlap or miss intervening output from a busy job. They do not provide a lossless stream or hold the tool call open until completion. For continuous following, use `xy job stream JOB_ID` or the xyOps `stream_job` API.
|
|
205
|
+
|
|
206
|
+
For a completed workflow, call `get_workflow_job_outputs` with `{"id":"WORKFLOW_JOB_ID","limit":10}`. The result contains `rows`, `total`, `offset`, `limit`, and `next_offset`. Each row includes the child job ID, workflow `node` ID, result details, available inline `output`, and output `data`. Children are ordered by node ID, then execution order within the node, including repeated executions and retries. Use `next_offset` to request the next page while it is less than `total`.
|
|
207
|
+
|
|
208
|
+
Workflow `max_bytes` defaults to 8192 (8 KiB) per child's console output and per child's serialized output data. `output_truncated` identifies clipped inline text. Oversized data is returned as a text `data_preview` with `data_truncated: true`; otherwise `data` retains its original JSON value. `log_available` identifies a captured console log, while `log_inline` identifies output stored in the job record. Use `get_job_log` with the child's ID for an archived or truncated log, and `get_job` with `fields: ["data"]` for larger structured data, subject to the overall result limit.
|
|
209
|
+
|
|
210
|
+
Only direct children are returned. A nested workflow appears as a child with `type: "workflow"`; call `get_workflow_job_outputs` with that child's ID to inspect its children. Missing, expired or inaccessible children return an `error` in their row, while the remaining page is still returned. Every child lookup independently checks the caller's permissions.
|
|
211
|
+
|
|
212
|
+
All three tools accept `max_bytes` from 4 through 262144 (256 KiB). The overall `max_result_bytes` limit still applies, including JSON escaping and metadata. If a response exceeds it, reduce `max_bytes` or the workflow page `limit`.
|
|
213
|
+
|
|
187
214
|
### Tickets
|
|
188
215
|
|
|
189
216
|
Create a ticket with `{"ticket":{"subject":"Backup failed","body":"Investigating the logs.","type":"issue"}}`. xyOps generates its ID, number and initial history. Ticket types and statuses follow your xyOps configuration, including custom values. This initial tool set supports text and metadata; file attachments, automatic job/alert templates and attached event definitions are not exposed.
|
|
@@ -213,12 +240,12 @@ Every bundled `.js` file in `lib/mcp/tools/` exports:
|
|
|
213
240
|
|
|
214
241
|
The registry sorts and loads files once, checks exports/names, and compiles schemas. Helpers belong outside the tools directory. Duplicate names or malformed definitions stop startup.
|
|
215
242
|
|
|
216
|
-
The context supplies `callAPI(name, params)`, `signal`, `log`, and `limits`. HTTP scopes this context to the incoming key. Tool modules must use
|
|
243
|
+
The context supplies `callAPI(name, params)`, `readJobLog(id, offset, max_bytes)`, `signal`, `log`, and `limits`. HTTP scopes this context to the incoming key. Tool modules must use these context methods so every upstream call uses the correct credentials. `readJobLog` handles bounded raw-text downloads; JSON APIs use `callAPI`. Add newly required JSON methods to the shared boundary's read/write API allowlists. Calls use the existing SDK. Cancellation prevents subsequent API calls but cannot undo requests already sent.
|
|
217
244
|
|
|
218
245
|
Both transports invoke the same modules. A tool can combine API calls, simplify inputs and select useful outputs. The runtime validates arguments and returns structured data plus JSON text. Provide pagination or field selection for large results. Keep credentials and raw transport envelopes out of outputs and diagnostics.
|
|
219
246
|
|
|
220
247
|
## Tests
|
|
221
248
|
|
|
222
|
-
`npm run test:offline` includes schema, permission-boundary and wire-level STDIO/HTTP/HTTPS checks using fixtures. The TLS key in `test/fixtures/mcp/` is a public test fixture, never a deployment credential.
|
|
249
|
+
`npm run test:offline` includes schema, permission-boundary and wire-level STDIO/HTTP/HTTPS checks using fixtures, including compressed logs, byte pagination, live tails and workflow child output. The TLS key in `test/fixtures/mcp/` is a public test fixture, never a deployment credential.
|
|
223
250
|
|
|
224
|
-
`node test.js mcp` runs the live suite against `http://localhost:5522`. It requires administrator test credentials, an enabled category, the stock Shell Plugin and a connected worker. It creates disposable events/API keys and a draft ticket, runs
|
|
251
|
+
`node test.js mcp` runs the live suite against `http://localhost:5522`. It requires administrator test credentials, an enabled category, the stock Shell Plugin and a connected worker. It creates disposable events/API keys and a draft ticket, runs harmless echo jobs including a workflow child, checks live tails and completed output, takes server/group snapshots, verifies restricted-key behavior over STDIO and concurrent HTTP requests, and cleans up its records. Monitoring tests require a worker in a group with a saved monitoring sample. The ticket remains a draft to suppress notifications; the suite deletes only snapshots it created and verifies their removal.
|
package/lib/mcp/context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Shared SDK boundary. No terminal formatting, cached records, or global args.
|
|
2
|
-
const READ_APIS = new Set(['get_events', 'get_event', 'get_categories', 'get_groups', 'get_plugins', 'get_plugin', 'get_job', 'search_jobs', 'search_alerts', 'search_snapshots', 'get_active_servers']);
|
|
2
|
+
const READ_APIS = new Set(['get_events', 'get_event', 'get_categories', 'get_groups', 'get_plugins', 'get_plugin', 'get_job', 'search_jobs', 'search_alerts', 'search_snapshots', 'get_active_servers', 'tail_live_job_log']);
|
|
3
3
|
const WRITE_APIS = new Set(['create_event', 'update_event', 'delete_event', 'run_event', 'create_ticket', 'update_ticket', 'delete_ticket', 'add_ticket_change', 'create_snapshot', 'create_group_snapshot']);
|
|
4
4
|
|
|
5
5
|
function checkKeys(value) {
|
|
@@ -18,6 +18,15 @@ function createContext(api, options = {}) {
|
|
|
18
18
|
|
|
19
19
|
return {
|
|
20
20
|
limits, log, redact, readOnly: !!options.read_only,
|
|
21
|
+
async readJobLog(id, offset, bytes, signal) {
|
|
22
|
+
// Raw log downloads need a bounded Writable rather than the JSON API
|
|
23
|
+
// path. Keep credentials scoped here just like every other API call.
|
|
24
|
+
if (signal?.aborted) throw new Error('Request cancelled before contacting xyOps.');
|
|
25
|
+
const requestOptions = { retries: 0, signal };
|
|
26
|
+
if (options.api_key) requestOptions.headers = { 'X-API-Key': options.api_key };
|
|
27
|
+
try { return await require('./job-output.js').download(api, id, offset, bytes, requestOptions); }
|
|
28
|
+
catch (err) { throw new Error(redact(err.message || err)); }
|
|
29
|
+
},
|
|
21
30
|
withApiKey(api_key) {
|
|
22
31
|
// HTTP requests get their own immutable credential scope, including
|
|
23
32
|
// error redaction. Never change environment variables or SDK defaults.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Shared output bounds. Keep log transport details outside the tool catalog.
|
|
2
|
+
const { Writable } = require('node:stream');
|
|
3
|
+
|
|
4
|
+
const maxBytes = { type: 'integer', minimum: 4, maximum: 262144, default: 32768, description: 'Maximum UTF-8 bytes of text to return (4 - 262144).' };
|
|
5
|
+
const offset = { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER - 262145, default: 0, description: 'Byte offset in the uncompressed log. Use next_offset from the previous response.' };
|
|
6
|
+
|
|
7
|
+
function prefix(buffer, bytes) {
|
|
8
|
+
// Leave a partial UTF-8 character for the next page rather than replacing it.
|
|
9
|
+
let end = Math.min(buffer.length, bytes);
|
|
10
|
+
if (end < buffer.length) {
|
|
11
|
+
let lead = end;
|
|
12
|
+
while (lead > 0 && (buffer[lead] & 0xc0) === 0x80) lead--;
|
|
13
|
+
const value = buffer[lead];
|
|
14
|
+
const width = value >= 0xc2 && value <= 0xdf ? 2 : (value >= 0xe0 && value <= 0xef ? 3 : (value >= 0xf0 && value <= 0xf4 ? 4 : 0));
|
|
15
|
+
if (lead < end && width && lead + width > end) end = lead;
|
|
16
|
+
}
|
|
17
|
+
return buffer.subarray(0, end);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function textOutput(text, bytes) {
|
|
21
|
+
const buffer = Buffer.from(text || '', 'utf8');
|
|
22
|
+
const output = prefix(buffer, bytes);
|
|
23
|
+
return { text: output.toString('utf8'), truncated: buffer.length > output.length };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function download(api, id, start, bytes, options) {
|
|
27
|
+
const chunks = [];
|
|
28
|
+
let received = 0;
|
|
29
|
+
let clipped = false;
|
|
30
|
+
let status;
|
|
31
|
+
|
|
32
|
+
// The SDK decompresses archived logs before writing here. Retain only the
|
|
33
|
+
// requested range plus one lookahead byte, even for very large log files.
|
|
34
|
+
const sink = new Writable({ write(chunk, encoding, callback) {
|
|
35
|
+
const end = Math.min(chunk.length, start + bytes + 1 - received);
|
|
36
|
+
const begin = Math.max(0, start - received);
|
|
37
|
+
if (end > begin) chunks.push(Buffer.from(chunk.subarray(begin, end)));
|
|
38
|
+
received += chunk.length;
|
|
39
|
+
|
|
40
|
+
// Stop downloading as soon as we can prove another page exists. Only a
|
|
41
|
+
// successful HTTP response may turn this deliberate stop into a result.
|
|
42
|
+
// A Writable error lets the SDK clean up its socket and request timers.
|
|
43
|
+
if (received > start + bytes) {
|
|
44
|
+
clipped = true;
|
|
45
|
+
return callback(new Error('MCP log range complete.'));
|
|
46
|
+
}
|
|
47
|
+
callback();
|
|
48
|
+
} });
|
|
49
|
+
sink.on('error', () => {});
|
|
50
|
+
|
|
51
|
+
// Cancel through the Writable error path as well, so the request library
|
|
52
|
+
// releases its download socket and timers. Wait until the SDK attaches the
|
|
53
|
+
// source pipe before destroying the sink, including for an empty response.
|
|
54
|
+
const { signal, ...requestOptions } = options;
|
|
55
|
+
let piped = false;
|
|
56
|
+
const cancel = () => { if (piped) sink.destroy(new Error('Request cancelled while reading the job log.')); };
|
|
57
|
+
sink.once('pipe', () => {
|
|
58
|
+
piped = true;
|
|
59
|
+
if (signal?.aborted) cancel();
|
|
60
|
+
});
|
|
61
|
+
signal?.addEventListener('abort', cancel, { once: true });
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const response = await api.get_job_log({ id }, {
|
|
65
|
+
...requestOptions, download: sink,
|
|
66
|
+
progress(chunk, response) { status = response.statusCode; }
|
|
67
|
+
});
|
|
68
|
+
if (options.signal?.aborted) throw new Error('Request cancelled while reading the job log.');
|
|
69
|
+
if (response?.err && !(clipped && status >= 200 && status < 300)) throw new Error(String(response.err));
|
|
70
|
+
if (!response || (!response.err && !response.resp)) throw new Error('Invalid xyOps log response.');
|
|
71
|
+
|
|
72
|
+
const buffer = Buffer.concat(chunks);
|
|
73
|
+
const output = prefix(buffer, bytes);
|
|
74
|
+
|
|
75
|
+
// Offsets count source bytes, even when invalid UTF-8 is displayed using
|
|
76
|
+
// replacement characters that take a different number of encoded bytes.
|
|
77
|
+
return { id, text: output.toString('utf8'), offset: start, next_offset: start + output.length, truncated: clipped };
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
// The request library does not own caller-supplied Writable streams.
|
|
81
|
+
signal?.removeEventListener('abort', cancel);
|
|
82
|
+
sink.destroy();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = { maxBytes, offset, prefix, textOutput, download };
|
package/lib/mcp/server.js
CHANGED
|
@@ -23,6 +23,7 @@ module.exports = function serverFactory(tools, context) {
|
|
|
23
23
|
checkKeys(args);
|
|
24
24
|
const invocation = { ...scoped, signal: request.mcpReq.signal };
|
|
25
25
|
invocation.callAPI = (name, params) => scoped.callAPI(name, params, invocation.signal);
|
|
26
|
+
invocation.readJobLog = (id, offset, bytes) => scoped.readJobLog(id, offset, bytes, invocation.signal);
|
|
26
27
|
return result(await tool.run(args, invocation), scoped.limits.max_result_bytes);
|
|
27
28
|
}
|
|
28
29
|
catch (err) { return failure(err, scoped.redact); }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const S = require('../schemas.js');
|
|
2
|
+
const O = require('../job-output.js');
|
|
3
|
+
|
|
4
|
+
exports.describe = () => S.describe('get_job_log', 'Read a completed job console log, including archived logs. Returns bounded text and a byte next_offset. Repeat with that offset while truncated is true. Uses API-key permissions; no download tokens are returned.', {
|
|
5
|
+
id: S.id, offset: O.offset, max_bytes: O.maxBytes
|
|
6
|
+
}, ['id']);
|
|
7
|
+
|
|
8
|
+
exports.run = async function(args, context) {
|
|
9
|
+
return context.readJobLog(args.id, args.offset ?? 0, args.max_bytes ?? 32768);
|
|
10
|
+
};
|
package/lib/mcp/tools/get-job.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const S = require('../schemas.js');
|
|
2
2
|
|
|
3
|
-
exports.describe = () => S.describe('get_job', 'Inspect a running or completed job. Returns status, completion details and output
|
|
3
|
+
exports.describe = () => S.describe('get_job', 'Inspect a running or completed job. Returns status, completion details, output data and inline console output. Use get_job_log for completed archived logs, tail_job_log for live console text, and get_workflow_job_outputs for child results. Optional fields selects additional job properties. Download tokens are not returned.', { id: S.id, fields: S.strings }, ['id']);
|
|
4
4
|
|
|
5
5
|
exports.run = async function(args, context) {
|
|
6
6
|
const { job } = await context.callAPI('get_job', { id: args.id });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const S = require('../schemas.js');
|
|
2
|
+
const O = require('../job-output.js');
|
|
3
|
+
|
|
4
|
+
exports.describe = () => S.describe('get_workflow_job_outputs', 'Inspect direct child jobs of a completed workflow. Returns paginated results, bounded console output and output data. Nested workflows are returned as children; call this tool with their IDs to descend. Each child is read with the caller\'s permissions. Use get_job_log for full child logs.', {
|
|
5
|
+
id: S.id, ...S.pagination,
|
|
6
|
+
max_bytes: { ...O.maxBytes, default: 8192, description: 'Maximum UTF-8 bytes per child console output and per child serialized output data. Defaults to 8192.' }
|
|
7
|
+
}, ['id']);
|
|
8
|
+
|
|
9
|
+
exports.run = async function(args, context) {
|
|
10
|
+
const { job } = await context.callAPI('get_job', { id: args.id });
|
|
11
|
+
if (job.type !== 'workflow' || !job.workflow?.jobs) throw new Error('Job is not a workflow with child job records.');
|
|
12
|
+
if (!job.final) throw new Error('Workflow is still running. Use get_job to inspect its current state.');
|
|
13
|
+
|
|
14
|
+
// Sort by node and attempt order so pagination stays stable after completion.
|
|
15
|
+
// Keep repeated executions of a node, including retries and multiplexed jobs.
|
|
16
|
+
const children = Object.keys(job.workflow.jobs).sort().flatMap(node => job.workflow.jobs[node].map(stub => ({ node, id: stub.id })));
|
|
17
|
+
const { offset, limit } = S.page(args, context);
|
|
18
|
+
const bytes = args.max_bytes ?? 8192;
|
|
19
|
+
const rows = [];
|
|
20
|
+
for (const child of children.slice(offset, offset + limit)) {
|
|
21
|
+
let subJob;
|
|
22
|
+
try { subJob = (await context.callAPI('get_job', { id: child.id })).job; }
|
|
23
|
+
catch (err) {
|
|
24
|
+
// Missing, expired or inaccessible children should not hide the rest
|
|
25
|
+
// of the page. Never swallow cancellation and continue fetching jobs.
|
|
26
|
+
if (context.signal?.aborted) throw err;
|
|
27
|
+
rows.push({ ...child, error: err.message });
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const row = { ...S.pick(subJob, ['id', 'title', 'type', 'state', 'final', 'code', 'description', 'started', 'completed', 'elapsed', 'log_file_size']), node: child.node };
|
|
32
|
+
const output = O.textOutput(subJob.output, bytes);
|
|
33
|
+
row.output = output.text;
|
|
34
|
+
row.output_truncated = output.truncated;
|
|
35
|
+
// Large archived logs are not inline. Make their availability explicit
|
|
36
|
+
// without downloading every log or returning shareable token URLs.
|
|
37
|
+
row.log_available = !!(subJob.output || subJob.log_file_size);
|
|
38
|
+
row.log_inline = typeof subJob.output === 'string';
|
|
39
|
+
if (subJob.data !== undefined) {
|
|
40
|
+
const data = O.textOutput(JSON.stringify(subJob.data), bytes);
|
|
41
|
+
row.data_truncated = data.truncated;
|
|
42
|
+
if (data.truncated) row.data_preview = data.text;
|
|
43
|
+
else row.data = subJob.data;
|
|
44
|
+
}
|
|
45
|
+
rows.push(row);
|
|
46
|
+
}
|
|
47
|
+
return { id: args.id, rows, total: children.length, offset, limit, next_offset: offset + rows.length };
|
|
48
|
+
};
|
|
@@ -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.6",
|
|
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 ? 11 : 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, 11);
|
|
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,7 @@ 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(), ['get_event', 'get_event_options', 'get_job', 'list_events', 'list_servers', 'search_alerts', 'search_jobs', 'search_snapshots']);
|
|
294
|
+
assert.deepEqual(listing.result.tools.map(tool => tool.name).sort(), ['get_event', 'get_event_options', 'get_job', 'get_job_log', 'get_workflow_job_outputs', 'list_events', 'list_servers', 'search_alerts', 'search_jobs', 'search_snapshots', 'tail_job_log']);
|
|
295
295
|
for (const tool of tools.values()) {
|
|
296
296
|
if (tool.description.annotations.readOnlyHint) continue;
|
|
297
297
|
const reply = await httpRPC(readonlyURL, 'tools/call', { name: tool.description.name, arguments: {} }, { headers });
|
|
@@ -299,3 +299,43 @@ test('new HTTP mutations use each client key and read-only mode rejects every wr
|
|
|
299
299
|
}
|
|
300
300
|
assert.equal(forbiddenCalls, 0);
|
|
301
301
|
});
|
|
302
|
+
|
|
303
|
+
test('HTTP job output tools scope raw downloads and every child lookup to the caller key', async t => {
|
|
304
|
+
const calls = [];
|
|
305
|
+
const context = createContext({
|
|
306
|
+
get_job_log: async (params, options) => {
|
|
307
|
+
const key = options.headers['X-API-Key'];
|
|
308
|
+
calls.push({ method: 'log', id: params.id, key });
|
|
309
|
+
assert.equal(options.retries, 0);
|
|
310
|
+
if (key === 'denied-key') return { err: 'Permission denied denied-key' };
|
|
311
|
+
await new Promise(resolve => setTimeout(resolve, key === 'slow-key' ? 20 : 1));
|
|
312
|
+
options.download.end('Log for ' + key);
|
|
313
|
+
return { resp: { statusCode: 200 } };
|
|
314
|
+
},
|
|
315
|
+
get_job: async (params, options) => {
|
|
316
|
+
const key = options.headers['X-API-Key'];
|
|
317
|
+
calls.push({ method: 'job', id: params.id, key });
|
|
318
|
+
return { data: { code: 0, token: 'private-token', job: params.id === 'parent' ? {
|
|
319
|
+
id: 'parent', type: 'workflow', final: true, workflow: { jobs: { node: [{ id: 'child' }] } }
|
|
320
|
+
} : { id: params.id, final: true, output: key } } };
|
|
321
|
+
}
|
|
322
|
+
}, { api_key: 'server-key', read_only: true });
|
|
323
|
+
const service = await start(factory(tools, context), { ...configuration({}, {}), port: 0, log() {} });
|
|
324
|
+
t.after(() => service.close());
|
|
325
|
+
const url = 'http://127.0.0.1:' + service.address.port + '/mcp';
|
|
326
|
+
const replies = await Promise.all(['slow-key', 'fast-key', 'denied-key'].map(key => httpRPC(url, 'tools/call', {
|
|
327
|
+
name: 'get_job_log', arguments: { id: 'log' }
|
|
328
|
+
}, { modern: true, headers: { Authorization: 'Bearer ' + key } })));
|
|
329
|
+
assert.equal(replies[0].result.structuredContent.text, 'Log for slow-key');
|
|
330
|
+
assert.equal(replies[1].result.structuredContent.text, 'Log for fast-key');
|
|
331
|
+
assert.equal(replies[2].result.isError, true);
|
|
332
|
+
assert.doesNotMatch(JSON.stringify(replies[2]), /denied-key|server-key/);
|
|
333
|
+
const workflow = await httpRPC(url, 'tools/call', { name: 'get_workflow_job_outputs', arguments: { id: 'parent' } }, {
|
|
334
|
+
headers: { Authorization: 'Bearer reader-key' }
|
|
335
|
+
});
|
|
336
|
+
assert.equal(workflow.result.structuredContent.rows[0].output, 'reader-key');
|
|
337
|
+
assert.doesNotMatch(JSON.stringify(workflow), /private-token|server-key/);
|
|
338
|
+
assert.deepEqual(calls.slice(-2), [
|
|
339
|
+
{ method: 'job', id: 'parent', key: 'reader-key' }, { method: 'job', id: 'child', key: 'reader-key' }
|
|
340
|
+
]);
|
|
341
|
+
});
|
|
@@ -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, 11);
|
|
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, 11);
|
|
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, 20);
|
|
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,104 @@ 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('job output tools use real SDK downloads, gzip, byte pages and read-only STDIO', async t => {
|
|
216
|
+
const { gzipSync } = require('node:zlib');
|
|
217
|
+
const text = 'abc😀é\n' + 'Archived output\n'.repeat(10000);
|
|
218
|
+
const requests = [];
|
|
219
|
+
const backend = http.createServer((request, response) => {
|
|
220
|
+
const url = new URL(request.url, 'http://fixture');
|
|
221
|
+
const name = url.pathname.split('/')[3];
|
|
222
|
+
const id = url.searchParams.get('id');
|
|
223
|
+
requests.push({ name, id });
|
|
224
|
+
assert.equal(request.headers['x-api-key'], 'fixture-key');
|
|
225
|
+
if (name === 'get_job_log') {
|
|
226
|
+
if (id === 'empty') { response.writeHead(204); response.end(); return; }
|
|
227
|
+
if (id === 'denied') { response.writeHead(403); response.end('Permission denied '.repeat(100)); return; }
|
|
228
|
+
response.setHeader('Content-Type', 'text/plain');
|
|
229
|
+
if (id === 'plain') { response.end('plain output'); return; }
|
|
230
|
+
response.setHeader('Content-Encoding', 'gzip');
|
|
231
|
+
response.end(id === 'broken' ? 'not gzip' : gzipSync(text));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
response.setHeader('Content-Type', 'application/json');
|
|
235
|
+
if (name === 'tail_live_job_log') {
|
|
236
|
+
// This API accepts POST JSON. Collect the body to check the SDK route.
|
|
237
|
+
let body = '';
|
|
238
|
+
request.on('data', chunk => { body += chunk; });
|
|
239
|
+
request.on('end', () => {
|
|
240
|
+
assert.deepEqual(JSON.parse(body), { id: 'running', bytes: 32768 });
|
|
241
|
+
response.end(JSON.stringify({ code: 0, text: 'live output' }));
|
|
242
|
+
});
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const job = id === 'parent' ? { id, type: 'workflow', final: true, workflow: { jobs: { node: [{ id: 'child' }] } } } : { id, final: id !== 'running', output: 'child output', data: { answer: 42 } };
|
|
246
|
+
response.end(JSON.stringify({ code: 0, token: 'private-token', job }));
|
|
247
|
+
});
|
|
248
|
+
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
249
|
+
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
250
|
+
const client = stdioClient(t, {
|
|
251
|
+
XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_MCP: '{}'
|
|
252
|
+
}, ['mcp', 'stdio', '--read-only']);
|
|
253
|
+
await client.initialize();
|
|
254
|
+
async function invoke(name, args) {
|
|
255
|
+
const reply = await client.call(name, args);
|
|
256
|
+
assert.ok(reply.result && !reply.result.isError, JSON.stringify(reply));
|
|
257
|
+
return reply.result.structuredContent;
|
|
258
|
+
}
|
|
259
|
+
const first = await invoke('get_job_log', { id: 'archive', max_bytes: 4 });
|
|
260
|
+
assert.deepEqual(first, { id: 'archive', text: 'abc', offset: 0, next_offset: 3, truncated: true });
|
|
261
|
+
const second = await invoke('get_job_log', { id: 'archive', offset: first.next_offset, max_bytes: 4 });
|
|
262
|
+
assert.equal(second.text, '😀');
|
|
263
|
+
assert.equal(second.next_offset, 7);
|
|
264
|
+
const complete = await invoke('get_job_log', { id: 'archive', max_bytes: 262144 });
|
|
265
|
+
assert.equal(complete.text, text);
|
|
266
|
+
assert.equal(complete.truncated, false);
|
|
267
|
+
assert.equal(complete.next_offset, Buffer.byteLength(text));
|
|
268
|
+
assert.equal((await invoke('get_job_log', { id: 'archive', offset: complete.next_offset })).text, '');
|
|
269
|
+
assert.equal((await invoke('get_job_log', { id: 'plain' })).text, 'plain output');
|
|
270
|
+
assert.equal((await invoke('get_job_log', { id: 'empty' })).text, '');
|
|
271
|
+
for (const id of ['denied', 'broken']) {
|
|
272
|
+
const reply = await client.call('get_job_log', { id, max_bytes: 4 });
|
|
273
|
+
assert.equal(reply.result.isError, true, id);
|
|
274
|
+
}
|
|
275
|
+
const tail = await invoke('tail_job_log', { id: 'running' });
|
|
276
|
+
assert.equal(tail.text, 'live output');
|
|
277
|
+
assert.equal(tail.final, false);
|
|
278
|
+
const workflow = await invoke('get_workflow_job_outputs', { id: 'parent' });
|
|
279
|
+
assert.equal(workflow.rows[0].output, 'child output');
|
|
280
|
+
assert.deepEqual(workflow.rows[0].data, { answer: 42 });
|
|
281
|
+
assert.ok(!JSON.stringify(workflow).includes('private-token'));
|
|
282
|
+
assert.deepEqual(requests.slice(-2), [{ name: 'get_job', id: 'parent' }, { name: 'get_job', id: 'child' }]);
|
|
283
|
+
client.child.stdin.end();
|
|
284
|
+
assert.equal((await client.exit)[0], 0);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('cancelling a log download closes its upstream socket and permits clean shutdown', { timeout: 10000 }, async t => {
|
|
288
|
+
let started;
|
|
289
|
+
const starting = new Promise(resolve => { started = resolve; });
|
|
290
|
+
let closed;
|
|
291
|
+
const closing = new Promise(resolve => { closed = resolve; });
|
|
292
|
+
const backend = http.createServer((request, response) => {
|
|
293
|
+
response.on('close', closed);
|
|
294
|
+
response.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
295
|
+
response.write('Still downloading\n');
|
|
296
|
+
started();
|
|
297
|
+
});
|
|
298
|
+
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
299
|
+
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
300
|
+
const client = stdioClient(t, {
|
|
301
|
+
XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_MCP: '{}'
|
|
302
|
+
});
|
|
303
|
+
await client.initialize();
|
|
304
|
+
// Write a known request ID directly so cancellation targets the exact
|
|
305
|
+
// invocation without adding a pending call to the small test client.
|
|
306
|
+
client.child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id: 999, method: 'tools/call', params: {
|
|
307
|
+
name: 'get_job_log', arguments: { id: 'large' }
|
|
308
|
+
} }) + '\n');
|
|
309
|
+
await starting;
|
|
310
|
+
client.child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/cancelled', params: { requestId: 999 } }) + '\n');
|
|
311
|
+
await closing;
|
|
312
|
+
client.child.stdin.end();
|
|
313
|
+
assert.equal((await client.exit)[0], 0);
|
|
314
|
+
});
|
|
@@ -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, 20);
|
|
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
|
+
});
|
package/test/mcp.test.js
CHANGED
|
@@ -9,6 +9,7 @@ test('MCP live event/job lifecycle and API-key permissions', async t => {
|
|
|
9
9
|
const config = loadTestConfig();
|
|
10
10
|
const stamp = Date.now();
|
|
11
11
|
const eventID = 'cli_mcp_' + stamp;
|
|
12
|
+
const workflowID = eventID + '_workflow';
|
|
12
13
|
const keyID = 'cli_mcp_key_' + stamp;
|
|
13
14
|
const sdk = require('@pixlcore/xyops-sdk');
|
|
14
15
|
const jobs = new Set();
|
|
@@ -43,7 +44,7 @@ test('MCP live event/job lifecycle and API-key permissions', async t => {
|
|
|
43
44
|
const created = await invoke('create_event', { event: {
|
|
44
45
|
id: eventID, title: 'Disposable MCP Test ' + stamp, enabled: true,
|
|
45
46
|
category: category.id, plugin: 'shellplug', targets: [target], algo: 'random',
|
|
46
|
-
params: { script: 'echo XYCLI_MCP_TEST_' + stamp },
|
|
47
|
+
params: { script: 'echo XYCLI_MCP_TEST_' + stamp + '\nsleep 2\necho Completed' },
|
|
47
48
|
triggers: [{ type: 'manual', enabled: true }], actions: [], limits: []
|
|
48
49
|
} });
|
|
49
50
|
assert.equal(created.event.id, eventID);
|
|
@@ -69,11 +70,45 @@ test('MCP live event/job lifecycle and API-key permissions', async t => {
|
|
|
69
70
|
assert.ok(!launched.result.isError, 'Restricted key should be able to run the fixture');
|
|
70
71
|
const jobID = launched.result.structuredContent.id;
|
|
71
72
|
jobs.add(jobID);
|
|
73
|
+
// Poll a bounded tail until the worker emits the first marker. This
|
|
74
|
+
// verifies output while active, without holding an MCP call open.
|
|
75
|
+
let tail;
|
|
76
|
+
const tailDeadline = Date.now() + 15000;
|
|
77
|
+
do {
|
|
78
|
+
tail = await invoke('tail_job_log', { id: jobID });
|
|
79
|
+
if (tail.text.includes('XYCLI_MCP_TEST_' + stamp) || tail.final) break;
|
|
80
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
81
|
+
} while (Date.now() < tailDeadline);
|
|
82
|
+
assert.match(tail.text, new RegExp('XYCLI_MCP_TEST_' + stamp));
|
|
83
|
+
assert.equal(tail.final, false);
|
|
72
84
|
const job = await finished(jobID);
|
|
73
85
|
assert.equal(job.code, 0);
|
|
86
|
+
const log = await invoke('get_job_log', { id: jobID });
|
|
87
|
+
assert.match(log.text, new RegExp('XYCLI_MCP_TEST_' + stamp));
|
|
88
|
+
assert.match(log.text, /Completed/);
|
|
89
|
+
assert.equal(log.truncated, false);
|
|
74
90
|
const results = await invoke('search_jobs', { query: 'event:' + eventID });
|
|
75
91
|
assert.ok(results.rows.some(row => row.id === jobID));
|
|
76
92
|
|
|
93
|
+
// Run one direct workflow child and retrieve its output through the
|
|
94
|
+
// structured MCP tool, without token-authenticated download reports.
|
|
95
|
+
await invoke('create_event', { event: {
|
|
96
|
+
id: workflowID, title: 'Disposable MCP Workflow ' + stamp, enabled: true, category: category.id, type: 'workflow',
|
|
97
|
+
triggers: [{ id: 'manual', type: 'manual', enabled: true }], actions: [], limits: [],
|
|
98
|
+
workflow: {
|
|
99
|
+
nodes: [{ id: 'manual', type: 'trigger', x: 100, y: 100 }, { id: 'child', type: 'event', x: 300, y: 100, data: { event: eventID } }],
|
|
100
|
+
connections: [{ id: 'run_child', source: 'manual', dest: 'child' }]
|
|
101
|
+
}
|
|
102
|
+
} });
|
|
103
|
+
const workflowJob = await invoke('run_event', { id: workflowID });
|
|
104
|
+
jobs.add(workflowJob.id);
|
|
105
|
+
assert.equal((await finished(workflowJob.id)).code, 0);
|
|
106
|
+
const outputs = await invoke('get_workflow_job_outputs', { id: workflowJob.id });
|
|
107
|
+
assert.equal(outputs.total, 1);
|
|
108
|
+
assert.equal(outputs.rows[0].node, 'child');
|
|
109
|
+
assert.equal(outputs.rows[0].code, 0);
|
|
110
|
+
assert.match(outputs.rows[0].output, new RegExp('XYCLI_MCP_TEST_' + stamp));
|
|
111
|
+
|
|
77
112
|
// Use the HTTP transport against the same live API and compare results.
|
|
78
113
|
const context = require('../lib/mcp/context.js').createContext(sdk.api, { api_key: config.api_key });
|
|
79
114
|
const factory = require('../lib/mcp/server.js')(require('../lib/mcp/registry.js')(), context);
|
|
@@ -114,12 +149,13 @@ test('MCP live event/job lifecycle and API-key permissions', async t => {
|
|
|
114
149
|
try {
|
|
115
150
|
const { job } = await call('getJob', { id });
|
|
116
151
|
if (!job.final) { await call('abortJob', { id }); await finished(id); }
|
|
152
|
+
// Deleting a workflow also deletes its child records and logs.
|
|
117
153
|
await call('deleteJob', { id });
|
|
118
154
|
}
|
|
119
155
|
catch (err) { errors.push(err); }
|
|
120
156
|
}
|
|
121
157
|
try { await cleanupFixtures([
|
|
122
|
-
{ list: 'events', method: 'deleteEvent', match: item => item.id === eventID },
|
|
158
|
+
{ list: 'events', method: 'deleteEvent', match: item => item.id === eventID || item.id === workflowID },
|
|
123
159
|
{ list: 'api_keys', method: 'deleteApiKey', match: item => item.id === keyID }
|
|
124
160
|
]); }
|
|
125
161
|
catch (err) { errors.push(err); }
|