"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 fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const GovernanceConsentStore_1 = require("./orchestrator/GovernanceConsentStore");
const GovernanceLayer_1 = require("./orchestrator/GovernanceLayer");
const SandboxPolicy_1 = require("./orchestrator/SandboxPolicy");
const SecurityEventStore_1 = require("./orchestrator/SecurityEventStore");
function assert(condition, message) {
    if (!condition)
        throw new Error(message);
}
async function main() {
    const root = process.cwd();
    const consent = new GovernanceConsentStore_1.GovernanceConsentStore(root);
    const governance = new GovernanceLayer_1.GovernanceLayer();
    const sandbox = new SandboxPolicy_1.SandboxPolicy();
    const security = new SecurityEventStore_1.SecurityEventStore(root);
    consent.approve('test-user', 'destructive-action');
    assert(consent.hasRecentApproval('test-user', 'destructive-action', 15), 'recent consent should exist');
    const destructive = governance.evaluate('rm -rf production backups');
    assert(destructive.requiresConsent === true, 'destructive flow should require consent');
    const sandboxBlocked = sandbox.evaluate('gemini', 'high');
    assert(sandboxBlocked.allowed === false, 'high risk secondary executor should be blocked');
    const sandboxAllowed = sandbox.evaluate('codex', 'high');
    assert(sandboxAllowed.allowed === true, 'high risk codex path should remain allowed');
    security.append({
        type: 'governance_decision',
        level: 'warning',
        summary: 'test event',
        details: 'advanced-test',
        at: new Date().toISOString(),
        taskId: 'task-test',
        userId: 'test-user'
    });
    assert(fs.existsSync(path.join(root, '.artifacts', 'security-events.jsonl')), 'security events file should exist');
    console.log('TEST_GOVERNANCE_ADVANCED_OK');
}
main().catch((error) => {
    console.error(error.message || error);
    process.exit(1);
});
