feat(dsh): harden health decisions and issue transport

This commit is contained in:
阿白叔 committed 2026-10-31 09:50:35 +08:00
1 parent 736b582bc1
commit eee4e6bde9
18 files changed
+592 -11

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
import json
import pytest
from dx_productivity.dsh.decision_log import DecisionLog
def _row(incident='a' * 24, outcome='pending_issue'):
return {'incident_id': incident, 'trigger': 'execution_failed', 'evidence_refs': ['dsh/incidents/x/gates.json'],
'gates': {'execution_authorized': True, 'retry_budget_available': False},
'candidate_action': 'none', 'authorized_scope': {'task_ids': ['task-1']}, 'outcome': outcome,
'human_takeover': False}
def test_decision_log_is_hash_linked_and_survives_restart(tmp_path):
store = DecisionLog(tmp_path)
first = store.append(_row())
second = DecisionLog(tmp_path).append(_row('b' * 24, 'resolved'))
assert first['sequence'] == 1
assert second['previous_hash'] == first['record_hash']
assert DecisionLog(tmp_path).verify()['valid'] is True
assert [row['sequence'] for row in DecisionLog(tmp_path).list()] == [1, 2]
def test_decision_log_detects_tampering_and_bounds_text(tmp_path):
store = DecisionLog(tmp_path)
store.append(_row())
path = tmp_path / 'dsh' / 'decisions.jsonl'
raw = path.read_text(encoding='utf8').replace('execution_failed', 'x' * 5000)
path.write_text(raw, encoding='utf8')
assert DecisionLog(tmp_path).verify()['valid'] is False
with pytest.raises(ValueError, match='incident_id'):
store.append(_row('bad'))