/**
 * 发布问题场景注册表 — 工作流导航场景（configuration_pending 阶段防回归）。
 *
 * 覆盖:
 * 1. 空项目 configuration_pending 不阻断
 * 2. 老项目 configuration_pending 只阻断高风险动作
 * 3. must_confirm 与 disallowed_actions 一致性
 * 4. Rule 3 阻断范围与 must_confirm 一致
 */
import path from "node:path";
import fs from "node:fs";
import os from "node:os";
function mkTmpDir(prefix) {
    return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
}
export const WORKFLOW_NAVIGATION_SCENARIOS = [
    {
        scenario_id: "workflow-greenfield-config-pending",
        test_files: ["tests/engine/workflow/next_action_planner_greenfield.test.ts"],
        production_entrypoint: "planNextAction → configuration_pending 空项目",
        expected_outcome: "不阻断，work_package.id=greenfield-start",
        runner: async () => {
            const { planNextAction } = await import("../../workflow/next_action_planner.js");
            const tmpDir = mkTmpDir("sf-scenario-greenfield-");
            try {
                fs.mkdirSync(path.join(tmpDir, ".soloforge"), { recursive: true });
                const plan = await planNextAction(tmpDir);
                if (plan.project_stage !== "configuration_pending") {
                    return { scenario_id: "workflow-greenfield-config-pending", status: "fail", error: `阶段=${plan.project_stage}` };
                }
                if (plan.disallowed_actions.some((a) => a.rule_id === "unconfirmed_config_no_action")) {
                    return { scenario_id: "workflow-greenfield-config-pending", status: "fail", error: "空项目不应有 unconfirmed_config_no_action" };
                }
                if (plan.work_package?.id !== "greenfield-start") {
                    return { scenario_id: "workflow-greenfield-config-pending", status: "fail", error: `work_package.id=${plan.work_package?.id}` };
                }
                return { scenario_id: "workflow-greenfield-config-pending", status: "pass", evidence: "空项目不阻断，greenfield-start" };
            }
            finally {
                fs.rmSync(tmpDir, { recursive: true, force: true });
            }
        },
    },
    {
        scenario_id: "workflow-existing-config-pending",
        test_files: ["tests/engine/workflow/next_action_planner_greenfield.test.ts"],
        production_entrypoint: "planNextAction → configuration_pending 老项目",
        expected_outcome: "只阻断编码+联调，允许需求分析",
        runner: async () => {
            const { planNextAction } = await import("../../workflow/next_action_planner.js");
            const tmpDir = mkTmpDir("sf-scenario-existing-");
            try {
                fs.mkdirSync(path.join(tmpDir, ".soloforge"), { recursive: true });
                fs.writeFileSync(path.join(tmpDir, "package.json"), "{}");
                fs.mkdirSync(path.join(tmpDir, "src"), { recursive: true });
                const plan = await planNextAction(tmpDir);
                if (plan.project_stage !== "configuration_pending") {
                    return { scenario_id: "workflow-existing-config-pending", status: "fail", error: `阶段=${plan.project_stage}` };
                }
                const rule = plan.disallowed_actions.find((a) => a.rule_id === "unconfirmed_config_no_action");
                if (!rule) {
                    return { scenario_id: "workflow-existing-config-pending", status: "fail", error: "老项目应有 unconfirmed_config_no_action" };
                }
                if (rule.blocked_actions.includes("需求分析") || rule.blocked_actions.includes("架构设计")) {
                    return { scenario_id: "workflow-existing-config-pending", status: "fail", error: "过度阻断需求分析/架构设计" };
                }
                return { scenario_id: "workflow-existing-config-pending", status: "pass", evidence: `阻断: ${rule.blocked_actions.join(",")}` };
            }
            finally {
                fs.rmSync(tmpDir, { recursive: true, force: true });
            }
        },
    },
    {
        scenario_id: "workflow-config-pending-consistency",
        test_files: ["tests/engine/workflow/next_action_planner_greenfield.test.ts"],
        production_entrypoint: "computeConfirmationDecisions + computeDisallowedActions 一致性",
        expected_outcome: "空项目 must_confirm 为空，disallowed_actions 不超过 2 个动作",
        runner: async () => {
            const { planNextAction } = await import("../../workflow/next_action_planner.js");
            const tmpDir = mkTmpDir("sf-scenario-consistency-");
            try {
                fs.mkdirSync(path.join(tmpDir, ".soloforge"), { recursive: true });
                const plan = await planNextAction(tmpDir);
                if ((plan.confirmation_decisions?.must_confirm?.length ?? 0) !== 0) {
                    return { scenario_id: "workflow-config-pending-consistency", status: "fail", error: `must_confirm 非空: ${plan.confirmation_decisions.must_confirm.length}` };
                }
                const configRule = plan.disallowed_actions.find((a) => a.rule_id === "unconfirmed_config_no_action");
                if (configRule && configRule.blocked_actions.length > 2) {
                    return { scenario_id: "workflow-config-pending-consistency", status: "fail", error: `blocked_actions 超过 2: ${configRule.blocked_actions.length}` };
                }
                return { scenario_id: "workflow-config-pending-consistency", status: "pass", evidence: "一致性校验通过" };
            }
            finally {
                fs.rmSync(tmpDir, { recursive: true, force: true });
            }
        },
    },
    {
        scenario_id: "workflow-unconfirmed-decision-scope",
        test_files: ["tests/engine/next_action_planner.test.ts"],
        production_entrypoint: "computeDisallowedActions 规则3",
        expected_outcome: "blocked_actions 包含联调验证",
        runner: async () => {
            const { computeDisallowedActions } = await import("../../workflow/next_action_planner.js");
            const tmpDir = mkTmpDir("sf-scenario-rule3-");
            try {
                const actions = computeDisallowedActions("development_in_progress", "编码与单元测试", {
                    task_id: "test-001",
                    created_at: new Date().toISOString(),
                    intent: "测试",
                    product_profile: "default",
                    status: "classifying",
                    architecture_decision_workshop: {
                        task_id: "test-001",
                        project_context: "new_system",
                        status: "awaiting_confirmation",
                        prerequisite_evidence_refs: [],
                        domains: {
                            data_architecture: { status: "awaiting_confirmation" },
                            backend_architecture: { status: "confirmed" },
                            business_process: { status: "confirmed" },
                            security_architecture: { status: "confirmed" },
                            frontend_architecture: { status: "confirmed" },
                            infrastructure: { status: "confirmed" },
                        },
                        required_diagrams: [],
                        design_generation_allowed: false,
                        blocking_findings: [],
                    },
                }, tmpDir);
                const rule3 = actions.find((a) => a.rule_id === "unconfirmed_decision_no_finalization");
                if (!rule3) {
                    return { scenario_id: "workflow-unconfirmed-decision-scope", status: "fail", error: "规则3 未触发" };
                }
                if (!rule3.blocked_actions.includes("联调验证")) {
                    return { scenario_id: "workflow-unconfirmed-decision-scope", status: "fail", error: `联调验证不在阻断范围: ${rule3.blocked_actions.join(",")}` };
                }
                return { scenario_id: "workflow-unconfirmed-decision-scope", status: "pass", evidence: `阻断范围: ${rule3.blocked_actions.join(",")}` };
            }
            finally {
                fs.rmSync(tmpDir, { recursive: true, force: true });
            }
        },
    },
];
//# sourceMappingURL=scenarios_workflow_navigation.js.map