test: fail when a preset drifts from the harness standard

The two files under `presets/` are frozen copies of the harness's `standard`
composition, and nothing noticed when the harness moved on — a missing row only
surfaced as a broken preset in a session, after the copy had already shipped.

`test/presets.test.js` now loads the installed harness's `standard` patch,
removes the deltas this bundle documents, and requires the remaining rows to
match exactly; it also resolves every plugin and subpath a preset names against
the harness scope, so a removed export fails the suite instead of a session.
Both checks skip when a checkout has no harness.

The scope search and the `js-yaml` link the comparison needs live in
`scripts/harness-scope.mjs` and `dev-links.mjs`; the search tries every
candidate scope because the legacy `profiles/node_modules` mirror is only a
snapshot of the installation.
This commit is contained in:
NotExpectedYet committed 2026-11-06 07:20:35 +00:00
1 parent 616cad75ce
commit 1697c24c3c
3 files changed
+224 -22

No files matched your search

+165 -1
View File
@@ -1,10 +1,14 @@
import assert from 'node:assert/strict'
import { readFileSync, readdirSync } from 'node:fs'
import { existsSync, readFileSync, readdirSync } from 'node:fs'
import { createRequire } from 'node:module'
import { dirname, join } from 'node:path'
import { test } from 'node:test'
import { fileURLToPath } from 'node:url'
import yaml from 'js-yaml'
import { facetContextText, facetRuleText } from '../lib/scope.js'
import { harnessScopes } from '../scripts/harness-scope.mjs'
const PRESETS = join(dirname(fileURLToPath(import.meta.url)), '..', 'presets')
@@ -59,3 +63,163 @@ test('the text this bundle contributes to the prompt holds no variable reference
assert.deepEqual(referencesIn(rule), [])
assert.deepEqual(referencesIn(binding), [])
})
/*
* Drift against the shipped `standard` composition.
*
* A preset declaration replaces the whole plugin list rather than merging into
* it, so both files under `presets/` are frozen copies of the harness's
* `standard` patch. That copy is what breaks when the harness changes: on dsh
* 0.2.2-rc.1 the harness folded `list_agents` into
* `@deepseek-ai/dsh-tool-subagent-control` and dropped its `./list-agents`
* subpath, and the copied row could never start — which breaks the *whole*
* preset, because one row that fails to mount fails the declaration. These
* tests turn "remember to re-copy it" into a build failure.
*
* They need the installed harness, so they skip on a checkout without one.
*/
const PACKAGE_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
const FACET_PRESET = join(PRESETS, 'facet.patch.yml')
const COMPACTION_PRESET = join(PRESETS, 'standard-compaction.patch.yml')
const HARNESS_SCOPES = harnessScopes()
const STANDARD_PRESET = HARNESS_SCOPES
.map((scope) => join(scope, '@deepseek-ai', 'dsh-web-app', 'presets', 'standard.patch.yml'))
.find((file) => existsSync(file))
const SKIP_DRIFT =
HARNESS_SCOPES.length === 0
? 'no dsh installation found; set DSH_HARNESS_NODE_MODULES to compare against the shipped standard preset'
: STANDARD_PRESET === undefined
? 'the shipped standard preset was not found in any harness scope'
: false
/** The `!!js` tag carries a source expression; both compared sides keep it as text. */
const PRESET_SCHEMA = yaml.DEFAULT_SCHEMA.extend([
new yaml.Type('tag:yaml.org,2002:js', { kind: 'scalar', construct: (value) => value }),
])
/** The plugin rows of a single-preset patch file, as written. */
function presetPlugins(file) {
const [patch] = yaml.load(readFileSync(file, 'utf8'), { schema: PRESET_SCHEMA })
return patch.insert[0].config.plugins
}
/** Drop absent keys, so a missing field and an undefined field compare the same. */
function normalizedRows(rows) {
return rows.map((row) => ({
id: row.id,
name: row.name,
...(row.disabled === undefined ? {} : { disabled: row.disabled }),
...(row.group === true ? { group: true } : {}),
...(row.isolate === undefined ? {} : { isolate: row.isolate }),
...(row.config === undefined ? {} : { config: Array.isArray(row.config) ? normalizedRows(row.config) : row.config }),
}))
}
/** One row by id, at any depth. */
function rowById(rows, id) {
for (const row of rows) {
if (row.id === id) return row
if (Array.isArray(row.config)) {
const found = rowById(row.config, id)
if (found !== undefined) return found
}
}
return undefined
}
/** A copy with the bundle's compaction budget removed, so everything else can be compared. */
function withoutCompactionBudget(rows) {
const copy = structuredClone(rows)
const strip = (list) => {
for (const row of list) {
if (row.id === 'compaction-basic') delete row.config
if (Array.isArray(row.config)) strip(row.config)
}
}
strip(copy)
return copy
}
/** The only settings either file adds to a `standard` row. */
const COMPACTION_BUDGET = { thresholdRatio: 0.35, retainTokens: 80000, maxTokens: 16384 }
test('the facet preset is the shipped standard composition plus its documented changes', { skip: SKIP_DRIFT }, () => {
const standard = normalizedRows(presetPlugins(STANDARD_PRESET))
const facet = normalizedRows(presetPlugins(FACET_PRESET))
const guard = facet.filter((row) => row.id === 'facet-guard')
assert.deepEqual(guard, [{ id: 'facet-guard', name: 'dsh-facet/guard' }], 'the facet preset mounts facet-guard exactly once')
const withoutGuard = facet.filter((row) => row.id !== 'facet-guard')
assert.deepEqual(
withoutCompactionBudget(withoutGuard),
withoutCompactionBudget(standard),
'presets/facet.patch.yml has drifted from the shipped standard composition; re-copy it from the harness and re-apply only the guard and the compaction budget',
)
assert.deepEqual(
rowById(withoutGuard, 'compaction-basic')?.config,
COMPACTION_BUDGET,
'the facet preset keeps its compaction budget',
)
})
test('the standard-compaction overlay is the shipped standard composition plus the compaction budget', { skip: SKIP_DRIFT }, () => {
const standard = normalizedRows(presetPlugins(STANDARD_PRESET))
const overlay = normalizedRows(presetPlugins(COMPACTION_PRESET))
assert.deepEqual(
rowById(overlay, 'compaction-basic')?.config,
COMPACTION_BUDGET,
'the optional overlay configures the compaction budget',
)
assert.deepEqual(
withoutCompactionBudget(overlay),
withoutCompactionBudget(standard),
'presets/standard-compaction.patch.yml has drifted from the shipped standard composition; re-copy it from the harness and re-apply only the compaction budget',
)
})
/** Every row's id and module specifier, groups included. */
function namedRows(rows) {
return rows.flatMap((row) => [
{ id: row.id, name: row.name },
...(Array.isArray(row.config) ? namedRows(row.config) : []),
])
}
test('every plugin a shipped preset names resolves against the installed harness', { skip: SKIP_DRIFT }, () => {
// Anchoring inside a scope makes Node look in that scope's own node_modules:
// its parent directory carries the scope as a `node_modules` entry, which is
// exactly the lookup the profile uses. Several scopes are tried because a
// legacy `profiles/node_modules` mirror is only a snapshot of the installation.
const harnessResolvers = HARNESS_SCOPES.map((scope) => createRequire(join(scope, 'noop.mjs')))
const fromPlugin = createRequire(join(PACKAGE_ROOT, 'package.json'))
const unresolved = []
for (const file of [FACET_PRESET, COMPACTION_PRESET]) {
for (const { id, name } of namedRows(presetPlugins(file))) {
// `cordis:group` is a loader builtin rather than an installed package.
if (name === 'cordis:group') continue
const resolvers = name === 'dsh-facet/guard' ? [fromPlugin] : harnessResolvers
let failure
const resolved = resolvers.some((resolver) => {
try {
resolver.resolve(name)
return true
} catch (error) {
failure = error
return false
}
})
if (!resolved) unresolved.push(`${file.split('/').pop()}: ${id} (${name}): ${failure?.code ?? failure?.message}`)
}
}
assert.deepEqual(
unresolved,
[],
'a preset names a plugin or subpath the harness no longer provides; re-copy the preset from the shipped standard',
)
})