fix(invariants): assert runtime relationships, not API shapes
This commit is contained in:
@@ -1,34 +1,24 @@
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-acp-snapshot. @module @deepseek-ai/dsh-acp-snapshot/invariant */
|
||||
/**
|
||||
* Package-owned invariant companion for `@deepseek-ai/dsh-acp-snapshot`.
|
||||
* @module @deepseek-ai/dsh-acp-snapshot/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-acp-snapshot'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'acp-snapshot-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Assert stable JSON-RPC correlation and volatile-value tokenization. */
|
||||
const install: InvariantInstaller = async (_ctx, fail) => {
|
||||
const { normalizeStdout } = await import('./normalize.ts')
|
||||
const sessionId = '12345678-1234-1234-1234-123456789abc'
|
||||
const volatile = { sessionIds: [sessionId], cwd: '/tmp/dsh-acp-invariant' }
|
||||
const raw = [
|
||||
JSON.stringify({ jsonrpc: '2.0', id: 'request-7', result: { cwd: volatile.cwd } }),
|
||||
JSON.stringify({ jsonrpc: '2.0', id: 'request-7', result: { sessionId } }),
|
||||
].join('\n')
|
||||
const normalized = normalizeStdout(raw, volatile)
|
||||
assertInvariant(fail,
|
||||
normalized.includes('"id":1')
|
||||
&& normalized.includes('"cwd":"{{cwd}}"')
|
||||
&& normalized.includes('"sessionId":"{{sessionId}}"'),
|
||||
'ACP normalization must preserve RPC correlation while tokenizing cwd and session ids')
|
||||
assertInvariant(fail, normalizeStdout(normalized, volatile) === normalized,
|
||||
'ACP stdout normalization must be idempotent')
|
||||
}
|
||||
/**
|
||||
* No runtime invariant: this test-support package owns no production event stream or mutable data;
|
||||
* consuming test suites exercise its behavior.
|
||||
*/
|
||||
const install: InvariantInstaller = () => {}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
Reference in New Issue
Block a user