ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/missionmatch / internal/platform/inference/client_test.go

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/missionmatch / internal/platform/inference/client_test.go
DateNot specified in source
RepositoryJanady13/missionmatch
Revision720d47fae476b0d38477ae4401697d372b1ea2bc
Branchfeature/opportunity-to-outcome
Path or archive memberinternal/platform/inference/client_test.go
Original SHA-2563e4420a0e03b085c5997707f2616c964f35c3248fc34b6710380a1571f5823ff
Git blob SHAb4877d394ba2a78bf9ea7ebe52fc23e3e4940d72
Reading-copy SHA-2563e4420a0e03b085c5997707f2616c964f35c3248fc34b6710380a1571f5823ff

Original source ↗

Every recorded occurrence

These 2 records contain identical original source bytes. Their paths and revisions remain part of the archive.

Original recordBranch or archiveRevision / identifierOriginal location
Janady13/missionmatch / internal/platform/inference/client_test.gofeature/opportunity-to-outcome720d47fae476b0d38477ae4401697d372b1ea2bcOpen original
Janady13/missionmatch / internal/platform/inference/client_test.gofeature/aioe-upgrade2178e7298d0e5d9af83afa12402fd587f0ba6ed8Open original

Recovered source transcript

package inference import ( "context" "encoding/json" "net/http" "net/http/httptest" "sync/atomic" "testing" "time" "github.com/missionworkforce/missionmatch/internal/platform/scrub" ) func newTestClient(t *testing.T, h http.Handler) *Client { t.Helper() srv := httptest.NewServer(h) t.Cleanup(srv.Close) c, err := New(Config{BaseURL: srv.URL, EmbedModel: "all-minilm", Dimension: 384, Timeout: 2 * time.Second}) if err != nil { t.Fatalf("New: %v", err) } return c } func TestEmbedReturnsVectorsAndChecksDimension(t *testing.T) { c := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var req EmbedRequest _ = json.NewDecoder(r.Body).Decode(&req) out := EmbedResponse{Model: req.Model, Dimension: 384, Embeddings: make([][]float32, len(req.Inputs))} for i := range out.Embeddings { out.Embeddings[i] = make([]float32, 384) } _ = json.NewEncoder(w).Encode(out) })) res, err := c.Embed(context.Background(), []string{"a", "b"}) if err != nil { t.Fatalf("Embed: %v", err) } if len(res.Embeddings) != 2 || len(res.Embeddings[0]) != 384 { t.Fatalf("expected 2 vectors of width 384, got %d x %d", len(res.Embeddings), len(res.Embeddings[0])) } } func TestEmbedRejectsWrongDimension(t *testing.T) { c := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { // A plane that returns 768 wide vectors would silently corrupt the vector(384) column. _ = json.NewEncoder(w).Encode(EmbedResponse{Dimension: 768, Embeddings: [][]float32{make([]float32, 768)}}) })) if _, err := c.Embed(context.Background(), []string{"x"}); err == nil { t.Fatal("Embed must hard fail when the plane returns the wrong embedding width") } } func TestRetriesOn5xxThenSucceeds(t *testing.T) { var calls int32 c := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { if atomic.AddInt32(&calls, 1) < 3 { w.WriteHeader(http.StatusBadGateway) return } _ = json.NewEncoder(w).Encode(GenerateResponse{Text: "ok"}) })) c.cfg.MaxRetries = 3 res, err := c.Generate(context.Background(), GenerateRequest{Prompt: "hi"}) if err != nil { t.Fatalf("Generate should succeed after transient 5xx retries: %v", err) } if res.Text != "ok" || atomic.LoadInt32(&calls) != 3 { t.Fatalf("expected success on the 3rd attempt, got %q after %d calls", res.Text, calls) } } func TestNon5xxErrorIsNotRetried(t *testing.T) { var calls int32 c := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { atomic.AddInt32(&calls, 1) w.WriteHeader(http.StatusBadRequest) })) c.cfg.MaxRetries = 3 if _, err := c.Generate(context.Background(), GenerateRequest{Prompt: "hi"}); err == nil { t.Fatal("a 400 must not be retried and must surface as an error") } if atomic.LoadInt32(&calls) != 1 { t.Fatalf("a 4xx must be tried exactly once, got %d calls", calls) } } func TestBreakerOpensAfterRepeatedFailures(t *testing.T) { c := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusServiceUnavailable) })) c.cfg.MaxRetries = 0 c.cb = newBreaker(3, time.Minute) for i := 0; i < 3; i++ { _, _ = c.Generate(context.Background(), GenerateRequest{Prompt: "x"}) } if _, err := c.Generate(context.Background(), GenerateRequest{Prompt: "x"}); err != ErrCircuitOpen { t.Fatalf("after repeated failures the breaker should fail fast with ErrCircuitOpen, got %v", err) } } func TestTeachEnforcesScrubBoundaryAndRespectsPosture(t *testing.T) { var transmitted int32 c := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { atomic.AddInt32(&transmitted, 1) w.WriteHeader(http.StatusAccepted) })) // A signal carrying a client fact (a UUID in model_version) must be refused before any transmit. leak := scrub.TeachingSignal{Pattern: "adjacent_skill_substitution_outcome", Band: scrub.BandHigh, Outcome: scrub.OutcomeApproved, Observations: 1, Successes: 1, ModelVersion: "11111111-1111-1111-1111-111111111111"} if err := c.Teach(context.Background(), leak); err == nil { t.Fatal("Teach must refuse a signal carrying a client fact") } // Register the model version this test signals on, the same way the producer registers engine.ModelVersion // at init, so the scrub boundary accepts it. The seam refuses any version nobody registered (the tripwire // for a drifted scoring contract), so a test that speaks a version must register it. scrub.RegisterModelVersion("v1.0.0") // A clean signal with teaching disabled (default posture) validates but does NOT transmit. clean := scrub.TeachingSignal{Pattern: "adjacent_skill_substitution_outcome", Band: scrub.BandHigh, Outcome: scrub.OutcomeApproved, Observations: 10, Successes: 7, ModelVersion: "v1.0.0"} if err := c.Teach(context.Background(), clean); err != nil { t.Fatalf("a clean signal should pass the boundary: %v", err) } if atomic.LoadInt32(&transmitted) != 0 { t.Fatal("with teaching disabled the signal must not be transmitted (federated loop is scaffolded, not active)") } } // TestClientErrorDoesNotConsumeTheBreakerBudget pins the fix for the configuration outage loop. A missing // or wrong MM_MEGAMIND_TOKEN makes the gateway answer 401 on every call. The plane is healthy, so those // failures must NOT count toward the breaker: if they did, the breaker would trip after BreakerTrips and // then sit in a cooldown loop forever, because every probe carries the same bad token. The breaker budget // is reserved for plane health (network faults, timeouts, 5xx), never for a fault on this side of the wire. func TestClientErrorDoesNotConsumeTheBreakerBudget(t *testing.T) { var calls int32 c := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { atomic.AddInt32(&calls, 1) w.WriteHeader(http.StatusUnauthorized) })) c.cfg.MaxRetries = 0 c.cb = newBreaker(2, time.Minute) for i := 0; i < 5; i++ { _, err := c.Generate(context.Background(), GenerateRequest{Prompt: "x"}) if err == nil { t.Fatal("a 401 must surface as an error") } if err == ErrCircuitOpen { t.Fatalf("attempt %d failed fast on an open breaker: a client side 401 must not trip it", i+1) } } // Every attempt must have reached the gateway. A tripped breaker would have short circuited the later // ones, which is exactly how the config error used to outlive its own fix. if got := atomic.LoadInt32(&calls); got != 5 { t.Fatalf("expected all 5 attempts to reach the plane, got %d", got) } } // TestBreakerStillOpensOnPlaneFailuresAfterClientErrors proves the fix did not disarm the breaker: a run of // client side 4xx leaves the budget untouched, and a following run of genuine 5xx still trips it. func TestBreakerStillOpensOnPlaneFailuresAfterClientErrors(t *testing.T) { var status int32 = http.StatusUnauthorized c := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(int(atomic.LoadInt32(&status))) })) c.cfg.MaxRetries = 0 c.cb = newBreaker(2, time.Minute) for i := 0; i < 4; i++ { _, _ = c.Generate(context.Background(), GenerateRequest{Prompt: "x"}) } atomic.StoreInt32(&status, http.StatusServiceUnavailable) for i := 0; i < 2; i++ { _, _ = c.Generate(context.Background(), GenerateRequest{Prompt: "x"}) } if _, err := c.Generate(context.Background(), GenerateRequest{Prompt: "x"}); err != ErrCircuitOpen { t.Fatalf("a sick plane must still open the breaker, got %v", err) } }

Search equations, builds, manuscript text, and recovered sources.