feat(invariants): implement package runtime checks
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/create-sdk`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/create-sdk/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/create-sdk. @module @deepseek-ai/create-sdk/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/create-sdk'
|
||||
|
||||
@@ -17,8 +11,26 @@ export const name = 'create-sdk-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert the bin-only entrypoint and its core argument mapping. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { parseCreateArgs } = await import('./args.ts')
|
||||
const packageEntry = await 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')
|
||||
return () => {}
|
||||
}, 'create-sdk: validate bin and argument contracts')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
Reference in New Issue
Block a user