import { expect, it } from 'bun:test'; import type { AppEnvironmentId } from './environments'; import type { InfraAdapterDescriptor, InfraAuthSpec, InfraAuthzSpec, InfraComputeAdapter, InfraComputeSnapshot, InfraControlPlaneCredentialRef, InfraCredentialPort, InfraDeploymentSpec, InfraDestroyRequest, InfraExecutionContext, InfraManifest, InfraObjectStorageSpec, InfraOutput, InfraResult, InfraRuntimeAdapter, InfraRuntimeDesiredState, InfraRuntimeProviderId, InfraServiceAdapter, } from './infra'; import type { AppStateSpec } from './state'; type Assignable = [T] extends [U] ? true : false; interface Deployment { readonly compute: C; readonly runtime: R; } interface Local { readonly provider: 'local'; } interface Hetzner { readonly provider: 'hetzner'; readonly location: 'nbg1'; } interface Runtime

{ readonly provider: P; } it('compiles the entire deployment matrix with exact assignability', () => { const matrix: readonly [ Assignable>, InfraDeploymentSpec>, Assignable>, InfraDeploymentSpec>, Assignable>, InfraDeploymentSpec>, Assignable>, InfraDeploymentSpec>, Assignable>, InfraDeploymentSpec>, Assignable>, InfraDeploymentSpec>, Assignable, InfraDeploymentSpec>, Assignable, InfraDeploymentSpec>, Assignable>, InfraDeploymentSpec>, Assignable, InfraDeploymentSpec>, ] = [true, true, true, false, true, true, false, false, false, false]; expect(matrix).toEqual([true, true, true, false, true, true, false, false, false, false]); }); it('closes environment, app-state, bootstrap and privileged-output boundaries', () => { const closed: readonly [ Assignable<'staging', AppEnvironmentId>, Assignable<{ provider: 'legend'; persistence: 'local' }, AppStateSpec>, Assignable<{ provider: 'custom' }, AppStateSpec>, Assignable<{ source: 'secret-store'; ref: string }, InfraControlPlaneCredentialRef>, Assignable<{ modules: [] }, InfraManifest>, Assignable<{ projectId: string; environment: 'production' }, InfraDestroyRequest>, Assignable< Omit, 'package'> & { package: '@ankhorage/supabase-db' }, InfraAdapterDescriptor >, Assignable< Omit, 'value'> & { value: string }, InfraOutput >, ] = [false, false, false, false, false, false, false, false]; expect(closed).toEqual([false, false, false, false, false, false, false, false]); }); it('rejects open or fictional service providers in typed selections', () => { const providers: readonly [ Assignable<{ provider: string }, InfraAuthSpec>, Assignable<{ provider: 'native'; kind: 'RBAC' }, InfraAuthzSpec>, Assignable<{ provider: 'auto' }, InfraObjectStorageSpec>, Assignable<{ provider: 's3' }, InfraObjectStorageSpec>, ] = [false, false, false, false]; expect(providers).toEqual([false, false, false, false]); }); it('requires resolved outputs at the runtime desired-state boundary', () => { interface RuntimeInput { readonly selection: { readonly provider: 'minikube' }; readonly targets: readonly []; readonly workloads: readonly []; } const outputBoundary: readonly [ Assignable>, Assignable, ] = [false, true]; expect(outputBoundary).toEqual([false, true]); }); it('requires runtime desired state for every target-dependent lifecycle operation', () => { type Adapter = InfraRuntimeAdapter<'docker-compose'>; type Desired = InfraRuntimeDesiredState<'docker-compose'>; const lifecycleBoundary: readonly [ Assignable, [context: unknown, desired: Desired]>, Assignable, [context: unknown, desired: Desired]>, Assignable< Parameters, [context: unknown, desired: Desired, request: InfraDestroyRequest] >, ] = [true, true, true]; expect(lifecycleBoundary).toEqual([true, true, true]); }); it('requires read-only compute discovery separately from mutating ensure', () => { type Adapter = InfraComputeAdapter<'local'>; const computeBoundary: readonly [ Assignable>, InfraResult>, Assignable>, InfraResult>, ] = [true, true]; expect(computeBoundary).toEqual([true, true]); }); it('shares one generic credential port and optional service preparation lifecycle', () => { type CredentialBundle = Readonly>; type Service = InfraServiceAdapter; const boundary: readonly [ Assignable, Assignable< Awaited>, InfraResult >, Assignable< Awaited>, InfraResult >, Assignable>, InfraResult>, Assignable< Exclude, (context: InfraExecutionContext) => Promise> >, ] = [true, true, true, true, true]; expect(boundary).toEqual([true, true, true, true, true]); });