fix(dsh): align recovery, scheduling audit and credential guarantees

This commit is contained in:
阿白叔 committed 2026-10-31 14:16:27 +08:00
1 parent e565f67b46
commit 9552f1eb95
32 files changed
+514 -135

No files matched your search

+35 -2
View File
@@ -49,12 +49,45 @@ def test_due_order_and_manual_confirmation_without_execution(project_service):
urgent = schedules.save(spec(ids, priority='urgent', auto_start=True), hashes)
rows = schedules.evaluate(service, now=NOW)
assert [row['schedule_id'] for row in rows] == [urgent['schedule_id'], normal['schedule_id']]
assert rows[0]['ready'] and rows[0]['requires_confirmation'] is True
assert rows[0]['dispatchable'] is False # model-supplied auto_start never grants authority
assert rows[0]['ready'] and rows[0]['requires_confirmation'] is False
assert rows[0]['dispatchable'] is True # save follows native future-run authorization
assert rows[0]['dispatch_authority'] == 'native_future_authorization'
assert rows[1]['requires_confirmation'] and not rows[1]['dispatchable']
assert not list(data.rglob('command.tsv'))
assert all('worker_busy' in row['blockers'] for row in schedules.evaluate(service, now=NOW, busy=True))
def test_dispatch_and_result_audit_are_durable_and_automatic_claim_needs_authority(project_service):
_, _, data, ids, hashes = project_service
schedules = ScheduleStore(data)
manual = schedules.save(spec(ids), hashes)
with pytest.raises(TaskCenterError, match='schedule_authority'):
schedules.claim(manual['schedule_id'], automatic=True, run_id='a' * 32)
assert schedules.get(manual['schedule_id'])['status'] == 'pending'
assert schedules.events() == []
row = schedules.save(spec(ids, auto_start=True), hashes)
schedules.claim(row['schedule_id'], automatic=True, run_id='b' * 32)
schedules.finish(row['schedule_id'], 'completed', run_id='b' * 32, receipt={'status': 'completed'})
events = ScheduleStore(data).events()
assert [e['event'] for e in reversed(events)] == ['dispatch', 'result']
assert events[1]['payload']['scope'] == {'task_ids': ids, 'plan_hashes': hashes}
assert events[1]['payload']['authority'] == 'native_future_authorization'
assert events[0]['payload']['receipt']['status'] == 'completed'
assert all(e['run_id'] == 'b' * 32 for e in events)
def test_audit_insert_failure_rolls_back_claim_before_execution(project_service):
import sqlite3
_, _, data, ids, hashes = project_service
schedules = ScheduleStore(data)
row = schedules.save(spec(ids, auto_start=True), hashes)
with sqlite3.connect(schedules.path) as db:
db.execute("CREATE TRIGGER reject_event BEFORE INSERT ON schedule_events BEGIN SELECT RAISE(ABORT, 'controlled audit fault'); END")
with pytest.raises(sqlite3.IntegrityError):
schedules.claim(row['schedule_id'], automatic=True, run_id='b' * 32)
assert ScheduleStore(data).get(row['schedule_id'])['status'] == 'pending'
def test_future_and_changed_plans_do_not_become_ready(project_service):
service, _, data, ids, hashes = project_service
schedules = ScheduleStore(data)