Files
dxdesigner-part-replacement/tests/dsh/test_health.py
阿白叔 cf6e3f9d2a
Core regression / Python 3.12 core, intervention UI and release configuration (push) Failing after 21s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python 3.12 core, intervention UI and release configuration (pull_request) Failing after 21s
Core regression / JavaScript syntax (pull_request) Successful in 3s
feat(dsh): show AI readiness and prevent repeated intervention on status changes
2026-11-05 16:09:41 +08:00

49 lines
2.2 KiB
Python

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'
def test_provider_metadata_without_a_key_does_not_claim_ready(tmp_path, monkeypatch):
for key in ('DSH_API_BASE', 'DSH_MODEL', 'DSH_API_KEY', 'DEEPSEEK_API_KEY'):
monkeypatch.delenv(key, raising=False)
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')
assert HealthStore(tmp_path)._provider()['status'] == 'degraded'