fix: preserve deep project scans and orphan recovery protection
This commit is contained in:
1 parent
2a90201bfa
commit
3367bb6454
5 files changed
+116
-32
No files matched your search
@@ -7,6 +7,7 @@ import subprocess
|
||||
import pytest
|
||||
|
||||
from dx_productivity.trial_task_center.errors import TaskCenterError
|
||||
from dx_productivity.trial_task_center.path_access import strip_extended_prefix
|
||||
from dx_productivity.trial_task_center.scanner import scan_projects
|
||||
|
||||
|
||||
@@ -58,7 +59,7 @@ def test_scan_projects_stops_at_selected_project_directory_when_it_contains_prj_
|
||||
real_scandir = os.scandir
|
||||
|
||||
def reject_nested(path: str | bytes | int) -> object:
|
||||
if Path(path) != root:
|
||||
if Path(strip_extended_prefix(path)) != root:
|
||||
raise AssertionError(f"unexpected nested scan: {path}")
|
||||
return real_scandir(path)
|
||||
|
||||
@@ -84,7 +85,7 @@ def test_scan_projects_reads_batch_root_once_before_recursive_fallback(
|
||||
|
||||
def count_root(path: str | bytes | int) -> object:
|
||||
nonlocal root_reads
|
||||
if Path(path) == root:
|
||||
if Path(strip_extended_prefix(path)) == root:
|
||||
root_reads += 1
|
||||
return real_scandir(path)
|
||||
|
||||
@@ -138,7 +139,7 @@ def test_scan_projects_turns_inaccessible_subtree_errors_into_explicit_task_erro
|
||||
real_scandir = __import__("os").scandir
|
||||
|
||||
def deny(path: str | bytes | int) -> object:
|
||||
if Path(path) == denied:
|
||||
if Path(strip_extended_prefix(path)) == denied:
|
||||
raise PermissionError("denied subtree")
|
||||
return real_scandir(path)
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from dx_productivity.trial_task_center.path_access import internal_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deep_windows_tree(tmp_path, monkeypatch):
|
||||
if os.name != 'nt':
|
||||
pytest.skip('real Windows long paths')
|
||||
root = tmp_path / ('projects-' + 'x' * 105) / ('revision-' + 'y' * 100)
|
||||
assert len(str(root)) > 260
|
||||
internal_path(root).mkdir(parents=True)
|
||||
def legacy_failure(path):
|
||||
return len(os.fspath(path)) >= 260 and not os.fspath(path).startswith(chr(92) * 2 + '?')
|
||||
for name in ('stat', 'open', 'resolve'):
|
||||
original = getattr(Path, name)
|
||||
def strict(path, *args, _original=original, **kwargs):
|
||||
if legacy_failure(path):
|
||||
raise FileNotFoundError(2, 'MAX_PATH host cannot access unprefixed deep path')
|
||||
return _original(path, *args, **kwargs)
|
||||
monkeypatch.setattr(Path, name, strict)
|
||||
original_scandir = os.scandir
|
||||
def scandir(path):
|
||||
if not isinstance(path, int) and legacy_failure(path):
|
||||
raise FileNotFoundError(2, 'MAX_PATH host cannot scan unprefixed deep path')
|
||||
return original_scandir(path)
|
||||
monkeypatch.setattr(os, 'scandir', scandir)
|
||||
return root
|
||||
|
||||
|
||||
def test_deep_schematic_scan_keeps_canonical_projects_exclusions_and_progress(deep_windows_tree):
|
||||
from dx_productivity.trial_task_center.scanner import scan_projects
|
||||
from dx_productivity.trial_task_center.project_tasks import scan_project_directory, _validate_selected
|
||||
root = deep_windows_tree
|
||||
project = root / 'selected/board.prj'
|
||||
excluded = root / 'excluded'
|
||||
for path in (project, excluded / 'hidden.prj'):
|
||||
internal_path(path.parent).mkdir(parents=True, exist_ok=True)
|
||||
internal_path(path).write_text('KEY FrontEndSnapshot "DxD"\nKEY iCDBDir "database"\n', encoding='utf-8')
|
||||
assert scan_projects(root, excluded_roots=(excluded,)) == (project,)
|
||||
progress = []
|
||||
assert scan_project_directory(root, excluded_roots=(excluded,), on_progress=lambda directory, *_: progress.append(directory)) == (project,)
|
||||
assert progress and all(path.is_relative_to(root) for path in progress)
|
||||
assert _validate_selected(root, (project,), (excluded,)) == (project,)
|
||||
|
||||
|
||||
def test_deep_orphan_uncertainty_flag_retains_task_without_handoff(deep_windows_tree, tmp_path, monkeypatch):
|
||||
from types import SimpleNamespace
|
||||
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
||||
from dx_productivity.trial_task_center.service import TaskCenterService
|
||||
from dx_productivity.trial_task_center.store import TaskStore
|
||||
from dx_productivity.trial_task_center.task_archive import archive_completed_session
|
||||
store = TaskStore(tmp_path / 'tasks.db')
|
||||
context = configure_logging(tmp_path / 'logs')
|
||||
service = TaskCenterService(store, context)
|
||||
task = service.create_task('protected')
|
||||
root = deep_windows_tree
|
||||
marker = root / 'quick-run/uncertain.flag'
|
||||
internal_path(marker.parent).mkdir(parents=True)
|
||||
internal_path(marker).write_text('needs verification', encoding='utf-8')
|
||||
monkeypatch.setattr(service, 'pending_batch_resources', lambda: ())
|
||||
monkeypatch.setattr(service, 'has_interrupted_quick_run', lambda task_id: False)
|
||||
facade = SimpleNamespace(_quick_run_preparer=SimpleNamespace(data_root=root))
|
||||
monkeypatch.setattr(service, '_project_task_service', lambda task_id: facade)
|
||||
try:
|
||||
report = archive_completed_session(service)
|
||||
assert report.archived_ids == ()
|
||||
assert report.retained_ids == (task.task_id,)
|
||||
assert [item.task_id for item in service.tasks()] == [task.task_id]
|
||||
assert internal_path(marker).read_text(encoding='utf-8') == 'needs verification'
|
||||
assert not internal_path(marker.with_name('command.tsv')).exists()
|
||||
finally:
|
||||
store.close()
|
||||
for handler in tuple(context.logger.handlers):
|
||||
handler.close()
|
||||
context.logger.removeHandler(handler)
|
||||
|
||||
Reference in new issue
Block a user