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

+104 -26
View File
@@ -6,38 +6,91 @@ const ts = require('typescript');
// Exercise the real list effect while explicitly releasing each HTTP response.
function listEffect() {
const source = fs.readFileSync(path.join(__dirname, '../../src/pages/crontab/index.tsx'), 'utf8');
const ast = ts.createSourceFile('index.tsx', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
const source = fs.readFileSync(
path.join(__dirname, '../../src/pages/crontab/index.tsx'),
'utf8',
);
const ast = ts.createSourceFile(
'index.tsx',
source,
ts.ScriptTarget.Latest,
true,
ts.ScriptKind.TSX,
);
const effects = [];
function visit(node) {
if (ts.isCallExpression(node) && node.expression.getText(ast) === 'useEffect' &&
node.arguments[1]?.getText(ast).includes('searchText')) effects.push(node.arguments[0]);
if (
ts.isCallExpression(node) &&
node.expression.getText(ast) === 'useEffect' &&
node.arguments[1]?.getText(ast).includes('searchText')
)
effects.push(node.arguments[0]);
ts.forEachChild(node, visit);
}
visit(ast);
assert.equal(effects.length, 1);
const js = ts.transpile('const effect = ' + effects[0].getText(ast), {target: ts.ScriptTarget.ES2022});
const requests = [], timers = new Set(), rows = [], totals = [], failures = [];
const js = ts.transpile('const effect = ' + effects[0].getText(ast), {
target: ts.ScriptTarget.ES2022,
});
const requests = [],
timers = new Set(),
rows = [],
totals = [],
failures = [];
const bindings = {
pageConf: { page: 1, size: 20 }, viewConf: null, config: {apiPrefix: '/api/'},
request: { get(url, options) {
return new Promise((resolve, reject) => requests.push({url, options, resolve, reject}));
} }, setValue: value => rows.push(value), setTotal: value => totals.push(value),
setLoading() {}, setListFailed(failed) { failures.push(failed); },
setTimeout(fn) { timers.add(fn); return fn; }, clearTimeout(fn) { timers.delete(fn); },
pageConf: { page: 1, size: 20 },
viewConf: null,
config: { apiPrefix: '/api/' },
request: {
get(url, options) {
return new Promise((resolve, reject) =>
requests.push({ url, options, resolve, reject }),
);
},
},
setValue: (value) => rows.push(value),
setTotal: (value) => totals.push(value),
setLoading() {},
setListFailed(failed) {
failures.push(failed);
},
setTimeout(fn) {
timers.add(fn);
return fn;
},
clearTimeout(fn) {
timers.delete(fn);
},
};
return {
requests,
timers,
rows,
totals,
failures,
start(searchText) {
return Function(
'searchText',
...Object.keys(bindings),
js + '\nreturn effect();',
)(searchText, ...Object.values(bindings));
},
};
return { requests, timers, rows, totals, failures, start(searchText) {
return Function('searchText', ...Object.keys(bindings), js + '\nreturn effect();')(searchText, ...Object.values(bindings));
} };
}
const flush = () => new Promise(resolve => setImmediate(resolve));
const page = (id, sub_id) => ({code: 200, data: {data: [{id, sub_id}], total: 1}});
const flush = () => new Promise((resolve) => setImmediate(resolve));
const page = (id, sub_id) => ({
code: 200,
data: { data: [{ id, sub_id }], total: 1 },
});
test('switching searches discards stale list and subscription responses and cancels old polling', async () => {
for (const delaySubscription of [false, true]) {
const view = listEffect();
const closeA = view.start('A');
if (delaySubscription) { view.requests[0].resolve(page(1, 7)); await flush(); }
if (delaySubscription) {
view.requests[0].resolve(page(1, 7));
await flush();
}
const stale = view.requests.at(-1);
closeA();
assert.ok(stale.options.signal.aborted);
@@ -46,9 +99,14 @@ test('switching searches discards stale list and subscription responses and canc
assert.equal(fresh.options.params.searchValue, 'B&+');
fresh.resolve(page(2));
await flush();
stale.resolve(delaySubscription ? {code: 200, data: [{id: 7}]} : page(1, 7));
stale.resolve(
delaySubscription ? { code: 200, data: [{ id: 7 }] } : page(1, 7),
);
await flush();
assert.deepEqual(view.rows.map(rows => rows.map(r => r.id)), [[2]]);
assert.deepEqual(
view.rows.map((rows) => rows.map((r) => r.id)),
[[2]],
);
assert.deepEqual(view.totals, [1]);
assert.equal(view.requests.length, delaySubscription ? 3 : 2);
assert.equal(view.timers.size, 1);
@@ -75,18 +133,35 @@ test('list polling recovers on the next tick after a network failure', async ()
});
test('the next search can be submitted while the table request is in flight', () => {
const source = fs.readFileSync(path.join(__dirname, '../../src/pages/crontab/index.tsx'), 'utf8');
const ast = ts.createSourceFile('index.tsx', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
const source = fs.readFileSync(
path.join(__dirname, '../../src/pages/crontab/index.tsx'),
'utf8',
);
const ast = ts.createSourceFile(
'index.tsx',
source,
ts.ScriptTarget.Latest,
true,
ts.ScriptKind.TSX,
);
const controls = [];
function visit(node) {
if (ts.isJsxSelfClosingElement(node) && node.tagName.getText(ast) === 'Search') controls.push(node);
if (
ts.isJsxSelfClosingElement(node) &&
node.tagName.getText(ast) === 'Search'
)
controls.push(node);
ts.forEachChild(node, visit);
}
visit(ast);
assert.equal(controls.length, 1);
const attributes = controls[0].attributes.properties.map(p => p.name?.getText(ast));
const attributes = controls[0].attributes.properties.map((p) =>
p.name?.getText(ast),
);
assert.ok(attributes.includes('onSearch'));
assert.ok(!attributes.includes('loading') && !attributes.includes('disabled'));
assert.ok(
!attributes.includes('loading') && !attributes.includes('disabled'),
);
});
test('a failed subscription lookup still displays the current task list', async () => {
@@ -96,7 +171,10 @@ test('a failed subscription lookup still displays the current task list', async
await flush();
view.requests[1].reject(Error('offline'));
await flush();
assert.deepEqual(view.rows[0].map(row => row.id), [42]);
assert.deepEqual(
view.rows[0].map((row) => row.id),
[42],
);
assert.deepEqual(view.totals, [1]);
stop();
});