fix: use extended filesystem paths for deep queue evidence
This commit is contained in:
1 parent
3c4e6e7e37
commit
c787ef325b
9 files changed
+208
-87
No files matched your search
@@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
from dx_productivity.trial_task_center.path_access import strip_extended_prefix
|
||||
import pytest
|
||||
from dx_productivity.trial_task_center.models import ProjectRecord, ProjectStatus, RuleRecord
|
||||
from dx_productivity.trial_task_center.quick_run import QuickRunPreparer
|
||||
@@ -21,7 +22,7 @@ def test_snapshot_reads_each_file_once_and_uses_same_status(tmp_path, monkeypatc
|
||||
opens = []
|
||||
original = Path.open
|
||||
def tracked(path, *args, **kwargs):
|
||||
if path.parent == handoff.command_path.parent:
|
||||
if Path(strip_extended_prefix(path)).parent == handoff.command_path.parent:
|
||||
opens.append(path.name)
|
||||
return original(path, *args, **kwargs)
|
||||
monkeypatch.setattr(Path, 'open', tracked)
|
||||
@@ -48,7 +49,7 @@ def test_snapshot_cancellation_stops_before_next_file_and_never_writes(tmp_path,
|
||||
def tracked(path, *args, **kwargs):
|
||||
opened.append(path.name)
|
||||
result = original(path, *args, **kwargs)
|
||||
if path == handoff.command_path:
|
||||
if Path(strip_extended_prefix(path)) == handoff.command_path:
|
||||
control.cancelled = True
|
||||
return result
|
||||
monkeypatch.setattr(Path, 'open', tracked)
|
||||
@@ -91,7 +92,7 @@ def test_snapshot_retries_when_uncertain_flag_is_created_during_status_read(tmp_
|
||||
injected = False
|
||||
def racing_open(path, *args, **kwargs):
|
||||
nonlocal injected
|
||||
if path == handoff.status_path and args and args[0] == 'r' and not injected:
|
||||
if Path(strip_extended_prefix(path)) == handoff.status_path and args and args[0] == 'r' and not injected:
|
||||
injected = True
|
||||
(path.parent / 'uncertain.flag').write_text('uncertain', encoding='utf-8')
|
||||
return original(path, *args, **kwargs)
|
||||
@@ -108,7 +109,7 @@ def test_snapshot_retries_command_and_status_as_one_generation(tmp_path, monkeyp
|
||||
injected = False
|
||||
def racing_open(path, *args, **kwargs):
|
||||
nonlocal injected
|
||||
if path == handoff.status_path and args and args[0] == 'r' and not injected:
|
||||
if Path(strip_extended_prefix(path)) == handoff.status_path and args and args[0] == 'r' and not injected:
|
||||
injected = True
|
||||
handoff.command_path.write_text(command.replace(job, 'new-generation'), encoding='utf-8')
|
||||
handoff.status_path.write_text('job_id\tstate\tcode\tmessage\nnew-generation\tno_match\t\tno match\n', encoding='utf-8')
|
||||
@@ -126,7 +127,7 @@ def test_snapshot_continuous_changes_block_continuation_after_bounded_retries(tm
|
||||
reads = 0
|
||||
def racing_open(path, *args, **kwargs):
|
||||
nonlocal reads
|
||||
if path == handoff.status_path and args and args[0] == 'r':
|
||||
if Path(strip_extended_prefix(path)) == handoff.status_path and args and args[0] == 'r':
|
||||
reads += 1
|
||||
(path.parent / 'changing.txt').write_text('x' * reads, encoding='utf-8')
|
||||
return original(path, *args, **kwargs)
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from dx_productivity.trial_task_center.path_access import internal_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deep_root(tmp_path, monkeypatch):
|
||||
if os.name != 'nt':
|
||||
pytest.skip('real Windows long-path regression')
|
||||
root = tmp_path / ('design-' + 'x' * 100) / ('revision-' + 'y' * 100)
|
||||
assert len(str(root)) > 260
|
||||
# Exercise real Windows files while reproducing a host with MAX_PATH-bound
|
||||
# nonextended access, regardless of this developer machine's policy.
|
||||
originals = {name: getattr(Path, name) for name in ('mkdir', 'open', 'stat')}
|
||||
for name, original in originals.items():
|
||||
def strict(path, *args, _original=original, **kwargs):
|
||||
if len(str(path)) >= 260 and not str(path).startswith(chr(92) * 2 + '?'):
|
||||
raise OSError(206, 'legacy MAX_PATH access')
|
||||
return _original(path, *args, **kwargs)
|
||||
monkeypatch.setattr(Path, name, strict)
|
||||
return root
|
||||
|
||||
|
||||
def test_deep_task_event_keeps_public_root_and_rotates_readable_events(deep_root, monkeypatch):
|
||||
from dx_productivity.trial_task_center import logging_setup
|
||||
context = logging_setup.configure_logging(deep_root)
|
||||
monkeypatch.setattr(logging_setup, '_MAX_EVENT_LOG_BYTES', 1)
|
||||
try:
|
||||
for operation in ('first', 'second', 'third'):
|
||||
logging_setup.append_task_event(context, level='INFO', task_id='task', operation=operation)
|
||||
path = deep_root / 'tasks/task/events.jsonl'
|
||||
assert context.root == deep_root
|
||||
assert context.application_log_path == deep_root / 'logs/application.log'
|
||||
assert json.loads(internal_path(path).read_text(encoding='utf-8'))['sequence'] == 3
|
||||
assert json.loads(internal_path(path.with_name('events.jsonl.1')).read_text(encoding='utf-8'))['sequence'] == 2
|
||||
finally:
|
||||
for handler in tuple(context.logger.handlers):
|
||||
handler.close()
|
||||
context.logger.removeHandler(handler)
|
||||
|
||||
|
||||
def test_deep_quick_run_prepare_publish_read_archive_keeps_canonical_results(deep_root, tmp_path):
|
||||
from dx_productivity.trial_task_center import quick_run
|
||||
from dx_productivity.trial_task_center.models import ProjectRecord, ProjectStatus, RuleRecord
|
||||
source = tmp_path / 'worker.vbs'
|
||||
source.write_text('runtime', encoding='utf-8')
|
||||
adapter = source.with_name('NativeSnapshotReader.vbs')
|
||||
adapter.write_text('adapter', encoding='utf-8')
|
||||
project = tmp_path / 'board.prj'
|
||||
project.touch()
|
||||
record = ProjectRecord('project', 'task', 'board', project, tmp_path, True, True, ProjectStatus.PENDING, 0)
|
||||
rule = RuleRecord('rule', 'task', 0, 'OLD', 'NEW', True)
|
||||
preparer = quick_run.QuickRunPreparer(deep_root, script_source=source, run_token_factory=lambda: 'run')
|
||||
handoff = preparer.prepare('task', (record,), (rule,))
|
||||
assert preparer.data_root == deep_root
|
||||
assert handoff.command_path == deep_root / 'quick-run/command.tsv'
|
||||
assert internal_path(handoff.script_path).read_text(encoding='utf-8') == 'runtime\nadapter'
|
||||
assert quick_run._read_commands(handoff.command_path)[0][2] == str(project)
|
||||
assert preparer.read_snapshot('task', (record,), (rule,)).evidence_path == deep_root / 'quick-run'
|
||||
statuses = (('run_0', 'no_match', '', 'done'),)
|
||||
quick_run._write_status_details(handoff.status_path, statuses)
|
||||
assert quick_run._read_status_details(handoff.status_path) == statuses
|
||||
quick_run._write_atomic_queue_text(handoff.command_path.parent / 'current-state.tsv', 'published', 'test', 'test')
|
||||
quick_run._write_uncertain_flag(handoff.command_path.parent / 'uncertain.flag')
|
||||
assert quick_run._queue_has_mutation_evidence(handoff.command_path.parent)
|
||||
archive = preparer.archive_current_handoff('task')
|
||||
assert archive.parent == deep_root / 'quick-run-history'
|
||||
assert quick_run._read_commands(archive / 'command.tsv')[0][2] == str(project)
|
||||
assert quick_run._read_status_details(archive / 'status.tsv') == statuses
|
||||
|
||||
assert preparer.read_snapshot('task', (record,), (rule,)).evidence_path == archive
|
||||
|
||||
def test_deep_native_recovery_keeps_canonical_proof_and_release_logs(deep_root):
|
||||
import hashlib
|
||||
from dx_productivity.trial_task_center.batch_runtime import BatchCadRuntime
|
||||
from test_batch_runtime import Desktop
|
||||
Desktop.created = []
|
||||
Desktop.fail_release = False
|
||||
project = deep_root / 'source/board.prj'
|
||||
database = project.with_name('icdb.dat')
|
||||
internal_path(project.parent).mkdir(parents=True)
|
||||
internal_path(project).write_bytes(b'project')
|
||||
internal_path(database).write_bytes(b'database')
|
||||
evidence = deep_root / 'quick-run-history/native-read'
|
||||
internal_path(evidence).mkdir(parents=True)
|
||||
with BatchCadRuntime(deep_root, 'bom_import', desktop_factory=Desktop) as owner:
|
||||
with owner.native_scope(evidence) as scope:
|
||||
pass
|
||||
proof = {'version': 1, 'native_read_only': True, 'workers_closed': True,
|
||||
'binding': scope.identity, 'project_path': str(project), 'evidence_root': str(evidence),
|
||||
'source_hashes': {str(path): hashlib.sha256(internal_path(path).read_bytes()).hexdigest()
|
||||
for path in (project, database)}}
|
||||
internal_path(evidence / 'native-retry-proof.json').write_text(json.dumps(proof), encoding='utf-8')
|
||||
assert owner.recover_native_failure(project, evidence, 'timeout')
|
||||
assert not owner.recover_native_failure(project, evidence, 'second timeout')
|
||||
assert all(desktop.released for desktop in Desktop.created)
|
||||
assert not owner.record.get('release_log_errors')
|
||||
release = owner.path.with_name('resource-release.log')
|
||||
assert 'resource-release' in str(release)
|
||||
assert 'released' in internal_path(release).read_text(encoding='utf-8')
|
||||
@@ -39,7 +39,9 @@ def test_existing_log_directories_avoid_mkdir_and_recreate_after_removal(tmp_pat
|
||||
directory=tmp_path/'tasks/task';directory.mkdir(parents=True)
|
||||
original=Path.mkdir;calls=[]
|
||||
def mkdir(path,*args,**kwargs):
|
||||
if path==directory:calls.append(path)
|
||||
from dx_productivity.trial_task_center.path_access import strip_extended_prefix
|
||||
canonical = Path(strip_extended_prefix(path))
|
||||
if canonical==directory:calls.append(canonical)
|
||||
return original(path,*args,**kwargs)
|
||||
monkeypatch.setattr(Path,'mkdir',mkdir)
|
||||
assert logging_setup._task_directory(context,'task')==directory
|
||||
|
||||
Reference in new issue
Block a user