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

+74 -30
View File
@@ -54,7 +54,8 @@ for (const [label, args] of [
f.write(`shell/${name}`, source(`shell/${name}`));
f.write(
'shell/api.sh',
extract('shell/api.sh', 'init_execution_id') + '\nupdate_cron(){ :; }; record_cron_stat(){ :; }\n',
extract('shell/api.sh', 'init_execution_id') +
'\nupdate_cron(){ :; }; record_cron_stat(){ :; }\n',
);
f.write('shell/preload/env.sh', 'export QA_PANEL="one&two"\n');
f.write('shell/preload/sitecustomize.js', '// fixture preloader\n');
@@ -557,46 +558,89 @@ for (const version of ['2.23.0', '2.23.0-beta.1+build.2', 'invalid']) {
});
}
test('ql extra propagates a sourced script failure through every logging mode', t => {
test('ql extra propagates a sourced script failure through every logging mode', (t) => {
const f = fixture(t);
f.write('shell/update.sh', source('shell/update.sh'));
f.write('shell/env.sh', '');
f.write('shell/share.sh', [
'load_ql_envs() { :; }; import_config() { :; }; make_dir() { mkdir -p "$1"; }',
't() { :; }; format_timestamp() { echo 1; }; format_time() { echo now; }',
].join('\n'));
f.write('shell/api.sh', [
extract('shell/api.sh', 'init_execution_id'),
'update_cron() { echo "status:$2:${7:-}" >> "$QL_DIR/records"; }',
'record_cron_stat() { echo "stat:$2" >> "$QL_DIR/records"; }',
].join('\n'));
for (const [real_time, no_tee] of [['false','false'], ['false','true'], ['true','false']]) {
for (const [script, code] of [['return 17', 17], ['exit 17', 17], ['return 0', 0],
['false | true', 0], ['set -o pipefail; false | true', 1]]) {
f.write(
'shell/share.sh',
[
'load_ql_envs() { :; }; import_config() { :; }; make_dir() { mkdir -p "$1"; }',
't() { :; }; format_timestamp() { echo 1; }; format_time() { echo now; }',
].join('\n'),
);
f.write(
'shell/api.sh',
[
extract('shell/api.sh', 'init_execution_id'),
'update_cron() { echo "status:$2:${7:-}" >> "$QL_DIR/records"; }',
'record_cron_stat() { echo "stat:$2" >> "$QL_DIR/records"; }',
].join('\n'),
);
for (const [real_time, no_tee] of [
['false', 'false'],
['false', 'true'],
['true', 'false'],
]) {
for (const [script, code] of [
['return 17', 17],
['exit 17', 17],
['return 0', 0],
['false | true', 0],
['set -o pipefail; false | true', 1],
]) {
f.write('records', '');
const result = f.run('exec "$QA_BASH" "$QL_DIR/shell/update.sh" extra', {
QA_BASH: bash, QL_DIR: f.root, ID: '42', real_time, no_tee,
dir_log: path.join(f.root, 'log'), file_extra_shell: f.write('extra.sh', script),
QA_BASH: bash,
QL_DIR: f.root,
ID: '42',
real_time,
no_tee,
dir_log: path.join(f.root, 'log'),
file_extra_shell: f.write('extra.sh', script),
});
assert.equal(result.status, code, result.stderr);
assert.equal(fs.readFileSync(path.join(f.root, 'records'), 'utf8'),
`status:0:\nstatus:1:${code}\nstat:${code}\n`);
assert.equal(
fs.readFileSync(path.join(f.root, 'records'), 'utf8'),
`status:0:\nstatus:1:${code}\nstat:${code}\n`,
);
}
}
});
test('raw sync recognizes the exact quoted operand in a wrapped crontab across repeated downloads', t => {
const f = fixture(t), file = "raw_owner_what's new.js";
test('raw sync recognizes the exact quoted operand in a wrapped crontab across repeated downloads', (t) => {
const f = fixture(t),
file = "raw_owner_what's new.js";
const { shellQuote } = require('../../back/shared/shellQuote');
f.write('raw/.keep', ''); f.write('scripts/.keep', '');
f.write('crontab.list', '1 * * * * ID=7 QL_TRIGGER_SOURCE=system bash "$QL_DIR/shell/system-cron.sh" ' +
shellQuote('QL_CRON_REVISION=10 real_time=false ID=7 task ' + shellQuote(file)) + '\n');
const result = f.run([extract('shell/update.sh', 'update_raw'), 't(){ :; }; set_proxy(){ :; }; unset_proxy(){ :; }',
'wget(){ printf "body" > "$4"; }; add_cron(){ exit 55; }',
'update_raw https://fixture.invalid/script.js "" true false'].join('\n'), {
dir_shell: path.resolve('shell'), dir_raw: path.join(f.root, 'raw'), dir_scripts: path.join(f.root, 'scripts'),
list_crontab_user: path.join(f.root, 'crontab.list'), cmd_task: 'task', uniq_path: "owner_what's new",
});
f.write('raw/.keep', '');
f.write('scripts/.keep', '');
f.write(
'crontab.list',
'1 * * * * ID=7 QL_TRIGGER_SOURCE=system bash "$QL_DIR/shell/system-cron.sh" ' +
shellQuote(
'QL_CRON_REVISION=10 real_time=false ID=7 task ' + shellQuote(file),
) +
'\n',
);
const result = f.run(
[
extract('shell/update.sh', 'update_raw'),
't(){ :; }; set_proxy(){ :; }; unset_proxy(){ :; }',
'wget(){ printf "body" > "$4"; }; add_cron(){ exit 55; }',
'update_raw https://fixture.invalid/script.js "" true false',
].join('\n'),
{
dir_shell: path.resolve('shell'),
dir_raw: path.join(f.root, 'raw'),
dir_scripts: path.join(f.root, 'scripts'),
list_crontab_user: path.join(f.root, 'crontab.list'),
cmd_task: 'task',
uniq_path: "owner_what's new",
},
);
assert.equal(result.status, 0, result.stderr);
assert.equal(fs.readFileSync(path.join(f.root, 'scripts', file), 'utf8'), 'body');
assert.equal(
fs.readFileSync(path.join(f.root, 'scripts', file), 'utf8'),
'body',
);
});