Files
wehub-resource-sync 0418dc5cf9
CI / Python tests (3.10) (push) Has been cancelled
CI / Python tests (3.11) (push) Has been cancelled
CI / Python quality (push) Has been cancelled
CI / Frontend typecheck (push) Has been cancelled
Autopilot Pages / deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:45:00 +08:00

103 lines
3.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Tests for teammate spawn helper behavior."""
from __future__ import annotations
import sys
from openharness.swarm.spawn_utils import (
TEAMMATE_COMMAND_ENV_VAR,
build_inherited_cli_flags,
build_inherited_env_vars,
get_teammate_command,
)
def test_get_teammate_command_prefers_current_interpreter(monkeypatch):
monkeypatch.delenv(TEAMMATE_COMMAND_ENV_VAR, raising=False)
monkeypatch.setattr(sys, "executable", "/tmp/current-python")
command = get_teammate_command()
assert command == "/tmp/current-python"
def test_build_inherited_env_vars_disables_coordinator_mode(monkeypatch):
monkeypatch.setenv("CLAUDE_CODE_COORDINATOR_MODE", "1")
env = build_inherited_env_vars()
assert env["CLAUDE_CODE_COORDINATOR_MODE"] == "0"
def test_build_inherited_env_vars_forwards_openharness_config_dir(monkeypatch):
monkeypatch.setenv("OPENHARNESS_CONFIG_DIR", "/opt/data/.openharness")
env = build_inherited_env_vars()
assert env["OPENHARNESS_CONFIG_DIR"] == "/opt/data/.openharness"
def test_build_inherited_env_vars_includes_openharness_auth_vars(monkeypatch):
monkeypatch.setenv("OPENHARNESS_PROVIDER", "openai")
monkeypatch.setenv("OPENHARNESS_BASE_URL", "https://relay.example.com/v1")
monkeypatch.setenv("OPENHARNESS_OPENAI_API_KEY", "sk-oh-openai")
monkeypatch.setenv("OPENHARNESS_ANTHROPIC_API_KEY", "sk-oh-anthropic")
env = build_inherited_env_vars()
assert env["OPENHARNESS_AGENT_TEAMS"] == "1"
assert env["OPENHARNESS_PROVIDER"] == "openai"
assert env["OPENHARNESS_BASE_URL"] == "https://relay.example.com/v1"
assert env["OPENHARNESS_OPENAI_API_KEY"] == "sk-oh-openai"
assert env["OPENHARNESS_ANTHROPIC_API_KEY"] == "sk-oh-anthropic"
# ---------------------------------------------------------------------------
# build_inherited_cli_flags model handling
# ---------------------------------------------------------------------------
def test_build_inherited_cli_flags_explicit_model_included():
flags = build_inherited_cli_flags(model="claude-opus-4-5")
assert "--model" in flags
idx = flags.index("--model")
assert "claude-opus-4-5" in flags[idx + 1]
def test_build_inherited_cli_flags_inherit_model_excluded():
"""model='inherit' must NOT produce a --model flag so the subprocess
picks up the parent's model from the OPENHARNESS_MODEL env var."""
flags = build_inherited_cli_flags(model="inherit")
assert "--model" not in flags
def test_build_inherited_cli_flags_none_model_excluded():
flags = build_inherited_cli_flags(model=None)
assert "--model" not in flags
def test_build_inherited_cli_flags_empty_string_model_excluded():
flags = build_inherited_cli_flags(model="")
assert "--model" not in flags
def test_build_inherited_cli_flags_forwards_system_prompt_as_replace():
flags = build_inherited_cli_flags(system_prompt="You are a specialized worker.")
assert "--system-prompt" in flags
idx = flags.index("--system-prompt")
assert "specialized worker" in flags[idx + 1]
assert "--append-system-prompt" not in flags
def test_build_inherited_cli_flags_forwards_system_prompt_as_append():
flags = build_inherited_cli_flags(
system_prompt="Extra worker instructions.",
system_prompt_mode="append",
)
assert "--append-system-prompt" in flags
idx = flags.index("--append-system-prompt")
assert "Extra worker instructions." in flags[idx + 1]
assert "--system-prompt" not in flags