Files
pages/internal/store/schema_inspect_test.go
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

84 lines
3.3 KiB
Go

package store
import (
"context"
"testing"
"pageswiki/internal/db"
)
func TestSchemaInspectionDoesNotRecoverJobsOrBackfill(t *testing.T) {
st := newSchemaTestStore(t)
for name := range managedStoreSchemas {
if err := st.ensureSchemaComponent(name); err != nil {
t.Fatal(err)
}
}
if err := db.ApplySQLiteMigrations(context.Background(), st.DB, "document-store", documentBackfillMigrations); err != nil {
t.Fatal(err)
}
if _, err := st.DB.Exec(`INSERT INTO event_jobs(uuid,event_type,event_key,payload,status,run_at_ms,created_at_ms,updated_at_ms) VALUES('running','test','key','','running',1,1,1); INSERT INTO document_backfills VALUES('store','cursor',7,0,1)`); err != nil {
t.Fatal(err)
}
report, err := InspectSchema(context.Background(), st.DB)
if err != nil {
t.Fatal(err)
}
for _, component := range report.Components {
if component.State != "current" {
t.Fatalf("component=%+v", component)
}
}
var status string
if err := st.DB.QueryRow(`SELECT status FROM event_jobs WHERE uuid='running'`).Scan(&status); err != nil || status != "running" {
t.Fatalf("job modified: %q %v", status, err)
}
var processed, complete int
if err := st.DB.QueryRow(`SELECT processed,completed FROM document_backfills WHERE store_id='store'`).Scan(&processed, &complete); err != nil || processed != 7 || complete != 0 {
t.Fatalf("backfill modified: %d %d %v", processed, complete, err)
}
if err := st.EnsureEventJobsSchema(); err != nil {
t.Fatal(err)
}
if err := st.DB.QueryRow(`SELECT status FROM event_jobs WHERE uuid='running'`).Scan(&status); err != nil || status != "queued" {
t.Fatalf("startup recovery broken: %q %v", status, err)
}
}
func TestEventJobMigrationAdoptsLegacyAndPreservesSettings(t *testing.T) {
st := newSchemaTestStore(t)
if _, err := st.DB.Exec(eventJobMigrations[0].Statements[0]); err != nil {
t.Fatal(err)
}
if _, err := st.DB.Exec(`INSERT INTO event_jobs(uuid,event_type,event_key,payload,status,run_at_ms,created_at_ms,updated_at_ms) VALUES('old','test','key','keep','running',1,1,1)`); err != nil {
t.Fatal(err)
}
if err := st.ensureSchemaComponent("event-jobs"); err != nil {
t.Fatal(err)
}
var payload, status string
var attempts int
if err := st.DB.QueryRow(`SELECT payload,status,max_attempts FROM event_jobs WHERE uuid='old'`).Scan(&payload, &status, &attempts); err != nil || payload != "keep" || status != "running" || attempts != 3 {
t.Fatalf("legacy job=%q %q %d %v", payload, status, attempts, err)
}
if _, err := st.DB.Exec(`UPDATE event_queue_settings SET paused=1,concurrency=3; UPDATE event_log_policies SET max_rows=42 WHERE event_type='*'`); err != nil {
t.Fatal(err)
}
if err := st.ensureSchemaComponent("event-jobs"); err != nil {
t.Fatal(err)
}
var paused, workers, rows int
if err := st.DB.QueryRow(`SELECT paused,concurrency FROM event_queue_settings WHERE id=1`).Scan(&paused, &workers); err != nil || paused != 1 || workers != 3 {
t.Fatalf("settings overwritten %d %d %v", paused, workers, err)
}
if err := st.DB.QueryRow(`SELECT max_rows FROM event_log_policies WHERE event_type='*'`).Scan(&rows); err != nil || rows != 42 {
t.Fatalf("policy overwritten %d %v", rows, err)
}
if _, err := st.DB.Exec(`DROP INDEX idx_event_jobs_due`); err != nil {
t.Fatal(err)
}
if err := st.ensureSchemaComponent("event-jobs"); err == nil {
t.Fatal("missing queue index accepted")
}
}