feat: add frozen project context and isolated worker boundary
This commit is contained in:
1 parent
4f457b1e88
commit
855af0bd12
7 files changed
+430
No files matched your search
@@ -0,0 +1,18 @@
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from dx_productivity.trial_task_center.errors import TaskCenterError
|
||||
from dx_productivity.trial_task_center.isolated_desktop import PrivateDesktop, build_startup_info
|
||||
|
||||
|
||||
def test_startup_info_always_targets_private_desktop():
|
||||
info = build_startup_info('dx-private-test')
|
||||
assert info.lpDesktop == 'dx-private-test'
|
||||
|
||||
|
||||
def test_private_desktop_never_falls_back_to_input_desktop(monkeypatch):
|
||||
desktop = PrivateDesktop('dx-private-test', enabled=True)
|
||||
monkeypatch.setattr(desktop, '_create', lambda: None)
|
||||
monkeypatch.setattr(desktop, '_handle', None)
|
||||
with pytest.raises(TaskCenterError, match='private desktop'):
|
||||
desktop.start_process(('cad.exe',))
|
||||
@@ -0,0 +1,78 @@
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from dx_productivity.trial_task_center.models import TaskStatus
|
||||
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.target_plan import ComponentTarget, TargetPlanRow
|
||||
from dx_productivity.trial_task_center.errors import TaskCenterError
|
||||
|
||||
|
||||
def make_service(tmp_path):
|
||||
store = TaskStore(tmp_path / 'tasks.db')
|
||||
logging = configure_logging(tmp_path / 'data')
|
||||
return TaskCenterService(store, logging), store
|
||||
|
||||
|
||||
def test_task_context_is_frozen_single_bound_project_and_cached(tmp_path):
|
||||
service, store = make_service(tmp_path)
|
||||
task = store.create_task('one')
|
||||
path = tmp_path / 'one.prj'; path.touch()
|
||||
project = store.sync_projects(task.task_id, tmp_path, (path,))[0]
|
||||
project = store.set_project_selected(project.project_id, True)
|
||||
store.bind_project_task(task.task_id, project.project_id, 'g', 0)
|
||||
target = ComponentTarget(path, 'MAIN', '1', 'u1', 'R1', 'OLD', 'V')
|
||||
store.record_target_inventory(task.task_id, (target,))
|
||||
store.replace_target_plan(task.task_id, (TargetPlanRow(target, False, 'NEW'),))
|
||||
|
||||
first = service.task_context(task.task_id)
|
||||
second = service.task_context(task.task_id)
|
||||
|
||||
assert first is second
|
||||
assert first.project == project
|
||||
assert first.targets[0].target.uid == 'u1'
|
||||
with pytest.raises(Exception):
|
||||
first.targets += ()
|
||||
|
||||
|
||||
def test_task_context_empty_disabled_plan_does_not_fallback_to_rules(tmp_path):
|
||||
service, store = make_service(tmp_path)
|
||||
task = store.create_task('one')
|
||||
path = tmp_path / 'one.prj'; path.touch()
|
||||
project = store.sync_projects(task.task_id, tmp_path, (path,))[0]
|
||||
store.bind_project_task(task.task_id, project.project_id, 'g', 0)
|
||||
store.add_rule(task.task_id, 'OLD', 'NEW')
|
||||
store.record_target_inventory(task.task_id, ())
|
||||
|
||||
context = service.refresh_bound_project(task.task_id)
|
||||
|
||||
assert context.targets == ()
|
||||
assert context.progress.total_items == 0
|
||||
assert context.legacy is False
|
||||
|
||||
|
||||
def test_multi_project_legacy_context_is_read_only(tmp_path):
|
||||
service, store = make_service(tmp_path)
|
||||
task = store.create_task('legacy')
|
||||
paths = (tmp_path / 'a.prj', tmp_path / 'b.prj')
|
||||
for path in paths: path.touch()
|
||||
store.sync_projects(task.task_id, tmp_path, paths)
|
||||
|
||||
context = service.task_context(task.task_id)
|
||||
|
||||
assert context.legacy is True
|
||||
assert context.project is None
|
||||
with pytest.raises(TaskCenterError):
|
||||
service.refresh_bound_project(task.task_id)
|
||||
|
||||
|
||||
def test_private_desktop_worker_is_opt_in_and_never_falls_back():
|
||||
from dx_productivity.trial_task_center.isolated_worker import IsolatedDesktopWorker, IsolatedWorkerRequest
|
||||
|
||||
request = IsolatedWorkerRequest('1', 'task', Path('C:/board.prj'), ('u1',), 'sha256:x')
|
||||
worker = IsolatedDesktopWorker(enabled=False)
|
||||
with pytest.raises(TaskCenterError, match='opt-in'):
|
||||
worker.run(request)
|
||||
Reference in new issue
Block a user