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.
virt/web/tests/UserCopyTicketContractTest.php

69 lines
2.4 KiB
PHTML

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Services\UserCopy\UserCopyCoverageScanner;
use App\Services\UserCopy\UserCopyManifest;
$root = dirname(__DIR__);
$read = static function (string $path) use ($root): string {
$source = file_get_contents($root . '/' . $path);
if (!is_string($source)) {
throw new RuntimeException('Unable to read ' . $path . '.');
}
return $source;
};
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$manifest = UserCopyManifest::load();
$entries = array_column($manifest['entries'], null, 'key');
foreach ([
'tickets.list.title',
'tickets.create.content_placeholder',
'tickets.detail.reply_close',
'tickets.author.admin',
'tickets.feedback.effect_unknown',
'tickets.upload.remove',
] as $key) {
$assert(isset($entries[$key]), 'Missing ticket copy key: ' . $key);
}
$paths = [
'resources/views/venix/user/ticket.tpl',
'resources/views/venix/user/ticket_create.tpl',
'resources/views/venix/user/ticket_view.tpl',
'public/theme/venix/js/ticket-page.js',
'public/cloud/ticket-upload.js',
];
$violations = [];
foreach ($paths as $path) {
array_push(
$violations,
...UserCopyCoverageScanner::scanContents($path, $read($path))
);
}
$assert($violations === [],
'Ticket user-copy source still contains unmanaged visible copy: '
. json_encode($violations, JSON_UNESCAPED_UNICODE));
$ticketPage = $read('public/theme/venix/js/ticket-page.js');
$upload = $read('public/cloud/ticket-upload.js');
$assert(str_contains($ticketPage, 'window.VenixUserCopy')
&& str_contains($ticketPage, 'tickets.feedback.effect_unknown')
&& !str_contains($ticketPage, 'data.msg')
&& !str_contains($ticketPage, 'error.message'),
'Ticket page feedback bypasses the published copy catalog or exposes raw errors.');
$assert(str_contains($upload, 'error.copyKey = copyKey')
&& str_contains($upload, 'error.mutationMayHaveApplied')
&& str_contains($upload, 'xhr.status === 408 || xhr.status >= 500')
&& !str_contains($upload, 'data.msg'),
'Ticket upload runtime does not preserve safe keyed failure semantics.');
$assert(substr_count($ticketPage, 'if (!effectUnknown) done();') === 2,
'An unknown-effect ticket mutation can re-enable controls and be replayed.');
echo "Ticket user-copy contracts passed.\n";