fix(invariants): assert runtime relationships, not API shapes
This commit is contained in:
@@ -1,22 +1,24 @@
|
||||
/** Package-owned runtime contract for @deepseek-ai/dsh-brand. @module @deepseek-ai/dsh-brand/invariant */
|
||||
/**
|
||||
* Package-owned invariant companion for `@deepseek-ai/dsh-brand`.
|
||||
* @module @deepseek-ai/dsh-brand/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-brand'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'brand-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Assert that the nominal-type primitive remains erased at runtime. */
|
||||
const install: InvariantInstaller = async (_ctx, fail) => {
|
||||
const brandRuntime = await import('./index.ts')
|
||||
assertInvariant(fail, Object.keys(brandRuntime).length === 0,
|
||||
'the branded-id primitive must remain type-only with no runtime exports')
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-home. @module @deepseek-ai/dsh-home/invariant */
|
||||
/**
|
||||
* Package-owned invariant companion for `@deepseek-ai/dsh-home`.
|
||||
* @module @deepseek-ai/dsh-home/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import { resolve } from 'node:path'
|
||||
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-home'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'home-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Assert the canonical environment key and configured-path precedence. */
|
||||
const install: InvariantInstaller = async (_ctx, fail) => {
|
||||
const { DSH_HOME_ENV, resolveDshHome } = await import('./index.ts')
|
||||
const environmentKey: string = DSH_HOME_ENV
|
||||
assertInvariant(fail, environmentKey === ['DSH', 'HOME'].join('_'),
|
||||
'the canonical Harness home environment key must remain DSH_HOME')
|
||||
const configured = 'relative-invariant-home'
|
||||
assertInvariant(fail, resolveDshHome(configured) === resolve(configured),
|
||||
'an explicitly configured Harness home must normalize to an absolute path')
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-paths. @module @deepseek-ai/dsh-paths/invariant */
|
||||
/**
|
||||
* Package-owned invariant companion for `@deepseek-ai/dsh-paths`.
|
||||
* @module @deepseek-ai/dsh-paths/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import { homedir } from 'node:os'
|
||||
import { join, resolve } from 'node:path'
|
||||
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-paths'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'paths-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Assert tilde expansion and explicit-over-environment home precedence. */
|
||||
const install: InvariantInstaller = async (_ctx, fail) => {
|
||||
const { DSH_HOME_ENV, expandHomePath, resolveDshHome } = await import('./index.ts')
|
||||
assertInvariant(fail, expandHomePath('~/invariant-probe') === join(homedir(), 'invariant-probe'),
|
||||
'supported tilde prefixes must expand against the operating-system home')
|
||||
const configured = 'relative-invariant-home'
|
||||
const resolved = resolveDshHome(configured, { [DSH_HOME_ENV]: '/ignored-environment-home' })
|
||||
assertInvariant(fail, resolved === resolve(configured),
|
||||
'an explicit DSH home must override the environment and normalize to an absolute path')
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-timeout. @module @deepseek-ai/dsh-timeout/invariant */
|
||||
/**
|
||||
* Package-owned invariant companion for `@deepseek-ai/dsh-timeout`.
|
||||
* @module @deepseek-ai/dsh-timeout/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-timeout'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'timeout-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Assert default-before-cap arithmetic and capability-code classification. */
|
||||
const install: InvariantInstaller = async (_ctx, fail) => {
|
||||
const { clampTimeout, TimeoutReason, timeoutOf } = await import('./index.ts')
|
||||
assertInvariant(fail,
|
||||
clampTimeout(undefined, 50, 30) === 30 && clampTimeout(20, 50, 30) === 20,
|
||||
'timeout resolution must apply the default before capping and preserve smaller requests')
|
||||
const reason = new TimeoutReason('INVARIANT_TIMEOUT', 25)
|
||||
assertInvariant(fail, timeoutOf({ reason }, 'INVARIANT_TIMEOUT') === reason,
|
||||
'timeout classification must recover a matching capability-owned reason')
|
||||
assertInvariant(fail, timeoutOf({ reason }, 'FOREIGN_TIMEOUT') === undefined,
|
||||
'timeout classification must reject a reason owned by another capability')
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
|
||||
Reference in New Issue
Block a user