fix(safety): reject frozen queue policy changes before project backup
This commit is contained in:
1 parent
2c88be99ce
commit
0151552f55
2 files changed
+24
-2
No files matched your search
@@ -6,6 +6,18 @@ from .schematic_backup import create_schematic_backup
|
||||
|
||||
|
||||
def prepare_private_single_step(preparer, task_id, projects, rules, copy_part_number_to_value, *, runtime=None):
|
||||
from .quick_run import (_queue_value_mode, _value_mode, _read_status_details,
|
||||
_queue_has_mutation_evidence)
|
||||
root = preparer.data_root / 'quick-run'
|
||||
command, status = root / 'command.tsv', root / 'status.tsv'
|
||||
# Reject a frozen-policy conflict before even opening the project tree for
|
||||
# backup. This preflight only reads evidence and cannot archive/rewrite it.
|
||||
if (command.is_file() and status.is_file()
|
||||
and _queue_value_mode(command) != _value_mode(copy_part_number_to_value)
|
||||
and (_read_status_details(status) or any(root.glob('snapshot-*'))
|
||||
or _queue_has_mutation_evidence(root))):
|
||||
raise TaskCenterError('quick_run_pending',
|
||||
'recorded Value policy differs; reconcile the old queue before creating a new task')
|
||||
progress = preparer.progress(task_id, projects, rules,
|
||||
copy_part_number_to_value=copy_part_number_to_value)
|
||||
if progress.queue_complete or progress.next_project_path is None:
|
||||
|
||||
@@ -78,14 +78,19 @@ def test_result_for_other_queued_project_is_rejected(tmp_path):
|
||||
assert (tmp_path / 'quick-run/uncertain.flag').exists()
|
||||
|
||||
|
||||
def test_policy_change_cannot_reinterpret_partial_queue(tmp_path):
|
||||
def test_policy_change_cannot_reinterpret_partial_queue(tmp_path, monkeypatch):
|
||||
projects, rules = inputs()
|
||||
preparer = QuickRunPreparer(tmp_path, script_source=SOURCE)
|
||||
result = preparer.prepare('task', projects, rules)
|
||||
job = result.command_path.read_text(encoding='utf-8').splitlines()[1].split('\t')[1]
|
||||
result.status_path.write_text(f'job_id\tstate\tcode\tmessage\n{job}\tawaiting_native_replace\t\tcaptured\n', encoding='utf-8')
|
||||
before = {path.name: path.read_bytes() for path in result.command_path.parent.iterdir() if path.is_file()}
|
||||
from dx_productivity.trial_task_center import single_step
|
||||
monkeypatch.setattr(single_step, 'create_schematic_backup',
|
||||
lambda *a, **k: pytest.fail('frozen policy must be rejected before backup or CAD'))
|
||||
with pytest.raises(TaskCenterError, match='quick_run_pending'):
|
||||
preparer.execute_step('task', projects, rules, copy_part_number_to_value=True)
|
||||
assert before == {path.name: path.read_bytes() for path in result.command_path.parent.iterdir() if path.is_file()}
|
||||
|
||||
|
||||
def test_service_freezes_setting_after_queue_is_prepared(tmp_path):
|
||||
@@ -189,7 +194,7 @@ def test_serial_three_project_two_rule_queue_pins_each_job(tmp_path):
|
||||
assert preparer.progress('task', projects, rules).queue_complete
|
||||
|
||||
|
||||
def test_old_queue_snapshot_blocks_policy_reinterpretation_without_status(tmp_path):
|
||||
def test_old_queue_snapshot_blocks_policy_reinterpretation_without_status(tmp_path, monkeypatch):
|
||||
projects, rules = inputs()
|
||||
preparer = QuickRunPreparer(tmp_path, script_source=SOURCE)
|
||||
result = preparer.prepare('task', projects, rules)
|
||||
@@ -200,8 +205,13 @@ def test_old_queue_snapshot_blocks_policy_reinterpretation_without_status(tmp_pa
|
||||
encoding='utf-8',
|
||||
)
|
||||
(result.command_path.parent / 'snapshot-old.tsv').write_text('retained evidence', encoding='utf-8')
|
||||
before = {path.name: path.read_bytes() for path in result.command_path.parent.iterdir() if path.is_file()}
|
||||
from dx_productivity.trial_task_center import single_step
|
||||
monkeypatch.setattr(single_step, 'create_schematic_backup',
|
||||
lambda *a, **k: pytest.fail('legacy snapshot must be checked before backup or CAD'))
|
||||
with pytest.raises(TaskCenterError, match='quick_run_pending'):
|
||||
preparer.execute_step('task', projects, rules)
|
||||
assert before == {path.name: path.read_bytes() for path in result.command_path.parent.iterdir() if path.is_file()}
|
||||
|
||||
|
||||
def test_frozen_launcher_reserves_helper_script_slot(monkeypatch, tmp_path):
|
||||
|
||||
Reference in new issue
Block a user