Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
test(model-hub): authenticate migration mock credentials (#2063)
Call Whitea32cd9df9be9
diff --git a/docs/plans/model-hub-e2e-test-plan.md b/docs/plans/model-hub-e2e-test-plan.mdindex 259558fe0..95c1a709b 100644--- a/docs/plans/model-hub-e2e-test-plan.md+++ b/docs/plans/model-hub-e2e-test-plan.md@@ -213,6 +213,20 @@ lane-to-lane.a bare array; extensible envelope), each record carrying method, path,headers subset, parsed body; `DELETE /__control/requests` resets.*(Shape frozen 2026-09-02.)*+- Credential-witness fixture amendment (2026-09-20):+ `required_api_key: <synthetic non-empty string>|null` is opt-in and defaults+ to `null`, preserving the public catalogue behavior. When set, the mock+ requires that exact `x-api-key` for Anthropic or `Authorization: Bearer ...`+ for OpenAI on all data endpoints, before applying the configured `auth`,+ protocol, inventory, or stream behavior. Missing/wrong credentials return+ 401; `/__control/` remains independently accessible. Correct credentials do+ not turn model-less schema errors into successful inference responses.+ F2 migration success explicitly opts into this gate, proving both the+ credentialed catalogue success and unauthenticated refusal over HTTP/IPC.+ Public-catalogue and wrong-key controls must refuse migration and preserve+ every seeded native file and the empty Source list. This is a fixture-only+ contract: production authentication evidence and other suites' defaults+ are unchanged.- The Playwright lane consumes this ONLY over HTTP via env`VIBE_E2E_MOCK_UPSTREAM_URL`; it never imports the Python module. Mock-dependent specs skip with a clear message when the env is absent.diff --git a/tests/e2e/drivers/mock_llm_upstream.py b/tests/e2e/drivers/mock_llm_upstream.pyindex 16e6a720c..359e2b879 100644--- a/tests/e2e/drivers/mock_llm_upstream.py+++ b/tests/e2e/drivers/mock_llm_upstream.py@@ -196,6 +196,7 @@ class MockUpstreamState:self._lock = threading.RLock()self._config: dict[str, Any] = {"auth": "ok",+ "required_api_key": None,"stream": "healthy","models": [copy.deepcopy(model) for model in DEFAULT_MODELS],"protocol": "openai_chat",@@ -213,6 +214,7 @@ class MockUpstreamState:def configure(self, update: Mapping[str, Any]) -> dict[str, Any]:unknown = set(update) - {"auth",+ "required_api_key","stream","models","protocol",@@ -227,6 +229,11 @@ class MockUpstreamState:candidate.update(copy.deepcopy(dict(update)))if candidate["auth"] not in AUTH_BEHAVIORS:raise ConfigurationError("unsupported auth behavior")+ required_key = candidate["required_api_key"]+ if required_key is not None and (+ not isinstance(required_key, str) or not required_key.strip()+ ):+ raise ConfigurationError("required_api_key must be a non-empty string or null")if candidate["stream"] not in STREAM_BEHAVIORS:raise ConfigurationError("unsupported stream behavior")if candidate["protocol"] not in PROTOCOLS:@@ -298,8 +305,7 @@ class MockLLMUpstreamHandler(BaseHTTPRequestHandler):if path == "/v1/models":self._capture(path, None)config = self.state.config()- if config["auth"] != "ok":- self._write_behavior_error(config)+ if not self._authenticate(config):returnif config["models_endpoint"] != "ok":self._write_models_endpoint_failure(@@ -347,8 +353,7 @@ class MockLLMUpstreamHandler(BaseHTTPRequestHandler):self._capture(path, body)config = self.state.config()protocol = config["protocol"]- if config["auth"] != "ok":- self._write_behavior_error(config)+ if not self._authenticate(config):returnif path != PROTOCOL_PATHS[protocol]:self._write_json(@@ -377,6 +382,28 @@ class MockLLMUpstreamHandler(BaseHTTPRequestHandler):_buffered_response(protocol, body),)+ def _authenticate(self, config: Mapping[str, Any]) -> bool:+ """Optional value check for synthetic credentials on data endpoints."""+ required_key = config["required_api_key"]+ if required_key is not None:+ supplied = (+ self.headers.get("x-api-key")+ if config["protocol"] == "anthropic"+ else self.headers.get("authorization")+ )+ expected = (+ required_key+ if config["protocol"] == "anthropic"+ else f"Bearer {required_key}"+ )+ if supplied != expected:+ self._write_behavior_error({**config, "auth": "401"})+ return False+ if config["auth"] != "ok":+ self._write_behavior_error(config)+ return False+ return True+def _configure(self, body: object) -> None:if not isinstance(body, dict):self._write_json(diff --git a/tests/e2e/test_model_hub_migration.py b/tests/e2e/test_model_hub_migration.pyindex 0aa668ee0..b2338bc4f 100644--- a/tests/e2e/test_model_hub_migration.py+++ b/tests/e2e/test_model_hub_migration.py@@ -13,6 +13,8 @@ from tests.e2e.test_model_hub_sources import _configure_protocolpytestmark = pytest.mark.e2e_model_hub+SYNTHETIC_MIGRATION_API_KEY = "sk-ant-e2e-claude-independent-123456"+def _write(path: Path, content: str) -> None:path.parent.mkdir(parents=True, exist_ok=True)@@ -34,7 +36,7 @@ def _seed_native_configs(app, upstream_url: str) -> list[Path]:json.dumps({"env": {- "ANTHROPIC_API_KEY": "sk-ant-e2e-claude-independent-123456",+ "ANTHROPIC_API_KEY": SYNTHETIC_MIGRATION_API_KEY,"ANTHROPIC_BASE_URL": upstream_url,},"permissions": {"allow": ["Read"]},@@ -172,7 +174,7 @@ def test_f2_apply_takes_over_selected_key_and_preserves_blocked_native_material() -> None:"""F2: grouped custody cleans the selected key without touching blockers."""- seeded_api_key = "sk-ant-e2e-claude-independent-123456"+ seeded_api_key = SYNTHETIC_MIGRATION_API_KEYseeded_api_key_digest = hashlib.sha256(seeded_api_key.encode("utf-8")).hexdigest()@@ -181,6 +183,7 @@ def test_f2_apply_takes_over_selected_key_and_preserves_blocked_native_material("anthropic",models=[{"id": "claude-sonnet-4-6"}],)+ mock_llm_upstream.configure(required_api_key=seeded_api_key)launch, seeded_paths = _launch_seeded_app(model_hub_app_factory, mock_llm_upstream)@@ -248,3 +251,50 @@ def test_f2_apply_takes_over_selected_key_and_preserves_blocked_native_material(hashlib.sha256(credential.encode("utf-8")).hexdigest())assert seeded_api_key_digest in captured_digests+ catalogue_headers = [+ request["headers"]+ for request in mock_llm_upstream.requests()+ if request["path"] == "/v1/models"+ ]+ assert any(headers.get("x-api-key") == seeded_api_key for headers in catalogue_headers)+ assert any(+ not headers.get("x-api-key") and not headers.get("authorization")+ for headers in catalogue_headers+ )+++ "required_api_key", [None, "sk-ant-e2e-different-key"],+ ids=["public-catalogue", "rejected-key"],+)+def test_f2_unproven_key_keeps_all_native_material(+ model_hub_app_factory, mock_llm_upstream, required_api_key: str | None,+) -> None:+ """F2: a public catalogue or credential rejection cannot authorize cleanup."""+ _configure_protocol(+ mock_llm_upstream, "anthropic",+ models=[{"id": "claude-sonnet-4-6"}],+ )+ mock_llm_upstream.configure(required_api_key=required_api_key)+ launch, seeded_paths = _launch_seeded_app(+ model_hub_app_factory, mock_llm_upstream,+ )+ with launch as app:+ before = {path: path.read_bytes() for path in seeded_paths}+ scan = app.client.post("/api/models/migration/scan", {})+ assert scan.status == 200, scan.json()+ selected = [+ item for item in scan.json()["scan"]["items"] if item["selected"]+ ]+ assert [(item["backend"], item["kind"]) for item in selected] == [+ ("claude", "api_key")+ ]+ response = app.client.post(+ "/api/models/migration/apply", {"item_ids": [item["id"] for item in selected]},+ )+ assert response.status == 409, response.json()+ assert response.json()["error"] == "migration_item_conflict"+ assert all(path.read_bytes() == before[path] for path in seeded_paths)+ listed = app.client.get("/api/models/sources")+ assert listed.status == 200, listed.json()+ assert listed.json()["sources"] == []diff --git a/tests/e2e/test_model_hub_mock_upstream.py b/tests/e2e/test_model_hub_mock_upstream.pyindex 91c106b8c..bad1cc527 100644--- a/tests/e2e/test_model_hub_mock_upstream.py+++ b/tests/e2e/test_model_hub_mock_upstream.py@@ -706,6 +706,92 @@ def test_mock_upstream_inventory_and_buffered_protocol_shapes(assert payload["usage"][email protected]("protocol", PROTOCOL_CASES)[email protected]("surface", ["models", "buffered", "probe"])[email protected]("credential", [None, "sk-wrong-fixture", "sk-required-fixture"])+def test_mock_upstream_required_api_key_gates_data_surfaces(+ mock_llm_upstream, protocol: str, surface: str, credential: str | None,+) -> None:+ """An authenticated fixture requires the value, not just a header."""+ case = PROTOCOL_CASES[protocol]+ configured = _configure(+ mock_llm_upstream.url, protocol=protocol,+ required_api_key="sk-required-fixture",+ )+ assert configured["required_api_key"] == "sk-required-fixture"+ headers = {}+ if credential is not None:+ headers = (+ {"X-Api-Key": credential}+ if protocol == "anthropic"+ else {"Authorization": f"Bearer {credential}"}+ )+ status, _, payload = _json_request(+ mock_llm_upstream.url,+ "/v1/models" if surface == "models" else case["path"],+ method="GET" if surface == "models" else "POST",+ body=None if surface == "models" else ({} if surface == "probe" else case["body"]),+ headers=headers,+ )+ if credential != "sk-required-fixture":+ assert status == 401+ assert payload["error"]["type"] == "authentication_error"+ elif surface == "probe":+ assert status == 400 # Authenticated schema rejection is not inference.+ assert payload["error"]["type"] == "invalid_request_error"+ else:+ assert status == 200+ if surface == "models":+ assert payload["data"][0]["id"] == "mock-model"+ else:+ assert payload[case["response_key"]] == case["response_value"]++[email protected]("protocol", PROTOCOL_CASES)+def test_mock_upstream_required_key_uses_the_configured_protocol_header(+ mock_llm_upstream, protocol: str,+) -> None:+ """The other family's header cannot satisfy this interface's credential."""+ _configure(+ mock_llm_upstream.url, protocol=protocol,+ required_api_key="sk-required-fixture",+ )+ headers = (+ {"Authorization": "Bearer sk-required-fixture"}+ if protocol == "anthropic"+ else {"X-Api-Key": "sk-required-fixture"}+ )+ status, _, _ = _json_request(+ mock_llm_upstream.url, "/v1/models", headers=headers,+ )+ assert status == 401+ # Control stays reachable and clearing the opt-in restores a public catalogue.+ assert _configure(mock_llm_upstream.url, required_api_key=None)["required_api_key"] is None+ assert _json_request(mock_llm_upstream.url, "/v1/models")[0] == 200++[email protected]("protocol", PROTOCOL_CASES)+ ("behavior", "status"),+ [({"auth": "429"}, 429), ({"models_endpoint": "http_500"}, 500)],+)+def test_mock_upstream_required_key_precedes_configured_failures(+ mock_llm_upstream, protocol: str, behavior: dict[str, str], status: int,+) -> None:+ """A valid credential reaches the existing failure modes unchanged."""+ _configure(+ mock_llm_upstream.url, protocol=protocol,+ required_api_key="sk-required-fixture", **behavior,+ )+ headers = (+ {"X-Api-Key": "sk-required-fixture"}+ if protocol == "anthropic"+ else {"Authorization": "Bearer sk-required-fixture"}+ )+ assert _json_request(mock_llm_upstream.url, "/v1/models")[0] == 401+ assert _json_request(mock_llm_upstream.url, "/v1/models", headers=headers)[0] == status++@pytest.mark.parametrize("protocol", PROTOCOL_CASES)def test_mock_upstream_invalid_probe_evidence_is_family_distinctive(mock_llm_upstream, protocol: str@@ -933,6 +1019,11 @@ def test_mock_upstream_control_validation_capture_envelope_and_reset({"stream": "invalid"},{"protocol": "invalid"},{"models_endpoint": "invalid"},+ {"required_api_key": ""},+ {"required_api_key": " "},+ {"required_api_key": 123},+ {"required_api_key": False},+ {"required_api_key": []},{"models": [""]},{"model_errors": []},{"model_errors": {"": "model_not_found"}},