chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
||||
@@ -0,0 +1,94 @@
|
||||
from pathlib import Path
|
||||
|
||||
from webwright.run.doctor import (
|
||||
check_chromium,
|
||||
check_openai_key,
|
||||
check_playwright,
|
||||
check_plugin_manifests,
|
||||
check_python,
|
||||
check_screenshot,
|
||||
)
|
||||
|
||||
|
||||
def test_check_python():
|
||||
ok, message = check_python()
|
||||
|
||||
assert isinstance(ok, bool)
|
||||
assert isinstance(message, str)
|
||||
|
||||
|
||||
def test_check_playwright():
|
||||
ok, message = check_playwright()
|
||||
|
||||
assert isinstance(ok, bool)
|
||||
assert isinstance(message, str)
|
||||
|
||||
|
||||
def test_check_chromium():
|
||||
ok, message = check_chromium()
|
||||
|
||||
assert isinstance(ok, bool)
|
||||
assert isinstance(message, str)
|
||||
|
||||
|
||||
def test_check_screenshot():
|
||||
ok, message = check_screenshot()
|
||||
|
||||
assert isinstance(ok, bool)
|
||||
assert isinstance(message, str)
|
||||
|
||||
|
||||
def test_check_openai_key_exists(monkeypatch):
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "test-key")
|
||||
|
||||
ok, message = check_openai_key()
|
||||
|
||||
assert ok is True
|
||||
assert "found" in message
|
||||
|
||||
|
||||
def test_check_openai_key_missing(monkeypatch):
|
||||
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
|
||||
|
||||
ok, message = check_openai_key()
|
||||
|
||||
assert ok is False
|
||||
assert "missing" in message
|
||||
|
||||
|
||||
def test_plugin_manifests_exist(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
claude_dir = tmp_path / ".claude-plugin"
|
||||
codex_dir = tmp_path / ".codex-plugin"
|
||||
|
||||
claude_dir.mkdir()
|
||||
codex_dir.mkdir()
|
||||
|
||||
(claude_dir / "plugin.json").write_text("{}")
|
||||
(codex_dir / "plugin.json").write_text("{}")
|
||||
|
||||
ok, message = check_plugin_manifests()
|
||||
|
||||
assert ok is True
|
||||
assert "found" in message
|
||||
|
||||
|
||||
def test_plugin_manifests_missing(tmp_path, monkeypatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
ok, message = check_plugin_manifests()
|
||||
|
||||
assert ok is False
|
||||
assert "missing" in message
|
||||
|
||||
|
||||
def test_screenshot_file_cleanup():
|
||||
screenshot_path = Path("doctor_test.png")
|
||||
|
||||
if screenshot_path.exists():
|
||||
screenshot_path.unlink()
|
||||
|
||||
check_screenshot()
|
||||
|
||||
assert not screenshot_path.exists()
|
||||
@@ -0,0 +1,69 @@
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from webwright.config import get_config_from_spec
|
||||
from webwright.tools._model_config import (
|
||||
DEFAULT_MERGED_CONFIG_RELPATH,
|
||||
_extract_model_block,
|
||||
resolve_model_config_path,
|
||||
)
|
||||
from webwright.utils.serialize import recursive_merge
|
||||
|
||||
|
||||
def test_model_claude_sets_top_level_anthropic_model() -> None:
|
||||
config = recursive_merge(
|
||||
get_config_from_spec("base.yaml"),
|
||||
get_config_from_spec("model_claude.yaml"),
|
||||
)
|
||||
|
||||
assert config["model"]["model_class"] == "anthropic"
|
||||
|
||||
|
||||
def test_model_claude_does_not_declare_per_tool_overrides() -> None:
|
||||
config = get_config_from_spec("model_claude.yaml")
|
||||
|
||||
assert "tools" not in config, "model_claude.yaml should rely on the top-level `model:` block"
|
||||
|
||||
|
||||
def test_extract_model_block_reads_top_level_model(tmp_path) -> None:
|
||||
config = {"model": {"model_class": "anthropic", "model_name": "claude-opus-4-7"}}
|
||||
|
||||
assert _extract_model_block(config) == config["model"]
|
||||
|
||||
|
||||
def test_extract_model_block_rejects_missing_block() -> None:
|
||||
with pytest.raises(ValueError, match="missing a top-level"):
|
||||
_extract_model_block({})
|
||||
|
||||
|
||||
def test_resolve_model_config_path_prefers_explicit_arg(tmp_path) -> None:
|
||||
explicit = tmp_path / "explicit.yaml"
|
||||
explicit.write_text("model: {model_class: anthropic, model_name: claude-opus-4-7}\n")
|
||||
|
||||
snapshot_dir = tmp_path / "ws" / DEFAULT_MERGED_CONFIG_RELPATH.parent
|
||||
snapshot_dir.mkdir(parents=True)
|
||||
(snapshot_dir / DEFAULT_MERGED_CONFIG_RELPATH.name).write_text(
|
||||
yaml.safe_dump({"model": {"model_class": "openai"}})
|
||||
)
|
||||
|
||||
resolved = resolve_model_config_path(str(explicit), workspace_dir=str(tmp_path / "ws"))
|
||||
|
||||
assert resolved == explicit.resolve()
|
||||
|
||||
|
||||
def test_resolve_model_config_path_falls_back_to_workspace_snapshot(tmp_path) -> None:
|
||||
workspace = tmp_path / "ws"
|
||||
snapshot_path = workspace / DEFAULT_MERGED_CONFIG_RELPATH
|
||||
snapshot_path.parent.mkdir(parents=True)
|
||||
snapshot_path.write_text(
|
||||
yaml.safe_dump({"model": {"model_class": "anthropic", "model_name": "claude-opus-4-7"}})
|
||||
)
|
||||
|
||||
resolved = resolve_model_config_path("", workspace_dir=str(workspace))
|
||||
|
||||
assert resolved == snapshot_path.resolve()
|
||||
|
||||
|
||||
def test_resolve_model_config_path_raises_when_nothing_found(tmp_path) -> None:
|
||||
with pytest.raises(FileNotFoundError, match="No tool model config found"):
|
||||
resolve_model_config_path("", workspace_dir=str(tmp_path))
|
||||
Reference in New Issue
Block a user