fix: launch supervisors through compatible working directory
This commit is contained in:
1 parent
62f143fe9f
commit
f3d7423d02
2 files changed
+36
-4
No files matched your search
@@ -14,7 +14,7 @@ import time
|
||||
from uuid import uuid4
|
||||
|
||||
from .errors import TaskCenterError
|
||||
from .path_access import canonical_path, internal_path
|
||||
from .path_access import canonical_path, internal_path, legacy_path
|
||||
from .supervisor_protocol import VERSION, MessageGate, valid_journal, encode, decode, decode_error
|
||||
|
||||
_WORKER_ROOT = None
|
||||
@@ -235,7 +235,7 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
||||
try:
|
||||
# A normal input-desktop supervisor owns its private-desktop children.
|
||||
# Only the supervisor, never the GUI, creates a private desktop.
|
||||
process = api.create_process(_command(internal_path(request)), None, root,
|
||||
process = api.create_process(_command(internal_path(request)), None, legacy_path(root),
|
||||
_environment(), stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
||||
journal.update(state='running', process=process_identity(process))
|
||||
write_record(directory / 'supervisor.json', journal)
|
||||
@@ -303,12 +303,16 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
||||
from .supervisor_result import validated_outcome, resource_pending_error
|
||||
decoded_result, decoded_error, decoded_primary = validated_outcome(operation, response['payload'])
|
||||
except (OSError, ValueError, KeyError, TypeError, AttributeError) as error:
|
||||
_mark_interrupted(root, journal, error)
|
||||
_mark_interrupted(root, journal, transport_error or error)
|
||||
# Recheck physical resources even when final business results are
|
||||
# missing; this never authorizes repeating the interrupted job.
|
||||
from .batch_resources import cleanup_pending_resources
|
||||
cleanup_pending_resources(root, logging_context=service._logging)
|
||||
raise TaskCenterError('supervisor_interrupted', '批次监督进程未留下可信结果;保留保护记录,不自动重试。') from error
|
||||
failure = TaskCenterError('supervisor_interrupted',
|
||||
'批次监督进程未留下可信结果;保留保护记录,不自动重试。' +
|
||||
(f' 首发原因:{transport_error}' if transport_error else ''))
|
||||
failure.primary_error = transport_error or error
|
||||
raise failure from (transport_error or error)
|
||||
if transport_error is not None:
|
||||
if response['payload']['business_succeeded']:
|
||||
journal.update(state='blocked', outcome='completed_resources_pending', error=str(transport_error))
|
||||
|
||||
@@ -29,6 +29,34 @@ def test_mutation_guard_refuses_owned_launch_gate(tmp_path):
|
||||
assert_supervisor_idle(tmp_path)
|
||||
|
||||
|
||||
def test_supervisor_deep_root_uses_compatible_process_working_directory(tmp_path, monkeypatch):
|
||||
from dx_productivity.trial_task_center.batch_supervisor import run_supervised
|
||||
from dx_productivity.trial_task_center.isolated_desktop import _Win32Api
|
||||
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
||||
from dx_productivity.trial_task_center.path_access import canonical_path
|
||||
from dx_productivity.trial_task_center.store import TaskStore
|
||||
from dx_productivity.trial_task_center.service import TaskCenterService
|
||||
root = tmp_path
|
||||
while len(str(root)) < 270:
|
||||
root = root / '中文深目录abcdef0123456789'
|
||||
root.mkdir(parents=True)
|
||||
actual = _Win32Api.create_process
|
||||
launched = []
|
||||
def create(api, command, desktop, cwd, *args, **kwargs):
|
||||
assert len(str(cwd)) < 260
|
||||
assert canonical_path(cwd) == root
|
||||
launched.append(True)
|
||||
return actual(api, command, desktop, cwd, *args, **kwargs)
|
||||
monkeypatch.setattr(_Win32Api, 'create_process', create)
|
||||
store = TaskStore(root/'task-center.db')
|
||||
try:
|
||||
service = TaskCenterService(store, configure_logging(root))
|
||||
assert run_supervised(service, 'probe', {})['pid'] != os.getpid()
|
||||
assert launched == [True]
|
||||
finally:
|
||||
store.close()
|
||||
|
||||
|
||||
def test_child_error_returns_original_code_without_acquiring_desktop(tmp_path):
|
||||
from dx_productivity.trial_task_center.batch_supervisor import run_supervised
|
||||
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
||||
|
||||
Reference in new issue
Block a user