The self-hosting orchestrator looped on deploy-staging -> development because
scripts/staging_check.py exited 1 on ANY failed check, so two infra-only checks
(C9a sandbox branch / C9b analyst-job — caused by SANDBOX bot accounts not being
members of the sandbox Plane project, NOT a pipeline regress) forced
staging_status: FAILED -> rollback -> loop, burning developer retries and tokens.
Direction (б) per ADR-001: classify staging checks as REAL (all pipeline checks,
fail-closed) vs SANDBOX_INFRA (narrow allowlist {C9a, C9b}, waivable). New leaf
module src/staging_verdict.py (stdlib-only, never-raise): classify_check +
compute_staging_verdict fold per-check results into a tolerant-but-fail-closed
verdict — any REAL failure -> FAILED/exit1 (safety net holds under any flag);
only C9a/C9b failed & tolerant -> SUCCESS/exit0 with waived list; only infra &
strict -> FAILED/exit1; any internal error -> FAILED/exit1 (never a false green).
staging_check.py now auto-classifies each check (public 3-tuple _items shape kept
as an ORCH-048 b6 regression guard), exposes categorized_items(), prints
INFRA-WAIVED/VERDICT lines, and exits via the verdict; new --strict flag forces
legacy strictness per-run. Kill-switch ORCH_STAGING_INFRA_TOLERANCE_ENABLED
(default true) restores legacy strict mode globally. launcher gains
action_stage_no_changes_note so "no changes to commit" on action stages is logged
as expected, not treated as under-delivery.
Contracts unchanged: STAGE_TRANSITIONS, QG_CHECKS registry, staging_status:/
deploy_status: frontmatter, hook exit-code (0/1/2), check_staging_status; no DB
migration. Docs: README, STAGING_CHECK.md, deployer.md, .env.example, CHANGELOG.
Refs: ORCH-061
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
168 lines
6.8 KiB
Python
168 lines
6.8 KiB
Python
"""ORCH-042: Settings.tracker_mode config field.
|
|
|
|
AC-1: tracker_mode defaults to "edit" and is read from env ORCH_TRACKER_MODE.
|
|
Settings is a Pydantic BaseSettings reading env at instantiation, so each case
|
|
builds a FRESH Settings() (the process-wide singleton is not mutated).
|
|
"""
|
|
|
|
from src.config import Settings
|
|
|
|
|
|
def test_tracker_mode_defaults_to_edit(monkeypatch):
|
|
# No env var -> default "edit" (TC-01 / AC-1).
|
|
monkeypatch.delenv("ORCH_TRACKER_MODE", raising=False)
|
|
assert Settings().tracker_mode == "edit"
|
|
|
|
|
|
def test_tracker_mode_reads_env_bump(monkeypatch):
|
|
# ORCH_TRACKER_MODE=bump -> "bump" (TC-01 / AC-1).
|
|
monkeypatch.setenv("ORCH_TRACKER_MODE", "bump")
|
|
assert Settings().tracker_mode == "bump"
|
|
|
|
|
|
def test_tracker_mode_reads_env_arbitrary(monkeypatch):
|
|
# The field is read verbatim from env; mode RESOLUTION (anything != "bump"
|
|
# -> edit) happens in notifications, not here (AC-1/AC-2 split).
|
|
monkeypatch.setenv("ORCH_TRACKER_MODE", "garbage")
|
|
assert Settings().tracker_mode == "garbage"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# ORCH-043 / TC-25: merge-gate settings defaults + env override.
|
|
# ---------------------------------------------------------------------------
|
|
_MERGE_ENV = (
|
|
"ORCH_MERGE_GATE_ENABLED",
|
|
"ORCH_MERGE_GATE_REPOS",
|
|
"ORCH_MERGE_RETEST_TIMEOUT_S",
|
|
"ORCH_MERGE_RETEST_TARGET",
|
|
"ORCH_MERGE_LOCK_TIMEOUT_S",
|
|
"ORCH_MERGE_DEFER_DELAY_S",
|
|
"ORCH_MERGE_DEFER_MAX_ATTEMPTS",
|
|
)
|
|
|
|
|
|
def test_merge_gate_settings_defaults(monkeypatch):
|
|
"""TC-25 / AC-10: documented defaults when no env is set."""
|
|
for name in _MERGE_ENV:
|
|
monkeypatch.delenv(name, raising=False)
|
|
s = Settings()
|
|
assert s.merge_gate_enabled is True
|
|
assert s.merge_gate_repos == ""
|
|
assert s.merge_retest_timeout_s == 600
|
|
assert s.merge_retest_target == "tests/"
|
|
assert s.merge_lock_timeout_s == 300
|
|
assert s.merge_defer_delay_s == 60
|
|
assert s.merge_defer_max_attempts == 5
|
|
|
|
|
|
def test_merge_gate_settings_env_override(monkeypatch):
|
|
"""TC-25 / AC-10: each field is read from its ORCH_* env var."""
|
|
monkeypatch.setenv("ORCH_MERGE_GATE_ENABLED", "false")
|
|
monkeypatch.setenv("ORCH_MERGE_GATE_REPOS", "orchestrator,enduro-trails")
|
|
monkeypatch.setenv("ORCH_MERGE_RETEST_TIMEOUT_S", "120")
|
|
monkeypatch.setenv("ORCH_MERGE_RETEST_TARGET", "tests/unit")
|
|
monkeypatch.setenv("ORCH_MERGE_LOCK_TIMEOUT_S", "90")
|
|
monkeypatch.setenv("ORCH_MERGE_DEFER_DELAY_S", "5")
|
|
monkeypatch.setenv("ORCH_MERGE_DEFER_MAX_ATTEMPTS", "9")
|
|
s = Settings()
|
|
assert s.merge_gate_enabled is False
|
|
assert s.merge_gate_repos == "orchestrator,enduro-trails"
|
|
assert s.merge_retest_timeout_s == 120
|
|
assert s.merge_retest_target == "tests/unit"
|
|
assert s.merge_lock_timeout_s == 90
|
|
assert s.merge_defer_delay_s == 5
|
|
assert s.merge_defer_max_attempts == 9
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# ORCH-053 / TC-22: reconcile_* settings defaults + env override.
|
|
# ---------------------------------------------------------------------------
|
|
_RECONCILE_ENV = (
|
|
"ORCH_RECONCILE_ENABLED",
|
|
"ORCH_RECONCILE_INTERVAL_S",
|
|
"ORCH_RECONCILE_PLANE_ENABLED",
|
|
"ORCH_RECONCILE_GRACE_DEFAULT_S",
|
|
"ORCH_RECONCILE_GRACE_OVERRIDES_JSON",
|
|
"ORCH_RECONCILE_NOTIFY_UNBLOCK",
|
|
)
|
|
|
|
|
|
def test_reconcile_settings_defaults(monkeypatch):
|
|
"""TC-22 / AC-13: documented defaults when no env is set."""
|
|
for name in _RECONCILE_ENV:
|
|
monkeypatch.delenv(name, raising=False)
|
|
s = Settings()
|
|
assert s.reconcile_enabled is True
|
|
assert s.reconcile_interval_s == 120
|
|
assert s.reconcile_plane_enabled is True
|
|
assert s.reconcile_grace_default_s == 600
|
|
assert s.reconcile_grace_overrides_json == ""
|
|
assert s.reconcile_notify_unblock is True
|
|
|
|
|
|
def test_reconcile_settings_env_override(monkeypatch):
|
|
"""TC-22 / AC-13: each field is read from its ORCH_* env var."""
|
|
monkeypatch.setenv("ORCH_RECONCILE_ENABLED", "false")
|
|
monkeypatch.setenv("ORCH_RECONCILE_INTERVAL_S", "300")
|
|
monkeypatch.setenv("ORCH_RECONCILE_PLANE_ENABLED", "false")
|
|
monkeypatch.setenv("ORCH_RECONCILE_GRACE_DEFAULT_S", "900")
|
|
monkeypatch.setenv("ORCH_RECONCILE_GRACE_OVERRIDES_JSON", '{"development": 300}')
|
|
monkeypatch.setenv("ORCH_RECONCILE_NOTIFY_UNBLOCK", "false")
|
|
s = Settings()
|
|
assert s.reconcile_enabled is False
|
|
assert s.reconcile_interval_s == 300
|
|
assert s.reconcile_plane_enabled is False
|
|
assert s.reconcile_grace_default_s == 900
|
|
assert s.reconcile_grace_overrides_json == '{"development": 300}'
|
|
assert s.reconcile_notify_unblock is False
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# ORCH-058 / TC-13: image-freshness settings defaults + env override.
|
|
# ---------------------------------------------------------------------------
|
|
_FRESH_ENV = (
|
|
"ORCH_IMAGE_FRESHNESS_ENABLED",
|
|
"ORCH_IMAGE_FRESHNESS_REPOS",
|
|
)
|
|
|
|
|
|
def test_image_freshness_settings_defaults(monkeypatch):
|
|
"""TC-13 / AC-9: kill-switch ON by default, empty CSV (self-hosting only)."""
|
|
for name in _FRESH_ENV:
|
|
monkeypatch.delenv(name, raising=False)
|
|
s = Settings()
|
|
assert s.image_freshness_enabled is True
|
|
assert s.image_freshness_repos == ""
|
|
|
|
|
|
def test_image_freshness_settings_env_override(monkeypatch):
|
|
"""TC-13 / AC-9: each field is read from its ORCH_* env var."""
|
|
monkeypatch.setenv("ORCH_IMAGE_FRESHNESS_ENABLED", "false")
|
|
monkeypatch.setenv("ORCH_IMAGE_FRESHNESS_REPOS", "orchestrator,enduro-trails")
|
|
s = Settings()
|
|
assert s.image_freshness_enabled is False
|
|
assert s.image_freshness_repos == "orchestrator,enduro-trails"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# ORCH-061 / TC-09: staging_infra_tolerance_enabled kill-switch (AC-7).
|
|
# ---------------------------------------------------------------------------
|
|
def test_staging_infra_tolerance_defaults_true(monkeypatch):
|
|
"""TC-09 / AC-7: the kill-switch defaults ON (safe default — the safety net
|
|
holds regardless; the flag exists to restore legacy strictness instantly)."""
|
|
monkeypatch.delenv("ORCH_STAGING_INFRA_TOLERANCE_ENABLED", raising=False)
|
|
assert Settings().staging_infra_tolerance_enabled is True
|
|
|
|
|
|
def test_staging_infra_tolerance_env_override_false(monkeypatch):
|
|
"""TC-09 / AC-7: ORCH_STAGING_INFRA_TOLERANCE_ENABLED=false -> strict (1:1
|
|
pre-ORCH-061: infra-only FAIL again rolls back)."""
|
|
monkeypatch.setenv("ORCH_STAGING_INFRA_TOLERANCE_ENABLED", "false")
|
|
assert Settings().staging_infra_tolerance_enabled is False
|
|
|
|
|
|
def test_staging_infra_tolerance_env_override_true(monkeypatch):
|
|
"""The field is read verbatim from its ORCH_* env var."""
|
|
monkeypatch.setenv("ORCH_STAGING_INFRA_TOLERANCE_ENABLED", "true")
|
|
assert Settings().staging_infra_tolerance_enabled is True
|