Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
This commit is contained in:
1 parent
288e6e94ac
commit
c1175d389f
699 files changed
+110197
-4117
No files matched your search
@@ -0,0 +1,92 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"pageswiki/internal/db"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func TestTextWindowIsBoundedUTF8AndDomainScoped(t *testing.T) {
|
||||
database, err := db.Open(t.TempDir() + "/pages.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = database.Close() })
|
||||
if err := db.Migrate(database); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := store.New(database)
|
||||
domain, _ := st.GetDefaultDomain()
|
||||
objectUUID, err := st.CreatePageAtPathInDomain(domain.UUID, "/large.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
revision, err := st.SaveRevisionContent(objectUUID, []byte(strings.Repeat("日本語\n", 100000)), "test", "und", "text/plain; charset=utf-8", "large.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := httptest.NewRequest(http.MethodGet, "http://localhost/v/text/rev:"+revision.UUID+"?offset=1&limit=1024", nil)
|
||||
response := httptest.NewRecorder()
|
||||
(&Server{store: st}).handleTextWindow(response, request)
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", response.Code, response.Body.String())
|
||||
}
|
||||
var payload struct {
|
||||
Text string `json:"text"`
|
||||
Offset int64 `json:"offset"`
|
||||
NextOffset int64 `json:"next_offset"`
|
||||
Truncated bool `json:"truncated"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.HasPrefix(payload.Text, "本語") || payload.Offset <= 1 || payload.NextOffset <= payload.Offset || !payload.Truncated {
|
||||
t.Fatalf("payload=%+v", payload)
|
||||
}
|
||||
if _, err := database.Exec(`DELETE FROM paths WHERE domain_uuid=? AND object_uuid=?`, domain.UUID, objectUUID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
denied := httptest.NewRecorder()
|
||||
(&Server{store: st}).handleTextWindow(denied, request)
|
||||
if denied.Code != http.StatusNotFound {
|
||||
t.Fatalf("unbound revision status=%d, want 404", denied.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticViewerSelectsImmutableWindowWithoutHydratingTail(t *testing.T) {
|
||||
database, err := db.Open(t.TempDir() + "/viewer.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = database.Close() })
|
||||
if err := db.Migrate(database); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := store.New(database)
|
||||
domain, _ := st.GetDefaultDomain()
|
||||
objectUUID, err := st.CreatePageAtPathInDomain(domain.UUID, "/huge.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := strings.Repeat("line of bounded text\n", 120000) + "SHOULD_NOT_BE_IN_INITIAL_HTML"
|
||||
revision, err := st.SaveRevisionContent(objectUUID, []byte(body), "test", "und", "text/plain; charset=utf-8", "huge.txt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := httptest.NewRequest(http.MethodGet, "http://localhost/huge.txt", nil)
|
||||
view, selected, err := (&Server{store: st}).windowedContentViewForRequest(request, objectUUID, "/huge.txt")
|
||||
if err != nil || !selected {
|
||||
t.Fatalf("selected=%v err=%v view=%+v", selected, err, view)
|
||||
}
|
||||
if strings.Contains(view.Text, "SHOULD_NOT_BE_IN_INITIAL_HTML") || int64(len(view.Text)) >= view.SizeBytes {
|
||||
t.Fatal("large text tail was hydrated into initial Viewer window")
|
||||
}
|
||||
if view.WindowURL != "/v/text/rev:"+revision.UUID || view.NextOffset <= 0 || !view.Windowed {
|
||||
t.Fatalf("windowed view=%+v", view)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user