def test_enqueue_fix_all_jobs_enforces_manual_taxonomy_mode(monkeypatch):
    from app.jobs import master_taxonomy_enqueue as mod

    captured = []

    def _fake_start(job_type, params):
        captured.append((job_type, dict(params)))
        return "job-1"

    monkeypatch.setattr(mod, "start_master_taxonomy_job", _fake_start)

    result = mod.enqueue_fix_all_jobs(
        dry_run=False,
        magento_connection_ids=[4],
        taxonomy_mode="full",
    )

    assert result["status"] == "queued"
    assert captured[0][0] == "fix_all"
    assert captured[0][1]["taxonomy_mode"] == "link_only"
    assert captured[0][1]["taxonomy_mode_requested"] == "full"


def test_execute_fix_all_enforces_manual_taxonomy_mode(monkeypatch):
    from app.jobs import master_taxonomy_enqueue as mod

    captured = {}

    monkeypatch.setattr(mod, "_resolve_connections", lambda *_args, **_kwargs: (4, None, None, None, None))

    def _fake_pipeline(**kwargs):
        captured.update(kwargs)
        return {"status": "ok"}

    monkeypatch.setattr(
        "app.jobs.sync_master_taxonomy_pipeline.run_master_taxonomy_pipeline",
        _fake_pipeline,
    )

    result = mod._execute_fix_all(
        {
            "dry_run": True,
            "magento_connection_id": 4,
            "pull_remotes": False,
            "create_missing": True,
            "push_products": False,
            "taxonomy_mode": "full",
        }
    )

    assert captured["taxonomy_mode"] == "link_only"
    assert result["taxonomy_mode_requested"] == "full"
    assert result["taxonomy_mode_enforced"] == "link_only"
