mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-10 05:01:28 -10:00
* fix(providers): register Atomic Chat as local OpenAI-compatible runtime Point atomic-chat at the default local API (http://127.0.0.1:1337/v1), mark it Local with no API key, and auto-detect it alongside Ollama and LM Studio. Keep opencode-go-anthropic-compatible in the provider catalog and curated model list after rebasing onto latest main. Co-authored-by: Cursor <[email protected]> * docs(zh): sync Atomic Chat local runtime into README_ZH The English README lists Atomic Chat in the provider list and tells local-model users to run its desktop app on http://127.0.0.1:1337/v1, but the Chinese README still mentioned only Ollama and LM Studio. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(providers): give the local Atomic Chat runtime its own catalog ID Repurposing the existing atomic-chat ID from the hosted, key-gated preset to a keyless local one silently downgraded credential checks for profiles already saved against the remote endpoint: MissingCredentialEnv resolves RequiresAuth from the catalog descriptor, so those profiles were reported as ready and only failed later with an unauthenticated call to api.atomic.chat. Keep the hosted atomic-chat descriptor as it was and register the local runtime under a separate atomic-chat-local ID, mirroring the existing ollama-cloud/ollama split. Stored profiles keep their identity and no migration is needed. Co-Authored-By: Claude Opus 4.8 <[email protected]> * test(onboarding): assert the full Atomic Chat local endpoint and default model Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(models): drop the placeholder curated list for atomic-chat-local Atomic Chat's model catalog is a Hugging Face scrape refreshed every 12h plus arbitrary owner/repo lookups, so the served model ID is whichever model the user loaded and no hardcoded list stays accurate. The single local-model entry short-circuited Models() without adding anything: the descriptor is openai-compatible, so modelMatchesProvider never matches a registry entry and the fallback already yields the descriptor's DefaultModel. Output is unchanged; the difference is that local-model is no longer presented as a curated contract. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(onboarding): pin the probed model in the local-runtime adopt command probeLocalRuntime already reads the runtime's /v1/models, but SetupAction dropped the result and emitted 'zero providers add <id> --set-active' with no --model. The add path then persisted the catalog DefaultModel, which for a local runtime is the placeholder 'local-model', and the first completion failed with an unknown-model response. SetupAction now pins the probed id via SetupCommandWithModel. The catalog default wins when the server actually serves it, so an existing Ollama setup does not switch models; otherwise the first advertised id is used. An empty probe result leaves the command on the catalog default rather than inventing an id. Covers a server whose returned id is not 'local-model'. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(onboarding): shell-safe adopt command + reject atomic-chat-local placeholder model commandArg now POSIX single-quotes rendered args instead of strconv.Quote, so a model id from an untrusted /v1/models response cannot expand when the adopt command is pasted into a shell. providerProfileForAdd now errors when atomic-chat-local is added without --model instead of persisting the local-model placeholder that fails the first completion. Adds regression tests for command substitution, backticks, and the require-model guard. * fix(onboarding): finish Atomic Chat setup across supported shells Rebase on current main and keep the hosted Atomic Chat preset intact. Only emit setup arguments that are portable across POSIX, cmd.exe and PowerShell; show interactive guidance for other model IDs. Reject the Atomic Chat placeholder before both CLI and TUI persistence, and stop advertising adoption when discovery finds no usable model. Validation: full Go test suite, focused race suite, vet, release build, smoke, formatting, advisory lint and vulncheck pass with isolated config and inherited Anthropic overrides removed. Onboarding, CLI and TUI test packages cross-compile for Windows and Linux. Regression tests fail on the rebased pre-fix code and pass with these changes. Refs Gitlawb/zero#550 and Gitlawb/zero#592. * fix(onboarding): preserve option-looking model IDs in adopt commands Use the existing --model=value grammar when a discovered model begins with a hyphen. Validate the model separately from the fixed separator so shell safety remains unchanged and '=' is not added to the allowlist. Exercise generated detection actions through shell tokenization, the actual add parser, and profile construction for Atomic Chat, LM Studio and Ollama. Cover leading hyphens, flag-looking IDs, ordinary IDs, spaces, and unsafe inline values. Before the fix, the new regression failed with: generated adoption command rejected by add parser: --model requires a value Validation: full Go suite, focused race tests, formatting, vet, release build, smoke, lint-static and vulncheck passed. Affected test packages cross-compiled for Windows and Linux. Refs Gitlawb/zero#550. * fix(onboarding): select eligible chat models and preserve Ollama defaults P2: apply the existing known-noncoding exclusion before default preference or first-model fallback. When a nonempty list has no eligible model, offer commandless guidance instead of persisting the rejected/default model. P3: recognize an Ollama untagged default's :latest spelling, preserving the advertised ID. Prefer exact matches and leave other tags/providers alone. Add selector tests plus a mock-server integration test through discovery, the generated action, the real add parser, profile persistence, a fresh process, and the chat completion request. Before this fix, that test failed: fresh process sent model "text-embedding-local", want eligible model "-loaded chat model" The Ollama alias case also failed before the fix: AdoptModel() = "qwen3:8b", want "llama3.1:latest" Explicit model choices, shell checks, hosted/local provider identities and Atomic placeholder guards retain their existing behavior. Validation: full Go suite, focused race tests, formatting, vet, release build, smoke, lint-static and vulncheck passed. Affected test packages cross-compiled for Windows and Linux. Integration evidence uses a mock server; native Windows shell and actual runtime behavior are not claimed. Refs Gitlawb/zero#550 and Gitlawb/zero#592. --------- Co-authored-by: Cursor <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: alex <[email protected]>
127 lines
4.7 KiB
Go
127 lines
4.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Gitlawb/zero/internal/config"
|
|
"github.com/Gitlawb/zero/internal/provideronboarding"
|
|
"mvdan.cc/sh/v3/shell"
|
|
)
|
|
|
|
// Regression for issue #555's follow-up: `zero providers check` must not
|
|
// error that a no-auth custom endpoint requires an API key, matching what
|
|
// /model and /providers already treat as usable.
|
|
func TestValidateProviderRuntimeReadyCustomEndpoint(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
profile config.ProviderProfile
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "custom openai compatible with no credential configured",
|
|
profile: config.ProviderProfile{
|
|
Name: "local-llama",
|
|
CatalogID: "custom-openai-compatible",
|
|
BaseURL: "http://192.168.1.50:8080/v1",
|
|
Model: "custom-model",
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "custom openai compatible with stale legacy default env",
|
|
profile: config.ProviderProfile{
|
|
Name: "local-llama",
|
|
CatalogID: "custom-openai-compatible",
|
|
BaseURL: "http://192.168.1.50:8080/v1",
|
|
APIKeyEnv: "OPENAI_API_KEY",
|
|
Model: "custom-model",
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "custom openai compatible with explicit non-default env still requires it",
|
|
profile: config.ProviderProfile{
|
|
Name: "local-llama",
|
|
CatalogID: "custom-openai-compatible",
|
|
BaseURL: "http://192.168.1.50:8080/v1",
|
|
APIKeyEnv: "LLAMA_CPP_API_KEY",
|
|
Model: "custom-model",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "catalog provider missing key still errors",
|
|
profile: config.ProviderProfile{
|
|
Name: "groq",
|
|
CatalogID: "groq",
|
|
Model: "llama-3.3-70b-versatile",
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
err := validateProviderRuntimeReady(c.profile)
|
|
if (err != nil) != c.wantErr {
|
|
t.Fatalf("validateProviderRuntimeReady() error = %v, wantErr %v", err, c.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// atomic-chat-local without --model would persist the catalog placeholder
|
|
// "local-model", which the Atomic Chat server never serves, so the first
|
|
// completion fails. Adding it must require a real model instead.
|
|
func TestProviderProfileForAddRequiresModelForAtomicChatLocal(t *testing.T) {
|
|
if _, err := providerProfileForAdd(providerAddOptions{catalogID: "atomic-chat-local"}); err == nil {
|
|
t.Fatalf("providerProfileForAdd(atomic-chat-local, no --model) = nil error, want a require-model error")
|
|
} else if !strings.Contains(err.Error(), "--model") {
|
|
t.Fatalf("error should tell the user to pass --model, got %v", err)
|
|
}
|
|
|
|
// The interactive wizards and the no-id detect fallback resolve the model to
|
|
// the catalog DefaultModel and pass it through as a non-empty value, so the
|
|
// placeholder itself must be rejected, not just an empty --model.
|
|
if _, err := providerProfileForAdd(providerAddOptions{catalogID: "atomic-chat-local", model: "local-model"}); err == nil {
|
|
t.Fatalf("providerProfileForAdd(atomic-chat-local, --model local-model) = nil error, want reject of the catalog placeholder")
|
|
}
|
|
|
|
profile, err := providerProfileForAdd(providerAddOptions{catalogID: "atomic-chat-local", model: "unsloth/gemma-4-E2B-it-GGUF"})
|
|
if err != nil {
|
|
t.Fatalf("providerProfileForAdd(atomic-chat-local, --model) returned error: %v", err)
|
|
}
|
|
if profile.Model != "unsloth/gemma-4-E2B-it-GGUF" {
|
|
t.Fatalf("profile.Model = %q, want the explicit model", profile.Model)
|
|
}
|
|
if profile.Model == "local-model" {
|
|
t.Fatalf("profile persisted the catalog placeholder")
|
|
}
|
|
}
|
|
|
|
func TestDetectedModelActionSurvivesAddParser(t *testing.T) {
|
|
for _, catalogID := range []string{"atomic-chat-local", "lmstudio", "ollama"} {
|
|
for _, modelID := range []string{"-loaded-model", "--set-active", "--model", "-loaded model", "ordinary/model", "model with spaces"} {
|
|
t.Run(catalogID+"/"+modelID, func(t *testing.T) {
|
|
detected := provideronboarding.DetectedLocalRuntime{
|
|
LocalRuntime: provideronboarding.LocalRuntime{CatalogID: catalogID, Name: "Local Runtime", DefaultModel: "local-model"},
|
|
Models: []string{modelID},
|
|
}
|
|
command := detected.SetupAction().Command
|
|
args, err := shell.Fields(command, func(string) string { return "" })
|
|
if err != nil || len(args) < 4 {
|
|
t.Fatalf("invalid adoption command %q: %v", command, err)
|
|
}
|
|
options, help, err := parseProviderAddArgs(args[3:])
|
|
if err != nil || help {
|
|
t.Fatalf("generated adoption command rejected by add parser: %q: %v", command, err)
|
|
}
|
|
profile, err := providerProfileForAdd(options)
|
|
if err != nil || profile.Model != modelID || !options.setActive || profile.Name != "Local Runtime" {
|
|
t.Fatalf("adoption changed model or options: model=%q name=%q active=%v err=%v", profile.Model, profile.Name, options.setActive, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|