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

+13 -21
View File
@@ -5,10 +5,12 @@
*
* ## Why this exists
*
* The plugin imports `@deepseek-ai/dsh-tools` and `@deepseek-ai/schemastery`.
* Once installed into 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 plugin imports `@deepseek-ai/dsh-tools` and `@deepseek-ai/schemastery`,
* and `test/presets.test.js` reads the shipped `standard` preset through
* `js-yaml` to compare it with this bundle's frozen copies. Once installed into
* 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`
* 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 { fileURLToPath } from 'node:url'
import { findHarnessScope } from './harness-scope.mjs'
/** 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 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()
if (scope === undefined) {
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')
mkdirSync(join(target, '@deepseek-ai'), { recursive: true })
mkdirSync(target, { recursive: true })
let linked = 0
for (const name of NEEDED) {
const source = join(scope, '@deepseek-ai', name)
const source = join(scope, name)
if (!existsSync(source)) {
console.error(`dev-links: ${name} is not in ${scope}; skipping`)
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 })
symlinkSync(source, link, 'dir')
linked += 1
+46
View File
@@ -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]
}