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

View File

@@ -1,35 +1,24 @@
/** Package-owned runtime contracts for @deepseek-ai/create-sdk. @module @deepseek-ai/create-sdk/invariant */
/**
* Package-owned invariant companion for `@deepseek-ai/create-sdk`.
* @module @deepseek-ai/create-sdk/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/create-sdk'
/** Cordis companion plugin name. */
export const name = 'create-sdk-invariant'
/** Services required before the companion can register. */
/** Service required before the companion can reserve package ownership. */
export const inject = ['invariants']
/** Assert the bin-only entrypoint and its core argument mapping. */
const install: InvariantInstaller = async (_ctx, fail) => {
const [{ parseCreateArgs }, packageEntry] = await Promise.all([
import('./args.ts'),
import('./index.ts'),
])
assertInvariant(fail, Object.keys(packageEntry).length === 0,
'the create-sdk library entrypoint must remain empty because the package is bin-only')
const parsed = parseCreateArgs([
'workspace', '--provider=custom', '--base-url=https://example.test', '--interface=embed', '--no-install',
])
assertInvariant(fail,
parsed.directory === 'workspace'
&& parsed.provider === 'custom'
&& parsed.baseURL === 'https://example.test'
&& parsed.runInterface === 'embed'
&& parsed.install === false,
'create-sdk arguments must preserve directory, provider, base URL, interface, and negative install flags')
}
/**
* No runtime invariant: this SDK build-time package owns no live event stream or mutable data;
* generated output and consumer tests cover its contract.
*/
const install: InvariantInstaller = () => {}
/**
* Register this package's invariant companion.

View File

@@ -1,29 +1,24 @@
/** Package-owned runtime contracts for @deepseek-ai/dsh-helper. @module @deepseek-ai/dsh-helper/invariant */
/**
* Package-owned invariant companion for `@deepseek-ai/dsh-helper`.
* @module @deepseek-ai/dsh-helper/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-helper'
/** Cordis companion plugin name. */
export const name = 'helper-invariant'
/** Services required before the companion can register. */
/** Service required before the companion can reserve package ownership. */
export const inject = ['invariants']
/** Assert FeatureId's zero-cost representation and boundary validation. */
const install: InvariantInstaller = async (_ctx, fail) => {
const { featureId } = await import('./ids.ts')
assertInvariant(fail, featureId('local-plugin') === 'local-plugin',
'a valid feature id must preserve its runtime string value')
let rejected = false
try {
featureId('Invalid Feature')
} catch (error) {
rejected = error instanceof Error
}
assertInvariant(fail, rejected, 'feature ids must reject values outside lowercase kebab-case')
}
/**
* No runtime invariant: this SDK build-time package owns no live event stream or mutable data;
* generated output and consumer tests cover its contract.
*/
const install: InvariantInstaller = () => {}
/**
* Register this package's invariant companion.

View File

@@ -1,31 +1,24 @@
/** Package-owned runtime contracts for @deepseek-ai/dsh-scripts. @module @deepseek-ai/dsh-scripts/invariant */
/**
* Package-owned invariant companion for `@deepseek-ai/dsh-scripts`.
* @module @deepseek-ai/dsh-scripts/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-scripts'
/** Cordis companion plugin name. */
export const name = 'scripts-invariant'
/** Services required before the companion can register. */
/** Service required before the companion can reserve package ownership. */
export const inject = ['invariants']
/** Assert the launcher's opaque post-separator forwarding boundary. */
const install: InvariantInstaller = async (_ctx, fail) => {
const { splitForwardedArgs } = await import('./forwarding.ts')
const plain = splitForwardedArgs(['dev', 'src/index.ts'])
const separated = splitForwardedArgs(['dev', 'src/index.ts', '--', '--inspect', '9229'])
assertInvariant(fail,
plain.launcher.length === 2
&& plain.forwarded.length === 0
&& separated.launcher.length === 2
&& separated.launcher[1] === 'src/index.ts'
&& separated.forwarded.length === 2
&& separated.forwarded[0] === '--inspect'
&& separated.forwarded[1] === '9229',
'dsh-sdk must split the first delimiter without interpreting forwarded runtime arguments')
}
/**
* No runtime invariant: this SDK build-time package owns no live event stream or mutable data;
* generated output and consumer tests cover its contract.
*/
const install: InvariantInstaller = () => {}
/**
* Register this package's invariant companion.

View File

@@ -1,28 +1,24 @@
/** Package-owned runtime contracts for @deepseek-ai/dsh-telemetry. @module @deepseek-ai/dsh-telemetry/invariant */
/**
* Package-owned invariant companion for `@deepseek-ai/dsh-telemetry`.
* @module @deepseek-ai/dsh-telemetry/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-telemetry'
/** Cordis companion plugin name. */
export const name = 'telemetry-invariant'
/** Services required before the companion can register. */
/** Service required before the companion can reserve package ownership. */
export const inject = ['invariants']
/** Assert the final telemetry redaction boundary removes secrets without corrupting ordinary package metadata. */
const install: InvariantInstaller = async (_ctx, fail) => {
const [{ telemetryRedactionViolation }, { DEFAULT_REDACTION_PLACEHOLDER, SecretRedactor }] = await Promise.all([
import('./redaction-contract.ts'),
import('./secret-redactor.ts'),
])
const redactor = new SecretRedactor()
const violation = telemetryRedactionViolation(redactor, DEFAULT_REDACTION_PLACEHOLDER, PACKAGE_NAME)
assertInvariant(fail,
violation === undefined,
violation ?? 'telemetry redaction contract failed without a diagnostic')
}
/**
* No runtime invariant: this SDK build-time package owns no live event stream or mutable data;
* generated output and consumer tests cover its contract.
*/
const install: InvariantInstaller = () => {}
/**
* Register this package's invariant companion.