From 9bcec51bc94b66da8cfcecdea4592bc30b4410f2 Mon Sep 17 00:00:00 2001 From: XinSpark Date: Thu, 5 Nov 2026 07:26:50 +0800 Subject: [PATCH] feat: adopt DSH 0.2.2-rc.1 settings.section.icon and re-baseline the host dependency DSH 0.2.2-rc.1 added the official settings.section.icon slot (list / inline / root, declared by dsh-client-ui-settings-general, rendered with {size, active} and {only: row.id}). The plugin had carried a DOM workaround for exactly this gap - row marking plus a CSS mask - with a note that it must be deleted once the slot exists. This removes it and registers the glyph the native way. - nav icon: slots.inject('settings.section.icon') with id 'token-stats' (the contract matches on the section id; a mismatch renders nothing, no error) - delete installSettingsNavIcon / NAV_ICON_MASK / NAV_ICON_CSS; older kernels simply fall back to the official gear - cordis peer+dev ~4.0.5 -> ~4.1.0; schemastery ~3.18.5 -> ~3.19.0 (host parity) - dsh.client.inject += @deepseek-ai/dsh-client-ui-settings-general - dsh.verifiedAgainst 0.2.1-rc.4 -> 0.2.2-rc.1; engines.dsh unchanged (0.2.2-rc.1 satisfies >=0.2.1-rc.3 <0.3.0 under includePrerelease) - tests 234 -> 238 (tests/client-settings-icon.test.js) - CHANGELOG: fold these items into the pending 0.5.1 section and restore descending order (0.4.0 sat above 0.5.0) --- CHANGELOG.md | 77 +++++++++++++-------- README.md | 4 +- package-lock.json | 38 +++++----- package.json | 13 ++-- src/client/index.js | 107 ++++++++--------------------- tests/client-settings-icon.test.js | 62 +++++++++++++++++ 6 files changed, 170 insertions(+), 131 deletions(-) create mode 100644 tests/client-settings-icon.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 8808a98..65702e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project are documented in this file. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). -## [Unreleased] +## [0.5.1] - 2026-11-05 ### Changed @@ -65,6 +65,18 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - 连带修掉一处会重复计费的隐患:`watermark` 领先于持久化事件数时,原来会被当成「日志变短」 而把整段日志从头重折 —— 重试过的 attempt 会因此被重复计费。现在用「本进程见过的最大 持久化事件数」(`state.persistedCounts`)判断是否真的变短,落后的日志只从水位继续读。 +- **设置页导航图标改用官方 `settings.section.icon`**(0.2.2-rc.1 新增:list / inline / root, + 由 `@deepseek-ai/dsh-client-ui-settings-general` 的 nav rows 以 `{size, active}` + + `only: row.id` 渲染):注册 id 必须等于 section id(`token-stats`),对不上的 id + **永不渲染、也不报错**。删掉 0.2.1 时代的 DOM 补缺(属性标记 + CSS mask + MutationObserver)—— + 那正是它自己注释里约定「官方补上就整体删除」的 L2,现在不再碰 React 管理的节点。 + **旧内核没有这个槽时 inject 不触发,行内图标退化成官方齿轮,其余一切不变。** +- `@deepseek-ai/cordis`(peer + dev)`~4.0.5` → `~4.1.0`;`@deepseek-ai/schemastery` + `~3.18.5` → `~3.19.0`,与 0.2.2-rc.1 宿主自带的版本一致。 +- `dsh.client.inject` 增加 `@deepseek-ai/dsh-client-ui-settings-general`:图标槽归该模块所有, + 静态 bundle 只有声明了才能在运行时拿到它。 +- `dsh.verifiedAgainst`:`0.2.1-rc.4` → `0.2.2-rc.1`。`engines.dsh` 不变 —— + 0.2.2-rc.1 仍落在 `>=0.2.1-rc.3 <0.3.0` 内(DSH 用 `includePrerelease: true` 判定)。 ### Tests @@ -84,35 +96,17 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - 232 → **234**:`tests/scan.test.js` 换成推送路径的门(事件折叠、fork 前缀不重复计费、 重复投递不重复计费、坏事件不抛、落后的持久化日志只从水位续读、真变短的日志才从头重折); `tests/native-hygiene.test.js` 钉住 `apply` 必须订阅 `session/event` 且不得再出现 `scanLive`。 -## [0.4.0] - 2026-10-24 - -输入区成本 pill:把「今天花了多少」搬到 composer 旁边,并对齐 DSH 0.2.1 的 dock 契约。 - -### Added - -- **输入区成本 pill**(`conversation.composer.dock`,id `usage-cost`,order 2):显示今日 - 参考成本,今日无调用时不占位;title 里带调用次数与 Token。宿主自己的 `usage` pill - 显示的是 token 数(读官方 `tokenUsage` 投影),两者互补。 - - 复用了设置页同一条 `usage/query` 通道,**按记录里的 provider/model 精确计价**,没有 - 用官方投影算钱:投影只有会话内合计、不带模型归因,用它计价会把不同单价混成一个数 - (正是 v0.3 修掉的问题类)。 - - 口径是「今日」而不是「本会话」:宿主渲染这个 slot 时是 - `renderSlot("conversation.composer.dock", {})`,dock 条目拿不到会话标识。 - - 币种跟随设置页的 ¥/$ 选择(读宿主动态解析的 `currency.symbol`,不写死符号); - 回填(backfill)进行中用 3s 快重试,完成后回到 30s 轮询;页面重新可见时立即刷新。 - -### Changed +- 234 → **238**。新增 `tests/client-settings-icon.test.js`:图标注册 id 必须等于 section id、 + 旧 DOM 补缺必须删净(留一条就是同一行画两个字形)、图标按 `size` 渲染且只用 `currentColor`、 + `dsh.client.inject` 必须声明槽位归属模块。 -- **`dsh.client.inject` 增加 `@deepseek-ai/dsh-client-ui-conversation`**:dock slot 归该模块 - 所有,静态 bundle 只有声明了才能在运行时拿到它。 -- 兼容性:`engines.dsh` 仍是 `>=0.2.0-rc.2 <0.3.0`;0.2.0 没有这个 slot,注入失败只 - 告警、不影响设置页(`try/catch` 包住)。 +### Verified -### Tests +- 0.2.2-rc.1 上 `npm test` 全绿(238)、`verify:typert`(4 端点)与 `verify:remote`(7/7)通过。 +- 与 0.2.1-rc.4 逐文件比对:会话持久化 `list()` / `read(offset, length, options)` 签名未变, + `tokenUsage` 投影字段未变(只有 `contextPressure` 多了 `summary: false`), + `settings.section` / `conversation.composer.dock` 槽位契约未变。 -- 83 → **87**。新增 `tests/client-dock.test.js`:dock 注册契约(slot 名 / id / order)、 - 不再注册旧 `stats` 行 ID、`dsh.client.inject` 必须声明 slot 归属模块、pill 的币种符号 - 必须来自宿主动态解析(防止 USD 视图印出 ¥)。 ## [0.5.0] - 2026-10-31 基于 0.4.0(输入区成本 pill)发布;`0.4.1`–`0.4.8` 以及本地标注为 `0.4.0` 的定价改造都是 @@ -171,6 +165,35 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `npm run verify:typert`(官方 loader 校验 4 个端点)与 `npm run verify:remote`(7 项)为原生契约门。 +## [0.4.0] - 2026-10-24 + +输入区成本 pill:把「今天花了多少」搬到 composer 旁边,并对齐 DSH 0.2.1 的 dock 契约。 + +### Added + +- **输入区成本 pill**(`conversation.composer.dock`,id `usage-cost`,order 2):显示今日 + 参考成本,今日无调用时不占位;title 里带调用次数与 Token。宿主自己的 `usage` pill + 显示的是 token 数(读官方 `tokenUsage` 投影),两者互补。 + - 复用了设置页同一条 `usage/query` 通道,**按记录里的 provider/model 精确计价**,没有 + 用官方投影算钱:投影只有会话内合计、不带模型归因,用它计价会把不同单价混成一个数 + (正是 v0.3 修掉的问题类)。 + - 口径是「今日」而不是「本会话」:宿主渲染这个 slot 时是 + `renderSlot("conversation.composer.dock", {})`,dock 条目拿不到会话标识。 + - 币种跟随设置页的 ¥/$ 选择(读宿主动态解析的 `currency.symbol`,不写死符号); + 回填(backfill)进行中用 3s 快重试,完成后回到 30s 轮询;页面重新可见时立即刷新。 + +### Changed + +- **`dsh.client.inject` 增加 `@deepseek-ai/dsh-client-ui-conversation`**:dock slot 归该模块 + 所有,静态 bundle 只有声明了才能在运行时拿到它。 +- 兼容性:`engines.dsh` 仍是 `>=0.2.0-rc.2 <0.3.0`;0.2.0 没有这个 slot,注入失败只 + 告警、不影响设置页(`try/catch` 包住)。 + +### Tests + +- 83 → **87**。新增 `tests/client-dock.test.js`:dock 注册契约(slot 名 / id / order)、 + 不再注册旧 `stats` 行 ID、`dsh.client.inject` 必须声明 slot 归属模块、pill 的币种符号 + 必须来自宿主动态解析(防止 USD 视图印出 ¥)。 ## [0.3.0] - 2026-10-19 设置页仪表盘的可用性与观感版本:修掉两处「看着正常其实不能用」的交互,补上 diff --git a/README.md b/README.md index f8e18bb..4cbe721 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,9 @@ id 只要表里有这一行就是精确、按它自己的价(促销期就是 0 ## 兼容性 -- DSH `>=0.2.1-rc.3 <0.3.0`(`engines.dsh`;在 `0.2.1-rc.4` 上验证过两个原生契约门),Node ≥ 22 +- DSH `>=0.2.1-rc.3 <0.3.0`(`engines.dsh`;在 `0.2.2-rc.1` 上验证过两个原生契约门与 228 项单测),Node ≥ 22 +- 设置页导航图标走官方 `settings.section.icon`(0.2.2-rc.1 新增):注册 id 必须等于 section id(`token-stats`); + 更早的内核没有这个槽,行内图标退化成官方齿轮,其余功能不变 - 输入区成本 pill 依赖 0.2.1 的 `conversation.composer.dock`:0.2.0 没有这个 slot,注入失败只告警,不影响设置页 - 更早的宿主保留 `Session.events` / `readFrom` 回退路径 diff --git a/package-lock.json b/package-lock.json index 946521c..7bac403 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,46 +1,46 @@ { "name": "dsh-plugin-usage", - "version": "0.5.0", + "version": "0.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dsh-plugin-usage", - "version": "0.5.0", + "version": "0.5.1", "license": "MIT", "dependencies": { - "@deepseek-ai/schemastery": "~3.18.5" + "@deepseek-ai/schemastery": "~3.19.0" }, "devDependencies": { - "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/cordis": "~4.1.0", "@types/react": "~18.3.1", "react": "^18.2.0", "typescript": "^5.5.0" }, "engines": { - "dsh": ">=0.2.0-rc.2 <0.3.0", + "dsh": ">=0.2.1-rc.3 <0.3.0", "node": ">=22" }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.5" + "@deepseek-ai/cordis": "~4.1.0" } }, "node_modules/@deepseek-ai/cordis": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cordis/-/cordis-4.0.5.tgz", - "integrity": "sha512-Sktq5axy0owk9PdnivBRNOJjHEVEibCt0+TDDZcv0+UH2KS1M910fX4kn5y45YFsrpZIi1mJf/1s5VzywMUnyg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@deepseek-ai/cordis/-/cordis-4.1.0.tgz", + "integrity": "sha512-CJrjNyBkKn1SfvBQUcgFYKFnLjS+uKrhdMsbHU60xabvi12d+xQ+IQSNlME5Z+B+4Zi6n4BDknKY94tEPeo47w==", "dev": true, "license": "MIT", "dependencies": { - "@deepseek-ai/cosmokit": "~1.8.6", + "@deepseek-ai/cosmokit": "~1.9.0", "@standard-schema/spec": "^1.1.0" }, "bin": { "cordis": "bin.js" }, "peerDependencies": { - "@deepseek-ai/cordis-plugin-include": "~1.0.10", - "@deepseek-ai/cordis-plugin-loader": "~1.0.6" + "@deepseek-ai/cordis-plugin-include": "~1.1.0", + "@deepseek-ai/cordis-plugin-loader": "~1.1.0" }, "peerDependenciesMeta": { "@deepseek-ai/cordis-plugin-include": { @@ -52,18 +52,18 @@ } }, "node_modules/@deepseek-ai/cosmokit": { - "version": "1.8.6", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.6.tgz", - "integrity": "sha512-ZSD/fN52L498LBIOYwjIOlaLv5veY6ZEwI2yzvZUKQtctn0QAPqu8tKdJ+OF5+Tv6NBq1U+wJWH+QI6OGy5EvQ==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.9.0.tgz", + "integrity": "sha512-5O1S53mZiJyZYcvxxD0Qv1EY7qFPSxbGyD8CbVK6gw7W9FvcXZj2YIX1ZkOqyQQ3Xt2rFkZDHJv0+V3Zmmp8CA==", "license": "MIT" }, "node_modules/@deepseek-ai/schemastery": { - "version": "3.18.5", - "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.5.tgz", - "integrity": "sha512-Mnobvqf9rHsZYv4g5edj5ddxS1oF1kIdSlz0DunUgnY3LWG5F26MqvH3YOOsSaodCgyzJ16OMN9O99/s5Crtdw==", + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.19.0.tgz", + "integrity": "sha512-bDXoYQa7ghAhmdYD5VPlzKxEzJV/aKkz5l4V5h1u06z8GAPN1ROewSjvR9WiXhpa52E9fng8lpH5QdCRIQgnyQ==", "license": "MIT", "dependencies": { - "@deepseek-ai/cosmokit": "~1.8.6", + "@deepseek-ai/cosmokit": "~1.9.0", "@standard-schema/spec": "^1.1.0" } }, diff --git a/package.json b/package.json index d21b060..88ee574 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dsh-plugin-usage", "description": "Token usage statistics for DeepSeek Harness — daily/custom-range views, model filters, call counts and cost, inspired by CC Switch statistics.", - "version": "0.5.0", + "version": "0.5.1", "license": "MIT", "repository": { "type": "git", @@ -46,7 +46,7 @@ }, "dsh": { "manifestVersion": 1, - "verifiedAgainst": "0.2.1-rc.4", + "verifiedAgainst": "0.2.2-rc.1", "bundle": { "patch": "./cordis.patch.yml" }, @@ -55,19 +55,20 @@ "@deepseek-ai/dsh-client-runtime", "@deepseek-ai/dsh-client-ui-settings", "@deepseek-ai/dsh-client-locale", - "@deepseek-ai/dsh-client-ui-conversation" + "@deepseek-ai/dsh-client-ui-conversation", + "@deepseek-ai/dsh-client-ui-settings-general" ], "platform": "web" } }, "dependencies": { - "@deepseek-ai/schemastery": "~3.18.5" + "@deepseek-ai/schemastery": "~3.19.0" }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.5" + "@deepseek-ai/cordis": "~4.1.0" }, "devDependencies": { - "@deepseek-ai/cordis": "~4.0.5", + "@deepseek-ai/cordis": "~4.1.0", "@types/react": "~18.3.1", "react": "^18.2.0", "typescript": "^5.5.0" diff --git a/src/client/index.js b/src/client/index.js index fbec04f..65edb05 100644 --- a/src/client/index.js +++ b/src/client/index.js @@ -4412,86 +4412,27 @@ function StatsDashboard(props) { } /* --------------------------------------------------------------------------- - * 设置页导航图标 + * 设置页导航图标(官方槽位) * - * 原生确实没有这个插口 —— 取证过的,不是"我觉得": - * · 官方设置页把 `settings.section` 的条目投影成 `{id, order, label}` 三字段, - * 没有 icon(`@deepseek-ai/dsh-client-ui-settings-general` 的 nav rows - * getSnapshot:`ctx.slots.entries("settings.section").map(e => ({id, order, - * label: resolveSlotLabel(e.options.label)}))`); - * · 图标由该包自己的 `navIcon(id)` 按 id 白名单选,未列出的 id 回落到设置齿轮 - * (同包 `function navIcon(id)`,其注释原文 "unknown ids fall back to the - * settings gear")。 - * 所以第三方只能给自己的那一行打属性标记、用 CSS mask 换字形:不替换节点、不碰 - * React 管的 svg(替换会让 React 卸载时抛 NotFoundError),只加属性、只用 ::before - * 画字形。官方一旦给 `settings.section` 加上 icon 字段,这个模块应整体删除 —— - * 那时它是可引用的 L0,不该再留 L2 补缺。 + * DSH 0.2.2-rc.1 起,设置页自带 `settings.section.icon`(list / inline / root, + * 声明在 `@deepseek-ai/dsh-client-ui-settings-general` 的 slots 契约里):nav rows + * 用 `renderSlot("settings.section.icon", { size, active }, { only: row.id })` + * 渲染,**注册 id 必须等于目标 section 的 id**,对不上的 id 永不渲染,没有注册的 + * id 回落到官方齿轮。 * - * 认行只能按可见文本:类名是 CSS Modules 哈希,账号行还会条件出现。 - * 官方一旦给 settings.section 加上 icon 字段,这个模块应整体删除。 + * 0.2.1 及更早没有这个槽位,本插件用「属性标记 + CSS mask」改字形(DOM 补缺); + * 官方补上后按当时的约定整体删除 —— 它现在是可以引用的 L0,不该再留 L2。 + * 旧内核没有这个槽时 inject 不触发,行内图标退化成齿轮,其余一切不变。 * ------------------------------------------------------------------------- */ -const NAV_ICON_MASK = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent( - '' - + '' - + '' - + '', -) -// mask 只读 alpha 通道,所以字形必须是纯色实心(icon.svg 的渐变与半透明在这里会丢) -const NAV_ICON_CSS = [ - '[data-tsd-nav] > svg { display: none; }', - '[data-tsd-nav]::before {', - " content: '';", - ' flex: none;', - ' width: 16px;', - ' height: 16px;', - ' background: currentColor;', - ' -webkit-mask-image: url("' + NAV_ICON_MASK + '");', - ' mask-image: url("' + NAV_ICON_MASK + '");', - ' -webkit-mask-size: 16px 16px;', - ' mask-size: 16px 16px;', - ' -webkit-mask-repeat: no-repeat;', - ' mask-repeat: no-repeat;', - '}', -].join('\n') - -/** 认不出行、拿不到 DOM,都只是退化成齿轮,绝不抛出。返回 disposer。 */ -function installSettingsNavIcon(label) { - if (typeof document === 'undefined' || typeof MutationObserver !== 'function') return null - let styleEl = null - try { - styleEl = document.createElement('style') - styleEl.setAttribute('data-plugin', 'dsh-plugin-usage') - styleEl.textContent = NAV_ICON_CSS - document.head.appendChild(styleEl) - } catch (e) { - logWarn('[usage] settings nav icon: styles unavailable') - return null - } - const mark = () => { - const rows = document.querySelectorAll('[role="dialog"] button') - const want = label() - for (let i = 0; i < rows.length; i++) { - const row = rows[i] - if (row.getAttribute('data-tsd-nav') !== null) continue - if (!row.querySelector('svg')) continue // 只标带图标的导航行,别误标普通按钮 - if ((row.textContent || '').trim() !== want) continue - row.setAttribute('data-tsd-nav', '') - } - } - let observer = null - try { - mark() - observer = new MutationObserver(() => { try { mark() } catch (e) {} }) - observer.observe(document.body, { childList: true, subtree: true }) - } catch (e) { - logWarn('[usage] settings nav icon: observer unavailable', e) - } - return () => { - if (observer) observer.disconnect() - if (styleEl) styleEl.remove() - const marked = document.querySelectorAll('[data-tsd-nav]') - for (let i = 0; i < marked.length; i++) marked[i].removeAttribute('data-tsd-nav') - } +function SettingsNavIcon(props) { + const size = props && typeof props.size === 'number' ? props.size : 16 + return h('svg', { + width: size, height: size, viewBox: '0 0 16 16', + 'aria-hidden': 'true', focusable: 'false', + }, + h('rect', { x: 2.5, y: 9, width: 2.5, height: 5, rx: 1, fill: 'currentColor' }), + h('rect', { x: 6.75, y: 5.5, width: 2.5, height: 8.5, rx: 1, fill: 'currentColor' }), + h('rect', { x: 11, y: 2.5, width: 2.5, height: 11.5, rx: 1, fill: 'currentColor' })) } /* --------------------------------------------------------------------------- @@ -4608,7 +4549,6 @@ function apply(ctx) { }, 'usage: styles') ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'usage: dictionaries') const t0 = ctx.locale ? ctx.locale.bind(NS) : fallbackT - ctx.effect(() => installSettingsNavIcon(() => t0('nav')), 'usage: nav-icon') // cordis ctx is a strict proxy: DIRECT property access on an un-injected // service throws ("cannot get property X without inject"), so a bare // `ctx.slots ?? ...` would throw and skip the fallback. Probe via the safe @@ -4636,6 +4576,17 @@ function apply(ctx) { (props) => h(StatsDashboard, props), )) + // 导航图标:官方 0.2.2-rc.1 的 settings.section.icon,按 section id 对齐。 + // 旧内核没有这个槽,inject 不触发(退化成官方齿轮),不能拖垮设置页。 + try { + slots.inject('settings.section.icon', () => slots.register( + { name: 'settings.section.icon', id: 'token-stats', order: 0, locale: NS }, + (props) => h(SettingsNavIcon, props), + )) + } catch (e) { + console.warn('[usage] settings nav icon slot unavailable', e) + } + // 输入区成本 pill。0.2.1 的 composer dock 是 list slot,宿主自己占了 activity(0) // 与 usage(1),插件排在它们之后;0.2.0 没有这个 slot,注入失败不能拖垮设置页。 try { diff --git a/tests/client-settings-icon.test.js b/tests/client-settings-icon.test.js new file mode 100644 index 0000000..7a32714 --- /dev/null +++ b/tests/client-settings-icon.test.js @@ -0,0 +1,62 @@ +/** + * Settings navigation icon coverage (DSH 0.2.2-rc.1 native slot). + * + * 0.2.1 and earlier projected `settings.section` as `{id, order, label}` with no + * icon hook, so this plugin painted its own glyph by marking the rendered row and + * swapping the shape with a CSS mask. The code carried its own expiry note: once + * the official slot exists, that workaround must be deleted rather than kept as + * a parallel path. + * + * 0.2.2-rc.1 ships `settings.section.icon` (list / inline / root, declared by + * `@deepseek-ai/dsh-client-ui-settings-general`). Its contract is stricter than a + * usual list slot: the registration id must equal the target section id, because + * the nav renders `renderSlot(..., { only: row.id })` — an unmatched id never + * renders, with no error. That is exactly the silent failure this file pins. + */ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const root = fileURLToPath(new URL('..', import.meta.url)); +const clientSource = readFileSync(join(root, 'src/client/index.js'), 'utf8'); +const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')); + +test('the nav icon registers into settings.section.icon under the section id', () => { + assert.match(clientSource, /slots\.inject\('settings\.section\.icon'/); + // `only: row.id` matches on the registration id, so a mismatch renders nothing. + assert.match( + clientSource, + /name: 'settings\.section\.icon', id: 'token-stats'/, + 'the icon registration id must equal the settings.section id (token-stats)', + ); + assert.match( + clientSource, + /name: 'settings\.section', id: 'token-stats'/, + 'the section id this icon is addressed to must still be token-stats', + ); +}); + +test('the DOM icon workaround is gone, not left as a second path', () => { + // Keeping the old hack alongside the native slot would paint two glyphs. + for (const banned of ['data-tsd-nav', 'installSettingsNavIcon', 'NAV_ICON_MASK', 'NAV_ICON_CSS']) { + assert.ok(!clientSource.includes(banned), `the 0.2.1 workaround must be deleted (${banned})`); + } +}); + +test('the icon is sized by the owner and coloured by the theme', () => { + const from = clientSource.indexOf('function SettingsNavIcon'); + assert.ok(from >= 0, 'SettingsNavIcon must exist'); + const body = clientSource.slice(from, from + 700); + assert.match(body, /props\.size/, 'the owner passes {size} and the icon must honour it'); + assert.match(body, /fill: 'currentColor'/, 'the glyph must inherit the nav row colour'); + assert.ok(!/#[0-9a-fA-F]{3,8}\b/.test(body), 'no hard-coded colour in the icon'); +}); + +test('the bundle is allowed to see the slot owner module', () => { + assert.ok( + pkg.dsh.client.inject.includes('@deepseek-ai/dsh-client-ui-settings-general'), + 'dsh.client.inject must name @deepseek-ai/dsh-client-ui-settings-general', + ); +});