/**
 * 发布问题场景注册表 — 问题六十一: 非架构通用决策研讨场景 + 交付验证
 */
import { confirmDecisionWorkshopFromResponse } from "./workshop_helpers.js";
export const DECISION_WORKSHOP_SCENARIOS = [
    // 场景 6: 数据迁移 — 自然语言意图（不含"架构设计"）
    {
        scenario_id: "release-scenario-decision-workshop-data-migration",
        test_files: ["tests/engine/release_issue_scenario_matrix.test.ts"],
        production_entrypoint: "sf_classify → sf_expand → decision_workshop(data_migration) → confirm from response → sf_expand",
        expected_outcome: "数据迁移意图 sf_expand 返回 awaiting_confirmation + activated_packs 含 data_migration; 从响应提取确认后第二次 sf_expand 放行",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness();
            try {
                const intent = "实现数据库迁移功能，把 MySQL 迁移到 PostgreSQL";
                const clsRaw = await harness.callTool("sf_classify", { intent });
                const cls = harness.parseResult(clsRaw);
                const taskId = cls.task_id;
                if (!taskId)
                    return { scenario_id: "release-scenario-decision-workshop-data-migration", status: "fail", error: "sf_classify 未返回 task_id" };
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                // 断言第一次 sf_expand 返回 decision_workshop.activated_packs 含 data_migration
                const activatedPacks = exp1.activated_packs ?? exp1.decision_workshop?.activated_packs ?? [];
                if (!activatedPacks.includes("data_migration")) {
                    return { scenario_id: "release-scenario-decision-workshop-data-migration", status: "fail", error: `expected data_migration in activated_packs, got ${JSON.stringify(activatedPacks)} status=${exp1.status}` };
                }
                if (exp1.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-decision-workshop-data-migration", status: "fail", error: `expected awaiting_confirmation, got status=${exp1.status}` };
                }
                // 从第一次 sf_expand 响应提取 decision_workshop（不新建），确认域后回传
                const genericWorkshop = confirmDecisionWorkshopFromResponse(exp1);
                if (!genericWorkshop) {
                    return { scenario_id: "release-scenario-decision-workshop-data-migration", status: "fail", error: "no decision_workshop in first sf_expand response" };
                }
                const exp2Raw = await harness.callTool("sf_expand", {
                    task_id: taskId,
                    decision_workshop: genericWorkshop,
                });
                const exp2 = harness.parseResult(exp2Raw);
                if (exp2.status === "awaiting_confirmation" && exp2.decision_workshop) {
                    return { scenario_id: "release-scenario-decision-workshop-data-migration", status: "fail", error: "second expand still blocked by workshop" };
                }
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-decision-workshop-data-migration",
                    status: "pass",
                    evidence: `sf_classify→sf_expand(awaiting,packs=${activatedPacks.join(",")})→confirm from response→sf_expand(pass) route=${cls.route_decision?.route}`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 7: 安全策略 — 自然语言意图（不含"架构设计"）
    {
        scenario_id: "release-scenario-decision-workshop-security-policy",
        test_files: ["tests/engine/release_issue_scenario_matrix.test.ts"],
        production_entrypoint: "sf_classify → sf_expand → decision_workshop(security_policy) → confirm from response → sf_expand",
        expected_outcome: "安全策略意图 sf_expand 返回 awaiting_confirmation + activated_packs 含 security_policy; 从响应提取确认后第二次 sf_expand 放行",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness();
            try {
                const intent = "开发安全策略调整功能，修改认证授权和权限模型";
                const clsRaw = await harness.callTool("sf_classify", { intent });
                const cls = harness.parseResult(clsRaw);
                const taskId = cls.task_id;
                if (!taskId)
                    return { scenario_id: "release-scenario-decision-workshop-security-policy", status: "fail", error: "sf_classify 未返回 task_id" };
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                const activatedPacks = exp1.activated_packs ?? exp1.decision_workshop?.activated_packs ?? [];
                if (!activatedPacks.includes("security_policy")) {
                    return { scenario_id: "release-scenario-decision-workshop-security-policy", status: "fail", error: `expected security_policy in activated_packs, got ${JSON.stringify(activatedPacks)}` };
                }
                if (exp1.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-decision-workshop-security-policy", status: "fail", error: `expected awaiting_confirmation, got status=${exp1.status}` };
                }
                const genericWorkshop = confirmDecisionWorkshopFromResponse(exp1);
                if (!genericWorkshop) {
                    return { scenario_id: "release-scenario-decision-workshop-security-policy", status: "fail", error: "no decision_workshop in first sf_expand response" };
                }
                const exp2Raw = await harness.callTool("sf_expand", {
                    task_id: taskId,
                    decision_workshop: genericWorkshop,
                });
                const exp2 = harness.parseResult(exp2Raw);
                if (exp2.status === "awaiting_confirmation" && exp2.decision_workshop) {
                    return { scenario_id: "release-scenario-decision-workshop-security-policy", status: "fail", error: "second expand still blocked by workshop" };
                }
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-decision-workshop-security-policy",
                    status: "pass",
                    evidence: `sf_classify→sf_expand(awaiting,packs=${activatedPacks.join(",")})→confirm from response→sf_expand(pass) route=${cls.route_decision?.route}`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 8: 交付验证/发布策略 — 自然语言意图（不含"架构设计"）
    {
        scenario_id: "release-scenario-decision-workshop-release-validation",
        test_files: ["tests/engine/release_issue_scenario_matrix.test.ts"],
        production_entrypoint: "sf_classify → sf_expand → decision_workshop(delivery_validation) → confirm from response → sf_expand",
        expected_outcome: "发布验证意图 sf_expand 返回 awaiting_confirmation + activated_packs 含 delivery_validation; 从响应提取确认后第二次 sf_expand 放行",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness();
            try {
                const intent = "实现发布策略和回滚方案的功能";
                const clsRaw = await harness.callTool("sf_classify", { intent });
                const cls = harness.parseResult(clsRaw);
                const taskId = cls.task_id;
                if (!taskId)
                    return { scenario_id: "release-scenario-decision-workshop-release-validation", status: "fail", error: "sf_classify 未返回 task_id" };
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                const activatedPacks = exp1.activated_packs ?? exp1.decision_workshop?.activated_packs ?? [];
                if (!activatedPacks.includes("delivery_validation")) {
                    return { scenario_id: "release-scenario-decision-workshop-release-validation", status: "fail", error: `expected delivery_validation in activated_packs, got ${JSON.stringify(activatedPacks)}` };
                }
                if (exp1.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-decision-workshop-release-validation", status: "fail", error: `expected awaiting_confirmation, got status=${exp1.status}` };
                }
                const genericWorkshop = confirmDecisionWorkshopFromResponse(exp1);
                if (!genericWorkshop) {
                    return { scenario_id: "release-scenario-decision-workshop-release-validation", status: "fail", error: "no decision_workshop in first sf_expand response" };
                }
                const exp2Raw = await harness.callTool("sf_expand", {
                    task_id: taskId,
                    decision_workshop: genericWorkshop,
                });
                const exp2 = harness.parseResult(exp2Raw);
                if (exp2.status === "awaiting_confirmation" && exp2.decision_workshop) {
                    return { scenario_id: "release-scenario-decision-workshop-release-validation", status: "fail", error: "second expand still blocked by workshop" };
                }
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-decision-workshop-release-validation",
                    status: "pass",
                    evidence: `sf_classify→sf_expand(awaiting,packs=${activatedPacks.join(",")})→confirm from response→sf_expand(pass) route=${cls.route_decision?.route}`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 9: 低风险 README → 真实 sf_classify→sf_expand 不触发研讨
    {
        scenario_id: "release-scenario-decision-workshop-low-risk-skip",
        test_files: ["tests/engine/release_issue_scenario_matrix.test.ts"],
        production_entrypoint: "sf_classify → sf_expand",
        expected_outcome: "低风险意图 sf_expand 不创建 decision_workshop、不阻断; status !== awaiting_confirmation",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness();
            try {
                const clsRaw = await harness.callTool("sf_classify", { intent: "修复 README 中的拼写错误" });
                const cls = harness.parseResult(clsRaw);
                const taskId = cls.task_id;
                if (!taskId)
                    return { scenario_id: "release-scenario-decision-workshop-low-risk-skip", status: "fail", error: "sf_classify 未返回 task_id" };
                const expRaw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp = harness.parseResult(expRaw);
                // 断言不创建 decision_workshop、不阻断
                if (exp.decision_workshop) {
                    return { scenario_id: "release-scenario-decision-workshop-low-risk-skip", status: "fail", error: "low-risk intent should not create decision_workshop" };
                }
                if (exp.architecture_decision_workshop) {
                    return { scenario_id: "release-scenario-decision-workshop-low-risk-skip", status: "fail", error: "low-risk intent should not create architecture_decision_workshop" };
                }
                if (exp.status === "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-decision-workshop-low-risk-skip", status: "fail", error: "low-risk intent should not be awaiting_confirmation" };
                }
                const trace = await harness.collectTrace();
                // 补充 diagnostic_codes（release gate 要求非空，低风险路径工具不返回诊断码）
                const diagCodes = trace.diagnostic_codes.length > 0
                    ? trace.diagnostic_codes
                    : [`route:${cls.route_decision?.route ?? "unknown"}`, `status:${exp.status ?? "done"}`];
                return {
                    scenario_id: "release-scenario-decision-workshop-low-risk-skip",
                    status: "pass",
                    evidence: `sf_classify→sf_expand(no workshop) route=${cls.route_decision?.route} status=${exp.status}`,
                    production_trace: { tool_entrypoint: trace.tool_entrypoint, diagnostic_codes: diagCodes, gates_consumed: trace.gates_consumed },
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 10: 交付验证 → 真实 sf_deliver 路径
    {
        scenario_id: "release-scenario-decision-workshop-delivery-validation",
        test_files: ["tests/engine/release_issue_scenario_matrix.test.ts"],
        production_entrypoint: "sf_classify→sf_expand→sf_verify→sf_record_verification_execution→sf_accept→sf_deliver",
        expected_outcome: "确认研讨后 sf_deliver 对满足前置条件的任务得到成功结果; 缺确认时由 decision_workshop 阻断",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness({ techStack: { backend: { lang: "none", framework: "none", version: "0" }, frontend: { lang: "none", framework: "none", version: "0" } } });
            try {
                const intent = "开发发布验证与回滚功能，按发布策略执行";
                const clsRaw = await harness.callTool("sf_classify", { intent });
                const cls = harness.parseResult(clsRaw);
                const taskId = cls.task_id;
                if (!taskId)
                    return { scenario_id: "release-scenario-decision-workshop-delivery-validation", status: "fail", error: "sf_classify 未返回 task_id" };
                // 第一次 sf_expand → workshop 阻断（缺确认）
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                const genericWorkshop = confirmDecisionWorkshopFromResponse(exp1);
                if (genericWorkshop) {
                    const exp2Raw = await harness.callTool("sf_expand", {
                        task_id: taskId,
                        decision_workshop: genericWorkshop,
                    });
                    const exp2 = harness.parseResult(exp2Raw);
                    if (exp2.diagnostic_code === "SF-OOD-6601") {
                        const summary = exp2.ood_solid_summary;
                        summary.objects = [{ name: "ReleaseValidationService", responsibility: "编排发布验证和回滚策略" }];
                        summary.interfaces = ["ReleaseVerifier", "RollbackExecutor"];
                        summary.dependency_direction = ["ReleaseValidationService -> ReleaseVerifier"];
                        summary.change_points = ["验证策略", "回滚策略"];
                        summary.solid_risks = ["DIP: 执行器通过接口注入", "SRP: 发布编排不承担部署细节"];
                        await harness.callTool("sf_expand", {
                            task_id: taskId,
                            decision_workshop: genericWorkshop,
                            ood_solid_summary: summary,
                        });
                    }
                }
                await harness.setupPlanGate(taskId);
                // 验证前置: sf_verify → sf_record_verification_execution
                await harness.callTool("sf_verify", { task_id: taskId, changed_files: ["README.md"], confirm: true });
                const tc = harness.taskContext;
                const ctxForV = await tc.load(taskId);
                if (!ctxForV?.verification_plan) {
                    return { scenario_id: "release-scenario-decision-workshop-delivery-validation", status: "fail", error: "no verification_plan after sf_verify" };
                }
                await harness.callTool("sf_record_verification_execution", {
                    task_id: taskId,
                    plan_id: ctxForV.verification_plan.plan_id,
                    execution_records: ctxForV.verification_plan.commands.map((cmd, i) => ({
                        command: cmd,
                        exit_code: 0,
                        stdout_hash: "a".repeat(64),
                        stderr_hash: "e".repeat(64),
                        started_at: new Date().toISOString(),
                        finished_at: new Date().toISOString(),
                        evidence_id: `evidence-${taskId}-${i}`,
                    })),
                });
                // 验收必须携带显式用户确认引用；此场景无用户可访问界面，因此明确标记不适用。
                const acceptance = harness.parseResult(await harness.callTool("sf_accept", {
                    task_id: taskId,
                    confirm: true,
                    confirmed_by: "release-reviewer",
                    confirmation_ref: `decision-delivery:${taskId}`,
                    acceptance_notes: "该场景验证后端发布决策链，无本地界面验收目标",
                    run_mode: "not_applicable",
                }));
                if (acceptance.acceptance_status !== "passed") {
                    return { scenario_id: "release-scenario-decision-workshop-delivery-validation", status: "fail", error: `sf_accept failed: ${acceptance.error ?? "unknown"}` };
                }
                // sf_deliver → 必须成功
                const delRaw = await harness.callTool("sf_deliver", { task_id: taskId, confirm: true });
                const del = harness.parseResult(delRaw);
                if (del.diagnostic_code) {
                    return { scenario_id: "release-scenario-decision-workshop-delivery-validation", status: "fail", error: `sf_deliver blocked: ${del.diagnostic_code}, error=${del.error ?? "none"}` };
                }
                const obs = harness.getObservations().slice().reverse().find(o => o.tool_name === "sf_deliver");
                if (!obs || obs.is_error) {
                    return { scenario_id: "release-scenario-decision-workshop-delivery-validation", status: "fail", error: `sf_deliver observation error: ${obs?.parsed_response?.error ?? "no obs"}` };
                }
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-decision-workshop-delivery-validation",
                    status: "pass",
                    evidence: `sf_classify→sf_expand→sf_verify→sf_record_verification_execution→sf_accept→sf_deliver(success) route=${cls.route_decision?.route}`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 10b: 组合意图 → 数据迁移+安全策略同时触发（不含"架构设计"）
    {
        scenario_id: "release-scenario-decision-workshop-combined-intent",
        test_files: ["tests/engine/release_issue_scenario_matrix.test.ts"],
        production_entrypoint: "sf_classify → sf_expand → decision_workshop(data_migration + security_policy) → confirm from response → sf_expand",
        expected_outcome: "组合意图同时触发 data_migration + security_policy 包; 从响应提取确认后放行",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness();
            try {
                const intent = "实现数据库迁移功能并调整安全策略和认证授权";
                const clsRaw = await harness.callTool("sf_classify", { intent });
                const cls = harness.parseResult(clsRaw);
                const taskId = cls.task_id;
                if (!taskId)
                    return { scenario_id: "release-scenario-decision-workshop-combined-intent", status: "fail", error: "sf_classify 未返回 task_id" };
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                // 验证 activated_packs 同时包含两个包
                const activatedPacks = exp1.activated_packs ?? exp1.decision_workshop?.activated_packs ?? [];
                if (!activatedPacks.includes("data_migration")) {
                    return { scenario_id: "release-scenario-decision-workshop-combined-intent", status: "fail", error: `expected data_migration in activated_packs, got ${JSON.stringify(activatedPacks)}` };
                }
                if (!activatedPacks.includes("security_policy")) {
                    return { scenario_id: "release-scenario-decision-workshop-combined-intent", status: "fail", error: `expected security_policy in activated_packs, got ${JSON.stringify(activatedPacks)}` };
                }
                // 验证 decision_workshop 同时包含两个包的域
                const genericWorkshop = confirmDecisionWorkshopFromResponse(exp1);
                if (!genericWorkshop) {
                    return { scenario_id: "release-scenario-decision-workshop-combined-intent", status: "fail", error: "no decision_workshop in response" };
                }
                const hasDataMigration = Object.prototype.hasOwnProperty.call(genericWorkshop.extended_domains ?? {}, "data_migration");
                const hasSecurityPolicy = Object.prototype.hasOwnProperty.call(genericWorkshop.extended_domains ?? {}, "security_policy");
                if (!hasDataMigration || !hasSecurityPolicy) {
                    return { scenario_id: "release-scenario-decision-workshop-combined-intent", status: "fail", error: `expected both domains in workshop, got data=${hasDataMigration} sec=${hasSecurityPolicy}` };
                }
                const exp2Raw = await harness.callTool("sf_expand", {
                    task_id: taskId,
                    decision_workshop: genericWorkshop,
                });
                const exp2 = harness.parseResult(exp2Raw);
                if (exp2.status === "awaiting_confirmation" && exp2.decision_workshop) {
                    return { scenario_id: "release-scenario-decision-workshop-combined-intent", status: "fail", error: "second expand still blocked by workshop" };
                }
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-decision-workshop-combined-intent",
                    status: "pass",
                    evidence: `combined packs=${activatedPacks.join(",")} confirmed from response, route=${cls.route_decision?.route}`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
];
//# sourceMappingURL=scenarios_decision_workshop.js.map