From 4fe54bfefb800c4a1be75b149649721f2020e2fc Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Wed, 11 Nov 2026 13:42:26 -0500 Subject: [PATCH] fix(api): repair artifact detail schema and YAML descriptions --- cli/internal/daemon/protocol/api.gen.go | 6 +- cli/internal/daemon/protocol/digest.gen.go | 2 +- cli/tools/apigen/main_test.go | 123 +++++++++++++++++++++ docs/openapi.yaml | 7 +- src/albedo/daemon/api_digest.gleam | 2 +- test.sh | 1 + web/src/lib/api.gen.d.ts | 6 +- 7 files changed, 135 insertions(+), 12 deletions(-) create mode 100644 cli/tools/apigen/main_test.go diff --git a/cli/internal/daemon/protocol/api.gen.go b/cli/internal/daemon/protocol/api.gen.go index 442bb794d..1314d1703 100644 --- a/cli/internal/daemon/protocol/api.gen.go +++ b/cli/internal/daemon/protocol/api.gen.go @@ -3903,7 +3903,7 @@ type TransferManifest struct { Bytes int64 `json:"bytes"` Columns []string `json:"columns"` - // Digest SHA-256 + // Digest SHA-256, lowercase hex. Digest string `json:"digest"` Kind string `json:"kind"` Name string `json:"name"` @@ -3960,7 +3960,7 @@ type TransferRunsThere struct { Alternatives []string `json:"alternatives"` Model string `json:"model"` - // Name The session's family name + // Name The session's family name, else its name or title. Name string `json:"name"` // Ok The target has this profile and it offers this model. @@ -4011,7 +4011,7 @@ type TransferStatus struct { Total int64 `json:"total"` } `json:"rows"` - // SessionID The root session + // SessionID The root session, the same id as on the source. SessionID string `json:"session_id"` // State importing and installing are still inert; active is live. diff --git a/cli/internal/daemon/protocol/digest.gen.go b/cli/internal/daemon/protocol/digest.gen.go index 68b25e043..3dcf998fb 100644 --- a/cli/internal/daemon/protocol/digest.gen.go +++ b/cli/internal/daemon/protocol/digest.gen.go @@ -5,4 +5,4 @@ package protocol // APIDigest identifies the wire contract these types were generated from. // The daemon reports its own in GET /server; a different value means this // client's decoders may reject what the daemon sends. -const APIDigest = "60d282d845d1f2094c44de9cf76c0eb27f1dcd7026e35751c3ade32cbf9d48ea" +const APIDigest = "648e670b275fd21a29c68724979500c75ec15e76f8f4d15889b4c5d85f7d8f0c" diff --git a/cli/tools/apigen/main_test.go b/cli/tools/apigen/main_test.go new file mode 100644 index 000000000..50644a555 --- /dev/null +++ b/cli/tools/apigen/main_test.go @@ -0,0 +1,123 @@ +package main + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/getkin/kin-openapi/openapi3" + "go.yaml.in/yaml/v3" +) + +// TestArtifactDetailContract catches the closed-base allOf contradiction +// that no generated type can express: Artifact forbade the history field +// that ArtifactDetail requires, so every real detail response was invalid. +// It also pins the three flow-style descriptions that YAML parsed into +// accidental schema keys. +func TestArtifactDetailContract(t *testing.T) { + rawDocument := readContractDocument(t) + assertDescription(t, rawDocument, + "The session's family name, else its name or title.", + "components", "schemas", "TransferRunsThere", "properties", "name") + assertDescription(t, rawDocument, + "SHA-256, lowercase hex.", + "components", "schemas", "TransferManifest", "properties", "segments", "items", "properties", "digest") + assertDescription(t, rawDocument, + "The root session, the same id as on the source.", + "components", "schemas", "TransferStatus", "properties", "session_id") + + document := loadContract(t, rawDocument) + detail := document.Components.Schemas["ArtifactDetail"] + if detail == nil || detail.Value == nil { + t.Fatal("ArtifactDetail schema is missing") + } + + complete := artifactDetailExample(t) + if err := detail.Value.VisitJSON(complete); err != nil { + t.Fatalf("complete flat artifact detail should validate: %v", err) + } + + incomplete := artifactDetailExample(t) + delete(incomplete, "history") + if err := detail.Value.VisitJSON(incomplete); err == nil { + t.Fatal("artifact detail without required history should not validate") + } +} + +func readContractDocument(t *testing.T) map[string]any { + t.Helper() + data, err := os.ReadFile(filepath.Join("..", "..", "..", "docs", "openapi.yaml")) + if err != nil { + t.Fatal(err) + } + var document map[string]any + if err := yaml.Unmarshal(data, &document); err != nil { + t.Fatal(err) + } + return document +} + +// loadContract mirrors the generator's loader input: the canonical 3.2 +// document with only its declared version lowered to the 3.1 the loader +// supports, before any lossy Go projection. +func loadContract(t *testing.T, document map[string]any) *openapi3.T { + t.Helper() + document["openapi"] = "3.1.0" + data, err := json.Marshal(document) + if err != nil { + t.Fatal(err) + } + loaded, err := openapi3.NewLoader().LoadFromData(data) + if err != nil { + t.Fatal(err) + } + return loaded +} + +func assertDescription(t *testing.T, document map[string]any, want string, path ...string) { + t.Helper() + node := document + for _, key := range path { + child, ok := node[key].(map[string]any) + if !ok { + t.Fatalf("schema path %v is missing at %q", path, key) + } + node = child + } + if got := node["description"]; got != want { + t.Fatalf("description at %v = %v, want %q (schema keys: %v)", path, got, want, node) + } +} + +func artifactDetailExample(t *testing.T) map[string]any { + t.Helper() + var example map[string]any + err := json.Unmarshal([]byte(`{ + "id": "abc123def456", + "key": "0123456789abcdef0123456789abcdef", + "title": "Report", + "version": 1, + "versions": 1, + "entry": "index.html", + "session_id": "session-1", + "session_name": "Session", + "session_deleted": false, + "workspace": "/tmp/workspace", + "created_at": 1, + "updated_at": 2, + "bytes": 123, + "history": [{ + "version": 1, + "entry": "index.html", + "created_at": 1, + "cell_id": "cell-1", + "files": [{"path": "index.html", "size": 123}], + "bytes": 123 + }] + }`), &example) + if err != nil { + t.Fatal(err) + } + return example +} diff --git a/docs/openapi.yaml b/docs/openapi.yaml index a2b696ac2..a8acf8e96 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -7029,7 +7029,7 @@ components: properties: session_id: $ref: '#/components/schemas/ID' - name: {type: string, description: The session's family name, else its name or title.} + name: {type: string, description: "The session's family name, else its name or title."} ok: {type: boolean, description: The target has this profile and it offers this model.} profile: {type: string} model: {type: string} @@ -7215,7 +7215,7 @@ components: items: {type: string} rows: {type: integer} bytes: {type: integer} - digest: {type: string, description: SHA-256, lowercase hex.} + digest: {type: string, description: 'SHA-256, lowercase hex.'} TransferStatus: type: object required: [state, bytes, received, rows, session_id, home, lost, error] @@ -7234,7 +7234,7 @@ components: properties: done: {type: integer} total: {type: integer} - session_id: {type: string, description: The root session, the same id as on the source.} + session_id: {type: string, description: 'The root session, the same id as on the source.'} home: {type: string, description: This daemon's home.} lost: type: array @@ -11056,7 +11056,6 @@ components: $ref: '#/components/schemas/Counter' required: [id, key, title, version, versions, entry, session_id, session_name, session_deleted, workspace, created_at, updated_at, bytes] - additionalProperties: false ArtifactPage: type: object properties: diff --git a/src/albedo/daemon/api_digest.gleam b/src/albedo/daemon/api_digest.gleam index 49cf91b52..a96e0345c 100644 --- a/src/albedo/daemon/api_digest.gleam +++ b/src/albedo/daemon/api_digest.gleam @@ -2,4 +2,4 @@ //// GET /server reports it so a client built from another contract can tell. pub const digest = - "60d282d845d1f2094c44de9cf76c0eb27f1dcd7026e35751c3ade32cbf9d48ea" + "648e670b275fd21a29c68724979500c75ec15e76f8f4d15889b4c5d85f7d8f0c" diff --git a/test.sh b/test.sh index c77458a5c..1527de0b7 100755 --- a/test.sh +++ b/test.sh @@ -106,6 +106,7 @@ changed() { suite "gleam test" gleam test suite "python harness" python3 test/python_test_runner.py --jobs "$ALBEDO_TEST_HARNESS_JOBS" test/harness/*_test.py suite "go test" go -C cli test ./internal/... ./cmd/... +suite "API contract" go -C cli/tools/apigen test . suite "web client" node --test web/scripts/*.test.mjs # the Go e2e suite builds its own CLI and boots a hermetic daemon, so it must # never reuse a cached run. Bound parallel scenarios while the other suites run. diff --git a/web/src/lib/api.gen.d.ts b/web/src/lib/api.gen.d.ts index 9cb5df39b..f7748bfe2 100644 --- a/web/src/lib/api.gen.d.ts +++ b/web/src/lib/api.gen.d.ts @@ -2083,7 +2083,7 @@ export interface components { }; TransferRunsThere: { session_id: components["schemas"]["ID"]; - /** @description The session's family name */ + /** @description The session's family name, else its name or title. */ name: string; /** @description The target has this profile and it offers this model. */ ok: boolean; @@ -2199,7 +2199,7 @@ export interface components { columns: string[]; rows: number; bytes: number; - /** @description SHA-256 */ + /** @description SHA-256, lowercase hex. */ digest: string; }[]; }; @@ -2215,7 +2215,7 @@ export interface components { done: number; total: number; }; - /** @description The root session */ + /** @description The root session, the same id as on the source. */ session_id: string; /** @description This daemon's home. */ home: string; -- knotmirror 0.0.1