fix(llamaswap): address Gadfly review findings
CI / Tidy (pull_request) Successful in 9m25s
CI / Build & Test (pull_request) Successful in 10m15s

- Unload: reject model ids containing path separators (/?#) so a model name
  can't redirect the request to another endpoint; ":" (common in ids) stays
  verbatim.
- doJSON: take a model arg so image/management HTTP errors carry the target id
  (was always ""); add a base-URL guard so management methods fail clearly
  instead of building a bare-path request; cap the success-path JSON decode with
  io.LimitReader (64 MiB) and drain the body when out is nil for conn reuse.
- image: reject negative Request.N before sending.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
2026-06-27 16:04:23 -04:00
co-authored by Claude Opus 4.8
parent 3ba2dbefae
commit 64642c43c4
3 changed files with 51 additions and 10 deletions
+18
View File
@@ -127,6 +127,24 @@ func TestUnload(t *testing.T) {
if gotPath != "/api/models/unload" {
t.Errorf("unload-all path = %q", gotPath)
}
// A model id with a path separator is rejected before any request.
if err := p.Unload(context.Background(), "../admin"); err == nil {
t.Error("expected error for model id with path separator")
}
}
func TestManagementNoBaseURL(t *testing.T) {
p := New() // no base URL
if _, err := p.ListModels(context.Background()); err == nil {
t.Error("ListModels: expected error for missing base URL")
}
if _, err := p.Running(context.Background()); err == nil {
t.Error("Running: expected error for missing base URL")
}
if err := p.Unload(context.Background(), "m"); err == nil {
t.Error("Unload: expected error for missing base URL")
}
}
func TestRunningRaw(t *testing.T) {