test(i18n): complete authoring regression gates

go
codex 1 week ago
parent 27fbd696e9
commit 6b07a2e285

@ -41,16 +41,31 @@ Virt Cloud 的用户界面文案使用“源码中文合同 + 管理员目标语
当前公共语言选择支持 `zh-CN` 与 `en`:优先使用 `?lang=`,其次使用持久 Cookie,最后解析浏览器 `Accept-Language`。源码没有英文兜底;尚未发布英文译文的条目按上述规则显示中文基线。
## 运行范围与编辑归属
`scope/page` 与 `editor_surface/editor_group` 是两套正交分类,不能互相替代:
- **运行范围**决定普通用户请求可以加载哪些词条,继续由 `scope`、Manifest 页面键和 `UserCopyPageResolver` 控制。
- **编辑归属**决定词条从哪个作者界面维护。`page` 归属当前页面正文;`shared` 归属导航、页眉、页脚等公共框架;`dialog`、`feedback`、`task`、`accessibility` 归入后台动态文案中心。
因此,用户页面内的超级管理员编辑器只显示当前 DOM 已绑定的 `page` 文案,以及该页面允许的 `shared` 公共框架;它不能扩大运行时 scope,也不能直接发布。管理员后台只管理弹窗、反馈、任务和无障碍等动态文案。所有入口最终写入同一草稿账本,并由同一发布事务生成不可变目录。
## 管理员工作流
超级管理员通过“管理员后台 → 用户界面译文”完成以下操作:
1. **同步源码词条**:把当前 Manifest 投影到管理账本;源码删除的条目标记为孤立,中文基线或参数合同变化会使不兼容草稿变为 stale。
2. **编辑草稿**:按页面和目标语言筛选词条,保存时校验 UTF-8、长度、ICU 参数、可见性和乐观版本。
2. **编辑草稿**:后台动态文案中心或用户页面内编辑器保存草稿;保存时校验 UTF-8、长度、ICU 参数、可见性和乐观版本。浏览器内未保存输入按“语言 + 稳定键”缓存,翻页、搜索和切换编辑分组不会清空;切换语言或离开页面前必须明确确认。
3. **安全预览**:预览使用受限 iframe,不执行目标译文中的脚本。
4. **发布目标语言**:把有效草稿和兼容的历史译文编译为新的不可变目录,并原子激活。
5. **发布历史与回滚**:历史发布保留完整词条快照;回滚只允许切换到已经通过完整性校验且属于同一语言的 generation。
后台显示的目录覆盖率只描述当前编辑通道与分组;`publication_readiness` 则始终核对该目标语言的全部活动草稿,不受当前搜索、类型、状态或分页条件影响。任意 invalid、stale 或 pending 草稿都会阻断发布;正式发布事务仍执行最终完整性校验。
目录读取接口保留 `page` 作为 Manifest 页面键,并使用独立的 `catalog_page` 与 `per_page` 分页;`per_page` 默认为 50、最大 100。`q` 搜索稳定键和中文源文案,`surface` 与 `state` 执行服务端筛选,响应返回稳定键排序后的 `pagination`。`groups`、覆盖率与发布就绪度均在分页和筛选前计算。
管理员目录和页面内编辑器只会取消 GET 读取:前端同时使用 `AbortController`、请求序号及筛选/语言/标签签名拒绝陈旧响应。保存、发布、同步和回滚等 mutation 不会因界面切换被取消,也不会自动重放;结果不确定时必须人工核对。
数据库是编辑和审计账本,不是用户请求的运行时依赖。管理员页面或数据库临时不可用不会影响已经发布的用户界面目录。
## 模板与浏览器运行时

@ -845,6 +845,200 @@ try {
]) === $restoredReadiness,
'Readiness recovery or reader-service DTO parity drifted.');
$database->table('ui_copy_drafts')
->where('id', (int) $validCount['id'])
->update([
'validation_state' => 'invalid',
'validation_errors_json' => '{',
]);
$corruptErrorsWorkspace = $service->workspace([
'page' => 'test.page',
'locale' => 'en',
'channel' => 'shared',
]);
$assert($corruptErrorsWorkspace['publication_readiness']
['invalid_draft_count'] === 1
&& $corruptErrorsWorkspace['publication_readiness']
['first_errors'] === [[
'key' => 'test.count',
'validation_state' => 'invalid',
'errors' => ['validation_result_corrupt'],
]],
'Corrupt draft validation errors did not map to a safe diagnostic.');
$database->table('ui_copy_drafts')
->where('id', (int) $validCount['id'])
->update([
'validation_state' => 'valid',
'validation_errors_json' => '[]',
]);
$database->table('ui_copy_drafts')
->where('id', (int) $warning['id'])
->update([
'validation_state' => 'unexpected',
'validation_errors_json' => '["ignored_fixture"]',
]);
$unknownStateWorkspace = $service->workspace([
'page' => 'test.page',
'locale' => 'en',
'channel' => 'page',
]);
$assert($unknownStateWorkspace['publication_readiness']
['invalid_draft_count'] === 1
&& $unknownStateWorkspace['publication_readiness']
['blocking_draft_count'] === 1
&& $unknownStateWorkspace['publication_readiness']
['first_errors'] === [[
'key' => 'test.warning',
'validation_state' => 'invalid',
'errors' => ['validation_state_unknown'],
]],
'Unknown draft validation state did not fail closed as invalid.');
$database->table('ui_copy_drafts')
->where('id', (int) $warning['id'])
->update([
'validation_state' => 'valid',
'validation_errors_json' => '[]',
]);
$targetLocaleId = (int) $database->table('ui_copy_locales')
->where('locale', 'en')
->value('id');
$database->table('ui_copy_locales')
->where('id', $targetLocaleId)
->update(['enabled' => 0]);
$disabledLocaleWorkspace = $service->workspace([
'page' => 'test.page',
'locale' => 'en',
'channel' => 'all',
]);
$assert($disabledLocaleWorkspace['publication_readiness']['ready']
=== false
&& $disabledLocaleWorkspace['publication_readiness']['locale_enabled']
=== false
&& $disabledLocaleWorkspace['publication_readiness']
['projection_ready'] === true
&& $disabledLocaleWorkspace['publication_readiness']
['blocking_draft_count'] === 0
&& $disabledLocaleWorkspace['write_ready'] === false,
'Disabled locale remained publication-ready.');
$database->table('ui_copy_locales')
->where('id', $targetLocaleId)
->update(['enabled' => 1]);
$sharedEntry = $database->table('ui_copy_entries')
->where('copy_key', 'test.shared')
->first();
$assert($sharedEntry !== null, 'Shared readiness fixture is missing.');
$database->table('ui_copy_entries')
->where('id', (int) $sharedEntry->id)
->update(['source_hash_zh' => str_repeat('0', 64)]);
$projectionBlockedWorkspace = $service->workspace([
'page' => 'test.page',
'locale' => 'en',
'channel' => 'shared',
]);
$assert($projectionBlockedWorkspace['publication_readiness']['ready']
=== false
&& $projectionBlockedWorkspace['publication_readiness']
['projection_ready'] === false
&& $projectionBlockedWorkspace['publication_readiness']
['locale_enabled'] === true
&& $projectionBlockedWorkspace['publication_readiness']
['blocking_draft_count'] === 0
&& $projectionBlockedWorkspace['write_ready'] === false,
'Unsynchronized Manifest projection remained publication-ready.');
$database->table('ui_copy_entries')
->where('id', (int) $sharedEntry->id)
->update(['source_hash_zh' => (string) $sharedEntry->source_hash_zh]);
$templateEntry = $database->table('ui_copy_entries')
->where('copy_key', 'test.title')
->first();
$templateDraft = $database->table('ui_copy_drafts')
->where('id', (int) $titleOne['id'])
->first();
$assert($templateEntry !== null && $templateDraft !== null,
'Readiness truncation fixtures are missing.');
$temporaryEntryIds = [];
for ($index = 6; $index >= 1; $index--) {
$copyKey = sprintf('readiness.temp.%02d', $index);
$entryValues = (array) $templateEntry;
unset($entryValues['id']);
$entryValues['copy_key'] = $copyKey;
$entryValues['location'] = 'test:' . $copyKey;
$entryValues['source_text_zh'] = '临时就绪度词条 ' . $index;
$entryValues['source_hash_zh'] = hash(
'sha256',
$entryValues['source_text_zh']
);
$temporaryEntryId = (int) $database->table('ui_copy_entries')
->insertGetId($entryValues);
$temporaryEntryIds[] = $temporaryEntryId;
$draftValues = (array) $templateDraft;
unset($draftValues['id']);
$draftValues['entry_id'] = $temporaryEntryId;
$draftValues['draft_text'] = 'temporary ' . $index;
$draftValues['draft_hash'] = hash(
'sha256',
$draftValues['draft_text']
);
$draftValues['translated_source_hash_zh']
= $entryValues['source_hash_zh'];
$draftValues['translated_placeholder_hash']
= $entryValues['placeholder_hash'];
$draftValues['validation_state'] = 'invalid';
$draftValues['validation_errors_json'] = json_encode(
['temporary_' . sprintf('%02d', $index)],
JSON_THROW_ON_ERROR
);
$database->table('ui_copy_drafts')->insert($draftValues);
}
$truncatedErrorsWorkspace = $service->workspace([
'page' => 'test.page',
'locale' => 'en',
'channel' => 'all',
]);
$assert($truncatedErrorsWorkspace['publication_readiness']
['blocking_draft_count'] === 6
&& $truncatedErrorsWorkspace['publication_readiness']
['invalid_draft_count'] === 6
&& count($truncatedErrorsWorkspace['publication_readiness']
['first_errors']) === 5
&& array_column(
$truncatedErrorsWorkspace['publication_readiness']['first_errors'],
'key'
) === [
'readiness.temp.01',
'readiness.temp.02',
'readiness.temp.03',
'readiness.temp.04',
'readiness.temp.05',
],
'Readiness diagnostics were not sorted and capped at five entries.');
$database->table('ui_copy_drafts')
->whereIn('entry_id', $temporaryEntryIds)
->delete();
$database->table('ui_copy_entries')
->whereIn('id', $temporaryEntryIds)
->delete();
$readinessAfterBoundaryChecks = $service->workspace([
'page' => 'test.page',
'locale' => 'en',
'channel' => 'all',
]);
$assert($readinessAfterBoundaryChecks['publication_readiness']['ready']
=== true
&& $readinessAfterBoundaryChecks['publication_readiness']
['projection_ready'] === true
&& $readinessAfterBoundaryChecks['publication_readiness']
['locale_enabled'] === true
&& $readinessAfterBoundaryChecks['publication_readiness']
['blocking_draft_count'] === 0,
'Readiness fixtures were not restored after boundary checks.');
$titleTwo = $service->saveDraft(
$super,
'test.title',

Loading…
Cancel
Save