import test from 'node:test' import assert from 'node:assert/strict' import { existsSync, readdirSync, statSync } from 'node:fs' import { join } from 'node:path' import { readSource } from './helpers.ts' /** * 操作列的按钮一旦超过列宽,会**整颗消失**而不是换行:这些页的 td 是 `overflow:hidden` + * `table-layout:fixed`,而 `.ops-cell` / `.asin-col-actions` 是 nowrap flex。2026-10-08 店铺密钥 * 那单"没有删除功能"就是这么来的——按钮在线上包的 DOM 里、事件也在,只是被裁到看不见点不到 * (列给 160px、实测需 215.5px)。 * * 两条失败方向都见过: * - 列宽写死 px(店铺密钥 160)⇒ 从**右**裁,最后一颗(删除)整颗没了; * - 列宽写百分比(最低价 ASIN `9%`)⇒ 百分比跟着容器一起缩,且 `.asin-col-actions` 带 * `justify-content: flex-end`,溢出翻到**左**侧,于是"配置"被吃掉、"删除"看着完好。 * 所以光补 `flex-wrap` 不够:900px 容器下 9% 只有 56.7px,连一颗 53px 的按钮加 24px padding * 都装不下,wrap 之后照样裁。列必须有 **px 下限**。 * * 下面 OPS_MIN_COL_PX 是实测不是估算:browser-use 在 100% 缩放下渲染 `.btn.btn-sm` 量的 * offsetWidth(两字 53 / 四字 80 / 五字 93.5),加 `gap: 8px` 与 td 左右 padding 各 12px。 * 三元文案按**较长**分支计(`检测中…` vs `检测白名单` 取后者)。 */ const SRC = 'src/pages' /** 每页操作列「单行装下全部按钮」所需的列最小宽(px,实测算出)。 */ const OPS_MIN_COL_PX: Record = { 'src/pages/account/CompaniesPage.vue': 77, 'src/pages/account/GroupsPage.vue': 138, 'src/pages/account/MenusPage.vue': 138, 'src/pages/account/UserSecretsPage.vue': 314, 'src/pages/account/UsersPage.vue': 138, 'src/pages/asin/AsinInvalidPage.vue': 138, 'src/pages/asin/DedupeRegistryPage.vue': 138, 'src/pages/asin/ProductCategoryPage.vue': 138, 'src/pages/asin/QueryAsinPage.vue': 138, 'src/pages/asin/SkipPricePage.vue': 138, 'src/pages/records/DeviceLogsPage.vue': 138, 'src/pages/records/RecordsDigitalHumanVersionPage.vue': 287, 'src/pages/records/RecordsSoftwareVersionPage.vue': 77, 'src/pages/records/RecordsTutorialPage.vue': 77, 'src/pages/records/WorkbenchClientPackagePage.vue': 77, 'src/pages/shop/ShopKeysPage.vue': 240, 'src/pages/shop/ShopManagePage.vue': 199, } /** 操作列的 flex 容器类名。漏一个就是把一整族页面留在盲区里(`.asin-col-actions` 曾这么漏过两页)。 */ const OPS_CELL_CLASSES = ['ops-cell', 'asin-col-actions'] function vueFiles(dir: string): string[] { const out: string[] = [] for (const name of readdirSync(dir)) { const p = join(dir, name) if (statSync(p).isDirectory()) out.push(...vueFiles(p)) else if (name.endsWith('.vue')) out.push(p) } return out } /** 相对工程根的正斜杠路径。 */ function rel(file: string): string { return file.replace(/\\/g, '/') } interface Cell { file: string buttons: number wrapped: boolean } /** 只做解析,不碰磁盘:读源码这一步留在用例体内(见 source-pin-ratchet 对"隔层 helper"的口径)。 */ function opsCells(sources: Array<{ file: string; source: string }>): Cell[] { const cells: Cell[] = [] for (const { file, source } of sources) { // 注释先剥掉:CSS 注释里的 `flex-wrap: wrap;` 会把"这条页已经能换行"判成恒真。 const markup = stripHtmlComments(source) let fileCells = 0 for (const cls of OPS_CELL_CLASSES) { const block = new RegExp('\\.' + cls + '[ \\t]*\\{([^}]*)\\}').exec(source) if (!block) continue const td = new RegExp(']*class="[^"]*' + cls + '[^"]*"[^>]*>([\\s\\S]*?)<\\/td>').exec(markup) const buttons = td ? (td[1].match(/', '', ].join('\n') const cells = opsCells([{ file: 'src/pages/asin/TrapPage.vue', source: wrapOnlyInComment }]) assert.equal(cells.length, 1, '假源码没被认出容器 ⇒ 扫描形状与源码脱节') assert.equal(cells[0].buttons, 2, `按钮数应认出 2,实际 ${cells[0].buttons}`) assert.equal(cells[0].wrapped, false, 'CSS 注释里的 flex-wrap: wrap; 被当成了真声明 ⇒ 这条看守对"只写在注释里"的修复恒绿') })