"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const strict_1 = __importDefault(require("node:assert/strict"));
const node_fs_1 = __importDefault(require("node:fs"));
const node_test_1 = __importDefault(require("node:test"));
const kicad_protocol_schemas_1 = require("@oaslananka/kicad-protocol-schemas");
(0, node_test_1.default)("exports every protocol schema definition and filesystem path", () => {
    strict_1.default.deepEqual(kicad_protocol_schemas_1.PROTOCOL_SCHEMA_NAMES, [
        "bom-netlist-summary",
        "compatibility-manifest",
        "extension-active-context",
        "kicad-mcp-server-info",
        "mcp-server-health",
        "mcp-tool-capability",
        "mcp-tool-discovery",
        "normalized-diagnostic",
    ]);
    for (const schemaName of kicad_protocol_schemas_1.PROTOCOL_SCHEMA_NAMES) {
        const schema = kicad_protocol_schemas_1.PROTOCOL_SCHEMA_DEFINITIONS[schemaName];
        strict_1.default.equal(schema.$schema, "https://json-schema.org/draft/2020-12/schema");
        strict_1.default.equal((0, kicad_protocol_schemas_1.protocolSchemaVersion)(schemaName), "1.0.0");
        strict_1.default.ok(node_fs_1.default.existsSync((0, kicad_protocol_schemas_1.protocolSchemaPath)(schemaName)));
    }
});
(0, node_test_1.default)("validates server-info payloads and reports schema errors", () => {
    const valid = (0, kicad_protocol_schemas_1.validateMcpServerInfoContract)(serverInfoFixture());
    strict_1.default.equal(valid.valid, true);
    strict_1.default.equal(valid.data?.server, "kicad-mcp-pro");
    const invalid = (0, kicad_protocol_schemas_1.validateMcpServerInfoContract)({
        ...serverInfoFixture(),
        server: "other-server",
    });
    strict_1.default.equal(invalid.valid, false);
    strict_1.default.ok(invalid.errors.some((error) => error.path === "/server"));
});
(0, node_test_1.default)("rejects payloads that declare an unsupported schema major", () => {
    const invalid = (0, kicad_protocol_schemas_1.validateMcpServerInfoContract)({
        ...serverInfoFixture(),
        schemaVersion: "2.0.0",
    });
    strict_1.default.equal(invalid.valid, false);
    strict_1.default.deepEqual(invalid.errors, [
        {
            path: "/schemaVersion",
            message: "kicad-mcp-server-info payload declares unsupported schema major 2; expected 1.x",
            keyword: "schemaMajor",
        },
    ]);
});
(0, node_test_1.default)("validates shared protocol payload families", () => {
    strict_1.default.equal((0, kicad_protocol_schemas_1.validateToolCapabilityMetadata)({
        schemaVersion: "1.0.0",
        name: "kicad_health",
        profiles: ["minimal", "analysis"],
        category: "project",
        tier: "read",
        runtime: "none",
        writes_files: false,
        writes_kicad_gui_state: false,
        supports_dry_run: false,
        supports_rollback: false,
        human_gate_required: false,
        requires_human_confirmation: false,
        description: "",
        verification_level: "verified",
        maturity: "stable",
        advisory_level: "none",
        tested_kicad_versions: ["10.0.x"],
    }).valid, true);
    const toolDiscovery = (0, kicad_protocol_schemas_1.validateMcpToolDiscovery)({
        schemaVersion: "1.7.0",
        _meta: { "io.modelcontextprotocol/related-task": "OASLANA-52" },
        nextCursor: "next-page",
        tools: [{ name: "kicad_health", inputSchema: { type: "object" } }],
        resources: [],
        prompts: [],
        vendorExtension: { accepted: true },
    });
    strict_1.default.equal(toolDiscovery.valid, true);
    strict_1.default.equal(toolDiscovery.data?.nextCursor, "next-page");
    strict_1.default.equal((0, kicad_protocol_schemas_1.validateMcpToolDiscovery)({
        tools: [{ name: "kicad_health", inputSchema: { type: "object" } }],
        resources: [],
        prompts: [],
    }).valid, true);
    strict_1.default.equal((0, kicad_protocol_schemas_1.validateExtensionActiveContextPayload)({
        schemaVersion: "1.0.0",
        activeFile: "board.kicad_pcb",
        fileType: "pcb",
        drcErrors: ["clearance"],
        cursorPosition: { line: 1, character: 2 },
    }).valid, true);
    strict_1.default.equal((0, kicad_protocol_schemas_1.validateNormalizedDiagnostic)({
        schemaVersion: "1.0.0",
        source: "drc",
        severity: "error",
        message: "Clearance violation",
        path: "board.kicad_pcb",
        capturedAt: "2026-05-25T00:00:00.000Z",
    }).valid, true);
    strict_1.default.equal((0, kicad_protocol_schemas_1.validateBomNetlistSummary)({
        schemaVersion: "1.0.0",
        project: { name: "demo" },
        bom: {
            totalComponents: 1,
            uniqueValues: 1,
            entries: [
                {
                    references: ["R1"],
                    value: "10k",
                    footprint: "Resistor_SMD:R_0603",
                    quantity: 1,
                },
            ],
        },
        netlist: {
            netCount: 1,
            nodes: [{ netName: "GND", pins: [{ reference: "R1", pin: "1" }] }],
        },
    }).valid, true);
    strict_1.default.equal((0, kicad_protocol_schemas_1.validateMcpServerHealth)({
        schemaVersion: "1.0.0",
        server: "kicad-mcp-pro",
        version: "3.5.2",
        status: "ok",
        mcpProtocolVersion: "2025-11-25",
        toolSchemaVersion: "1.0.0",
        transport: {
            type: "streamable-http",
            endpoint: "http://127.0.0.1:3334/mcp",
        },
        kicad: { cliFound: true, cliVersion: "KiCad 10.0.3", ipcAvailable: true },
        diagnostics: [],
    }).valid, true);
    strict_1.default.equal((0, kicad_protocol_schemas_1.validateCompatibilityManifest)({
        schemaVersion: "1.0.0",
        products: {
            "kicad-studio": { version: "1.0.0", supportedSchemaMajors: [1] },
            "kicad-mcp-pro": { version: "3.5.2", supportedSchemaMajors: [1] },
        },
        schemas: {
            "kicad-mcp-server-info": {
                current: "1.0.0",
                compatibility: ">=1.0.0 <2.0.0",
            },
        },
        policy: {
            breakingChanges: "major",
            additiveChanges: "minor",
            documentationChanges: "patch",
        },
    }).valid, true);
});
function serverInfoFixture() {
    return {
        schemaVersion: "1.2.0",
        server: "kicad-mcp-pro",
        description: "KiCad MCP Pro server for PCB and schematic workflows.",
        localizedDescriptions: {
            en: "KiCad MCP Pro server for PCB and schematic workflows.",
            tr: "PCB ve sematik is akislari icin KiCad MCP Pro sunucusu.",
        },
        version: "3.5.2",
        mcpProtocolVersion: "2025-11-25",
        toolSchemaVersion: "1.0.0",
        compatibilityRange: {
            kicadStudio: {
                required: ">=3.5.2 <4.0.0",
                recommended: ">=3.5.2 <4.0.0",
                testedAgainst: "3.5.2",
            },
            kicadMcpPro: {
                required: ">=1.0.0 <2.0.0",
                testedAgainst: "1.0.0",
            },
        },
        transport: {
            type: "streamable-http",
            streamableHttp: true,
            statelessHttp: true,
            legacySse: false,
            authRequired: false,
            endpoint: "http://127.0.0.1:3334/mcp",
        },
        kicad: {
            cliFound: true,
            cliPath: "/usr/bin/kicad-cli",
            cliVersion: "KiCad 10.0.3",
            ipcAvailable: true,
            ipcVersion: "KiCad 10.0.3",
            ipcApiVersion: null,
            ipcMajorVersion: 10,
            ipcEndpointSource: "default",
            livePcbContext: true,
            liveSchematicContext: false,
            ipcDocumentLoaded: true,
        },
        operatingMode: {
            active: "readonly",
            default: "readonly",
            available: ["readonly", "write", "manufacturing", "experimental"],
            experimentalEnabled: false,
            toolAvailability: {
                kicad_get_version: {
                    available: true,
                    requiredMode: "readonly",
                    reason: null,
                },
                pcb_add_track: {
                    available: false,
                    requiredMode: "write",
                    reason: "Requires write operating mode.",
                },
                export_manufacturing_package: {
                    available: false,
                    requiredMode: "manufacturing",
                    reason: "Requires manufacturing operating mode.",
                },
                route_tune_length: {
                    available: false,
                    requiredMode: "experimental",
                    reason: "Requires experimental operating mode.",
                },
            },
        },
        capabilities: {
            fileBackedDrc: true,
            fileBackedErc: true,
            fileBackedExports: true,
            livePcbRead: true,
            livePcbWrite: true,
            liveSchematicRead: false,
            liveSchematicWrite: false,
            liveEditingTools: {
                pcb_place_component: liveTool(9),
                pcb_route_trace: {
                    available: true,
                    backend: "kicad-ipc",
                    reason: null,
                    minimumKiCadMajor: 9,
                },
                pcb_add_zone: liveTool(9),
                pcb_set_design_rules: {
                    available: true,
                    backend: "hybrid-file-ipc",
                    reason: null,
                    minimumKiCadMajor: 9,
                },
                pcb_move_component: liveTool(9),
                pcb_delete_object: liveTool(9),
                sch_add_component: liveTool(10),
                sch_add_wire: liveTool(10),
                sch_modify_property: liveTool(10),
            },
            chatgptConnectorCompatible: false,
            cliExports: {
                ipc2581: true,
                odb: true,
                svg: true,
                dxf: true,
                step: true,
                stepz: true,
                xao: true,
                render: true,
                spiceNetlist: true,
            },
        },
        diagnostics: [],
    };
}
function liveTool(minimumKiCadMajor) {
    return {
        available: true,
        backend: "kicad-ipc",
        reason: null,
        minimumKiCadMajor,
    };
}
//# sourceMappingURL=index.test.js.map