fix: preflight short batch attempts and preserve cleanup causes

This commit is contained in:
阿白叔 committed 2026-10-23 15:11:16 +08:00
1 parent b21960cda1
commit 7d5ea814ec
11 files changed
+332 -94

No files matched your search

+36
View File
@@ -161,3 +161,39 @@ def test_native_failure_does_not_reuse_previous_attempt_transaction(prepared, tm
assert report['stage'] == 'preflight' and 'transaction' not in report
assert report['batch_attempt']['job_id'] == 'job-a'
assert attempts.read_attempt(path)['state'] == 'prepared'
def test_attempt_write_handles_long_unicode_evidence_and_keeps_canonical_identity(tmp_path, monkeypatch):
from pathlib import Path
directory = tmp_path / ('long-' + 'x' * 110) / ('more-' + 'y' * 80)
path = directory / 'attempt.json'
real_mkdir = Path.mkdir
def strict_mkdir(target, *args, **kwargs):
if len(str(target)) >= 260 and not str(target).startswith(chr(92) * 2 + '?'):
raise OSError('legacy MAX_PATH')
return real_mkdir(target, *args, **kwargs)
monkeypatch.setattr(Path, 'mkdir', strict_mkdir)
project = tmp_path / 'board.prj'
record = attempts.prepare_attempt(path, session_id='session', generation=1,
task_id='task', job_id='job', project_path=project)
assert record['project_path'] == os.path.normcase(str(project.resolve()))
assert attempts.can_retry_attempt(path, record)
assert not str(record['project_path']).startswith(chr(92) * 2 + '?')
def test_publication_retries_sharing_violation_only_and_keeps_original_record(tmp_path, monkeypatch):
path = tmp_path / 'attempt.json'
first = attempts.prepare_attempt(path, session_id='session', generation=1,
task_id='task', job_id='job', project_path=tmp_path / 'board.prj')
calls = []
def fail(source, target):
calls.append((source, target))
error = PermissionError('sharing violation')
error.winerror = 32
raise error
monkeypatch.setattr(os, 'replace', fail)
with pytest.raises(PermissionError):
attempts.prepare_attempt(path, session_id='session', generation=2,
task_id='task', job_id='job', project_path=tmp_path / 'board.prj')
assert len(calls) == 3
assert attempts.read_attempt(path) == first
assert list(tmp_path.iterdir()) == [path]