The delegate_tool_* siblings imported names back from tools.delegate_tool inside functions only so tests could patch `tools.delegate_tool.<name>` (routes said so: "the facade is the patch seam"). That kept a facade <-> sibling import cycle and a function-level import at each read. - child_run owns the heartbeat/stale-grace constants (only it reads them) and imports _get_child_timeout, _get_subagent_approval_callback, _get_worktree_isolation, _resolve_workspace_hint and terminal_tool's set_approval_callback at module top. - config drops `_cfg()` (a loop back to its own `_load_config`) and the loop back for `_get_max_concurrent_children`, defined in the same file. - routes, dispatch and continue import their config getters at module top. - `_load_config` is read through `delegate_tool_config._load_config` by the facade, continue, results and process_registry_notifications, so one patch target reaches every reader, as the facade target did before. - cronjob_tools, process_registry_notifications and subagent_lifecycle read these names from their owner; the facade stops importing the names its body never used, so a stale facade patch now fails instead of silently doing nothing. Tests move their patches to the module whose code reads the name. Two worktree tests that patched `_resolve_workspace_hint` on the facade relied on it reaching both the facade's prompt build and child_run's worktree setup, so they now patch both readers. Every delegate_tool* module imports cleanly as the first import in a fresh interpreter.
62 lines
3.2 KiB
Python
62 lines
3.2 KiB
Python
"""Grouping is advertised only when the delivery policy consumes it."""
|
|
|
|
import json
|
|
from dataclasses import fields
|
|
|
|
from tools.delegate_tool import DELEGATE_TASK_SCHEMA, _strip_model_hidden_task_fields
|
|
from tools.delegate_tool_dispatch import _Batch, _units_of
|
|
from tools.delegate_tool_tasks import _normalize_task_list
|
|
from tools.registry import registry
|
|
|
|
|
|
def test_group_schema_tracks_delivery_policy_without_mutating_previous_definitions(monkeypatch):
|
|
from tools import delegate_tool_config
|
|
|
|
original = json.dumps(DELEGATE_TASK_SCHEMA)
|
|
snapshots = []
|
|
for config in ({}, {"independent_completions": True}, {"independent_completions": False}):
|
|
monkeypatch.setattr(delegate_tool_config, "_load_config", lambda: config)
|
|
definition = registry.get_definitions({"delegate_task"})[0]
|
|
enabled = config.get("independent_completions", False)
|
|
task = definition["function"]["parameters"]["properties"]["tasks"]["items"]
|
|
assert ("group" in task["properties"]) == enabled
|
|
# Advertised as a per-task requirement, so the delivery choice is explicit in every call.
|
|
assert task["required"] == (["goal", "group"] if enabled else ["goal"])
|
|
assert ("group" in definition["function"]["description"]) == enabled
|
|
assert json.dumps(registry.get_definitions({"delegate_task"})[0]) == json.dumps(definition)
|
|
for previous, serialized in snapshots:
|
|
assert json.dumps(previous) == serialized
|
|
snapshots.append((definition, json.dumps(definition)))
|
|
assert json.dumps(DELEGATE_TASK_SCHEMA) == original
|
|
|
|
|
|
def test_joined_variant_asks_for_no_delivery_group(monkeypatch):
|
|
# One-shot and inline-gateway sessions join every task in the call, so a group would change nothing there.
|
|
from tools import delegate_tool_config
|
|
from tools.delegate_tool import oneshot_delegate_function
|
|
|
|
monkeypatch.setattr(delegate_tool_config, "_load_config", lambda: {"independent_completions": True})
|
|
joined = oneshot_delegate_function(registry.get_definitions({"delegate_task"})[0]["function"])
|
|
task = joined["parameters"]["properties"]["tasks"]["items"]
|
|
assert "group" not in task["properties"] and task["required"] == ["goal"]
|
|
assert "group" not in joined["description"]
|
|
|
|
|
|
def test_legacy_group_replay_remains_accepted_and_delivery_policy_controls_units(monkeypatch):
|
|
from tools import delegate_tool_config
|
|
|
|
tasks = [{"goal": "Review first module", "group": "join"}, {"goal": "Review second module", "group": "join"}, {"goal": "Review third module"}]
|
|
assert _strip_model_hidden_task_fields(tasks) is tasks
|
|
normalized, error = _normalize_task_list(None, None, tasks, None, "leaf", 3)
|
|
assert error is None and normalized == tasks
|
|
batch = _Batch(**{field.name: None for field in fields(_Batch)})
|
|
batch.children = [(i, task, None) for i, task in enumerate(tasks)]
|
|
for enabled in (False, True):
|
|
monkeypatch.setattr(delegate_tool_config, "_load_config", lambda: {"independent_completions": enabled})
|
|
units = _units_of(batch)
|
|
if enabled:
|
|
assert [[i for i, _, _ in unit.children] for unit in units] == [[0, 1], [2]]
|
|
assert [unit.group for unit in units] == ["join", None]
|
|
else:
|
|
assert units == [batch]
|