import json from pathlib import Path from dx_productivity.dsh.health import HealthStore class _Service: pass def test_health_snapshot_reports_unconfigured_provider_and_local_stores(tmp_path, monkeypatch): monkeypatch.delenv('DSH_API_BASE', raising=False) value = HealthStore(tmp_path).snapshot(_Service()) checks = {row['name']: row for row in value['checks']} assert value['status'] == 'degraded' assert checks['provider']['status'] == 'degraded' assert checks['provider']['code'] == 'provider_unconfigured' assert checks['stores']['status'] == 'ok' def test_health_snapshot_marks_active_worker_and_static_issue_token(tmp_path, monkeypatch): provider = tmp_path / 'dsh' / 'provider.json' provider.parent.mkdir(parents=True) provider.write_text(json.dumps({'base_url': 'https://example.test/v1', 'default_model': 'm'}), encoding='utf8') monkeypatch.setattr('dx_productivity.dsh.health.load_bootstrap', lambda: {'token': 'secret', 'username': 'u', 'scopes': ['write:issue'], 'server': 'https://git.test', 'repository': 'o/r'}) value = HealthStore(tmp_path).snapshot(_Service(), execution='busy') checks = {row['name']: row for row in value['checks']} assert checks['execution']['status'] == 'degraded' assert checks['execution']['code'] == 'worker_active' assert checks['issue_credentials']['code'] == 'credential_rotation_required' assert 'secret' not in json.dumps(value) def test_health_snapshot_reports_stale_ticket_cache(tmp_path): cache = tmp_path / 'dsh' / 'ticket-cache' cache.mkdir(parents=True) value = HealthStore(tmp_path).snapshot(_Service()) checks = {row['name']: row for row in value['checks']} assert checks['tickets']['status'] == 'ok'