Introduce a commercial license option alongside AGPL-3.0-only, require a CLA for contributors, and document the terms in COMMERCIAL.md and NOTICE. Add a script to stamp SPDX headers on Go files and apply it across the tree.
99 lines
3.2 KiB
Go
99 lines
3.2 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
package screens
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/forms"
|
|
|
|
// The registry is populated as the packages that declare forms
|
|
// initialise, so the coverage test links them in. internal/server
|
|
// declares the console's own forms; the integrations declare theirs.
|
|
_ "git.coopcloud.tech/wiki-cafe/member-console/internal/server"
|
|
)
|
|
|
|
// Capture coverage (spec ui-quality-gate "Capture coverage is checked
|
|
// against the form registry"; design D16). The capture utility writes the
|
|
// data-form id of every form it rendered open or refused to
|
|
// out/forms.json; this compares that set with the registry and fails on a
|
|
// form no capture ever showed. The thirteen-of-twenty-two gap the forms
|
|
// audit found (finding FA-45) turns from a hope into a red test.
|
|
//
|
|
// The test skips when there is no capture output, so `go test ./...`
|
|
// without `make screens` stays green; it is the sheet's gate, not a unit
|
|
// test.
|
|
func TestEveryRegisteredFormWasCaptured(t *testing.T) {
|
|
path := filepath.Join("..", "..", "screens", "out", "forms.json")
|
|
body, err := os.ReadFile(path)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
t.Skip("no capture output; run `make screens` first")
|
|
}
|
|
t.Fatalf("read %s: %v", path, err)
|
|
}
|
|
var shown []string
|
|
if err := json.Unmarshal(body, &shown); err != nil {
|
|
t.Fatalf("parse %s: %v", path, err)
|
|
}
|
|
seen := map[string]bool{}
|
|
for _, id := range shown {
|
|
seen[id] = true
|
|
}
|
|
|
|
registered := forms.All()
|
|
if len(registered) == 0 {
|
|
t.Fatal("no forms are registered; the declarations register as their package initialises")
|
|
}
|
|
|
|
var uncovered []string
|
|
for _, spec := range registered {
|
|
if seen[spec.Name] {
|
|
continue
|
|
}
|
|
if walkthrough, ok := WalkthroughVerifiedForms[spec.Name]; ok {
|
|
t.Logf("%s: not capturable; verified by %s", spec.Name, walkthrough)
|
|
continue
|
|
}
|
|
uncovered = append(uncovered, spec.Name)
|
|
}
|
|
sort.Strings(uncovered)
|
|
for _, name := range uncovered {
|
|
t.Errorf("the form %q was never shown open or refused by the capture; make it reachable from a manifest screen, or declare it in WalkthroughVerifiedForms with the walkthrough that drives it", name)
|
|
}
|
|
|
|
// The declaration only shrinks: an entry for a form nothing registers,
|
|
// or for one the capture now shows, is stale.
|
|
names := map[string]bool{}
|
|
for _, spec := range registered {
|
|
names[spec.Name] = true
|
|
}
|
|
for name, walkthrough := range WalkthroughVerifiedForms {
|
|
if !names[name] {
|
|
t.Errorf("WalkthroughVerifiedForms names %q (%s), which no package registers; remove the entry", name, walkthrough)
|
|
} else if seen[name] {
|
|
t.Errorf("WalkthroughVerifiedForms names %q (%s), which the capture now shows; remove the entry", name, walkthrough)
|
|
}
|
|
}
|
|
|
|
// A form id the capture saw that nothing registers means a template
|
|
// wrote a data-form attribute by hand, which the declaration is
|
|
// supposed to be the only source of.
|
|
var unknown []string
|
|
for id := range seen {
|
|
if !names[id] {
|
|
unknown = append(unknown, id)
|
|
}
|
|
}
|
|
sort.Strings(unknown)
|
|
if len(unknown) > 0 {
|
|
t.Errorf("the capture saw data-form ids no declaration owns: %s", strings.Join(unknown, ", "))
|
|
}
|
|
}
|