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.
This commit is contained in:
whyour committed 2026-11-22 12:24:29 +08:00
1 parent 77ece406ac
commit c5458596c8
346 files changed
+32133 -11556

No files matched your search

+43 -9
View File
@@ -11,18 +11,47 @@ test('public task entries retain no-argument script discovery and help stays rea
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-public-inventory-'));
t.after(() => fs.rm(root, { recursive: true, force: true }));
await fs.mkdir(path.join(root, 'data/scripts'), { recursive: true });
await fs.writeFile(path.join(root, 'data/scripts/job.js'), 'throw Error("do not execute"); const $ = new Env("Job");');
for (const [entry, args] of [['task', []], ['ql', ['task']]]) {
const run = (...extra) => spawnSync(process.execPath, [path.resolve(__dirname, `../../dist/${entry}.js`), ...args, ...extra, '--json'], { env: { PATH: process.env.PATH, QL_DIR: root }, encoding: 'utf8' });
await fs.writeFile(
path.join(root, 'data/scripts/job.js'),
'throw Error("do not execute"); const $ = new Env("Job");',
);
for (const [entry, args] of [
['task', []],
['ql', ['task']],
]) {
const run = (...extra) =>
spawnSync(
process.execPath,
[
path.resolve(__dirname, `../../dist/${entry}.js`),
...args,
...extra,
'--json',
],
{ env: { PATH: process.env.PATH, QL_DIR: root }, encoding: 'utf8' },
);
const listing = run();
assert.equal(listing.status, 0, listing.stderr);
assert.deepEqual(JSON.parse(listing.stdout).data.scripts, [{ file: 'job.js', name: 'Job' }]);
assert.deepEqual(JSON.parse(listing.stdout).data.scripts, [
{ file: 'job.js', name: 'Job' },
]);
assert.equal(JSON.parse(run('--help').stdout).data.scripts, undefined);
}
});
test('removed development publication is rejected before doing any work', () => {
const result = spawnSync(process.execPath, [path.resolve(__dirname, '../../dist/ql.js'), 'dev', 'release', '--root', '/absent', '--json'], { encoding: 'utf8' });
const result = spawnSync(
process.execPath,
[
path.resolve(__dirname, '../../dist/ql.js'),
'dev',
'release',
'--root',
'/absent',
'--json',
],
{ encoding: 'utf8' },
);
assert.equal(result.status, 2);
assert.equal(result.stdout, '');
assert.equal(JSON.parse(result.stderr).code, 2);
@@ -39,13 +68,18 @@ test('health probes use the base path and reject failed or malformed scheduler h
} else if (req.url === '/ql/') res.end('<div id="root"></div>');
else res.end('{"code":200,"data":{"version":"2.21.0"}}');
});
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
t.after(() => new Promise(resolve => server.close(resolve)));
const context = { env: { QlPort: String(server.address().port), QlBaseUrl: '/ql/' } };
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
t.after(() => new Promise((resolve) => server.close(resolve)));
const context = {
env: { QlPort: String(server.address().port), QlBaseUrl: '/ql/' },
};
assert.equal((await inspectPanel(context)).backend.healthy, false);
health = { status: 200, body: { code: 200, data: {} } };
assert.equal((await inspectPanel(context)).backend.healthy, false);
health = { status: 200, body: { code: 200, data: { status: 'ok' } } };
assert.equal((await inspectPanel(context)).backend.healthy, true);
assert.equal(seen.some(route => route.includes('/api/system')), false);
assert.equal(
seen.some((route) => route.includes('/api/system')),
false,
);
});