|
|
|
|
@ -4,6 +4,10 @@ import { readFile } from 'node:fs/promises';
|
|
|
|
|
globalThis.location = new URL('https://panel.example.test/user/cloud');
|
|
|
|
|
const copyFixture = {
|
|
|
|
|
'common.tasks.error.protocol': '任务状态协议无效,请联系管理员核查。',
|
|
|
|
|
'common.tasks.error.invalid_response': '任务状态服务返回了无效数据。',
|
|
|
|
|
'common.tasks.error.http': '任务状态读取失败(状态码 {status})。',
|
|
|
|
|
'common.tasks.error.execution_failed': '任务执行失败。',
|
|
|
|
|
'common.tasks.recovery.continuing': '持续自动核对',
|
|
|
|
|
'common.tasks.resolved.partial': '原任务失败;系统已确认部分宿主机已应用、部分未应用,未确认状态已收敛,资源锁已解除。',
|
|
|
|
|
'common.tasks.resolved.applied': '原任务失败,但系统已确认操作已应用,资源锁已解除。',
|
|
|
|
|
'common.tasks.resolved.not_applied': '原任务失败,但系统已确认操作未应用,资源锁已解除。',
|
|
|
|
|
@ -58,11 +62,13 @@ const protocolFailure = task => {
|
|
|
|
|
const running = normalizeTask({ id: '41', completed: false });
|
|
|
|
|
assert.equal(running.status, 'running');
|
|
|
|
|
assert.equal(running.terminal, false);
|
|
|
|
|
assert.equal(running.error, '');
|
|
|
|
|
|
|
|
|
|
for (const status of ['succeeded', 'failed']) {
|
|
|
|
|
const task = normalizeTask({ id: '41', completed: true, status });
|
|
|
|
|
assert.equal(task.status, status);
|
|
|
|
|
assert.equal(task.terminal, true);
|
|
|
|
|
assert.equal(task.error, status === 'failed' ? '任务执行失败。' : '');
|
|
|
|
|
assert.equal(taskSucceededWithoutRecovery(task), status === 'succeeded');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -88,14 +94,15 @@ const protocolFailure = task => {
|
|
|
|
|
});
|
|
|
|
|
assert.equal(failed.effect_may_have_applied, true);
|
|
|
|
|
assert.equal(failed.safe_to_resubmit, false, 'A possibly-applied task can never be resubmitted.');
|
|
|
|
|
assert.equal(failed.error, 'host result lost');
|
|
|
|
|
assert.equal(failed.error, '任务执行失败。');
|
|
|
|
|
assert.doesNotMatch(failed.error, /host result lost/);
|
|
|
|
|
assert.equal(Object.prototype.hasOwnProperty.call(failed, 'failure'), false);
|
|
|
|
|
|
|
|
|
|
const nestedOnly = normalizeTask({
|
|
|
|
|
id: '43', completed: true, status: 'failed',
|
|
|
|
|
failure: { error: 'legacy', effect_may_have_applied: true, safe_to_resubmit: true },
|
|
|
|
|
});
|
|
|
|
|
assert.equal(nestedOnly.error, '');
|
|
|
|
|
assert.equal(nestedOnly.error, '任务执行失败。');
|
|
|
|
|
assert.equal(nestedOnly.effect_may_have_applied, false);
|
|
|
|
|
assert.equal(nestedOnly.safe_to_resubmit, false);
|
|
|
|
|
|
|
|
|
|
@ -177,7 +184,7 @@ const protocolFailure = task => {
|
|
|
|
|
});
|
|
|
|
|
assert.deepEqual(recovering.recovery, {
|
|
|
|
|
pending: true,
|
|
|
|
|
message: 'Agent 回执与宿主机证据暂不一致;系统仍会继续自动核对。',
|
|
|
|
|
message: '持续自动核对',
|
|
|
|
|
last_checked_at: 1_600_000_000,
|
|
|
|
|
next_check_at: 1_600_000_030,
|
|
|
|
|
});
|
|
|
|
|
@ -198,7 +205,7 @@ const protocolFailure = task => {
|
|
|
|
|
assert.equal(taskSucceededWithoutRecovery(succeededWithInvalidLedger), false);
|
|
|
|
|
assert.equal(
|
|
|
|
|
recoveryTaskFailureNotice(succeededWithInvalidLedger),
|
|
|
|
|
succeededWithInvalidLedger.recovery.message,
|
|
|
|
|
'持续自动核对',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// A previously resolved failed task can become fenced again when its
|
|
|
|
|
@ -223,9 +230,21 @@ const protocolFailure = task => {
|
|
|
|
|
assert.equal(failedResolvedButFenced.effect_resolution, null);
|
|
|
|
|
assert.equal(failedResolvedButFenced.recovery?.pending, true);
|
|
|
|
|
assert.equal(resolvedTaskFailureNotice(failedResolvedButFenced), '');
|
|
|
|
|
assert.equal(recoveryTaskFailureNotice(failedResolvedButFenced), message);
|
|
|
|
|
assert.equal(recoveryTaskFailureNotice(failedResolvedButFenced), '持续自动核对');
|
|
|
|
|
assert.notEqual(recoveryTaskFailureNotice(failedResolvedButFenced), message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const oversizedRecovery = normalizeTask({
|
|
|
|
|
id: '55', completed: true, status: 'failed',
|
|
|
|
|
effect_may_have_applied: true, safe_to_resubmit: false,
|
|
|
|
|
recovery: {
|
|
|
|
|
pending: true, message: 'x'.repeat(401),
|
|
|
|
|
last_checked_at: 1_600_000_000, next_check_at: 1_600_000_300,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
assert.equal(oversizedRecovery.recovery, null,
|
|
|
|
|
'Catalog copy must not bypass the backend recovery-message protocol limit.');
|
|
|
|
|
|
|
|
|
|
for (const recovery of [
|
|
|
|
|
null,
|
|
|
|
|
{ pending: false, message: '伪造恢复状态' },
|
|
|
|
|
@ -282,6 +301,51 @@ const protocolFailure = task => {
|
|
|
|
|
protocolFailure(await readTask('/api/v1/tasks/1', {
|
|
|
|
|
fetchImpl: async () => response(200, { ret: 0, error: 'legacy envelope' }),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
await assert.rejects(readTask('/api/v1/tasks/1', {
|
|
|
|
|
fetchImpl: async () => response(503, {
|
|
|
|
|
error: 'raw infrastructure secret', message: 'raw backend detail',
|
|
|
|
|
}),
|
|
|
|
|
}), error => error.message === '任务状态读取失败(状态码 503)。'
|
|
|
|
|
&& !error.message.includes('raw'));
|
|
|
|
|
|
|
|
|
|
await assert.rejects(readTask('/api/v1/tasks/1', {
|
|
|
|
|
fetchImpl: async () => ({ status: 502, ok: false, json: async () => {
|
|
|
|
|
throw new SyntaxError('raw parser detail');
|
|
|
|
|
} }),
|
|
|
|
|
}), error => error.message === '任务状态服务返回了无效数据。');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The transport is shared with the Chinese-only administrator surface. Only
|
|
|
|
|
// that surface may retain the already-sanitized backend diagnostic summary;
|
|
|
|
|
// the ordinary user runtime above must always resolve catalog copy.
|
|
|
|
|
{
|
|
|
|
|
const userRuntime = globalThis.VenixUserCopy;
|
|
|
|
|
globalThis.VenixUserCopy = {};
|
|
|
|
|
try {
|
|
|
|
|
const adminTasks = await import(`${observerUrl.href}?admin=${Date.now()}`);
|
|
|
|
|
const adminFailed = adminTasks.normalizeTask({
|
|
|
|
|
id: '56', completed: true, status: 'failed', error: 'admin diagnostic',
|
|
|
|
|
});
|
|
|
|
|
assert.equal(adminFailed.error, 'admin diagnostic');
|
|
|
|
|
const adminRecovering = adminTasks.normalizeTask({
|
|
|
|
|
id: '57', completed: true, status: 'failed',
|
|
|
|
|
effect_may_have_applied: true, safe_to_resubmit: false,
|
|
|
|
|
recovery: {
|
|
|
|
|
pending: true, message: 'admin recovery diagnostic',
|
|
|
|
|
last_checked_at: 1_600_000_000, next_check_at: 1_600_000_300,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
assert.equal(adminRecovering.recovery.message, 'admin recovery diagnostic');
|
|
|
|
|
await assert.rejects(adminTasks.readTask('/api/v1/tasks/1', {
|
|
|
|
|
fetchImpl: async () => ({
|
|
|
|
|
status: 503, ok: false,
|
|
|
|
|
json: async () => ({ error: 'admin HTTP diagnostic' }),
|
|
|
|
|
}),
|
|
|
|
|
}), error => error.message === 'admin HTTP diagnostic');
|
|
|
|
|
} finally {
|
|
|
|
|
globalThis.VenixUserCopy = userRuntime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reproduce hidden -> visible before the aborted request's finally block. The
|
|
|
|
|
@ -466,6 +530,12 @@ const protocolFailure = task => {
|
|
|
|
|
assert.match(source, /common\.tasks\.details\.next_check/);
|
|
|
|
|
assert.match(source, /common\.tasks\.status\.ledger_error/);
|
|
|
|
|
assert.match(source, /common\.tasks\.details\.duration/);
|
|
|
|
|
assert.match(source, /common\.tasks\.error\.execution_failed/);
|
|
|
|
|
assert.match(source, /common\.tasks\.error\.unavailable_http/);
|
|
|
|
|
assert.match(source, /recoveryTaskFailureNotice\(task\)/);
|
|
|
|
|
assert.doesNotMatch(source, /task\.error(?!_)/);
|
|
|
|
|
assert.doesNotMatch(source, /task\.recovery\.message/);
|
|
|
|
|
assert.doesNotMatch(source, /payload\?\.(?:error|message|detail)/);
|
|
|
|
|
assert.doesNotMatch(source, /复制任务编号|copyButton|panel-task-copy/);
|
|
|
|
|
assert.doesNotMatch(source, /重试任务|重新提交任务|data-task-retry/);
|
|
|
|
|
|
|
|
|
|
@ -473,6 +543,9 @@ const protocolFailure = task => {
|
|
|
|
|
assert.match(observerSource, /common\.tasks\.resolved\.partial/);
|
|
|
|
|
assert.match(observerSource, /common\.tasks\.resolved\.applied/);
|
|
|
|
|
assert.match(observerSource, /common\.tasks\.resolved\.not_applied/);
|
|
|
|
|
assert.match(observerSource,
|
|
|
|
|
/typeof globalThis\.VenixUserCopy\?\.text === 'function'/);
|
|
|
|
|
assert.match(observerSource, /user-copy: allow admin-compatibility/);
|
|
|
|
|
assert.doesNotMatch(observerSource, /finalization_error_code/);
|
|
|
|
|
|
|
|
|
|
const appSource = await readFile(appUrl, 'utf8');
|
|
|
|
|
@ -508,9 +581,11 @@ const protocolFailure = task => {
|
|
|
|
|
{
|
|
|
|
|
const detailSource = await readFile(detailUrl, 'utf8');
|
|
|
|
|
assert.match(detailSource, /resolvedTaskFailureNotice\(task\)/);
|
|
|
|
|
assert.match(detailSource, /resolvedTaskFailureNotice\(normalizeTask\(entry\)\)/);
|
|
|
|
|
assert.match(detailSource, /recoveryTaskFailureNotice\(task\)/);
|
|
|
|
|
assert.match(detailSource, /recoveryTaskFailureNotice\(normalizeTask\(entry\)\)/);
|
|
|
|
|
assert.match(detailSource, /const normalizedTask = normalizeTask\(entry\)/);
|
|
|
|
|
assert.match(detailSource, /resolvedTaskFailureNotice\(normalizedTask\)/);
|
|
|
|
|
assert.match(detailSource, /normalizedTask\.recovery\?\.pending === true/);
|
|
|
|
|
assert.match(detailSource, /taskFailureMessage\(normalizedTask\)/);
|
|
|
|
|
assert.match(detailSource, /task\?\.recovery\?\.pending === true/);
|
|
|
|
|
assert.match(detailSource, /task\.effect_resolution === 'applied'/);
|
|
|
|
|
assert.match(detailSource, /task\.effect_resolution === 'not_applied'/);
|
|
|
|
|
const firewallReceipt = detailSource.indexOf('expectedStatus: 202', detailSource.indexOf('async function saveVmFirewall'));
|
|
|
|
|
@ -544,7 +619,9 @@ const protocolFailure = task => {
|
|
|
|
|
|
|
|
|
|
const runtimeSource = await readFile(runtimeUrl, 'utf8');
|
|
|
|
|
assert.match(runtimeSource, /resolvedTaskFailureNotice\(task\)/);
|
|
|
|
|
assert.match(runtimeSource, /recoveryTaskFailureNotice\(task\)/);
|
|
|
|
|
assert.match(runtimeSource, /function taskFailureMessage\(task/);
|
|
|
|
|
assert.match(runtimeSource,
|
|
|
|
|
/task\?\.recovery\?\.pending === true \|\| task\?\.effect_may_have_applied/);
|
|
|
|
|
assert.match(runtimeSource, /task\.effect_resolution === 'applied'/);
|
|
|
|
|
assert.match(runtimeSource, /task\.effect_resolution === 'not_applied'/);
|
|
|
|
|
assert.match(runtimeSource, /expectedStatus: 202, requireTaskReceipt: true/);
|
|
|
|
|
@ -596,7 +673,9 @@ const protocolFailure = task => {
|
|
|
|
|
/taskSucceededWithoutRecovery\(task\)/);
|
|
|
|
|
const invoiceDetailRuntimeSource = await readFile(invoiceDetailRuntimeUrl, 'utf8');
|
|
|
|
|
assert.match(invoiceDetailRuntimeSource, /taskSucceededWithoutRecovery\(task\)/);
|
|
|
|
|
assert.match(invoiceDetailRuntimeSource, /recoveryTaskFailureNotice\(task\)/);
|
|
|
|
|
assert.match(invoiceDetailRuntimeSource, /function terminalTaskProblem\(task/);
|
|
|
|
|
assert.match(invoiceDetailRuntimeSource,
|
|
|
|
|
/task\?\.recovery\?\.pending === true \|\| task\?\.effect_may_have_applied === true/);
|
|
|
|
|
assert.doesNotMatch(invoiceDetailRuntimeSource, /task\.status === 'succeeded'/);
|
|
|
|
|
|
|
|
|
|
const reinstallView = await readFile(reinstallViewUrl, 'utf8');
|
|
|
|
|
|