/**
 * 发布问题场景注册表 — 问题六十一: 架构决策研讨场景
 */
import { injectTechDecisionForWorkshop } from "./workshop_helpers.js";
export const ARCHITECTURE_WORKSHOP_SCENARIOS = [
    // 场景 1: greenfield 架构设计 → 完整闭环：阻断 → 全部确认 → 放行
    {
        scenario_id: "release-scenario-architecture-workshop-greenfield",
        test_files: ["tests/engine/architecture_decision_workshop.test.ts"],
        production_entrypoint: "sf_classify → sf_expand → confirm all → sf_expand",
        expected_outcome: "greenfield sf_expand 阻断(六域未确认) → 全部确认+输出确认 → 二次 sf_expand 放行",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness();
            try {
                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-architecture-workshop-greenfield", status: "fail", error: "sf_classify 未返回 task_id" };
                if (!await injectTechDecisionForWorkshop(harness, taskId)) {
                    return { scenario_id: "release-scenario-architecture-workshop-greenfield", status: "fail", error: "task context load failed" };
                }
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                if (exp1.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-architecture-workshop-greenfield", status: "fail", error: `expected awaiting_confirmation, got status=${exp1.status}` };
                }
                const workshop = exp1.architecture_decision_workshop;
                if (!workshop) {
                    return { scenario_id: "release-scenario-architecture-workshop-greenfield", status: "fail", error: "sf_expand 未返回 architecture_decision_workshop" };
                }
                const domainCount = Object.keys(workshop.domains ?? {}).length;
                if (domainCount < 6) {
                    return { scenario_id: "release-scenario-architecture-workshop-greenfield", status: "fail", error: `expected >=6 domains, got ${domainCount}` };
                }
                // 全部域确认 + document_output_confirmation_ref
                for (const key of Object.keys(workshop.domains ?? {})) {
                    workshop.domains[key].status = "confirmed";
                    workshop.domains[key].user_confirmation_ref = `confirm:${key}`;
                }
                workshop.document_output_confirmation_ref = "confirm:output";
                const exp2Raw = await harness.callTool("sf_expand", { task_id: taskId, architecture_decision_workshop: workshop });
                const exp2 = harness.parseResult(exp2Raw);
                if (exp2.status === "awaiting_confirmation" || exp2.status === "blocked") {
                    return { scenario_id: "release-scenario-architecture-workshop-greenfield", status: "fail", error: `second expand still blocked: status=${exp2.status}, error=${exp2.error ?? "none"}` };
                }
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-architecture-workshop-greenfield",
                    status: "pass",
                    evidence: `sf_classify→sf_expand(awaiting_confirmation,workshop=true,domains=${domainCount})→all confirm→sf_expand(pass)`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 2: existing_system 架构设计被阻断；补充确认+证据后放行
    {
        scenario_id: "release-scenario-architecture-workshop-existing-system",
        test_files: ["tests/adapters/architecture_design_workshop_mainpath.test.ts"],
        production_entrypoint: "sf_classify → sf_expand → confirm workshop with evidence → sf_expand",
        expected_outcome: "existing_system sf_expand sf_expand 返回 workshop + awaiting_confirmation；补入确认和证据后放行",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness({ copyKnowledge: true });
            try {
                const fs = await import("node:fs");
                const srcDir = `${harness.tmpDir}/src`;
                fs.mkdirSync(srcDir, { recursive: true });
                fs.writeFileSync(`${srcDir}/index.ts`, "export {}");
                fs.writeFileSync(`${harness.tmpDir}/package.json`, '{"name":"existing"}');
                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-architecture-workshop-existing-system", status: "fail", error: "sf_classify 未返回 task_id" };
                // 提供完整技术决策契约，确保证据门禁和决策主权门禁通过
                if (!await injectTechDecisionForWorkshop(harness, taskId)) {
                    return { scenario_id: "release-scenario-architecture-workshop-existing-system", status: "fail", error: "task context load failed" };
                }
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                if (exp1.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-architecture-workshop-existing-system", status: "fail", error: `expected awaiting_confirmation, got status=${exp1.status}` };
                }
                const workshop = exp1.architecture_decision_workshop;
                if (!workshop) {
                    return { scenario_id: "release-scenario-architecture-workshop-existing-system", status: "fail", error: "sf_expand 未返回 architecture_decision_workshop" };
                }
                // 全部域确认 + 补齐前置证据
                for (const key of Object.keys(workshop.domains ?? {})) {
                    workshop.domains[key].status = "confirmed";
                    workshop.domains[key].user_confirmation_ref = `confirm:${key}`;
                }
                workshop.prerequisite_evidence_refs = ["现状分析报告", "差距分析文档"];
                workshop.document_output_confirmation_ref = "confirm:output";
                const exp2Raw = await harness.callTool("sf_expand", { task_id: taskId, architecture_decision_workshop: workshop });
                const exp2 = harness.parseResult(exp2Raw);
                if ((exp2.status === "awaiting_confirmation" || exp2.status === "blocked") && exp2.architecture_decision_workshop) {
                    return { scenario_id: "release-scenario-architecture-workshop-existing-system", status: "fail", error: `second expand still blocked: ${JSON.stringify(exp2.blocking_findings ?? []).slice(0, 200)}` };
                }
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-architecture-workshop-existing-system",
                    status: "pass",
                    evidence: `sf_classify→sf_expand(awaiting_confirmation,workshop=true,domains=${Object.keys(workshop.domains ?? {}).length})→confirm all+evidence→sf_expand(${exp2.status ?? "pass"})`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 3: 部分域确认 → 仍 blocked
    {
        scenario_id: "release-scenario-architecture-workshop-confirmation-block",
        test_files: ["tests/adapters/architecture_design_workshop_mainpath.test.ts"],
        production_entrypoint: "sf_classify → sf_expand → partial confirm → sf_expand",
        expected_outcome: "部分域确认后仍 blocked，返回 next_domain；全部确认后放行",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness();
            try {
                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-architecture-workshop-confirmation-block", status: "fail", error: "sf_classify 未返回 task_id" };
                // 提供完整技术决策契约，确保证据门禁和决策主权门禁通过
                if (!await injectTechDecisionForWorkshop(harness, taskId)) {
                    return { scenario_id: "release-scenario-architecture-workshop-confirmation-block", status: "fail", error: "task context load failed" };
                }
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                if (exp1.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-architecture-workshop-confirmation-block", status: "fail", error: `expected awaiting_confirmation, got status=${exp1.status}` };
                }
                const workshop = exp1.architecture_decision_workshop;
                if (!workshop) {
                    return { scenario_id: "release-scenario-architecture-workshop-confirmation-block", status: "fail", error: "sf_expand 未返回 architecture_decision_workshop" };
                }
                // 只确认第一个域
                const domainKeys = Object.keys(workshop.domains ?? {});
                const confirmedCount = Math.min(1, domainKeys.length);
                for (let i = 0; i < confirmedCount; i++) {
                    workshop.domains[domainKeys[i]].status = "confirmed";
                    workshop.domains[domainKeys[i]].user_confirmation_ref = `confirm:${domainKeys[i]}`;
                }
                workshop.document_output_confirmation_ref = "confirm:output";
                const exp2Raw = await harness.callTool("sf_expand", { task_id: taskId, architecture_decision_workshop: workshop });
                const exp2 = harness.parseResult(exp2Raw);
                if (exp2.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-architecture-workshop-confirmation-block", status: "fail", error: `expected still awaiting_confirmation after partial confirm (${confirmedCount}/${domainKeys.length}), got status=${exp2.status}` };
                }
                // 全部确认后必须放行
                for (const key of domainKeys) {
                    workshop.domains[key].status = "confirmed";
                    workshop.domains[key].user_confirmation_ref = `confirm:${key}`;
                }
                const exp3Raw = await harness.callTool("sf_expand", { task_id: taskId, architecture_decision_workshop: workshop });
                const exp3 = harness.parseResult(exp3Raw);
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-architecture-workshop-confirmation-block",
                    status: (exp3.status !== "awaiting_confirmation" && exp3.status !== "blocked") ? "pass" : "fail",
                    evidence: `sf_classify→sf_expand(awaiting_confirmation,workshop=true,domains=${domainKeys.length})→partial(${confirmedCount}/${domainKeys.length})→sf_expand(awaiting_confirmation)→all confirm→sf_expand(${exp3.status ?? "pass"})`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 4: 低风险不触发架构研讨
    {
        scenario_id: "release-scenario-architecture-workshop-low-risk-skip",
        test_files: ["tests/engine/architecture_decision_workshop.test.ts"],
        production_entrypoint: "sf_classify → sf_expand",
        expected_outcome: "低风险修改 sf_expand 不创建 architecture_decision_workshop，不 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: "修复按钮文字拼写错误" });
                const cls = harness.parseResult(clsRaw);
                const taskId = cls.task_id;
                if (!taskId)
                    return { scenario_id: "release-scenario-architecture-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);
                if (exp.architecture_decision_workshop) {
                    return { scenario_id: "release-scenario-architecture-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-architecture-workshop-low-risk-skip", status: "fail", error: "low-risk intent should not be awaiting_confirmation" };
                }
                const trace = await harness.collectTrace();
                if (trace.diagnostic_codes.length === 0) {
                    trace.diagnostic_codes = [`route:${cls.route_decision?.route ?? "unknown"}`, `expand_status:${exp.status ?? "ok"}`];
                }
                return {
                    scenario_id: "release-scenario-architecture-workshop-low-risk-skip",
                    status: "pass",
                    evidence: `sf_classify→sf_expand(workshop=false,route=${cls.route_decision?.route},status=${exp.status}) 低风险跳过架构研讨`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
    // 场景 5: rework_required 域阻断设计生成
    {
        scenario_id: "release-scenario-architecture-workshop-rework",
        test_files: [],
        production_entrypoint: "sf_classify → sf_expand → inject rework_required → sf_expand",
        expected_outcome: "rework_required 域仍出现在 missing/阻断中，不进入正式设计生成；修正为 confirmed 后放行",
        runner: async () => {
            const { createToolHarness } = await import("../release_tool_harness.js");
            const harness = await createToolHarness();
            try {
                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-architecture-workshop-rework", status: "fail", error: "sf_classify 未返回 task_id" };
                // 提供完整技术决策契约，确保证据门禁和决策主权门禁通过
                if (!await injectTechDecisionForWorkshop(harness, taskId)) {
                    return { scenario_id: "release-scenario-architecture-workshop-rework", status: "fail", error: "task context load failed" };
                }
                const exp1Raw = await harness.callTool("sf_expand", { task_id: taskId });
                const exp1 = harness.parseResult(exp1Raw);
                if (exp1.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-architecture-workshop-rework", status: "fail", error: `expected awaiting_confirmation, got status=${exp1.status}` };
                }
                const workshop = exp1.architecture_decision_workshop;
                if (!workshop) {
                    return { scenario_id: "release-scenario-architecture-workshop-rework", status: "fail", error: "sf_expand 未返回 architecture_decision_workshop" };
                }
                const domainKeys = Object.keys(workshop.domains ?? {});
                // 确认大部分域，但将一个域设为 rework_required
                const reworkKey = domainKeys.find(k => k === "backend_architecture") ?? domainKeys[0];
                for (const key of domainKeys) {
                    if (key === reworkKey) {
                        workshop.domains[key].status = "rework_required";
                    }
                    else {
                        workshop.domains[key].status = "confirmed";
                        workshop.domains[key].user_confirmation_ref = `confirm:${key}`;
                    }
                }
                workshop.document_output_confirmation_ref = "confirm:output";
                const exp2Raw = await harness.callTool("sf_expand", { task_id: taskId, architecture_decision_workshop: workshop });
                const exp2 = harness.parseResult(exp2Raw);
                if (exp2.status !== "awaiting_confirmation") {
                    return { scenario_id: "release-scenario-architecture-workshop-rework", status: "fail", error: `expected still awaiting_confirmation with rework_required, got status=${exp2.status}` };
                }
                // 修正 rework 域为 confirmed
                workshop.domains[reworkKey].status = "confirmed";
                workshop.domains[reworkKey].user_confirmation_ref = `confirm:${reworkKey}`;
                const exp3Raw = await harness.callTool("sf_expand", { task_id: taskId, architecture_decision_workshop: workshop });
                const exp3 = harness.parseResult(exp3Raw);
                const trace = await harness.collectTrace();
                return {
                    scenario_id: "release-scenario-architecture-workshop-rework",
                    status: (exp3.status !== "awaiting_confirmation" && exp3.status !== "blocked") ? "pass" : "fail",
                    evidence: `sf_classify→sf_expand(awaiting_confirmation,workshop=true,domains=${domainKeys.length})→${reworkKey}=rework_required→sf_expand(awaiting_confirmation)→fix→sf_expand(${exp3.status ?? "pass"})`,
                    production_trace: trace,
                };
            }
            finally {
                harness.cleanup();
            }
        },
    },
];
//# sourceMappingURL=scenarios_architecture_workshop.js.map