fix(dsh): align recovery, scheduling audit and credential guarantees
This commit is contained in:
1 parent
e565f67b46
commit
9552f1eb95
32 files changed
+514
-135
No files matched your search
@@ -1,32 +1,48 @@
|
||||
from types import SimpleNamespace as NS
|
||||
|
||||
from dx_productivity.dsh.resume_diff import resume_diff
|
||||
from dx_productivity.dsh.run_journal import RunJournal
|
||||
from test_run_journal import project_service, checkpoint, evidence
|
||||
|
||||
|
||||
class Service:
|
||||
def __init__(self, contexts, hashes=None): self.contexts, self.current_plan_hashes = contexts, hashes or {'t1': 'h1', 't2': 'h2'}
|
||||
def task_context(self, task_id): return self.contexts[task_id]
|
||||
def test_real_service_plan_changes_are_reported(project_service):
|
||||
service, _, data, ids, hashes = project_service
|
||||
journal = RunJournal(data)
|
||||
journal.begin('a' * 32, ids, hashes)
|
||||
checkpoint(data, 'a' * 32, ids, hashes)
|
||||
rule = service.rules(ids[0])[0]
|
||||
service.update_rule(rule.rule_id, old_part_number='OLD', new_part_number='DIFFERENT', enabled=True)
|
||||
report = journal.inspect(service, 'a' * 32)
|
||||
assert ids[0] in report['diff']['changed']
|
||||
change = next(row for row in report['diff']['plan_changes'] if row['task_id'] == ids[0])
|
||||
assert change['saved'] == hashes[ids[0]] and change['current'] != change['saved']
|
||||
assert report['diff']['safe'] is False
|
||||
|
||||
|
||||
def context(status='ready', interrupted=False):
|
||||
return NS(task=NS(status=NS(value=status), name='Board'), progress=NS(queue_complete=status == 'completed',
|
||||
saved_items=1 if status == 'completed' else 0, failed_items=0, no_match_items=0), interrupted=interrupted)
|
||||
def test_real_service_uses_original_checkpoint_remaining_scope(project_service):
|
||||
service, _, data, ids, hashes = project_service
|
||||
journal = RunJournal(data)
|
||||
journal.begin('a' * 32, ids, hashes)
|
||||
checkpoint(data, 'a' * 32, ids, hashes)
|
||||
report = journal.inspect(service, 'a' * 32)
|
||||
assert report['diff']['safe'] is True
|
||||
assert report['diff']['remaining'] == ids
|
||||
assert report['diff']['completed'] == []
|
||||
|
||||
|
||||
def inspected():
|
||||
return {'run_id': 'a' * 32, 'task_ids': ['t1', 't2'], 'remaining_task_ids': ['t2'],
|
||||
'plan_hashes': {'t1': 'h1', 't2': 'h2'}, 'queue_available': True, 'resume_ready': True,
|
||||
'blockers': [], 'tasks': [{'task_id': 't1', 'status': 'completed'}, {'task_id': 't2', 'status': 'ready'}]}
|
||||
def test_evidence_counter_changes_since_receipt_are_visible(project_service):
|
||||
service, _, data, ids, hashes = project_service
|
||||
journal = RunJournal(data)
|
||||
journal.begin('a' * 32, ids, hashes)
|
||||
checkpoint(data, 'a' * 32, ids, hashes)
|
||||
journal.finish('a' * 32, {'status': 'paused', 'tasks': [{'task_id': ids[0], 'no_match_items': 0}]})
|
||||
evidence(service, ids[0])
|
||||
report = journal.inspect(service, 'a' * 32)
|
||||
assert {'task_id': ids[0], 'field': 'no_match_items', 'saved': 0, 'current': 1} in report['diff']['evidence_changes']
|
||||
assert 'evidence_changed' in report['diff']['blockers']
|
||||
|
||||
|
||||
def test_resume_diff_is_safe_for_unchanged_frozen_scope():
|
||||
value = resume_diff(Service({'t1': context('completed'), 't2': context()}), inspected())
|
||||
assert value['safe'] is True and value['completed'] == ['t1'] and value['remaining'] == ['t2']
|
||||
assert value['changed'] == []
|
||||
|
||||
|
||||
def test_resume_diff_blocks_plan_change_and_uncertainty():
|
||||
row = inspected()
|
||||
value = resume_diff(Service({'t1': context('completed', interrupted=True), 't2': context()}, {'t1': 'changed', 't2': 'h2'}), row)
|
||||
def test_missing_current_hash_cannot_be_silently_ignored(project_service):
|
||||
service, _, _, ids, hashes = project_service
|
||||
value = resume_diff(service, {'task_ids': ids, 'plan_hashes': {}, 'remaining_task_ids': ids,
|
||||
'queue_available': True, 'resume_ready': True, 'tasks': []})
|
||||
assert value['safe'] is False
|
||||
assert 'plan_changed' in value['blockers'] and 'interrupted' in value['blockers']
|
||||
assert value['changed'] == ids
|
||||
Reference in new issue
Block a user