From 3e95ea9b3ffccdcdec439c78aaebc0682f80b7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Mon, 5 Oct 2026 07:06:09 +0800 Subject: [PATCH] =?UTF-8?q?test(=E5=89=8D=E7=AB=AF):=20=E6=8E=A5=E7=BA=BF?= =?UTF-8?q?=E5=B0=BA=E5=AD=90=E8=A1=A5=E4=B8=A4=E5=A4=84=E7=9B=B2=E5=8C=BA?= =?UTF-8?q?=E2=80=94=E2=80=94SFC=20=E6=B3=A8=E9=87=8A=E5=81=87=E6=8E=A5?= =?UTF-8?q?=E7=BA=BF=E4=B8=8E=20tab=20=E5=A4=B1=E8=B4=A5=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (a) stripComments 增剥 :往页面追加两行 HTML 注释就能同时骗过 「watch activeId」与「读 requestCompanyId」两条断言,实测缺口现在仍在列。 (c) I5 失败路径三支钉子:store 必须 catch 出 error 再 rethrow(口径照 admin-session.ts:37-39)、模板不得出现 tab.error(提示条不在已批的两处 界面暴露里)、组件必须 .catch 接住 rethrow。变异取证 M1/M2/M3 各判红 6/4/2,对照轮 6/5/1(唯一红仍是计划明令的接线正向半支)。 全量前端 1726/1725/1、vue-tsc rc=0。 --- .../tests/company-tab-wiring.test.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/admin-frontend-vue/tests/company-tab-wiring.test.ts b/admin-frontend-vue/tests/company-tab-wiring.test.ts index 26131997a..deed473bc 100644 --- a/admin-frontend-vue/tests/company-tab-wiring.test.ts +++ b/admin-frontend-vue/tests/company-tab-wiring.test.ts @@ -32,7 +32,7 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company for (const file of page.pageFiles) { // 与 api 侧同口径先剥注释(约束 6:注释里出现字面量不算接线)——否则一句 // `// 这里读 companyTab.requestCompanyId` 就能同时骗过下面两条断言。 - // 残留面:stripComments 只剥 JS 的 `//` 与 `/* */`,Vue 模板的 `` 不剥。 + // 残留面已封:stripComments 现在 JS 的 `//`、`/* */` 与 Vue 模板的 `` 三类都剥。 const source = stripComments(read(file)) if (!/watch\(\(\)\s*=>\s*companyTab\.activeId/.test(source)) { gaps.push(`${file} 没监听公司 tab:切 tab 不重取数 = 这页的 tab 是装饰品`) @@ -98,6 +98,9 @@ function listTs(dir: string): string[] { // 放进块注释会把注释当场截断,node 的 TS 解析器随即报 ERR_INVALID_TYPESCRIPT_SYNTAX——整支用例加载都失败。) function stripComments(source: string): string { return source + // Vue 模板的 也要剥:pageFiles 取样全是 .sfc.vue,一句 `` + // 在只剥 JS 注释时能同时骗过 page 侧两条钉子(2026-10-05 复评 (a))。 + .replace(//g, '') .replace(/\/\*[\s\S]*?\*\//g, '') .split(/\r?\n/) .filter((line) => !line.trimStart().startsWith('//')) @@ -171,4 +174,14 @@ test('挂载与单一尺子:tab 条挂在壳层、公司名读 companyName、 'visibleForOperator 必须含「有可选公司」判定,全是停用公司时 tab 条整体不渲染') assert.match(store, /requestCompanyId\(\)[\s\S]{0,120}companyIdForRequest/, 'requestCompanyId 必须是 companyIdForRequest 的唯一出口(页面只读这个 getter)') + + // 失败路径也要有钉子(2026-10-05 复评 (c)):改前 `initialize` 只有 try/finally ⇒ GET /companies 抛错时 + // loaded 永远 false、tab 条静默消失、异常落 unhandled rejection(全仓 src 无 errorHandler 兜底)。 + // 只补代码不补钉子的话,Task 8-12 里谁把它改回 try/finally,1726 支用例一支都不会红——那是"修好了但没护栏"。 + assert.match(store, /catch \(error\)[\s\S]{0,420}this\.error =[\s\S]{0,120}throw error/, + 'initialize 必须 catch 出 error 状态再 rethrow(口径照 admin-session.ts:37-39),不许退回只有 try/finally') + // error 只许住 store 与 console:一旦进模板就是§12 第 5 条没批的那一处新界面暴露。 + assert.equal(tabs.includes('tab.error'), false, '不许把 error 渲染进模板:提示条/文案都不在已批的两处暴露里') + assert.match(tabs, /initialize\(\)\.catch\(/, + '组件侧必须 .catch 接住 store 的 rethrow,否则又变回 unhandled rejection') })