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.
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package dr
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"pageswiki/internal/db"
|
|
"pageswiki/internal/geduldh"
|
|
)
|
|
|
|
func TestGeduldhSnapshotRestoreCompatibility(t *testing.T) {
|
|
root := fixture(t)
|
|
documents := filepath.Join(root, "documents")
|
|
if err := os.MkdirAll(documents, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
backend, err := geduldh.NewLocal(documents)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx := context.Background()
|
|
body := []byte("Geduldh DR compatibility 日本語\x00\xff")
|
|
sum := sha256.Sum256(body)
|
|
hash := hex.EncodeToString(sum[:])
|
|
if err := backend.PutIfAbsent(ctx, hash, int64(len(body)), bytes.NewReader(body)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
database, err := db.Open(filepath.Join(root, "pages.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer database.Close()
|
|
if _, err := database.Exec(`UPDATE revisions SET document_hash=? WHERE rowid=42`, hash); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
snapshot := filepath.Join(t.TempDir(), "snapshot")
|
|
_, digest, err := Snapshot(ctx, root, snapshot)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := Verify(ctx, snapshot, digest); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
restored := filepath.Join(t.TempDir(), "standby")
|
|
if _, err := Restore(ctx, snapshot, digest, restored); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
recovered, err := geduldh.NewLocal(filepath.Join(restored, "documents"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := recovered.Verify(ctx, hash); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reader, err := recovered.Open(ctx, hash)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer reader.Close()
|
|
data, err := io.ReadAll(reader)
|
|
if err != nil || !bytes.Equal(data, body) {
|
|
t.Fatalf("restored payload changed: %v", err)
|
|
}
|
|
}
|