ObserveShadow computes intended outcome only and refuses FAV_DEGRADED_READ; HandleLease and Register(fav) stay fail-closed. Co-authored-by: Cursor <cursoragent@cursor.com>
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/config"
|
|
)
|
|
|
|
func TestVaultDefaultsStayDisabled(t *testing.T) {
|
|
cfg, err := config.Load("/dev/null")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.FAVDegradedRead {
|
|
t.Fatal("FAV_DEGRADED_READ must default false")
|
|
}
|
|
if cfg.FAVPublisherEnabled {
|
|
t.Fatal("FAV_PUBLISHER_ENABLED must default false")
|
|
}
|
|
|
|
s := &Server{cfg: cfg}
|
|
s.initArtifactVault()
|
|
s.startVaultPublisher()
|
|
if s.vaultPub != nil {
|
|
t.Fatal("vault publisher must stay nil when flag off")
|
|
}
|
|
if s.vaultPublisherRunning() {
|
|
t.Fatal("vault publisher must not start when flag off")
|
|
}
|
|
if _, _, err := s.tryVaultDegraded(context.Background(), "dev", "doc", "1"); err == nil {
|
|
t.Fatal("degraded read must refuse when flag off")
|
|
}
|
|
}
|
|
|
|
func TestVaultStatusReportsOff(t *testing.T) {
|
|
s := &Server{cfg: &config.Config{Env: "dev"}}
|
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/vault/status", nil)
|
|
rr := httptest.NewRecorder()
|
|
s.handleVaultStatus(rr, req)
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("status=%d", rr.Code)
|
|
}
|
|
var body map[string]any
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if body["consumer_mode"] != "off" {
|
|
t.Fatalf("consumer_mode=%v", body["consumer_mode"])
|
|
}
|
|
if body["publisher_enabled"] != false {
|
|
t.Fatalf("publisher_enabled=%v", body["publisher_enabled"])
|
|
}
|
|
if body["degraded_read"] != false {
|
|
t.Fatalf("degraded_read=%v", body["degraded_read"])
|
|
}
|
|
if body["shadow_observe"] != true {
|
|
t.Fatalf("shadow_observe=%v", body["shadow_observe"])
|
|
}
|
|
if body["would_stage"] != false || body["would_publish"] != false {
|
|
t.Fatalf("shadow must not claim writes: %+v", body)
|
|
}
|
|
if body["live_not_opened"] != true {
|
|
t.Fatalf("live_not_opened=%v", body["live_not_opened"])
|
|
}
|
|
}
|
|
|
|
func TestValidateIndependentVaultRejectsDataRoot(t *testing.T) {
|
|
if err := config.ValidateIndependentVault("./data/dev", "./data/dev"); err == nil {
|
|
t.Fatal("expected vault/data collision error")
|
|
}
|
|
if err := config.ValidateIndependentVault("", "./data/dev"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|