{"repo": "1mb-dev/shim", "files": {"cmd/shim/main_test.go": {"a411f221b2a0c6797dff0ce292467543246c951d": {"t": 1785746077.7950313, "n": 2825, "h": "55553aad0bcd42ce", "c": "package main\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"log/slog\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/1mb-dev/shim/internal/config\"\n)\n\n// TestDispatchVersion: `shim version` (and -v/--version) print \"shim \"\n// and exit 0 without starting the server.\nfunc TestDispatchVersion(t *testing.T) {\n\tfor _, arg := range []string{\"version\", \"-v\", \"--version\"} {\n\t\tvar out bytes.Buffer\n\t\tcode, err := dispatch([]string{arg}, &out)\n\t\tif err != nil || code != 0 {\n\t\t\tt.Fatalf(\"dispatch %q = (%d, %v), want (0, nil)\", arg, code, err)\n\t\t}\n\t\tif got := strings.TrimSpace(out.String()); got != \"shim dev\" {\n\t\t\tt.Errorf(\"%q output = %q, want %q\", arg, got, \"shim dev\")\n\t\t}\n\t}\n}\n\n// TestBuildAdapter_AnthropicNoDeepseekMisroute fences the v0.5 fix: with\n// ADAPTER=anthropic and UPSTREAM_BASE_URL unset, buildAdapter must resolve the\n// adapter to api.anthropic.com — never inherit a deepseek host. The latent\n// misroute existed while config.Load globally defaulted UPSTREAM_BASE_URL to\n// the deepseek endpoint; this asserts the wiring (config empty → anthropic's\n// own default) composes correctly, the gap unit tests on either half missed.\nfunc TestBuildAdapter_AnthropicNoDeepseekMisroute(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"anthropic\", UpstreamAPIKey: \"k\"} // UpstreamBaseURL: \"\"\n\ta, err := buildAdapter(cfg, slog.Default())\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\treq, err := a.BuildRequest(context.Background(), []byte(`{}`))\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif req.URL.Host != \"api.anthropic.com\" {\n\t\tt.Errorf(\"anthropic empty-base host = %q, want api.anthropic.com\", req.URL.Host)\n\t}\n\tif strings.Contains(req.URL.Host, \"deepseek\") {\n\t\tt.Fatalf(\"misroute: anthropic traffic routed to deepseek host %q\", req.URL.Host)\n\t}\n}\n\n// TestBuildAdapter_OpenAIDialectPreset covers the default→openaichat branch of\n// buildAdapter (the anthropic test covers the other branch): a preset name\n// resolves to an openaichat adapter at the preset's own base URL.\nfunc TestBuildAdapter_OpenAIDialectPreset(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"deepseek\", UpstreamAPIKey: \"k\"}\n\ta, err := buildAdapter(cfg, slog.Default())\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif a.Name() != \"deepseek\" {\n\t\tt.Errorf(\"name = %q, want deepseek\", a.Name())\n\t}\n\treq, err := a.BuildRequest(context.Background(), []byte(`{}`))\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif req.URL.Host != \"api.deepseek.com\" {\n\t\tt.Errorf(\"host = %q, want api.deepseek.com\", req.URL.Host)\n\t}\n}\n\n// TestBuildAdapter_Unknown: an unknown ADAPTER fails loudly (the loud-fail the\n// removed registry once owned now lives in openaichat.New, surfaced here).\nfunc TestBuildAdapter_Unknown(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"ghost\", UpstreamAPIKey: \"k\"}\n\tif _, err := buildAdapter(cfg, slog.Default()); err == nil {\n\t\tt.Fatal(\"expected error for unknown ADAPTER, got nil\")\n\t}\n}\n"}, "66d5bfe38119adec0660c1f6bb95a4981702696f": {"t": 1785759613.3019388, "n": 2825, "h": "55553aad0bcd42ce", "c": "package main\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"log/slog\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/1mb-dev/shim/internal/config\"\n)\n\n// TestDispatchVersion: `shim version` (and -v/--version) print \"shim \"\n// and exit 0 without starting the server.\nfunc TestDispatchVersion(t *testing.T) {\n\tfor _, arg := range []string{\"version\", \"-v\", \"--version\"} {\n\t\tvar out bytes.Buffer\n\t\tcode, err := dispatch([]string{arg}, &out)\n\t\tif err != nil || code != 0 {\n\t\t\tt.Fatalf(\"dispatch %q = (%d, %v), want (0, nil)\", arg, code, err)\n\t\t}\n\t\tif got := strings.TrimSpace(out.String()); got != \"shim dev\" {\n\t\t\tt.Errorf(\"%q output = %q, want %q\", arg, got, \"shim dev\")\n\t\t}\n\t}\n}\n\n// TestBuildAdapter_AnthropicNoDeepseekMisroute fences the v0.5 fix: with\n// ADAPTER=anthropic and UPSTREAM_BASE_URL unset, buildAdapter must resolve the\n// adapter to api.anthropic.com — never inherit a deepseek host. The latent\n// misroute existed while config.Load globally defaulted UPSTREAM_BASE_URL to\n// the deepseek endpoint; this asserts the wiring (config empty → anthropic's\n// own default) composes correctly, the gap unit tests on either half missed.\nfunc TestBuildAdapter_AnthropicNoDeepseekMisroute(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"anthropic\", UpstreamAPIKey: \"k\"} // UpstreamBaseURL: \"\"\n\ta, err := buildAdapter(cfg, slog.Default())\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\treq, err := a.BuildRequest(context.Background(), []byte(`{}`))\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif req.URL.Host != \"api.anthropic.com\" {\n\t\tt.Errorf(\"anthropic empty-base host = %q, want api.anthropic.com\", req.URL.Host)\n\t}\n\tif strings.Contains(req.URL.Host, \"deepseek\") {\n\t\tt.Fatalf(\"misroute: anthropic traffic routed to deepseek host %q\", req.URL.Host)\n\t}\n}\n\n// TestBuildAdapter_OpenAIDialectPreset covers the default→openaichat branch of\n// buildAdapter (the anthropic test covers the other branch): a preset name\n// resolves to an openaichat adapter at the preset's own base URL.\nfunc TestBuildAdapter_OpenAIDialectPreset(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"deepseek\", UpstreamAPIKey: \"k\"}\n\ta, err := buildAdapter(cfg, slog.Default())\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif a.Name() != \"deepseek\" {\n\t\tt.Errorf(\"name = %q, want deepseek\", a.Name())\n\t}\n\treq, err := a.BuildRequest(context.Background(), []byte(`{}`))\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif req.URL.Host != \"api.deepseek.com\" {\n\t\tt.Errorf(\"host = %q, want api.deepseek.com\", req.URL.Host)\n\t}\n}\n\n// TestBuildAdapter_Unknown: an unknown ADAPTER fails loudly (the loud-fail the\n// removed registry once owned now lives in openaichat.New, surfaced here).\nfunc TestBuildAdapter_Unknown(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"ghost\", UpstreamAPIKey: \"k\"}\n\tif _, err := buildAdapter(cfg, slog.Default()); err == nil {\n\t\tt.Fatal(\"expected error for unknown ADAPTER, got nil\")\n\t}\n}\n"}, "2fb89bf475b98844a1fa43474d83b5f2b18e8867": {"t": 1785759614.8824377, "n": 2281, "h": "680012e77438ceba", "c": "package main\n\nimport (\n\t\"context\"\n\t\"log/slog\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/1mb-dev/shim/internal/config\"\n)\n\n// TestBuildAdapter_AnthropicNoDeepseekMisroute fences the v0.5 fix: with\n// ADAPTER=anthropic and UPSTREAM_BASE_URL unset, buildAdapter must resolve the\n// adapter to api.anthropic.com — never inherit a deepseek host. The latent\n// misroute existed while config.Load globally defaulted UPSTREAM_BASE_URL to\n// the deepseek endpoint; this asserts the wiring (config empty → anthropic's\n// own default) composes correctly, the gap unit tests on either half missed.\nfunc TestBuildAdapter_AnthropicNoDeepseekMisroute(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"anthropic\", UpstreamAPIKey: \"k\"} // UpstreamBaseURL: \"\"\n\ta, err := buildAdapter(cfg, slog.Default())\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\treq, err := a.BuildRequest(context.Background(), []byte(`{}`))\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif req.URL.Host != \"api.anthropic.com\" {\n\t\tt.Errorf(\"anthropic empty-base host = %q, want api.anthropic.com\", req.URL.Host)\n\t}\n\tif strings.Contains(req.URL.Host, \"deepseek\") {\n\t\tt.Fatalf(\"misroute: anthropic traffic routed to deepseek host %q\", req.URL.Host)\n\t}\n}\n\n// TestBuildAdapter_OpenAIDialectPreset covers the default→openaichat branch of\n// buildAdapter (the anthropic test covers the other branch): a preset name\n// resolves to an openaichat adapter at the preset's own base URL.\nfunc TestBuildAdapter_OpenAIDialectPreset(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"deepseek\", UpstreamAPIKey: \"k\"}\n\ta, err := buildAdapter(cfg, slog.Default())\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif a.Name() != \"deepseek\" {\n\t\tt.Errorf(\"name = %q, want deepseek\", a.Name())\n\t}\n\treq, err := a.BuildRequest(context.Background(), []byte(`{}`))\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif req.URL.Host != \"api.deepseek.com\" {\n\t\tt.Errorf(\"host = %q, want api.deepseek.com\", req.URL.Host)\n\t}\n}\n\n// TestBuildAdapter_Unknown: an unknown ADAPTER fails loudly (the loud-fail the\n// removed registry once owned now lives in openaichat.New, surfaced here).\nfunc TestBuildAdapter_Unknown(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"ghost\", UpstreamAPIKey: \"k\"}\n\tif _, err := buildAdapter(cfg, slog.Default()); err == nil {\n\t\tt.Fatal(\"expected error for unknown ADAPTER, got nil\")\n\t}\n}\n"}, "ddd48e7b3e291507ac391ad36e2a82042eff12e2": {"t": 1785759616.1872349, "n": 1178, "h": "f071269b26cc69d1", "c": "package main\n\nimport (\n\t\"context\"\n\t\"log/slog\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/1mb-dev/shim/internal/config\"\n)\n\n// TestBuildAdapter_AnthropicNoDeepseekMisroute fences the v0.5 fix: with\n// ADAPTER=anthropic and UPSTREAM_BASE_URL unset, buildAdapter must resolve the\n// adapter to api.anthropic.com — never inherit a deepseek host. The latent\n// misroute existed while config.Load globally defaulted UPSTREAM_BASE_URL to\n// the deepseek endpoint; this asserts the wiring (config empty → anthropic's\n// own default) composes correctly, the gap unit tests on either half missed.\nfunc TestBuildAdapter_AnthropicNoDeepseekMisroute(t *testing.T) {\n\tcfg := &config.Config{Adapter: \"anthropic\", UpstreamAPIKey: \"k\"} // UpstreamBaseURL: \"\"\n\ta, err := buildAdapter(cfg, slog.Default())\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\treq, err := a.BuildRequest(context.Background(), []byte(`{}`))\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\tif req.URL.Host != \"api.anthropic.com\" {\n\t\tt.Errorf(\"anthropic empty-base host = %q, want api.anthropic.com\", req.URL.Host)\n\t}\n\tif strings.Contains(req.URL.Host, \"deepseek\") {\n\t\tt.Fatalf(\"misroute: anthropic traffic routed to deepseek host %q\", req.URL.Host)\n\t}\n}\n"}}}}