/**
 * RED-GREEN tests for the hook install snippet generator.
 *
 * @connexum/ai-governance  hook-install path (companion to W4.4 proxy onboarding)
 */
import { describe, it } from 'node:test';
import * as assert from 'node:assert/strict';
import { buildHookInstallSnippet, SUPPORTED_HOOK_FRAMEWORKS, } from './hook-install-snippet.js';
const ALL = [
    'claude-code',
    'openai-agents-py',
    'openai-agents-ts',
    'langchain-py',
    'langchain-ts',
    'crew-ai',
    'langgraph',
];
describe('hook install snippet generator', () => {
    it('SUPPORTED_HOOK_FRAMEWORKS lists all 7 frameworks', () => {
        const ids = SUPPORTED_HOOK_FRAMEWORKS.map((f) => f.id).sort();
        assert.deepEqual(ids, [...ALL].sort());
    });
    it('every framework produces an install command + config path + snippet + verification', () => {
        for (const framework of ALL) {
            const s = buildHookInstallSnippet({ framework, tenantId: 'tenant-1' });
            assert.ok(s.installCommand.length > 0, `${framework} installCommand`);
            assert.ok(s.configPath.length > 0, `${framework} configPath`);
            assert.ok(s.snippet.length > 0, `${framework} snippet`);
            assert.ok(s.verificationStep.length > 0, `${framework} verificationStep`);
            assert.ok(s.snippet.includes('tenant-1'), `${framework} snippet must embed tenantId`);
        }
    });
    it('claude-code uses settings.json and PreToolUse / PostToolUse hooks', () => {
        const s = buildHookInstallSnippet({ framework: 'claude-code', tenantId: 'tenant-1' });
        assert.match(s.configPath, /\.claude\/settings\.json$/);
        assert.match(s.snippet, /PreToolUse/);
        assert.match(s.snippet, /PostToolUse/);
        assert.match(s.installCommand, /npx @connexum\/ai-governance init/);
    });
    it('openai-agents-py uses pip + wrap_agent', () => {
        const s = buildHookInstallSnippet({ framework: 'openai-agents-py', tenantId: 'tenant-1' });
        assert.match(s.installCommand, /pip install connexum-governance/);
        assert.match(s.snippet, /wrap_agent/);
        assert.match(s.snippet, /tenant_id="tenant-1"/);
    });
    it('openai-agents-ts uses npm + wrapAgent', () => {
        const s = buildHookInstallSnippet({ framework: 'openai-agents-ts', tenantId: 'tenant-1' });
        assert.match(s.installCommand, /npm install @connexum\/ai-governance/);
        assert.match(s.snippet, /wrapAgent/);
        assert.match(s.snippet, /tenantId: 'tenant-1'/);
    });
    it('langchain-py uses callbacks=[cb]', () => {
        const s = buildHookInstallSnippet({ framework: 'langchain-py', tenantId: 'tenant-1' });
        assert.match(s.snippet, /ConnexumGovernanceCallback/);
        assert.match(s.snippet, /callbacks=\[cb\]/);
    });
    it('langchain-ts uses callbacks: [cb]', () => {
        const s = buildHookInstallSnippet({ framework: 'langchain-ts', tenantId: 'tenant-1' });
        assert.match(s.snippet, /ConnexumGovernanceCallback/);
        assert.match(s.snippet, /callbacks: \[cb\]/);
    });
    it('crew-ai uses GovernedCrew', () => {
        const s = buildHookInstallSnippet({ framework: 'crew-ai', tenantId: 'tenant-1' });
        assert.match(s.snippet, /GovernedCrew/);
        assert.match(s.snippet, /connexum_tenant_id="tenant-1"/);
    });
    it('langgraph uses attach_governance', () => {
        const s = buildHookInstallSnippet({ framework: 'langgraph', tenantId: 'tenant-1' });
        assert.match(s.snippet, /attach_governance/);
    });
    it('endpoint override is honored', () => {
        const s = buildHookInstallSnippet({
            framework: 'claude-code',
            tenantId: 'tenant-1',
            endpoint: 'https://staging-events.my-cc.io/api/v1/events',
        });
        assert.ok(s.snippet.includes('staging-events.my-cc.io'));
    });
    it('default endpoint references proxy.my-cc.io', () => {
        const s = buildHookInstallSnippet({ framework: 'claude-code', tenantId: 'tenant-1' });
        assert.ok(s.endpoint.includes('proxy.my-cc.io'));
        assert.ok(s.snippet.includes('proxy.my-cc.io'));
    });
    it('missing tenantId throws (fail-closed)', () => {
        assert.throws(() => buildHookInstallSnippet({ framework: 'claude-code', tenantId: '' }), /tenantId is required/);
    });
    it('verificationStep mentions the dashboard + 5-second window for every framework', () => {
        for (const framework of ALL) {
            const s = buildHookInstallSnippet({ framework, tenantId: 'tenant-1' });
            assert.match(s.verificationStep, /dashboard/i);
            assert.match(s.verificationStep, /5 seconds/);
        }
    });
});
//# sourceMappingURL=hook-install-snippet.test.js.map