mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-28 13:12:59 +08:00
* feat(cordis): add volatile config references without remounting
* refactor(cordis): use internal prefix for volatile updates
* fix(schemastery): preserve metadata-free serialized schemas
* refactor(config): move volatile updates into an opt-in Loader plugin
* refactor(config): reuse Loader context patch for volatile updates
* refactor(config): let the volatile watcher commit equal candidates
* refactor(config): separate comparison from volatile reconciliation
* refactor(loader): extract pure entry option diff
* refactor(loader): compare volatile config through schema metadata
* refactor(loader): make volatile comparison policy explicit
* refactor: name config reload and volatile HMR events
* refactor(loader): compare volatile config in one schema walk; declare hmr/volatile-update in volatile-hmr
Replace the mask/project pair in vendor/loader/src/config/diff.ts with one recursive schema-guided comparison. Absent objects now compare as their declared schema default at every object node, not only under volatile ancestors; both inputs resolve to the same validated config, so the one changed assertion (undefined vs {} under a non-volatile object schema) becomes unchanged. The isJsExpr special case is dropped: expression keys fall through to raw comparison.
Move the hmr/volatile-update Events declaration from vendored Cordis core to its producer, packages/boot/volatile-hmr, matching how dsh-hmr declares hmr/change and hmr/reload. Vendored cordis events.ts returns to upstream content; the inherited Cordis API catalog and the event matrix are regenerated, and the tutorial example imports the package types.
* fix(cosmokit): compare sparse array slots in deepEqual; extend volatile diff coverage
Array.prototype.every skipped holes, so deepEqual(Array(1), ['new']) was true in one direction. Compare every index with holes read as undefined.
config/diff.ts treats expression objects as opaque values even when a schema field shares the marker name, and looks up field schemas with Object.hasOwn so unknown keys named after Object prototype members compare raw. Tests cover absent-object defaults, sparse arrays in both directions, prototype-named keys, metadata-free serialized schema nodes, and a runtime remount check in volatile-hmr. READMEs and the architecture note describe the object-default rule.
* test(schemastery): build serialized schema fixtures without unknown casts
verify-no-unknown-casts rejects the two as-unknown assertions in scripts/volatile-config.spec.ts. Parse the serialized nodes from JSON text instead, matching scripts/loader-config-diff.spec.ts.
* docs(volatile-hmr): drop the scope-scan tag from hmr/volatile-update
verify-scoped-events rejects @dshScopeScan on an event that carries no scoped keys. Catalogs and the event matrix are regenerated.
* docs: regenerate module graph for the volatile-hmr dependency edge
verify-module-graph reports the merged docs stale: volatile-hmr now lists its app-boot dependency.
* test(volatile-hmr): watch the real YAML through an exact config watch
The Windows coverage lane lost the whole spec: its vitest worker exited without a report once this test started a chokidar directory watch (root: ['.']), the only real directory watch in the test suite. Register the include file through hmr.watchConfig instead, the pattern the HMR package's own real-file tests run on Windows, and emit loader/config-reload from the refresh callback as the root-watch path does. packages/boot/hmr/tests/coordination.spec.ts already covers that root-watch emission with a mocked watcher; volatile-hmr and hmr sources stay at 100% coverage.
* test(volatile-hmr): pass the Include path as a file URL
On Windows the plain absolute path made the include subtree fail to load, so the profile-patch test found no consumer entry. Other Include fixtures in this spec already pass file URLs.
* refactor(loader): commit volatile config in Entry.update and remove volatile-hmr
loader/config-reload was emitted from two places (app-boot profile reconciliation and the HMR root watch) and by hand in tests, because a separate plugin needed a "configuration applied" signal to run its own pass. Every update path already funnels through Entry.update, which is where the Loader decides to skip a remount for a volatile-only change. Entry._commitVolatile now parses the candidate through the fiber's internal/config hook and schema, commits the new values into the running references when the ordinary effective values still match, and emits loader/volatile-update to the owning fiber. A changed ordinary effective value falls back to the ordinary remount instead of leaving the instance stale; an invalid candidate is logged and keeps the running references, with the raw config retained for the next activation. Forced group updates take the same path.
Remove packages/boot/volatile-hmr, its event, the app-boot loader/config-reload declaration and emit, and the HMR emission. Loader runtime and real-file tests move to scripts/loader-volatile-update.spec.ts. Docs, catalogs, the event matrix, module graph and the architecture note follow.
* test: share the volatile schema fixture between the schema and Loader specs
The duplication gate flagged the identical Config fixture in scripts/volatile-config.spec.ts and scripts/loader-volatile-update.spec.ts.
* refactor(loader): reduce config/diff.ts to equalExceptVolatile
Entry.update now computes the strict raw option changes itself and only asks diff.ts whether two raw configs differ at most in volatile fields. The ignoreVolatile flag, the options object and the "config is the sole change" rule leave diff.ts; they were the Loader's decision and now sit next to the commit they gate. The raw-config deepEqual in the volatile branch is gone because the strict change list already answers it.
* refactor(loader): type the volatile comparison against Schemastery's Schema
config/diff.ts narrows the plugin's Standard Schema to Schemastery's own Schema type instead of a hand-written structural interface, which makes vendor/loader a type-only dependent of @deepseek-ai/schemastery. The rescope codemod treats the vendor identifier comparison like schemastery's own source and renames the import through an exact edit.
* fix(loader): address review findings on the volatile commit path
Entry.update only replaces the fiber's pending raw config for a volatile-only change, so a noSave direct update survives a no-op entry update. _commitVolatile logs at debug level when ordinary effective values changed and the ordinary update applies, dispatches loader/volatile-update with a Context receiver like Cordis' own filtered emits, and isolates a throwing listener. Schemastery reports unsupported volatile values as ValidationError with their path and validates a lazy inner once when it is built. The inherited-event catalog gains internal/config and corrected source lines; the Loader spec imports dsh-hmr by package name and covers the new behaviors. Docs record that class-instance ordinary fields always take the remount path and that .default() accepts the raw input type.
110 lines
5.8 KiB
TypeScript
110 lines
5.8 KiB
TypeScript
/** Raw config comparison reads schema metadata without resolving config or committing references. */
|
|
import { expect, it, vi } from 'vitest'
|
|
import z from '@deepseek-ai/schemastery'
|
|
import { equalExceptVolatile as equal } from '../vendor/loader/src/config/diff.ts'
|
|
|
|
it('ignores volatile fields in frozen raw inputs without running schema callbacks', () => {
|
|
const validate = vi.fn((value: string) => value.trim())
|
|
const schema = z.object({ title: z.transform(z.string(), validate).volatile(), fixed: z.string() })
|
|
Object.freeze(schema.meta)
|
|
Object.freeze(schema.dict)
|
|
const previous = Object.freeze({ title: 'old', fixed: 'same' })
|
|
const next = Object.freeze({ title: { __jsExpr: 'throw new Error("must not run")' }, fixed: 'same' })
|
|
expect(equal(previous, next, schema)).toBe(true)
|
|
expect(equal(previous, next, schema)).toBe(true)
|
|
expect(validate).not.toHaveBeenCalled()
|
|
expect(previous.title).toBe('old')
|
|
expect(next.title).toEqual({ __jsExpr: 'throw new Error("must not run")' })
|
|
})
|
|
|
|
it('ignores absent, nested and whole-object/array/union volatile fields', () => {
|
|
const schema = z.object({
|
|
nested: z.object({ value: z.string().volatile() }),
|
|
block: z.object({ title: z.string() }).volatile(),
|
|
list: z.array(z.string()).volatile(),
|
|
choice: z.union([z.string(), z.number()]).volatile(),
|
|
})
|
|
const next = { nested: { value: 'new' }, block: { title: 'new' }, list: ['new'], choice: 1 }
|
|
expect(equal({}, next, schema)).toBe(true)
|
|
expect(equal(next, {}, schema)).toBe(true)
|
|
expect(equal('old', 'new', z.string().volatile())).toBe(true)
|
|
const restored = new z<unknown>(JSON.parse(JSON.stringify(schema)) as z<unknown>)
|
|
expect(equal({}, next, restored)).toBe(true)
|
|
})
|
|
|
|
it('preserves ordinary and unknown fields, object defaults and parent expressions', () => {
|
|
const schema = z.object({ nested: z.object({ live: z.string().volatile(), fixed: z.string() }).default({ fixed: 'default' }) })
|
|
expect(equal({}, { nested: { live: 'new', fixed: 'default' } }, schema)).toBe(true)
|
|
expect(equal({}, { nested: { live: 'new' } }, schema)).toBe(false)
|
|
expect(equal({}, { unknown: 'new' }, schema)).toBe(false)
|
|
expect(equal({ nested: { __jsExpr: 'source.a' } }, { nested: { __jsExpr: 'source.b' } }, schema)).toBe(false)
|
|
expect(equal({ nested: 'invalid' }, { nested: { live: 'new' } }, schema)).toBe(false)
|
|
expect(equal({ nested: new Date(0) }, { nested: new Date(1) }, schema)).toBe(false)
|
|
expect(equal({ nested: [] }, { nested: ['new'] }, schema)).toBe(false)
|
|
})
|
|
|
|
it('keeps ordinary raw changes even if schema validation would normalize them to equal values', () => {
|
|
const normalize = vi.fn(() => 'same')
|
|
const schema = z.object({ fixed: z.transform(z.string(), normalize), live: z.string().volatile() })
|
|
expect(equal({ fixed: 'first' }, { fixed: 'second' }, schema)).toBe(false)
|
|
expect(normalize).not.toHaveBeenCalled()
|
|
const other = { '~standard': { version: 1 as const, vendor: 'other', validate: vi.fn() } }
|
|
expect(equal('first', 'second', other)).toBe(false)
|
|
expect(other['~standard'].validate).not.toHaveBeenCalled()
|
|
expect(equal('first', 'second', undefined)).toBe(false)
|
|
})
|
|
|
|
it('compares raw values strictly without a schema', () => {
|
|
expect(equal([undefined], [null], undefined)).toBe(false)
|
|
expect(equal(undefined, null, undefined)).toBe(false)
|
|
expect(equal({ fixed: 'same' }, { fixed: 'same' }, undefined)).toBe(true)
|
|
expect(equal({ list: Array(1) }, { list: ['new'] }, undefined)).toBe(false)
|
|
})
|
|
|
|
it('compares recursive schemas conservatively and visits shared schema nodes at each path', () => {
|
|
const recursive = z.object({ value: z.string() }).extra('default', undefined)
|
|
recursive.set('child', recursive)
|
|
expect(equal({ value: 'old' }, { value: 'new' }, recursive)).toBe(false)
|
|
const shared = z.object({ value: z.string().volatile() })
|
|
const schema = z.object({ first: shared, second: shared })
|
|
expect(equal({}, { first: { value: 'one' }, second: { value: 'two' } }, schema)).toBe(true)
|
|
})
|
|
|
|
it('equates absent objects with defaults while preserving ordinary field differences', () => {
|
|
const schema = z.object({ nested: z.object({ fixed: z.string() }).default({ fixed: 'default' }) })
|
|
for (const absent of [undefined, null]) {
|
|
expect(equal(absent, {}, schema)).toBe(true)
|
|
expect(equal({}, absent, schema)).toBe(true)
|
|
expect(equal({ nested: absent }, { nested: { fixed: 'default' } }, schema)).toBe(true)
|
|
}
|
|
expect(equal({}, { nested: { fixed: 'changed' } }, schema)).toBe(false)
|
|
expect(equal({}, { nested: {} }, schema)).toBe(false)
|
|
})
|
|
|
|
it('preserves parent expression edits even when their marker matches a volatile field', () => {
|
|
const schema = z.object({ __jsExpr: z.string().volatile() })
|
|
expect(equal({ __jsExpr: 'first' }, { __jsExpr: 'second' }, schema)).toBe(false)
|
|
})
|
|
|
|
it('detects ordinary sparse array edits in both directions', () => {
|
|
const schema = z.object({ list: z.array(z.string()), live: z.string().volatile() })
|
|
const before = { list: Array(1), live: 'before' }
|
|
const after = { list: ['new'], live: 'after' }
|
|
expect(equal(before, after, schema)).toBe(false)
|
|
expect(equal(after, before, schema)).toBe(false)
|
|
})
|
|
|
|
it('compares unknown fields whose names match Object prototype properties', () => {
|
|
const schema = z.object({ live: z.string().volatile() })
|
|
for (const key of ['constructor', 'toString', '__proto__']) {
|
|
const previous = { [key]: 'first', live: 'old' }
|
|
expect(equal(previous, { [key]: 'second', live: 'new' }, schema)).toBe(false)
|
|
expect(equal(previous, { [key]: 'first', live: 'new' }, schema)).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('compares metadata-free serialized schema nodes', () => {
|
|
const schema = new z<unknown>(JSON.parse('{"type":"object","dict":{"nested":{"type":"object","dict":{"enabled":{"type":"boolean"}}}}}') as z<unknown>)
|
|
expect(equal({ nested: { enabled: true } }, { nested: { enabled: false } }, schema)).toBe(false)
|
|
})
|