Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/platform/inference/client_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 43d56387270ef4da4cabd794d97ca6a49909bc7d |
| Branch | w3-ai-staffing-recommendations |
| Path or archive member | internal/platform/inference/client_test.go |
| Original SHA-256 | a5e76730ef7fd304beb47351237fd3952ba111f6cbf2933ad7cf9cd8038b55e6 |
| Git blob SHA | edcc53f87f8c00a07345e57bf55ddabc5cd89fc4 |
| Reading-copy SHA-256 | a5e76730ef7fd304beb47351237fd3952ba111f6cbf2933ad7cf9cd8038b55e6 |
Every recorded occurrence
These 21 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/platform/inference/client_test.go | w3-ai-staffing-recommendations | 43d56387270ef4da4cabd794d97ca6a49909bc7d | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws3-clearance | 4b8e7ce594c068621867f9c9deed0ec64ae6c553 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ai-intelligence-layer | 5d5ddff70393a197c5f54a45280bb5dd42b24755 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws7-federal-signal | 6a9f6ce9cfb13345ffb47770d4960e7c2d9c17c2 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws6-retrieval | 6c56e29231ec05735927fa265c97d517499dfeaf | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | per-tenant-routing | 9bde0f9a74b89d01980fa658e5253acda7528d0c | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ai-brain-live | aac32fc49c878cc5bca099459307611562d0bac1 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws1-ontology-sync | b596f449a32a1016fbd403c36505cc00a1ac9ee6 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | deploy-and-ops | bdacd9d0b4d5998d25fc74bf4007f4c3ec538c7a | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | phase2-eval-fairness | d361af254701975fe239927656ababb56374655e | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws2-alias-relationship | e4dada4601c6eb101830f9d223a9655dfa120616 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | per-tenant-routing | 9bde0f9a74b89d01980fa658e5253acda7528d0c | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws6-retrieval | 6c56e29231ec05735927fa265c97d517499dfeaf | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws1-ontology-sync | b596f449a32a1016fbd403c36505cc00a1ac9ee6 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | w3-ai-staffing-recommendations | 43d56387270ef4da4cabd794d97ca6a49909bc7d | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws3-clearance | 4b8e7ce594c068621867f9c9deed0ec64ae6c553 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | phase2-eval-fairness | d361af254701975fe239927656ababb56374655e | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ai-intelligence-layer | 5d5ddff70393a197c5f54a45280bb5dd42b24755 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | deploy-and-ops | bdacd9d0b4d5998d25fc74bf4007f4c3ec538c7a | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ws7-federal-signal | 6a9f6ce9cfb13345ffb47770d4960e7c2d9c17c2 | Open original |
| Janady13/missionmatch / internal/platform/inference/client_test.go | ai-brain-live | aac32fc49c878cc5bca099459307611562d0bac1 | Open original |
Recovered source transcript
Download complete source text ↓123 lines · 4.6 KB
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")
}
// 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)")
}
}