mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
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:
1 parent
77ece406ac
commit
c5458596c8
346 files changed
+32133
-11556
No files matched your search
@@ -25,26 +25,42 @@ test('command log preserves scheduler path and rejects escaping the log director
|
||||
);
|
||||
});
|
||||
|
||||
test('managed CLI tasks and maintenance commands report against the parent receipt', async t => {
|
||||
test('managed CLI tasks and maintenance commands report against the parent receipt', async (t) => {
|
||||
const { LocalApi } = require('../../dist/internal/runtime/api');
|
||||
const { executeTask } = require('../../dist/internal/execution/taskRunner');
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-managed-cli-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
const id = 'parent-receipt-7';
|
||||
const context = createContext({ root }, {
|
||||
PATH: process.env.PATH, ID: '7', no_tee: 'true', QL_TRIGGER_ID: id,
|
||||
QL_CLI_LIFECYCLE: 'extended', QL_EXECUTION_ORIGIN: 'scheduled_system',
|
||||
});
|
||||
const context = createContext(
|
||||
{ root },
|
||||
{
|
||||
PATH: process.env.PATH,
|
||||
ID: '7',
|
||||
no_tee: 'true',
|
||||
QL_TRIGGER_ID: id,
|
||||
QL_CLI_LIFECYCLE: 'extended',
|
||||
QL_EXECUTION_ORIGIN: 'scheduled_system',
|
||||
},
|
||||
);
|
||||
await fs.mkdir(context.paths.dir_scripts, { recursive: true });
|
||||
await fs.writeFile(path.join(context.paths.dir_scripts, 'fixture.sh'), 'return 7');
|
||||
await fs.writeFile(
|
||||
path.join(context.paths.dir_scripts, 'fixture.sh'),
|
||||
'return 7',
|
||||
);
|
||||
const calls = [];
|
||||
t.mock.method(LocalApi.prototype, 'call', async (endpoint, method, body) => {
|
||||
calls.push({ endpoint, body });
|
||||
return { code: 200 };
|
||||
});
|
||||
const result = await executeTask(context, { argv: ['fixture.sh'], mode: 'now' });
|
||||
const result = await executeTask(context, {
|
||||
argv: ['fixture.sh'],
|
||||
mode: 'now',
|
||||
});
|
||||
assert.equal(result.exitCode, 7);
|
||||
assert.deepEqual(calls.map(r => r.endpoint), ['crons/status', 'crons/status', 'dashboard/record']);
|
||||
assert.deepEqual(
|
||||
calls.map((r) => r.endpoint),
|
||||
['crons/status', 'crons/status', 'dashboard/record'],
|
||||
);
|
||||
await loggedOperation(context, 'extra', async () => true);
|
||||
assert.equal(calls.length, 5);
|
||||
for (const { body } of calls) {
|
||||
@@ -55,23 +71,43 @@ test('managed CLI tasks and maintenance commands report against the parent recei
|
||||
context.env.QL_CLI_LIFECYCLE = 'legacy';
|
||||
await loggedOperation(context, 'extra', async () => true);
|
||||
assert.ok(calls.length);
|
||||
assert.ok(calls.every(r => !('trigger_id' in r.body)));
|
||||
assert.ok(calls.every((r) => !('trigger_id' in r.body)));
|
||||
});
|
||||
|
||||
test('distinct managed triggers in the same clock tick have separate maintenance and task logs', async t => {
|
||||
test('distinct managed triggers in the same clock tick have separate maintenance and task logs', async (t) => {
|
||||
const { executeTask } = require('../../dist/internal/execution/taskRunner');
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-same-tick-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
t.mock.method(Date, 'now', () => 1800000000000);
|
||||
const run = async id => {
|
||||
const context = createContext({ root }, { QL_CLI_LIFECYCLE: 'extended', QL_TRIGGER_ID: id,
|
||||
PATH: process.env.PATH, no_tee: 'true', log_name: 'shared' });
|
||||
const run = async (id) => {
|
||||
const context = createContext(
|
||||
{ root },
|
||||
{
|
||||
QL_CLI_LIFECYCLE: 'extended',
|
||||
QL_TRIGGER_ID: id,
|
||||
PATH: process.env.PATH,
|
||||
no_tee: 'true',
|
||||
log_name: 'shared',
|
||||
},
|
||||
);
|
||||
await fs.mkdir(context.paths.dir_scripts, { recursive: true });
|
||||
await fs.writeFile(path.join(context.paths.dir_scripts, id + '.sh'), 'echo ' + id);
|
||||
await fs.writeFile(
|
||||
path.join(context.paths.dir_scripts, id + '.sh'),
|
||||
'echo ' + id,
|
||||
);
|
||||
const command = await loggedOperation(context, 'extra', async () => {});
|
||||
const task = await executeTask(context, { argv: [id + '.sh'], mode: 'now' });
|
||||
return { command: command.logPath, file: task.logPath,
|
||||
content: await fs.readFile(path.join(context.paths.dir_log, task.logPath), 'utf8') };
|
||||
const task = await executeTask(context, {
|
||||
argv: [id + '.sh'],
|
||||
mode: 'now',
|
||||
});
|
||||
return {
|
||||
command: command.logPath,
|
||||
file: task.logPath,
|
||||
content: await fs.readFile(
|
||||
path.join(context.paths.dir_log, task.logPath),
|
||||
'utf8',
|
||||
),
|
||||
};
|
||||
};
|
||||
const [a, b] = await Promise.all([run('marker-alpha'), run('marker-bravo')]);
|
||||
assert.notEqual(a.command, b.command);
|
||||
@@ -82,25 +118,41 @@ test('distinct managed triggers in the same clock tick have separate maintenance
|
||||
assert.doesNotMatch(b.content, /marker-alpha/);
|
||||
});
|
||||
|
||||
test('same-tick standalone tasks and commands share a receipt only within one invocation', async t => {
|
||||
test('same-tick standalone tasks and commands share a receipt only within one invocation', async (t) => {
|
||||
const { LocalApi } = require('../../dist/internal/runtime/api');
|
||||
const { executeTask } = require('../../dist/internal/execution/taskRunner');
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-client-receipts-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
t.mock.method(Date, 'now', () => 1800000000000);
|
||||
const context = createContext({root}, {ID:'5', QL_CLI_LIFECYCLE:'extended', no_tee:'true',
|
||||
real_log_path:'shared.log', PATH:process.env.PATH});
|
||||
await fs.mkdir(context.paths.dir_scripts, {recursive:true});
|
||||
await fs.writeFile(path.join(context.paths.dir_scripts, 'receipt.sh'), 'exit 0');
|
||||
const context = createContext(
|
||||
{ root },
|
||||
{
|
||||
ID: '5',
|
||||
QL_CLI_LIFECYCLE: 'extended',
|
||||
no_tee: 'true',
|
||||
real_log_path: 'shared.log',
|
||||
PATH: process.env.PATH,
|
||||
},
|
||||
);
|
||||
await fs.mkdir(context.paths.dir_scripts, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(context.paths.dir_scripts, 'receipt.sh'),
|
||||
'exit 0',
|
||||
);
|
||||
const groups = new Map();
|
||||
t.mock.method(LocalApi.prototype, 'call', async (endpoint, method, body) => {
|
||||
const id = body.execution_id;
|
||||
assert.match(id, /^client-[0-9a-f-]{36}$/);
|
||||
groups.set(id, [...(groups.get(id) || []), body.status ?? 'stat']);
|
||||
return {code:200};
|
||||
return { code: 200 };
|
||||
});
|
||||
await Promise.all([executeTask(context, {argv:['receipt.sh'], mode:'now'}),
|
||||
executeTask(context, {argv:['receipt.sh'], mode:'now'}),
|
||||
loggedOperation(context, 'extra', async () => {})]);
|
||||
assert.deepEqual([...groups.values()].map(sequence => sequence.join(',')).sort(), ['0,1','0,1,stat','0,1,stat']);
|
||||
await Promise.all([
|
||||
executeTask(context, { argv: ['receipt.sh'], mode: 'now' }),
|
||||
executeTask(context, { argv: ['receipt.sh'], mode: 'now' }),
|
||||
loggedOperation(context, 'extra', async () => {}),
|
||||
]);
|
||||
assert.deepEqual(
|
||||
[...groups.values()].map((sequence) => sequence.join(',')).sort(),
|
||||
['0,1', '0,1,stat', '0,1,stat'],
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user