mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-28 09:02:12 +08:00
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
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
exports.verifyOperator = async function verifyOperator(api) {
|
||||
const ql = path.join(os.homedir(), 'bin/ql');
|
||||
const invoke = (args) => {
|
||||
const result = spawnSync(ql, args, {
|
||||
env: { ...process.env, QL_DIR: '/ql' },
|
||||
encoding: 'utf8',
|
||||
timeout: 45000,
|
||||
});
|
||||
assert.equal(result.status, 0, `${args[0]} failed: ${result.stderr}`);
|
||||
return JSON.parse(result.stdout).data;
|
||||
};
|
||||
const dir = '/ql/data/log/cli-retention';
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
await fs.writeFile(`${dir}/2000-01-01-unused.log`, 'unused');
|
||||
await fs.writeFile(`${dir}/2000-01-01-kept.log`, 'referenced');
|
||||
const task = (
|
||||
await api('crons', 'POST', {
|
||||
name: 'CLI retention reference',
|
||||
command: 'echo retention',
|
||||
schedule: '0 0 1 1 *',
|
||||
})
|
||||
).data;
|
||||
try {
|
||||
await api('crons/status', 'PUT', {
|
||||
ids: [task.id],
|
||||
status: '0',
|
||||
log_path: 'cli-retention/2000-01-01-kept.log',
|
||||
});
|
||||
const result = invoke(['rmlog', '7']);
|
||||
assert.ok(result.removed.includes('cli-retention/2000-01-01-unused.log'));
|
||||
assert.ok(result.retained.includes('cli-retention/2000-01-01-kept.log'));
|
||||
await assert.rejects(fs.access(`${dir}/2000-01-01-unused.log`));
|
||||
assert.equal(
|
||||
await fs.readFile(`${dir}/2000-01-01-kept.log`, 'utf8'),
|
||||
'referenced',
|
||||
);
|
||||
} finally {
|
||||
await api('crons', 'DELETE', [task.id]);
|
||||
}
|
||||
const service = invoke(['reload']);
|
||||
assert.ok(['pm2', 'node'].includes(service.manager));
|
||||
let ready = false;
|
||||
for (let i = 0; i < 60; i++) {
|
||||
try {
|
||||
const response = await fetch('http://127.0.0.1:5700/api/system', {
|
||||
signal: AbortSignal.timeout(500),
|
||||
});
|
||||
if ((await response.json()).code === 200) {
|
||||
ready = true;
|
||||
break;
|
||||
}
|
||||
} catch {}
|
||||
await new Promise((resolve) => setTimeout(resolve, 250));
|
||||
}
|
||||
assert.equal(ready, true, 'Panel failed to recover after reload');
|
||||
const retained = !(await fs.lstat(ql)).isSymbolicLink();
|
||||
assert.equal(
|
||||
retained,
|
||||
true,
|
||||
'Panel startup overwrote the TypeScript ql entrypoint',
|
||||
);
|
||||
return true;
|
||||
};
|
||||
Reference in New Issue
Block a user