mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-06-13 18:31:16 +08:00
feat(i18n): localize planner and authority diagnostics
This commit is contained in:
@@ -6,6 +6,9 @@ import {
|
||||
formatAuthorityUpgradeMeta,
|
||||
} from "../runtime/authority-upgrade-state.js";
|
||||
import { createGraphPersistenceState } from "../ui/ui-status.js";
|
||||
import { t, formatUiStatusText, formatUiStatusMeta } from "../i18n/index.js";
|
||||
|
||||
// ── Original tests (unchanged expectations) ──
|
||||
|
||||
const initial = createAuthorityUpgradeState();
|
||||
assert.equal(initial.mode, "standalone");
|
||||
@@ -69,4 +72,144 @@ assert.equal(
|
||||
"准备就绪 · 服务端增强已启用",
|
||||
);
|
||||
|
||||
console.log("authority-upgrade-state tests passed");
|
||||
// ── Phase 7: textKey / metaKey presence and defaults ──
|
||||
|
||||
// createAuthorityUpgradeState defaults
|
||||
const defaults = createAuthorityUpgradeState();
|
||||
assert.equal(defaults.textKey, "authority.mode.standalone", "default textKey");
|
||||
assert.equal(defaults.metaKey, "authority.mode.standalone.meta", "default metaKey");
|
||||
assert.deepEqual(defaults.textParams, {}, "default textParams is empty object");
|
||||
assert.deepEqual(defaults.metaParams, {}, "default metaParams is empty object");
|
||||
|
||||
// deriveAuthorityUpgradeState: each branch has correct keys
|
||||
const disabledState = deriveAuthorityUpgradeState({
|
||||
settings: { authorityEnabled: "off" },
|
||||
capability: {},
|
||||
browserState: { mode: "minimal" },
|
||||
});
|
||||
assert.equal(disabledState.textKey, "authority.mode.standalone");
|
||||
assert.equal(disabledState.metaKey, "authority.mode.standalone.disabled.meta");
|
||||
|
||||
assert.equal(absent.textKey, "authority.mode.standalone");
|
||||
assert.equal(absent.metaKey, "authority.mode.standalone.noAuthority.meta");
|
||||
|
||||
assert.equal(degraded.textKey, "authority.mode.degraded");
|
||||
assert.equal(degraded.metaKey, "authority.mode.degraded.unhealthy.meta");
|
||||
assert.equal(degraded.metaParams.reason, "probe-failed");
|
||||
|
||||
assert.equal(enhanced.textKey, "authority.mode.enhanced");
|
||||
assert.equal(enhanced.metaKey, "authority.mode.enhanced.meta.manifestReady");
|
||||
|
||||
const shadow = deriveAuthorityUpgradeState({
|
||||
settings: { authorityEnabled: "auto", authorityPrimaryWhenAvailable: false },
|
||||
capability: {
|
||||
installed: true, healthy: true, sessionReady: true, permissionReady: true,
|
||||
},
|
||||
browserState: { mode: "minimal" },
|
||||
});
|
||||
assert.equal(shadow.textKey, "authority.mode.shadow");
|
||||
assert.equal(shadow.metaKey, "authority.mode.shadow.meta");
|
||||
|
||||
const candidateStorage = deriveAuthorityUpgradeState({
|
||||
settings: { authorityEnabled: "auto", authorityPrimaryWhenAvailable: true },
|
||||
capability: {
|
||||
installed: true, healthy: true, sessionReady: true, permissionReady: true,
|
||||
storagePrimaryReady: true, triviumPrimaryReady: false,
|
||||
},
|
||||
browserState: { mode: "minimal" },
|
||||
});
|
||||
assert.equal(candidateStorage.textKey, "authority.mode.candidate");
|
||||
assert.equal(candidateStorage.metaKey, "authority.mode.candidate.meta.storageReady");
|
||||
|
||||
const candidateVector = deriveAuthorityUpgradeState({
|
||||
settings: { authorityEnabled: "auto", authorityPrimaryWhenAvailable: true },
|
||||
capability: {
|
||||
installed: true, healthy: true, sessionReady: true, permissionReady: true,
|
||||
storagePrimaryReady: false, triviumPrimaryReady: true,
|
||||
},
|
||||
browserState: { mode: "minimal" },
|
||||
});
|
||||
assert.equal(candidateVector.textKey, "authority.mode.candidate");
|
||||
assert.equal(candidateVector.metaKey, "authority.mode.candidate.meta.vectorReady");
|
||||
|
||||
const degradedCapability = deriveAuthorityUpgradeState({
|
||||
settings: { authorityEnabled: "auto", authorityPrimaryWhenAvailable: true },
|
||||
capability: {
|
||||
installed: true, healthy: true, sessionReady: true, permissionReady: true,
|
||||
reason: "time-out",
|
||||
},
|
||||
browserState: { mode: "minimal" },
|
||||
});
|
||||
assert.equal(degradedCapability.textKey, "authority.mode.degraded");
|
||||
assert.equal(degradedCapability.metaKey, "authority.mode.degraded.capabilityNotReady.meta");
|
||||
assert.equal(degradedCapability.metaParams.reason, "time-out");
|
||||
|
||||
// Enhanced with no jobs
|
||||
const enhancedNoJobs = deriveAuthorityUpgradeState({
|
||||
settings: { authorityEnabled: "auto", authorityPrimaryWhenAvailable: true },
|
||||
capability: {
|
||||
installed: true, healthy: true, sessionReady: true, permissionReady: true,
|
||||
storagePrimaryReady: true, triviumPrimaryReady: true, jobsReady: false,
|
||||
},
|
||||
browserState: { mode: "minimal" },
|
||||
});
|
||||
assert.equal(enhancedNoJobs.textKey, "authority.mode.enhanced");
|
||||
assert.equal(enhancedNoJobs.metaKey, "authority.mode.enhanced.meta.noJobs");
|
||||
|
||||
// Enhanced with jobs but no manifest
|
||||
const enhancedNoManifest = deriveAuthorityUpgradeState({
|
||||
settings: { authorityEnabled: "auto", authorityPrimaryWhenAvailable: true },
|
||||
capability: {
|
||||
installed: true, healthy: true, sessionReady: true, permissionReady: true,
|
||||
storagePrimaryReady: true, triviumPrimaryReady: true,
|
||||
jobsReady: true, bmeVectorManifestReady: false,
|
||||
},
|
||||
browserState: { mode: "minimal" },
|
||||
});
|
||||
assert.equal(enhancedNoManifest.textKey, "authority.mode.enhanced");
|
||||
assert.equal(enhancedNoManifest.metaKey, "authority.mode.enhanced.meta.noManifest");
|
||||
|
||||
// ── Phase 7: formatUiStatusText / formatUiStatusMeta with i18n ──
|
||||
|
||||
// When textKey resolves to a catalog entry, t() should produce the localized string
|
||||
const standaloneText = formatUiStatusText(disabledState);
|
||||
assert.ok(typeof standaloneText === "string", "formatUiStatusText returns string");
|
||||
assert.ok(standaloneText.length > 0, "formatUiStatusText is non-empty");
|
||||
|
||||
const standaloneMeta = formatUiStatusMeta(disabledState);
|
||||
assert.ok(typeof standaloneMeta === "string", "formatUiStatusMeta returns string");
|
||||
assert.ok(standaloneMeta.length > 0, "formatUiStatusMeta is non-empty");
|
||||
|
||||
// Verify that zh-CN (default locale) catalog keys match the Chinese fallbacks
|
||||
assert.equal(t("authority.mode.standalone"), "纯前端模式");
|
||||
assert.equal(t("authority.mode.shadow"), "服务端影子同步");
|
||||
assert.equal(t("authority.mode.enhanced"), "服务端增强已启用");
|
||||
assert.equal(t("authority.mode.candidate"), "服务端增强准备中");
|
||||
assert.equal(t("authority.mode.degraded"), "已自动回退");
|
||||
|
||||
// Verify meta keys resolve
|
||||
assert.equal(
|
||||
t("authority.mode.enhanced.meta.manifestReady"),
|
||||
"图谱与向量存储已增强,服务端向量清单可用",
|
||||
);
|
||||
assert.equal(
|
||||
t("authority.mode.candidate.meta.storageReady"),
|
||||
"图谱服务端存储可用,向量增强仍在等待能力确认",
|
||||
);
|
||||
|
||||
// Verify degraded meta with params
|
||||
assert.equal(
|
||||
t("authority.mode.degraded.unhealthy.meta", { reason: "probe-failed" }),
|
||||
"服务端增强暂不可用:probe-failed",
|
||||
);
|
||||
|
||||
// Verify formatUiStatusText falls back to .text when no textKey
|
||||
const noKeyState = { text: "fallback", meta: "metaFallback" };
|
||||
assert.equal(formatUiStatusText(noKeyState), "fallback");
|
||||
assert.equal(formatUiStatusMeta(noKeyState), "metaFallback");
|
||||
|
||||
// Verify string passthrough
|
||||
assert.equal(formatUiStatusText("just a string"), "just a string");
|
||||
assert.equal(formatUiStatusMeta("just a meta string"), "just a meta string");
|
||||
|
||||
console.log("authority-upgrade-state tests passed");
|
||||
Reference in New Issue
Block a user