Skip to content

Commit bbd0abc

Browse files
authored
fix(panel): update-check reported failure on success (#460)
* fix(panel): update-check always reported failure on success The panel compared updateInfo.status against names the backend classify (src/version-check.js) never returns, so a successful check fell through to the error branch. Align the status name and add a cross-file contract lock: every status the panel compares must be a value classify can actually return, and the fetch path must match the registered route (77 tests). Discrimination verified by re-injecting the wrong name - the new lock names it. * fix(panel): star entry should lead to the repo page, not the stargazers list The star entry linked to /stargazers - the page that lists who already starred, with no way to star. Point it at the repo home, where the Star button sits in the header (recheck feedback).
1 parent be4b10a commit bbd0abc

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎dsh-mneme/lib/client.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3452,7 +3452,10 @@ window.__ModuleLoader__.load({
34523452
.replace("{v}", updateInfo.latest)
34533453
.replace("{c}", updateInfo.current);
34543454
}
3455-
if (updateInfo.status === "latest" || updateInfo.status === "up_to_date") return t("memory.settings.update.latest");
3455+
// 后端 classify(src/version-check.js)返回的是 "up-to-date"(连字符)。
3456+
// 前端状态名必须与它逐字对齐:此前误写 "latest"/"up_to_date" 两个后端
3457+
// 从未返回过的名字,检测成功也掉进 error 兜底(复验实测踩中)。
3458+
if (updateInfo.status === "up-to-date") return t("memory.settings.update.latest");
34563459
if (updateInfo.status === "ahead") return t("memory.settings.update.ahead");
34573460
return t("memory.settings.update.error");
34583461
}
@@ -4184,10 +4187,11 @@ window.__ModuleLoader__.load({
41844187
),
41854188
updateInfo?.status === "outdated" && h("div", { className: "mneme-set-hint", style: { marginTop: 8 } },
41864189
t("memory.settings.version.outdatedHint")),
4187-
// star 鼓励入口:给仓库点星是零成本的支持方式
4190+
// star 鼓励入口:链接到仓库主页而非 stargazers——前者右上角就有
4191+
// Star 按钮,后者只是「看谁点过」的名单页(复验实测反馈)。
41884192
h("div", { className: "mneme-feedlist", style: { marginTop: 12 } },
41894193
feedRow("star", t("memory.settings.star"), t("memory.settings.star.sub"),
4190-
{ href: "https://github.com/slow-stack/mneme/stargazers", target: "_blank", rel: "noopener noreferrer" })
4194+
{ href: "https://github.com/slow-stack/mneme", target: "_blank", rel: "noopener noreferrer" })
41914195
),
41924196
h("div", { className: "mneme-set-foot" },
41934197
h("span", null, `dsh-mneme v${pkgVersion}`)
@@ -8215,3 +8219,7 @@ window.__ModuleLoader__.load({
82158219
return module.exports;
82168220
}
82178221
});
8222+
8223+
8224+
8225+

‎dsh-mneme/test/client.test.js‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,3 +2055,36 @@ test("persona card is multi-card with visible field labels and save-failure erro
20552055
// 保存失败提示:personaError 状态有渲染路径(非仅 setState)
20562056
assert.ok(clientSource.includes("t(\"memory.settings.personaSaveFailed\")"), "save failure must render an error line");
20572057
});
2058+
2059+
// 回归锁(复验实测踩中):面板「检测更新」的状态名必须与后端 classify
2060+
// (src/version-check.js)逐字对齐。此前前端误写 "latest"/"up_to_date"(后端
2061+
// 从未返回过),检测成功也掉进 error 兜底——按钮永远报「检测失败」。
2062+
// 这条缝两端各有测试(version-check.test.js 测 classify、面板测试测渲染),
2063+
// 但契约本身没人管。锁三件事:①前端比较的字面量是后端真实返回值;②后端
2064+
// classify 的返回集合没有前端漏接的成员;③apiFetch 的路由路径与后端注册一致。
2065+
test("update-check status names match the backend classify contract verbatim", () => {
2066+
const vcSource = readFileSync(join(root, "src/version-check.js"), "utf8");
2067+
// ① 后端 classify 的全部返回字面量
2068+
const backendStatuses = new Set(
2069+
[...vcSource.matchAll(/return "([a-z-]+)";/g)].map((m) => m[1])
2070+
);
2071+
assert.ok(backendStatuses.has("up-to-date") && backendStatuses.has("outdated") && backendStatuses.has("ahead") && backendStatuses.has("unknown"),
2072+
`classify must return the known status set (saw ${[...backendStatuses].join(", ")})`);
2073+
// ② 前端 checkResultText 比较的每个状态名都必须 ∈ 后端集合(防再发明新名)
2074+
const iStart = clientSource.indexOf("function checkResultText");
2075+
assert.ok(iStart > 0, "checkResultText must exist");
2076+
// 函数块取到下一个同级 function 声明为止:indexOf("}") 会切在首个 if 的
2077+
// 右括号,比较分支被截断成 1 个(2026-10-17 实测)。
2078+
const iEnd = clientSource.slice(iStart).search(/\n {6}function /);
2079+
const block = clientSource.slice(iStart, iEnd > 0 ? iStart + iEnd : undefined);
2080+
const compared = [...block.matchAll(/updateInfo\.status === "([a-zA-Z_-]+)"/g)].map((m) => m[1]);
2081+
assert.ok(compared.length >= 2, `the panel must compare real statuses (saw ${compared.length})`);
2082+
const unknown = [...new Set(compared)].filter((s) => !backendStatuses.has(s));
2083+
assert.deepEqual(unknown, [], `前端比较了后端不会返回的状态名(检测成功也会显示失败):${unknown.join(", ")}`);
2084+
// ③ 路由契约:前端 fetch 的路径必须与后端注册的 exact path 一致
2085+
assert.ok(clientSource.includes('apiFetch("/api/dsh-mneme/version-check")'),
2086+
"the panel must call the registered version-check route");
2087+
const apiSource = readFileSync(join(root, "src/api.js"), "utf8");
2088+
assert.ok(apiSource.includes('path: "/api/dsh-mneme/version-check"'),
2089+
"the backend must register the version-check route");
2090+
});

0 commit comments

Comments
 (0)