dsh-background-by-model 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -20
- package/README.zh.md +13 -20
- package/lib/client.js +2 -1642
- package/lib/client.js.map +1 -1
- package/lib/index.js +0 -24
- package/package.json +4 -9
- package/lib/host-scan-B-xmbcxD.js +0 -1182
- package/lib/host-scan.js +0 -2
- package/lib/testing.js +0 -613
- package/scripts/host-contract-scan.mjs +0 -182
- package/test/host-check.test.mjs +0 -459
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Host-contract scan — run this after a dsh upgrade.
|
|
3
|
-
*
|
|
4
|
-
* pnpm bundle && node scripts/host-contract-scan.mjs [--host <dir>] [--json]
|
|
5
|
-
*
|
|
6
|
-
* The settings page's "Host check" tab answers the same question against the
|
|
7
|
-
* RUNNING host, from the DOM, the host stylesheets and the Cordis services. This
|
|
8
|
-
* answers it with no browser at all, straight from the installed files — which is
|
|
9
|
-
* what makes it runnable in CI, or right after `npm i -g @deepseek-ai/dsh@latest`
|
|
10
|
-
* and before anyone looks at the interface.
|
|
11
|
-
*
|
|
12
|
-
* It exits non-zero the moment a contract target is gone, so a host rename turns
|
|
13
|
-
* into a red build instead of a support report. `src/host-contracts.ts` is the
|
|
14
|
-
* single source of truth for WHAT is checked — this script only drives it, which
|
|
15
|
-
* is why a newly added contract point cannot be forgotten here.
|
|
16
|
-
*
|
|
17
|
-
* It reads the built `lib/host-scan.js` (a node entry of its own) rather than the
|
|
18
|
-
* TypeScript sources: that is the code that actually ships, and it keeps this
|
|
19
|
-
* script runnable by plain `node` with no flags and no loader.
|
|
20
|
-
*/
|
|
21
|
-
import { readFile, readdir } from 'node:fs/promises'
|
|
22
|
-
import { dirname, join, resolve } from 'node:path'
|
|
23
|
-
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
24
|
-
|
|
25
|
-
const here = dirname(fileURLToPath(import.meta.url))
|
|
26
|
-
const pluginDir = resolve(here, '..')
|
|
27
|
-
|
|
28
|
-
const exists = async (p) => { try { await readFile(p); return true } catch { return false } }
|
|
29
|
-
|
|
30
|
-
const scanPath = join(pluginDir, 'lib', 'host-scan.js')
|
|
31
|
-
if (!(await exists(scanPath))) {
|
|
32
|
-
console.error(`contract scan: ${scanPath} is missing — run "pnpm bundle" first`)
|
|
33
|
-
process.exit(2)
|
|
34
|
-
}
|
|
35
|
-
const { HOST_CONTRACTS, DSH_FLOOR, checkHostOnDisk, resolveHostRoots, meetsFloor, versionOf } =
|
|
36
|
-
await import(pathToFileURL(scanPath).href)
|
|
37
|
-
|
|
38
|
-
const args = process.argv.slice(2)
|
|
39
|
-
const json = args.includes('--json')
|
|
40
|
-
const hostFlag = args.indexOf('--host')
|
|
41
|
-
if (hostFlag >= 0 && args[hostFlag + 1] !== undefined) {
|
|
42
|
-
process.env.DAB_HOST_ROOT = args[hostFlag + 1]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Every installation of the host this machine can reach.
|
|
47
|
-
*
|
|
48
|
-
* A contract holds when ANY of them still contains the literal, because the dsh
|
|
49
|
-
* that is running may not be the one a dev checkout resolves first. The roots the
|
|
50
|
-
* plugin itself would pick come first, then the two layouts this project ships
|
|
51
|
-
* against (a global npm install, and a dsh profile's own node_modules).
|
|
52
|
-
*/
|
|
53
|
-
async function hostCandidates() {
|
|
54
|
-
const found = []
|
|
55
|
-
const push = (base, origin) => {
|
|
56
|
-
base = resolve(base)
|
|
57
|
-
if (!found.some(f => f.base === base)) found.push({ base, origin })
|
|
58
|
-
}
|
|
59
|
-
const resolved = await resolveHostRoots(pluginDir)
|
|
60
|
-
if (resolved.roots !== null) push(resolved.roots.packages, 'resolved')
|
|
61
|
-
// Two shipped layouts: a global npm install keeps its own `@deepseek-ai` scope
|
|
62
|
-
// (`dsh` moves to its latest release each time), and the dsh version the profile
|
|
63
|
-
// actually loads lives in that package's nested node_modules.
|
|
64
|
-
const roots = []
|
|
65
|
-
const appData = process.env.APPDATA
|
|
66
|
-
if (typeof appData === 'string' && appData !== '') roots.push(join(appData, 'npm', 'node_modules', '@deepseek-ai'))
|
|
67
|
-
const profileDir = process.env.DSH_PROFILE_DIR
|
|
68
|
-
if (typeof profileDir === 'string' && profileDir !== '') roots.push(join(profileDir, 'node_modules', '@deepseek-ai'))
|
|
69
|
-
const home = process.env.USERPROFILE ?? process.env.HOME
|
|
70
|
-
if (typeof home === 'string' && home !== '') roots.push(join(home, '.dsh', 'profiles'))
|
|
71
|
-
for (const root of roots) {
|
|
72
|
-
push(root, 'npm scope')
|
|
73
|
-
push(join(root, 'dsh', 'node_modules', '@deepseek-ai'), 'dsh nested')
|
|
74
|
-
}
|
|
75
|
-
return found
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const usable = []
|
|
79
|
-
for (const candidate of await hostCandidates()) {
|
|
80
|
-
// A scope counts only when it holds the UI plugin packages the contracts name.
|
|
81
|
-
// The runtime package itself may be a sibling (`<scope>/dsh`) or absent — on a
|
|
82
|
-
// global npm install the version the profile actually loads sits one level down,
|
|
83
|
-
// in `<scope>/dsh/node_modules/@deepseek-ai`, where `dsh` is NOT repeated — so
|
|
84
|
-
// requiring `<scope>/dsh/package.json` would reject the only real host on this
|
|
85
|
-
// machine and report every contract as missing.
|
|
86
|
-
if (!(await exists(join(candidate.base, 'dsh-client-ui-theme', 'lib', 'client.js')))) continue
|
|
87
|
-
const named = join(candidate.base, 'dsh', 'package.json')
|
|
88
|
-
const nested = join(candidate.base, 'dsh-app-boot', 'package.json')
|
|
89
|
-
const manifest = (await exists(named)) ? named : ((await exists(nested)) ? nested : '')
|
|
90
|
-
// The served frontend is NOT necessarily a sibling of the package scope: on a
|
|
91
|
-
// global install the scope lives inside the `dsh` package, so its web frontend
|
|
92
|
-
// is at `<sourceDir>/dsh-web-frontend`. Prefer wherever that package really is.
|
|
93
|
-
let frontend = join(candidate.base, 'dsh-web-frontend', 'dist', 'assets')
|
|
94
|
-
for (const guess of [join(dirname(candidate.base), 'dsh-web-frontend'), join(candidate.base, 'dsh', 'node_modules', '@deepseek-ai', 'dsh-web-frontend')]) {
|
|
95
|
-
if (await exists(join(guess, 'dist', 'assets'))) { frontend = join(guess, 'dist', 'assets'); break }
|
|
96
|
-
}
|
|
97
|
-
usable.push({ ...candidate, manifest, frontend })
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (usable.length === 0) {
|
|
101
|
-
const report = await checkHostOnDisk(pluginDir, 'en')
|
|
102
|
-
console.error('contract scan: no installed dsh was found.')
|
|
103
|
-
if (report.host.note !== '') console.error(` ${report.host.note}`)
|
|
104
|
-
console.error(' pass --host <dir containing @deepseek-ai/dsh-app-boot> or set DAB_HOST_ROOT')
|
|
105
|
-
process.exit(2)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** How one contract's sources fare in one candidate installation. */
|
|
109
|
-
async function checkOne(contract, candidate) {
|
|
110
|
-
const bad = []
|
|
111
|
-
for (const source of contract.sources) {
|
|
112
|
-
const root = source.root === 'frontend' ? candidate.frontend : candidate.base
|
|
113
|
-
// `.` names the root directory: the literal is searched across the script and
|
|
114
|
-
// stylesheet files in it, for targets whose FILE name is not stable.
|
|
115
|
-
if (source.path === '.') {
|
|
116
|
-
let names = []
|
|
117
|
-
try { names = await readdir(root) } catch { /* missing */ }
|
|
118
|
-
let hit = ''
|
|
119
|
-
for (const name of names) {
|
|
120
|
-
if (!/\.(?:js|mjs|cjs|css|html|json)$/i.test(name)) continue
|
|
121
|
-
try {
|
|
122
|
-
if ((await readFile(join(root, name), 'utf8')).includes(source.literal)) { hit = name; break }
|
|
123
|
-
} catch { /* unreadable entry */ }
|
|
124
|
-
}
|
|
125
|
-
if (hit === '') bad.push(`${root} — no ${JSON.stringify(source.literal)} in any asset`)
|
|
126
|
-
continue
|
|
127
|
-
}
|
|
128
|
-
const file = source.path.startsWith('src/') ? join(pluginDir, source.path) : join(root, source.path)
|
|
129
|
-
let text = null
|
|
130
|
-
try { text = await readFile(file, 'utf8') } catch { /* missing */ }
|
|
131
|
-
if (text === null) bad.push(`${source.path} — file missing`)
|
|
132
|
-
else if (!text.includes(source.literal)) bad.push(`${source.path} — no ${JSON.stringify(source.literal)}`)
|
|
133
|
-
}
|
|
134
|
-
return bad
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const rows = []
|
|
138
|
-
for (const contract of HOST_CONTRACTS) {
|
|
139
|
-
let best = null
|
|
140
|
-
for (const candidate of usable) {
|
|
141
|
-
const bad = await checkOne(contract, candidate)
|
|
142
|
-
if (bad.length === 0) { best = { candidate, bad: [] }; break }
|
|
143
|
-
if (best === null || bad.length < best.bad.length) best = { candidate, bad }
|
|
144
|
-
}
|
|
145
|
-
rows.push({
|
|
146
|
-
id: contract.id,
|
|
147
|
-
group: contract.group,
|
|
148
|
-
criticality: contract.criticality,
|
|
149
|
-
target: contract.target,
|
|
150
|
-
ok: best !== null && best.bad.length === 0,
|
|
151
|
-
why: best === null ? ['no host found'] : best.bad,
|
|
152
|
-
where: best === null ? '' : best.candidate.origin,
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const hosts = []
|
|
157
|
-
for (const candidate of usable) {
|
|
158
|
-
const version = candidate.manifest === '' ? '' : await versionOf(dirname(candidate.manifest))
|
|
159
|
-
hosts.push({ origin: candidate.origin, path: candidate.base, version, meetsFloor: meetsFloor(version, DSH_FLOOR) })
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (json) {
|
|
163
|
-
console.log(JSON.stringify({ floor: DSH_FLOOR, hosts, contracts: rows }, null, 2))
|
|
164
|
-
} else {
|
|
165
|
-
console.log('dsh-background-by-model — host contract scan')
|
|
166
|
-
console.log(`floor: dsh >=${DSH_FLOOR}`)
|
|
167
|
-
for (const h of hosts) {
|
|
168
|
-
const verdict = h.meetsFloor === null ? 'unknown' : h.meetsFloor ? 'ok' : 'BELOW FLOOR'
|
|
169
|
-
console.log(`host : ${h.version !== '' ? h.version : 'unreadable'} [${verdict}] ${h.path}`)
|
|
170
|
-
}
|
|
171
|
-
console.log('')
|
|
172
|
-
let failed = 0
|
|
173
|
-
for (const row of rows) {
|
|
174
|
-
if (!row.ok) failed++
|
|
175
|
-
console.log(`${row.ok ? 'PASS' : 'FAIL'} ${row.id.padEnd(30)} ${row.target}`)
|
|
176
|
-
for (const why of row.why) console.log(` > ${why}`)
|
|
177
|
-
}
|
|
178
|
-
console.log('')
|
|
179
|
-
console.log(`${rows.length - failed}/${rows.length} contracts hold`)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
process.exit(rows.some(r => !r.ok) ? 1 : 0)
|
package/test/host-check.test.mjs
DELETED
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The host self-check's own tests 鈥?run with
|
|
3
|
-
*
|
|
4
|
-
* pnpm test
|
|
5
|
-
*
|
|
6
|
-
* Three things are covered, and they are the three that can rot silently:
|
|
7
|
-
*
|
|
8
|
-
* 1. **The contract table holds together** 鈥?unique ids, machine-checkable
|
|
9
|
-
* sources, a known criticality, and at least one check or an explicit
|
|
10
|
-
* "documentation only" marker. A contract point added without a source would
|
|
11
|
-
* otherwise be invisible to the offline scan.
|
|
12
|
-
* 2. **The probe reports what is actually there** 鈥?the whole probe is driven
|
|
13
|
-
* against a fixture written in the shape of a host DOM, so "the host renamed
|
|
14
|
-
* `--dsw-specific-menu`" produces exactly the failure the panel claims, and a
|
|
15
|
-
* surface that is merely off screen produces `n/a` rather than a false alarm.
|
|
16
|
-
* 3. **The UI stylesheet, and the one piece of version logic** 鈥?every `dab-*`
|
|
17
|
-
* class a component uses is defined in it, and the floor comparison is exact
|
|
18
|
-
* on the release triple.
|
|
19
|
-
*
|
|
20
|
-
* The tests run against the BUILT node entries (`lib/testing.js`), not the
|
|
21
|
-
* TypeScript sources: `node --test` cannot resolve extensionless relative imports
|
|
22
|
-
* inside a `.ts` file, and asserting on the shipped bundle is the more honest
|
|
23
|
-
* target anyway. `pnpm test` bundles first.
|
|
24
|
-
*/
|
|
25
|
-
import { test } from 'node:test'
|
|
26
|
-
import assert from 'node:assert/strict'
|
|
27
|
-
import { dirname, join, resolve } from 'node:path'
|
|
28
|
-
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
29
|
-
|
|
30
|
-
const here = dirname(fileURLToPath(import.meta.url))
|
|
31
|
-
const pluginDir = resolve(here, '..')
|
|
32
|
-
const testingPath = join(pluginDir, 'lib', 'testing.js')
|
|
33
|
-
|
|
34
|
-
const { HOST_CONTRACTS, DSH_FLOOR, probeContracts, verdictOf, meetsFloor, UI_CSS, OWN_SHEET_ATTR, OWN_SHEET_DATASET } =
|
|
35
|
-
await import(pathToFileURL(testingPath).href)
|
|
36
|
-
|
|
37
|
-
const { readFile, readdir } = await import('node:fs/promises')
|
|
38
|
-
|
|
39
|
-
// 鈹€鈹€ 1. the contract table 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
40
|
-
|
|
41
|
-
test('contract ids are unique and non-empty', () => {
|
|
42
|
-
const seen = new Set()
|
|
43
|
-
for (const c of HOST_CONTRACTS) {
|
|
44
|
-
assert.ok(c.id.length > 0, 'a contract has an empty id')
|
|
45
|
-
assert.ok(!seen.has(c.id), `duplicate contract id ${c.id}`)
|
|
46
|
-
seen.add(c.id)
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('every contract is machine-checkable', () => {
|
|
51
|
-
for (const c of HOST_CONTRACTS) {
|
|
52
|
-
assert.ok(c.target.length > 0, `${c.id} has no target`)
|
|
53
|
-
assert.ok(c.sources.length > 0, `${c.id} declares no source, so the offline scan cannot see it`)
|
|
54
|
-
assert.ok(c.usedBy.length > 0, `${c.id} does not say which plugin file reads it`)
|
|
55
|
-
assert.ok(['core', 'looks', 'label'].includes(c.criticality), `${c.id} has an unknown criticality`)
|
|
56
|
-
assert.ok(['<=0.1.6', '0.1.7'].includes(c.since), `${c.id} has an unknown "since"`)
|
|
57
|
-
for (const s of c.sources) {
|
|
58
|
-
assert.ok(s.literal.length > 0, `${c.id} has a source without a literal`)
|
|
59
|
-
assert.ok(!s.path.includes('\\'), `${c.id} source path must use forward slashes: ${s.path}`)
|
|
60
|
-
if (s.path === '.') assert.equal(s.root, 'frontend', `${c.id}: "." only makes sense for the frontend root`)
|
|
61
|
-
}
|
|
62
|
-
if (c.checks.length === 0) {
|
|
63
|
-
// Documentation-only entries are allowed (a legacy alias we still accept),
|
|
64
|
-
// but they must be the minority and must not claim to be checkable.
|
|
65
|
-
assert.ok(c.criticality !== 'core', `${c.id} is critical but has no check`)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
test('critical contracts carry a check that can fail', () => {
|
|
71
|
-
const critical = HOST_CONTRACTS.filter(c => c.criticality === 'core')
|
|
72
|
-
assert.ok(critical.length >= 4, 'the model hop and the menu split should be critical')
|
|
73
|
-
for (const c of critical) {
|
|
74
|
-
assert.ok(c.checks.length > 0, `${c.id} is critical but nothing verifies it at runtime`)
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
// 鈹€鈹€ 2. the probe, against a fixture in the shape of a host DOM 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
79
|
-
|
|
80
|
-
/** A DOM stand-in with just enough selector support for the contract checks. */
|
|
81
|
-
function makeDom(host) {
|
|
82
|
-
/**
|
|
83
|
-
* `selector 鈫?present`, including attribute and comma-OR forms. A descendant
|
|
84
|
-
* selector is satisfied when every compound in it is present 鈥?the stand-in has
|
|
85
|
-
* no tree, and the contracts are written so that "the elements exist" is the
|
|
86
|
-
* question being asked.
|
|
87
|
-
*/
|
|
88
|
-
const one = part => {
|
|
89
|
-
// `*` is the universal selector: always satisfied.
|
|
90
|
-
if (part === '*') return true
|
|
91
|
-
if (host.has(part)) return true
|
|
92
|
-
const attr = /^\[([a-z-]+)\]$/.exec(part)
|
|
93
|
-
if (attr !== null && host.has(`[${attr[1]}]`)) return true
|
|
94
|
-
return false
|
|
95
|
-
}
|
|
96
|
-
const matches = sel => sel.split(',').map(p => p.trim()).some(
|
|
97
|
-
part => part.split(/\s+/).every(one),
|
|
98
|
-
)
|
|
99
|
-
return {
|
|
100
|
-
querySelector: sel => (matches(sel) ? { style: {} } : null),
|
|
101
|
-
// Where the host publishes its palette: `body` in the real client, and the
|
|
102
|
-
// fixture models exactly that. Reading the document element instead is what
|
|
103
|
-
// made seven healthy tokens report as empty.
|
|
104
|
-
tokenRoot: () => ({ style: {} }),
|
|
105
|
-
// `on` is null for an unscoped token check (the probe reads it off the token
|
|
106
|
-
// root) and the resolved element otherwise. The fixture answers from its own
|
|
107
|
-
// table either way 鈥?whether a value is readable is the host's own business,
|
|
108
|
-
// and that is exactly what the table stands in for.
|
|
109
|
-
computedValue: (token, _on) => (host.get(`computed:${token}`) ?? ''),
|
|
110
|
-
styleSheets: () => [],
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** Selectors for the surfaces that are on screen in every fixture. */
|
|
115
|
-
const CORE_PRESENT = [
|
|
116
|
-
'div[data-sidebar-right-panel]',
|
|
117
|
-
'div[role="dialog"][aria-modal="true"][aria-labelledby]',
|
|
118
|
-
'[data-shell-overlay]',
|
|
119
|
-
'[data-composer-card]',
|
|
120
|
-
'[data-cordis-panel]',
|
|
121
|
-
'[data-chat-flow]',
|
|
122
|
-
'[data-conversation-scroll]',
|
|
123
|
-
'[data-conversation-composer-overlay]',
|
|
124
|
-
'.dab-root',
|
|
125
|
-
'[data-dockkit-strip]',
|
|
126
|
-
]
|
|
127
|
-
|
|
128
|
-
/** Every design token the contracts read; each one resolves in a healthy host. */
|
|
129
|
-
const PRESENT_TOKENS = [
|
|
130
|
-
'--dsw-alias-bg-base',
|
|
131
|
-
'--dsw-alias-bg-layer-1',
|
|
132
|
-
'--dsw-alias-bg-layer-2',
|
|
133
|
-
'--dsw-alias-bg-layer-3',
|
|
134
|
-
'--dsw-specific-menu',
|
|
135
|
-
'--dsw-menu-surface-fill',
|
|
136
|
-
'--dsw-specific-sidebar-fill',
|
|
137
|
-
'--dsw-specific-input-major',
|
|
138
|
-
'--dsw-alias-label-caption',
|
|
139
|
-
]
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* The literals the HOST's stylesheets declare. The two halves of a token
|
|
143
|
-
* contract ask different questions 鈥?`rule` = "does the host still declare this
|
|
144
|
-
* name", `computed` = "does it resolve to a value" 鈥?so both are listed.
|
|
145
|
-
*/
|
|
146
|
-
const HOST_RULES = [
|
|
147
|
-
'--dsw-menu-surface-fill', '--dsw-specific-menu', '--dsw-specific-sidebar-fill',
|
|
148
|
-
'--dsw-specific-input-major', '--dsw-alias-bg-base', '--dsw-alias-bg-layer-1',
|
|
149
|
-
'--dsw-alias-label-caption',
|
|
150
|
-
'.md-table-wide', '[data-dockkit-content]', '[data-dockkit-empty]',
|
|
151
|
-
'[data-dockkit-float]', '[data-sidebar-right-open]', 'data-ds-dark-theme',
|
|
152
|
-
]
|
|
153
|
-
|
|
154
|
-
/** The one literal only THIS plugin's stylesheet declares (`.dab-card`, `side: 'own'`). */
|
|
155
|
-
const OWN_RULES = ['.dab-card']
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* A stylesheet the probe may read.
|
|
159
|
-
*
|
|
160
|
-
* `own: true` writes this plugin's marker 鈥?the ONLY thing that tells our sheets
|
|
161
|
-
* apart from the host's, since the host's own CSS modules set `data-plugin` on
|
|
162
|
-
* theirs, so a probe keying off that skips the entire host theme.
|
|
163
|
-
*
|
|
164
|
-
* The fixture exposes the attribute the way a REAL element does: `getAttribute`
|
|
165
|
-
* answers the dashed name, and `dataset` only the camel-cased key. Modelling this
|
|
166
|
-
* wrong is how a probe that reads `dataset['data-dab-side']` passes here and
|
|
167
|
-
* silently fails in a browser.
|
|
168
|
-
*/
|
|
169
|
-
function sheet(literals, own = false) {
|
|
170
|
-
const attrs = {}
|
|
171
|
-
const dataset = {}
|
|
172
|
-
if (own) {
|
|
173
|
-
attrs[OWN_SHEET_ATTR] = 'own'
|
|
174
|
-
dataset[OWN_SHEET_DATASET] = 'own'
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
ownerNode: {
|
|
178
|
-
dataset,
|
|
179
|
-
getAttribute: name => (name in attrs ? attrs[name] : null),
|
|
180
|
-
setAttribute: (name, value) => { attrs[name] = value },
|
|
181
|
-
},
|
|
182
|
-
cssRules: literals.map(l => ({ cssText: `.x{color:red}/* ${l} */` })),
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/** The host's sheets plus our own, minus whatever a test removes. */
|
|
187
|
-
function hostStyles(literals = HOST_RULES, ownLiterals = OWN_RULES) {
|
|
188
|
-
const sheets = [sheet(literals)]
|
|
189
|
-
if (ownLiterals.length > 0) sheets.push(sheet(ownLiterals, true))
|
|
190
|
-
return sheets
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* A fixture host: `selectors` are the ones that match, `rules` the literals the
|
|
195
|
-
* host stylesheet declares, and every token in `PRESENT_TOKENS` resolves unless
|
|
196
|
-
* the caller drops it.
|
|
197
|
-
*/
|
|
198
|
-
function hostEnv({ ctx, selectors = CORE_PRESENT, rules = HOST_RULES, tokens = PRESENT_TOKENS }) {
|
|
199
|
-
// A Map, not a Set: the fixture must answer with the token's VALUE, and only a
|
|
200
|
-
// Map carries one (a Set has no `get`).
|
|
201
|
-
const host = new Map()
|
|
202
|
-
for (const s of selectors) host.set(s, true)
|
|
203
|
-
for (const t of tokens) host.set(`computed:${t}`, '#123456')
|
|
204
|
-
return { ...makeDom(host), styleSheets: () => hostStyles(rules), ctx }
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* The two states the dock alternates between. In the real DOM they live in
|
|
209
|
-
* different panes (a populated tab host carries `data-dockkit-content`, an empty
|
|
210
|
-
* pane carries `data-dockkit-empty`), and each contract's anchor is what says
|
|
211
|
-
* whether its own attribute can be observed 鈥?so the fixture provides the anchor
|
|
212
|
-
* for every contract it expects to answer, and omits the anchors of the ones it
|
|
213
|
-
* expects to read as n/a.
|
|
214
|
-
*/
|
|
215
|
-
const DOCK_POPULATED = [
|
|
216
|
-
'div[data-sidebar-right-panel]',
|
|
217
|
-
'[data-dockkit-tab]',
|
|
218
|
-
'[data-dockkit-content]',
|
|
219
|
-
'[data-dockkit-empty]',
|
|
220
|
-
]
|
|
221
|
-
const DOCK_EMPTY = ['div[data-sidebar-right-panel]', '[data-dockkit-empty]']
|
|
222
|
-
|
|
223
|
-
/** The healthy fixtures: nothing missing, every service published. */
|
|
224
|
-
const healthyEnv = (dock = DOCK_POPULATED) => hostEnv({
|
|
225
|
-
ctx: healthyCtx(),
|
|
226
|
-
selectors: [...CORE_PRESENT, ...dock],
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
/** A context publishing the four services the model hop needs. */
|
|
230
|
-
function healthyCtx(overrides = {}) {
|
|
231
|
-
const face = { subscribe: () => () => {}, getSnapshot: () => ({}) }
|
|
232
|
-
const services = {
|
|
233
|
-
sessions: { list: face, binding: () => ({}) },
|
|
234
|
-
uiSession: { current: face },
|
|
235
|
-
modelDirectories: { directoryFor: () => ({ store: face }) },
|
|
236
|
-
...overrides,
|
|
237
|
-
}
|
|
238
|
-
return { get: id => services[id] }
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
test('a healthy host passes every contract, in either dock state', () => {
|
|
242
|
-
for (const [name, dock] of [['populated tab', DOCK_POPULATED], ['empty seat', DOCK_EMPTY]]) {
|
|
243
|
-
const results = probeContracts(healthyEnv(dock), 'en')
|
|
244
|
-
const failed = results.filter(r => r.status === 'fail')
|
|
245
|
-
assert.deepEqual(failed.map(r => r.id), [],
|
|
246
|
-
`unexpected failures with a ${name}: ${failed.map(r => `${r.id}: ${r.reason}`).join('; ')}`)
|
|
247
|
-
assert.equal(verdictOf({ results, summary: { pass: results.length, fail: 0, skip: 0, total: results.length } }), 'ok')
|
|
248
|
-
}
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
test('a renamed menu token fails exactly that contract, and names the symptom', () => {
|
|
252
|
-
// The 0.1.8 rename: the host stops declaring the token the sticky group
|
|
253
|
-
// headings paint from. Everything else still answers.
|
|
254
|
-
const env = hostEnv({ ctx: healthyCtx(), rules: HOST_RULES.filter(l => l !== '--dsw-menu-surface-fill') })
|
|
255
|
-
const results = probeContracts(env, 'en')
|
|
256
|
-
const failed = results.filter(r => r.status === 'fail').map(r => r.id)
|
|
257
|
-
assert.deepEqual(failed, ['token.menuSurface'])
|
|
258
|
-
const row = results.find(r => r.id === 'token.menuSurface')
|
|
259
|
-
assert.match(row.reason, /--dsw-menu-surface-fill/)
|
|
260
|
-
assert.match(row.symptom, /solid band|white band|sticky/i)
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
test('a renamed token the host still aliases is caught by the rule half', () => {
|
|
264
|
-
// The 0.1.7 menu split in reverse: the host keeps the OLD name working (aliased)
|
|
265
|
-
// but stops declaring the new one. `computed` still answers 鈥?which is exactly
|
|
266
|
-
// how that bug stayed silent 鈥?so the `rule` half is the only thing that can
|
|
267
|
-
// tell "renamed" from "still there".
|
|
268
|
-
const env = hostEnv({
|
|
269
|
-
ctx: healthyCtx(),
|
|
270
|
-
rules: HOST_RULES.filter(l => l !== '--dsw-menu-surface-fill'),
|
|
271
|
-
})
|
|
272
|
-
const results = probeContracts(env, 'en')
|
|
273
|
-
const row = results.find(r => r.id === 'token.menuSurface')
|
|
274
|
-
assert.equal(row.status, 'fail')
|
|
275
|
-
// The computed half would have passed: the token still resolves a value.
|
|
276
|
-
assert.match(row.detail, /host stylesheet includes/)
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
test('a host that stops publishing the palette fails the computed half', () => {
|
|
280
|
-
// The other failure shape: the name is still declared somewhere, but body no
|
|
281
|
-
// longer carries a value 鈥?the case that made 7 healthy tokens look empty when
|
|
282
|
-
// the probe read the wrong element.
|
|
283
|
-
const env = hostEnv({
|
|
284
|
-
ctx: healthyCtx(),
|
|
285
|
-
tokens: PRESENT_TOKENS.filter(t => t !== '--dsw-alias-bg-base'),
|
|
286
|
-
})
|
|
287
|
-
const results = probeContracts(env, 'en')
|
|
288
|
-
const row = results.find(r => r.id === 'token.bgBase')
|
|
289
|
-
assert.equal(row.status, 'fail')
|
|
290
|
-
assert.match(row.reason, /--dsw-alias-bg-base/)
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
test('a dropped session service fails the model hop', () => {
|
|
294
|
-
const env = hostEnv({ ctx: healthyCtx({ sessions: undefined }) })
|
|
295
|
-
const results = probeContracts(env, 'en')
|
|
296
|
-
assert.equal(results.find(r => r.id === 'sessions.list').status, 'fail')
|
|
297
|
-
assert.equal(results.find(r => r.id === 'sessions.binding.projections').status, 'skip')
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
test('the plugin\'s own token stylesheet cannot make a host check pass', () => {
|
|
301
|
-
// The situation that produced the 0.1.7 white band: the plugin re-emits the
|
|
302
|
-
// menu fill itself, so its own sheet declares the token. That re-emission must
|
|
303
|
-
// never be accepted as evidence about the HOST 鈥?otherwise the check is green
|
|
304
|
-
// by construction on exactly the host where the token was renamed away.
|
|
305
|
-
const env = hostEnv({
|
|
306
|
-
ctx: healthyCtx(),
|
|
307
|
-
// The host sheet is readable but has moved on: it no longer declares the
|
|
308
|
-
// menu fill under this name.
|
|
309
|
-
rules: [],
|
|
310
|
-
})
|
|
311
|
-
env.styleSheets = () => [
|
|
312
|
-
sheet([]), // the host's own, readable, declaring nothing
|
|
313
|
-
sheet(['--dsw-menu-surface-fill', '--dsw-specific-menu', '.dab-card'], true),
|
|
314
|
-
]
|
|
315
|
-
const results = probeContracts(env, 'en')
|
|
316
|
-
const byId = id => results.find(r => r.id === id)
|
|
317
|
-
assert.equal(byId('token.menuSurface').status, 'fail')
|
|
318
|
-
assert.match(byId('token.menuSurface').reason, /no host stylesheet declares/)
|
|
319
|
-
assert.equal(byId('token.menuAlias').status, 'fail')
|
|
320
|
-
// 鈥hile the contract whose other half IS our own sheet still passes: this is
|
|
321
|
-
// what `side: 'own'` is for, and why the two sides must never be merged.
|
|
322
|
-
assert.equal(byId('settings.card').status, 'pass')
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
test('a host sheet carrying data-plugin is not mistaken for ours', () => {
|
|
326
|
-
// Regression for the probe bug that reported 7 healthy tokens as renamed: the
|
|
327
|
-
// host's CSS modules ALSO set `data-plugin` on their <style> elements, so a
|
|
328
|
-
// probe that skips "sheets with data-plugin" skips the host's whole theme.
|
|
329
|
-
const hostSheet = sheet(['--dsw-alias-bg-base'])
|
|
330
|
-
hostSheet.ownerNode.dataset.plugin = '@deepseek-ai/dsh-client-ui-theme'
|
|
331
|
-
const env = hostEnv({ ctx: healthyCtx(), rules: [] })
|
|
332
|
-
env.styleSheets = () => [hostSheet]
|
|
333
|
-
const results = probeContracts(env, 'en')
|
|
334
|
-
assert.equal(results.find(r => r.id === 'token.bgBase').status, 'pass')
|
|
335
|
-
})
|
|
336
|
-
|
|
337
|
-
test('a closed dock holding only its empty seat is n/a, not a failure', () => {
|
|
338
|
-
// The state a healthy host sits in most of the time: the dock holds no tab, so
|
|
339
|
-
// `data-dockkit-content` (a JS-set attribute the host never styles) cannot be
|
|
340
|
-
// observed at all. It used to read as "no host stylesheet declares it" 鈥?a
|
|
341
|
-
// perfectly healthy host reported as broken.
|
|
342
|
-
const env = healthyEnv(DOCK_EMPTY)
|
|
343
|
-
const results = probeContracts(env, 'en')
|
|
344
|
-
const byId = id => results.find(r => r.id === id)
|
|
345
|
-
assert.equal(byId('dockkit.content').status, 'skip')
|
|
346
|
-
// The empty seat IS on screen here, so its own contract answers.
|
|
347
|
-
assert.equal(byId('dockkit.empty').status, 'pass')
|
|
348
|
-
assert.equal(byId('dockkit.float').status, 'skip')
|
|
349
|
-
assert.deepEqual(results.filter(r => r.status === 'fail').map(r => r.id), [])
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
test('a renamed dock tab attribute still fails once a tab is open', () => {
|
|
353
|
-
// The guard must not swallow a real rename: with a tab open the host has to
|
|
354
|
-
// carry `data-dockkit-content` on the tab host, and if the name moved, say so.
|
|
355
|
-
// A populated tab is on screen (the host marks the tab chip), but the attribute
|
|
356
|
-
// the contract names no longer matches anything.
|
|
357
|
-
const env = hostEnv({
|
|
358
|
-
ctx: healthyCtx(),
|
|
359
|
-
selectors: ['div[data-sidebar-right-panel]', '[data-dockkit-tab]'],
|
|
360
|
-
})
|
|
361
|
-
const results = probeContracts(env, 'en')
|
|
362
|
-
const row = results.find(r => r.id === 'dockkit.content')
|
|
363
|
-
assert.equal(row.status, 'fail')
|
|
364
|
-
assert.match(row.reason, /data-dockkit-content/)
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
test('a floating pane missing its flag is a failure while it is on screen', () => {
|
|
368
|
-
// The float flag is a JS attribute too, so it is only observable when the user
|
|
369
|
-
// has a pane floated 鈥?and then, if the host stopped setting it, the plugin
|
|
370
|
-
// would paint that pane like a docked one.
|
|
371
|
-
const env = hostEnv({
|
|
372
|
-
ctx: healthyCtx(),
|
|
373
|
-
selectors: [...CORE_PRESENT, ...DOCK_POPULATED, '[data-sidebar-right-mode="float"]'],
|
|
374
|
-
})
|
|
375
|
-
const results = probeContracts(env, 'en')
|
|
376
|
-
const row = results.find(r => r.id === 'dockkit.float')
|
|
377
|
-
assert.equal(row.status, 'fail')
|
|
378
|
-
assert.match(row.reason, /data-dockkit-float/)
|
|
379
|
-
})
|
|
380
|
-
|
|
381
|
-
test('a surface that is merely off screen is n/a, not a failure', () => {
|
|
382
|
-
// The app frame and every service are up (the settings section is rendered
|
|
383
|
-
// inside the frame, so the frame is always there) 鈥?but the conversation view,
|
|
384
|
-
// the right panel and the Cordis panel are not. Nothing is broken; those
|
|
385
|
-
// surfaces simply are not there to observe.
|
|
386
|
-
const env = hostEnv({
|
|
387
|
-
ctx: healthyCtx(),
|
|
388
|
-
selectors: ['.dab-root', 'div[role="dialog"][aria-modal="true"][aria-labelledby]', '[data-shell-overlay]'],
|
|
389
|
-
})
|
|
390
|
-
const results = probeContracts(env, 'en')
|
|
391
|
-
const byId = id => results.find(r => r.id === id)
|
|
392
|
-
assert.equal(byId('chat.flow').status, 'skip')
|
|
393
|
-
assert.equal(byId('conversation.scroll').status, 'skip')
|
|
394
|
-
assert.equal(byId('trajectory.root').status, 'skip')
|
|
395
|
-
assert.equal(byId('rightbar.panel').status, 'skip')
|
|
396
|
-
assert.equal(byId('cordis.panel').status, 'skip')
|
|
397
|
-
assert.equal(byId('composer.card').status, 'skip')
|
|
398
|
-
assert.equal(byId('settings.dialog').status, 'pass')
|
|
399
|
-
assert.deepEqual(results.filter(r => r.status === 'fail').map(r => r.id), [])
|
|
400
|
-
})
|
|
401
|
-
|
|
402
|
-
test('a mounted but marker-less surface is a failure, not n/a', () => {
|
|
403
|
-
// The dialog is open, so the right panel's anchor is off screen 鈥?but the
|
|
404
|
-
// dialog's own selector still matches. A surface whose anchor IS on screen and
|
|
405
|
-
// whose selector is not is a rename, and must not read as "not observable".
|
|
406
|
-
const env = hostEnv({
|
|
407
|
-
ctx: healthyCtx(),
|
|
408
|
-
// The dock chrome is mounted (the panel container exists) but the panel
|
|
409
|
-
// attribute the contract names is gone.
|
|
410
|
-
selectors: ['.dab-root', '[data-dockkit-strip]'],
|
|
411
|
-
})
|
|
412
|
-
const results = probeContracts(env, 'en')
|
|
413
|
-
const byId = id => results.find(r => r.id === id)
|
|
414
|
-
assert.equal(byId('rightbar.panel').status, 'fail')
|
|
415
|
-
assert.match(byId('rightbar.panel').reason, /data-sidebar-right-panel/)
|
|
416
|
-
assert.equal(byId('chat.flow').status, 'skip')
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
// 鈹€鈹€ 3. the settings UI's own stylesheet 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
420
|
-
|
|
421
|
-
test('every dab-* class a component uses is defined in the UI stylesheet', async () => {
|
|
422
|
-
const dir = join(pluginDir, 'src', 'client')
|
|
423
|
-
const files = []
|
|
424
|
-
const walk = async d => {
|
|
425
|
-
for (const entry of await readdir(d, { withFileTypes: true })) {
|
|
426
|
-
const p = join(d, entry.name)
|
|
427
|
-
if (entry.isDirectory()) await walk(p)
|
|
428
|
-
else if (entry.name.endsWith('.tsx')) files.push(p)
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
await walk(dir)
|
|
432
|
-
assert.ok(files.length > 0, 'no component sources found')
|
|
433
|
-
|
|
434
|
-
const missing = []
|
|
435
|
-
for (const file of files) {
|
|
436
|
-
const text = await readFile(file, 'utf8')
|
|
437
|
-
for (const m of text.matchAll(/(?<![\w-])dab-[a-z0-9-]+/g)) {
|
|
438
|
-
const cls = m[0]
|
|
439
|
-
// `--dab-mono` and friends are this plugin's own CSS VARIABLES, not classes.
|
|
440
|
-
if (text.slice(Math.max(0, m.index - 2), m.index) === '--') continue
|
|
441
|
-
if (UI_CSS.includes(`.${cls}`)) continue
|
|
442
|
-
if (missing.some(x => x.cls === cls && x.file === file)) continue
|
|
443
|
-
missing.push({ cls, file: file.slice(pluginDir.length + 1) })
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
assert.deepEqual(missing, [], `classes used but never styled: ${missing.map(m => `${m.cls} (${m.file})`).join(', ')}`)
|
|
447
|
-
})
|
|
448
|
-
|
|
449
|
-
// 鈹€鈹€ 4. the floor comparison 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
450
|
-
|
|
451
|
-
test('the floor comparison is coarse on purpose and exact on the triple', () => {
|
|
452
|
-
assert.equal(meetsFloor('0.1.7-rc.2', DSH_FLOOR), true, 'the floor itself satisfies the floor')
|
|
453
|
-
assert.equal(meetsFloor('0.1.7', DSH_FLOOR), true)
|
|
454
|
-
assert.equal(meetsFloor('0.2.0', DSH_FLOOR), true)
|
|
455
|
-
assert.equal(meetsFloor('1.0.0', DSH_FLOOR), true)
|
|
456
|
-
assert.equal(meetsFloor('0.1.6', DSH_FLOOR), false)
|
|
457
|
-
assert.equal(meetsFloor('0.1.0', DSH_FLOOR), false)
|
|
458
|
-
assert.equal(meetsFloor('not-a-version', DSH_FLOOR), null)
|
|
459
|
-
})
|