Release / release (push) Successful in 9s
`presets/standard-compaction.patch.yml` inserted a second `preset-standard` declaration. It happened to take effect because it applied last, but which of the two declarations mounted was decided by the loader's duplicate-id handling, and the composed tree carried two rows with the same id. The file now overrides the shipped row by id, so the intent is explicit and only one declaration exists. `test/presets.test.js` composes the shipped declaration and the overlay through the harness's own patch engine and asserts one row, no skipped patch, and the compaction budget applied — which the old insert form no longer satisfies.
261 lines
11 KiB
JavaScript
261 lines
11 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
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, pathToFileURL } 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')
|
|
|
|
/**
|
|
* The prompt variables the harness registers for a section.
|
|
*
|
|
* `dsh-agent-loop` puts each of these into the prompt registry, and an assembly
|
|
* substitutes only what is registered. An unknown reference is not rendered as
|
|
* text — interpolation throws, and the throw takes the entire turn with it, so
|
|
* the user sees "This turn failed" and nothing else. A harness release that
|
|
* stopped registering `cwd` is exactly how this bundle's preset stopped
|
|
* composing sessions: the persona suffix it copied from the deployment said
|
|
* "Your working directory is …" with that variable in it.
|
|
*/
|
|
const REGISTERED = ['provider', 'model']
|
|
|
|
/** Every `{{name}}` reference in one text, as the name alone. */
|
|
function referencesIn(text) {
|
|
return [...text.matchAll(/\{\{([^{}]*)\}\}/g)].map((match) => match[1])
|
|
}
|
|
|
|
test('no preset references a prompt variable the harness does not register', () => {
|
|
const files = readdirSync(PRESETS).filter((name) => name.endsWith('.yml'))
|
|
assert.ok(files.length > 0, 'the bundle ships at least one preset')
|
|
|
|
const found = []
|
|
for (const file of files) {
|
|
for (const name of referencesIn(readFileSync(join(PRESETS, file), 'utf8'))) found.push([file, name])
|
|
}
|
|
|
|
// The model reference is the one that has to keep working, so the guard cannot
|
|
// be satisfied by a preset that references nothing at all.
|
|
assert.ok(
|
|
found.some(([, name]) => name === 'model'),
|
|
'a preset still names the model',
|
|
)
|
|
for (const [file, name] of found) {
|
|
assert.ok(
|
|
REGISTERED.includes(name),
|
|
`${file} references {{${name}}}; the harness registers only ${REGISTERED.join(', ')}, and an unregistered reference fails the whole turn`,
|
|
)
|
|
}
|
|
})
|
|
|
|
test('the text this bundle contributes to the prompt holds no variable references', () => {
|
|
// The rule and the binding are rebuilt from real values on every request, so a
|
|
// placeholder in either would be a reference the harness never resolves — the
|
|
// same failure, this time from the bundle's own hand.
|
|
const rule = facetRuleText()
|
|
const binding = facetContextText({ cwd: '/w', root: '/w/src', extras: ['/w/shared'], mode: 'ask' })
|
|
assert.ok(rule.length > 0 && binding.length > 0, 'both halves contribute text')
|
|
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 APP_BOOT = HARNESS_SCOPES
|
|
.map((scope) => join(scope, '@deepseek-ai', 'dsh-app-boot', 'lib', 'index.js'))
|
|
.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 })
|
|
// The facet preset is an insert; the optional overlay overrides the shipped
|
|
// row by id and carries the full config instead.
|
|
const declaration = patch.insert === undefined ? patch : patch.insert[0]
|
|
return declaration.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',
|
|
)
|
|
})
|
|
|
|
test(
|
|
'the standard-compaction overlay replaces the shipped preset instead of adding a second declaration',
|
|
{ skip: SKIP_DRIFT },
|
|
async (t) => {
|
|
if (APP_BOOT === undefined) return t.skip('the harness app-boot package was not found in any scope')
|
|
|
|
// Compose the way the launcher does: the shipped declaration first, then the
|
|
// overlay. A second declaration carrying the same preset id would register
|
|
// in the wrong order and lose — which is how this overlay used to do nothing.
|
|
const { composeEntries } = await import(pathToFileURL(APP_BOOT).href)
|
|
const standardPatch = yaml.load(readFileSync(STANDARD_PRESET, 'utf8'), { schema: PRESET_SCHEMA })
|
|
const overlayPatch = yaml.load(readFileSync(COMPACTION_PRESET, 'utf8'), { schema: PRESET_SCHEMA })
|
|
const warnings = []
|
|
const entries = composeEntries([standardPatch, overlayPatch], (message) => warnings.push(message))
|
|
|
|
assert.deepEqual(warnings, [], 'the overlay applies without a skipped patch')
|
|
const declarations = entries.filter((entry) => entry.id === 'preset-standard')
|
|
assert.equal(
|
|
declarations.length,
|
|
1,
|
|
'the overlay overrides the row; a second declaration would be ignored by the registry',
|
|
)
|
|
assert.deepEqual(
|
|
rowById(declarations[0].config.plugins, 'compaction-basic')?.config,
|
|
COMPACTION_BUDGET,
|
|
'the applied overlay carries 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',
|
|
)
|
|
})
|