diff --git a/web/app/Services/UserCopy/UserCopyAuthoringProjection.php b/web/app/Services/UserCopy/UserCopyAuthoringProjection.php index 7b93ae0f..09528b9c 100644 --- a/web/app/Services/UserCopy/UserCopyAuthoringProjection.php +++ b/web/app/Services/UserCopy/UserCopyAuthoringProjection.php @@ -97,7 +97,11 @@ final class UserCopyAuthoringProjection $channel = $candidate; } } - if (!in_array($channel, ['legacy', 'page', 'advanced', 'all'], true)) { + if (!in_array( + $channel, + ['legacy', 'page', 'shared', 'advanced', 'all'], + true + )) { throw new UserCopyAdminException('文案编辑通道无效。'); } @@ -124,11 +128,17 @@ final class UserCopyAuthoringProjection $inSelectedPage = isset($selectedScopes[(string) $entry->scope]); $matchesChannel = match ($channel) { 'legacy' => $inSelectedPage, - 'page' => $inSelectedPage - && is_array($manifestEntry) - && $manifestEntry['editor_surface'] === 'page', + 'page' => is_array($manifestEntry) + && $manifestEntry['editor_surface'] === 'page' + && $manifestEntry['editor_group'] === $selectedPage, + 'shared' => is_array($manifestEntry) + && $manifestEntry['editor_surface'] === 'shared', 'advanced' => is_array($manifestEntry) - && $manifestEntry['editor_surface'] !== 'page', + && in_array( + $manifestEntry['editor_surface'], + ['dialog', 'feedback', 'task', 'accessibility'], + true + ), 'all' => is_array($manifestEntry), }; if (!$matchesChannel) { diff --git a/web/app/Services/UserCopy/UserCopyManifest.php b/web/app/Services/UserCopy/UserCopyManifest.php index 57af74a8..274f40b9 100644 --- a/web/app/Services/UserCopy/UserCopyManifest.php +++ b/web/app/Services/UserCopy/UserCopyManifest.php @@ -33,7 +33,7 @@ final class UserCopyManifest ]; private const TOAST_TONES = ['success', 'info', 'warning', 'error']; private const EDITOR_SURFACES = [ - 'page', 'dialog', 'feedback', 'task', 'accessibility', + 'page', 'shared', 'dialog', 'feedback', 'task', 'accessibility', ]; private const ENTRY_FIELDS = [ diff --git a/web/resources/user-copy/entries/instances-deploy.entries.php b/web/resources/user-copy/entries/instances-deploy.entries.php index cf87da86..9ce004bb 100644 --- a/web/resources/user-copy/entries/instances-deploy.entries.php +++ b/web/resources/user-copy/entries/instances-deploy.entries.php @@ -3,8 +3,32 @@ $entry = require dirname(__DIR__) . '/entry.php'; return [ - $entry('common.template.other_system', 'common', 'cloud.deploy', '其他系统'), - $entry('common.template.system_image', 'common', 'cloud.deploy', '系统镜像'), + $entry( + 'common.template.other_system', + 'common', + 'cloud.deploy', + '其他系统', + 'label', + [], + 'required', + false, + null, + 'page', + 'cloud.deploy' + ), + $entry( + 'common.template.system_image', + 'common', + 'cloud.deploy', + '系统镜像', + 'label', + [], + 'required', + false, + null, + 'page', + 'cloud.deploy' + ), $entry('instances.eyebrow', 'instances', 'cloud.instances', '虚拟机'), $entry('instances.title', 'instances', 'cloud.instances', '实例管理', 'title'), $entry('instances.description', 'instances', 'cloud.instances', '查看实例信息;点击名称进入管理页面执行操作。', 'description'), diff --git a/web/resources/user-copy/entry.php b/web/resources/user-copy/entry.php index afa71a6b..c04be0d9 100644 --- a/web/resources/user-copy/entry.php +++ b/web/resources/user-copy/entry.php @@ -36,6 +36,16 @@ $surfaceFor = static function ( )) { return 'feedback'; } + if (str_starts_with($key, 'common.shell.') + || str_starts_with($key, 'common.theme.') + || str_starts_with($key, 'public.shell.') + || in_array( + $key, + ['common.action.refresh', 'common.action.load_more'], + true + )) { + return 'shared'; + } return 'page'; }; @@ -43,6 +53,13 @@ $groupFor = static function (string $key, string $page, ?string $requested): str if ($requested !== null) { return $requested; } + if (str_starts_with($key, 'common.shell.') + || str_starts_with($key, 'common.theme.')) { + return 'shell.user'; + } + if (str_starts_with($key, 'public.shell.')) { + return 'shell.public'; + } if (str_starts_with($key, 'common.tasks.') || str_starts_with($key, 'common.drawer.tasks.')) { return 'user.tasks'; diff --git a/web/tests/UserCopyAdminServiceTest.php b/web/tests/UserCopyAdminServiceTest.php index c8c2e51a..57763fa0 100644 --- a/web/tests/UserCopyAdminServiceTest.php +++ b/web/tests/UserCopyAdminServiceTest.php @@ -196,6 +196,14 @@ $manifest = [ 'allow_hide' => false, 'toast_tone' => null, 'editor_surface' => 'feedback', 'editor_group' => 'test.advanced', ], + [ + 'key' => 'test.shared', 'scope' => 'test', + 'page' => 'test.page', 'kind' => 'button', + 'source' => '公共操作', 'format' => 'plain_text', + 'parameters' => [], 'criticality' => 'required', + 'allow_hide' => false, 'toast_tone' => null, + 'editor_surface' => 'shared', 'editor_group' => 'common.shared', + ], ], ]; @@ -212,9 +220,9 @@ $super = [ try { $sync = new UserCopyManifestSynchronizer($database, $manifest); $syncResult = $sync->synchronize((int) $super['user_id']); - $assert($syncResult['active'] === 4 - && $syncResult['created'] === 4 - && $database->table('ui_copy_entries')->where('state', 'active')->count() === 4, + $assert($syncResult['active'] === 5 + && $syncResult['created'] === 5 + && $database->table('ui_copy_entries')->where('state', 'active')->count() === 5, 'Manifest synchronization did not create the active source projection.'); $sourceLocale = $database->table('ui_copy_locales') ->where('locale', 'zh-CN')->first(); @@ -232,7 +240,7 @@ try { $store = new UserCopyPublicationStore($root); $service = new UserCopyAdminService($database, $manifest, $store); $resynchronized = $service->synchronize($super); - $assert($resynchronized['active'] === 4 + $assert($resynchronized['active'] === 5 && $resynchronized['created'] === 0, 'Administrator service could not idempotently synchronize the Manifest.'); $locale = $service->saveLocale($super, 'en', '目标语言', true); @@ -302,10 +310,10 @@ try { $first = $service->publish($super, 'en', str_repeat('b', 64)); $assert($first['state'] === 'ready' - && $first['entry_count'] === 4 + && $first['entry_count'] === 5 && is_file($root . '/current.json') && $database->table('ui_copy_revision_items') - ->where('publication_id', $first['id'])->count() === 4, + ->where('publication_id', $first['id'])->count() === 5, 'First publication did not freeze all revision items and switch current.json.'); $hiddenItem = $database->table('ui_copy_revision_items') ->where('publication_id', $first['id']) @@ -334,6 +342,10 @@ try { 'group' => '', ] && $workspace['groups'] === [ + [ + 'id' => 'common.shared', + 'label' => '公共框架', + ], [ 'id' => 'test.advanced', 'label' => 'test.advanced', @@ -344,7 +356,8 @@ try { ], ] && $workspace['coverage']['published'] === 4 - && count($workspace['entries']) === 4 + && $workspace['coverage']['missing'] === 1 + && count($workspace['entries']) === 5 && $workspace['write_ready'] === true && $workspace['current_generation'] === $first['generation'], 'Administrator workspace omitted selection, coverage or current generation.'); @@ -417,13 +430,25 @@ try { && $emptyPageWorkspace['current_generation'] === $first['generation'] && $emptyPageWorkspace['write_ready'] === true, 'Empty authoring projection lost the locale publication state.'); + $sharedWorkspace = $service->workspace([ + 'page' => 'test.page', + 'locale' => 'en', + 'channel' => 'shared', + ]); + $assert($sharedWorkspace['authoring']['channel'] === 'shared' + && $sharedWorkspace['coverage']['total'] === 1 + && $sharedWorkspace['coverage']['missing'] === 1 + && array_column($sharedWorkspace['entries'], 'key') === [ + 'test.shared', + ], + 'Shared editing channel did not isolate reusable copy.'); $allWorkspace = $service->workspace([ 'page' => 'test.page', 'locale' => 'en', 'channel' => 'all', ]); - $assert($allWorkspace['coverage']['total'] === 4 - && count($allWorkspace['entries']) === 4, + $assert($allWorkspace['coverage']['total'] === 5 + && count($allWorkspace['entries']) === 5, 'All-copy authoring channel did not return the complete projection.'); $reject( static fn () => $service->workspace([ @@ -529,7 +554,7 @@ try { $changed = $changedSync->synchronize((int) $super['user_id']); $titleDraftState = (string) $database->table('ui_copy_drafts') ->where('id', $titleOne['id'])->value('validation_state'); - $assert($changed['active'] === 4 + $assert($changed['active'] === 5 && $changed['created'] === 1 && $changed['orphaned'] === 1 && $titleDraftState === 'stale' diff --git a/web/tests/UserCopyAuthoringProjectionTest.php b/web/tests/UserCopyAuthoringProjectionTest.php index e7c1dd2a..2bf16ad6 100644 --- a/web/tests/UserCopyAuthoringProjectionTest.php +++ b/web/tests/UserCopyAuthoringProjectionTest.php @@ -63,6 +63,10 @@ $manifest = [ $entry( 'a.title', 'a', 'a.page', '页面 A 标题', 'title', 'page', 'a.page' ), + $entry( + 'b.common_title', 'common', 'b.page', '页面 B 公共词条', 'label', + 'page', 'b.page' + ), $entry( 'b.dialog', 'b', 'b.page', '页面 B 弹窗', 'confirmation', 'dialog', 'b.advanced' @@ -72,7 +76,11 @@ $manifest = [ ), $entry( 'common.shell.title', 'common', 'a.page', '公共导航', - 'navigation', 'page', 'common.shared' + 'navigation', 'shared', 'shell.user' + ), + $entry( + 'common.shell.aria', 'common', 'a.page', '公共导航无障碍标签', + 'aria_label', 'accessibility', 'shell.user' ), $entry( 'common.warning', 'common', 'a.page', '公共提醒', 'warning', @@ -87,8 +95,10 @@ $rows = array_map( ], [ ['a.title', 'a'], + ['b.common_title', 'common'], ['b.dialog', 'b'], ['b.title', 'b'], + ['common.shell.aria', 'common'], ['common.shell.title', 'common'], ['common.warning', 'common'], ] @@ -104,7 +114,8 @@ $assert($default['selected_page'] === 'a.page' && $default['channel'] === 'legacy' && $default['selected_group'] === '' && $keys($default) === [ - 'a.title', 'common.shell.title', 'common.warning', + 'a.title', 'b.common_title', 'common.shell.aria', + 'common.shell.title', 'common.warning', ], 'Default legacy authoring projection changed its page-scope behavior.'); $assert($default['pages'] === [ @@ -116,6 +127,7 @@ $assert($default['pages'] === [ ['id' => 'b.advanced', 'label' => 'b.advanced'], ['id' => 'b.page', 'label' => '页面 B'], ['id' => 'common.shared', 'label' => '公共框架'], + ['id' => 'shell.user', 'label' => 'shell.user'], ], 'Authoring pages or sorted group labels changed during extraction.'); @@ -123,40 +135,50 @@ $pageA = $projection->project([ 'page' => 'a.page', 'channel' => 'page', ], $rows); -$assert($keys($pageA) === ['a.title', 'common.shell.title'], - 'Page channel no longer selects page-scope entries with page surfaces.'); +$assert($keys($pageA) === ['a.title'], + 'Page channel did not isolate entries owned by the selected page.'); $pageB = $projection->project([ 'page' => 'b.page', 'channel' => 'page', ], $rows); -$assert($keys($pageB) === ['b.title', 'common.shell.title'], - 'Stage-one extraction unexpectedly changed shared page-copy behavior.'); +$assert($keys($pageB) === ['b.common_title', 'b.title'], + 'Page channel did not follow explicit authoring ownership.'); + +$shared = $projection->project([ + 'page' => 'b.page', + 'channel' => 'shared', +], $rows); +$assert($keys($shared) === ['common.shell.title'], + 'Shared channel did not isolate visible reusable copy.'); $advanced = $projection->project([ 'page' => 'a.page', 'channel' => 'advanced', ], $rows); -$assert($keys($advanced) === ['b.dialog', 'common.warning'], - 'Advanced channel no longer spans every non-page authoring surface.'); +$assert($keys($advanced) === [ + 'b.dialog', 'common.shell.aria', 'common.warning', + ], + 'Advanced channel did not retain dialog, feedback and accessibility copy.'); $all = $projection->project([ 'page' => 'b.page', 'channel' => 'all', ], $rows); $assert($keys($all) === [ - 'a.title', 'b.dialog', 'b.title', 'common.shell.title', + 'a.title', 'b.common_title', 'b.dialog', 'b.title', + 'common.shell.aria', 'common.shell.title', 'common.warning', ], 'All-copy authoring projection no longer includes every Manifest entry.'); $grouped = $projection->project([ 'page' => 'b.page', - 'channel' => 'page', - 'group' => 'common.shared', + 'channel' => 'shared', + 'group' => 'shell.user', ], $rows); $assert($keys($grouped) === ['common.shell.title'], 'Authoring group filtering no longer runs after channel selection.'); $assert(isset($grouped['metadata_by_key']['common.shell.title']) && $grouped['metadata_by_key']['common.shell.title']['editor_surface'] - === 'page', + === 'shared', 'Projection omitted the Manifest metadata needed by workspace DTO hydration.'); $rejects( diff --git a/web/tests/UserCopyBindingContractTest.php b/web/tests/UserCopyBindingContractTest.php index 76bd39b1..c2b09868 100644 --- a/web/tests/UserCopyBindingContractTest.php +++ b/web/tests/UserCopyBindingContractTest.php @@ -63,8 +63,13 @@ foreach ($files as $file) { $key = (string) $match[2]; $assert(isset($entries[$key]), 'Copy binding references an unknown key in ' . $relative . ': ' . $key); - $assert($entries[$key]['editor_surface'] === 'page', - 'Advanced copy cannot be bound to a page element: ' . $key); + $assert(in_array( + $entries[$key]['editor_surface'], + ['page', 'shared'], + true + ), + 'Non-visible advanced copy cannot be bound to a page element: ' + . $key); $boundGroups[(string) $entries[$key]['editor_group']] = true; $tagStart = strrpos(substr($source, 0, (int) $offset), '<'); @@ -112,6 +117,8 @@ foreach ([ 'legal.terms', 'public.error', 'public.home', + 'shell.public', + 'shell.user', 'user.account', 'user.invite', 'user.recharge', diff --git a/web/tests/UserCopyManifestContractTest.php b/web/tests/UserCopyManifestContractTest.php index 44983fe0..6dedade3 100644 --- a/web/tests/UserCopyManifestContractTest.php +++ b/web/tests/UserCopyManifestContractTest.php @@ -37,6 +37,20 @@ $assert(($loadedEntries['common.toast.success.title']['editor_surface'] ?? null) && ($loadedEntries['common.tasks.status.running']['editor_group'] ?? null) === 'user.tasks', 'User-copy editor surfaces or task authoring groups are incomplete.'); +$surfaceCounts = array_count_values(array_column( + $manifest['entries'], + 'editor_surface' +)); +ksort($surfaceCounts, SORT_STRING); +$assert($surfaceCounts === [ + 'accessibility' => 102, + 'dialog' => 56, + 'feedback' => 609, + 'page' => 1509, + 'shared' => 46, + 'task' => 53, + ], + 'User-copy authoring surface census drifted from the reviewed taxonomy.'); foreach ($loadedEntries as $copyKey => $entry) { $assert(is_string($entry['editor_surface'] ?? null) && is_string($entry['editor_group'] ?? null), @@ -61,6 +75,42 @@ foreach ($loadedEntries as $copyKey => $entry) { $assert($entry['editor_surface'] === 'dialog', 'Confirmation copy is not assigned to dialog editing: ' . $copyKey); } + if (str_starts_with($copyKey, 'common.shell.')) { + $assert($entry['editor_group'] === 'shell.user' + && in_array( + $entry['editor_surface'], + ['shared', 'accessibility'], + true + ), + 'Authenticated shell copy has the wrong authoring owner: ' . $copyKey); + } + if (str_starts_with($copyKey, 'public.shell.')) { + $assert($entry['editor_group'] === 'shell.public' + && in_array( + $entry['editor_surface'], + ['shared', 'accessibility'], + true + ), + 'Public shell copy has the wrong authoring owner: ' . $copyKey); + } +} +$assert($loadedEntries['common.theme.light']['editor_surface'] === 'shared' + && $loadedEntries['common.theme.light']['editor_group'] === 'shell.user' + && $loadedEntries['common.theme.dark']['editor_surface'] === 'shared' + && $loadedEntries['common.theme.dark']['editor_group'] === 'shell.user', + 'Theme copy is not owned by the authenticated shared shell.'); +foreach (['common.action.refresh', 'common.action.load_more'] as $copyKey) { + $assert($loadedEntries[$copyKey]['editor_surface'] === 'shared' + && $loadedEntries[$copyKey]['editor_group'] === 'common.shared', + 'Reusable action copy is not isolated in shared authoring: ' . $copyKey); +} +foreach ([ + 'common.template.other_system', + 'common.template.system_image', +] as $copyKey) { + $assert($loadedEntries[$copyKey]['editor_surface'] === 'page' + && $loadedEntries[$copyKey]['editor_group'] === 'cloud.deploy', + 'Deployment template copy lost its page owner: ' . $copyKey); } $hashedDetailKeys = array_filter( array_keys($loadedEntries), @@ -79,6 +129,34 @@ $assert(isset($runtimeSource->entries()['common.toast.success.title']) true ), 'Validated Manifest is incompatible with the runtime source catalog.'); +$legacyAuthoring = $manifest; +foreach ($legacyAuthoring['entries'] as &$legacyEntry) { + if ($legacyEntry['editor_surface'] === 'shared') { + $legacyEntry['editor_surface'] = 'page'; + } + if ($legacyEntry['editor_group'] === 'shell.user') { + $legacyEntry['editor_group'] = 'common.shared'; + } elseif ($legacyEntry['editor_group'] === 'shell.public') { + $legacyEntry['editor_group'] = 'public.home'; + } + if (in_array( + $legacyEntry['key'], + ['common.template.other_system', 'common.template.system_image'], + true + )) { + $legacyEntry['editor_group'] = 'common.shared'; + } +} +unset($legacyEntry); +$legacyAuthoring = UserCopyManifest::validate($legacyAuthoring); +$legacySource = new UserCopySourceCatalog($legacyAuthoring); +$assert(hash_equals($runtimeSource->sourceHash(), $legacySource->sourceHash()), + 'Shared authoring taxonomy changed the runtime source hash.'); +$currentCompiled = (new UserCopyCatalogCompiler($runtimeSource))->compile('en'); +$legacyCompiled = (new UserCopyCatalogCompiler($legacySource))->compile('en'); +$assert($currentCompiled->generation === $legacyCompiled->generation + && $currentCompiled->scopes === $legacyCompiled->scopes, + 'Shared authoring taxonomy changed the compiled runtime catalog.'); $base = [ 'version' => 1, 'pages' => [