From eb5b66d164c20fd99b7e97b79f28b628e83cfc91 Mon Sep 17 00:00:00 2001 From: Randy <857271370@qq.com> Date: Mon, 5 Oct 2026 00:03:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=85=20test:=20verify=20Store-neutral?= =?UTF-8?q?=20Native=20requests=20and=20field=20rules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- tests/integration/lifecycle_test.go | 22 ++++++++-- tests/integration/semantics_test.go | 63 ++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0c942f51..c76a02da 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ confirmed record outcomes; unconfirmed mutations remain indeterminate. Each Execute request carries one record and its consecutive index. The client streams records as they are produced; server aggregation stays within the Store. Later invalid records stop the stream while preserving earlier acknowledged writes. -Documents use explicit `ContentType` fields. Native selects either a BSON MongoDB command or a typed Search HTTP request; SDK consumers receive chunks with validated response metadata. +Documents use explicit `ContentType` fields. Native carries an opaque request Document and optional response metadata; adapters own the formats. HTTP fixtures use standard messages through SDK helpers. Tests verify unknown content types reach adapter classification, while adapter-specific projection rules do not constrain other Stores. Services bind to loopback and own exclusive namespaces. Cleanup verifies exact process and container ownership. Fixture logs, manifests and cleanup receipts diff --git a/tests/integration/lifecycle_test.go b/tests/integration/lifecycle_test.go index a31e0a19..2eff34da 100644 --- a/tests/integration/lifecycle_test.go +++ b/tests/integration/lifecycle_test.go @@ -216,9 +216,9 @@ func testNative(t *testing.T, ctx context.Context, client *weir.Client, backend parts := strings.Split(backend.collection, "/") filter := bson.D{{Key: "_id", Value: "primary"}} command := bson.D{{Key: "count", Value: parts[len(parts)-1]}, {Key: "query", Value: filter}} - request.MongoDBCommand = bsonDocument(t, command).Data + request.Request = bsonDocument(t, command) } else { - request.SearchHTTP = &weir.SearchHTTPRequest{Method: http.MethodGet, Path: "/_doc/primary"} + request = nativeHTTPGet(t, backend.collection, "/_doc/primary") } var head *weir.NativeResponse var body []byte @@ -247,7 +247,10 @@ func testNative(t *testing.T, ctx context.Context, client *weir.Client, backend } return } - metadata := head.GetHttp() + metadata, err := weir.ParseHTTPNativeResponse(head) + if err != nil { + t.Fatal(err) + } var response struct { Found bool `json:"found"` Source struct { @@ -258,3 +261,16 @@ func testNative(t *testing.T, ctx context.Context, client *weir.Client, backend t.Fatalf("Native Search response: metadata=%v body=%s err=%v", metadata, body, err) } } + +func nativeHTTPGet(t *testing.T, resource, path string) *weir.NativeRequest { + t.Helper() + request, err := http.NewRequest(http.MethodGet, "http://weir.invalid"+path, nil) + if err != nil { + t.Fatal(err) + } + native, err := weir.NewHTTPNativeRequest(resource, request) + if err != nil { + t.Fatal(err) + } + return native +} diff --git a/tests/integration/semantics_test.go b/tests/integration/semantics_test.go index 30482384..77102e2c 100644 --- a/tests/integration/semantics_test.go +++ b/tests/integration/semantics_test.go @@ -221,6 +221,56 @@ func (s *system) testProjectionAndFailures(t *testing.T, backend *backendData) { t.Fatalf("exclude projection: %v %v", end, err) } s.testMissingTargets(t, target) + s.testAdapterOwnedEnvelopes(t, target) +} + +func (s *system) testAdapterOwnedEnvelopes(t *testing.T, target *backendData) { + t.Helper() + payload := &weir.Document{ContentType: "application/vnd.example.operation", Data: []byte("opaque request")} + native := &weir.NativeRequest{Resource: target.collection, Request: payload} + options := weir.NativeOptions{StoreName: target.name, Request: native, Consume: func(context.Context, *weir.NativeResponse, []byte) error { return nil }} + result, err := s.client.Native(s.ctx, options) + if err != nil || result == nil || result.Response != nil || result.Completion != weir.NativeNotStarted || result.Failure.GetCode() != weir.FailureUnsupported { + t.Fatalf("unknown format must reach adapter classification: %v %v", result, err) + } + + projection := &weir.Projection{Mode: weir.ProjectionInclude, Fields: []string{"$literal"}} + request := &weir.ScanRequest{Resource: target.collection, Projection: projection, PageSize: 1} + scan := weir.ScanOptions{StoreName: target.name, Request: request, Consume: func(context.Context, *weir.Document) error { return nil }} + if target.name == "mongo" { + end, err := s.client.Scan(s.ctx, scan) + if err != nil || end.GetDocumentCount() != 0 || end.GetFailure().GetCode() != weir.FailureUnsupported { + t.Fatalf("Mongo field rule must be enforced by adapter: %v %v", end, err) + } + return + } + + literal := target.provisionTarget(t, s.ctx, "literal.fields") + document := &weir.Document{ContentType: "application/json", Data: []byte(`{"$literal":42,"n":1}`)} + write := &weir.WriteRequest{Resource: literal.resource("literal"), Document: document} + writeOptions := weir.WriteOptions{StoreName: literal.name, Request: write} + mutation, err := s.client.Create(s.ctx, writeOptions) + assertApplied(t, mutation, err) + refresh := httpRequest{method: http.MethodPost, path: "/" + literal.collection + "/_refresh"} + code, body := literal.httpDo(t, s.ctx, refresh) + if code != http.StatusOK { + t.Fatalf("refresh literal field: %d %s", code, body) + } + request.Resource = literal.collection + scan.Consume = func(_ context.Context, value *weir.Document) error { + var fields map[string]int + if err := json.Unmarshal(value.Data, &fields); err != nil { + return err + } + if len(fields) != 1 || fields["$literal"] != 42 { + return fmt.Errorf("literal field projection mismatch: %s", value.Data) + } + return nil + } + end, err := s.client.Scan(s.ctx, scan) + if err != nil || end.GetFailure() != nil || end.GetDocumentCount() != 1 { + t.Fatalf("store-neutral literal field: %v %v", end, err) + } } func (s *system) testMissingTargets(t *testing.T, target *backendData) { @@ -258,9 +308,9 @@ func (s *system) testMissingTargets(t *testing.T, target *backendData) { nativeMissing := &weir.NativeRequest{Resource: missing.collection} if target.name == "mongo" { command := bson.D{{Key: "count", Value: target.mongo.Name() + ".never_created"}} - nativeMissing.MongoDBCommand = bsonDocument(t, command).Data + nativeMissing.Request = bsonDocument(t, command) } else { - nativeMissing.SearchHTTP = &weir.SearchHTTPRequest{Method: http.MethodGet, Path: "/_doc/absent"} + nativeMissing = nativeHTTPGet(t, missing.collection, "/_doc/absent") } nativeMissingOptions := weir.NativeOptions{StoreName: target.name, Request: nativeMissing, Consume: func(context.Context, *weir.NativeResponse, []byte) error { return nil }} missingResult, err := s.client.Native(s.ctx, nativeMissingOptions) @@ -268,12 +318,15 @@ func (s *system) testMissingTargets(t *testing.T, target *backendData) { t.Fatalf("missing Native target: %v %v", missingResult, err) } if target.name == "search" { - httpRequest := &weir.SearchHTTPRequest{Method: http.MethodGet, Path: "/_doc/absent"} - native := &weir.NativeRequest{Resource: target.collection, SearchHTTP: httpRequest} + native := nativeHTTPGet(t, target.collection, "/_doc/absent") nativeOpts := weir.NativeOptions{StoreName: target.name, Request: native, Consume: func(context.Context, *weir.NativeResponse, []byte) error { return nil }} result, err := s.client.Native(s.ctx, nativeOpts) - if err != nil || result == nil || result.Completion != weir.NativeResponseComplete || result.Failure != nil || result.Response.GetHttp().GetStatusCode() != http.StatusNotFound { + if err != nil || result == nil || result.Completion != weir.NativeResponseComplete || result.Failure != nil { t.Fatalf("complete HTTP 404 native response: %v %v", result, err) } + response, err := weir.ParseHTTPNativeResponse(result.Response) + if err != nil || response.StatusCode != http.StatusNotFound { + t.Fatalf("HTTP 404 metadata: %v %v", response, err) + } } } From 1e3da2d0e19294e54b16216c72cf48a5b435100a Mon Sep 17 00:00:00 2001 From: Randy <857271370@qq.com> Date: Mon, 5 Oct 2026 00:28:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=8C=20chore:=20lock=20Store-neutra?= =?UTF-8?q?l=20releases=20and=20server=20revision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 4 ++-- go.sum | 8 ++++---- versions.json | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 3ce375c0..4e4c0f0f 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/batchstream/weir-tests go 1.27.1 require ( - github.com/batchstream/weir-go v0.8.0 - github.com/batchstream/weir-protocol v0.6.0 + github.com/batchstream/weir-go v0.9.0 + github.com/batchstream/weir-protocol v0.7.0 go.mongodb.org/mongo-driver/v2 v2.9.1 google.golang.org/grpc v1.83.2 ) diff --git a/go.sum b/go.sum index f044fcb5..35f74460 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ -github.com/batchstream/weir-go v0.8.0 h1:NB1K66a61ceLnE7GVUw3N5VfK19D5tunqXzuK59Xkxw= -github.com/batchstream/weir-go v0.8.0/go.mod h1:nNqdGY1ajxYNkRLJWUprF+vQebxd2fOuq0ePAgo2rXs= -github.com/batchstream/weir-protocol v0.6.0 h1:Mpminz34U6IFmqJ0eIl5YA3ClyTok+sxnuLqvIBZHKU= -github.com/batchstream/weir-protocol v0.6.0/go.mod h1:hHmwPoE9yHYAz7Auc3a14Ijo/uxAef4sQ9nBtyXNcGc= +github.com/batchstream/weir-go v0.9.0 h1:a4pGdTJd9/5Y8QMTz37ipHpfSXztpPB84Wm4Wl0fc7A= +github.com/batchstream/weir-go v0.9.0/go.mod h1:lAlK3m/CBl+WZUhMIKwhGdqoeb4wnoteKWppyCfgZLo= +github.com/batchstream/weir-protocol v0.7.0 h1:+LSSLPCWv8GL8RgkH06LYNT8wDN5tFRAs0rle1Ym4sY= +github.com/batchstream/weir-protocol v0.7.0/go.mod h1:hHmwPoE9yHYAz7Auc3a14Ijo/uxAef4sQ9nBtyXNcGc= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/versions.json b/versions.json index 6d5872ad..efb76296 100644 --- a/versions.json +++ b/versions.json @@ -1,13 +1,13 @@ { "go": "1.27.1", - "sdk": "v0.8.0", - "protocol": "v0.6.0", - "weir_source": "dbcf308fd682905c8d45ea631107c2e454a4af80", + "sdk": "v0.9.0", + "protocol": "v0.7.0", + "weir_source": "c00fcec963326100f6156e183bbc074dc7a7d4d7", "mongodb_version": "8.0.32", "elasticsearch_version": "8.19.22", "elasticsearch_image": "docker.elastic.co/elasticsearch/elasticsearch@sha256:e98f9c3b09beb2fbb9eaf667d602df3f0e00bd3644138b8458dc17ba1a675595", - "weir_version": "v0.1.1-0.20261004150119-dbcf308fd682", - "weir_sum": "h1:FVKpFJrCgCUE3Ej9QmKIeeFU8ft40KYlRuc/Ld4Vhy8=", + "weir_version": "v0.1.1-0.20261004162211-c00fcec96332", + "weir_sum": "h1:DowMQvE5uL5fI0iUCLenY/kaFPLr0XHIV6HYnKULr5o=", "mongodb_image": "mongo@sha256:d0d926f94df099bff534b7ee5b5986458131a22489dfff8664509af0c1e2ca9c", "mongodb_darwin_arm64_url": "https://fastdl.mongodb.org/osx/mongodb-macos-arm64-8.0.32.tgz", "mongodb_darwin_arm64_sha256": "f81cb258434d548dca7244d599c82eb339043d8dedd0b1b807870c9d263117f2",