acupedia-ops/acupedia_ops/local/validation.py

103 lines
3.1 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
from acupedia_ops.local.workspace import LocalWorkspace
@dataclass(frozen=True)
class ValidationIssue:
level: str
component: str
message: str
def validate_workspace(workspace: LocalWorkspace) -> list[ValidationIssue]:
issues: list[ValidationIssue] = []
for component, path in workspace.paths.items():
if not path.exists():
issues.append(
ValidationIssue(
level="error",
component=component,
message=f"path does not exist: {path}",
)
)
elif not path.is_dir():
issues.append(
ValidationIssue(
level="error",
component=component,
message=f"path is not a directory: {path}",
)
)
for component, config in workspace.components.items():
path = workspace.paths[component]
if not path.is_dir():
continue
for marker in config.required_markers:
if not (path / marker).exists():
issues.append(
ValidationIssue(
level="error",
component=component,
message=f"missing expected repository marker: {marker}",
)
)
if workspace.paths["api"].is_dir():
if not (workspace.paths["api"] / "app").is_dir():
issues.append(
ValidationIssue(
level="error",
component="api",
message="missing app/ package",
)
)
if workspace.paths["content"].is_dir():
if not workspace.bootstrap.content_config.exists():
issues.append(
ValidationIssue(
level="warning",
component="content",
message=(
"bootstrap content config not found: "
f"{workspace.bootstrap.content_config}"
),
)
)
if not workspace.bootstrap.modules_root.exists():
issues.append(
ValidationIssue(
level="error",
component="content",
message=(
"bootstrap modules root not found: "
f"{workspace.bootstrap.modules_root}"
),
)
)
if not workspace.infra.compose_file.exists():
issues.append(
ValidationIssue(
level="warning",
component="infra",
message=(
"local compose file not found: "
f"{workspace.infra.compose_file}. "
"infra-* commands will remain unavailable until it exists."
),
)
)
return issues
def has_errors(issues: list[ValidationIssue]) -> bool:
return any(issue.level == "error" for issue in issues)