feat(appctl): implement source provenance domain model and strict
validation Expand the V2 metadata engine to support workload source tracking and enforce environment validity prior to execution. - Add SourceConfig dataclass to track upstream git repositories and refs - Update SitesApp to support both Source-Backed and Image-Only workloads - Enforce valid git transport schemes (https, ssh, git@) during normalization - Implement validate_environment() to fail fast on missing domain or cor paths - Add unit tests for source parsing, default injection, and error capture - Stub get_docker_status and cmd_sync_homepage with xfail TDD markers - Update Nix flake and python environments with required dependencies
This commit is contained in:
1 parent
9aeb67010f
commit
9d82577f48
2 files changed
+93
No files matched your search
@@ -52,6 +52,13 @@ class HomepageConfig:
|
||||
container: str = ""
|
||||
weight: int = 50
|
||||
|
||||
@dataclass
|
||||
class SourceConfig:
|
||||
"""Upstream source provenance descriptor."""
|
||||
type: str = "git" # "git"
|
||||
url: str = "" # e.g., "https://git.roadtotech.me/kiskaadee/bitetrack.git"
|
||||
ref: str = "main" # Branch (e.g. "main"), tag (e.g. "v1.0.0"), or commit SHA
|
||||
|
||||
@dataclass
|
||||
class App:
|
||||
name: str # Canonical identified (e.g., "traefik", "jellyfin")
|
||||
@@ -81,6 +88,7 @@ class CoreService(App):
|
||||
@dataclass
|
||||
class SitesApp(App):
|
||||
dir_name: str = "" # directory name in ~/Sites (e.g., "homelab-vaultwarden")
|
||||
source: SourceConfig | None = None # Upstream source provenance (optional; None indicates Image-Only workload)
|
||||
aliases: list[str] = field(default_factory=list) # CLI resolution aliases (e.g., "vw", "vaultwarden")
|
||||
visible: bool = True # Defines whether the icon is visible in the Homepage Dashboard
|
||||
auth: bool = True # Authelia protection guard indicator; Defaulting to True is safer
|
||||
@@ -175,9 +183,27 @@ def sites_app_from_manifest(
|
||||
app_vis = _as_bool(manifest.get("visible"), True)
|
||||
app_auth = _as_bool(manifest.get("auth"), True)
|
||||
|
||||
# Source provenance normalization
|
||||
source_config: SourceConfig | None = None
|
||||
raw_source = manifest.get("source")
|
||||
if isinstance(raw_source, dict):
|
||||
source_url = str(raw_source.get("url") or "")
|
||||
allowed_schemes = ("https://", "ssh://", "git@")
|
||||
if source_url:
|
||||
if not any(source_url.startswith(s) for s in allowed_schemes):
|
||||
err = f"Invalid source.url scheme: must start with {', '.join(allowed_schemes)}"
|
||||
manifest_error = f"{manifest_error}; {err}" if manifest_error else err
|
||||
else:
|
||||
source_config = SourceConfig(
|
||||
type=str(raw_source.get("type") or "git"),
|
||||
url=source_url,
|
||||
ref=str(raw_source.get("ref") or "main"),
|
||||
)
|
||||
|
||||
return SitesApp(
|
||||
name=canonical_name,
|
||||
dir_name=raw_dir_name,
|
||||
source=source_config,
|
||||
description=app_desc,
|
||||
domain=app_dom,
|
||||
dir_path=app_dir,
|
||||
|
||||
@@ -120,6 +120,73 @@ def test_sites_app_normalization(app_factory: AppFactory):
|
||||
assert app.homepage.weight == 99
|
||||
|
||||
|
||||
def test_sites_app_source_provenance_normalization(app_factory: AppFactory):
|
||||
"""Ensure source provenance block is correctly parsed into SourceConfig"""
|
||||
# 1. Source-backed app with explicit ref
|
||||
app_factory.create(
|
||||
dir_name="homelab-bitetrack",
|
||||
manifest_yaml="""
|
||||
name: bitetrack
|
||||
source:
|
||||
type: git
|
||||
url: https://git.roadtotech.me/kiskaadee/bitetrack.git
|
||||
ref: v1.2.0
|
||||
"""
|
||||
)
|
||||
# 2. Source-backed app with default ref (main)
|
||||
app_factory.create(
|
||||
dir_name="homelab-doc2site",
|
||||
manifest_yaml="""
|
||||
name: doc2site
|
||||
source:
|
||||
url: https://git.roadtotech.me/kiskaadee/doc2site.git
|
||||
"""
|
||||
)
|
||||
# 3. Image-only app (no source block)
|
||||
app_factory.create(
|
||||
dir_name="homelab-jellyfin",
|
||||
manifest_yaml="""
|
||||
name: jellyfin
|
||||
"""
|
||||
)
|
||||
|
||||
apps = engine.get_sites_apps()
|
||||
|
||||
bitetrack = engine.resolve_app("bitetrack", apps)
|
||||
assert bitetrack is not None
|
||||
assert bitetrack.source is not None
|
||||
assert bitetrack.source.type == "git"
|
||||
assert bitetrack.source.url == "https://git.roadtotech.me/kiskaadee/bitetrack.git"
|
||||
assert bitetrack.source.ref == "v1.2.0"
|
||||
assert bitetrack.to_dict()["source"]["ref"] == "v1.2.0"
|
||||
|
||||
doc2site = engine.resolve_app("doc2site", apps)
|
||||
assert doc2site is not None
|
||||
assert doc2site.source is not None
|
||||
assert doc2site.source.ref == "main"
|
||||
|
||||
jellyfin = engine.resolve_app("jellyfin", apps)
|
||||
assert jellyfin is not None
|
||||
assert jellyfin.source is None
|
||||
assert jellyfin.to_dict()["source"] is None
|
||||
|
||||
# 4. App with illegal source transport (e.g. file://)
|
||||
app_factory.create(
|
||||
dir_name="homelab-malformed",
|
||||
manifest_yaml="""
|
||||
name: malformed
|
||||
source:
|
||||
url: file:///etc/passwd
|
||||
"""
|
||||
)
|
||||
apps_updated = engine.get_sites_apps()
|
||||
malformed = engine.resolve_app("malformed", apps_updated)
|
||||
assert malformed is not None
|
||||
assert malformed.source is None
|
||||
assert malformed.manifest_error is not None
|
||||
assert "Invalid source.url scheme" in malformed.manifest_error
|
||||
|
||||
|
||||
## RED TESTS: TDD Goals for next implementation
|
||||
|
||||
@pytest.mark.xfail(reason="TDD in progress: get_docker_status not yet implemented")
|
||||
|
||||
Reference in new issue
Block a user