@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/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); }