71 lines
3.0 KiB
Python
71 lines
3.0 KiB
Python
import pytest
|
|
|
|
|
|
def test_windows_extended_paths_keep_canonical_identity():
|
|
from dx_productivity.trial_task_center.path_access import windows_extended_path, strip_extended_prefix
|
|
slash = chr(92)
|
|
local = 'C:' + slash + ('nested' + slash) * 45 + 'file.json'
|
|
assert windows_extended_path(local) == slash * 2 + '?' + slash + local
|
|
assert strip_extended_prefix(windows_extended_path(local)) == local
|
|
unc = slash * 2 + 'server' + slash + 'share' + slash + 'file.json'
|
|
assert windows_extended_path(unc) == slash * 2 + '?' + slash + 'UNC' + unc[1:]
|
|
assert strip_extended_prefix(windows_extended_path(unc)) == unc
|
|
|
|
|
|
def test_sharing_retry_is_bounded_and_does_not_retry_permission_denied():
|
|
from dx_productivity.trial_task_center.path_access import retry_sharing_violation
|
|
calls = []
|
|
def operation():
|
|
calls.append(1)
|
|
error = PermissionError('sharing violation')
|
|
error.winerror = 32
|
|
raise error
|
|
with pytest.raises(PermissionError):
|
|
retry_sharing_violation(operation, sleep=lambda delay: None)
|
|
assert len(calls) == 3
|
|
calls.clear()
|
|
def denied():
|
|
calls.append(1)
|
|
raise PermissionError('access denied')
|
|
with pytest.raises(PermissionError):
|
|
retry_sharing_violation(denied, sleep=lambda delay: None)
|
|
assert len(calls) == 1
|
|
|
|
def test_discovery_uses_extended_filesystem_access_before_legacy_launch(tmp_path, monkeypatch):
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
from dx_productivity.trial_task_center.project_discovery import discover_project, DiscoveryRuntime
|
|
if os.name != 'nt':
|
|
pytest.skip('Windows filesystem boundary')
|
|
data = tmp_path / ('nested-' + 'a' * 90) / ('more-' + 'b' * 70)
|
|
project = tmp_path / 'board.prj'
|
|
project.write_text('project')
|
|
script = tmp_path / 'worker.vbs'
|
|
script.write_text('script')
|
|
real_mkdir = Path.mkdir
|
|
def strict_mkdir(path, *args, **kwargs):
|
|
if len(str(path)) >= 260 and not str(path).startswith(chr(92) * 2 + '?'):
|
|
raise OSError('legacy MAX_PATH filesystem access')
|
|
return real_mkdir(path, *args, **kwargs)
|
|
monkeypatch.setattr(Path, 'mkdir', strict_mkdir)
|
|
reached = []
|
|
def launch(*args):
|
|
reached.append(1)
|
|
raise subprocess.SubprocessError('stop at launch')
|
|
runtime = DiscoveryRuntime(launch, lambda: Path('cscript'), lambda s, r: (str(s), str(r)),
|
|
lambda: (), str, lambda *a: (), lambda *a: {}, 5)
|
|
with pytest.raises(Exception):
|
|
discover_project(project, ('OLD',), data_root=data, script_source=script, runtime=runtime)
|
|
assert reached, 'long-path filesystem preparation failed before worker boundary'
|
|
|
|
def test_native_short_path_never_passes_extended_prefix_to_wsh(tmp_path):
|
|
import os
|
|
from dx_productivity.trial_task_center.legacy_paths import _short_path
|
|
if os.name != 'nt':
|
|
pytest.skip('Windows short-path boundary')
|
|
result = _short_path(tmp_path)
|
|
if result is None:
|
|
pytest.skip('filesystem does not provide short paths')
|
|
assert not result.startswith(chr(92) * 2 + '?')
|