Files
qinglong/cli/test/linux/panel-operator.cjs
T
whyour c5458596c8 feat(cron): expose run receipts and modularize execution
Return committed trigger IDs and add CLI wait and trigger-specific logs while
preserving API, CLI, transaction, deduplication and unknown-result semantics.

Move scheduling, lifecycle, settlement, queries and legacy adapters into
back/cron; remove obsolete internal import paths and circular dependencies.

Apply project formatting across the repository, cover CJS/MJS in formatting
hooks, add prettier:check and require formatting checks in AGENTS.md.

Validation: backend build; 1398 backend/frontend tests passed (17 platform
skips); 327 CLI tests passed (6 platform skips); 670 files pass format checks.
2026-11-22 12:24:29 +08:00

82 lines
2.6 KiB
JavaScript

const assert = require('node:assert/strict');
const fs = require('node:fs/promises');
const path = require('node:path');
const os = require('node:os');
const { spawn, spawnSync } = require('node:child_process');
const { once } = require('node:events');
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;
const child = spawn('sleep', ['60']);
const ended = once(child, 'exit');
const start = Math.floor(Date.now() / 1000);
try {
await api('crons/status', 'PUT', {
ids: [task.id],
status: '0',
pid: String(child.pid),
last_execution_time: start,
log_path: 'cli-retention/2000-01-01-kept.log',
});
assert.equal(
(await api(`crons/${task.id}`)).data.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 {
child.kill();
await ended;
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;
};