feat(invariants): implement package runtime checks
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-paths`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-paths/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts 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 type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-paths'
|
||||
|
||||
@@ -17,8 +13,19 @@ export const name = 'paths-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 tilde expansion and explicit-over-environment home precedence. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
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')
|
||||
return () => {}
|
||||
}, 'paths: validate DSH home resolution')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
Reference in New Issue
Block a user