32 lines
1.8 KiB
Python
32 lines
1.8 KiB
Python
from dx_productivity.dsh.failure_policy import classify_failure
|
|
|
|
|
|
def test_failure_policy_allows_one_authorized_transient_retry():
|
|
assert not classify_failure('worker_timeout', 'failed', authorized=True)['retry_allowed']
|
|
value = classify_failure('worker_timeout', 'failed', authorized=True, certified=True)
|
|
assert value['category'] == 'transient' and value['retry_allowed']
|
|
assert value['max_attempts'] == 1
|
|
|
|
|
|
def test_code_names_cannot_establish_prewrite_evidence():
|
|
for code in ('worker_timeout_before_write', 'cad_attachment_failed', 'worker_error'):
|
|
assert not classify_failure(code, 'failed', authorized=True)['retry_allowed']
|
|
assert not classify_failure(code, 'failed', certified=True)['retry_allowed']
|
|
assert not classify_failure(code, 'saved_unverified', certified=True, authorized=True)['retry_allowed']
|
|
|
|
|
|
def test_execution_phase_controls_continuation_and_unknown_write_blocks_retry():
|
|
for phase in ('read', 'not_dispatched'):
|
|
policy = classify_failure('new_error', 'failed', phase=phase, authorized=True)
|
|
assert policy['continue_allowed'] and not policy['retry_allowed']
|
|
for phase in ('may_write', 'saved'):
|
|
policy = classify_failure('worker_timeout_before_write', 'failed', phase=phase, authorized=True)
|
|
assert policy['category'] == 'uncertain' and not policy['continue_allowed']
|
|
|
|
|
|
def test_failure_policy_blocks_uncertain_and_deterministic_errors():
|
|
assert classify_failure('quick_run_uncertain', 'uncertain', interrupted=True)['category'] == 'uncertain'
|
|
assert classify_failure('target_identity', 'failed', authorized=True)['retry_allowed'] is False
|
|
assert classify_failure('paused', 'paused', authorized=True)['category'] == 'paused'
|
|
assert classify_failure('new_error', 'failed')['category'] == 'observe'
|