You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
3.0 KiB
JavaScript
43 lines
3.0 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
|
|
const source = await readFile(new URL('../public/cloud/admin.js', import.meta.url), 'utf8');
|
|
globalThis.location = { href: 'https://panel.test/admin/cloud', origin: 'https://panel.test' };
|
|
const { taskUrl } = await import('../public/cloud/task-observer.js');
|
|
|
|
// Only endpoints that are defined as asynchronous task mutations use this
|
|
// strict helper. Existing synchronous and hybrid endpoints continue through
|
|
// api(), so their 200 responses remain valid.
|
|
assert.match(source, /async function acceptedTask\(path, options = \{\}\)/);
|
|
assert.match(source, /status !== 202 \|\| !taskUrl\(payload\)/);
|
|
assert.match(source, /import \{ announceTaskAccepted, observeTask, taskUrl \}/);
|
|
assert.equal(taskUrl({ task_id: 42, status_url: '/api/v1/tasks/42' }), '/api/v1/tasks/42');
|
|
assert.equal(taskUrl({ task_id: 42, status_url: '/api/v1/tasks/42', status: 'active' }), '');
|
|
assert.equal(taskUrl({ task_id: 42, status_url: 'https://other.test/api/v1/tasks/42' }), '');
|
|
const generalApi = source.slice(source.indexOf('async function api('), source.indexOf('async function acceptedTask('));
|
|
assert.doesNotMatch(generalApi, /status !== 202/,
|
|
'The general API helper must not reject synchronous 200 or hybrid 200/202 endpoints.');
|
|
|
|
const storage = source.slice(source.indexOf('async function saveHostStorage'), source.indexOf('function schedulerLabel'));
|
|
const storageObserver = source.slice(source.indexOf('function refreshHostStorageAfterTask'), source.indexOf('function storageBody'));
|
|
assert.match(storage, /acceptedTask\(`\/api\/v1\/admin\/hosts\/\$\{encodeURIComponent\(hostId\)\}\/storage-configuration`/);
|
|
assert.match(storage, /announceTaskAccepted\(receipt/);
|
|
assert.match(storage, /observeHostStorageTask\(receipt, hostId\)/);
|
|
assert.match(storageObserver, /observeTask\(receipt/);
|
|
assert.match(storageObserver, /task\.status === 'succeeded'/);
|
|
assert.match(storageObserver, /api\(`\/api\/v1\/admin\/hosts\/\$\{encodeURIComponent\(hostId\)\}\/storage-configuration`\)/);
|
|
assert.match(storageObserver, /renderHostStorage\(payload\)/);
|
|
assert.match(storageObserver, /task\.effect_may_have_applied === true/);
|
|
assert.match(storageObserver, /payload\.state === 'failed' && payload\.can_submit === true/);
|
|
assert.match(storageObserver, /旧任务已终止且不会重放/);
|
|
assert.doesNotMatch(storageObserver, /task\.safe_to_resubmit/);
|
|
assert.doesNotMatch(storage + storageObserver, /setInterval\(/);
|
|
|
|
const catalog = source.slice(source.indexOf('async function loadCatalog'), source.indexOf('function taskFailureMessage'));
|
|
assert.match(catalog, /acceptedTask\(`\$\{catalogPath\(\)\}\/\$\{encodeURIComponent\(entry\.id\)\}`/);
|
|
assert.match(catalog, /importProgress\(receipt, '同步镜像名称'/);
|
|
assert.match(catalog, /await loadCatalog\(\);\s*notice\('名称已保存。'\);/);
|
|
assert.doesNotMatch(catalog, /await api\([^;]+method: 'PATCH'[\s\S]*?await loadCatalog\(\);\s*notice\('名称已保存。'\);/);
|
|
|
|
console.log('Admin strict 202 task receipt, bounded observation and terminal refresh behavior passed.');
|