Files
Docwell/Server/internal/httpapi/contract_test.go
T
tajniak81andClaude Opus 5.5 ba394b8fac Finish Phase 0: lint, codegen, contributor docs and the two remaining spikes
Repository basics:
- CONTRIBUTING.md and CODE_OF_CONDUCT.md (Contributor Covenant 2.1)
- SPDX AGPL-3.0-or-later headers on all hand-written sources, checked in CI
- golangci-lint (shared .golangci.yml), ESLint and Prettier, all run in CI

API codegen from api/openapi.yaml (npm run generate, drift fails CI):
- Go types via oapi-codegen in Server/internal/api
- a contract test that the router and the spec list the same routes
- Dart models via Phone-App/tool/generate_api.dart; the app uses them

Spike: shared Tiptap editor in a Flutter WebView (ADR-4)
- @docwell/editor-bridge builds the editor into one HTML page with a
  versioned JSON protocol; Phone-App hosts it with webview_flutter and a
  native toolbar. Integration test passes on an Android API 35 emulator.
- flutter_inappwebview dropped: its Android plugin fails on AGP 9.

Spike: Wails v3 desktop (ADR-11)
- system tray, docwell:// deep links (page and space only) with
  single-instance hand-off, and the built-in updater with a required
  ed25519 signing key. Verified on Windows.
- regenerated build assets register the scheme and drop template
  placeholders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 16:11:07 +01:00

67 lines
1.5 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
"io"
"log/slog"
"net/http"
"os"
"slices"
"strings"
"testing"
"gopkg.in/yaml.v3"
)
// notInSpec are routes that OpenAPI does not describe: the catch-all 404, the
// admin SPA and the collaboration WebSocket.
var notInSpec = []string{"/api/", "GET /admin/", "GET /admin", "GET /collab"}
// TestRoutesMatchContract checks that the router and api/openapi.yaml list the
// same operations, so neither can change without the other.
func TestRoutesMatchContract(t *testing.T) {
raw, err := os.ReadFile("../../../api/openapi.yaml")
if err != nil {
t.Fatal(err)
}
var spec struct {
Paths map[string]map[string]any `yaml:"paths"`
}
if err := yaml.Unmarshal(raw, &spec); err != nil {
t.Fatal(err)
}
var want []string
for path, ops := range spec.Paths {
for method := range ops {
switch method {
case "get", "put", "post", "patch", "delete":
want = append(want, strings.ToUpper(method)+" "+path)
}
}
}
mux := newMux(Deps{
DB: fakeDB{},
Admin: http.NotFoundHandler(),
Log: slog.New(slog.NewTextHandler(io.Discard, nil)),
})
var got []string
for _, p := range mux.patterns {
if !slices.Contains(notInSpec, p) {
got = append(got, p)
}
}
for _, op := range want {
if !slices.Contains(got, op) {
t.Errorf("%s is in api/openapi.yaml but not routed", op)
}
}
for _, p := range got {
if !slices.Contains(want, p) {
t.Errorf("%s is routed but missing from api/openapi.yaml", p)
}
}
}