From d73d68dac0d4908661361f20223421535a21eb17 Mon Sep 17 00:00:00 2001 From: Hannah Cheng Date: Thu, 13 Aug 2026 21:49:41 +0800 Subject: [PATCH 1/2] fix(errors): map application error codes to HTTP statuses A "not found" left this service as HTTP 500. So did bad parameters, and every other application error - a client could not tell a missing document from a broken server, which is what #59 asked for four hundred days ago. The mapping was never missing. sderrors.Code has carried GRPCCode() for a long time (CodeNotFound -> codes.NotFound, CodeBadParameters -> codes.InvalidArgument, ...) and grpc-gateway renders the status from there. What was missing is GRPCStatus() on *sderrors.Error, which arrived in a newer github.com/sdinsure/agent than this module pinned. Without it every error left gRPC as codes.Unknown and the gateway rendered 500, discarding a code the error was carrying the whole time: [500] {"code":2, "message":"code(1), document nope not found ..."} ^^^ HTTP ^^^ Unknown ^^^ CodeNotFound, right there Consumers whose module graph already selected a newer sdinsure got correct statuses out of these same handlers - which is why grandturks saw a proper 501 from DeleteDocument while restcol standalone saw 500. v0.0.0-20240507074650-281b67936555 -> v0.0.0-20260812141753-3e9fb7b72eaa Measured after the bump, not assumed: missing document DELETE -> 404 (was 500) missing document GET -> 404 (was 500) unknown project DELETE -> 400 (was 500) Two API changes needed migrating: - runtime.ProjectInfor gained Visibility(). restcol has no per-project visibility - ModelProject carries an ID and a type, and authorization is AllowEveryOne - so it returns "", which the interface defines as unknown/unresolved and which sdinsure's own invalidProjectInfor returns. Inventing "PUBLIC" would tell a future authorization path that every restcol project is world-visible, on no evidence. - logger.NewLogger gained a verbose bool. Passing false preserves the old behaviour: the previous constructor logged at info and above. One latent bug surfaced and had to be fixed with it. The bump carries gorm.io/driver/postgres 1.5.7 -> 1.5.11 and pgx v5.5.5 -> v5.9.2, and the newer pgx calls driver.Valuer on nil pointers where the old one short-circuited to NULL. SwagValueValue.Value has had a pointer receiver since 073e3a3e, so a nil *SwagValueValue satisfies driver.Valuer, and ModelFieldSchema.FieldExample is routinely nil: unable to encode (*SwagValueValue)(nil) into text format for jsonb (OID 3802): proto: google.protobuf.Value: none of the oneof fields is set That failed every insert carrying a schema field without an example, taking out TestDocument and TestStorage. Value now returns NULL for a nil receiver, and Scan tolerates a NULL column instead of panicking on its type assertion. Worth noting this was only visible because #134 made the postgres-backed tests run. On the old CI it would have merged green and broken writes in production. The integration assertions now check the HTTP status as well as the application code. The previous comment explaining why they could not is removed along with the reason for it. Closes #59 Co-Authored-By: Claude Opus 5 (1M context) --- go.mod | 47 +++++----- go.sum | 97 ++++++++++----------- integrationtest/document_delete_test.go | 36 +++++--- integrationtest/stream_test.go | 2 +- integrationtest/suite.go | 2 +- main.go | 2 +- pkg/app/handlers_test.go | 6 +- pkg/models/collections/schema.go | 29 +++++- pkg/runtime/getter/project.go | 16 ++++ pkg/schema/schema_finder_test.go | 4 +- pkg/storage/collections/collections_test.go | 2 +- pkg/storage/documents/documents_test.go | 10 +-- pkg/storage/projects/projects_test.go | 2 +- 13 files changed, 149 insertions(+), 106 deletions(-) diff --git a/go.mod b/go.mod index 023402c..c2f86a1 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/footprintai/restcol -go 1.23.0 - -toolchain go1.24.1 +go 1.25.0 require ( github.com/clbanning/mxj/v2 v2.7.0 @@ -20,8 +18,8 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 github.com/hashicorp/go-version v1.7.0 - github.com/sdinsure/agent v0.0.0-20240507074650-281b67936555 - github.com/stretchr/testify v1.10.0 + github.com/sdinsure/agent v0.0.0-20260812141753-3e9fb7b72eaa + github.com/stretchr/testify v1.11.1 google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb google.golang.org/grpc v1.72.0 google.golang.org/protobuf v1.36.6 @@ -46,45 +44,41 @@ require ( github.com/google/go-querystring v1.1.0 // indirect github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/jackc/chunkreader/v2 v2.0.1 // indirect - github.com/jackc/pgconn v1.14.3 // indirect github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa // indirect - github.com/jackc/pgio v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgproto3/v2 v2.3.3 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgx/v5 v5.5.5 // indirect - github.com/jackc/puddle/v2 v2.2.1 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/pgx/v5 v5.9.2 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mailru/easyjson v0.9.0 // indirect github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oklog/ulid v1.3.1 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_golang v1.19.0 // indirect + github.com/prometheus/client_golang v1.20.5 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.48.0 // indirect - github.com/prometheus/procfs v0.12.0 // indirect + github.com/prometheus/common v0.61.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/spf13/viper v1.18.2 // indirect + github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/zeromicro/go-zero v1.6.4 // indirect - go.mongodb.org/mongo-driver v1.14.0 // indirect + go.mongodb.org/mongo-driver v1.16.1 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.51.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.58.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect go.opentelemetry.io/otel v1.34.0 // indirect - go.opentelemetry.io/otel/exporters/prometheus v0.48.0 // indirect + go.opentelemetry.io/otel/exporters/prometheus v0.56.0 // indirect go.opentelemetry.io/otel/metric v1.34.0 // indirect go.opentelemetry.io/otel/sdk v1.34.0 // indirect go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect @@ -92,15 +86,14 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/crypto v0.36.0 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/net v0.38.0 // indirect - golang.org/x/sync v0.12.0 // indirect + golang.org/x/sync v0.17.0 // indirect golang.org/x/sys v0.31.0 // indirect - golang.org/x/text v0.23.0 // indirect + golang.org/x/text v0.29.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/driver/postgres v1.5.7 // indirect + gorm.io/driver/postgres v1.5.11 // indirect ) diff --git a/go.sum b/go.sum index 2db2d2e..a1454a6 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.110.10 h1:LXy9GEO+timppncPIAZoOj3l58LIU9k+kn48AN7IO3Y= -cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk= +cloud.google.com/go v0.112.1 h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM= +cloud.google.com/go/compute v1.24.0 h1:phWcR2eWzRJaL/kOiJwfFsPs4BaKq1j6vnpZrc1YlVg= cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I= cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -104,27 +104,16 @@ github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= -github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= -github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= -github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= -github.com/jackc/pgconn v1.14.3 h1:bVoTr12EGANZz66nZPkMInAV/KHD2TxH9npjXXgiB3w= -github.com/jackc/pgconn v1.14.3/go.mod h1:RZbme4uasqzybK2RK5c65VsHxoyaml09lx3tXOcO/VM= github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa h1:s+4MhCQ6YrzisK6hFJUX53drDT4UsSW3DEhKn0ifuHw= github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds= -github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= -github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= -github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc= -github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag= -github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= -github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= -github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= -github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.9.2 h1:3ZhOzMWnR4yJ+RW1XImIPsD1aNSz4T4fyP7zlQb56hw= +github.com/jackc/pgx/v5 v5.9.2/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= @@ -133,6 +122,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -143,12 +134,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4= github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 h1:BpfhmLKZf+SjVanKKhCgf3bg+511DmU9eDQTen7LLbY= github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= @@ -158,21 +153,21 @@ github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeR github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= -github.com/pelletier/go-toml/v2 v2.2.0 h1:QLgLl2yMN7N+ruc31VynXs1vhMZa7CeHHejIeBAsoHo= -github.com/pelletier/go-toml/v2 v2.2.0/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= -github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= -github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= -github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= -github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFSRQQ= +github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= @@ -180,8 +175,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/sdinsure/agent v0.0.0-20240507074650-281b67936555 h1:1QWQNdQ2Ht1Fo5T22Re72sSVYldONdmCxuilAXeuHQI= -github.com/sdinsure/agent v0.0.0-20240507074650-281b67936555/go.mod h1:K6hMvibmTgmP6SYCl/MwZCllUUKuz1qO/OULetwZOTU= +github.com/sdinsure/agent v0.0.0-20260812141753-3e9fb7b72eaa h1:+T43N+MK3WjGz5wSxmR4wfdBO2k5ygSGaJFWAbUbplM= +github.com/sdinsure/agent v0.0.0-20260812141753-3e9fb7b72eaa/go.mod h1:9rGqrYh+SJsX+NKHW62fUs8654DimzazcQjTAxt/ns0= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= @@ -191,8 +186,8 @@ github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= -github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= @@ -206,29 +201,27 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zeromicro/go-zero v1.6.4 h1:GvZXxxwl1Lby/gIHxHwN/ZNmXl1WFJa1DvoVgqgttUs= -github.com/zeromicro/go-zero v1.6.4/go.mod h1:dQ39Zoz20/6x/SUhFXyEEg8lWjl+CO3dzg8Je2xG63Q= -go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80= -go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8= +go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 h1:A3SayB3rNyt+1S6qpI9mHPkeHTZbD7XILEqWnYZb2l0= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0/go.mod h1:27iA5uvhuRNmalO+iEUdVn5ZMj2qy10Mm+XRIpRmyuU= -go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.51.0 h1:974XTyIwHI4nHa1+uSLxHtUnlJ2DiVtAJjk7fd07p/8= -go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.51.0/go.mod h1:ZvX/taFlN6TGaOOM6D42wrNwPKUV1nGO2FuUXkityBU= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 h1:Xs2Ncz0gNihqu9iosIZ5SkBbWo5T8JhhLJFMQL1qmLI= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0/go.mod h1:vy+2G/6NvVMpwGX/NyLqcC41fxepnuKHk16E6IZUcJc= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 h1:qtFISDHKolvIxzSs0gIaiPUPR0Cucb0F2coHC7ZLdps= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0/go.mod h1:Y+Pop1Q6hCOnETWTW4NROK/q1hv50hM7yDaUTjG8lp8= +go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.58.0 h1:xwH3QJv6zL4u+gkPUu59NeT1Gyw9nScWT8FQpKLUJJI= +go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.58.0/go.mod h1:uosvgpqTcTXtcPQORTbEkZNDQTCDOgTz1fe6aLSyqrQ= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 h1:yd02MEjBdJkG3uabWP9apV+OuWRIXGDuJEUJbOHmCFU= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0/go.mod h1:umTcuxiv1n/s/S6/c2AT/g2CQ7u5C59sHDNmfSwgz7Q= go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= -go.opentelemetry.io/otel/exporters/prometheus v0.48.0 h1:sBQe3VNGUjY9IKWQC6z2lNqa5iGbDSxhs60ABwK4y0s= -go.opentelemetry.io/otel/exporters/prometheus v0.48.0/go.mod h1:DtrbMzoZWwQHyrQmCfLam5DZbnmorsGbOtTbYHycU5o= +go.opentelemetry.io/otel/exporters/prometheus v0.56.0 h1:GnCIi0QyG0yy2MrJLzVrIM7laaJstj//flf1zEJCG+E= +go.opentelemetry.io/otel/exporters/prometheus v0.56.0/go.mod h1:JQcVZtbIIPM+7SWBB+T6FK+xunlyidwLp++fN0sUaOk= go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= @@ -253,8 +246,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= -golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= @@ -286,8 +277,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= -golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -308,8 +299,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= -golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= +golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -359,8 +350,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM= -gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA= +gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= +gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= gorm.io/gorm v1.26.1 h1:ghB2gUI9FkS46luZtn6DLZ0f6ooBJ5IbVej2ENFDjRw= gorm.io/gorm v1.26.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/integrationtest/document_delete_test.go b/integrationtest/document_delete_test.go index a791e2f..eab8f97 100644 --- a/integrationtest/document_delete_test.go +++ b/integrationtest/document_delete_test.go @@ -2,6 +2,7 @@ package integrationtest import ( "fmt" + "net/http" "testing" sderrors "github.com/sdinsure/agent/pkg/errors" @@ -12,19 +13,16 @@ import ( ) // assertNotFound asserts that a call was refused because the document is not -// there, in the given (project, collection) scope. +// there, in the given (project, collection) scope — and that the refusal +// reaches the caller as an HTTP 404. // -// It checks the application error code carried in the message rather than the -// HTTP status, and that is deliberate. Standalone restcol answers 500 for -// *every* application error: this module pins a github.com/sdinsure/agent that -// predates GRPCStatus() on *sderrors.Error, so NotFound degrades to Unknown on -// the way out through the gateway. Consumers whose module graph selects a newer -// sdinsure — grandturks does, via MVS — already get a correct 404 out of this -// same handler. -// -// Asserting the application code therefore states the real contract, passes -// today, and keeps passing once the dependency is bumped and the status becomes -// 404. Asserting 500 would freeze the bug into the suite. +// The status half is the regression guard for #59. Until the sdinsure/agent +// bump, *every* application error left this service as a 500: the pinned +// version had no GRPCStatus() on *sderrors.Error, so NotFound degraded to +// Unknown on the way out through the gateway, and a client could not tell a +// missing document from a broken server. An earlier version of this helper +// deliberately asserted only the application code, so it would keep passing +// once the status was fixed. It is fixed; assert both. func assertNotFound(t *testing.T, err error) { t.Helper() if !assert.Error(t, err) { @@ -33,6 +31,14 @@ func assertNotFound(t *testing.T, err error) { want := fmt.Sprintf("code(%d),", sderrors.CodeNotFound.Int()) assert.Contains(t, err.Error(), want, "expected a NotFound application error, got: %v", err) + + coder, ok := err.(interface{ Code() int }) + if !assert.True(t, ok, "expected a generated error carrying a status, got %T", err) { + return + } + assert.Equal(t, http.StatusNotFound, coder.Code(), + "NotFound must reach the client as 404; a 500 here means the error code "+ + "is not being mapped to a gRPC status (#59)") } func TestDeleteDocument(t *testing.T) { @@ -182,6 +188,12 @@ func TestDeleteDocument_UnknownProjectIsRejected(t *testing.T) { assert.Error(t, err) assert.Contains(t, err.Error(), fmt.Sprintf("code(%d),", sderrors.CodeBadParameters.Int()), "an unresolvable project must be rejected by the identity middleware, got: %v", err) + if coder, ok := err.(interface{ Code() int }); assert.True(t, ok) { + // The other half of the #59 mapping: BadParameters must arrive as 400, + // not as the blanket 500 every application error used to become. + assert.Equal(t, http.StatusBadRequest, coder.Code(), + "BadParameters must reach the client as 400, got: %v", err) + } // ... and the document is untouched under its real project. getResp, err := client.Document.RestColServiceGetDocument( diff --git a/integrationtest/stream_test.go b/integrationtest/stream_test.go index 404a69a..cbae4b1 100644 --- a/integrationtest/stream_test.go +++ b/integrationtest/stream_test.go @@ -25,7 +25,7 @@ func TestIntegrationStreamTest(t *testing.T) { suite := SetupTest(t) defer suite.Close() - log := logger.NewLogger() + log := logger.NewLogger(false) client := suite.NewClient() // post /api/newdoc diff --git a/integrationtest/suite.go b/integrationtest/suite.go index 0c84a2f..57e6a14 100644 --- a/integrationtest/suite.go +++ b/integrationtest/suite.go @@ -35,7 +35,7 @@ func (s *suite) NewClient() *restcolopenapi.RestColAPIDocumentations { } func SetupTest(t *testing.T) *suite { - log := logger.NewLogger() + log := logger.NewLogger(false) postgresDb, err := storagetestutils.NewTestPostgresCli(log) if err != nil { assert.NoError(t, err) diff --git a/main.go b/main.go index 8116535..61a48bd 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ func main() { flag.Parse() version.Print() - log := logger.NewLogger() + log := logger.NewLogger(false) postgresDb, err := postgresstorage.NewPostgresDbHelper(log, restcolPostgresFlags) if err != nil { diff --git a/pkg/app/handlers_test.go b/pkg/app/handlers_test.go index 9626891..d8c31e9 100644 --- a/pkg/app/handlers_test.go +++ b/pkg/app/handlers_test.go @@ -41,11 +41,15 @@ type fixedProjectInfor struct { func (f *fixedProjectInfor) GetProjectID() (string, error) { return f.pid.String(), nil } func (f *fixedProjectInfor) GetProject(any) error { return nil } +// Visibility matches the production getter, which reports "" because restcol +// has no per-project visibility. See pkg/runtime/getter.projectInfor. +func (f *fixedProjectInfor) Visibility() string { return "" } + // newTestService spins up a full handler against a real postgres. Tests using // it must be guarded with testing.Short() — CI runs -short. func newTestService(t *testing.T) (*RestColServiceServerService, *projectsmodel.ModelProject) { t.Helper() - log := logger.NewLogger() + log := logger.NewLogger(false) db, err := storagetestutils.NewTestPostgresCli(log) assert.NoError(t, err) diff --git a/pkg/models/collections/schema.go b/pkg/models/collections/schema.go index 2b2e759..12c1860 100644 --- a/pkg/models/collections/schema.go +++ b/pkg/models/collections/schema.go @@ -176,10 +176,37 @@ var ( ) func (s *SwagValueValue) Scan(in any) error { - return s.Proto().UnmarshalJSON(in.([]byte)) + // A NULL column leaves the zero value rather than panicking on the type + // assertion, which is what happened when nothing checked. + if in == nil { + return nil + } + b, ok := in.([]byte) + if !ok { + return fmt.Errorf("schema: cannot scan %T into SwagValueValue, want []byte", in) + } + return s.Proto().UnmarshalJSON(b) } +// Value implements driver.Valuer. +// +// The nil check is load-bearing. The receiver is a pointer, so a nil +// *SwagValueValue *does* satisfy driver.Valuer, and database/sql hands it to +// the driver instead of substituting NULL - so this method gets called on nil. +// ModelFieldSchema.FieldExample is routinely nil (a field with no example), and +// without the guard the call reaches MarshalJSON on a nil structpb.Value and +// fails the whole insert: +// +// unable to encode (*SwagValueValue)(nil) into text format for jsonb (OID 3802): +// proto: google.protobuf.Value: none of the oneof fields is set +// +// pgx before v5.9 short-circuited nil pointers and never reached here, so this +// stayed latent from the receiver change until the driver moved. A missing +// example is SQL NULL. func (s *SwagValueValue) Value() (driver.Value, error) { + if s == nil { + return nil, nil + } return s.Proto().MarshalJSON() } diff --git a/pkg/runtime/getter/project.go b/pkg/runtime/getter/project.go index 1b4ed3c..1a9087a 100644 --- a/pkg/runtime/getter/project.go +++ b/pkg/runtime/getter/project.go @@ -47,3 +47,19 @@ func (p projectInfor) GetProjectID() (string, error) { func (p projectInfor) GetProject(v any) error { return errors.New("not impl") } + +// Visibility reports the project's visibility tag, and restcol has none. +// +// ModelProject carries an ID and a ProjectType (regular/external/proxy) — +// nothing about who may see it — and authorization here is +// appauthz.AllowEveryOne, so there is no visibility to report and nothing that +// would consume it. The interface defines the empty string as "unknown / +// unresolved", which is exactly the truthful answer; sdinsure's own +// invalidProjectInfor returns the same. +// +// Inventing a value ("PUBLIC") would be worse than saying nothing: a consumer +// that later reads this on an authorization path would be told every restcol +// project is world-visible on no evidence. +func (p projectInfor) Visibility() string { + return "" +} diff --git a/pkg/schema/schema_finder_test.go b/pkg/schema/schema_finder_test.go index bcca529..533c304 100644 --- a/pkg/schema/schema_finder_test.go +++ b/pkg/schema/schema_finder_test.go @@ -14,7 +14,7 @@ import ( func TestTraverseMap(t *testing.T) { traversedMap := make(map[string]interface{}) - TraverseMap(logger.NewLogger(), m1, []string{}, func(prefixes []string, current string, val any) error { + TraverseMap(logger.NewLogger(false), m1, []string{}, func(prefixes []string, current string, val any) error { path := strings.Join(append(prefixes, current), ".") traversedMap[path] = val return nil @@ -55,7 +55,7 @@ var ( ) func TestSchemaFlatten(t *testing.T) { - schemaBuilder := NewSchemaBuilder(logger.NewLogger()) + schemaBuilder := NewSchemaBuilder(logger.NewLogger(false)) m1Schema, err := schemaBuilder.Flatten(m1) assert.NoError(t, err) diff --git a/pkg/storage/collections/collections_test.go b/pkg/storage/collections/collections_test.go index ea23ac6..182ece5 100644 --- a/pkg/storage/collections/collections_test.go +++ b/pkg/storage/collections/collections_test.go @@ -29,7 +29,7 @@ func TestStorage(t *testing.T) { return } ctx := context.Background() - postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger()) + postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger(false)) assert.NoError(t, err) regularProject, proxyProject, err := storageprojects.TestProjectSuite(postgrescli) diff --git a/pkg/storage/documents/documents_test.go b/pkg/storage/documents/documents_test.go index c631589..b01e56c 100644 --- a/pkg/storage/documents/documents_test.go +++ b/pkg/storage/documents/documents_test.go @@ -33,7 +33,7 @@ func TestDocument(t *testing.T) { return } ctx := context.Background() - postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger()) + postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger(false)) assert.NoError(t, err) regularProject, _, err := storageprojects.TestProjectSuite(postgrescli) @@ -65,7 +65,7 @@ func TestDocumentQuery(t *testing.T) { return } ctx := context.Background() - postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger()) + postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger(false)) assert.NoError(t, err) regularProject, _, err := storageprojects.TestProjectSuite(postgrescli) @@ -131,7 +131,7 @@ func TestDocumentSameID(t *testing.T) { return } ctx := context.Background() - postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger()) + postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger(false)) assert.NoError(t, err) regularProject, _, err := storageprojects.TestProjectSuite(postgrescli) @@ -178,7 +178,7 @@ func TestDocumentCURD_Delete(t *testing.T) { if testing.Short() { t.Skip("requires a local postgres; skipping under -short") } - postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger()) + postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger(false)) assert.NoError(t, err) regularProject, _, err := storageprojects.TestProjectSuite(postgrescli) @@ -231,7 +231,7 @@ func TestDocumentCURD_Delete_WithWrongScope(t *testing.T) { if testing.Short() { t.Skip("requires a local postgres; skipping under -short") } - postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger()) + postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger(false)) assert.NoError(t, err) regularProject, proxyProject, err := storageprojects.TestProjectSuite(postgrescli) diff --git a/pkg/storage/projects/projects_test.go b/pkg/storage/projects/projects_test.go index 03c3b5c..4fbfdce 100644 --- a/pkg/storage/projects/projects_test.go +++ b/pkg/storage/projects/projects_test.go @@ -23,7 +23,7 @@ func TestProject(t *testing.T) { t.Skip("skip this for now") return } - postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger()) + postgrescli, err := storagetestutils.NewTestPostgresCli(logger.NewLogger(false)) assert.NoError(t, err) _, _, err = TestProjectSuite(postgrescli) From dae1c51beb4cc899beed475bab729cd74a88b05b Mon Sep 17 00:00:00 2001 From: Hannah Cheng Date: Thu, 13 Aug 2026 22:02:30 +0800 Subject: [PATCH 2/2] ci: move to go 1.25, which the sdinsure bump requires The first CI run of this branch failed, and not on a test: # github.com/footprintai/restcol/pkg/storage/testutil go: no such tool "covdata" # github.com/footprintai/restcol/pkg/version go: no such tool "covdata" Every test passed. The two packages named are the ones with no test files, where -coverprofile needs the covdata tool. The cause is a version split I introduced without noticing. sdinsure v0.0.0-20260812141753 declares `go 1.25.0`, so `go mod tidy` raised this module's directive from 1.23.0 to 1.25.0 and dropped `toolchain go1.24.1` - while the workflow still installed 1.24.1. Confirmed it is a real requirement rather than tidy being opinionated: $ GOTOOLCHAIN=go1.24.1 go build ./... go: github.com/sdinsure/agent@... requires go >= 1.25.0 (running go 1.24.1) So CI was compiling through an auto-downloaded 1.25 toolchain while its tool lookup still resolved against the 1.24.1 install, and only the two packages that need covdata noticed. Aligns the workflow with the directive: go-version 1.24.1 -> 1.25.0 in both jobs. Verified with GOTOOLCHAIN=go1.25.0 running CI's exact command, `go test -race ./... -p 1 -timeout 15m -coverprofile=...`: no covdata error, and every postgres-backed package green under -race. Refs: #59 Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/go-build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go-build.yaml b/.github/workflows/go-build.yaml index 5b11294..d1af58b 100644 --- a/.github/workflows/go-build.yaml +++ b/.github/workflows/go-build.yaml @@ -49,7 +49,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.24.1" + go-version: "1.25.0" id: go - name: Check out code into the Go module directory @@ -88,7 +88,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.24.1" + go-version: "1.25.0" - name: Check out code into the Go module directory uses: actions/checkout@v4