/**
 * RED-GREEN tests for F-NEW-PRODUCT-PASTE-YOUR-AGENT (W4.3).
 *
 * @connexum/ai-governance  F-NEW-PRODUCT-PASTE-YOUR-AGENT
 */
import { describe, it } from 'node:test';
import * as assert from 'node:assert/strict';
import { parseAgentDefinition } from './paste-your-agent.js';
describe('F-NEW-PRODUCT-PASTE-YOUR-AGENT (W4.3)', () => {
    it('detects Claude Code agent.md frontmatter', () => {
        const text = `---
name: mailer
tools: Read, Write, Bash, WebFetch
---

You are a mailer agent.`;
        const r = 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']);
    });
    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 = 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'));
    });
    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 = parseAgentDefinition(text);
        assert.equal(r.format, 'langchain');
        assert.deepEqual(r.manifest?.tools.sort(), ['computeTool', 'searchTool']);
    });
    it('detects MCP config JSON', () => {
        const text = JSON.stringify({
            mcpServers: {
                github: { command: 'mcp-server-github' },
                postgres: { url: 'https://internal.example/mcp' },
            },
        });
        const r = 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);
    });
    it('empty input returns format=unknown with reason', () => {
        const r = parseAgentDefinition('   \n\n   ');
        assert.equal(r.format, 'unknown');
        assert.equal(r.manifest, null);
        assert.match(r.detail ?? '', /empty/);
    });
    it('unrecognized text returns format=unknown with supported-formats hint', () => {
        const r = parseAgentDefinition('hello world, this is just prose');
        assert.equal(r.format, 'unknown');
        assert.match(r.detail ?? '', /no agent-definition format detected/);
    });
    it('hint=claude-code parses non-frontmatter only when content matches', () => {
        const text = `---
name: hinted
tools: A, B
---`;
        const r = parseAgentDefinition(text, 'claude-code');
        assert.equal(r.format, 'claude-code');
        assert.equal(r.manifest?.name, 'hinted');
    });
    it('downstream: pasted agent feeds OWASP scanner + auto-pack', async () => {
        const text = `---
name: payments
tools: Bash, postgres_query, WebFetch
---
Payment agent`;
        const { manifest } = parseAgentDefinition(text);
        assert.ok(manifest);
        const { scanAgent } = await import('./owasp-agentic-scanner.js');
        const { autoGenerateCompanyPack } = await import('./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);
    });
    it('claude-code frontmatter with no body still parses', () => {
        const r = parseAgentDefinition(`---\nname: skinny\ntools: Read\n---`);
        assert.equal(r.format, 'claude-code');
        assert.equal(r.manifest?.name, 'skinny');
    });
    it('JSON that is NOT an mcp-config returns unknown (not mcp-config)', () => {
        const text = JSON.stringify({ unrelated: 'data', name: 'something' });
        const r = parseAgentDefinition(text);
        assert.equal(r.format, 'unknown');
    });
});
//# sourceMappingURL=paste-your-agent.test.js.map