diff options
| author | Fuwn <[email protected]> | 2026-02-27 09:26:06 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-27 09:26:06 -0800 |
| commit | 8980607ef8e7426b601f942f26ae2cd4c4f3edff (patch) | |
| tree | 60bdb4bbbe5755223c3387179ee7406432d084ab /internal/ingest/client_test.go | |
| parent | fix: make mirror replay lossless with strict seq accounting and trace (diff) | |
| download | plutia-test-8980607ef8e7426b601f942f26ae2cd4c4f3edff.tar.xz plutia-test-8980607ef8e7426b601f942f26ae2cd4c4f3edff.zip | |
feat: add thin mode for on-demand verified PLC resolution
Diffstat (limited to 'internal/ingest/client_test.go')
| -rw-r--r-- | internal/ingest/client_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/ingest/client_test.go b/internal/ingest/client_test.go index 50595ec..2552855 100644 --- a/internal/ingest/client_test.go +++ b/internal/ingest/client_test.go @@ -1,6 +1,10 @@ package ingest import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" "strings" "testing" ) @@ -38,3 +42,62 @@ func TestDecodeExportBody_FailsOnMalformedNonTrailingNDJSONLine(t *testing.T) { t.Fatalf("expected malformed middle line to fail") } } + +func TestFetchDIDLog_UsesAuditFallbackForCIDs(t *testing.T) { + const did = "did:plc:alice" + op1 := json.RawMessage(`{"did":"did:plc:alice","sig":"x","sigPayload":"e30","publicKey":"a"}`) + op2 := json.RawMessage(`{"did":"did:plc:alice","prev":"bafy-one","sig":"x","sigPayload":"e30","publicKey":"a"}`) + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/" + did + "/log": + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode([]json.RawMessage{op1, op2}) + case "/" + did + "/log/audit": + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode([]map[string]any{ + {"did": did, "operation": op1, "cid": "bafy-one", "createdAt": "2026-02-27T00:00:00Z"}, + {"did": did, "operation": op2, "cid": "bafy-two", "createdAt": "2026-02-27T00:00:01Z"}, + }) + default: + http.NotFound(w, r) + } + })) + defer srv.Close() + + client := NewClient(srv.URL) + records, err := client.FetchDIDLog(context.Background(), did) + if err != nil { + t.Fatalf("fetch did log: %v", err) + } + + if len(records) != 2 { + t.Fatalf("record count mismatch: got %d want 2", len(records)) + } + + if records[0].CID != "bafy-one" || records[1].CID != "bafy-two" { + t.Fatalf("cid fallback mismatch: got [%s %s]", records[0].CID, records[1].CID) + } +} + +func TestFetchDIDLog_FailsWhenCIDsUnavailable(t *testing.T) { + const did = "did:plc:bob" + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/" + did + "/log": + _ = json.NewEncoder(w).Encode([]json.RawMessage{json.RawMessage(`{"did":"did:plc:bob"}`)}) + case "/" + did + "/log/audit": + http.NotFound(w, r) + default: + http.NotFound(w, r) + } + })) + defer srv.Close() + + client := NewClient(srv.URL) + _, err := client.FetchDIDLog(context.Background(), did) + if err == nil { + t.Fatalf("expected cid fallback error") + } +} |