Implements Increment 1 of `docs/superpowers/specs/2026-07-04-crucible-depot-core-design.md`: a new stdlib-only `internal/depot` package wired into the dispatcher. - `crucible depot status|push|verify|get|pull` with backends `local`/`cdn`/`bunny`; exit contract `0` clean / `1` drift / `2` unconfirmed-only / `64` usage / `70` internal. - Presence is always probed against the real target (IPv4 1-byte range GET; HEAD is banned with a regression-tripwire test). `unconfirmed` is a distinct state, never collapsed into `missing`. - No prompting anywhere: missing `BUNNY_STORAGE_*` env fails closed (read path included), enforced by a no-stdin test. - Uploads: probe-then-PUT with `Checksum: <UPPER-sha>`; read/write key split (`BUNNY_STORAGE_READ_PASSWORD` falls back to `BUNNY_STORAGE_PASSWORD`). - Field-driven fix included: per-probe transient retry (curl `--retry 2` equivalent) — without it a real 1490-blob CDN sweep reported 1222 false-unconfirmed; with it, 1490/1490 present in 74s, exit 0. - Registry: depot `Wired: true`, joins the interactive menu; stale "(SeaweedFS)" wording removed. Tests: unit + httptest fake-Bunny (probe sequence, Checksum header, key split, 428 throttling → exit 2) + local→bunny integration (drift → push → clean → idempotent no-second-PUT; incremental pull). `make check` green. **Merge ordering:** this merges FIRST; the companion `sow-assets-manifest#crucible-depot-cutover` PR needs its flake input bumped to include this. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: #30 Reviewed-by: xtul <mpiasecki720@protonmail.com> Co-authored-by: vickydotbat <vickydotbat@tutamail.com> Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
116 lines
2.9 KiB
Go
116 lines
2.9 KiB
Go
package depot
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLoadConfigDefaults(t *testing.T) {
|
|
getenv := func(key string) string {
|
|
return ""
|
|
}
|
|
cfg := LoadConfig(getenv)
|
|
if cfg.CDNBase != "https://cdn-a7f3k9.westgate.pw" {
|
|
t.Errorf("CDNBase: got %q, want %q", cfg.CDNBase, "https://cdn-a7f3k9.westgate.pw")
|
|
}
|
|
if cfg.StorageZone != "sow-assets-depot" {
|
|
t.Errorf("StorageZone: got %q, want %q", cfg.StorageZone, "sow-assets-depot")
|
|
}
|
|
if cfg.ProbeJobs != 16 {
|
|
t.Errorf("ProbeJobs: got %d, want 16", cfg.ProbeJobs)
|
|
}
|
|
if cfg.Jobs != 16 {
|
|
t.Errorf("Jobs: got %d, want 16", cfg.Jobs)
|
|
}
|
|
if cfg.ConnectTimeout != 10*time.Second {
|
|
t.Errorf("ConnectTimeout: got %v, want 10s", cfg.ConnectTimeout)
|
|
}
|
|
if cfg.ProbeMaxTime != 30*time.Second {
|
|
t.Errorf("ProbeMaxTime: got %v, want 30s", cfg.ProbeMaxTime)
|
|
}
|
|
if cfg.ConfirmRetries != 3 {
|
|
t.Errorf("ConfirmRetries: got %d, want 3", cfg.ConfirmRetries)
|
|
}
|
|
if cfg.ConfirmMax != 200 {
|
|
t.Errorf("ConfirmMax: got %d, want 200", cfg.ConfirmMax)
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigReadKeyFallback(t *testing.T) {
|
|
// When READ unset, falls back to WriteKey
|
|
getenv := func(key string) string {
|
|
if key == "BUNNY_STORAGE_PASSWORD" {
|
|
return "write-key"
|
|
}
|
|
return ""
|
|
}
|
|
cfg := LoadConfig(getenv)
|
|
if cfg.ReadKey != "write-key" {
|
|
t.Errorf("ReadKey fallback: got %q, want %q", cfg.ReadKey, "write-key")
|
|
}
|
|
if cfg.WriteKey != "write-key" {
|
|
t.Errorf("WriteKey: got %q, want %q", cfg.WriteKey, "write-key")
|
|
}
|
|
|
|
// When READ is set, uses its own value
|
|
getenv = func(key string) string {
|
|
if key == "BUNNY_STORAGE_READ_PASSWORD" {
|
|
return "read-key"
|
|
}
|
|
if key == "BUNNY_STORAGE_PASSWORD" {
|
|
return "write-key"
|
|
}
|
|
return ""
|
|
}
|
|
cfg = LoadConfig(getenv)
|
|
if cfg.ReadKey != "read-key" {
|
|
t.Errorf("ReadKey explicit: got %q, want %q", cfg.ReadKey, "read-key")
|
|
}
|
|
if cfg.WriteKey != "write-key" {
|
|
t.Errorf("WriteKey: got %q, want %q", cfg.WriteKey, "write-key")
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigBadIntFallsBack(t *testing.T) {
|
|
getenv := func(key string) string {
|
|
if key == "DEPOT_PROBE_JOBS" {
|
|
return "not-a-number"
|
|
}
|
|
if key == "DEPOT_JOBS" {
|
|
return "invalid"
|
|
}
|
|
if key == "DEPOT_CONNECT_TIMEOUT" {
|
|
return "bad"
|
|
}
|
|
if key == "DEPOT_PROBE_MAX_TIME" {
|
|
return "wrong"
|
|
}
|
|
if key == "DEPOT_CONFIRM_RETRIES" {
|
|
return "nope"
|
|
}
|
|
if key == "DEPOT_CONFIRM_MAX" {
|
|
return "nah"
|
|
}
|
|
return ""
|
|
}
|
|
cfg := LoadConfig(getenv)
|
|
if cfg.ProbeJobs != 16 {
|
|
t.Errorf("ProbeJobs fallback: got %d, want 16", cfg.ProbeJobs)
|
|
}
|
|
if cfg.Jobs != 16 {
|
|
t.Errorf("Jobs fallback: got %d, want 16", cfg.Jobs)
|
|
}
|
|
if cfg.ConnectTimeout != 10*time.Second {
|
|
t.Errorf("ConnectTimeout fallback: got %v, want 10s", cfg.ConnectTimeout)
|
|
}
|
|
if cfg.ProbeMaxTime != 30*time.Second {
|
|
t.Errorf("ProbeMaxTime fallback: got %v, want 30s", cfg.ProbeMaxTime)
|
|
}
|
|
if cfg.ConfirmRetries != 3 {
|
|
t.Errorf("ConfirmRetries fallback: got %d, want 3", cfg.ConfirmRetries)
|
|
}
|
|
if cfg.ConfirmMax != 200 {
|
|
t.Errorf("ConfirmMax fallback: got %d, want 200", cfg.ConfirmMax)
|
|
}
|
|
}
|