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>
This commit is contained in:
tajniak81andClaude Opus 5.5 committed 2026-10-31 16:11:07 +01:00
1 parent e717c1d69f
commit ba394b8fac
193 files changed
+6425 -399

No files matched your search

+3 -1
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
@@ -62,7 +64,7 @@ func (a *api) requireManager(next http.HandlerFunc) http.HandlerFunc {
})
}
func (a *api) routes(mux *http.ServeMux) {
func (a *api) routes(mux *routeMux) {
mux.HandleFunc("GET /api/v1/auth/methods", func(w http.ResponseWriter, r *http.Request) {
m, err := a.auth.Methods(r.Context())
a.respond(w, m, err)
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
+3 -1
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
@@ -31,7 +33,7 @@ const (
// collabRoute serves /collab?page=<id>: the y-websocket protocol for one page.
// Browsers cannot set headers on a WebSocket, and tokens in URLs end up in
// logs, so the first message must be a text frame holding the session token.
func (a *api) collabRoute(mux *http.ServeMux, origins []string) {
func (a *api) collabRoute(mux *routeMux, origins []string) {
patterns := make([]string, 0, len(origins))
for _, o := range origins {
if u, err := url.Parse(o); err == nil && u.Host != "" {
+66
View File
@@ -0,0 +1,66 @@
// 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)
}
}
}
+3 -1
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
@@ -38,7 +40,7 @@ func caller(r *http.Request) access.Caller {
return u.Caller()
}
func (a *api) directoryRoutes(mux *http.ServeMux) {
func (a *api) directoryRoutes(mux *routeMux) {
// Users (admins: own organization; superadmins: everyone).
mux.HandleFunc("GET /api/v1/users", a.requireManager(func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
+24 -2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// Package httpapi wires the public HTTP surface of docwell-server.
package httpapi
@@ -27,8 +29,28 @@ type Deps struct {
Log *slog.Logger
}
// routeMux is a ServeMux that remembers its patterns, so a test can compare
// them with api/openapi.yaml.
type routeMux struct {
*http.ServeMux
patterns []string
}
func (m *routeMux) Handle(pattern string, h http.Handler) {
m.patterns = append(m.patterns, pattern)
m.ServeMux.Handle(pattern, h)
}
func (m *routeMux) HandleFunc(pattern string, h func(http.ResponseWriter, *http.Request)) {
m.Handle(pattern, http.HandlerFunc(h))
}
func NewRouter(d Deps) http.Handler {
mux := http.NewServeMux()
return logRequests(d.Log, cors(d.CORSOrigins, newMux(d)))
}
func newMux(d Deps) *routeMux {
mux := &routeMux{ServeMux: http.NewServeMux()}
a := &api{auth: d.Auth, dir: d.Directory, collab: d.Collab, log: d.Log}
a.routes(mux)
a.collabRoute(mux, d.CORSOrigins)
@@ -58,7 +80,7 @@ func NewRouter(d Deps) http.Handler {
mux.Handle("GET /admin", http.RedirectHandler("/admin/", http.StatusMovedPermanently))
}
return logRequests(d.Log, cors(d.CORSOrigins, mux))
return mux
}
func writeJSON(w http.ResponseWriter, status int, v any) {
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
+3 -1
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
@@ -37,7 +39,7 @@ type SpaceService interface {
PurgePage(ctx context.Context, c access.Caller, id string) error
}
func (a *api) spaceRoutes(mux *http.ServeMux) {
func (a *api) spaceRoutes(mux *routeMux) {
// Spaces. Rights are resolved per space (see access.SpaceRole).
mux.HandleFunc("GET /api/v1/workspaces/{id}/spaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
list, err := a.dir.ListSpaces(r.Context(), caller(r), r.PathValue("id"))
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (