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
build(model-hub): adopt CPA v8.0.23 with Windows targets and a loopback OAuth forwarder (#2466)
Call Whiteed24c33fff4d
diff --git a/.github/workflows/model-hub-engine-release-guard.yml b/.github/workflows/model-hub-engine-release-guard.ymlindex eca79dfdc..0f048ee16 100644--- a/.github/workflows/model-hub-engine-release-guard.yml+++ b/.github/workflows/model-hub-engine-release-guard.yml@@ -5,7 +5,7 @@ on:branches: [master]paths:- "vibe/model_hub_runtime/cliproxyapi_manifest.json"- - "patches/model-hub-cpa-v7.3.16/**"+ - "patches/model-hub-cpa-*/**"- "scripts/build_model_hub_engine.py"- "scripts/model_hub_engine_release_guard.py"- ".github/workflows/model-hub-engine-release-guard.yml"@@ -34,7 +34,7 @@ jobs:- uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6with:- go-version: "1.26.0"+ go-version: "1.26.9"- name: Build and verify patched source assetsrun: |diff --git a/docs/plans/model-hub-contracts/runtime-dependency.schema.json b/docs/plans/model-hub-contracts/runtime-dependency.schema.jsonindex 70ddc128c..6b5e1c43d 100644--- a/docs/plans/model-hub-contracts/runtime-dependency.schema.json+++ b/docs/plans/model-hub-contracts/runtime-dependency.schema.json@@ -57,7 +57,7 @@"required": ["platform", "url", "size_bytes", "sha256"],"additionalProperties": false,"properties": {- "platform": { "enum": ["darwin-arm64", "darwin-x64", "linux-amd64", "linux-arm64"] },+ "platform": { "enum": ["darwin-arm64", "darwin-x64", "linux-amd64", "linux-arm64", "windows-amd64", "windows-arm64"] },"url": { "type": "string" },"size_bytes": { "type": "integer" },"sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }diff --git a/docs/plans/model-hub-cpa-dependency.md b/docs/plans/model-hub-cpa-dependency.mdindex 27d6ef3bd..76899d03f 100644--- a/docs/plans/model-hub-cpa-dependency.md+++ b/docs/plans/model-hub-cpa-dependency.md@@ -64,11 +64,14 @@ SHA-256, and extracted binary SHA-256. The verified upstream bytes are publishedpublication. A scheduled guard verifies that release and preserves amanifest-keyed backup that can restore missing assets without overwriting amismatched asset. For this change,-the reviewed target is Avibe-owned CLIProxyAPI `v7.3.16` at source commit-`c404af96ebacedf8168b3c2bdbf4449a21cd1c1e`. The release assets are built-from that exact upstream source with the compatibility patch recorded in-`patches/model-hub-cpa-v7.3.16/`; the packaged manifest records the resulting-archive and binary digests.+the reviewed target is Avibe-owned CLIProxyAPI `v8.0.23` at source commit+`d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5`, built with Go 1.26.9 for+darwin-arm64, darwin-x64, linux-amd64, linux-arm64, windows-amd64 and+windows-arm64. The release assets are built from that exact upstream source+with the patches in `patches/model-hub-cpa-v8.0.23/`, applied in the order the+manifest's `build.patches` records; the packaged manifest records the resulting+archive and binary digests. Rolling back means reverting the whole adoption+change, which restores the previous patch directory and manifest together.## Acceptance Criteriadiff --git a/patches/model-hub-cpa-v7.3.16/README.md b/patches/model-hub-cpa-v7.3.16/README.mddeleted file mode 100644index 6ab8d4a15..000000000--- a/patches/model-hub-cpa-v7.3.16/README.md+++ /dev/null@@ -1,45 +0,0 @@-# Avibe-owned CPA v7.3.16 compatibility patch--This directory records the small source patch carried by Avibe's-`model-hub-engine-v7.3.16-3` build.--Base:--- Repository: `router-for-me/CLIProxyAPI`-- Release: `v7.3.16`-- Source commit: `c404af96ebacedf8168b3c2bdbf4449a21cd1c1e`--## Contract--Avibe owns the OpenAI-compatible Source boundary. When an incoming Chat-request contains `max_completion_tokens`, or `max_tokens`, the engine must-preserve that caller-selected field unless Avibe explicitly selects the-`use-max-completion-tokens` compatibility mode for a model. The stock-v7.3.16 default rewrites the former field to the latter, which breaks-upstreams that accept only the native field.--The patch therefore makes the stock `false` path a preservation path. The-existing explicit `true` path still canonicalizes to-`max_completion_tokens`. Avibe does not set the option today, so both-buffered and streaming requests retain their native token-limit field.--The patch is intentionally limited to the helper used by both OpenAI Chat-execution paths. Claude filename migration is handled in Avibe's credential-state layer and is not encoded in the CPA binary.--## Rebuild--The repository-owned release path checks out `source_sha`, applies this patch,-builds all four supported targets with `CGO_ENABLED=0`, packages deterministic-archives, and verifies the generated bytes against the checked-in manifest-before publication:--```sh-python3 scripts/model_hub_engine_release_guard.py fetch-source \- --output-dir /tmp/model-hub-engine-patched-```--The same command is available from the manual Model Hub release-guard-workflow. Its uploaded artifact is the source-built publication input; the-runtime manifest is updated only after the generated bytes and release assets-have been reviewed.diff --git a/patches/model-hub-cpa-v8.0.23/README.md b/patches/model-hub-cpa-v8.0.23/README.mdnew file mode 100644index 000000000..5b9db60a2--- /dev/null+++ b/patches/model-hub-cpa-v8.0.23/README.md@@ -0,0 +1,98 @@+# Avibe-owned CPA v8.0.23 compatibility patches++This directory records the source patches carried by Avibe's+`model-hub-engine-v8.0.23-1` build. Each patch applies independently to the+pinned source; the build applies them in the order the manifest's+`build.patches` records.++Base:++- Repository: `router-for-me/CLIProxyAPI`+- Release: `v8.0.23`+- Source commit: `d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5`++## `openai-compat-native-token-field.patch`++Avibe owns the OpenAI-compatible Source boundary. When an incoming Chat+request contains `max_completion_tokens`, or `max_tokens`, the engine must+preserve that caller-selected field unless Avibe explicitly selects the+`use-max-completion-tokens` compatibility mode for a model. The stock+default rewrites the former field to the latter, which breaks upstreams that+accept only the native field.++The patch therefore makes the stock `false` path a preservation path. The+existing explicit `true` path still canonicalizes to+`max_completion_tokens`. Avibe does not set the option today, so both+buffered and streaming requests retain their native token-limit field.++The patch is limited to the helper used by both OpenAI Chat execution paths+(`openai_compat_executor.go`, buffered and streaming). The helper is+byte-identical between v8.0.20 and v8.0.23 and differs from v7.3.16 only in+its module import path, outside the patched hunk.++## `oauth-callback-forwarder-loopback.patch`++Avibe starts every redirect-based subscription login (Claude, Codex,+Antigravity) with `is_webui=true`. The engine then starts a callback forwarder+on the vendor's fixed redirect port (54545, 1455 or 51121) that relays the+browser's redirect to the management callback. Stock CPA binds that forwarder+on `0.0.0.0` and aborts the login with a 500 when the bind fails.++The patch binds the forwarder on `127.0.0.1` only, because the redirect always+comes from a browser on the same machine. A wildcard bind exposed the port to+the network and, on Windows, raised a Defender Firewall prompt for the engine.+A failed bind (the port is in use, or reserved by Hyper-V, WSL or Docker) is+logged and no longer aborts the login: Avibe's Web UI still accepts the pasted+callback URL, which reaches the same session through `POST /oauth-callback`.++A container deployment that publishes the callback ports to reach a browser+outside the container loses the automatic callback, since the forwarder no+longer listens on the container's external interface. The pasted callback URL+completes the login there.++Go's wildcard listen is dual-stack, so the stock forwarder also accepted+`[::1]`; the patched one accepts 127.0.0.1 only. The vendors' redirect URIs+name `localhost`, and a browser that tries `::1` first is refused at once and+falls back to 127.0.0.1, as mainstream browsers do. Where one does not, the+pasted callback URL still completes the login. Revisit this if anyone reports+a refused connection to `localhost` at the OAuth callback.++## `antigravity-static-catalog-until-probe.patch`++Avibe ships Gemini subscriptions through Antigravity OAuth grants and routes+to them as soon as the engine has loaded a grant: right after every engine+start and right after a new login. Since v8.0.14 the stock engine registers no+Antigravity models until its per-account entitlement probe+(`/v1internal:fetchAvailableModels`) answers. Until then a request gets+`model_not_found` and model discovery sees an empty catalog; when the probe+fails, the account stays unroutable until a backed-off retry succeeds+(1-2 minutes at first, up to 30 minutes).++The patch registers the static Antigravity catalog while no entitlement hints+are cached. The probe that registration already queues narrows the catalog+through the fenced `ReplaceClientModels` when it answers; a failed probe leaves+the static catalog in place. This is the pre-v8.0.14 startup behavior plus+the later narrowing. The patch also rewrites upstream's+`TestAntigravityModelRegistration_AsyncNonBlocking`, which asserted the stock+behavior, to assert this contract: the static catalog is registered before the+probe answers, then narrowed to the entitled set. With both patches applied,+`go test -run Antigravity ./sdk/cliproxy/` passes.++Drop the patch once router-for-me/CLIProxyAPI#6531 is fixed upstream.++## Rebuild++The repository-owned release path checks out `source_sha`, applies the+recorded patches, builds every supported target with `CGO_ENABLED=0`,+packages deterministic archives, and verifies the generated bytes against the+checked-in manifest before publication:++```sh+python3 scripts/model_hub_engine_release_guard.py fetch-source \+ --output-dir /tmp/model-hub-engine-patched+```++The same command is available from the manual Model Hub release-guard+workflow. Its uploaded artifact is the source-built publication input; the+runtime manifest is updated only after the generated bytes and release assets+have been reviewed.diff --git a/patches/model-hub-cpa-v8.0.23/antigravity-static-catalog-until-probe.patch b/patches/model-hub-cpa-v8.0.23/antigravity-static-catalog-until-probe.patchnew file mode 100644index 000000000..ff82f0e88--- /dev/null+++ b/patches/model-hub-cpa-v8.0.23/antigravity-static-catalog-until-probe.patch@@ -0,0 +1,79 @@+diff --git a/sdk/cliproxy/antigravity_models_timeout_test.go b/sdk/cliproxy/antigravity_models_timeout_test.go+index fe25493e..8d3edee9 100644+--- a/sdk/cliproxy/antigravity_models_timeout_test.go++++ b/sdk/cliproxy/antigravity_models_timeout_test.go+@@ -10,6 +10,7 @@ import (+ "testing"+ "time"+++ "github.com/router-for-me/CLIProxyAPI/v8/internal/registry"+ coreauth "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/auth"+ cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/executor"+ "github.com/router-for-me/CLIProxyAPI/v8/sdk/config"+@@ -59,14 +60,22 @@ func TestAntigravityCapabilityProbe_UsesFirstConfiguredEndpoint(t *testing.T) {+ }++ // TestAntigravityModelRegistration_AsyncNonBlocking verifies that registerModelsForAuth+-// returns immediately without exposing unverified models and does not block on the probe.++// returns immediately, registers the static catalog while the probe is pending, and++// lets the probe narrow it once it answers (Avibe patch; router-for-me/CLIProxyAPI#6531).+ func TestAntigravityModelRegistration_AsyncNonBlocking(t *testing.T) {++ static := registry.GetAntigravityModels()++ if len(static) < 2 {++ t.Fatalf("static Antigravity catalog has %d models, want at least 2", len(static))++ }++ entitled := static[0].ID++ release := make(chan struct{})+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ select {+ case <-r.Context().Done():+ return+- case <-time.After(10 * time.Second):++ case <-release:+ }++ _, _ = w.Write([]byte(`{"models":{"` + entitled + `":{}}}`))+ }))+ t.Cleanup(func() {+ server.CloseClientConnections()+@@ -101,9 +110,21 @@ func TestAntigravityModelRegistration_AsyncNonBlocking(t *testing.T) {+ t.Fatalf("registerModelsForAuth took %v, want non-blocking < 500ms", elapsed)+ }++- models := GlobalModelRegistry().GetModelsForClient(auth.ID)+- if len(models) != 0 {+- t.Fatal("unverified models registered before probe completed")++ if got := len(GlobalModelRegistry().GetModelsForClient(auth.ID)); got != len(static) {++ t.Fatalf("registered %d models before the probe answered, want the static %d", got, len(static))++ }++++ close(release)++ deadline := time.Now().Add(5 * time.Second)++ for {++ models := GlobalModelRegistry().GetModelsForClient(auth.ID)++ if len(models) == 1 && models[0].ID == entitled {++ return++ }++ if time.Now().After(deadline) {++ t.Fatalf("probe did not narrow the static catalog: %d models registered", len(models))++ }++ time.Sleep(20 * time.Millisecond)+ }+ }++diff --git a/sdk/cliproxy/service_models.go b/sdk/cliproxy/service_models.go+index a444b64c..2ea086ef 100644+--- a/sdk/cliproxy/service_models.go++++ b/sdk/cliproxy/service_models.go+@@ -123,6 +123,12 @@ func (s *Service) registerModelsForAuthWithCache(ctx context.Context, a *coreaut+ s.asyncProbeAntigravityCapabilities(ctx, a, provider)+ return+ }++ // Avibe: until this account's entitlement probe has answered, register++ // the static catalog so a fresh engine routes the account at once. The++ // probe queued after registration below narrows it through the fenced++ // ReplaceClientModels; a failed probe leaves the static list in place.++ // Drop once router-for-me/CLIProxyAPI#6531 is fixed upstream.++ models = registry.GetAntigravityModels()+ } else {+ models = registry.GetAntigravityModels()+ }diff --git a/patches/model-hub-cpa-v8.0.23/oauth-callback-forwarder-loopback.patch b/patches/model-hub-cpa-v8.0.23/oauth-callback-forwarder-loopback.patchnew file mode 100644index 000000000..9a05ce3f0--- /dev/null+++ b/patches/model-hub-cpa-v8.0.23/oauth-callback-forwarder-loopback.patch@@ -0,0 +1,59 @@+diff --git a/internal/api/handlers/management/auth_files_oauth_callback.go b/internal/api/handlers/management/auth_files_oauth_callback.go+index f33f82e..b1cefdf 100644+--- a/internal/api/handlers/management/auth_files_oauth_callback.go++++ b/internal/api/handlers/management/auth_files_oauth_callback.go+@@ -50,7 +50,10 @@ func startCallbackForwarder(port int, provider, targetBase string) (*callbackFor+ stopForwarderInstance(port, prev)+ }++- addr := fmt.Sprintf("0.0.0.0:%d", port)++ // Avibe: the forwarder only relays the vendor redirect from this machine's++ // browser, so it listens on loopback alone. A wildcard bind exposes the++ // port to the network and raises a firewall prompt on Windows.++ addr := fmt.Sprintf("127.0.0.1:%d", port)+ ln, err := net.Listen("tcp", addr)+ if err != nil {+ return nil, fmt.Errorf("failed to listen on %s: %w", addr, err)+diff --git a/internal/api/handlers/management/auth_files_provider_oauth.go b/internal/api/handlers/management/auth_files_provider_oauth.go+index 48fc4ef..cac8253 100644+--- a/internal/api/handlers/management/auth_files_provider_oauth.go++++ b/internal/api/handlers/management/auth_files_provider_oauth.go+@@ -80,9 +80,9 @@ func (h *Handler) RequestAnthropicToken(c *gin.Context) {+ }+ var errStart error+ if forwarder, errStart = startCallbackForwarder(anthropicCallbackPort, "anthropic", targetURL); errStart != nil {+- log.WithError(errStart).Error("failed to start anthropic callback forwarder")+- c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to start callback server"})+- return++ // Avibe: an occupied or reserved port must not abort the login. The++ // callback URL can still be submitted through /oauth-callback.++ log.WithError(errStart).Warn("anthropic callback forwarder unavailable; waiting for a submitted callback")+ }+ }++@@ -241,9 +241,9 @@ func (h *Handler) RequestCodexToken(c *gin.Context) {+ }+ var errStart error+ if forwarder, errStart = startCallbackForwarder(codexCallbackPort, "codex", targetURL); errStart != nil {+- log.WithError(errStart).Error("failed to start codex callback forwarder")+- c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to start callback server"})+- return++ // Avibe: an occupied or reserved port must not abort the login. The++ // callback URL can still be submitted through /oauth-callback.++ log.WithError(errStart).Warn("codex callback forwarder unavailable; waiting for a submitted callback")+ }+ }++@@ -387,9 +387,9 @@ func (h *Handler) RequestAntigravityToken(c *gin.Context) {+ }+ var errStart error+ if forwarder, errStart = startCallbackForwarder(antigravity.CallbackPort, "antigravity", targetURL); errStart != nil {+- log.WithError(errStart).Error("failed to start antigravity callback forwarder")+- c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to start callback server"})+- return++ // Avibe: an occupied or reserved port must not abort the login. The++ // callback URL can still be submitted through /oauth-callback.++ log.WithError(errStart).Warn("antigravity callback forwarder unavailable; waiting for a submitted callback")+ }+ }+diff --git a/patches/model-hub-cpa-v7.3.16/openai-compat-native-token-field.patch b/patches/model-hub-cpa-v8.0.23/openai-compat-native-token-field.patchsimilarity index 96%rename from patches/model-hub-cpa-v7.3.16/openai-compat-native-token-field.patchrename to patches/model-hub-cpa-v8.0.23/openai-compat-native-token-field.patchindex 229abda3c..fedf3bd2c 100644--- a/patches/model-hub-cpa-v7.3.16/openai-compat-native-token-field.patch+++ b/patches/model-hub-cpa-v8.0.23/openai-compat-native-token-field.patch@@ -1,5 +1,5 @@diff --git a/internal/runtime/executor/helps/openai_compat_max_tokens.go b/internal/runtime/executor/helps/openai_compat_max_tokens.go-index bceddd20..5ba754b0 100644+index 71915c5b..9819da97 100644--- a/internal/runtime/executor/helps/openai_compat_max_tokens.go+++ b/internal/runtime/executor/helps/openai_compat_max_tokens.go@@ -55,6 +55,13 @@ func NormalizeOpenAIMaxTokens(payload []byte, useMaxCompletionTokens bool) []bytediff --git a/scripts/build_model_hub_engine.py b/scripts/build_model_hub_engine.pyindex 38a9f876d..08d6df1ac 100644--- a/scripts/build_model_hub_engine.py+++ b/scripts/build_model_hub_engine.py@@ -27,8 +27,10 @@ TARGETS = {"darwin-x64": ("darwin", "amd64", "darwin_amd64"),"linux-amd64": ("linux", "amd64", "linux_amd64"),"linux-arm64": ("linux", "arm64", "linux_aarch64"),+ "windows-amd64": ("windows", "amd64", "windows_amd64"),+ "windows-arm64": ("windows", "arm64", "windows_aarch64"),}-ARCHIVE_MEMBERS = ("cli-proxy-api", "LICENSE", "README.md", "README_CN.md", "config.example.yaml")+DOCUMENT_MEMBERS = ("LICENSE", "README.md", "README_CN.md", "config.example.yaml")class BuildError(RuntimeError):@@ -112,18 +114,51 @@ def _checkout_source(raise BuildError(f"source checkout resolved {actual}, expected {source_sha}")+def _binary_name(platform: str) -> str:+ return "cli-proxy-api.exe" if TARGETS[platform][0] == "windows" else "cli-proxy-api"+++def _pinned_patches(build_metadata: Mapping[str, Any]) -> list[Path]:+ """Return the manifest's patches in apply order, each checked against its digest."""++ recorded = build_metadata.get("patches")+ if not isinstance(recorded, list) or not recorded:+ raise BuildError("Model Hub manifest compatibility patch identity is invalid")+ patches: list[Path] = []+ for item in recorded:+ path = item.get("path") if isinstance(item, dict) else None+ digest = item.get("sha256") if isinstance(item, dict) else None+ if (+ not isinstance(path, str)+ or not path+ or Path(path).is_absolute()+ or ".." in Path(path).parts+ or not isinstance(digest, str)+ or re.fullmatch(r"[0-9a-f]{64}", digest) is None+ ):+ raise BuildError("Model Hub manifest compatibility patch identity is invalid")+ patch_path = REPO_ROOT / path+ if not patch_path.is_file() or patch_path.is_symlink():+ raise BuildError(f"Model Hub compatibility patch is missing or unsafe: {path}")+ if _sha256(patch_path) != digest:+ raise BuildError(f"Model Hub compatibility patch checksum differs from pinned manifest: {path}")+ patches.append(patch_path.resolve())+ if len(set(patches)) != len(patches):+ raise BuildError("Model Hub manifest lists a compatibility patch twice")+ return patches++def _prepare_source(source_root: Path,*,repository: str,source_sha: str,- patch_path: Path,+ patches: Sequence[Path],) -> Path:checkout = source_root / "source"_checkout_source(checkout, repository=repository, source_sha=source_sha)- if not patch_path.is_file() or patch_path.is_symlink():- raise BuildError("Model Hub compatibility patch is missing or unsafe")- _run(["git", "apply", "--whitespace=error", str(patch_path)], cwd=checkout)+ for patch_path in patches:+ _run(["git", "apply", "--whitespace=error", str(patch_path)], cwd=checkout)return checkout@@ -131,20 +166,21 @@ def _archive(source: Path,destination: Path,*,+ binary_name: str,source_date_epoch: int,) -> None:destination.parent.mkdir(parents=True, exist_ok=True)with destination.open("wb") as raw:with gzip.GzipFile(fileobj=raw, mode="wb", filename="", mtime=0) as compressed:with tarfile.open(fileobj=compressed, mode="w", format=tarfile.USTAR_FORMAT) as bundle:- for member_name in ARCHIVE_MEMBERS:+ for member_name in (binary_name, *DOCUMENT_MEMBERS):path = source / member_nameif not path.is_file() or path.is_symlink():raise BuildError(f"source build is missing a safe archive member: {member_name}")data = path.read_bytes()member = tarfile.TarInfo(member_name)member.size = len(data)- member.mode = 0o755 if member_name == "cli-proxy-api" else 0o644+ member.mode = 0o755 if member_name == binary_name else 0o644member.mtime = source_date_epochmember.uid = 0member.gid = 0@@ -158,7 +194,7 @@ def _asset_name(version: str, platform: str) -> str:def _native_target() -> str | None:- goos = {"Darwin": "darwin", "Linux": "linux"}.get(platform.system())+ goos = {"Darwin": "darwin", "Linux": "linux", "Windows": "windows"}.get(platform.system())goarch = {"aarch64": "arm64","amd64": "amd64",@@ -207,7 +243,6 @@ def build_source_release(output_dir: Path,*,source_repository: str = DEFAULT_SOURCE_REPOSITORY,- patch_path: Path | None = None,go_binary: str = "go",) -> Path:"""Build all pinned targets and return the checked-in manifest path."""@@ -223,22 +258,7 @@ def build_source_release(build_metadata = payload.get("build")if not isinstance(build_metadata, dict):build_metadata = {}- recorded_patch = build_metadata.get("patch")- patch_digest = build_metadata.get("patch_sha256")- if (- not isinstance(recorded_patch, str)- or not recorded_patch- or Path(recorded_patch).is_absolute()- or ".." in Path(recorded_patch).parts- or not isinstance(patch_digest, str)- or re.fullmatch(r"[0-9a-f]{64}", patch_digest) is None- ):- raise BuildError("Model Hub manifest compatibility patch identity is invalid")- patch_path = patch_path if patch_path is not None else REPO_ROOT / recorded_patch- if not patch_path.is_file() or patch_path.is_symlink():- raise BuildError("Model Hub compatibility patch is missing or unsafe")- if _sha256(patch_path) != patch_digest:- raise BuildError("Model Hub compatibility patch checksum differs from pinned manifest")+ patches = _pinned_patches(build_metadata)source_date_epoch = build_metadata.get("source_date_epoch", 0)if isinstance(source_date_epoch, bool) or not isinstance(source_date_epoch, int) or source_date_epoch < 0:raise BuildError("Model Hub build source_date_epoch is invalid")@@ -248,7 +268,7 @@ def build_source_release(Path(temporary),repository=source_repository,source_sha=str(payload["source_sha"]),- patch_path=patch_path.resolve(),+ patches=patches,)go_version = _go_toolchain_version(_run([go_binary, "version"], cwd=checkout))pinned_go_version = build_metadata.get("go_version")@@ -262,7 +282,7 @@ def build_source_release(goos, goarch, _asset_arch = TARGETS[platform]build_dir = Path(temporary) / "artifacts" / platformbuild_dir.mkdir(parents=True)- binary = build_dir / "cli-proxy-api"+ binary = build_dir / _binary_name(platform)environment = os.environ.copy()environment.update({@@ -293,11 +313,16 @@ def build_source_release(target=platform,checkout=checkout,)- for member_name in ARCHIVE_MEMBERS[1:]:+ for member_name in DOCUMENT_MEMBERS:shutil.copy2(checkout / member_name, build_dir / member_name)archive_name = _asset_name(str(payload["version"]), platform)archive_path = output_dir / archive_name- _archive(build_dir, archive_path, source_date_epoch=source_date_epoch)+ _archive(+ build_dir,+ archive_path,+ binary_name=binary.name,+ source_date_epoch=source_date_epoch,+ )generated_assets.append({"platform": platform,@@ -309,7 +334,7 @@ def build_source_release("size_bytes": archive_path.stat().st_size,"sha256": _sha256(archive_path),"binary_sha256": _sha256(binary),- "bin_path": "cli-proxy-api",+ "bin_path": binary.name,})(output_dir / f"{archive_name}.sha256").write_text(@@ -339,10 +364,6 @@ def build_source_release(def _build_parser() -> argparse.ArgumentParser:parser = argparse.ArgumentParser(description=__doc__)parser.add_argument("--manifest", type=Path, default=DEFAULT_MANIFEST)- parser.add_argument(- "--patch", type=Path,- help="Use a local copy of the manifest-pinned patch (checksum must match).",- )parser.add_argument("--source-repository", default=DEFAULT_SOURCE_REPOSITORY)parser.add_argument("--go", default="go", dest="go_binary")parser.add_argument("output_dir", type=Path)@@ -356,7 +377,6 @@ def main(argv: list[str] | None = None) -> int:args.manifest,args.output_dir,source_repository=args.source_repository,- patch_path=args.patch,go_binary=args.go_binary,)except BuildError as exc:diff --git a/scripts/model_hub_engine_release_guard.py b/scripts/model_hub_engine_release_guard.pyindex 94f128f89..15c469074 100755--- a/scripts/model_hub_engine_release_guard.py+++ b/scripts/model_hub_engine_release_guard.py@@ -21,15 +21,23 @@ from pathlib import PathREPO_ROOT = Path(__file__).resolve().parents[1]DEFAULT_MANIFEST = REPO_ROOT / "vibe" / "model_hub_runtime" / "cliproxyapi_manifest.json"OWNED_RELEASE_ROOT = "https://github.com/avibe-bot/avibe/releases/download"-UPSTREAM_RELEASE_ROOT = "https://github.com/router-for-me/CLIProxyAPI/releases/download"EXPECTED_PLATFORMS = frozenset(- {"darwin-arm64", "darwin-x64", "linux-amd64", "linux-arm64"}+ {+ "darwin-arm64",+ "darwin-x64",+ "linux-amd64",+ "linux-arm64",+ "windows-amd64",+ "windows-arm64",+ })UPSTREAM_PLATFORM_NAMES = {"darwin-arm64": "darwin_aarch64","darwin-x64": "darwin_amd64","linux-amd64": "linux_amd64","linux-arm64": "linux_aarch64",+ "windows-amd64": "windows_amd64",+ "windows-arm64": "windows_aarch64",}ASSET_TAG_RE = re.compile(r"model-hub-engine-v[0-9]+\.[0-9]+\.[0-9]+-[1-9][0-9]*"@@ -49,7 +57,6 @@ class ArchiveSpec:platform: strname: strowned_url: str- upstream_url: strsize: intsha256: strbinary_sha256: str@@ -118,7 +125,6 @@ def load_release_spec(manifest_path: Path) -> ReleaseSpec:raise ReleaseGuardError("Model Hub engine source URL is invalid")owned_release_url = f"{OWNED_RELEASE_ROOT}/{asset_release_tag}"- upstream_release_url = f"{UPSTREAM_RELEASE_ROOT}/{upstream_release_tag}"raw_assets = payload.get("assets")if not isinstance(raw_assets, list):raise ReleaseGuardError("Model Hub engine manifest assets must be a list")@@ -151,7 +157,7 @@ def load_release_spec(manifest_path: Path) -> ReleaseSpec:raise ReleaseGuardError(f"{context} has an invalid digest")if not isinstance(size, int) or isinstance(size, bool) or not 0 < size <= MAX_ARCHIVE_BYTES:raise ReleaseGuardError(f"{context}.size_bytes is invalid")- if bin_path != "cli-proxy-api":+ if bin_path != ("cli-proxy-api.exe" if platform.startswith("windows-") else "cli-proxy-api"):raise ReleaseGuardError(f"{context}.bin_path is invalid")seen_platforms.add(platform)seen_names.add(name)@@ -160,7 +166,6 @@ def load_release_spec(manifest_path: Path) -> ReleaseSpec:platform=platform,name=name,owned_url=owned_url,- upstream_url=f"{upstream_release_url}/{name}",size=size,sha256=sha256,binary_sha256=binary_sha256,@@ -335,39 +340,25 @@ def _download(url: str, destination: Path, *, max_bytes: int, attempts: int = 3)time.sleep(float(attempt))-def _materialize(- manifest_path: Path,- output_dir: Path,- *,- from_upstream: bool,-) -> ReleaseSpec:+def fetch_release_assets(manifest_path: Path, output_dir: Path) -> ReleaseSpec:spec = load_release_spec(manifest_path)output_dir.parent.mkdir(parents=True, exist_ok=True)staging = Path(tempfile.mkdtemp(prefix=f".{output_dir.name}-", dir=output_dir.parent))try:- (staging / "model-hub-engine-manifest.json").write_bytes(spec.manifest_bytes)for archive in spec.archives:- url = archive.upstream_url if from_upstream else archive.owned_url- _download(url, staging / archive.name, max_bytes=archive.size)+ _download(archive.owned_url, staging / archive.name, max_bytes=archive.size)if (staging / archive.name).stat().st_size != archive.size:raise ReleaseGuardError(f"Model Hub engine archive size mismatch: {archive.name}")- if from_upstream:- (staging / f"{archive.name}.sha256").write_text(- f"{archive.sha256} {archive.name}\n",- encoding="utf-8",- )- else:- _download(- f"{archive.owned_url}.sha256",- staging / f"{archive.name}.sha256",- max_bytes=256,- )- if not from_upstream:_download(- f"{spec.owned_release_url}/model-hub-engine-manifest.json",- staging / "model-hub-engine-manifest.json",- max_bytes=max(len(spec.manifest_bytes), 1),+ f"{archive.owned_url}.sha256",+ staging / f"{archive.name}.sha256",+ max_bytes=256,)+ _download(+ f"{spec.owned_release_url}/model-hub-engine-manifest.json",+ staging / "model-hub-engine-manifest.json",+ max_bytes=max(len(spec.manifest_bytes), 1),+ )verify_release_assets(manifest_path, staging)if output_dir.exists():if not output_dir.is_dir() or output_dir.is_symlink():@@ -380,10 +371,6 @@ def _materialize(return spec-def fetch_release_assets(manifest_path: Path, output_dir: Path) -> ReleaseSpec:- return _materialize(manifest_path, output_dir, from_upstream=False)--def fetch_upstream_assets(manifest_path: Path, output_dir: Path) -> ReleaseSpec:try:from scripts.build_model_hub_engine import build_source_releasediff --git a/tests/e2e/drivers/mock_llm_upstream.py b/tests/e2e/drivers/mock_llm_upstream.pyindex 415b8b371..a97654275 100644--- a/tests/e2e/drivers/mock_llm_upstream.py+++ b/tests/e2e/drivers/mock_llm_upstream.py@@ -1093,6 +1093,19 @@ def _chat_stream_frames(model: str) -> list[bytes]:],},),+ _sse(+ None,+ {+ **common,+ "choices": [+ {+ "index": 0,+ "delta": {},+ "finish_reason": "stop",+ }+ ],+ },+ ),_sse(None,{diff --git a/tests/e2e/test_model_hub_engine_contract.py b/tests/e2e/test_model_hub_engine_contract.pynew file mode 100644index 000000000..921a1ded5--- /dev/null+++ b/tests/e2e/test_model_hub_engine_contract.py@@ -0,0 +1,623 @@+"""What Avibe needs from the pinned CPA binary, independent of its version.++These cases run against whichever engine ``VIBE_MODEL_HUB_ENGINE_MANIFEST_PATH``+names, so one suite characterizes the shipped engine and an upgrade candidate.+Every upstream is a loopback fixture; the engine, its config and its+management API are real. Each case writes a value-free evidence summary to+``tmp_path / "evidence.json"`` so two engines' runs can be compared.+"""++from __future__ import annotations++import asyncio+import base64+import contextlib+import hashlib+import json+import os+import re+import socket+import threading+import time+import urllib.error+import urllib.request+from contextlib import contextmanager+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer++import psutil+import pytest+import yaml++from core.handlers.model_hub.service import ModelHubError+from tests.e2e.test_model_hub_runtime import _isolated_engine_adapter+from tests.scenario_harness.model_hub import MemoryModelHubStore, service_for+from tests.test_model_hub_l3 import _source+from tests.test_model_hub_vibey_consumer import _vibey_service+from vibe.model_hub_runtime import config as engine_config+from vibe.model_hub_runtime.client import EngineClient, EngineClientError+from vibe.model_hub_runtime.config import expected_model_names+from vibe.model_hub_runtime.state import SourceRecord+++pytestmark = pytest.mark.e2e_model_hub++_UNUSED_UPSTREAM = "http://127.0.0.1:9"+_READY_SECONDS = 15.0+++def _sha(data: bytes) -> str:+ return hashlib.sha256(data).hexdigest()+++def _await(condition, *, what: str, seconds: float = _READY_SECONDS):+ """Wait for an engine-side effect Avibe also waits for, never longer than ``seconds``."""+ deadline = time.monotonic() + seconds+ while True:+ value = condition()+ if value:+ return value+ if time.monotonic() >= deadline:+ raise AssertionError(f"engine never reached: {what}")+ time.sleep(0.1)+++def _shape(value, depth: int = 0):+ """Keys and JSON types only, so evidence never carries a value."""+ if isinstance(value, dict):+ return {key: _shape(item, depth + 1) for key, item in sorted(value.items())} if depth < 3 else "object"+ if isinstance(value, list):+ merged: dict = {}+ for item in value:+ shaped = _shape(item, depth + 1)+ if isinstance(shaped, dict):+ merged.update(shaped)+ else:+ return [shaped]+ return [merged] if merged else []+ return type(value).__name__+++def _all_protocol_sources(store) -> list[SourceRecord]:+ """One API-key Source per protocol, together using every YAML feature Avibe renders."""+ sources = []+ for index, (protocol, vendor, models, efforts, route_ids, text_only) in enumerate((+ ("openai_chat", "custom", ("chat-model", "chat-text-only"), (), (), ("chat-text-only",)),+ ("openai_responses", "custom", ("responses-model",), (("responses-model", ("low", "high")),), (), ()),+ ("anthropic", "custom", ("anthropic-model",), (), ("anthropic-routed",), ()),+ ("google", "custom", ("gemini-model",), (), (), ()),+ )):+ base_url = f"{_UNUSED_UPSTREAM}/fixture-{index}"+ credential_ref = store.store_api_key(+ f"sk-synthetic-contract-{index}", vendor=vendor, protocol=protocol, base_url=base_url,+ )+ sources.append(SourceRecord(+ source_id=f"src_contract{index:03d}",+ vendor=vendor,+ protocol=protocol,+ base_url=base_url,+ credential_ref=credential_ref,+ allowed_origins=(),+ model_ids=models,+ prefix=f"avibe-{index:024x}",+ model_reasoning_efforts=efforts,+ route_model_ids=route_ids,+ text_only_model_ids=text_only,+ ))+ return sources+++def _write_evidence(tmp_path, payload) -> None:+ text = json.dumps(payload, sort_keys=True)+ (tmp_path / "evidence.json").write_text(text, encoding="utf-8")+ # One line per case, so a run's captured output compares across engines.+ print(f"EVIDENCE {os.environ.get('PYTEST_CURRENT_TEST', '').split(' ')[0]} {text}")+++def _without_secret(text: str) -> tuple[dict, str]:+ document = yaml.safe_load(text)+ secret = document["remote-management"].pop("secret-key")+ return document, secret+++def _secret_masked_sha(data: bytes) -> str:+ """The file's sha with the salted management-key hash masked, comparable across runs."""+ masked = re.sub(rb"(secret-key:\s*)\S+", rb"\1<secret>", data)+ return _sha(masked)+++def test_engine_keeps_avibe_config_content_across_start_and_hot_reload(tmp_path, monkeypatch) -> None:+ """The engine applies Avibe's config.yaml as written, at start and on PUT reload.++ Every load replaces the plaintext management key with a salted bcrypt hash+ and re-encodes the file (CPA ``config_load.go``), so the bytes Avibe wrote+ never survive a load. Everything else must: no migrated, dropped, added or+ renamed setting, and the key Avibe holds must still authenticate.+ """+ written: dict[str, str] = {}+ original_write = engine_config.write_atomic++ def recording_write(path, text, *args, **kwargs):+ written[str(path)] = text+ return original_write(path, text, *args, **kwargs)++ monkeypatch.setattr(engine_config, "write_atomic", recording_write)+ sent: list[str] = []+ original_put = EngineClient.put_config_yaml++ def recording_put(self, text, **kwargs):+ sent.append(text)+ return original_put(self, text, **kwargs)++ monkeypatch.setattr(EngineClient, "put_config_yaml", recording_put)++ with _isolated_engine_adapter(tmp_path, monkeypatch) as adapter:+ store = adapter.state_store+ store.replace_sources(_all_protocol_sources(store))+ connection = adapter.supervisor.ensure_running()+ [config_path] = list(store.root.glob("instances/*/config.yaml"))+ start_text = written[str(config_path)]+ client = EngineClient(connection)+ expected = expected_model_names(store.list_sources(), store, "1")+ _await(+ lambda: all(client.list_model_names(timeout=1.0).get(model) == name for model, name in expected.items()),+ what="start projection listed",+ )+ settings = client.management_request("GET", "/config")+ after_start = config_path.read_bytes()++ previous = store.list_sources()+ store.set_models("src_contract000", ("chat-model", "chat-text-only", "chat-added"))+ adapter.supervisor.reload_config_if_running(previous)+ [reload_text] = sent+ client.management_request("GET", "/config")+ after_reload = config_path.read_bytes()++ evidence = {}+ for phase, avibe_text, on_disk in (("start", start_text, after_start), ("reload", reload_text, after_reload)):+ rendered, plaintext = _without_secret(avibe_text)+ loaded, stored = _without_secret(on_disk.decode())+ evidence[phase] = {+ "avibe_sha": _sha(avibe_text.encode()),+ "file_sha": _sha(on_disk),+ "file_bytes_equal_avibe": on_disk == avibe_text.encode(),+ "file_secret_masked_sha": _secret_masked_sha(on_disk),+ "stored_secret_kind": "bcrypt" if stored.startswith(("$2a$", "$2b$", "$2y$")) else (+ "plaintext" if stored == plaintext else "other"),+ "content_equal_without_secret": loaded == rendered,+ "added_keys": sorted(set(loaded) - set(rendered)),+ "dropped_keys": sorted(set(rendered) - set(loaded)),+ }+ evidence["get_config_shape"] = _shape(settings)+ _write_evidence(tmp_path, evidence)+ for phase in ("start", "reload"):+ assert evidence[phase]["content_equal_without_secret"], evidence[phase]+ assert evidence[phase]["stored_secret_kind"] in {"bcrypt", "plaintext"}, evidence[phase]+ # The settings Avibe relies on were read, not dropped as unknown keys.+ assert settings.get("request-retry") == 0+ assert settings.get("disable-cooling") is True+ assert settings.get("force-model-prefix") is True+ assert settings.get("routing", {}).get("strategy") == "fill-first"+++def _jwt(claims: dict) -> str:+ def part(value: dict) -> str:+ return base64.urlsafe_b64encode(json.dumps(value).encode()).rstrip(b"=").decode()++ return f"{part({'alg': 'none', 'typ': 'JWT'})}.{part(claims)}.c2lnbmF0dXJl"+++@contextmanager+def _capturing_server():+ seen: list[dict] = []++ class Handler(BaseHTTPRequestHandler):+ def do_GET(self): # noqa: N802 - http.server API+ seen.append({"path": self.path, "authorization": self.headers.get("Authorization")})+ body = b'{"fixture":"quota"}'+ self.send_response(200)+ self.send_header("Content-Type", "application/json")+ self.send_header("X-Fixture", "yes")+ self.send_header("Content-Length", str(len(body)))+ self.end_headers()+ self.wfile.write(body)++ def log_message(self, *args):+ return++ server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)+ thread = threading.Thread(target=server.serve_forever, daemon=True)+ thread.start()+ try:+ yield f"http://127.0.0.1:{server.server_address[1]}", seen+ finally:+ server.shutdown()+ server.server_close()+ thread.join(timeout=5)+++def _call(client: EngineClient, method: str, path: str, **kwargs):+ try:+ return {"ok": True, "body": client.management_request(method, path, **kwargs)}+ except EngineClientError as exc:+ return {"ok": False, "status": exc.status_code, "error_type": exc.error_type}+++def test_engine_management_surface_avibe_reads(tmp_path, monkeypatch) -> None:+ """Every /v0/management call Avibe makes answers with the fields Avibe reads."""+ access_token = "synthetic-access-token-contract"+ account_id = "acct-synthetic-contract"+ auth_name = "codex-contract-fixture.json"+ grant = {+ "type": "codex",+ "access_token": access_token,+ "refresh_token": "",+ "id_token": _jwt({+ "email": "[email protected]",+ "https://api.openai.com/auth": {"chatgpt_account_id": account_id, "chatgpt_plan_type": "plus"},+ }),+ "account_id": account_id,+ "email": "[email protected]",+ "expired": "2099-01-01T00:00:00Z",+ "last_refresh": "2026-01-01T00:00:00Z",+ }+ evidence: dict = {}+ with contextlib.ExitStack() as stack:+ upstream, seen = stack.enter_context(_capturing_server())+ adapter = stack.enter_context(_isolated_engine_adapter(tmp_path, monkeypatch))+ client = EngineClient(adapter.supervisor.ensure_running())+ adapter.state_store.write_oauth_auth_file(auth_name, grant)++ def listed():+ files = client.management_request("GET", "/auth-files").get("files") or []+ return next((item for item in files if item.get("name") == auth_name), None)++ record = _await(listed, what="auth file listed")+ evidence["auth_files_item"] = _shape(record)+ assert record.get("auth_index")+ assert (record.get("provider") or record.get("type")) == "codex"+ assert (record.get("id_token") or {}).get("chatgpt_account_id") == account_id++ models = _call(client, "GET", "/auth-files/models", query={"name": auth_name})+ evidence["auth_files_models"] = {"ok": models["ok"], "shape": _shape(models.get("body"))}+ assert models["ok"] and isinstance(models["body"].get("models"), list) and models["body"]["models"]++ prefix = "avibe-" + "c" * 24+ patched = _call(client, "PATCH", "/auth-files/fields", payload={"name": auth_name, "prefix": prefix})+ evidence["auth_files_fields"] = {"ok": patched["ok"], "shape": _shape(patched.get("body"))}+ assert patched["ok"]+ _await(+ lambda: any(model.startswith(f"{prefix}/") for model in client.list_model_ids(timeout=1.0)),+ what="prefixed OAuth models listed",+ )++ called = _call(client, "POST", "/api-call", payload={+ "auth_index": record["auth_index"],+ "method": "GET",+ "url": f"{upstream}/quota",+ "header": {"Authorization": "Bearer $TOKEN$"},+ })+ evidence["api_call"] = {"ok": called["ok"], "shape": _shape(called.get("body"))}+ assert called["ok"] and called["body"].get("status_code") == 200+ assert seen and seen[-1]["authorization"] == f"Bearer {access_token}"++ flows = {}+ # A redirect login binds the vendor's fixed callback port on this host,+ # so these run only where the network belongs to the test (see+ # test_oauth_callback_forwarder_is_loopback_only_and_optional).+ redirect_logins = ("/codex-auth-url", "/anthropic-auth-url")+ for endpoint in redirect_logins if os.environ.get("AVIBE_E2E_ISOLATED_NETWORK") == "1" else ():+ started = _call(client, "GET", endpoint, query={"is_webui": "true"})+ assert started["ok"], (endpoint, started)+ state = started["body"].get("state")+ assert state and (started["body"].get("url") or started["body"].get("verification_uri"))+ waiting = _call(client, "GET", "/get-auth-status", query={"state": state})+ refused = _call(client, "POST", "/oauth-callback", payload={+ "provider": "codex" if "codex" in endpoint else "anthropic",+ "state": "not-" + state,+ "code": "synthetic-code",+ })+ cancelled = _call(client, "DELETE", "/oauth-session", query={"state": state})+ after_cancel = _call(client, "GET", "/get-auth-status", query={"state": state})+ flows[endpoint] = {+ "start": _shape(started["body"]),+ "status_waiting": waiting.get("body", waiting),+ "callback_wrong_state": {"ok": refused["ok"], "status": refused.get("status")},+ "cancel": {"ok": cancelled["ok"], "status": cancelled.get("status")},+ "status_after_cancel": after_cancel.get("body", after_cancel),+ }+ assert waiting["ok"] and waiting["body"].get("status") == "wait"+ assert cancelled["ok"]+ evidence["oauth"] = flows++ deleted = _call(client, "DELETE", "/auth-files", query={"name": auth_name})+ evidence["auth_files_delete"] = {"ok": deleted["ok"], "shape": _shape(deleted.get("body"))}+ assert deleted["ok"]+ _await(lambda: listed() is None, what="auth file removed")++ # Characterization only: whether a freshly loaded Gemini (Antigravity)+ # grant lists models before its entitlement probe has answered. The+ # probe goes to a loopback stand-in for Google, never to Google.+ antigravity = "antigravity-contract-fixture.json"+ google = stack.enter_context(_antigravity_upstream("delayed_success"))[0]+ adapter.state_store.write_oauth_auth_file(antigravity, _antigravity_grant(google))+ _await(+ lambda: any(item.get("name") == antigravity+ for item in client.management_request("GET", "/auth-files").get("files") or []),+ what="antigravity auth file listed",+ )+ counts = []+ for _ in range(5):+ listing = _call(client, "GET", "/auth-files/models", query={"name": antigravity})+ counts.append(len((listing.get("body") or {}).get("models") or []))+ time.sleep(1)+ evidence["antigravity_models_first_5s"] = counts+ _write_evidence(tmp_path, evidence)+++def _engine_listeners(adapter, port: int) -> set[str]:+ """The addresses the test-owned engine itself listens on at ``port``.++ The vendors' callback ports are fixed, so another process on this host may+ hold one; reading the engine's own sockets never touches that process.+ """+ record = json.loads((adapter.state_store.root / "engine-process.json").read_text(encoding="utf-8"))+ [engine] = record["engines"]+ return {+ connection.laddr.ip+ for connection in psutil.Process(engine["pid"]).net_connections(kind="tcp")+ if connection.status == psutil.CONN_LISTEN and connection.laddr.port == port+ }+++def _port_free(port: int) -> bool:+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as probe:+ try:+ probe.bind(("127.0.0.1", port))+ except OSError:+ return False+ return True+++def test_oauth_callback_forwarder_is_loopback_only_and_optional(tmp_path, monkeypatch) -> None:+ """A redirect login relays its callback on loopback only, and starts without the relay.++ Scenario: AUTH-SETUP-130 (the engine half). Codex's forwarder must listen+ on 127.0.0.1 and nowhere else. With Claude's fixed port already taken, the+ login still starts and waits for a pasted callback, and the engine holds no+ listener there.++ The vendors' callback ports are fixed, so the engine and this test bind real+ host ports; a login in a service on the same host could collide with them.+ It runs only where the network belongs to the test: set+ AVIBE_E2E_ISOLATED_NETWORK=1 in an isolated environment such as the Incus+ regression env.+ """+ if os.environ.get("AVIBE_E2E_ISOLATED_NETWORK") != "1":+ pytest.skip("binds the vendors' fixed OAuth callback ports; set AVIBE_E2E_ISOLATED_NETWORK=1 to run")+ if not _port_free(1455):+ pytest.skip("Codex's fixed OAuth callback port 1455 is in use on this host")+ evidence: dict = {}+ with _isolated_engine_adapter(tmp_path, monkeypatch) as adapter:+ client = EngineClient(adapter.supervisor.ensure_running())++ started = _call(client, "GET", "/codex-auth-url", query={"is_webui": "true"})+ assert started["ok"], started+ state = started["body"]["state"]+ # The forwarder listens before the engine answers the start.+ evidence["codex_forwarder_listens_on"] = sorted(_engine_listeners(adapter, 1455))+ assert evidence["codex_forwarder_listens_on"] == ["127.0.0.1"], evidence+ assert _call(client, "DELETE", "/oauth-session", query={"state": state})["ok"]++ with contextlib.ExitStack() as stack:+ if _port_free(54545):+ holder = stack.enter_context(socket.socket(socket.AF_INET, socket.SOCK_STREAM))+ holder.bind(("127.0.0.1", 54545))+ holder.listen()+ started = _call(client, "GET", "/anthropic-auth-url", query={"is_webui": "true"})+ evidence["anthropic_port_taken"] = {"ok": started["ok"], "status": started.get("status")}+ assert started["ok"], started+ assert started["body"].get("url")+ assert _engine_listeners(adapter, 54545) == set()+ state = started["body"]["state"]+ waiting = _call(client, "GET", "/get-auth-status", query={"state": state})+ assert waiting["ok"] and waiting["body"].get("status") == "wait", waiting+ assert _call(client, "DELETE", "/oauth-session", query={"state": state})["ok"]+ _write_evidence(tmp_path, evidence)+++# The engine's embedded Antigravity catalog (models.json at v8.0.23). The+# fixture's entitlement answer names all of them except one, so a narrowing+# that the probe applies is observable.+_ANTIGRAVITY_IDS = (+ "claude-opus-4-6-thinking", "claude-sonnet-4-6", "claude-opus-5-5-high", "claude-sonnet-5-5-high",+ "gemini-3.6-flash-high", "gemini-3.7-flash-high", "gemini-3.8-flash-high", "gemini-3-flash",+ "gemini-3.1-flash-image", "gemini-pro-agent", "gemini-3.1-pro-low", "gpt-oss-120b-medium",+ "gemini-3.1-flash-lite", "gemini-3.5-flash-lite",+)+_ANTIGRAVITY_NOT_ENTITLED = "gemini-3.1-flash-lite"+_ANTIGRAVITY_PROBE_DELAY = 3.0+_ANTIGRAVITY_PREFIX = "avibe-" + "a" * 24+++@contextmanager+def _antigravity_upstream(probe: str):+ """Google's Antigravity endpoints on loopback: entitlement probe plus generation."""+ seen: list[dict] = []++ class Handler(BaseHTTPRequestHandler):+ def do_POST(self): # noqa: N802 - http.server API+ self.rfile.read(int(self.headers.get("Content-Length") or 0))+ seen.append({"path": self.path, "at": time.monotonic()})+ if self.path.startswith("/v1internal:fetchAvailableModels"):+ if probe == "failure":+ body, status = b'{"error":{"code":503,"message":"fixture outage"}}', 503+ else:+ time.sleep(_ANTIGRAVITY_PROBE_DELAY)+ entitled = [model for model in _ANTIGRAVITY_IDS if model != _ANTIGRAVITY_NOT_ENTITLED]+ body = json.dumps({"models": {model: {} for model in entitled}}).encode()+ status = 200+ self.send_response(status)+ self.send_header("Content-Type", "application/json")+ self.send_header("Content-Length", str(len(body)))+ self.end_headers()+ self.wfile.write(body)+ return+ chunk = {"response": {"candidates": [{"content": {"role": "model", "parts": [{"text": "ok"}]},+ "finishReason": "STOP"}],+ "usageMetadata": {"promptTokenCount": 1, "candidatesTokenCount": 1,+ "totalTokenCount": 2}}}+ body = b"data: " + json.dumps(chunk).encode() + b"\n\n"+ self.send_response(200)+ self.send_header("Content-Type", "text/event-stream")+ self.send_header("Content-Length", str(len(body)))+ self.end_headers()+ self.wfile.write(body)++ def log_message(self, *args):+ return++ server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)+ thread = threading.Thread(target=server.serve_forever, daemon=True)+ thread.start()+ try:+ yield f"http://127.0.0.1:{server.server_address[1]}", seen+ finally:+ server.shutdown()+ server.server_close()+ thread.join(timeout=5)+++def _antigravity_grant(upstream: str, *, prefix: str | None = None) -> dict:+ grant = {+ "type": "antigravity",+ "access_token": "synthetic-antigravity-token",+ "refresh_token": "",+ "email": "[email protected]",+ "project_id": "synthetic-project",+ "expired": "2099-01-01T00:00:00Z",+ "base_url": upstream,+ }+ if prefix:+ grant["prefix"] = prefix+ return grant+++def _engine_chat(client: EngineClient, model: str) -> tuple[int, str]:+ request = urllib.request.Request(+ client.connection.base_url + "/v1/chat/completions",+ data=json.dumps({"model": model, "messages": [{"role": "user", "content": "x"}]}).encode(),+ headers={"Authorization": f"Bearer {client.connection.gateway_token}", "Content-Type": "application/json"},+ method="POST",+ )+ try:+ with urllib.request.urlopen(request, timeout=20) as response:+ return response.status, response.read().decode(errors="replace")+ except urllib.error.HTTPError as exc:+ return exc.code, exc.read().decode(errors="replace")+++def _antigravity_timeline(client: EngineClient, auth_name: str, started: float, *, seconds: float) -> list[dict]:+ """Listing and routing, sampled from the moment the grant is loaded."""+ entitled = f"{_ANTIGRAVITY_PREFIX}/gemini-3-flash"+ excluded = f"{_ANTIGRAVITY_PREFIX}/{_ANTIGRAVITY_NOT_ENTITLED}"+ samples = []+ deadline = started + seconds+ while time.monotonic() < deadline:+ listing = _call(client, "GET", "/auth-files/models", query={"name": auth_name})+ # A prefixed grant lists its routed IDs; compare the upstream model names.+ ids = {str(item.get("id")).rsplit("/", 1)[-1] for item in (listing.get("body") or {}).get("models") or []}+ samples.append({+ "t": round(time.monotonic() - started, 2),+ "listed": len(ids),+ "excluded_listed": _ANTIGRAVITY_NOT_ENTITLED in ids,+ "entitled_status": _engine_chat(client, entitled)[0],+ "excluded_status": _engine_chat(client, excluded)[0],+ })+ time.sleep(0.5)+ return samples++[email protected]("probe", ["delayed_success", "failure"])+def test_antigravity_grant_routes_at_once_and_narrows_when_the_probe_answers(tmp_path, monkeypatch, probe) -> None:+ """A Gemini (Antigravity) grant routes from the moment the engine loads it.++ Avibe discovers a new grant's models right after the OAuth flow and routes+ to them right after every engine start. Since v8.0.14 the stock engine+ lists nothing until its per-account entitlement probe answers; Avibe's+ engine patch registers the static catalog meanwhile, the probe narrows it,+ and a failed probe leaves it in place (router-for-me/CLIProxyAPI#6531).+ """+ auth_name = "antigravity-window-fixture.json"+ evidence: dict = {"probe": probe}+ with _antigravity_upstream(probe) as (upstream, seen), _isolated_engine_adapter(tmp_path, monkeypatch) as adapter:+ client = EngineClient(adapter.supervisor.ensure_running())+ adapter.state_store.write_oauth_auth_file(auth_name, _antigravity_grant(upstream, prefix=_ANTIGRAVITY_PREFIX))+ loaded = time.monotonic()+ _await(+ lambda: any(item.get("name") == auth_name+ for item in client.management_request("GET", "/auth-files").get("files") or []),+ what="antigravity grant listed",+ )+ evidence["after_grant_load"] = _antigravity_timeline(+ client, auth_name, loaded, seconds=_ANTIGRAVITY_PROBE_DELAY + 5)+ adapter.supervisor.stop()+ restarted = time.monotonic()+ client = EngineClient(adapter.supervisor.ensure_running())+ evidence["after_engine_restart"] = _antigravity_timeline(+ client, auth_name, restarted, seconds=_ANTIGRAVITY_PROBE_DELAY + 5)+ evidence["probe_calls"] = sum(1 for item in seen if "fetchAvailableModels" in item["path"])+ _write_evidence(tmp_path, evidence)+ for phase in ("after_grant_load", "after_engine_restart"):+ samples = evidence[phase]+ assert samples[0]["listed"] > 0 and samples[0]["entitled_status"] == 200, (phase, samples)+ assert all(sample["entitled_status"] == 200 for sample in samples), (phase, samples)+ if probe == "delayed_success":+ final = samples[-1]+ assert not final["excluded_listed"] and final["excluded_status"] == 400, (phase, samples)+ else:+ assert all(sample["excluded_listed"] and sample["excluded_status"] == 200 for sample in samples), (+ phase, samples)+++async def _refresh(service, source_id: str) -> dict:+ try:+ result = await service.refresh_source(source_id)+ outcome = {"ok": True, "models": sorted(model["id"] for model in result["source"].get("models") or [])}+ except ModelHubError as exc:+ outcome = {"ok": False, "error": exc.code}+ state = service._source(service.store.load(), source_id).state+ return {**outcome, "source_state": [state.status, state.detail_key]}+++async def test_antigravity_source_refresh_right_after_engine_start(tmp_path, monkeypatch) -> None:+ """A Gemini subscription Source refreshed right after the engine starts keeps its models."""+ auth_name = "antigravity-refresh-fixture.json"+ with _antigravity_upstream("delayed_success") as (upstream, seen), \+ _isolated_engine_adapter(tmp_path, monkeypatch) as adapter:+ adapter.state_store.write_oauth_auth_file(auth_name, _antigravity_grant(upstream))+ source = _source("src_gemini0001", "Gemini subscription", vendor="gemini", protocol="openai_chat",+ model_id="gemini-3-flash")+ source.kind = "subscription"+ source.billing = "monthly"+ source.credential_ref = adapter.state_store.bind_oauth_credential("src_gemini0001", "gemini", auth_name)+ config = _vibey_service(tmp_path, [source]).store.config+ service = service_for(tmp_path, MemoryModelHubStore(config), adapter)+ await service.runtime_start()+ started = time.monotonic()+ first = await _refresh(service, "src_gemini0001")+ first["after_seconds"] = round(time.monotonic() - started, 2)+ client = adapter.supervisor.client_if_running()++ def narrowed():+ listing = client.management_request("GET", "/auth-files/models", query={"name": auth_name})+ ids = {item.get("id") for item in listing.get("models") or []}+ return ids and _ANTIGRAVITY_NOT_ENTITLED not in ids++ await asyncio.to_thread(_await, narrowed, what="entitlement narrowing applied")+ narrowed_after = round(time.monotonic() - started, 2)+ second = await _refresh(service, "src_gemini0001")+ _write_evidence(tmp_path, {"refresh_at_start": first, "narrowed_after_seconds": narrowed_after,+ "refresh_after_narrowing": second})+ assert first["ok"] and "gemini-3-flash" in first["models"], first+ assert second["ok"] and _ANTIGRAVITY_NOT_ENTITLED not in second["models"], second+ assert second["source_state"][0] == "standby", seconddiff --git a/tests/e2e/test_model_hub_engine_wire.py b/tests/e2e/test_model_hub_engine_wire.pynew file mode 100644index 000000000..345444810--- /dev/null+++ b/tests/e2e/test_model_hub_engine_wire.py@@ -0,0 +1,561 @@+"""Stream and failure wire behavior Vibey receives through the gateway and the pinned CPA.++Each case drives the real gateway, router, adapter and engine against a+loopback upstream that misbehaves in one specific way. The assertions pin what+Avibe relies on; ``tmp_path / "evidence.json"`` records the full observation,+including Model Hub's own outcome for the Turn, so two engines can be compared.+"""++from __future__ import annotations++import asyncio+import json+import os+import signal+import time+from contextlib import AsyncExitStack, asynccontextmanager+from urllib.parse import quote++import aiohttp+from aiohttp import web+import pytest++from core.handlers.model_hub.turn_gateway import ModelHubTurnGateway+from core.run_settlement import SETTLED_BY_TERMINAL_RESULT+from modules.agents.model_hub import ModelHubRuntimeRouter+from tests.e2e.test_model_hub_runtime import _isolated_engine_adapter+from tests.scenario_harness.model_hub import MemoryModelHubStore, service_for+from tests.test_model_hub_google import _server, _sse+from tests.test_model_hub_l3 import _source+from tests.test_model_hub_vibey_consumer import _vibey_service+from vibe.model_hub_runtime import supervisor as engine_supervisor+++pytestmark = pytest.mark.e2e_model_hub++MODEL = "fixture-model"+PROTOCOLS = ("openai_chat", "openai_responses", "anthropic", "google")+_FRONTEND_PATH = {+ "anthropic": "/v1/messages",+ "openai_responses": "/v1/responses",+ "openai_chat": "/v1/chat/completions",+}+_TURN = "wire"+++def _partial_frames(protocol: str) -> list[bytes]:+ """Output that a healthy stream would continue; no terminal frame."""+ if protocol == "openai_chat":+ return [_sse({"id": "chatcmpl-fixture", "object": "chat.completion.chunk", "created": 1700000000,+ "model": MODEL, "choices": [{"index": 0, "delta": {"role": "assistant", "content": "partial"},+ "finish_reason": None}]})]+ if protocol == "openai_responses":+ return [+ b"event: response.created\n" + _sse({"type": "response.created", "sequence_number": 0, "response": {+ "id": "resp_fixture", "object": "response", "status": "in_progress", "model": MODEL, "output": []}}),+ b"event: response.output_item.added\n" + _sse({+ "type": "response.output_item.added", "sequence_number": 1, "output_index": 0,+ "item": {"id": "msg_fixture", "type": "message", "role": "assistant", "status": "in_progress",+ "content": []}}),+ b"event: response.output_text.delta\n" + _sse({+ "type": "response.output_text.delta", "sequence_number": 2, "item_id": "msg_fixture",+ "output_index": 0, "content_index": 0, "delta": "partial"}),+ ]+ if protocol == "anthropic":+ return [+ b"event: message_start\n" + _sse({"type": "message_start", "message": {+ "id": "msg_fixture", "type": "message", "role": "assistant", "model": MODEL, "content": [],+ "stop_reason": None, "usage": {"input_tokens": 3, "output_tokens": 0}}}),+ b"event: content_block_start\n" + _sse({"type": "content_block_start", "index": 0,+ "content_block": {"type": "text", "text": ""}}),+ b"event: content_block_delta\n" + _sse({"type": "content_block_delta", "index": 0,+ "delta": {"type": "text_delta", "text": "partial"}}),+ ]+ return [_sse({"candidates": [{"index": 0, "content": {"role": "model", "parts": [{"text": "partial"}]}}],+ "modelVersion": MODEL})]+++_CHAT_FINISH = _sse({"id": "chatcmpl-fixture", "object": "chat.completion.chunk", "created": 1700000000,+ "model": MODEL, "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}]})+_CHAT_USAGE = _sse({"id": "chatcmpl-fixture", "object": "chat.completion.chunk", "created": 1700000000,+ "model": MODEL, "choices": [],+ "usage": {"prompt_tokens": 3, "completion_tokens": 1, "total_tokens": 4}})+# Fernet-shaped, so the engine keeps it with its id (CPA strips other shapes).+_ENCRYPTED = "g" + "A" * 97+++def _responses_reasoning_tool_frames() -> list[bytes]:+ events = [+ {"type": "response.created", "response": {"id": "resp_rt", "object": "response", "status": "in_progress",+ "model": MODEL, "output": []}},+ {"type": "response.output_item.added", "output_index": 0,+ "item": {"id": "rs_1", "type": "reasoning", "summary": []}},+ {"type": "response.reasoning_summary_part.added", "item_id": "rs_1", "output_index": 0,+ "summary_index": 0, "part": {"type": "summary_text", "text": ""}},+ {"type": "response.reasoning_summary_text.delta", "item_id": "rs_1", "output_index": 0,+ "summary_index": 0, "delta": "Checking the "},+ {"type": "response.reasoning_summary_text.delta", "item_id": "rs_1", "output_index": 0,+ "summary_index": 0, "delta": "weather tool."},+ {"type": "response.reasoning_summary_text.done", "item_id": "rs_1", "output_index": 0,+ "summary_index": 0, "text": "Checking the weather tool."},+ {"type": "response.reasoning_summary_part.done", "item_id": "rs_1", "output_index": 0,+ "summary_index": 0, "part": {"type": "summary_text", "text": "Checking the weather tool."}},+ {"type": "response.output_item.done", "output_index": 0,+ "item": {"id": "rs_1", "type": "reasoning", "encrypted_content": _ENCRYPTED,+ "summary": [{"type": "summary_text", "text": "Checking the weather tool."}]}},+ {"type": "response.output_item.added", "output_index": 1,+ "item": {"id": "fc_1", "type": "function_call", "status": "in_progress", "call_id": "call_fixture",+ "name": "weather", "arguments": ""}},+ {"type": "response.function_call_arguments.delta", "item_id": "fc_1", "output_index": 1,+ "delta": "{\"city\":"},+ {"type": "response.function_call_arguments.delta", "item_id": "fc_1", "output_index": 1,+ "delta": "\"上海\"}"},+ {"type": "response.function_call_arguments.done", "item_id": "fc_1", "output_index": 1,+ "arguments": "{\"city\":\"上海\"}"},+ {"type": "response.output_item.done", "output_index": 1,+ "item": {"id": "fc_1", "type": "function_call", "status": "completed", "call_id": "call_fixture",+ "name": "weather", "arguments": "{\"city\":\"上海\"}"}},+ {"type": "response.completed", "response": {+ "id": "resp_rt", "object": "response", "status": "completed", "model": MODEL, "output": [],+ "usage": {"input_tokens": 11, "output_tokens": 7, "total_tokens": 18}}},+ ]+ return [+ f"event: {event['type']}\n".encode() + _sse({**event, "sequence_number": index})+ for index, event in enumerate(events)+ ]+++def _frontend_request(protocol: str, hop: dict, *, stream: bool, extra: dict | None = None) -> tuple[str, dict]:+ base = hop["base_url"].rsplit("/", 1)[0]+ prompt = "wire fixture"+ if protocol == "google":+ method = "streamGenerateContent?alt=sse" if stream else "generateContent"+ return (f'{base}/v1beta/models/{quote(hop["runtime_model"], safe="")}:{method}',+ {"contents": [{"role": "user", "parts": [{"text": prompt}]}], **(extra or {})})+ body = {"model": hop["runtime_model"], "stream": stream}+ if protocol == "openai_responses":+ body.update(input=prompt, max_output_tokens=64)+ else:+ body.update(messages=[{"role": "user", "content": prompt}], max_tokens=64)+ body.update(extra or {})+ return base + _FRONTEND_PATH[protocol], body+++class _Harness:+ def __init__(self, service, router, adapter, hop, requests) -> None:+ self.service = service+ self.router = router+ self.adapter = adapter+ self.hop = hop+ # Requests per Source, in route order.+ self.requests = requests++ async def outcome(self) -> dict:+ """Model Hub's own verdict on the Turn, and the state it left on each Source."""+ completion = self.router.settle_turn(_TURN, settled_by=SETTLED_BY_TERMINAL_RESULT, ts="2026-10-11T09:00:00Z")+ if completion:+ await completion+ record = self.service.provenance.get(_TURN) or {}+ served = record.get("served") or {}+ return {+ "provenance_outcome": record.get("outcome"),+ "served_source": served.get("source_id"),+ "failed_attempts": [+ {key: attempt.get(key) for key in ("source_id", "reason", "http_status", "stream_started")}+ for attempt in record.get("failed_attempts") or []+ ],+ "terminal_error": {key: (record.get("terminal_error") or {}).get(key)+ for key in ("source_id", "reason", "http_status", "stream_started")},+ "sources": {source.id: [source.state.status, source.state.detail_key]+ for source in self.service.store.load().sources},+ }+++@asynccontextmanager+async def _through_engine(tmp_path, monkeypatch, protocol: str, *handlers):+ """A route of one Source per handler, in order, all speaking ``protocol``."""+ requests: list[list[dict]] = [[] for _ in handlers]++ def recording(index, handler):+ async def respond(request):+ try:+ body = await request.json()+ except Exception: # noqa: BLE001 - the fixture records whatever arrived+ body = None+ requests[index].append({"path": request.path, "body": body, "at": time.monotonic()})+ return await handler(request, body)++ return respond++ with _isolated_engine_adapter(tmp_path, monkeypatch) as adapter:+ async with AsyncExitStack() as stack:+ sources = []+ for index, handler in enumerate(handlers):+ root = await stack.enter_async_context(_server(recording(index, handler)))+ source = _source(f"src_wire{index:04d}", f"Wire fixture {index}", vendor="custom",+ protocol=protocol, model_id=MODEL)+ source.base_url = root + ("/v1" if protocol == "openai_responses" else "")+ source.credential_ref = adapter.state_store.store_api_key(+ f"sk-synthetic-wire-{index}", vendor="custom", protocol=protocol, base_url=source.base_url,+ )+ sources.append(source)+ config = _vibey_service(tmp_path, sources).store.config+ service = service_for(tmp_path, MemoryModelHubStore(config), adapter)+ await service.runtime_start()+ gateway = ModelHubTurnGateway(service)+ router = ModelHubRuntimeRouter(service=service, turn_gateway=gateway)+ try:+ hop = await router.resolve_hop("menu-alias", process_scope="vibey:wire", turn_id=_TURN)+ yield _Harness(service, router, adapter, hop, requests)+ finally:+ await gateway.close()+++async def _post(url: str, hop: dict, body: dict, *, timeout: float = 150) -> dict:+ started = time.monotonic()+ async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=timeout)) as client:+ async with client.post(url, headers={"Authorization": f'Bearer {hop["token"]}'}, json=body) as response:+ transport_error = None+ try:+ raw = await response.read()+ except aiohttp.ClientPayloadError as exc:+ raw = b""+ transport_error = type(exc).__name__+ return {+ "status": response.status,+ "content_type": response.headers.get("Content-Type", "").split(";")[0],+ "raw": raw.decode("utf-8", errors="replace"),+ "transport_error": transport_error,+ "seconds": round(time.monotonic() - started, 3),+ }+++def _frames(raw: str) -> list[str]:+ return [line[5:].strip() for line in raw.splitlines() if line.startswith("data:")]+++def _json_frames(raw: str) -> list[dict]:+ parsed = []+ for frame in _frames(raw):+ try:+ parsed.append(json.loads(frame))+ except json.JSONDecodeError:+ continue+ return parsed+++def _record(tmp_path, payload) -> None:+ text = json.dumps(payload, ensure_ascii=False)+ (tmp_path / "evidence.json").write_text(text, encoding="utf-8")+ # One line per case, so a run's captured output compares across engines.+ print(f"EVIDENCE {os.environ.get('PYTEST_CURRENT_TEST', '').split(' ')[0]} {text}")+++async def _stream(request, frames: list[bytes], *, close: str = "eof") -> web.StreamResponse:+ response = web.StreamResponse(headers={"Content-Type": "text/event-stream"})+ await response.prepare(request)+ for frame in frames:+ await response.write(frame)+ if close == "abort":+ request.transport.close()+ else:+ await response.write_eof()+ return response+++def _upstream_error(status: int, body_kind: str):+ async def handler(request, body):+ if body_kind == "text":+ return web.Response(status=status, text="upstream timeout\n", content_type="text/plain")+ if body_kind == "html":+ return web.Response(status=status, text=f"<html>{status}</html>", content_type="text/html")+ return web.json_response({"error": {"message": "fixture timeout", "type": "server_error",+ "code": "upstream_timeout"}}, status=status)++ return handler+++async def _healthy(protocol: str):+ async def handler(request, body):+ frames = list(_partial_frames(protocol))+ if protocol == "openai_chat":+ frames += [_CHAT_FINISH, _CHAT_USAGE]+ elif protocol == "openai_responses":+ frames.append(b"event: response.completed\n" + _sse({"type": "response.completed", "sequence_number": 3,+ "response": {"id": "resp_fixture", "object": "response", "status": "completed",+ "model": MODEL, "output": [],+ "usage": {"input_tokens": 3, "output_tokens": 1, "total_tokens": 4}}}))+ elif protocol == "anthropic":+ frames += [b"event: content_block_stop\n" + _sse({"type": "content_block_stop", "index": 0}),+ b"event: message_delta\n" + _sse({"type": "message_delta", "delta": {"stop_reason": "end_turn"},+ "usage": {"output_tokens": 1}}),+ b"event: message_stop\n" + _sse({"type": "message_stop"})]+ else:+ frames.append(_sse({"candidates": [{"index": 0, "content": {"role": "model", "parts": [{"text": "."}]},+ "finishReason": "STOP"}], "modelVersion": MODEL,+ "usageMetadata": {"promptTokenCount": 3, "candidatesTokenCount": 1,+ "totalTokenCount": 4}}))+ return await _stream(request, frames)++ return handler++[email protected](("protocol", "status", "body_kind"), [+ *[(protocol, 408, "text") for protocol in PROTOCOLS],+ ("openai_chat", 408, "json"),+ ("openai_chat", 502, "html"),+])+async def test_upstream_http_error_on_a_single_source_route(tmp_path, monkeypatch, protocol, status, body_kind) -> None:+ """What the consumer gets, and when, after a pre-stream upstream error on the only Source."""+ async with _through_engine(tmp_path, monkeypatch, protocol, _upstream_error(status, body_kind)) as harness:+ url, body = _frontend_request(protocol, harness.hop, stream=True)+ observed = await _post(url, harness.hop, body)+ outcome = await harness.outcome()+ calls = harness.requests[0]+ _record(tmp_path, {"protocol": protocol, "upstream": [status, body_kind], "observed": observed,+ "outcome": outcome, "upstream_calls": len(calls),+ "call_offsets": [round(call["at"] - calls[0]["at"], 1) for call in calls]})+ assert observed["status"] >= 400, observed+ # The engine runs with zero retries: every upstream call is one Model Hub attempt.+ assert len(calls) == max(1, len(outcome["failed_attempts"])), (calls, outcome)+ assert outcome["provenance_outcome"] != "served", outcome+++async def test_pre_stream_408_with_a_second_hop(tmp_path, monkeypatch) -> None:+ """A plain-text 408 from the first hop either surfaces or moves the Turn to the next hop."""+ protocol = "openai_chat"+ async with _through_engine(tmp_path, monkeypatch, protocol, _upstream_error(408, "text"),+ await _healthy(protocol)) as harness:+ url, body = _frontend_request(protocol, harness.hop, stream=True)+ observed = await _post(url, harness.hop, body)+ outcome = await harness.outcome()+ _record(tmp_path, {"observed": observed, "outcome": outcome,+ "upstream_calls": [len(calls) for calls in harness.requests]})+ # v7.3.16 typed a text 408 as invalid_request_error, so Avibe surfaced a+ # 400 and never tried the next hop. v8 types it server_error.+ assert observed["status"] == 200, observed+ assert outcome["served_source"] == "src_wire0001", outcome+ assert [len(calls) for calls in harness.requests] == [1, 1]+++async def test_responses_stream_with_zero_bytes_is_a_failed_turn(tmp_path, monkeypatch) -> None:+ async def handler(request, body):+ return await _stream(request, [])++ async with _through_engine(tmp_path, monkeypatch, "openai_responses", handler) as harness:+ url, body = _frontend_request("openai_responses", harness.hop, stream=True)+ observed = await _post(url, harness.hop, body)+ outcome = await harness.outcome()+ _record(tmp_path, {"observed": observed, "outcome": outcome})+ assert observed["status"] >= 400, observed+ assert outcome["provenance_outcome"] != "served", outcome++[email protected]("protocol", PROTOCOLS)+async def test_upstream_drop_mid_stream_is_not_a_clean_completion(tmp_path, monkeypatch, protocol) -> None:+ async def handler(request, body):+ return await _stream(request, _partial_frames(protocol), close="abort")++ async with _through_engine(tmp_path, monkeypatch, protocol, handler) as harness:+ url, body = _frontend_request(protocol, harness.hop, stream=True)+ observed = await _post(url, harness.hop, body)+ outcome = await harness.outcome()+ _record(tmp_path, {"protocol": protocol, "observed": observed, "tail": _frames(observed["raw"])[-3:],+ "outcome": outcome})+ assert "partial" in observed["raw"]+ assert outcome["provenance_outcome"] != "served", outcome+ if protocol == "openai_responses":+ # The in-stream shape of an incomplete Codex Responses stream (the+ # astra-style drop) is what Vibey's retry policy keys on.+ terminal = _json_frames(observed["raw"])[-1]+ assert terminal == {+ "type": "error",+ "error": {+ "code": "request_timeout",+ "message": "stream error: stream disconnected before completion: "+ "stream closed before response.completed",+ "param": None,+ "type": "server_error",+ },+ "sequence_number": 3,+ }, terminal++[email protected]("ending", ["done_marker", "eof", "finish_then_eof"])+async def test_chat_stream_terminal_depends_on_finish_reason(tmp_path, monkeypatch, ending) -> None:+ """A Chat stream is complete only when a chunk carried ``finish_reason``.++ The second request, sent at once to the same single-Source route with a+ healthy upstream, shows what an incomplete stream costs the next Turn.+ """+ frames = list(_partial_frames("openai_chat"))+ if ending == "done_marker":+ frames.append(b"data: [DONE]\n\n")+ elif ending == "finish_then_eof":+ frames += [_CHAT_FINISH, _CHAT_USAGE]+ healthy = await _healthy("openai_chat")+ calls = 0++ async def handler(request, body):+ nonlocal calls+ calls += 1+ return await (_stream(request, frames) if calls == 1 else healthy(request, body))++ async with _through_engine(tmp_path, monkeypatch, "openai_chat", handler) as harness:+ url, body = _frontend_request("openai_chat", harness.hop, stream=True)+ observed = await _post(url, harness.hop, body)+ outcome = await harness.outcome()+ harness.hop = await harness.router.resolve_hop("menu-alias", process_scope="vibey:wire", turn_id=_TURN + "-2")+ url, body = _frontend_request("openai_chat", harness.hop, stream=True)+ following = await _post(url, harness.hop, body)+ tail = _frames(observed["raw"])+ _record(tmp_path, {"ending": ending, "observed": observed, "tail": tail[-3:], "outcome": outcome,+ "next_request": {key: following[key] for key in ("status", "seconds", "transport_error")}+ | {"tail": _frames(following["raw"])[-2:]}})+ if ending == "finish_then_eof":+ assert tail[-1] == "[DONE]", tail+ assert outcome["provenance_outcome"] == "served", outcome+ else:+ assert "[DONE]" not in tail, tail+ assert any("error" in frame for frame in _json_frames(observed["raw"])), tail+ assert outcome["provenance_outcome"] != "served", outcome+ assert following["status"] == 200, following+++async def test_responses_stream_with_reasoning_and_tool_call(tmp_path, monkeypatch) -> None:+ """Reasoning summaries and a tool call pass through in order; the replay keeps its items."""+ async def handler(request, body):+ return await _stream(request, _responses_reasoning_tool_frames())++ replay = [+ {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "weather in 上海?"}]},+ {"type": "reasoning", "id": "rs_1", "status": "completed", "encrypted_content": _ENCRYPTED,+ "summary": [{"type": "summary_text", "text": "Checking the weather tool."}]},+ {"type": "function_call", "id": "fc_1", "status": "completed", "call_id": "call_fixture",+ "name": "weather", "arguments": "{\"city\":\"上海\"}"},+ {"type": "function_call_output", "call_id": "call_fixture", "output": "{\"temperature\":21}"},+ ]+ tools = [{"type": "function", "name": "weather", "description": "fixture",+ "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}]+ async with _through_engine(tmp_path, monkeypatch, "openai_responses", handler) as harness:+ url, body = _frontend_request("openai_responses", harness.hop, stream=True, extra={+ "tools": tools, "reasoning": {"effort": "high", "summary": "auto"},+ "include": ["reasoning.encrypted_content"],+ })+ first = await _post(url, harness.hop, body)+ second = await _post(url, harness.hop, {**body, "input": replay})+ outcome = await harness.outcome()+ events = _json_frames(first["raw"])+ types = [event.get("type") for event in events]+ completed = next((event for event in events if event.get("type") == "response.completed"), {})+ replayed = harness.requests[0][-1]["body"]["input"]+ _record(tmp_path, {"first_status": first["status"], "event_types": types,+ "completed_output": completed.get("response", {}).get("output"),+ "second_status": second["status"], "replayed_input_upstream": replayed,+ "outcome": outcome})+ assert first["status"] == 200, first+ assert types[0] == "response.created" and types[-1] == "response.completed", types+ assert types.count("response.reasoning_summary_text.delta") == 2, types+ assert types.count("response.function_call_arguments.delta") == 2, types+ assert types.index("response.reasoning_summary_text.done") < types.index("response.output_item.added", 2)+ assert [item["type"] for item in completed["response"]["output"]] == ["reasoning", "function_call"]+ assert second["status"] == 200, second+ reasoning, call = replayed[1], replayed[2]+ assert reasoning["id"] == "rs_1" and reasoning["encrypted_content"] == _ENCRYPTED, reasoning+ assert call["call_id"] == "call_fixture" and call["arguments"] == "{\"city\":\"上海\"}", call++[email protected]("protocol", PROTOCOLS)+async def test_consumer_cancel_closes_upstream_and_keeps_the_source(tmp_path, monkeypatch, protocol) -> None:+ """A consumer that stops reading cancels the upstream call and leaves the Source routable."""+ upstream_closed: asyncio.Future = asyncio.get_running_loop().create_future()+ healthy = await _healthy(protocol)+ calls = 0++ async def handler(request, body):+ nonlocal calls+ calls += 1+ if calls > 1:+ return await healthy(request, body)+ response = web.StreamResponse(headers={"Content-Type": "text/event-stream"})+ await response.prepare(request)+ frames = _partial_frames(protocol)+ try:+ for frame in frames:+ await response.write(frame)+ for _ in range(150):+ await asyncio.sleep(0.2)+ await response.write(frames[-1])+ except (ConnectionResetError, asyncio.CancelledError, RuntimeError):+ if not upstream_closed.done():+ upstream_closed.set_result(time.monotonic())+ raise+ return response++ async with _through_engine(tmp_path, monkeypatch, protocol, handler) as harness:+ url, body = _frontend_request(protocol, harness.hop, stream=True)+ async with aiohttp.ClientSession() as client:+ async with client.post(url, headers={"Authorization": f'Bearer {harness.hop["token"]}'},+ json=body) as response:+ assert response.status == 200+ await response.content.readuntil(b"partial")+ cancelled_at = time.monotonic()+ try:+ lag = round(await asyncio.wait_for(asyncio.shield(upstream_closed), timeout=10) - cancelled_at, 3)+ except asyncio.TimeoutError:+ lag = None+ again = await _post(url, harness.hop, body)+ state = harness.service.store.load().sources[0].state.status+ _record(tmp_path, {"protocol": protocol, "upstream_close_lag_seconds": lag, "next_status": again["status"],+ "source_status_after": state})+ assert lag is not None and lag < 2, lag+ assert again["status"] == 200, again+ assert state != "cooldown", state+++async def test_engine_stop_ends_open_streams_without_a_forced_kill(tmp_path, monkeypatch) -> None:+ """Stopping the engine (service shutdown, runtime disable) must not need SIGKILL while a stream is open."""+ signals: list[int] = []+ original = engine_supervisor.signal_process_tree++ def recording(process, sig, *args, **kwargs):+ signals.append(int(sig))+ return original(process, sig, *args, **kwargs)++ monkeypatch.setattr(engine_supervisor, "signal_process_tree", recording)++ async def handler(request, body):+ response = web.StreamResponse(headers={"Content-Type": "text/event-stream"})+ await response.prepare(request)+ frames = _partial_frames("openai_chat")+ try:+ for _ in range(300):+ await response.write(frames[-1])+ await asyncio.sleep(0.2)+ except (ConnectionResetError, asyncio.CancelledError, RuntimeError):+ raise+ return response++ async with _through_engine(tmp_path, monkeypatch, "openai_chat", handler) as harness:+ connection = harness.adapter.supervisor.client_if_running().connection+ url = connection.base_url + "/v1/chat/completions"+ body = {"model": f'{harness.adapter.state_store.list_sources()[0].prefix}/{MODEL}', "stream": True,+ "messages": [{"role": "user", "content": "x"}]}+ async with aiohttp.ClientSession() as client:+ async with client.post(url, headers={"Authorization": f"Bearer {connection.gateway_token}"},+ json=body) as response:+ assert response.status == 200, await response.text()+ await response.content.readuntil(b"partial")+ started = time.monotonic()+ await asyncio.to_thread(harness.adapter.supervisor.stop)+ stop_seconds = round(time.monotonic() - started, 3)+ try:+ await asyncio.wait_for(response.content.read(), timeout=5)+ stream_end = "eof"+ except aiohttp.ClientPayloadError:+ stream_end = "payload_error"+ except asyncio.TimeoutError:+ stream_end = "still_open"+ _record(tmp_path, {"signals": signals, "stop_seconds": stop_seconds, "stream_end": stream_end})+ assert signals == [int(signal.SIGTERM)], signals+ assert stream_end != "still_open"diff --git a/tests/e2e/test_model_hub_google_chat.py b/tests/e2e/test_model_hub_google_chat.pyindex 7aae9339b..22b981995 100644--- a/tests/e2e/test_model_hub_google_chat.py+++ b/tests/e2e/test_model_hub_google_chat.py@@ -84,7 +84,7 @@ def _gemini_reply(parts, finish="STOP", *, usage=True):@asynccontextmanager-async def _chat_gateway(tmp_path, monkeypatch, upstream, *, model="gemini-3-pro-preview"):+async def _chat_gateway(tmp_path, monkeypatch, upstream, *, model="gemini-3-pro-preview", complete=True):with _isolated_engine_adapter(tmp_path, monkeypatch) as adapter:async with _server(upstream) as root:source = _source("src_google001", "Gemini fixture", vendor="custom", protocol="google", model_id=model)@@ -122,7 +122,10 @@ async def _chat_gateway(tmp_path, monkeypatch, upstream, *, model="gemini-3-pro-if not stream:return [json.loads(raw)]data = [line[5:].strip() for line in raw.splitlines() if line.startswith(b"data:")]- assert data[-1] == b"[DONE]", raw+ # A Chat stream is complete only when a chunk carried+ # finish_reason: CPA ends it with [DONE], otherwise+ # with an error frame.+ assert (data[-1] == b"[DONE]") is complete, rawreturn [json.loads(frame) for frame in data if frame != b"[DONE]"]yield post@@ -132,6 +135,9 @@ async def _chat_gateway(tmp_path, monkeypatch, upstream, *, model="gemini-3-pro-if completion:await completionrecord = service.provenance.get("chat-gemini")+ if not complete:+ assert record["outcome"] != "served", record+ returnassert record["outcome"] == "served", recordassert record["served"]["origin"] == originassert record["failed_attempts"] == []@@ -279,7 +285,7 @@ async def test_chat_google_tool_round_trip_loses_signature_but_explicit_carrier_"missing_finish", "missing_finish_and_usage",])async def test_chat_google_stream_terminal_boundaries(tmp_path, monkeypatch, ending):- """Without traceId, split finish/usage is lost; CPA's [DONE] is not semantic proof."""+ """Without traceId, split finish/usage is lost, and CPA ends that stream with an error."""requests = []content = _gemini_reply([{"text": "streamed answer"}], usage=False)content["candidates"][0].pop("finishReason")@@ -298,7 +304,8 @@ async def test_chat_google_stream_terminal_boundaries(tmp_path, monkeypatch, endframes = [content] + tails[ending]return web.Response(body=b"".join(_sse(frame) for frame in frames), content_type="text/event-stream")- async with _chat_gateway(tmp_path, monkeypatch, upstream) as post:+ complete = ending == "same_frame"+ async with _chat_gateway(tmp_path, monkeypatch, upstream, complete=complete) as post:frames = await post([{"role": "user", "content": "Finish boundary fixture"}],stream=True, stream_options={"include_usage": True},@@ -307,7 +314,7 @@ async def test_chat_google_stream_terminal_boundaries(tmp_path, monkeypatch, endassert requests[0][0].endswith(":streamGenerateContent")reasons = [(choice.get("finish_reason"), choice.get("native_finish_reason"))- for frame in frames for choice in frame["choices"]+ for frame in frames for choice in frame.get("choices", [])if choice.get("finish_reason") is not None]# CPA filters usage on frames without their own finishReason, then the@@ -316,3 +323,8 @@ async def test_chat_google_stream_terminal_boundaries(tmp_path, monkeypatch, endassert reasons == expected, framesusages = [frame["usage"] for frame in frames if "usage" in frame]assert usages == ([CHAT_USAGE] if ending == "same_frame" else []), frames+ if not complete:+ assert frames[-1] == {"error": {+ "message": "upstream stream closed before any chunk carried finish_reason",+ "type": "server_error", "code": "internal_server_error",+ }}, framesdiff --git a/tests/scenarios/auth_setup/catalog.yaml b/tests/scenarios/auth_setup/catalog.yamlindex 0db00cd1d..bbb7f599f 100644--- a/tests/scenarios/auth_setup/catalog.yaml+++ b/tests/scenarios/auth_setup/catalog.yaml@@ -527,4 +527,25 @@ scenarios:- ui/src/components/onboarding/BuiltinAssistant.test.tsx- ui/src/components/onboarding/entryGate.test.ts- ui/e2e/onboarding-fidelity/lineup.spec.ts+ - id: AUTH-SETUP-130+ name: "Occupied vendor callback port: OAuth start succeeds and the pasted callback completes the login"+ status: partial+ kind: negative_path+ layer: scenario+ missing_layer: live-vendor-e2e+ backend: shared+ reason: >-+ The engine relays a redirect login's callback through a forwarder on the+ vendor's fixed loopback port (54545 Claude, 1455 Codex, 51121 Antigravity).+ When something else holds that port, the start used to fail with a 500; the+ engine now starts the login anyway and waits for the pasted callback that+ Avibe always offers. The closed loop ends in the vendor's token exchange,+ which cannot run hermetically, so the engine half and Avibe's paste half are+ pinned separately and no harness case duplicates the paste scenario.+ owning_layer: L4 integrated acceptance (real engine and a real vendor sign-in)+ partial_evidence:+ covers: the engine half at the real engine — with Claude's port taken the start succeeds and the session waits for a pasted callback, and Codex's forwarder listens on 127.0.0.1 only; it runs where AVIBE_E2E_ISOLATED_NETWORK=1, because it binds the vendors' fixed ports+ test: tests/e2e/test_model_hub_engine_contract.py::test_oauth_callback_forwarder_is_loopback_only_and_optional+ supporting_tests:+ - tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_hub_oauth_mispaste_stays_recoverable_and_schemeless_address_signs_innext_priority: []diff --git a/tests/test_model_hub_api.py b/tests/test_model_hub_api.pyindex d9f49c0e5..1c0650d18 100644--- a/tests/test_model_hub_api.py+++ b/tests/test_model_hub_api.py@@ -1018,6 +1018,8 @@ def test_runtime_status_reports_packaged_engine_manifest(tmp_path):"darwin-x64","linux-amd64","linux-arm64",+ "windows-amd64",+ "windows-arm64",]@@ -1774,7 +1776,7 @@ def test_runtime_install_rejects_unsupported_server_host_without_mutation(monkeypatch.setattr("core.managed_runtime.runtime_platform_tag",- lambda: "win32-x64",+ lambda: "linux-riscv64",)service = ModelHubService(store=MemoryStore(),diff --git a/tests/test_model_hub_engine_build.py b/tests/test_model_hub_engine_build.pyindex 6ba7e739b..061022db8 100644--- a/tests/test_model_hub_engine_build.py+++ b/tests/test_model_hub_engine_build.py@@ -14,22 +14,36 @@ from scripts import model_hub_engine_release_guard as guard# Independent fixture contract: do not derive names, contents, or expected# digests from builder constants or a previous invocation of the builder.-FIXTURE_MEMBERS = {- "cli-proxy-api": b"CLIProxyAPI v7.3.16",+FIXTURE_BINARY = b"CLIProxyAPI v7.3.16"+FIXTURE_DOCUMENTS = {"LICENSE": b"LICENSE","README.md": b"README.md","README_CN.md": b"README_CN.md","config.example.yaml": b"config.example.yaml",}+# platform -> (asset arch, GOOS, GOARCH, binary member)FIXTURE_TARGETS = {- "darwin-arm64": "darwin_aarch64",- "darwin-x64": "darwin_amd64",- "linux-amd64": "linux_amd64",- "linux-arm64": "linux_aarch64",+ "darwin-arm64": ("darwin_aarch64", "darwin", "arm64", "cli-proxy-api"),+ "darwin-x64": ("darwin_amd64", "darwin", "amd64", "cli-proxy-api"),+ "linux-amd64": ("linux_amd64", "linux", "amd64", "cli-proxy-api"),+ "linux-arm64": ("linux_aarch64", "linux", "arm64", "cli-proxy-api"),+ "windows-amd64": ("windows_amd64", "windows", "amd64", "cli-proxy-api.exe"),+ "windows-arm64": ("windows_aarch64", "windows", "arm64", "cli-proxy-api.exe"),}+# USTAR fixture: the binary member then the documents above, epoch 123, root+# ownership, 0755 executable/0644 docs; gzip mtime 0. Keyed by binary member.+FIXTURE_ARCHIVES = {+ "cli-proxy-api": (234, "fb13ef1030f49b5b64993f9596a227ac519b38d637b1a61fa95d3c73fc3d5ab8"),+ "cli-proxy-api.exe": (237, "b6dca6c7afaf0e6be1958edf957bfcfb702e4a420019a119b8c6470b9566a37a"),+}+++def _patch(path: Path, *lines: str) -> Path:+ path.write_text("\n".join([*lines, ""]), encoding="utf-8")+ return path-def _manifest(tmp_path: Path, *, source_sha: str, patch: Path) -> Path:+def _manifest(tmp_path: Path, *, source_sha: str, patches: list[Path]) -> Path:version = "v7.3.16"release_tag = "model-hub-engine-v7.3.16-3"assets = [@@ -39,14 +53,12 @@ def _manifest(tmp_path: Path, *, source_sha: str, patch: Path) -> Path:f"{guard.OWNED_RELEASE_ROOT}/{release_tag}/"f"CLIProxyAPI_7.3.16_{asset_arch}.tar.gz"),- # USTAR fixture: members above in declared order, epoch 123,- # root ownership, 0755 executable/0644 docs; gzip mtime 0.- "size_bytes": 234,- "sha256": "fb13ef1030f49b5b64993f9596a227ac519b38d637b1a61fa95d3c73fc3d5ab8",+ "size_bytes": FIXTURE_ARCHIVES[binary_name][0],+ "sha256": FIXTURE_ARCHIVES[binary_name][1],"binary_sha256": "0e18ced596a1e68e5dfdcc5c8bf98668f405061aeca0fc2a4501aeeeeebf809d",- "bin_path": "cli-proxy-api",+ "bin_path": binary_name,}- for platform, asset_arch in FIXTURE_TARGETS.items()+ for platform, (asset_arch, _goos, _goarch, binary_name) in FIXTURE_TARGETS.items()]path = tmp_path / "manifest.json"path.write_text(@@ -65,8 +77,10 @@ def _manifest(tmp_path: Path, *, source_sha: str, patch: Path) -> Path:"build": {"go_version": "go1.26.0","source_date_epoch": 123,- "patch": patch.name,- "patch_sha256": hashlib.sha256(patch.read_bytes()).hexdigest(),+ "patches": [+ {"path": patch.name, "sha256": hashlib.sha256(patch.read_bytes()).hexdigest()}+ for patch in patches+ ],},}),@@ -77,9 +91,9 @@ def _manifest(tmp_path: Path, *, source_sha: str, patch: Path) -> Path:@pytest.mark.parametrize(("patch_mode", "wrong_pinned_size"),- [("explicit", False), ("default", False), ("explicit", True), ("changed", False)],+ [("pinned", False), ("pinned", True), ("changed", False)],)-def test_build_source_release_applies_patch_and_materializes_four_targets(+def test_build_source_release_applies_patches_in_order_and_materializes_six_targets(tmp_path: Path,monkeypatch,wrong_pinned_size: bool,@@ -87,9 +101,8 @@ def test_build_source_release_applies_patch_and_materializes_four_targets() -> None:source = tmp_path / "source"(source / "cmd" / "server").mkdir(parents=True)- for name, data in FIXTURE_MEMBERS.items():- if name != "cli-proxy-api":- (source / name).write_bytes(data)+ for name, data in FIXTURE_DOCUMENTS.items():+ (source / name).write_bytes(data)subprocess.run(["git", "init", "--quiet", str(source)], check=True)subprocess.run(["git", "-C", str(source), "config", "user.email", "[email protected]"],@@ -108,27 +121,34 @@ def test_build_source_release_applies_patch_and_materializes_four_targets(["git", "-C", str(source), "rev-parse", "HEAD"],text=True,).strip()- patch = tmp_path / "compat.patch"- patch.write_text(- "\n".join(- [- "diff --git a/patched-marker.txt b/patched-marker.txt",- "new file mode 100644",- "--- /dev/null",- "+++ b/patched-marker.txt",- "@@ -0,0 +1 @@",- "+patched",- "",- ]+ # The second patch edits the file the first creates, so it applies only in+ # the recorded order.+ patches = [+ _patch(+ tmp_path / "first.patch",+ "diff --git a/patched-marker.txt b/patched-marker.txt",+ "new file mode 100644",+ "--- /dev/null",+ "+++ b/patched-marker.txt",+ "@@ -0,0 +1 @@",+ "+patched",),- encoding="utf-8",- )- manifest = _manifest(tmp_path, source_sha=source_sha, patch=patch)+ _patch(+ tmp_path / "second.patch",+ "diff --git a/patched-marker.txt b/patched-marker.txt",+ "--- a/patched-marker.txt",+ "+++ b/patched-marker.txt",+ "@@ -1 +1 @@",+ "-patched",+ "+patched twice",+ ),+ ]+ manifest = _manifest(tmp_path, source_sha=source_sha, patches=patches)monkeypatch.setattr(builder, "REPO_ROOT", tmp_path)if patch_mode == "changed":# A provenance-only change leaves all compiled/archive bytes intact.# Output hash validation alone cannot detect this changed build input.- patch.write_bytes(b"# changed provenance\n" + patch.read_bytes())+ patches[1].write_bytes(b"# changed provenance\n" + patches[1].read_bytes())if wrong_pinned_size:pinned = json.loads(manifest.read_text(encoding="utf-8"))pinned["assets"][0]["size_bytes"] = 1@@ -141,22 +161,21 @@ def test_build_source_release_applies_patch_and_materializes_four_targets(if command[:2] == ["go", "version"]:return "go version go1.26.0 darwin/arm64\n"if command[:2] == ["go", "build"]:- assert (cwd / "patched-marker.txt").read_text(encoding="utf-8") == "patched\n"+ assert (cwd / "patched-marker.txt").read_text(encoding="utf-8") == "patched twice\n"binary = Path(command[command.index("-o") + 1])- binary.write_bytes(FIXTURE_MEMBERS["cli-proxy-api"])+ binary.write_bytes(FIXTURE_BINARY)return ""- if command[0].endswith("cli-proxy-api") and command[1:] == ["--help"]:+ if Path(command[0]).name.startswith("cli-proxy-api") and command[1:] == ["--help"]:return "CLIProxyAPI Version: v7.3.16, Commit: fixture\n"return real_run(command, cwd=cwd, env=env)monkeypatch.setattr(builder, "_run", fake_run)output = tmp_path / "output"if patch_mode == "changed":- with pytest.raises(builder.BuildError, match="patch.*checksum"):+ with pytest.raises(builder.BuildError, match="patch.*checksum.*second.patch"):builder.build_source_release(manifest,output,- patch_path=patch,source_repository=str(source),)assert not commands@@ -166,7 +185,6 @@ def test_build_source_release_applies_patch_and_materializes_four_targets(builder.build_source_release(manifest,output,- patch_path=patch,source_repository=str(source),go_binary="go",)@@ -177,30 +195,29 @@ def test_build_source_release_applies_patch_and_materializes_four_targets(output,source_repository=str(source),go_binary="go",- **({"patch_path": patch} if patch_mode == "explicit" else {}),)- assert {path.name for path in output.glob("*.tar.gz")} == {- f"CLIProxyAPI_7.3.16_{arch}.tar.gz" for arch in FIXTURE_TARGETS.values()- }- for archive in output.glob("*.tar.gz"):- with tarfile.open(archive, "r:gz") as bundle:- assert bundle.getnames() == list(FIXTURE_MEMBERS)+ for asset_arch, _goos, _goarch, binary_name in FIXTURE_TARGETS.values():+ with tarfile.open(output / f"CLIProxyAPI_7.3.16_{asset_arch}.tar.gz", "r:gz") as bundle:+ expected = {binary_name: FIXTURE_BINARY, **FIXTURE_DOCUMENTS}+ assert bundle.getnames() == list(expected)for member in bundle.getmembers():assert member.isfile()- assert member.mode == (0o755 if member.name == "cli-proxy-api" else 0o644)+ assert member.mode == (0o755 if member.name == binary_name else 0o644)assert member.mtime == 123assert (member.uid, member.gid, member.uname, member.gname) == (0, 0, "", "")- assert bundle.extractfile(member).read() == FIXTURE_MEMBERS[member.name]+ assert bundle.extractfile(member).read() == expected[member.name]assert generated_manifest.read_bytes() == manifest.read_bytes()- assert any(command[:3] == ["git", "apply", "--whitespace=error"] for command, _ in commands)+ assert [command[3] for command, _ in commands if command[:3] == ["git", "apply", "--whitespace=error"]] == [+ str(patch.resolve()) for patch in patches+ ]+ build_commands = [command for command, _ in commands if command[:2] == ["go", "build"]]build_envs = [env for command, env in commands if command[:2] == ["go", "build"]]- assert len(build_envs) == 4- assert {(env["GOOS"], env["GOARCH"]) for env in build_envs} == {- ("darwin", "arm64"), ("darwin", "amd64"), ("linux", "amd64"), ("linux", "arm64"),- }+ assert sorted(+ (env["GOOS"], env["GOARCH"], Path(command[command.index("-o") + 1]).name)+ for command, env in zip(build_commands, build_envs)+ ) == sorted((goos, goarch, binary_name) for _arch, goos, goarch, binary_name in FIXTURE_TARGETS.values())assert {env["CGO_ENABLED"] for env in build_envs} == {"0"}- build_commands = [command for command, _ in commands if command[:2] == ["go", "build"]]assert all("-ldflags" in command and "-X main.Version=v7.3.16" in commandfor command in build_commandsdiff --git a/tests/test_model_hub_engine_release_guard.py b/tests/test_model_hub_engine_release_guard.pyindex 7630bebc8..bed6f5068 100644--- a/tests/test_model_hub_engine_release_guard.py+++ b/tests/test_model_hub_engine_release_guard.py@@ -14,11 +14,11 @@ from scripts import build_model_hub_enginefrom scripts import model_hub_engine_release_guard as guard-def _archive(binary: bytes) -> bytes:+def _archive(binary: bytes, bin_path: str) -> bytes:output = io.BytesIO()with gzip.GzipFile(fileobj=output, mode="wb", filename="", mtime=0) as compressed:with tarfile.open(fileobj=compressed, mode="w") as bundle:- member = tarfile.TarInfo("cli-proxy-api")+ member = tarfile.TarInfo(bin_path)member.mode = 0o755member.size = len(binary)bundle.addfile(member, io.BytesIO(binary))@@ -29,15 +29,15 @@ def _manifest(tmp_path: Path) -> tuple[Path, dict[str, bytes], dict[str, bytes]]version = "v7.2.149"asset_release_tag = "model-hub-engine-v7.2.149-1"owned_root = f"{guard.OWNED_RELEASE_ROOT}/{asset_release_tag}"- upstream_root = f"{guard.UPSTREAM_RELEASE_ROOT}/{version}"source_sha = "2a6b87aca083a5bf498ac1f68a1b636c500d7aaa"owned: dict[str, bytes] = {}- upstream: dict[str, bytes] = {}+ built: dict[str, bytes] = {}assets = []for platform in sorted(guard.EXPECTED_PLATFORMS):upstream_platform = guard.UPSTREAM_PLATFORM_NAMES[platform]name = f"CLIProxyAPI_7.2.149_{upstream_platform}.tar.gz"- archive = _archive(f"{platform}-binary".encode())+ bin_path = "cli-proxy-api.exe" if platform.startswith("windows-") else "cli-proxy-api"+ archive = _archive(f"{platform}-binary".encode(), bin_path)archive_sha = hashlib.sha256(archive).hexdigest()binary_sha = hashlib.sha256(f"{platform}-binary".encode()).hexdigest()url = f"{owned_root}/{name}"@@ -48,12 +48,12 @@ def _manifest(tmp_path: Path) -> tuple[Path, dict[str, bytes], dict[str, bytes]]"size_bytes": len(archive),"sha256": archive_sha,"binary_sha256": binary_sha,- "bin_path": "cli-proxy-api",+ "bin_path": bin_path,})owned[url] = archiveowned[f"{url}.sha256"] = f"{archive_sha} {name}\n".encode()- upstream[f"{upstream_root}/{name}"] = archive+ built[name] = archivepayload = {"schema_version": 1,@@ -70,7 +70,7 @@ def _manifest(tmp_path: Path) -> tuple[Path, dict[str, bytes], dict[str, bytes]]manifest_path = tmp_path / "cliproxyapi_manifest.json"manifest_path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")owned[f"{owned_root}/model-hub-engine-manifest.json"] = manifest_path.read_bytes()- return manifest_path, owned, upstream+ return manifest_path, owned, builtdef _fake_download(remote: dict[str, bytes]):@@ -88,7 +88,7 @@ def test_fetch_owned_release_materializes_exact_verified_assets(tmp_path: Path,monkeypatch: pytest.MonkeyPatch,) -> None:- manifest_path, owned, _upstream = _manifest(tmp_path)+ manifest_path, owned, _built = _manifest(tmp_path)monkeypatch.setattr(guard, "_download", _fake_download(owned))spec = guard.fetch_release_assets(manifest_path, tmp_path / "backup")@@ -104,7 +104,7 @@ def test_fetch_source_verifies_upstream_bytes_and_builds_publishable_release(tmp_path: Path,monkeypatch: pytest.MonkeyPatch,) -> None:- manifest_path, _owned, upstream = _manifest(tmp_path)+ manifest_path, _owned, built = _manifest(tmp_path)def build_source(manifest: Path, output: Path) -> Path:output.mkdir()output_manifest = output / "model-hub-engine-manifest.json"@@ -112,9 +112,7 @@ def test_fetch_source_verifies_upstream_bytes_and_builds_publishable_release(payload = json.loads(manifest.read_text(encoding="utf-8"))for raw in payload["assets"]:name = Path(raw["url"]).name- archive = upstream[- f"{guard.UPSTREAM_RELEASE_ROOT}/{payload['release_tag']}/{name}"- ]+ archive = built[name](output / name).write_bytes(archive)(output / f"{name}.sha256").write_text(f"{hashlib.sha256(archive).hexdigest()} {name}\n",@@ -143,7 +141,7 @@ def test_verify_rejects_changed_release_bytes(mutate,match,) -> None:- manifest_path, owned, _upstream = _manifest(tmp_path)+ manifest_path, owned, _built = _manifest(tmp_path)monkeypatch.setattr(guard, "_download", _fake_download(owned))backup = tmp_path / "backup"guard.fetch_release_assets(manifest_path, backup)@@ -160,7 +158,7 @@ def test_verify_rejects_non_release_entries(monkeypatch: pytest.MonkeyPatch,entry_kind: str,) -> None:- manifest_path, owned, _upstream = _manifest(tmp_path)+ manifest_path, owned, _built = _manifest(tmp_path)monkeypatch.setattr(guard, "_download", _fake_download(owned))backup = tmp_path / "backup"guard.fetch_release_assets(manifest_path, backup)@@ -179,7 +177,7 @@ def test_failed_fetch_preserves_last_verified_backup(tmp_path: Path,monkeypatch: pytest.MonkeyPatch,) -> None:- manifest_path, owned, _upstream = _manifest(tmp_path)+ manifest_path, owned, _built = _manifest(tmp_path)del owned[next(url for url in owned if url.endswith(".tar.gz"))]monkeypatch.setattr(guard, "_download", _fake_download(owned))backup = tmp_path / "backup"@@ -194,7 +192,7 @@ def test_failed_fetch_preserves_last_verified_backup(def test_manifest_rejects_non_owned_release_url(tmp_path: Path) -> None:- manifest_path, _owned, _upstream = _manifest(tmp_path)+ manifest_path, _owned, _built = _manifest(tmp_path)payload = json.loads(manifest_path.read_text(encoding="utf-8"))payload["assets"][0]["url"] = ("https://github.com/router-for-me/CLIProxyAPI/releases/download/"@@ -206,6 +204,24 @@ def test_manifest_rejects_non_owned_release_url(tmp_path: Path) -> None:guard.load_release_spec(manifest_path)+ ("platform", "bin_path"),+ [("windows-amd64", "cli-proxy-api"), ("linux-amd64", "cli-proxy-api.exe"), ("darwin-arm64", "bin/cli-proxy-api")],+)+def test_manifest_pins_the_engine_binary_name_per_platform(+ tmp_path: Path, platform: str, bin_path: str,+) -> None:+ # Windows resolves an extensionless path by appending .exe, so a Windows+ # asset must name the .exe member and no other asset may.+ manifest_path, _owned, _built = _manifest(tmp_path)+ payload = json.loads(manifest_path.read_text(encoding="utf-8"))+ next(asset for asset in payload["assets"] if asset["platform"] == platform)["bin_path"] = bin_path+ manifest_path.write_text(json.dumps(payload), encoding="utf-8")++ with pytest.raises(guard.ReleaseGuardError, match="bin_path is invalid"):+ guard.load_release_spec(manifest_path)++@pytest.mark.parametrize("remote_state",["valid", "missing", "extra", "corrupt", "bad_upload", "published", "download_once", "unavailable"],@@ -216,7 +232,7 @@ def test_draft_publication_repairs_exact_asset_set_before_becoming_public(# Contract: either publish the exact pinned bytes, or preserve the draft.# The old workflow deleted only expected names, so an extra asset survived# every recovery. Source-text assertions never exercised this transition.- manifest, owned, _upstream = _manifest(tmp_path)+ manifest, owned, _built = _manifest(tmp_path)monkeypatch.setattr(guard, "_download", _fake_download(owned))verified = tmp_path / "verified"guard.fetch_release_assets(manifest, verified)diff --git a/tests/test_model_hub_runtime.py b/tests/test_model_hub_runtime.pyindex 69c35c57a..f78c7a289 100644--- a/tests/test_model_hub_runtime.py+++ b/tests/test_model_hub_runtime.py@@ -890,37 +890,54 @@ def test_packaged_manifest_matches_frozen_runtime_dependency_values(assert manifest == {"name": "cliproxyapi","resolution": "resolved",- "version": "v7.3.16",- "source_sha": "c404af96ebacedf8168b3c2bdbf4449a21cd1c1e",+ "version": "v8.0.23",+ "source_sha": "d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5","assets": [{"platform": "darwin-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v7.3.16-3/CLIProxyAPI_7.3.16_darwin_aarch64.tar.gz",- "size_bytes": 39534924,- "sha256": "bc046156ac880beb1c09b2b69a8f80513ce3caec92f34fbc00dbf8aaf2c91754",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_darwin_aarch64.tar.gz",+ "size_bytes": 40511180,+ "sha256": "bd863d04d950390b745dd4414ea8c8be715cb5c21b492d3c0d71504f64fca978",},{"platform": "darwin-x64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v7.3.16-3/CLIProxyAPI_7.3.16_darwin_amd64.tar.gz",- "size_bytes": 41928346,- "sha256": "6cdc647a2bb0ccc8d179f290cb1f90da28ef3d02e7c2d6aa96f5903760a78328",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_darwin_amd64.tar.gz",+ "size_bytes": 42973748,+ "sha256": "eda0092a9d1afecf8471fc95e4c077825a3db8059df7caa6a06816a2a8a438eb",},{"platform": "linux-amd64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v7.3.16-3/CLIProxyAPI_7.3.16_linux_amd64.tar.gz",- "size_bytes": 39894112,- "sha256": "88e0843bb5eaecb2748ff7fc5c4d61d301927ccd0aec7b35b1e20efc551957e9",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_linux_amd64.tar.gz",+ "size_bytes": 40932246,+ "sha256": "e72351f5280f943233c9ddc8ab9f51556f57e9f95d68bf13a15b141a95e48b65",},{"platform": "linux-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v7.3.16-3/CLIProxyAPI_7.3.16_linux_aarch64.tar.gz",- "size_bytes": 36618378,- "sha256": "a289bbc2d409e5a54a2f65c9d331f7e968b0f18fba2f3b56477a30a2a3c08c3a",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_linux_aarch64.tar.gz",+ "size_bytes": 37548183,+ "sha256": "ca06e508c654d6c8cfc5af44341eeac339e0a033d217a480c44043b8e8c81ebc",+ },+ {+ "platform": "windows-amd64",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_windows_amd64.tar.gz",+ "size_bytes": 41444644,+ "sha256": "7d138744b44a7ee103f15d065712f97798db0259cdafce2a93819b4135b69006",+ },+ {+ "platform": "windows-arm64",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_windows_aarch64.tar.gz",+ "size_bytes": 37803078,+ "sha256": "969997f1dbe169c83e227def75ca51e105aafb9f3d30bb3bb615685fc289b525",},],}- monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "win32-x64")+ for host_platform, asset_platform in (("win32-x64", "windows-amd64"), ("win32-arm64", "windows-arm64")):+ monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda tag=host_platform: tag)+ assert manager.host_platform() == asset_platform+ assert manager.supports_host_platform() is True++ monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "linux-riscv64")unsupported = EngineRuntimeManager(runtime_dir=tmp_path / "unsupported-runtime",offline=True,@@ -936,12 +953,12 @@ def test_contract_manifest_filters_unsupported_override_assets(payload = json.loads(Path("vibe/model_hub_runtime/cliproxyapi_manifest.json").read_text(encoding="utf-8"))payload["assets"].append({- "platform": "win32-x64",- "url": "https://example.test/unsupported.zip",+ "platform": "linux-riscv64",+ "url": "https://example.test/unsupported.tar.gz","size_bytes": 1,"sha256": "1" * 64,"binary_sha256": "2" * 64,- "bin_path": "cli-proxy-api.exe",+ "bin_path": "cli-proxy-api",})manifest_path = tmp_path / "override.json"@@ -952,9 +969,9 @@ def test_contract_manifest_filters_unsupported_override_assets(offline=True,)- assert "win32-x64" not in {asset["platform"] for asset in manager.contract_manifest()["assets"]}+ assert "linux-riscv64" not in {asset["platform"] for asset in manager.contract_manifest()["assets"]}- monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "win32-x64")+ monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "linux-riscv64")assert manager.supports_host_platform() is Falseunsupported = manager.ensure()assert unsupported["ok"] is False@@ -998,7 +1015,7 @@ def test_foreign_pointer_inspection_cannot_hide_an_unsupported_host(json.dumps({"platform": "linux-amd64"}),encoding="utf-8",)- monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "win32-x64")+ monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "linux-riscv64")manager = EngineRuntimeManager(runtime_dir=runtime_dir, offline=True)status = manager.status()@@ -1311,7 +1328,7 @@ def test_manifest_resolution_drives_admission_persistence_and_schema()else:if resolution is ManifestResolution.UNSUPPORTED:- monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "win32-x64")+ monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "linux-riscv64")elif resolution is not ManifestResolution.RESOLVED:raise AssertionError(f"unmodelled manifest resolution: {resolution}")manager = EngineRuntimeManager(@@ -1406,35 +1423,55 @@ def test_installing_projection_matches_live_owner_or_resumable_claim(@pytest.mark.parametrize(- ("host_platform", "asset_platform", "size_bytes", "archive_sha256", "binary_sha256"),+ ("host_platform", "asset_platform", "size_bytes", "archive_sha256", "binary_sha256", "bin_path"),[("darwin-arm64","darwin-arm64",- 39534924,- "bc046156ac880beb1c09b2b69a8f80513ce3caec92f34fbc00dbf8aaf2c91754",- "bfd39d09fd0f5f922ba5cd1a6d86cb86b928e31bcf1746cb763f5632af13c068",+ 40511180,+ "bd863d04d950390b745dd4414ea8c8be715cb5c21b492d3c0d71504f64fca978",+ "f953540b126b220352bb66991e9f8d1c29cf18054f4c75f17e49a7d73fb17e19",+ "cli-proxy-api",),("darwin-x64","darwin-x64",- 41928346,- "6cdc647a2bb0ccc8d179f290cb1f90da28ef3d02e7c2d6aa96f5903760a78328",- "dc1339f5a5a50d7b8254c1b1662177beb9a597aab04ba647ee9b6f555de1b87d",+ 42973748,+ "eda0092a9d1afecf8471fc95e4c077825a3db8059df7caa6a06816a2a8a438eb",+ "f279440f5689b15f322bb9c4116fcf8434d0b48bfcac2c2f2e089557e6f59f36",+ "cli-proxy-api",),("linux-x64","linux-amd64",- 39894112,- "88e0843bb5eaecb2748ff7fc5c4d61d301927ccd0aec7b35b1e20efc551957e9",- "8c500c984e056a2b191c8a3a2780062ca447659244d7b62b9544c5a4af29b0de",+ 40932246,+ "e72351f5280f943233c9ddc8ab9f51556f57e9f95d68bf13a15b141a95e48b65",+ "fa7fa7cd0289a4912587764c535adcd06a41fe1fb0dc92193925883bbfe8b3a1",+ "cli-proxy-api",),("linux-arm64","linux-arm64",- 36618378,- "a289bbc2d409e5a54a2f65c9d331f7e968b0f18fba2f3b56477a30a2a3c08c3a",- "9ddb102bbd6b80c2651e5eb2939840142efb8068e802521ae0c1eac3877a84b9",+ 37548183,+ "ca06e508c654d6c8cfc5af44341eeac339e0a033d217a480c44043b8e8c81ebc",+ "5a514166e95e35b53a846030ab3cb4af5a1c52c06df2c3db8c764adde1bc6178",+ "cli-proxy-api",+ ),+ (+ "win32-x64",+ "windows-amd64",+ 41444644,+ "7d138744b44a7ee103f15d065712f97798db0259cdafce2a93819b4135b69006",+ "c265136d64bc6fdb7a4737e28333ff58ed995407d50b0581857e6693a2952a32",+ "cli-proxy-api.exe",+ ),+ (+ "win32-arm64",+ "windows-arm64",+ 37803078,+ "969997f1dbe169c83e227def75ca51e105aafb9f3d30bb3bb615685fc289b525",+ "0ba1b87a3c562f5121f2902507e6608713237a3daafa229bca5b4829b29c29ec",+ "cli-proxy-api.exe",),],)@@ -1446,6 +1483,7 @@ def test_engine_installer_selects_verified_packaged_asset(size_bytes: int,archive_sha256: str,binary_sha256: str,+ bin_path: str,) -> None:monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: host_platform)manager = EngineRuntimeManager(runtime_dir=tmp_path / host_platform, offline=True)@@ -1459,6 +1497,7 @@ def test_engine_installer_selects_verified_packaged_asset(assert archive.size == size_bytesassert archive.sha256 == archive_sha256assert archive.binary_sha256 == binary_sha256+ assert archive.bin_path == bin_pathdef test_engine_platform_identity_is_normalized_locally() -> None:@@ -5332,7 +5371,7 @@ def test_platform_refusal_never_creates_or_settles_an_install_claim(async def run() -> None:archive, binary = _write_fixture_archive(tmp_path / "fixture")manifest_path = _write_fixture_manifest(tmp_path / "fixture", archive, binary)- monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "win32-x64")+ monkeypatch.setattr(managed_runtime, "runtime_platform_tag", lambda: "linux-riscv64")installer = EngineRuntimeManager(runtime_dir=tmp_path / "runtime",manifest_path=manifest_path,diff --git a/ui/src/components/settings/models/types.ts b/ui/src/components/settings/models/types.tsindex 1f9ba53c9..a269e02a3 100644--- a/ui/src/components/settings/models/types.ts+++ b/ui/src/components/settings/models/types.ts@@ -741,7 +741,7 @@ export type OAuthFlow = {export type RuntimeHealth = 'ok' | 'degraded' | 'down' | 'not_started' | 'not_installed' | 'installing';type RuntimeManifestAsset = {- platform: 'darwin-arm64' | 'darwin-x64' | 'linux-amd64' | 'linux-arm64';+ platform: 'darwin-arm64' | 'darwin-x64' | 'linux-amd64' | 'linux-arm64' | 'windows-amd64' | 'windows-arm64';url: string;size_bytes: number;sha256: string;diff --git a/vibe/model_hub_runtime/cliproxyapi_manifest.json b/vibe/model_hub_runtime/cliproxyapi_manifest.jsonindex 845095bc1..8163b4171 100644--- a/vibe/model_hub_runtime/cliproxyapi_manifest.json+++ b/vibe/model_hub_runtime/cliproxyapi_manifest.json@@ -1,55 +1,83 @@{"schema_version": 1,"name": "cliproxyapi",- "version": "v7.3.16",+ "version": "v8.0.23","source": "router-for-me/CLIProxyAPI",- "source_url": "https://github.com/router-for-me/CLIProxyAPI/tree/c404af96ebacedf8168b3c2bdbf4449a21cd1c1e",- "source_sha": "c404af96ebacedf8168b3c2bdbf4449a21cd1c1e",- "release_tag": "v7.3.16",- "asset_release_tag": "model-hub-engine-v7.3.16-3",+ "source_url": "https://github.com/router-for-me/CLIProxyAPI/tree/d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5",+ "source_sha": "d318bcc3afb9ea8782862f5e8cdb541afdc9dfa5",+ "release_tag": "v8.0.23",+ "asset_release_tag": "model-hub-engine-v8.0.23-1","license": "MIT","assets": [{"platform": "darwin-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v7.3.16-3/CLIProxyAPI_7.3.16_darwin_aarch64.tar.gz",- "size_bytes": 39534924,- "sha256": "bc046156ac880beb1c09b2b69a8f80513ce3caec92f34fbc00dbf8aaf2c91754",- "binary_sha256": "bfd39d09fd0f5f922ba5cd1a6d86cb86b928e31bcf1746cb763f5632af13c068",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_darwin_aarch64.tar.gz",+ "size_bytes": 40511180,+ "sha256": "bd863d04d950390b745dd4414ea8c8be715cb5c21b492d3c0d71504f64fca978",+ "binary_sha256": "f953540b126b220352bb66991e9f8d1c29cf18054f4c75f17e49a7d73fb17e19","bin_path": "cli-proxy-api"},{"platform": "darwin-x64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v7.3.16-3/CLIProxyAPI_7.3.16_darwin_amd64.tar.gz",- "size_bytes": 41928346,- "sha256": "6cdc647a2bb0ccc8d179f290cb1f90da28ef3d02e7c2d6aa96f5903760a78328",- "binary_sha256": "dc1339f5a5a50d7b8254c1b1662177beb9a597aab04ba647ee9b6f555de1b87d",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_darwin_amd64.tar.gz",+ "size_bytes": 42973748,+ "sha256": "eda0092a9d1afecf8471fc95e4c077825a3db8059df7caa6a06816a2a8a438eb",+ "binary_sha256": "f279440f5689b15f322bb9c4116fcf8434d0b48bfcac2c2f2e089557e6f59f36","bin_path": "cli-proxy-api"},{"platform": "linux-amd64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v7.3.16-3/CLIProxyAPI_7.3.16_linux_amd64.tar.gz",- "size_bytes": 39894112,- "sha256": "88e0843bb5eaecb2748ff7fc5c4d61d301927ccd0aec7b35b1e20efc551957e9",- "binary_sha256": "8c500c984e056a2b191c8a3a2780062ca447659244d7b62b9544c5a4af29b0de",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_linux_amd64.tar.gz",+ "size_bytes": 40932246,+ "sha256": "e72351f5280f943233c9ddc8ab9f51556f57e9f95d68bf13a15b141a95e48b65",+ "binary_sha256": "fa7fa7cd0289a4912587764c535adcd06a41fe1fb0dc92193925883bbfe8b3a1","bin_path": "cli-proxy-api"},{"platform": "linux-arm64",- "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v7.3.16-3/CLIProxyAPI_7.3.16_linux_aarch64.tar.gz",- "size_bytes": 36618378,- "sha256": "a289bbc2d409e5a54a2f65c9d331f7e968b0f18fba2f3b56477a30a2a3c08c3a",- "binary_sha256": "9ddb102bbd6b80c2651e5eb2939840142efb8068e802521ae0c1eac3877a84b9",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_linux_aarch64.tar.gz",+ "size_bytes": 37548183,+ "sha256": "ca06e508c654d6c8cfc5af44341eeac339e0a033d217a480c44043b8e8c81ebc",+ "binary_sha256": "5a514166e95e35b53a846030ab3cb4af5a1c52c06df2c3db8c764adde1bc6178","bin_path": "cli-proxy-api"+ },+ {+ "platform": "windows-amd64",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_windows_amd64.tar.gz",+ "size_bytes": 41444644,+ "sha256": "7d138744b44a7ee103f15d065712f97798db0259cdafce2a93819b4135b69006",+ "binary_sha256": "c265136d64bc6fdb7a4737e28333ff58ed995407d50b0581857e6693a2952a32",+ "bin_path": "cli-proxy-api.exe"+ },+ {+ "platform": "windows-arm64",+ "url": "https://github.com/avibe-bot/avibe/releases/download/model-hub-engine-v8.0.23-1/CLIProxyAPI_8.0.23_windows_aarch64.tar.gz",+ "size_bytes": 37803078,+ "sha256": "969997f1dbe169c83e227def75ca51e105aafb9f3d30bb3bb615685fc289b525",+ "binary_sha256": "0ba1b87a3c562f5121f2902507e6608713237a3daafa229bca5b4829b29c29ec",+ "bin_path": "cli-proxy-api.exe"}],"build": {"builder": "scripts/build_model_hub_engine.py",- "go_version": "go1.26.0",+ "go_version": "go1.26.9","cgo_enabled": false,"trimpath": true,"buildvcs": false,- "patch": "patches/model-hub-cpa-v7.3.16/openai-compat-native-token-field.patch",- "patch_sha256": "5861e81791cf02adf67e249ddb92fa0119dff477e0ca54f5279ac817acc989e0",+ "patches": [+ {+ "path": "patches/model-hub-cpa-v8.0.23/openai-compat-native-token-field.patch",+ "sha256": "b2b80bb2c10887926c467f3088b2c16c5c048714a4bbb8f3c0b6a237c65c9675"+ },+ {+ "path": "patches/model-hub-cpa-v8.0.23/oauth-callback-forwarder-loopback.patch",+ "sha256": "bafde5939b84a440908727e098dff29270742f9b3ab425bb9a5e1223a02e770f"+ },+ {+ "path": "patches/model-hub-cpa-v8.0.23/antigravity-static-catalog-until-probe.patch",+ "sha256": "d6e0c77a0271f5671ba8090e0f14d91bb293a50cfa4d5127dd15e87bd0619d19"+ }+ ],"source_date_epoch": 0}}diff --git a/vibe/model_hub_runtime/installer.py b/vibe/model_hub_runtime/installer.pyindex 14ae913b9..6e5708978 100644--- a/vibe/model_hub_runtime/installer.py+++ b/vibe/model_hub_runtime/installer.py@@ -34,6 +34,8 @@ _ENGINE_PLATFORM_MAP = {"darwin-x64": "darwin-x64","linux-x64": "linux-amd64","linux-arm64": "linux-arm64",+ "win32-x64": "windows-amd64",+ "win32-arm64": "windows-arm64",}_ENGINE_ASSET_PLATFORMS = frozenset(_ENGINE_PLATFORM_MAP.values())_INSTALL_STATE_SCHEMA_VERSION = 3