deploy: add build_sha visibility for precise drift detection
Make /health report the precise git SHA the container was built from,
so 'is the live service current?' can be answered without ambiguity.
0.2.0 was too coarse to trust as a 'live is current' signal — many
commits share the same __version__.
Three layers:
1. /health endpoint (src/atocore/api/routes.py)
- Reads ATOCORE_BUILD_SHA, ATOCORE_BUILD_TIME, ATOCORE_BUILD_BRANCH
from environment, defaults to 'unknown'
- Reports them alongside existing code_version field
2. docker-compose.yml
- Forwards the three env vars from the host into the container
- Defaults to 'unknown' so direct `docker compose up` runs (without
deploy.sh) cleanly signal missing build provenance
3. deploy.sh
- Step 2 captures git SHA + UTC timestamp + branch and exports them
as env vars before `docker compose up -d --build`
- Step 6 reads /health post-deploy and compares the reported
build_sha against the freshly-built one. Mismatch exits non-zero
(exit code 6) with a remediation hint covering cached image,
env propagation, and concurrent restart cases
Tests (tests/test_api_storage.py):
- test_health_endpoint_reports_code_version_from_module
- test_health_endpoint_reports_build_metadata_from_env
- test_health_endpoint_reports_unknown_when_build_env_unset
Docs (docs/dalidou-deployment.md):
- Three-level drift detection table (code_version coarse,
build_sha precise, build_time/branch forensic)
- Canonical drift check script using LIVE_SHA vs EXPECTED_SHA
- Note that running deploy.sh is itself the simplest drift check
219/219 tests passing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -50,6 +50,65 @@ def test_health_endpoint_exposes_machine_paths_and_source_readiness(tmp_data_dir
|
||||
assert "run_dir" in body["machine_paths"]
|
||||
|
||||
|
||||
def test_health_endpoint_reports_code_version_from_module(tmp_data_dir):
|
||||
"""The /health response must include code_version reflecting
|
||||
atocore.__version__, so deployment drift detection works."""
|
||||
from atocore import __version__
|
||||
|
||||
client = TestClient(app)
|
||||
response = client.get("/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["version"] == __version__
|
||||
assert body["code_version"] == __version__
|
||||
|
||||
|
||||
def test_health_endpoint_reports_build_metadata_from_env(tmp_data_dir, monkeypatch):
|
||||
"""The /health response must include build_sha, build_time, and
|
||||
build_branch from the ATOCORE_BUILD_* env vars, so deploy.sh can
|
||||
detect precise drift via SHA comparison instead of relying on
|
||||
the coarse code_version field.
|
||||
|
||||
Regression test for the codex finding from 2026-04-08:
|
||||
code_version 0.2.0 is too coarse to trust as a 'live is current'
|
||||
signal because it only changes on manual bumps. The build_sha
|
||||
field changes per commit and is set by deploy.sh.
|
||||
"""
|
||||
monkeypatch.setenv("ATOCORE_BUILD_SHA", "abc1234567890fedcba0987654321")
|
||||
monkeypatch.setenv("ATOCORE_BUILD_TIME", "2026-04-09T01:23:45Z")
|
||||
monkeypatch.setenv("ATOCORE_BUILD_BRANCH", "main")
|
||||
|
||||
client = TestClient(app)
|
||||
response = client.get("/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["build_sha"] == "abc1234567890fedcba0987654321"
|
||||
assert body["build_time"] == "2026-04-09T01:23:45Z"
|
||||
assert body["build_branch"] == "main"
|
||||
|
||||
|
||||
def test_health_endpoint_reports_unknown_when_build_env_unset(tmp_data_dir, monkeypatch):
|
||||
"""When deploy.sh hasn't set the build env vars (e.g. someone
|
||||
ran `docker compose up` directly), /health reports 'unknown'
|
||||
for all three build fields. This is a clear signal to the
|
||||
operator that the deploy provenance is missing and they should
|
||||
re-run via deploy.sh."""
|
||||
monkeypatch.delenv("ATOCORE_BUILD_SHA", raising=False)
|
||||
monkeypatch.delenv("ATOCORE_BUILD_TIME", raising=False)
|
||||
monkeypatch.delenv("ATOCORE_BUILD_BRANCH", raising=False)
|
||||
|
||||
client = TestClient(app)
|
||||
response = client.get("/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["build_sha"] == "unknown"
|
||||
assert body["build_time"] == "unknown"
|
||||
assert body["build_branch"] == "unknown"
|
||||
|
||||
|
||||
def test_projects_endpoint_reports_registered_projects(tmp_data_dir, monkeypatch):
|
||||
vault_dir = tmp_data_dir / "vault-source"
|
||||
drive_dir = tmp_data_dir / "drive-source"
|
||||
|
||||
Reference in New Issue
Block a user