Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

2.3 KB
Raw Blame
"""Schema migrations run at deploy time, so they are tooling, not production.

A migration's loop over rows is not a request path, and classing it
``production`` ranked it beside the code users wait on. A bare ``versions/``
directory stays production: API version packages use the same name.
"""

from __future__ import annotations

import pytest

from repowise.core.analysis.health.perf.causal import execution_context


@pytest.mark.parametrize(
    "path",
    [
        "app/migrations/0001_initial.py",  # Django
        "blog/migrations/0012_backfill.py",
        "migrations/versions/3f2a_add_index.py",  # Flask-Migrate
        "alembic/versions/3f2a_add_index.py",  # Alembic
        "src/db/alembic/versions/3f2a_add_index.py",
        "db/migrate/20240101000000_create_users.rb",  # Rails
        "src/Data/Migrations/20240101_Init.cs",  # EF Core
        "src\\Data\\Migrations\\20240101_Init.cs",
    ],
)
def test_migrations_are_tooling(path: str) -> None:
    assert execution_context(path) == "tooling"


@pytest.mark.parametrize(
    "path",
    [
        "app/versions/api.py",
        "api/versions/v2/handlers.py",
        "app/db/migrate.py",  # a module named migrate, not the Rails directory
        "app/migrate/runner.py",
        "app/alembic_utils.py",
        "app/migrations_helper.py",
    ],
)
def test_lookalikes_stay_production(path: str) -> None:
    assert execution_context(path) == "production"


@pytest.mark.parametrize(
    "path",
    [
        "build.gradle.kts",  # a root build file is tooling, no longer unknown
        "ktor-client/ktor-client-core/build.gradle.kts",
        "crates/core/build.rs",
        "packages/app/vite.config.ts",
        "src/lib/CMakeLists.txt",
    ],
)
def test_build_files_are_tooling(path: str) -> None:
    assert execution_context(path) == "tooling"


@pytest.mark.parametrize(
    ("path", "expected"),
    [
        ("src/build.rs", "production"),
        ("src/x/examples/a.py", "unknown"),  # a nested example may or may not ship
        ("pkg/doc/gen.go", "unknown"),
        ("vendor/github.com/x/y.go", "unknown"),
        ("src/__generated__/schema.ts", "unknown"),
        ("benches/parse.rs", "tooling"),
        ("main.py", "unknown"),  # no directory, no evidence
    ],
)
def test_contexts_follow_the_shared_origin(path: str, expected: str) -> None:
    assert execution_context(path) == expected