fix: 修复任务生命周期与调度就绪,优化执行和构建开销 (#3069)

* fix: harden task lifecycle and scheduler readiness

* fix: confine log writes to the configured log directory

* fix: verify complete build artifacts and untracked inputs

* fix: reconcile scheduler state and make stop win startup races

* fix: isolate cron generations and serialize scheduler recovery
This commit is contained in:
whyour
2026-09-13 00:32:41 +08:00
committed by GitHub
parent d62d8f3025
commit a94e665054
61 changed files with 4214 additions and 608 deletions
+53
View File
@@ -0,0 +1,53 @@
const assert = require('node:assert/strict');
const test = require('node:test');
const path = require('node:path');
const dayjs = require('dayjs');
const load = require('../helpers/load-security-module.cjs');
test('subscription becomes idle and closes its log even when completion logging fails', async () => {
const updates = [];
let closed = 0;
let notified = 0;
const Subscription = load(path.resolve('back/services/subscription.ts'), {
'../config': {},
'../data/subscription': {
SubscriptionModel: { update: async (values) => updates.push(values) },
SubscriptionStatus: { idle: 1 },
},
'../data/cron': {},
'../config/util': { handleLogPath: async () => '/tmp/unused-log' },
'../config/const': { LOG_END_SYMBOL: 'end' },
'../config/subscription': {},
'../shared/i18n': { t: (s) => s, tf: (s) => s },
'../shared/pLimit': {},
'../shared/logReader': {},
'../shared/logStreamManager': {
logStreamManager: {
write: async () => {
throw new Error('ENOSPC');
},
closeStream: async () => {
closed++;
throw new Error('ENOSPC');
},
},
},
'./schedule': {},
'./sock': {},
'./sshKey': {},
'./cron': {},
}).default;
const service = new Subscription(
{},
{},
{ sendMessage: () => notified++ },
{},
{},
);
service.getDb = async () => ({ id: 1, log_path: 'log' });
const callbacks = service.taskCallbacks({ id: 1 });
await assert.rejects(callbacks.onEnd(undefined, dayjs(), 1), /ENOSPC/);
assert.equal(closed, 1);
assert.equal(updates.at(-1).status, 1);
assert.equal(notified, 1);
});