Files
qinglong/cli/test/linux/panel-subscription.cjs
T
whyour 801a71d740 feat(cli): cover OpenAPI with a remote npm CLI and internal panel tools (#3074)
* feat(cli): add unified Commander CLI for QingLong 2.x

* fix(cli): publish via npm and address security review feedback

* ci(cli): package npm artifacts and remove evaluation collateral

* test(cli): use a fixed shell fixture for log retention

* refactor(cli): separate remote npm client from panel tools

* feat(cli): cover active panel OpenAPI resources

* docs(cli): unify authentication and skill guidance

* refactor(cli): isolate internal commands and generate Commander help

* refactor(cli): organize remote and internal modules by responsibility

* ci(cli): publish verified npm archives from master

* fix(cli): publish under the whyour npm scope

* ci: use npm trusted publishing for both packages

* docs: introduce the published CLI on the project homepage

* fix(cli): preserve server log truncation and correct login hints

* fix(cli): accept dashboard record request bodies

* fix(cli): preserve stdin for local task execution

* fix(cli): resolve task executables after changing directory

* fix(cli): preserve shell function tasks and sanitize test failures

* fix(cli): preserve shell hook state and resolve workdir after hooks

* fix(cli): preserve cleanup across shared shell task timeouts

* fix(cli): isolate shell control descriptors and reap timed-out descendants
2026-09-25 23:24:41 +08:00

70 lines
2.4 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs/promises');
const http = require('node:http');
exports.verifySubscription = async function verifySubscription(api, cli) {
const marker = 'CLI_SUBSCRIPTION_PANEL_MARKER';
const server = http.createServer((req, res) =>
res.end(`// cron: 0 0 1 1 *\nconsole.log('${marker}');\n`),
);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
let subscription;
let generated = [];
try {
subscription = (
await api('subscriptions', 'POST', {
name: 'CLI raw integration',
alias: 'cli-raw-integration',
type: 'file',
url: `http://127.0.0.1:${server.address().port}/fixture.js`,
schedule_type: 'crontab',
schedule: '0 0 1 1 *',
autoAddCron: true,
autoDelCron: false,
})
).data;
const id = String(subscription.id);
assert.equal(cli(['subscription', 'run', id]).data.accepted, true);
let log = '';
for (let attempt = 0; attempt < 80; attempt++) {
await new Promise((resolve) => setTimeout(resolve, 250));
log = cli(['subscription', 'logs', id]).data;
if (log.includes('"added":1')) break;
}
assert.match(log, /"added":1/, log);
assert.doesNotMatch(log, /reporting failed/);
generated = cli(['task', 'list']).data.data.filter(
(row) => row.sub_id === subscription.id,
);
assert.equal(generated.length, 1);
const task = generated[0];
assert.match(task.command, /^task raw_/);
assert.match(
await fs.readFile(`/ql/data/scripts/${task.command.slice(5)}`, 'utf8'),
new RegExp(marker),
);
cli(['task', 'run', String(task.id)]);
let taskLog = '';
for (let attempt = 0; attempt < 60; attempt++) {
await new Promise((resolve) => setTimeout(resolve, 250));
taskLog = cli(['task', 'logs', String(task.id)]).data;
if (taskLog.includes(marker) && /完成|执行结束/.test(taskLog)) break;
}
assert.match(taskLog, new RegExp(marker));
assert.match(taskLog, /完成|执行结束/);
return true;
} finally {
if (generated.length)
await api(
'crons',
'DELETE',
generated.map((row) => row.id),
);
if (subscription) await api('subscriptions', 'DELETE', [subscription.id]);
await new Promise((resolve) => {
server.close(resolve);
server.closeAllConnections();
});
}
};