Files
Anya Tokugawa d5d21b7841
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s
Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
2026-11-01 15:23:31 +09:00

57 lines
2.0 KiB
Go

package server
import (
"context"
"encoding/json"
"errors"
"testing"
"pageswiki/internal/seheweit"
"pageswiki/internal/store"
)
func TestSeheweitAPIContractAndReadOnlyCollection(t *testing.T) {
s, token, _ := configFixture(t)
seedMonitorJobs(t, s)
s.schedulerRunning.Store(2)
w := configRequest(s, token, "GET", "/_/api/v1/queue/resources", nil)
var snapshot seheweit.Snapshot
if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &snapshot) != nil {
t.Fatalf("snapshot %d %s", w.Code, w.Body.String())
}
if snapshot.Queue.Stats.Queued != 1 || snapshot.Queue.Stats.Running != 1 || snapshot.Queue.ActiveWorkers != 2 || snapshot.IO.ProcessID == "" {
t.Fatalf("application connection %+v", snapshot)
}
if w.Header().Get("Cache-Control") != "no-store" {
t.Fatal("live response cached")
}
for _, tc := range []struct {
query string
hours int
}{{"", 24}, {"?hours=invalid", 24}, {"?hours=1", 1}, {"?hours=168", 168}} {
w = configRequest(s, token, "GET", "/_/api/v1/queue/resources/history"+tc.query, nil)
var result struct {
Samples []json.RawMessage
Hours int
RetentionDays int `json:"retention_days"`
}
if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &result) != nil || result.Hours != tc.hours || result.RetentionDays != 7 || result.Samples == nil || len(result.Samples) != 0 {
t.Fatalf("history default/empty shape %s", w.Body.String())
}
}
// Neither current-value nor history GET creates persisted samples.
var count int
if err := s.store.DB.QueryRow(`SELECT COUNT(*) FROM resource_samples`).Scan(&count); err != nil || count != 0 {
t.Fatalf("request persisted sample: %d %v", count, err)
}
ctx, cancel := context.WithCancel(t.Context())
cancel()
err := s.registeredEventHandlers().Run(ctx, &store.EventJob{UUID: "cancelled-monitor", Type: store.ResourceEventType})
if !errors.Is(err, context.Canceled) {
t.Fatalf("cancelled job %v", err)
}
if err := s.store.DB.QueryRow(`SELECT COUNT(*) FROM resource_samples`).Scan(&count); err != nil || count != 0 {
t.Fatal("cancelled job persisted sample")
}
}