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.
53 lines
3.6 KiB
JavaScript
53 lines
3.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
|
|
const hostSource = await readFile(
|
|
new URL('../public/cloud/admin-hosts.js', import.meta.url), 'utf8');
|
|
const catalogSource = await readFile(
|
|
new URL('../public/cloud/admin-catalog-runtime.js', import.meta.url), 'utf8');
|
|
const requestRuntime = await readFile(
|
|
new URL('../public/cloud/admin-request-runtime.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(hostSource, /async function acceptedTask\(path, options = \{\}\)/);
|
|
assert.match(hostSource, /response: 'task'/);
|
|
assert.match(hostSource, /taskReceiptValidator: taskUrl/);
|
|
assert.match(catalogSource, /async function acceptedTask\(path, options = \{\}\)/);
|
|
assert.match(requestRuntime, /response\.status !== 202 \|\| !taskReceiptValidator/);
|
|
assert.match(hostSource, /taskSucceededWithoutRecovery, 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 = hostSource.slice(hostSource.indexOf('async function api('), hostSource.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 = hostSource.slice(hostSource.indexOf('async function saveHostStorage'), hostSource.indexOf('function schedulerLabel'));
|
|
const storageObserver = hostSource.slice(hostSource.indexOf('function refreshHostStorageAfterTask'), hostSource.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, /taskSucceededWithoutRecovery\(task\)/);
|
|
assert.doesNotMatch(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 = catalogSource.slice(catalogSource.indexOf('function bindCloudTemplateActions'), catalogSource.indexOf('function cloudTemplateVersion'));
|
|
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.');
|