Brain Structural Validation / Validate Markdown Structure & Links (push) Failing after 8s
86 lines
5.1 KiB
Markdown
86 lines
5.1 KiB
Markdown
---
|
|
type: journal
|
|
project: homelab
|
|
date: 2026-09-21
|
|
tags:
|
|
- homelab
|
|
- orchestration
|
|
- appctl
|
|
- python
|
|
- architecture
|
|
- testing
|
|
- pytest
|
|
- gitops
|
|
- webhook
|
|
- cryptography
|
|
---
|
|
|
|
# Daily Journal: 2026-09-21
|
|
|
|
## Wins
|
|
|
|
### Architecture & TDD: appctl Engine V2 Domain Modeling and Test Suite Scaffold
|
|
Initiated a comprehensive architectural rework of `scripts/appctl_engine.py` to elevate the homelab control utility into clean, type-safe engineering code (`appctl_engine_v2.py`). Development is conducted in an isolated Git worktree at `~/Projects/active/appctl-refactor`.
|
|
|
|
#### Key Architectural Decisions & Progress
|
|
|
|
1. **Standardized YAML Parsing & Custom Exception Handling**
|
|
- **Replaced Custom Parser**: Deprecated the hand-rolled `parse_yaml_simple()` in favor of standard `yaml.safe_load()` using PyYAML.
|
|
- **Explicit Failure Boundary**: Defined `class ManifestError(Exception): pass` to cleanly catch and isolate malformed YAML syntax without crashing the whole application inventory.
|
|
|
|
2. **Explicit Domain Model Hierarchy**
|
|
- **Base Domain Model**: Established `@dataclass class App` representing common operational primitives (`name`, `description`, `domain`, `dir_path`, `has_compose`).
|
|
- **Layer-Specific Models**:
|
|
- `SitesApp(App)`: Represents dynamic `~/Sites/*` workloads with `app.yaml` metadata (`aliases`, `visible`, `auth`, `networks`, `env`, `homepage`, `manifest_error`).
|
|
- `CoreService(App)`: Represents Core platform services (`container`, `weight`, `icon`).
|
|
- `HomepageConfig`: Strongly-typed representation for dashboard cards.
|
|
|
|
3. **Pure Normalization Boundary**
|
|
- Extracted `sites_app_from_manifest(app_dir, manifest, manifest_error) -> SitesApp` as a pure normalization seam.
|
|
- Separates filesystem discovery from domain instantiation, enabling unit tests to verify manifest coercion without disk I/O.
|
|
|
|
4. **Domain-Agnostic Infrastructure & Strict Validation**
|
|
- Decoupled hardcoded personal domains by parameterizing `HOMELAB_DOMAIN = os.environ.get("HOMELAB_DOMAIN") or os.environ.get("DOMAIN", "")`.
|
|
- Added `validate_environment()` to fail fast if mandatory environment variables or Core directories are missing.
|
|
|
|
5. **TDD Test Suite Scaffold**
|
|
- Created `tests/unit/test_appctl_engine_v2.py` with custom Pytest fixtures:
|
|
- `mock_sites_dir` & `mock_core_dir`: Isolated temporary directories with automatic `monkeypatch` teardown.
|
|
- `AppFactory`: Object Mother/Factory class to generate test app directories with `app.yaml` and Compose manifests in one line.
|
|
- Verified passing tests for resolution hierarchy, manifest overrides, and type normalization.
|
|
- Established failing (Red) acceptance criteria for upcoming Docker inspection and Homepage YAML compilation.
|
|
|
|
---
|
|
|
|
## Incidents & Debugging
|
|
|
|
- [Remediation: Gitea Actions CI Runner Container Initialization Failure (Missing /bin/sleep)](../debug/2026-09-21-gitea-actions-fhs-nix-container-fix.md)
|
|
- **Issue**: Gitea Actions runner failed at job initialization with `exec: "/bin/sleep": stat /bin/sleep: no such file or directory`.
|
|
- **Root Cause**: Minimal `nixos/nix` container image lacks the Linux Filesystem Hierarchy Standard (FHS) paths expected by `act_runner` at container entrypoint initialization.
|
|
- **Remediation**: Transitioned CI base image to `nixery.dev/shell/coreutils/git/nix/nodejs:latest`, restoring standard `/bin` utilities while preserving declarative Nix tooling.
|
|
|
|
- [GitOps Dispatcher Webhook Signature Mismatch: Epistemic Root Cause Analysis](../debug/2026-09-21-gitops-webhook-payload-signature-mismatch.md)
|
|
- **Issue**: Automated GitOps dispatcher rejected repository push deliveries with `Authentication failed: Signature mismatch`.
|
|
- **Root Cause**: Payload serialization divergence in `adnanh/webhook` parameter extraction combined with secret synchronization mismatch between Gitea webhook settings and the server's SOPS age secret.
|
|
- **Remediation**: Corrected raw payload extraction, synchronized SOPS secrets, and implemented constant-time HMAC-SHA256 signature verification in `gitops_dispatcher.py`.
|
|
|
|
---
|
|
|
|
## Mistakes and Lessons Learned
|
|
|
|
### Python `str(None)` Truthiness Trap
|
|
Calling `str(manifest.get("key")) or "fallback"` returns `"None"` (a truthy string) when the key is missing, completely breaking fallback evaluation. Safe normalization requires checking `manifest.get("key") is not None` before string casting.
|
|
|
|
### Nix Function Call Syntax in Lists
|
|
Calling `python3.withPackages` inside Nix lists `[ ... ]` requires outer parentheses `(python3.withPackages (ps: [ ... ]))`, otherwise Nix evaluates the function and lambda as two separate invalid list elements.
|
|
|
|
### FHS Invariant for Gitea `act_runner`
|
|
`act_runner` assumes a standard FHS environment (like `/bin/sleep` and `/bin/sh`) for container setup scripts. Bare Nix store container images must be supplemented with core utilities to satisfy runner bootstrap requirements.
|
|
|
|
---
|
|
|
|
## Next Objectives
|
|
1. Implement inspection layer in `scripts/appctl_engine_v2.py` (Docker status, Git sync status, SSL checks).
|
|
2. Port CLI command handlers (`cmd_sync_homepage`, `cmd_list`, `cmd_info`, `cmd_ssl`).
|
|
3. Turn remaining unit tests green and swap V2 into production `Core/scripts/appctl_engine.py`.
|