test: replace false-green checks with behavioral coverage (#6282)
* test: replace false-green checks with behavioral coverage * test: complete behavior-focused audit coverage
This commit is contained in:
1 parent
c7ab7aa6da
commit
74942bd190
91 files changed
+1891
-1391
No files matched your search
@@ -0,0 +1,41 @@
|
||||
[
|
||||
"agents.defaults.timezone",
|
||||
"agents.defaults.timezone_mode",
|
||||
"agents.defaults.unified_session",
|
||||
"agents.defaults.max_tool_iterations",
|
||||
"agents.defaults.max_concurrent_subagents",
|
||||
"agents.defaults.max_tool_result_chars",
|
||||
"agents.defaults.provider_retry_mode",
|
||||
"agents.defaults.tool_hint_max_length",
|
||||
"agents.defaults.dream.enabled",
|
||||
"gateway.host",
|
||||
"gateway.port",
|
||||
"gateway.restart_mode",
|
||||
"tools.exec.enable",
|
||||
"tools.exec.timeout",
|
||||
"tools.exec.path_prepend",
|
||||
"tools.exec.path_append",
|
||||
"tools.exec.sandbox",
|
||||
"tools.exec.sandbox_ro_binds",
|
||||
"tools.exec.sandbox_rw_binds",
|
||||
"tools.exec.allowed_env_keys",
|
||||
"tools.exec.allow_patterns",
|
||||
"tools.exec.deny_patterns",
|
||||
"tools.file.enable",
|
||||
"tools.my.enable",
|
||||
"tools.my.allow_set",
|
||||
"tools.cli_apps.enable",
|
||||
"tools.cli_apps.install_timeout",
|
||||
"tools.cli_apps.run_timeout",
|
||||
"tools.cli_apps.catalog_ttl_seconds",
|
||||
"tools.restrict_to_workspace",
|
||||
"tools.ssrf_whitelist",
|
||||
"tools.max_session_messages_per_minute",
|
||||
"tools.webui_allow_remote_package_install",
|
||||
"tools.web.enable",
|
||||
"tools.web.proxy",
|
||||
"tools.web.user_agent",
|
||||
"tools.image_generation.save_dir",
|
||||
"api.host",
|
||||
"api.timeout"
|
||||
]
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
|
||||
from nanobot.webui.build import (
|
||||
@@ -88,13 +87,6 @@ def test_shared_notifications_make_existing_bundle_stale(tmp_path: Path) -> None
|
||||
assert status.newest_source == shared
|
||||
|
||||
|
||||
def test_channel_owned_ui_sources_are_included_in_distributions() -> None:
|
||||
project_root = Path(__file__).resolve().parents[2]
|
||||
pyproject = tomllib.loads((project_root / "pyproject.toml").read_text(encoding="utf-8"))
|
||||
|
||||
assert "nanobot/channels/*/webui/**/*" in pyproject["tool"]["hatch"]["build"]["include"]
|
||||
|
||||
|
||||
def test_inspect_webui_bundle_accepts_fresh_dist(tmp_path: Path) -> None:
|
||||
source = tmp_path / "webui"
|
||||
dist = tmp_path / "nanobot" / "web" / "dist"
|
||||
|
||||
@@ -61,7 +61,7 @@ def test_json_presets_reject_invalid_configuration(preset_data: dict, invalid_pa
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["wheel", "sdist"])
|
||||
def test_distributions_bundle_mcp_preset_resource(tmp_path: Path, target: str) -> None:
|
||||
def test_distributions_bundle_webui_and_channel_resources(tmp_path: Path, target: str) -> None:
|
||||
repository = Path(__file__).resolve().parents[2]
|
||||
for name in ("pyproject.toml", "README.md", "LICENSE", "THIRD_PARTY_NOTICES.md"):
|
||||
shutil.copyfile(repository / name, tmp_path / name)
|
||||
@@ -70,8 +70,15 @@ def test_distributions_bundle_mcp_preset_resource(tmp_path: Path, target: str) -
|
||||
(tmp_path / "nanobot/__init__.py").write_text("", encoding="utf-8")
|
||||
(package / "__init__.py").write_text("", encoding="utf-8")
|
||||
resource = "nanobot/webui/mcp_presets.json"
|
||||
expected = (repository / resource).read_bytes()
|
||||
(tmp_path / resource).write_bytes(expected)
|
||||
resources = {
|
||||
resource: (repository / resource).read_bytes(),
|
||||
"nanobot/channels/example/webui/index.tsx": b"export const channel = 'example';\n",
|
||||
"nanobot/channels/example/webui/assets/icon.svg": b'<svg id="channel-icon"/>\n',
|
||||
}
|
||||
for name, content in resources.items():
|
||||
destination = tmp_path / name
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
destination.write_bytes(content)
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", f"import hatchling.build; hatchling.build.build_{target}('dist')"],
|
||||
@@ -85,11 +92,14 @@ def test_distributions_bundle_mcp_preset_resource(tmp_path: Path, target: str) -
|
||||
|
||||
if target == "wheel":
|
||||
with ZipFile(next((tmp_path / "dist").glob("*.whl"))) as wheel:
|
||||
assert wheel.read(resource) == expected
|
||||
for name, content in resources.items():
|
||||
assert wheel.read(name) == content
|
||||
else:
|
||||
with tarfile.open(next((tmp_path / "dist").glob("*.tar.gz"))) as sdist:
|
||||
member = next(name for name in sdist.getnames() if name.endswith(f"/{resource}"))
|
||||
bundled = sdist.extractfile(member)
|
||||
assert bundled is not None
|
||||
with bundled:
|
||||
assert bundled.read() == expected
|
||||
for name, content in resources.items():
|
||||
member = next((member for member in sdist.getnames() if member.endswith(f"/{name}")), None)
|
||||
assert member is not None, f"Missing bundled resource: {name}"
|
||||
bundled = sdist.extractfile(member)
|
||||
assert bundled is not None
|
||||
with bundled:
|
||||
assert bundled.read() == content
|
||||
@@ -237,16 +237,26 @@ def test_webui_session_list_surfaces_pending_recovery_state(tmp_path: Path) -> N
|
||||
|
||||
|
||||
def test_webui_session_index_uses_unique_temp_file(tmp_path: Path) -> None:
|
||||
key = "websocket:unique-index-temp"
|
||||
transcript = tmp_path / "webui" / f"{SessionManager.safe_key(key)}.jsonl"
|
||||
transcript.write_text(
|
||||
'{"event":"user","chat_id":"unique-index-temp","text":"hello"}\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
manager = SessionManager(tmp_path)
|
||||
session = manager.get_or_create("websocket:unique-index-temp")
|
||||
session.add_message("user", "hello")
|
||||
manager.save(session)
|
||||
stale_shared_tmp = manager.sessions_dir / ".webui_session_index.json.tmp"
|
||||
stale_shared_tmp.write_text("stale", encoding="utf-8")
|
||||
stale_bytes = b"pre-existing shared temp\x00\xff"
|
||||
stale_shared_tmp.write_bytes(stale_bytes)
|
||||
|
||||
assert list_webui_sessions(manager)[0]["preview"] == "hello"
|
||||
row, = list_webui_sessions(manager)
|
||||
|
||||
assert stale_shared_tmp.read_text(encoding="utf-8") == "stale"
|
||||
assert row["key"] == key
|
||||
assert row["preview"] == "hello"
|
||||
cache = json.loads((manager.sessions_dir / ".webui_session_index.json").read_text(encoding="utf-8"))
|
||||
cached_row, = cache["sessions"]
|
||||
assert cached_row["key"] == key
|
||||
assert cached_row["preview"] == "hello"
|
||||
assert stale_shared_tmp.read_bytes() == stale_bytes
|
||||
assert not list(manager.sessions_dir.glob(".webui_session_index.json.*.tmp"))
|
||||
|
||||
|
||||
|
||||
@@ -2725,15 +2725,6 @@ def test_create_model_configuration_accepts_azure_openai_aad_mode(
|
||||
assert saved.model_presets["azure-aad"].model == "my-deployment"
|
||||
|
||||
|
||||
def test_azure_openai_spec_no_longer_requires_api_key() -> None:
|
||||
"""Contract guard: api_key is optional for azure_openai (AAD fallback)."""
|
||||
from nanobot.webui.settings_api import _provider_requires_api_key
|
||||
|
||||
spec = find_by_name("azure_openai")
|
||||
assert spec is not None
|
||||
assert _provider_requires_api_key(spec) is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize("protocol", ["chat_completions", "responses", "anthropic_messages"])
|
||||
def test_custom_connection_api_create_edit_and_preset_ceiling(tmp_path, monkeypatch, protocol):
|
||||
config_path = tmp_path / "config.json"
|
||||
|
||||
@@ -649,13 +649,35 @@ async def test_reverting_runtime_switch_clears_restart_but_preserves_other_chang
|
||||
|
||||
async def test_reverting_web_reader_preserves_unrelated_restart_reason(tmp_path):
|
||||
router = _router(config_path=tmp_path / "config.json")
|
||||
original = router.settings.config.load().tools.web.fetch.use_jina_reader
|
||||
config = router.settings.config.load()
|
||||
original_reader = config.tools.web.fetch.use_jina_reader
|
||||
original_timeout = config.api.timeout
|
||||
path = "/api/settings/web-search/update"
|
||||
first = await router.dispatch(None, _mutation_request(path, {"provider": "duckduckgo", "use_jina_reader": not original}), path)
|
||||
first = await router.dispatch(None, _mutation_request(path, {
|
||||
"provider": "duckduckgo", "use_jina_reader": not original_reader,
|
||||
}), path)
|
||||
assert first.status_code == 200
|
||||
assert json.loads(first.body)["restart_required_sections"] == ["browser"]
|
||||
router._restart_sections.add("runtime")
|
||||
restored = await router.dispatch(None, _mutation_request(path, {"provider": "duckduckgo", "use_jina_reader": original}), path)
|
||||
|
||||
runtime_path = "/api/settings/runtime-config/update"
|
||||
changed = await router.dispatch(None, _mutation_request(runtime_path, {
|
||||
"values": {"api.timeout": original_timeout + 1},
|
||||
}), runtime_path)
|
||||
assert changed.status_code == 200
|
||||
assert set(json.loads(changed.body)["restart_required_sections"]) == {"browser", "runtime"}
|
||||
|
||||
restored = await router.dispatch(None, _mutation_request(path, {
|
||||
"provider": "duckduckgo", "use_jina_reader": original_reader,
|
||||
}), path)
|
||||
assert restored.status_code == 200
|
||||
assert json.loads(restored.body)["restart_required_sections"] == ["runtime"]
|
||||
refreshed = await router.dispatch(None, SimpleNamespace(path="/api/settings", headers=Headers()), "/api/settings")
|
||||
assert json.loads(refreshed.body)["restart_required_sections"] == ["runtime"]
|
||||
reverted = await router.dispatch(None, _mutation_request(runtime_path, {
|
||||
"values": {"api.timeout": original_timeout},
|
||||
}), runtime_path)
|
||||
assert reverted.status_code == 200
|
||||
assert json.loads(reverted.body)["restart_required_sections"] == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("enabled", [False, True])
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -11,7 +10,6 @@ from nanobot.config.schema import Config
|
||||
from nanobot.webui.settings_api import update_runtime_config_settings
|
||||
from nanobot.webui.settings_contracts import WebUISettingsError
|
||||
from nanobot.webui.settings_runtime import (
|
||||
RUNTIME_CONFIG_PATHS,
|
||||
runtime_config_payload,
|
||||
update_runtime_config,
|
||||
)
|
||||
@@ -166,13 +164,11 @@ def test_api_changes_require_explicit_restart(tmp_path):
|
||||
assert payload["requires_restart"]
|
||||
|
||||
|
||||
def test_every_exposed_runtime_setting_has_a_frontend_use():
|
||||
fields = Path(__file__).parents[2] / "webui/src/components/settings/system/runtime-config-fields.ts"
|
||||
paths = re.findall(r'group: "[^"]+", path: "([^"]+)"', fields.read_text(encoding="utf-8"))
|
||||
def test_runtime_payload_matches_shared_catalogue_contract():
|
||||
fixture = Path(__file__).with_name("fixtures") / "runtime-config-keys.json"
|
||||
paths = json.loads(fixture.read_text(encoding="utf-8"))
|
||||
assert len(paths) == len(set(paths))
|
||||
# The CLI enable flag controls visibility of its advanced fields, without an editor.
|
||||
visibility_only = {"tools.cli_apps.enable"}
|
||||
assert set(paths) | visibility_only == set(RUNTIME_CONFIG_PATHS)
|
||||
assert set(runtime_config_payload(Config())) == set(paths)
|
||||
|
||||
|
||||
def test_disabling_memory_consolidation_preserves_other_memory_settings():
|
||||
|
||||
Reference in new issue
Block a user