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/TicketWriteIntentSchemaCont...

26 lines
1.1 KiB
PHTML

<?php
$schema = file_get_contents(dirname(__DIR__) . '/sql/ss.sql');
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(str_contains($schema, 'CREATE TABLE `ticket_write_requests`'),
'Fresh schema is missing durable ticket write intents.');
foreach (['actor_user_id', 'request_key', 'request_hash', 'operation', 'ticket_id', 'message_id', 'created_at'] as $column) {
$assert(str_contains($schema, '`' . $column . '`'),
'Ticket write intent schema is missing ' . $column . '.');
}
$assert(str_contains($schema, 'UNIQUE KEY `ticket_write_actor_key` (`actor_user_id`,`request_key`)'),
'Ticket write intents are not unique per actor and request key.');
$assert(str_contains($schema, 'CHARACTER SET ascii COLLATE ascii_bin'),
'Ticket idempotency keys and hashes must use exact ASCII comparison.');
$assert(str_contains($schema, 'CREATE TABLE `ticket_user_guards`')
&& str_contains($schema, 'PRIMARY KEY (`user_id`)'),
'Ticket policy writes are missing a user-scoped lock row.');
echo "Ticket write intent schema contract passed.\n";