isDir() ? rmdir($item->getPathname()) : unlink($item->getPathname()); } rmdir($directory); }; $manifest = UserCopyManifest::validate([ 'version' => 1, 'pages' => [ 'test.page' => ['label' => '测试页', 'scopes' => ['common']], ], 'entries' => [[ 'key' => 'common.test.title', 'scope' => 'common', 'page' => 'test.page', 'kind' => 'title', 'source' => '中文安全基线', 'format' => 'plain_text', 'parameters' => [], 'criticality' => 'required', 'allow_hide' => false, 'toast_tone' => null, 'editor_surface' => 'page', 'editor_group' => 'test.page', ]], ]); $compiler = new UserCopyCatalogCompiler(new UserCopySourceCatalog($manifest)); $root = sys_get_temp_dir() . '/virt-user-copy-store-' . bin2hex(random_bytes(8)); mkdir($root, 0750, true); try { $store = new UserCopyPublicationStore($root); $first = $compiler->compile('en', [ 'common.test.title' => '管理员发布版本一', ]); $firstPointer = $store->publish($first, [ 'display_name' => 'English', 'enabled' => true, ]); $assert($firstPointer['generation'] === $first->generation, 'First immutable generation was not activated.'); $firstCurrent = $store->current(); $assert(($firstCurrent['locale_directory']['en'] ?? null) === [ 'display_name' => 'English', 'enabled' => true, ], 'Publishing did not atomically activate locale metadata.'); $store->validateGeneration($first->generation); $second = $compiler->compile('en', [ 'common.test.title' => '管理员发布版本二', ]); $secondPointer = $store->publish($second, [ 'display_name' => 'English (US)', 'enabled' => true, ]); $assert($secondPointer['generation'] === $second->generation && $first->generation !== $second->generation, 'A changed catalog did not create a new generation.'); $assert(is_dir($root . '/generations/' . $first->generation) && is_dir($root . '/generations/' . $second->generation), 'Publishing removed a retained immutable generation.'); $configured = $store->configureLocale('en', 'English (US)', false); $assert($configured['enabled'] === false && $store->current()['locale_directory']['en'] === [ 'display_name' => 'English (US)', 'enabled' => false, ], 'Locale enablement was not atomically updated.'); $rollback = $store->rollback('en', $first->generation); $assert($rollback['generation'] === $first->generation, 'Rollback did not reactivate the retained generation.'); $current = json_decode( (string) file_get_contents($root . '/current.json'), true, 512, JSON_THROW_ON_ERROR ); $assert($current['locales']['en']['generation'] === $first->generation, 'The authoritative pointer disagrees with the rollback result.'); $assert($current['locale_directory']['en']['enabled'] === false, 'Rollback unexpectedly changed locale availability metadata.'); } finally { $removeTree($root); } echo "User copy publication store tests passed.\n";