fix(invariants): assert runtime relationships, not API shapes

This commit is contained in:
Tianyi Cui
2026-07-20 19:34:19 +08:00
parent 1254c07025
commit 1145ee5fc3
124 changed files with 2923 additions and 2334 deletions
+11 -20
View File
@@ -1,33 +1,24 @@
/** Package-owned runtime contracts for @deepseek-ai/dsh-retention. @module @deepseek-ai/dsh-retention/invariant */
/**
* Package-owned invariant companion for `@deepseek-ai/dsh-retention`.
* @module @deepseek-ai/dsh-retention/invariant
*/
/* jscpd:ignore-start */
import type { Context } from 'cordis'
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
const PACKAGE_NAME = '@deepseek-ai/dsh-retention'
/** Cordis companion plugin name. */
export const name = 'retention-invariant'
/** Services required before the companion can register. */
/** Service required before the companion can reserve package ownership. */
export const inject = ['invariants']
/** Assert exact head-retention accounting after the budget is exceeded. */
const install: InvariantInstaller = async (_ctx, fail) => {
const { ItemRetainer } = await import('./index.ts')
const retainer = new ItemRetainer<string>({ kind: 'head', maxItems: 2 })
retainer.push('first')
retainer.push('second')
retainer.push('third')
const result = retainer.finish()
assertInvariant(fail,
result.items.join(',') === 'first,second'
&& result.seen === 3
&& result.kept === 2
&& result.truncated
&& result.omitted.kind === 'exact'
&& result.omitted.count === 1,
'head retention must keep the prefix and report exact seen, kept, and omitted counts')
}
/**
* No runtime invariant: this pure utility owns no event stream or mutable runtime data; its value
* algebra is enforced by unit tests.
*/
const install: InvariantInstaller = () => {}
/**
* Register this package's invariant companion.