feat(i18n): migrate ISO and SSH key pages
parent
1e3a0fcbe5
commit
e3bba49d7b
@ -0,0 +1,81 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const copyText = (key, parameters = {}) => `${key}:${JSON.stringify(parameters)}`;
|
||||
|
||||
{
|
||||
const source = await readFile(new URL('../public/cloud/iso-images.js', import.meta.url), 'utf8');
|
||||
const safeError = source.slice(source.indexOf('function isoMutationMayHaveApplied('),
|
||||
source.indexOf('function setImportStatus('));
|
||||
const context = vm.createContext({ t: copyText });
|
||||
vm.runInContext(`${safeError}\nglobalThis.safeIsoErrorForTest = safeIsoError;`, context);
|
||||
const display = context.safeIsoErrorForTest;
|
||||
assert.match(display(new Error('private transport detail'), 'isos.error.import', true),
|
||||
/^isos\.error\.mutation_unknown:/);
|
||||
assert.match(display({ status: 500 }, 'isos.error.delete', true),
|
||||
/^isos\.error\.mutation_unknown:/);
|
||||
assert.match(display({ status: 422 }, 'isos.error.import', true),
|
||||
/^isos\.error\.invalid_input:/);
|
||||
assert.match(display({ status: 500 }, 'isos.error.load'),
|
||||
/^isos\.error\.request:\{"status":500\}$/);
|
||||
assert.match(display({ status: 409, mutationMayHaveApplied: true },
|
||||
'isos.error.delete', true), /^isos\.error\.mutation_unknown:/);
|
||||
}
|
||||
|
||||
{
|
||||
const source = await readFile(new URL('../public/cloud/ssh-keys.js', import.meta.url), 'utf8');
|
||||
const transport = source.slice(source.indexOf('class UiCopyError'),
|
||||
source.indexOf('function normalizeKey('));
|
||||
const context = vm.createContext({
|
||||
Headers,
|
||||
location: { protocol: 'https:', hostname: 'panel.example.test', assign() {} },
|
||||
state: { csrfToken: 'fixture' },
|
||||
byId() { return null; },
|
||||
t: copyText,
|
||||
fetch: async () => { throw new Error('private network failure'); },
|
||||
});
|
||||
vm.runInContext(`${transport}\nglobalThis.apiForTest = api; globalThis.errorTextForTest = errorText;`,
|
||||
context);
|
||||
|
||||
await assert.rejects(context.apiForTest('/api/v1/ssh-keys', {
|
||||
method: 'POST', body: { name: 'fixture', public_key: 'fixture' },
|
||||
}), error => error.copyKey === 'ssh_keys.error.mutation_unknown'
|
||||
&& error.mutationMayHaveApplied === true);
|
||||
|
||||
context.fetch = async () => ({ status: 201, ok: true, async json() {
|
||||
throw new Error('invalid response');
|
||||
} });
|
||||
await assert.rejects(context.apiForTest('/api/v1/ssh-keys', {
|
||||
method: 'POST', body: { name: 'fixture', public_key: 'fixture' },
|
||||
}), error => error.copyKey === 'ssh_keys.error.mutation_unknown'
|
||||
&& error.mutationMayHaveApplied === true);
|
||||
|
||||
context.fetch = async () => ({
|
||||
status: 422, ok: false,
|
||||
async json() { return { message: 'private backend validation detail' }; },
|
||||
});
|
||||
await assert.rejects(context.apiForTest('/api/v1/ssh-keys', {
|
||||
method: 'POST', body: { name: 'fixture', public_key: 'fixture' },
|
||||
}), error => error.copyKey === 'ssh_keys.error.invalid_input'
|
||||
&& !String(error.message).includes('private backend'));
|
||||
|
||||
context.fetch = async () => ({
|
||||
status: 500, ok: false,
|
||||
async json() { return { detail: 'private backend exception' }; },
|
||||
});
|
||||
await assert.rejects(context.apiForTest('/api/v1/ssh-keys'),
|
||||
error => error.copyKey === 'ssh_keys.error.request'
|
||||
&& error.parameters.status === 500
|
||||
&& !String(error.message).includes('private backend'));
|
||||
await assert.rejects(context.apiForTest('/api/v1/ssh-keys', {
|
||||
method: 'POST', body: { name: 'fixture', public_key: 'fixture' },
|
||||
}), error => error.copyKey === 'ssh_keys.error.mutation_unknown'
|
||||
&& error.mutationMayHaveApplied === true
|
||||
&& !String(error.message).includes('private backend'));
|
||||
|
||||
assert.match(context.errorTextForTest(new Error('private backend exception'),
|
||||
'ssh_keys.error.initialize'), /^ssh_keys\.error\.initialize:/);
|
||||
}
|
||||
|
||||
console.log('ISO and SSH-key safe feedback behavior tests passed.');
|
||||
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use App\Services\UserCopy\UserCopyCoverageScanner;
|
||||
use App\Services\UserCopy\UserCopyManifest;
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$manifest = UserCopyManifest::load();
|
||||
$entries = array_column($manifest['entries'], null, 'key');
|
||||
$assert(($manifest['pages']['cloud.isos']['scopes'] ?? null) === ['common', 'isos']
|
||||
&& ($manifest['pages']['cloud.keys']['scopes'] ?? null) === ['common', 'ssh_keys'],
|
||||
'ISO and SSH-key pages must publish only their declared copy scopes.');
|
||||
|
||||
$required = [
|
||||
'isos.list.aria', 'isos.empty', 'isos.confirm.delete.body',
|
||||
'isos.confirm.cleanup_downloaded.body', 'isos.task.failure.recovering',
|
||||
'isos.task.failure.effect_unknown', 'isos.task.receipt.invalid',
|
||||
'isos.toast.import.ready.body', 'isos.error.mutation_unknown',
|
||||
'ssh_keys.list.aria', 'ssh_keys.empty.title',
|
||||
'ssh_keys.confirm.delete.body', 'ssh_keys.toast.deleted.body',
|
||||
'ssh_keys.error.mutation_unknown', 'ssh_keys.error.initialize',
|
||||
];
|
||||
foreach ($required as $key) {
|
||||
$assert(isset($entries[$key]), 'Required media/key copy is missing: ' . $key);
|
||||
}
|
||||
|
||||
$assert($entries['isos.item.summary_digest']['parameters'] === [
|
||||
'digest' => 'string', 'size' => 'string',
|
||||
] && $entries['isos.confirm.delete.body']['parameters'] === ['name' => 'string']
|
||||
&& $entries['ssh_keys.confirm.delete.body']['parameters'] === ['name' => 'string']
|
||||
&& $entries['isos.error.request']['parameters'] === ['status' => 'integer']
|
||||
&& $entries['ssh_keys.error.request']['parameters'] === ['status' => 'integer'],
|
||||
'Media/key parameter contracts drifted from their call sites.');
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
if (!in_array($entry['scope'], ['isos', 'ssh_keys'], true)
|
||||
|| !str_starts_with($entry['kind'], 'toast_')) {
|
||||
continue;
|
||||
}
|
||||
$assert(in_array($entry['toast_tone'], ['success', 'warning', 'error', 'info'], true),
|
||||
'Media/key Toast copy is missing an explicit tone: ' . $entry['key']);
|
||||
}
|
||||
|
||||
$paths = [
|
||||
$root . '/resources/views/venix/cloud/pages/isos.tpl',
|
||||
$root . '/resources/views/venix/cloud/pages/keys.tpl',
|
||||
$root . '/public/cloud/iso-images.js',
|
||||
$root . '/public/cloud/ssh-keys.js',
|
||||
];
|
||||
$violations = UserCopyCoverageScanner::scanFiles($paths);
|
||||
$assert($violations === [], 'Media/key pages retain direct user-visible copy: '
|
||||
. json_encode($violations, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
$referenced = [];
|
||||
foreach ($paths as $path) {
|
||||
$source = file_get_contents($path);
|
||||
preg_match_all(
|
||||
'/(?:user_copy\s+key=|\bt\()[\'\"]((?:isos|ssh_keys)\.[a-z0-9_.]+)[\'\"]/',
|
||||
$source,
|
||||
$matches
|
||||
);
|
||||
array_push($referenced, ...$matches[1]);
|
||||
}
|
||||
foreach (array_unique($referenced) as $key) {
|
||||
$assert(isset($entries[$key]), 'Media/key source references an undeclared key: ' . $key);
|
||||
}
|
||||
|
||||
$isoModule = file_get_contents($root . '/public/cloud/iso-images.js');
|
||||
$keyModule = file_get_contents($root . '/public/cloud/ssh-keys.js');
|
||||
$assert(str_contains($isoModule, 'globalThis.VenixUserCopy')
|
||||
&& str_contains($keyModule, 'globalThis.VenixUserCopy'),
|
||||
'Media/key modules must resolve feedback through the user-copy runtime.');
|
||||
$assert(!preg_match('/payload\?\.(?:detail|message|msg|error)/', $keyModule)
|
||||
&& !preg_match('/task\?\.error/', $isoModule)
|
||||
&& !str_contains($isoModule, 'recoveryTaskFailureNotice(task)')
|
||||
&& !preg_match('/showError\([^\n]+error\?*\.message/', $isoModule . "\n" . $keyModule),
|
||||
'Media/key feedback must not expose raw backend or task messages.');
|
||||
$assert(str_contains($isoModule, "t('isos.confirm.delete.body', { name: isoName })")
|
||||
&& str_contains($keyModule, "t('ssh_keys.confirm.delete.body', { name: key.name })")
|
||||
&& str_contains($isoModule, "t('isos.toast.import.ready.title')")
|
||||
&& str_contains($keyModule, "t('ssh_keys.toast.deleted.title')"),
|
||||
'Media/key confirmations and Toasts must use their parameterized copy contracts.');
|
||||
$assert(str_contains($isoModule, 'uncertainMutations: new Set()')
|
||||
&& str_contains($isoModule, "pageState.activeStatusUrl = 'unknown'")
|
||||
&& substr_count($keyModule, 'if (!keepLocked) setMutationBusy(false);') === 2,
|
||||
'Unknown media/key mutations must remain locally locked until a fresh page reconciliation.');
|
||||
|
||||
echo "ISO and SSH-key user-copy contract checks passed.\n";
|
||||
Loading…
Reference in New Issue