Files
iios/packages/iios-contracts/src/index.test.ts
T
maaz519 fbea291609 feat(contracts): @insignia/iios-contracts — scope, enums, platform ports, CloudEvents, errors
Verbatim IiosPlatformPorts from the bottom-up atlas; orgId/appId required scope
(KG-02); PolicyDeniedError for fail-closed. Vitest as workspace test runner.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-30 20:59:34 +05:30

36 lines
1.2 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import {
IIOS_EVENTS,
PolicyDeniedError,
ACTOR_KINDS,
type ScopeVector,
type IiosPlatformPorts,
} from './index';
describe('iios-contracts public entrypoint', () => {
it('exports the event catalog', () => {
expect(IIOS_EVENTS.interactionNormalized).toBe('com.insignia.iios.interaction.normalized.v1');
});
it('PolicyDeniedError carries the stable POLICY_DENIED code', () => {
const err = new PolicyDeniedError('opa denied');
expect(err.code).toBe('POLICY_DENIED');
expect(err).toBeInstanceOf(Error);
});
it('actor kinds include the four real principals + UNKNOWN', () => {
expect(ACTOR_KINDS).toContain('HUMAN');
expect(ACTOR_KINDS).toContain('AI');
expect(ACTOR_KINDS).toContain('SERVICE');
});
it('types are usable (compile-time check)', () => {
const scope: ScopeVector = { orgId: 'org_1', appId: 'portal-demo' };
const ports: Pick<IiosPlatformPorts, 'opa'> = {
opa: { decide: async () => ({ decisionRef: 'd', allow: true, obligations: [], ttlSeconds: 60 }) },
};
expect(scope.appId).toBe('portal-demo');
expect(typeof ports.opa.decide).toBe('function');
});
});