edf6c03a7c
Pre-existing work-in-progress in the tree: karakeep, snippets, skills-health and redaction ingesters, the opencode.db session sweep, gossip and metrics changes. Checkpointed as-is so the adapter fix in the next commit stays reviewable on its own.
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package ingest
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHTMLToText(t *testing.T) {
|
|
in := `<div id="readability-page-1"><article><h1>Hello</h1>` +
|
|
`<script>evil()</script><style>.x{}</style>` +
|
|
`<p>A & B 'quoted'</p></article></div>`
|
|
out := htmlToText(in)
|
|
if strings.Contains(out, "evil()") || strings.Contains(out, ".x{}") {
|
|
t.Fatalf("script/style not stripped: %q", out)
|
|
}
|
|
for _, want := range []string{"Hello", "A & B", "'quoted'"} {
|
|
if !strings.Contains(out, want) {
|
|
t.Fatalf("missing %q in %q", want, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestKarakeepToResult(t *testing.T) {
|
|
title := "My Link"
|
|
k := &KarakeepIngester{Version: "test"}
|
|
b := kaBookmark{
|
|
ID: "bm1",
|
|
CreatedAt: "2026-01-02T03:04:05Z",
|
|
ModifiedAt: "2026-01-02T03:04:05Z",
|
|
Title: &title,
|
|
Tags: []kaTag{{Name: "zigbee"}},
|
|
Content: kaContent{Type: "link", URL: "https://example.com/a", Description: "short desc"},
|
|
}
|
|
r := k.toResult(b)
|
|
if r == nil {
|
|
t.Fatal("nil result")
|
|
}
|
|
if r.SourceID != "karakeep" || r.Title != "My Link" || r.SourcePath != "https://example.com/a" {
|
|
t.Fatalf("unexpected mapping: %+v", r)
|
|
}
|
|
// No asset and no inline text -> content falls back to description.
|
|
if r.Content != "short desc" {
|
|
t.Fatalf("content=%q, want description fallback", r.Content)
|
|
}
|
|
if r.Fingerprint == "" || r.ContentHash == "" {
|
|
t.Fatal("fingerprint/content hash must be set")
|
|
}
|
|
}
|
|
|
|
func TestKarakeepUnconfigured(t *testing.T) {
|
|
k := &KarakeepIngester{Version: "test"} // no BaseURL/APIKey
|
|
got, err := k.IngestAll()
|
|
if err != nil || got != nil {
|
|
t.Fatalf("unconfigured ingester should no-op, got %v %v", got, err)
|
|
}
|
|
}
|