|
| 1 | +import pytest |
| 2 | +from databricks.sql.common.agent import detect, KNOWN_AGENTS |
| 3 | + |
| 4 | + |
| 5 | +class TestAgentDetection: |
| 6 | + def test_detects_single_agent_claude_code(self): |
| 7 | + assert detect({"CLAUDECODE": "1"}) == "claude-code" |
| 8 | + |
| 9 | + def test_detects_single_agent_cursor(self): |
| 10 | + assert detect({"CURSOR_AGENT": "1"}) == "cursor" |
| 11 | + |
| 12 | + def test_detects_single_agent_gemini_cli(self): |
| 13 | + assert detect({"GEMINI_CLI": "1"}) == "gemini-cli" |
| 14 | + |
| 15 | + def test_detects_single_agent_cline(self): |
| 16 | + assert detect({"CLINE_ACTIVE": "1"}) == "cline" |
| 17 | + |
| 18 | + def test_detects_single_agent_codex(self): |
| 19 | + assert detect({"CODEX_CI": "1"}) == "codex" |
| 20 | + |
| 21 | + def test_detects_single_agent_opencode(self): |
| 22 | + assert detect({"OPENCODE": "1"}) == "opencode" |
| 23 | + |
| 24 | + def test_detects_single_agent_antigravity(self): |
| 25 | + assert detect({"ANTIGRAVITY_AGENT": "1"}) == "antigravity" |
| 26 | + |
| 27 | + def test_returns_empty_when_no_agent_detected(self): |
| 28 | + assert detect({}) == "" |
| 29 | + |
| 30 | + def test_returns_empty_when_multiple_agents_detected(self): |
| 31 | + assert detect({"CLAUDECODE": "1", "CURSOR_AGENT": "1"}) == "" |
| 32 | + |
| 33 | + def test_ignores_empty_env_var_values(self): |
| 34 | + assert detect({"CLAUDECODE": ""}) == "" |
| 35 | + |
| 36 | + def test_all_known_agents_are_covered(self): |
| 37 | + for env_var, product in KNOWN_AGENTS: |
| 38 | + assert detect({env_var: "1"}) == product, ( |
| 39 | + f"Agent with env var {env_var} should be detected as {product}" |
| 40 | + ) |
| 41 | + |
| 42 | + def test_defaults_to_os_environ(self, monkeypatch): |
| 43 | + monkeypatch.delenv("CLAUDECODE", raising=False) |
| 44 | + monkeypatch.delenv("CURSOR_AGENT", raising=False) |
| 45 | + monkeypatch.delenv("GEMINI_CLI", raising=False) |
| 46 | + monkeypatch.delenv("CLINE_ACTIVE", raising=False) |
| 47 | + monkeypatch.delenv("CODEX_CI", raising=False) |
| 48 | + monkeypatch.delenv("OPENCODE", raising=False) |
| 49 | + monkeypatch.delenv("ANTIGRAVITY_AGENT", raising=False) |
| 50 | + # With all agent vars cleared, detect() should return empty |
| 51 | + assert detect() == "" |
0 commit comments