fix: isolate component failures and recover owned CAD resources

This commit is contained in:
阿白叔 committed 2026-11-06 14:56:53 +08:00
1 parent a8da30aad2
commit 4db5f05531
87 files changed
+6688 -301

No files matched your search

+13 -8
View File
@@ -149,7 +149,7 @@ def worker_runtime(tmp_path, monkeypatch, monitor):
return BatchCadRuntime(tmp_path / 'data', 'execution', desktop_factory=Desktop, cad_factory=Cad)
def test_two_projects_reuse_cad_and_produce_distinct_close_checkpoints(tmp_path, monkeypatch):
def test_same_project_reuses_cad_then_next_project_starts_a_fresh_session(tmp_path, monkeypatch):
import subprocess
from dx_productivity.trial_task_center.batch_resources import project_checkpoint_released
one, _ = command_for(tmp_path)
@@ -159,10 +159,15 @@ def test_two_projects_reuse_cad_and_produce_distinct_close_checkpoints(tmp_path,
with runtime:
runtime.run_worker(one, 5)
assert project_checkpoint_released(Path(one[3]))
first = runtime.cad
runtime.run_worker(one, 5)
assert runtime.cad is first
runtime.run_worker(two, 5)
assert project_checkpoint_released(Path(two[3]))
assert len(Cad.created) == len(Desktop.created) == 1
assert Cad.created[0].closed and Desktop.created[0].released
assert first.closed and Desktop.created[0].released
assert len(Cad.created) == len(Desktop.created) == 2
assert all(cad.closed for cad in Cad.created)
assert all(desktop.released for desktop in Desktop.created)
def test_completed_project_does_not_hold_resolution_wait_for_next_project_failure(tmp_path, monkeypatch):
@@ -410,7 +415,7 @@ def test_native_rebuild_requires_strict_source_and_worker_proof(tmp_path):
for path in (project, database)}}
path = evidence / 'native-retry-proof.json'
path.write_text(json.dumps(proof))
with BatchCadRuntime(tmp_path / 'data', 'bom_import', desktop_factory=Desktop) as runtime:
with BatchCadRuntime(tmp_path / 'data', 'execution', desktop_factory=Desktop) as runtime:
with runtime.native_scope(evidence) as scope:
pass
proof['binding'] = scope.identity
@@ -475,17 +480,17 @@ def test_mock_different_projects_each_get_one_retry_without_accumulating_budget(
calls[command[3]] += 1
if calls[command[3]] == 2:
return subprocess.CompletedProcess(command, 0, '', '')
raise WorkerMonitorError('unchanged prewrite failure')
return subprocess.CompletedProcess(command, 2, '', 'unchanged prewrite failure')
runtime = worker_runtime(tmp_path, monkeypatch, monitor)
with runtime:
runtime.run_worker(one, 5)
assert len(Desktop.created) == 2
runtime.run_worker(two, 5)
assert len(Desktop.created) == 3 # Each project gets its own single rebuild.
for command in (one, two):
assert len(Desktop.created) == 4 # Separate project startup plus its single rebuild.
for expected_sessions, command in enumerate((one, two), 5):
with pytest.raises(WorkerMonitorError, match='prewrite failure'):
runtime.run_worker(command, 5)
assert len(Desktop.created) == 3 # Success cannot replenish either budget.
assert len(Desktop.created) == expected_sessions # Switching projects is not another retry.
assert calls == {one[3]: 3, two[3]: 3}
assert set(runtime.record['retries']) == {
str(project_one.resolve()).casefold(), str(project_two.resolve()).casefold()}