ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
@@ -0,0 +1,43 @@
|
||||
import pytest
|
||||
from config import DEFAULT_BASE_URL, DEFAULT_MODEL, ConfigError, resolve_endpoint
|
||||
|
||||
|
||||
def test_openrouter_reference_route() -> None:
|
||||
endpoint = resolve_endpoint({"OPENROUTER_API_KEY": "secret"})
|
||||
|
||||
assert endpoint.api_key == "secret"
|
||||
assert endpoint.api_key_env == "OPENROUTER_API_KEY"
|
||||
assert endpoint.base_url == DEFAULT_BASE_URL
|
||||
assert endpoint.model == DEFAULT_MODEL
|
||||
assert endpoint.public_dict()["requested_model"] == DEFAULT_MODEL
|
||||
assert "secret" not in str(endpoint.public_dict())
|
||||
|
||||
|
||||
def test_generic_endpoint_takes_precedence() -> None:
|
||||
endpoint = resolve_endpoint(
|
||||
{
|
||||
"OPEN_MODEL_API_KEY": "local",
|
||||
"OPENROUTER_API_KEY": "gateway-secret",
|
||||
"OPEN_MODEL_BASE_URL": "http://127.0.0.1:8000/v1/",
|
||||
"OPEN_MODEL_MODEL": "Qwen/Qwen3-VL-32B-Instruct",
|
||||
"OPEN_MODEL_SCHEMA_MODE": "prompt",
|
||||
}
|
||||
)
|
||||
|
||||
assert endpoint.api_key == "local"
|
||||
assert endpoint.api_key_env == "OPEN_MODEL_API_KEY"
|
||||
assert endpoint.base_url == "http://127.0.0.1:8000/v1"
|
||||
assert endpoint.schema_mode == "prompt"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("values", "message"),
|
||||
[
|
||||
({}, "OPEN_MODEL_API_KEY"),
|
||||
({"OPEN_MODEL_API_KEY": "x", "OPEN_MODEL_BASE_URL": "localhost:8000/v1"}, "absolute"),
|
||||
({"OPEN_MODEL_API_KEY": "x", "OPEN_MODEL_SCHEMA_MODE": "xml"}, "native"),
|
||||
],
|
||||
)
|
||||
def test_invalid_configuration_fails_closed(values: dict[str, str], message: str) -> None:
|
||||
with pytest.raises(ConfigError, match=message):
|
||||
resolve_endpoint(values)
|
||||
@@ -0,0 +1,35 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from evidence import retain_step_screenshots, sha256_file, write_json, write_manifest
|
||||
|
||||
|
||||
def test_screenshots_are_copied_and_history_is_rewritten(tmp_path: Path) -> None:
|
||||
temporary_screenshot = tmp_path / "temporary.png"
|
||||
temporary_screenshot.write_bytes(b"not-a-real-png-but-stable")
|
||||
run_dir = tmp_path / "run"
|
||||
history = {"history": [{"state": {"screenshot_path": str(temporary_screenshot)}}]}
|
||||
|
||||
retained, records = retain_step_screenshots(history, run_dir)
|
||||
|
||||
retained_path = run_dir / "screenshots" / "step-001.png"
|
||||
assert retained_path.read_bytes() == temporary_screenshot.read_bytes()
|
||||
assert retained["history"][0]["state"]["screenshot_path"] == "screenshots/step-001.png"
|
||||
assert records[0]["sha256"] == sha256_file(retained_path)
|
||||
assert history["history"][0]["state"]["screenshot_path"] == str(temporary_screenshot)
|
||||
|
||||
|
||||
def test_manifest_hashes_retained_artifacts(tmp_path: Path) -> None:
|
||||
write_json(tmp_path / "summary.json", {"status": "complete"})
|
||||
|
||||
manifest_path = write_manifest(tmp_path, {"experiment": "test", "credential_retained": False})
|
||||
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
||||
|
||||
assert manifest["credential_retained"] is False
|
||||
assert manifest["artifacts"] == [
|
||||
{
|
||||
"path": "summary.json",
|
||||
"bytes": (tmp_path / "summary.json").stat().st_size,
|
||||
"sha256": sha256_file(tmp_path / "summary.json"),
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user