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.
115 lines
4.9 KiB
PHP
115 lines
4.9 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$schema = file_get_contents($root . '/sql/ss.sql');
|
|
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
$table = static function (string $name) use ($schema, $assert): string {
|
|
$matched = preg_match(
|
|
'/CREATE TABLE `' . preg_quote($name, '/')
|
|
. '` \(([\s\S]*?)\n\) ENGINE=InnoDB/',
|
|
$schema,
|
|
$match
|
|
) === 1;
|
|
$assert($matched, 'Missing UI copy table: ' . $name);
|
|
return $match[1];
|
|
};
|
|
|
|
$tables = [
|
|
'ui_copy_locales', 'ui_copy_entries', 'ui_copy_drafts',
|
|
'ui_copy_publications', 'ui_copy_revision_items',
|
|
];
|
|
foreach ($tables as $name) {
|
|
$table($name);
|
|
$assert(str_contains($setup, "'" . $name . "'"),
|
|
'CloudSetup does not own UI copy table: ' . $name);
|
|
}
|
|
|
|
$locale = $table('ui_copy_locales');
|
|
$entry = $table('ui_copy_entries');
|
|
$draft = $table('ui_copy_drafts');
|
|
$publication = $table('ui_copy_publications');
|
|
$revision = $table('ui_copy_revision_items');
|
|
|
|
$assert(!str_contains($locale, 'current_publication_id')
|
|
&& !str_contains($publication, 'active_claim')
|
|
&& !str_contains($locale, 'published_generation'),
|
|
'The database must not duplicate the runtime current.json pointer.');
|
|
$assert(str_contains($entry, '`source_text_zh` longtext NOT NULL')
|
|
&& str_contains($entry, '`source_hash_zh` char(64)')
|
|
&& str_contains($entry, '`placeholder_contract_json` mediumtext NOT NULL')
|
|
&& str_contains($entry, '`placeholder_hash` char(64)')
|
|
&& !preg_match('/(?:source|baseline|default)_(?:text_)?en\b/i', $entry),
|
|
'UI copy entries must contain only the Chinese source baseline.');
|
|
$assert(str_contains($draft, '`draft_version` bigint(20) UNSIGNED')
|
|
&& str_contains($draft, '`created_by` bigint(20) UNSIGNED')
|
|
&& str_contains($draft, '`updated_by` bigint(20) UNSIGNED')
|
|
&& str_contains($draft, '`validation_state` varchar(16)'),
|
|
'UI copy drafts lack optimistic versioning, validation or audit fields.');
|
|
$assert(str_contains($publication, '`revision` bigint(20) UNSIGNED')
|
|
&& str_contains($publication, '`catalog_generation` char(66)')
|
|
&& str_contains($publication, '`manifest_hash` char(64)')
|
|
&& str_contains($publication, '`catalog_hash` char(64)')
|
|
&& str_contains($publication, '`artifact_path` varchar(512)')
|
|
&& str_contains($publication, '`request_idempotency_key` char(64)')
|
|
&& str_contains($publication, '`request_fingerprint` char(64)')
|
|
&& str_contains($publication, '`published_by` bigint(20) UNSIGNED')
|
|
&& str_contains($publication, '`published_at` bigint(20) UNSIGNED'),
|
|
'UI copy publications lack durable generation or audit evidence.');
|
|
$assert(str_contains($revision, '`source_text_zh` longtext NOT NULL')
|
|
&& str_contains($revision, '`published_text` longtext NOT NULL')
|
|
&& str_contains($revision, '`placeholder_contract_json` mediumtext NOT NULL')
|
|
&& str_contains($revision, '`published_hash` char(64)'),
|
|
'UI copy revision items do not freeze publication evidence.');
|
|
|
|
foreach ([
|
|
'ui_copy_locale_name', 'ui_copy_locale_source',
|
|
'ui_copy_entry_key', 'ui_copy_draft_entry_locale',
|
|
'ui_copy_publication_key',
|
|
'ui_copy_publication_revision', 'ui_copy_publication_generation',
|
|
'ui_copy_publication_request',
|
|
'ui_copy_revision_item_entry', 'ui_copy_revision_item_key',
|
|
] as $index) {
|
|
$assert(str_contains($schema, 'UNIQUE KEY `' . $index . '`')
|
|
&& str_contains($setup, "'" . $index . "'"),
|
|
'UI copy unique-index contract is missing: ' . $index);
|
|
}
|
|
foreach ([
|
|
'chk_ui_copy_locale_shape', 'chk_ui_copy_entry_shape',
|
|
'chk_ui_copy_draft_shape', 'chk_ui_copy_publication_identity',
|
|
'chk_ui_copy_publication_terminal',
|
|
'chk_ui_copy_revision_item_shape',
|
|
] as $check) {
|
|
$assert(str_contains($schema, 'CONSTRAINT `' . $check . '`')
|
|
&& str_contains($setup, "'" . $check . "'"),
|
|
'UI copy CHECK contract is missing: ' . $check);
|
|
}
|
|
|
|
$models = [
|
|
'UiCopyLocale' => 'ui_copy_locales',
|
|
'UiCopyEntry' => 'ui_copy_entries',
|
|
'UiCopyDraft' => 'ui_copy_drafts',
|
|
'UiCopyPublication' => 'ui_copy_publications',
|
|
'UiCopyRevisionItem' => 'ui_copy_revision_items',
|
|
];
|
|
foreach ($models as $class => $modelTable) {
|
|
$model = file_get_contents($root . '/app/Models/' . $class . '.php');
|
|
$assert(is_string($model)
|
|
&& str_contains($model, "protected \$table = '" . $modelTable . "'"),
|
|
'UI copy model contract is missing: ' . $class);
|
|
}
|
|
|
|
$assert(str_contains($setup,
|
|
"SCHEMA_VERSION = 'go-agent-wss-v42-abuse-observation'")
|
|
&& str_contains($setup,
|
|
"self::schema('ss.sql') . \"\\0\" . self::schema('cloud.sql')")
|
|
&& str_contains($setup,
|
|
'self::managedMainTables()'),
|
|
'Clean-break marker/fingerprint does not cover the UI copy schema.');
|
|
|
|
echo "UI copy catalog schema contracts passed.\n";
|