"use strict";
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 path = __importStar(require("path"));
const os = __importStar(require("os"));
const OUTCOME_DIR = path.join(os.homedir(), '.fivo', 'cell', 'outcome-graph');
describe('WorkflowOutcomeGraph', () => {
    let module;
    beforeAll(async () => {
        module = await Promise.resolve().then(() => __importStar(require('../../walls/03-knowledge/decisions/workflow-outcome-graph')));
    });
    beforeEach(() => {
        const fs = require('fs');
        if (fs.existsSync(OUTCOME_DIR)) {
            const fp = path.join(OUTCOME_DIR, 'sequences.json');
            if (fs.existsSync(fp))
                fs.unlinkSync(fp);
        }
    });
    test('recordOutcome creates a sequence', () => {
        module.recordOutcome({ patternId: 'p1', action: 'refactor', description: 'test', success: true, durationMs: 100, timestamp: Date.now() });
        const stats = module.getGraphStats();
        expect(stats.totalSessions).toBe(1);
    });
    test('recordStepSequence stores the sequence', () => {
        module.recordStepSequence({ sessionId: 's1', steps: ['step1', 'step2'], success: true, totalDurationMs: 200, timestamp: Date.now() });
        module.recordStepSequence({ sessionId: 's2', steps: ['step1', 'step3'], success: false, totalDurationMs: 300, timestamp: Date.now() });
        const stats = module.getGraphStats();
        expect(stats.totalSessions).toBe(2);
        expect(stats.uniqueSteps).toBe(3);
    });
    test('getNodes returns aggregated nodes', () => {
        module.recordStepSequence({ sessionId: 's1', steps: ['a', 'b', 'c'], success: true, totalDurationMs: 100, timestamp: Date.now() });
        module.recordStepSequence({ sessionId: 's2', steps: ['a', 'b'], success: false, totalDurationMs: 200, timestamp: Date.now() });
        const nodes = module.getNodes();
        expect(nodes.length).toBe(3);
        const aNode = nodes.find((n) => n.step === 'a');
        expect(aNode.count).toBe(2);
        expect(aNode.successRate).toBe(0.5);
    });
    test('getEdges returns aggregated edges', () => {
        module.recordStepSequence({ sessionId: 's1', steps: ['a', 'b', 'c'], success: true, totalDurationMs: 100, timestamp: Date.now() });
        module.recordStepSequence({ sessionId: 's2', steps: ['a', 'b'], success: false, totalDurationMs: 200, timestamp: Date.now() });
        const edges = module.getEdges();
        const abEdge = edges.find((e) => e.from === 'a' && e.to === 'b');
        expect(abEdge.count).toBe(2);
    });
    test('getPathProbabilities returns paths', () => {
        module.recordStepSequence({ sessionId: 's1', steps: ['a', 'b', 'c'], success: true, totalDurationMs: 100, timestamp: Date.now() });
        module.recordStepSequence({ sessionId: 's2', steps: ['a', 'c'], success: true, totalDurationMs: 100, timestamp: Date.now() });
        const paths = module.getPathProbabilities('a', 'c');
        expect(paths.length).toBeGreaterThanOrEqual(1);
        expect(paths[0].from).toBe('a');
        expect(paths[0].to).toBe('c');
    });
});
//# sourceMappingURL=workflow-outcome-graph.test.js.map