Files
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

92 lines
2.7 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package main
import (
"context"
"crypto/ed25519"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/json"
"net/http"
"net/http/httptest"
"runtime"
"strings"
"testing"
"github.com/wailsapp/wails/v3/pkg/updater"
)
// fakeHost stands in for the Wails app; Check only emits events.
type fakeHost struct{}
func (fakeHost) Emit(string, ...any) bool { return true }
func (fakeHost) OnEvent(string, func(any)) func() { return func() {} }
func (fakeHost) OpenWindow(updater.WindowOptions) updater.WindowHandle { return nil }
func (fakeHost) Quit() {}
func TestUpdateConfigNeedsFeedAndKey(t *testing.T) {
if _, ok, err := updateConfig("", ""); ok || err != nil {
t.Fatalf("no feed: ok=%v err=%v, want updates off", ok, err)
}
if _, _, err := updateConfig("https://updates.docwell.test/desktop.json", ""); err == nil {
t.Fatal("a feed without a signing key must be refused")
}
}
// TestUpdateFeed serves a signed manifest the way a release would publish it
// and checks the updater finds the new version for this platform.
func TestUpdateFeed(t *testing.T) {
pub, priv, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatal(err)
}
binary := []byte("docwell 9.9.9")
digest := sha256.Sum256(binary)
b64 := base64.StdEncoding.EncodeToString
var query string
mux := http.NewServeMux()
mux.HandleFunc("GET /desktop.json", func(w http.ResponseWriter, r *http.Request) {
query = r.URL.RawQuery
_ = json.NewEncoder(w).Encode(map[string]any{
"schemaVersion": 1,
"version": "9.9.9",
"notes": "Faster sync",
"artifacts": []map[string]any{{
"url": "/docwell-9.9.9",
"platform": runtime.GOOS,
"arch": runtime.GOARCH,
"size": len(binary),
"digestAlgo": "sha256",
"digest": b64(digest[:]),
"signatureAlgo": "ed25519",
"signature": b64(ed25519.Sign(priv, digest[:])),
}},
})
})
srv := httptest.NewServer(mux)
defer srv.Close()
cfg, ok, err := updateConfig(srv.URL+"/desktop.json", b64(pub))
if err != nil || !ok {
t.Fatalf("updateConfig: ok=%v err=%v", ok, err)
}
cfg.CheckInterval = 0
u := updater.New(fakeHost{})
if err := u.Init(cfg); err != nil {
t.Fatal(err)
}
rel, err := u.Check(context.Background())
if err != nil {
t.Fatal(err)
}
if rel == nil || rel.Version != "9.9.9" || rel.Verification == nil || len(rel.Verification.Signature) == 0 {
t.Fatalf("release = %+v", rel)
}
if want := "arch=" + runtime.GOARCH; !strings.Contains(query, want) || !strings.Contains(query, "version="+version) {
t.Errorf("manifest query %q should carry platform, arch and version", query)
}
}