Refactor architecture into eight components and consolidate reliability work
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s

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.
This commit is contained in:
Anya Tokugawa committed 2026-11-01 15:23:31 +09:00
1 parent 9dd425f765
commit d5d21b7841
302 files changed
+20037 -3492

No files matched your search

@@ -0,0 +1,176 @@
package documentstore_test
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"io"
"os"
"path/filepath"
"strings"
"testing"
"time"
"pageswiki/internal/documentstore"
"pageswiki/internal/geduldh"
)
// These assignments intentionally fail compilation if aliases become wrappers
// with different type identities or constructor signatures.
var (
_ func(string) (*geduldh.Local, error) = documentstore.NewLocal
_ func(documentstore.Source, documentstore.MaterializeOptions) (*documentstore.Materializer, error) = geduldh.NewMaterializer
_ documentstore.Store = (*geduldh.Local)(nil)
_ geduldh.Store = (*documentstore.Local)(nil)
)
func TestGeduldhLegacyLayoutAndSharedIdentity(t *testing.T) {
ctx := context.Background()
root := t.TempDir()
body := []byte("existing Document 日本語\x00\xff")
sum := sha256.Sum256(body)
hash := hex.EncodeToString(sum[:])
// Seed the pre-extraction layout independently of either Key implementation.
filename := filepath.Join(root, "sha256", hash[:2], hash)
if err := os.MkdirAll(filepath.Dir(filename), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filename, body, 0644); err != nil {
t.Fatal(err)
}
before, err := os.Stat(filename)
if err != nil {
t.Fatal(err)
}
old, err := documentstore.NewLocal(root)
if err != nil {
t.Fatal(err)
}
current, err := geduldh.NewLocal(root)
if err != nil {
t.Fatal(err)
}
for _, backend := range []geduldh.Store{old, current} {
// The old normalization rules and payload bytes stay unchanged.
inputHash := " " + strings.ToUpper(hash) + " "
info, err := backend.Stat(ctx, inputHash)
if err != nil || info.Hash != hash || info.Size != int64(len(body)) {
t.Fatalf("stat=%+v err=%v", info, err)
}
reader, err := backend.Open(ctx, inputHash)
if err != nil {
t.Fatal(err)
}
func() {
defer reader.Close()
if _, err := reader.Seek(2, io.SeekStart); err != nil {
t.Fatal(err)
}
buf := make([]byte, 4)
if _, err := reader.ReadAt(buf, 5); err != nil || !bytes.Equal(buf, body[5:9]) {
t.Fatalf("ReadAt=%q err=%v", buf, err)
}
// ReaderAt must not move the sequential stream cursor (ZIP and Range).
data, err := io.ReadAll(reader)
if err != nil || !bytes.Equal(data, body[2:]) {
t.Fatalf("stream=%q err=%v", data, err)
}
}()
if err := backend.PutIfAbsent(ctx, hash, int64(len(body)), bytes.NewReader(body)); err != nil {
t.Fatal(err)
}
if err := backend.Verify(ctx, hash); err != nil {
t.Fatal(err)
}
}
after, err := os.Stat(filename)
if err != nil || !os.SameFile(before, after) {
t.Fatalf("canonical inode replaced: %v", err)
}
oldKey, err := documentstore.Key(hash)
if err != nil {
t.Fatal(err)
}
newKey, err := geduldh.Key(hash)
if err != nil || oldKey != newKey || oldKey != "sha256/"+hash[:2]+"/"+hash {
t.Fatalf("key changed: %s %s %v", oldKey, newKey, err)
}
if documentstore.ErrInvalidHash != geduldh.ErrInvalidHash || documentstore.ErrHashMismatch != geduldh.ErrHashMismatch || documentstore.ErrSizeMismatch != geduldh.ErrSizeMismatch || documentstore.ErrMaterializeLimit != geduldh.ErrMaterializeLimit {
t.Fatal("legacy error identity changed")
}
if err := os.WriteFile(filename, []byte("corrupt"), 0644); err != nil {
t.Fatal(err)
}
for _, backend := range []geduldh.Store{old, current} {
if err := backend.PutIfAbsent(ctx, hash, int64(len(body)), bytes.NewReader(body)); !errors.Is(err, documentstore.ErrHashMismatch) {
t.Fatalf("corruption repaired or error changed: %v", err)
}
}
corrupt, err := os.ReadFile(filename)
if err != nil || string(corrupt) != "corrupt" {
t.Fatalf("corrupt canonical overwritten: %v", err)
}
}
func TestGeduldhCompatibilityMaterializer(t *testing.T) {
root, scratch := t.TempDir(), t.TempDir()
backend, err := geduldh.NewLocal(root)
if err != nil {
t.Fatal(err)
}
body := []byte("shared scratch bytes")
sum := sha256.Sum256(body)
hash := hex.EncodeToString(sum[:])
ctx := context.Background()
if err := backend.PutIfAbsent(ctx, hash, int64(len(body)), bytes.NewReader(body)); err != nil {
t.Fatal(err)
}
var materializer *geduldh.Materializer
materializer, err = documentstore.NewMaterializer(backend, documentstore.MaterializeOptions{TempDir: scratch, MaxBytes: 1024, Concurrent: 1, Timeout: time.Second})
if err != nil {
t.Fatal(err)
}
var first *documentstore.Lease
first, err = materializer.Acquire(ctx, hash, 1024)
if err != nil {
t.Fatal(err)
}
defer first.Close()
second, err := materializer.Acquire(ctx, hash, 1024)
if err != nil {
t.Fatal(err)
}
defer second.Close()
if first.Path != second.Path {
t.Fatal("legacy/current leases no longer share the same copy")
}
first.Close()
data, err := os.ReadFile(second.Path)
if err != nil || !bytes.Equal(data, body) {
t.Fatalf("active lease lost: %v", err)
}
second.Close()
if _, err := os.Stat(second.Path); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("scratch not reclaimed: %v", err)
}
if err := backend.Verify(ctx, hash); err != nil {
t.Fatal("lease cleanup affected canonical content", err)
}
}
func TestGeduldhConstructorsDoNotProvisionRoots(t *testing.T) {
root := filepath.Join(t.TempDir(), "missing")
for _, create := range []func(string) (*geduldh.Local, error){documentstore.NewLocal, geduldh.NewLocal} {
if _, err := create(root); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(root); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("constructor wrote to storage root: %v", err)
}
if _, err := create(" "); err == nil {
t.Fatal("empty root accepted")
}
}
}
+34
View File
@@ -0,0 +1,34 @@
// Package documentstore preserves the original Document Store entry points.
// Payload storage and scratch materialization are implemented by Geduldh.
// New consumers should use pageswiki/internal/geduldh directly.
package documentstore
import "pageswiki/internal/geduldh"
// Aliases preserve interface/type identity, method sets and error matching.
// This package must not acquire its own persistence or validation logic.
type (
Info = geduldh.Info
Reader = geduldh.Reader
Store = geduldh.Store
Local = geduldh.Local
Source = geduldh.Source
MaterializeOptions = geduldh.MaterializeOptions
Materializer = geduldh.Materializer
Lease = geduldh.Lease
)
var (
ErrInvalidHash = geduldh.ErrInvalidHash
ErrHashMismatch = geduldh.ErrHashMismatch
ErrSizeMismatch = geduldh.ErrSizeMismatch
ErrMaterializeLimit = geduldh.ErrMaterializeLimit
)
func Key(hash string) (string, error) { return geduldh.Key(hash) }
func NewLocal(root string) (*Local, error) { return geduldh.NewLocal(root) }
func NewMaterializer(source Source, options MaterializeOptions) (*Materializer, error) {
return geduldh.NewMaterializer(source, options)
}