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:
1 parent
616cad75ce
commit
1697c24c3c
3 files changed
+224
-22
No files matched your search
+13
-21
@@ -5,10 +5,12 @@
|
|||||||
*
|
*
|
||||||
* ## Why this exists
|
* ## Why this exists
|
||||||
*
|
*
|
||||||
* The plugin imports `@deepseek-ai/dsh-tools` and `@deepseek-ai/schemastery`.
|
* The plugin imports `@deepseek-ai/dsh-tools` and `@deepseek-ai/schemastery`,
|
||||||
* Once installed into a profile those resolve from the profile's own
|
* and `test/presets.test.js` reads the shipped `standard` preset through
|
||||||
* `node_modules`, which is where the harness lives — but a bare checkout has no
|
* `js-yaml` to compare it with this bundle's frozen copies. Once installed into
|
||||||
* such tree, so the tests cannot even load the module under test.
|
* a profile those resolve from the profile's own `node_modules`, which is where
|
||||||
|
* the harness lives — but a bare checkout has no such tree, so the tests cannot
|
||||||
|
* even load the module under test.
|
||||||
*
|
*
|
||||||
* The alternative is declaring them as dependencies, and for `@deepseek-ai/cordis`
|
* The alternative is declaring them as dependencies, and for `@deepseek-ai/cordis`
|
||||||
* that would be a genuine bug rather than untidiness: a second copy of Cordis
|
* that would be a genuine bug rather than untidiness: a second copy of Cordis
|
||||||
@@ -23,25 +25,14 @@ import { existsSync, mkdirSync, readdirSync, rmSync, symlinkSync } from 'node:fs
|
|||||||
import { dirname, join, resolve } from 'node:path'
|
import { dirname, join, resolve } from 'node:path'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
|
import { findHarnessScope } from './harness-scope.mjs'
|
||||||
|
|
||||||
/** Packages this checkout imports at runtime, and which the harness must supply. */
|
/** Packages this checkout imports at runtime, and which the harness must supply. */
|
||||||
const NEEDED = ['cordis', 'schemastery', 'dsh-tools']
|
const NEEDED = ['@deepseek-ai/cordis', '@deepseek-ai/schemastery', '@deepseek-ai/dsh-tools', 'js-yaml']
|
||||||
|
|
||||||
const here = dirname(fileURLToPath(import.meta.url))
|
const here = dirname(fileURLToPath(import.meta.url))
|
||||||
const packageRoot = resolve(here, '..')
|
const packageRoot = resolve(here, '..')
|
||||||
|
|
||||||
/** Where a dsh installation keeps the scope, newest layout first. */
|
|
||||||
function findHarnessScope() {
|
|
||||||
const candidates = [
|
|
||||||
process.env.DSH_HARNESS_NODE_MODULES,
|
|
||||||
resolve(process.env.DSH_HOME ?? join(process.env.HOME ?? '', '.dsh'), 'profiles', 'node_modules'),
|
|
||||||
'/usr/local/lib/node_modules/@deepseek-ai/dsh/node_modules',
|
|
||||||
]
|
|
||||||
for (const candidate of candidates) {
|
|
||||||
if (typeof candidate === 'string' && existsSync(join(candidate, '@deepseek-ai', 'cordis'))) return candidate
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
const scope = findHarnessScope()
|
const scope = findHarnessScope()
|
||||||
if (scope === undefined) {
|
if (scope === undefined) {
|
||||||
console.error('dev-links: no dsh installation found. Set DSH_HARNESS_NODE_MODULES to its node_modules directory.')
|
console.error('dev-links: no dsh installation found. Set DSH_HARNESS_NODE_MODULES to its node_modules directory.')
|
||||||
@@ -49,16 +40,17 @@ if (scope === undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const target = join(packageRoot, 'node_modules')
|
const target = join(packageRoot, 'node_modules')
|
||||||
mkdirSync(join(target, '@deepseek-ai'), { recursive: true })
|
mkdirSync(target, { recursive: true })
|
||||||
|
|
||||||
let linked = 0
|
let linked = 0
|
||||||
for (const name of NEEDED) {
|
for (const name of NEEDED) {
|
||||||
const source = join(scope, '@deepseek-ai', name)
|
const source = join(scope, name)
|
||||||
if (!existsSync(source)) {
|
if (!existsSync(source)) {
|
||||||
console.error(`dev-links: ${name} is not in ${scope}; skipping`)
|
console.error(`dev-links: ${name} is not in ${scope}; skipping`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const link = join(target, '@deepseek-ai', name)
|
const link = join(target, name)
|
||||||
|
mkdirSync(dirname(link), { recursive: true })
|
||||||
if (existsSync(link)) rmSync(link, { recursive: true, force: true })
|
if (existsSync(link)) rmSync(link, { recursive: true, force: true })
|
||||||
symlinkSync(source, link, 'dir')
|
symlinkSync(source, link, 'dir')
|
||||||
linked += 1
|
linked += 1
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Locate a dsh installation's dependency scope from a checkout.
|
||||||
|
*
|
||||||
|
* The plugin links harness packages into a bare checkout (see `dev-links.mjs`)
|
||||||
|
* and `test/presets.test.js` reads the shipped `standard` preset to compare it
|
||||||
|
* with this bundle's frozen copies. Both need the same answer to "where is the
|
||||||
|
* harness?", so the search lives here rather than twice.
|
||||||
|
*
|
||||||
|
* There can be more than one answer. A harness home may carry the legacy
|
||||||
|
* `profiles/node_modules` mirror that an older link backend projected, and that
|
||||||
|
* mirror is a snapshot: packages added to the installation later are missing
|
||||||
|
* from it. Callers that resolve more than one package should therefore try
|
||||||
|
* every scope, not only {@link findHarnessScope}'s first answer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { existsSync } from 'node:fs'
|
||||||
|
import { join, resolve } from 'node:path'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every dependency scope a dsh installation may occupy, newest layout first.
|
||||||
|
*
|
||||||
|
* @returns the directories that hold `@deepseek-ai/cordis`, deduplicated, in
|
||||||
|
* preference order.
|
||||||
|
*/
|
||||||
|
export function harnessScopes() {
|
||||||
|
const candidates = [
|
||||||
|
process.env.DSH_HARNESS_NODE_MODULES,
|
||||||
|
resolve(process.env.DSH_HOME ?? join(process.env.HOME ?? '', '.dsh'), 'profiles', 'node_modules'),
|
||||||
|
'/usr/local/lib/node_modules/@deepseek-ai/dsh/node_modules',
|
||||||
|
]
|
||||||
|
const scopes = []
|
||||||
|
for (const candidate of candidates) {
|
||||||
|
if (typeof candidate !== 'string' || !existsSync(join(candidate, '@deepseek-ai', 'cordis'))) continue
|
||||||
|
if (!scopes.includes(candidate)) scopes.push(candidate)
|
||||||
|
}
|
||||||
|
return scopes
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The preferred dependency scope of a dsh installation.
|
||||||
|
*
|
||||||
|
* @returns the first directory that holds `@deepseek-ai/cordis`, or undefined.
|
||||||
|
*/
|
||||||
|
export function findHarnessScope() {
|
||||||
|
return harnessScopes()[0]
|
||||||
|
}
|
||||||
+165
-1
@@ -1,10 +1,14 @@
|
|||||||
import assert from 'node:assert/strict'
|
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 { dirname, join } from 'node:path'
|
||||||
import { test } from 'node:test'
|
import { test } from 'node:test'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
|
import yaml from 'js-yaml'
|
||||||
|
|
||||||
import { facetContextText, facetRuleText } from '../lib/scope.js'
|
import { facetContextText, facetRuleText } from '../lib/scope.js'
|
||||||
|
import { harnessScopes } from '../scripts/harness-scope.mjs'
|
||||||
|
|
||||||
const PRESETS = join(dirname(fileURLToPath(import.meta.url)), '..', 'presets')
|
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(rule), [])
|
||||||
assert.deepEqual(referencesIn(binding), [])
|
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',
|
||||||
|
)
|
||||||
|
})
|
||||||
Reference in new issue
Block a user