diff --git a/main/manager-web/scripts/integrity-check.js b/main/manager-web/scripts/integrity-check.js index d86f26a90..57416c745 100644 --- a/main/manager-web/scripts/integrity-check.js +++ b/main/manager-web/scripts/integrity-check.js @@ -134,54 +134,105 @@ for (const f of walk(SRC)) { } } -// ---- Pass 3: duplicated top-level Vue options keys (class 3) ------------- +// ---- Pass 3: duplicated Vue option keys, AST-based (class 3) ------------- +// A duplicate key inside an options object is legal JS but silently clobbers +// the first property at object-literal eval time. Rebase merges have produced +// both top-level duplicates (two `computed:` blocks) and nested ones (two +// `dialogVisible` handlers inside `watch:`), the latter disabling the model +// edit dialog's data-population trigger. Check the export-default object at +// depth 1 (Vue options) and inside the option maps at depth 2. const OPTION_KEYS = new Set([ 'name', 'components', 'directives', 'mixins', 'props', 'data', 'computed', 'methods', 'watch', 'created', 'mounted', 'beforeMount', 'updated', 'beforeUpdate', 'destroyed', 'beforeDestroy', 'activated', 'deactivated', 'render', 'template', 'inheritAttrs', 'model', 'provide', 'inject', 'filters', ]); -function dupOptionKeys(scriptCode) { - // Find `export default { ... }` object and read depth-1 keys. - const i = scriptCode.indexOf('export default'); - if (i < 0) return []; - const start = scriptCode.indexOf('{', i); - if (start < 0) return []; - const keys = []; - let depth = 0, k = start, str = null; - while (k < scriptCode.length) { - const ch = scriptCode[k]; - if (str) { - if (ch === '\\') { k += 2; continue; } - if (ch === str) str = null; - k++; continue; +const OPTION_MAP_KEYS = new Set(['watch', 'computed', 'methods', 'filters', 'directives']); + +function nodeKey(p) { + if (!p.key) return null; + if (p.key.type === 'Identifier') return p.key.name; + if (p.key.type === 'Literal') return String(p.key.value); + return null; +} + +function dupKeys(objExpr) { + if (!objExpr || objExpr.type !== 'ObjectExpression') return []; + const seen = new Map(); + for (const p of objExpr.properties) { + if (p.type !== 'Property') continue; // spread etc. + const k = nodeKey(p); + if (k === null) continue; + seen.set(k, (seen.get(k) || 0) + 1); + } + return [...seen].filter(([, n]) => n > 1).map(([k]) => k); +} + +function optionObject(node) { + // Property value is either an object literal (watch/computed/methods) or a + // function whose single return statement yields one (data). + if (!node) return null; + if (node.type === 'ObjectExpression') return node; + if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') { + const body = node.body; + if (body.type === 'BlockStatement') { + const ret = body.body.find((s) => s.type === 'ReturnStatement'); + if (ret && ret.argument && ret.argument.type === 'ObjectExpression') return ret.argument; } - if (ch === '"' || ch === "'" || ch === '`') { str = ch; k++; continue; } - if (ch === '{') { depth++; k++; continue; } - if (ch === '}') { depth--; if (depth === 0) break; k++; continue; } - if (depth === 1) { - const mm = /^([A-Za-z_$][\w$]*)\s*:/.exec(scriptCode.slice(k, k + 60)); - if (mm) { - const ls = scriptCode.lastIndexOf('\n', k); - if (scriptCode.slice(ls + 1, k).trim() === '') { - keys.push(mm[1]); - k += mm[0].length - 1; + } + return null; +} + +function exportDefaultObject(ast) { + for (const n of ast.body) { + if (n.type === 'ExportDefaultDeclaration') { + if (n.declaration.type === 'ObjectExpression') return n.declaration; + if (n.declaration.type === 'VariableDeclaration') { + for (const d of n.declaration.declarations) { + if (d.init && d.init.type === 'ObjectExpression') return d.init; } } } - k++; } - const seen = new Map(); - for (const key of keys) seen.set(key, (seen.get(key) || 0) + 1); - return [...seen].filter(([key, n]) => n > 1 && OPTION_KEYS.has(key)).map(([key]) => key); + return null; } + for (const f of walk(SRC)) { if (!f.endsWith('.vue')) continue; const raw = fs.readFileSync(f, 'utf8'); - const sfc = parseComponent(raw); - const opts = sfc.script ? sfc.script.content : ''; - for (const dup of dupOptionKeys(opts)) { - addError('DUP-OPT', f, null, `duplicate options key "${dup}" (later block clobbers the first)`); + for (const s of scriptsOf(f, raw)) { + let ast; + try { + ast = acorn.parse(s.code, { + ecmaVersion: 'latest', sourceType: 'module', locations: true, ranges: true, + allowReturnOutsideFunction: true, allowAwaitOutsideFunction: true, + }); + } catch { + continue; // PARRESS already reported in pass 1 + } + const root = exportDefaultObject(ast); + if (!root) continue; + for (const dup of dupKeys(root)) { + if (OPTION_KEYS.has(dup)) { + addError('DUP-OPT', f, s.offset, `duplicate options key "${dup}" (later value clobbers the first)`); + } + } + for (const p of root.properties) { + const k = nodeKey(p); + if (k === null) continue; + if (OPTION_MAP_KEYS.has(k)) { + for (const dup of dupKeys(optionObject(p.value))) { + addError('DUP-OPT', f, s.offset + (p.loc ? p.loc.start.line - 1 : 0), + `duplicate "${k}" key "${dup}" (later handler clobbers the first)`); + } + } + if (k === 'data') { + for (const dup of dupKeys(optionObject(p.value))) { + addError('DUP-OPT', f, s.offset + (p.loc ? p.loc.start.line - 1 : 0), + `duplicate data() key "${dup}" (later value clobbers the first)`); + } + } + } } } diff --git a/main/manager-web/src/components/ModelEditDialog.vue b/main/manager-web/src/components/ModelEditDialog.vue index a748fb736..aec6746be 100644 --- a/main/manager-web/src/components/ModelEditDialog.vue +++ b/main/manager-web/src/components/ModelEditDialog.vue @@ -153,6 +153,9 @@ export default { this.resetProviders(); this.loadProviders(); }, + visible(val) { + this.dialogVisible = val; + }, dialogVisible(val) { this.$emit('update:visible', val); if (!val) { @@ -161,12 +164,6 @@ export default { this.loadModelData(); } }, - visible(val) { - this.dialogVisible = val; - }, - dialogVisible(val) { - this.$emit("update:visible", val); - }, 'form.configJson.type'(newVal) { if (newVal && this.providersLoaded) { this.loadProviderFields(newVal); diff --git a/main/manager-web/src/views/KnowledgeBaseManagement.vue b/main/manager-web/src/views/KnowledgeBaseManagement.vue index 4a579649f..0349eeea5 100644 --- a/main/manager-web/src/views/KnowledgeBaseManagement.vue +++ b/main/manager-web/src/views/KnowledgeBaseManagement.vue @@ -487,14 +487,6 @@ export default { this.selectedFilesList.splice(index, 1); }, - formatFileSize(bytes) { - if (bytes === 0) return '0 B'; - const k = 1024; - const sizes = ['B', 'KB', 'MB', 'GB']; - const i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; - }, - handleBatchUploadSubmit() { if (this.selectedFilesList.length === 0) { this.$message.error(this.$t('knowledgeFileUpload.fileRequired')); diff --git a/main/manager-web/src/views/home.vue b/main/manager-web/src/views/home.vue index c926359d7..eba48270f 100644 --- a/main/manager-web/src/views/home.vue +++ b/main/manager-web/src/views/home.vue @@ -181,11 +181,6 @@ export default { handleDeviceManage() { this.$router.push('/device-management'); }, - handleSearch(regex) { - this.isSearching = true; - this.searchRegex = regex; - this.applySearchFilter(); - }, handleSearchReset() { this.isSearching = false; this.searchRegex = null; diff --git a/westernization.md b/westernization.md index 9ceee8113..b058c945e 100644 --- a/westernization.md +++ b/westernization.md @@ -181,7 +181,7 @@ provider management rendered as garbage). All are now machine-checked: | Check | Command | Catches | | --- | --- | --- | -| Integrity | `node main/manager-web/scripts/integrity-check.js` | undefined identifiers (lost imports, dropped function params/`const request` bindings), mismatched template tags, duplicated Vue option keys (`computed:` twice clobbers the first) | +| Integrity | `node main/manager-web/scripts/integrity-check.js` | undefined identifiers (lost imports, dropped function params/`const request` bindings), mismatched template tags, duplicated keys in `export default` options and inside `watch`/`computed`/`methods`/`data` (later value silently clobbers the first) | | i18n | `cd main/manager-web && npm run check:i18n` | duplicate keys, cross-locale drift vs `en`, `$t('...')` keys with no definition in any locale | | Snapshot contract | `npm run test:snapshot` | agent snapshot API shape (`restoreAgentSnapshot` etc. were silently deleted once, while `AgentSnapshotDialog.vue` still called them) | | Han audit | `./scripts/westernization_audit.sh` | Chinese text/paths outside exception zones | @@ -219,6 +219,18 @@ of them, but knowing the shapes speeds up conflict resolution: 5. **Half-converted components** - root tag converted (`el-dialog` -> `CustomDialog`) but closing tag/footer wiring left behind (FirmwareDialog, AddWisdomBodyDialog, CustomDialog's duplicated `computed`). +6. **Duplicate keys inside option maps** - the 2026-10-11 merge left two + `dialogVisible` handlers inside `watch:` in ModelEditDialog.vue (the + later, trivial one clobbered the version holding the `loadModelData()` + open-trigger, so the model edit form opened empty), plus dead duplicate + `handleSearch` in home.vue and duplicate `formatFileSize` in + KnowledgeBaseManagement.vue (the latter two survived into the pushed + tree). Top-level `computed:` duplication was caught earlier; keys nested + in `watch`/`methods` are just as silent. `integrity-check.js` now parses + the options object and its `watch`/`computed`/`methods`/`data` maps and + fails on any duplicate key. After any rebase touching a `.vue` file that + exists on both sides, diff its option maps against upstream, not just + the template. ### Translation tool