|
1 | 1 | """agent_params: turn agent/<layer>.json into the arguments for agents.create/update.""" |
2 | 2 |
|
3 | 3 | import inspect |
| 4 | +import json |
| 5 | +import os |
| 6 | +import subprocess |
4 | 7 |
|
5 | 8 | import pytest |
6 | 9 | from orca.resources.agents.agents import Agents |
7 | 10 |
|
8 | | -from common import Config, ConfigError, agent_params, load_layer |
| 11 | +from common import REPO_ROOT, Config, ConfigError, agent_params, load_layer |
9 | 12 | from policy import effective_policy |
10 | 13 |
|
11 | 14 | MCP_URL = "https://mcp.example.com/mcp/x/o-test/sqlworkspace/ws-1" |
12 | 15 |
|
13 | 16 |
|
14 | 17 | def config(**overrides: str) -> Config: |
15 | | - values = {"ORCA_MODEL": "claude-sonnet-4-6", "SN_MCP_URL": MCP_URL, **overrides} |
| 18 | + values = {"ORCA_MODEL": "claude-sonnet-4-6", "SN_MCP_URL": MCP_URL, "RW_MCP_URL": "http://localhost:8080/mcp", **overrides} |
16 | 19 | return Config(values=values, participant="jane") |
17 | 20 |
|
18 | 21 |
|
@@ -61,6 +64,37 @@ def test_different_layers_carry_different_definition_fingerprints(): |
61 | 64 | assert fingerprint("l3-live-context") == fingerprint("l3-live-context") |
62 | 65 |
|
63 | 66 |
|
| 67 | +@pytest.mark.parametrize("layer", ["l3-live-context", "l4-act"]) |
| 68 | +def test_configured_database_scopes_cloud_agent_and_changes_fingerprint(layer): |
| 69 | + params = agent_params(load_layer(layer), config(SN_SQL_DATABASE='catalog-\"rfu')) |
| 70 | + assert params["system"].startswith('Target SQL database: "catalog-\\\"rfu".') |
| 71 | + assert "never fall back to another database" in params["system"] |
| 72 | + assert params["metadata"]["definition_sha"] != agent_params(load_layer(layer), config())["metadata"]["definition_sha"] |
| 73 | + assert params["metadata"]["definition_sha"] != agent_params(load_layer(layer), config(SN_SQL_DATABASE="other"))["metadata"]["definition_sha"] |
| 74 | + |
| 75 | + |
| 76 | +@pytest.mark.parametrize("layer, stack", [("l1-hello", "cloud"), ("l3-live-context", "local"), ("l4-act", "local")]) |
| 77 | +def test_database_setting_does_not_change_hello_or_local_agents(layer, stack): |
| 78 | + definition = load_layer(layer, stack) |
| 79 | + assert agent_params(definition, config(TUTORIAL_STACK=stack, SN_SQL_DATABASE="catalog-rfu")) == agent_params(definition, config(TUTORIAL_STACK=stack)) |
| 80 | + |
| 81 | + |
| 82 | +@pytest.mark.parametrize("layer", ["l3-live-context", "l4-act"]) |
| 83 | +def test_cli_database_definition_matches_python_without_loading_dotenv(layer): |
| 84 | + # Extract only the pure definition builder; never source lib.sh/env.sh or .env. |
| 85 | + source = (REPO_ROOT / "cli/lib.sh").read_text() |
| 86 | + builder = source[source.index("agent_definition() {"):source.index("\n# Same recipe as the other languages")] |
| 87 | + script = """layer_file() { printf '%s/agent/cloud/%s.json' "$REPO" "$1"; } |
| 88 | +""" + builder + '\nagent_definition "$LAYER"' |
| 89 | + env = {"PATH": os.environ["PATH"], "REPO": str(REPO_ROOT), "LAYER": layer, |
| 90 | + "HELLO_PARTICIPANT": "jane", "ORCA_MODEL": "claude-sonnet-4-6", |
| 91 | + "SN_MCP_URL": MCP_URL, "SN_SQL_DATABASE": 'catalog-\"rfu'} |
| 92 | + result = subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, check=True) |
| 93 | + expected = agent_params(load_layer(layer), config(SN_SQL_DATABASE=env["SN_SQL_DATABASE"])) |
| 94 | + expected.pop("metadata") |
| 95 | + assert json.loads(result.stdout) == expected |
| 96 | + |
| 97 | + |
64 | 98 | @pytest.mark.parametrize( |
65 | 99 | "layer, tool, expected", |
66 | 100 | [ |
|
0 commit comments