"use strict";
/**
 * RED-GREEN tests for F-NEW-PRODUCT-PASTE-YOUR-AGENT (W4.3).
 *
 * @connexum/ai-governance  F-NEW-PRODUCT-PASTE-YOUR-AGENT
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const node_test_1 = require("node:test");
const assert = __importStar(require("node:assert/strict"));
const paste_your_agent_1 = require("./paste-your-agent");
(0, node_test_1.describe)('F-NEW-PRODUCT-PASTE-YOUR-AGENT (W4.3)', () => {
    (0, node_test_1.it)('detects Claude Code agent.md frontmatter', () => {
        const text = `---
name: mailer
tools: Read, Write, Bash, WebFetch
---

You are a mailer agent.`;
        const r = (0, paste_your_agent_1.parseAgentDefinition)(text);
        assert.equal(r.format, 'claude-code');
        assert.equal(r.manifest?.agentId, 'claude-code:mailer');
        assert.deepEqual(r.manifest?.tools, ['Read', 'Write', 'Bash', 'WebFetch']);
    });
    (0, node_test_1.it)('detects OpenAI Agents SDK new Agent() instantiation', () => {
        const text = `
      import { Agent } from '@openai/agents';
      const a = new Agent({
        name: 'researcher',
        tools: [webSearch, summarize, dbQuery],
        instructions: 'do research'
      });
    `;
        const r = (0, paste_your_agent_1.parseAgentDefinition)(text);
        assert.equal(r.format, 'openai-agents');
        assert.equal(r.manifest?.name, 'researcher');
        assert.ok(r.manifest?.tools.includes('webSearch'));
        assert.ok(r.manifest?.tools.includes('dbQuery'));
    });
    (0, node_test_1.it)('detects LangChain Tool / DynamicTool', () => {
        const text = `
      const search = new DynamicTool({ name: 'searchTool', description: 'search' });
      const compute = new Tool({ name: 'computeTool', description: 'compute' });
    `;
        const r = (0, paste_your_agent_1.parseAgentDefinition)(text);
        assert.equal(r.format, 'langchain');
        assert.deepEqual(r.manifest?.tools.sort(), ['computeTool', 'searchTool']);
    });
    (0, node_test_1.it)('detects MCP config JSON', () => {
        const text = JSON.stringify({
            mcpServers: {
                github: { command: 'mcp-server-github' },
                postgres: { url: 'https://internal.example/mcp' },
            },
        });
        const r = (0, paste_your_agent_1.parseAgentDefinition)(text);
        assert.equal(r.format, 'mcp-config');
        assert.deepEqual(r.manifest?.tools.sort(), ['mcp__github', 'mcp__postgres']);
        assert.equal(r.manifest?.mcpServers?.length, 2);
    });
    (0, node_test_1.it)('empty input returns format=unknown with reason', () => {
        const r = (0, paste_your_agent_1.parseAgentDefinition)('   \n\n   ');
        assert.equal(r.format, 'unknown');
        assert.equal(r.manifest, null);
        assert.match(r.detail ?? '', /empty/);
    });
    (0, node_test_1.it)('unrecognized text returns format=unknown with supported-formats hint', () => {
        const r = (0, paste_your_agent_1.parseAgentDefinition)('hello world, this is just prose');
        assert.equal(r.format, 'unknown');
        assert.match(r.detail ?? '', /no agent-definition format detected/);
    });
    (0, node_test_1.it)('hint=claude-code parses non-frontmatter only when content matches', () => {
        const text = `---
name: hinted
tools: A, B
---`;
        const r = (0, paste_your_agent_1.parseAgentDefinition)(text, 'claude-code');
        assert.equal(r.format, 'claude-code');
        assert.equal(r.manifest?.name, 'hinted');
    });
    (0, node_test_1.it)('downstream: pasted agent feeds OWASP scanner + auto-pack', async () => {
        const text = `---
name: payments
tools: Bash, postgres_query, WebFetch
---
Payment agent`;
        const { manifest } = (0, paste_your_agent_1.parseAgentDefinition)(text);
        assert.ok(manifest);
        const { scanAgent } = await Promise.resolve().then(() => __importStar(require('./owasp-agentic-scanner.js')));
        const { autoGenerateCompanyPack } = await Promise.resolve().then(() => __importStar(require('./auto-pack-generator.js')));
        const report = scanAgent(manifest);
        assert.ok(report.findings.length > 0, 'scanner produced findings');
        const result = autoGenerateCompanyPack(manifest, { acceptAllSuggestedRules: true });
        assert.ok(result.pack.id.startsWith('auto-pack-'));
        assert.ok(result.acceptedRules.length >= 1);
    });
    (0, node_test_1.it)('claude-code frontmatter with no body still parses', () => {
        const r = (0, paste_your_agent_1.parseAgentDefinition)(`---\nname: skinny\ntools: Read\n---`);
        assert.equal(r.format, 'claude-code');
        assert.equal(r.manifest?.name, 'skinny');
    });
    (0, node_test_1.it)('JSON that is NOT an mcp-config returns unknown (not mcp-config)', () => {
        const text = JSON.stringify({ unrelated: 'data', name: 'something' });
        const r = (0, paste_your_agent_1.parseAgentDefinition)(text);
        assert.equal(r.format, 'unknown');
    });
});
//# sourceMappingURL=paste-your-agent.test.js.map