8d6d73b747
Fixes #6. opencode 2.0.24 migrated its session store on 2026-11-01 21:01:20 UTC. `session`, `message` and `part` stopped being written; sessions now live in `session_v2` and messages in `session_message`. The ingest kept querying the abandoned tables, so every sweep after the migration logged `0 new` — no error, no new sessions indexed. ## Changes - **`internal/ingest/opencode_db.go`** - Read sessions from `session_v2` (title is nullable there, the existing COALESCE + fallback still apply). - Rebuild transcripts from both message shapes: user turns at `$.text`, assistant turns from `$.content[]` filtered to `type='text'` (reasoning and tool parts are not indexed). Ordered by `seq`, then part index. - Count messages from `session_message` instead of parts. - Drop `<system-reminder>` text — reminders now arrive as `synthetic` messages and would eat the 4000-byte summary budget. - Ingester version is now `opencode-db/v2`. - **`internal/watch/watch.go`** — an entry is no longer skipped on `created_at` alone. Resuming a session appends messages without touching the creation time, so the summary is compared too. - **`internal/ingest/opencode_db_test.go`** — new test builds the v2 schema in a temp SQLite database and asserts user text and assistant text parts are indexed while reasoning, tool and reminder content is not. ## Validation - `go build ./...`, `go test ./internal/ingest/ ./internal/db/ ./internal/watch/` pass. - Rebuilt the binary and restarted `knox.service` against the live store: ``` [knox] opencode.db: 1 new, 387 unchanged ``` The new entry is the session that had been invisible since the migration (`Knox OpenCode session adapter compatibility check`, observation version `opencode-db/v2`), and `knox query "knox opencode session adapter compatibility"` finds it. - 59 pre-migration sessions re-recorded because their stored transcripts contained reminder text that the new filter drops; summaries still carry the conversation. ## Notes The first commit on this branch is a checkpoint of pre-existing uncommitted work that the adapter fix sits on top of; the fix itself is the second commit (`e07ae8a`). Reviewed-on: #7 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package noise
|
|
|
|
import "testing"
|
|
|
|
func TestIsNoisyURL(t *testing.T) {
|
|
webapps := []string{
|
|
"https://mail.google.com/mail/u/0/#inbox",
|
|
"https://calendar.google.com/calendar/u/0/r",
|
|
"https://app.privacy.com/",
|
|
"https://login.microsoftonline.com/common/oauth2",
|
|
"https://accounts.google.com/signin",
|
|
}
|
|
for _, u := range webapps {
|
|
if !IsNoisyURL(u) {
|
|
t.Errorf("expected webapp URL to be filtered: %s", u)
|
|
}
|
|
}
|
|
signals := []string{
|
|
"https://github.com/david/knox/pull/3",
|
|
"https://go.dev/blog/go1.26",
|
|
"https://git.notsosm.art/david/knox",
|
|
}
|
|
for _, u := range signals {
|
|
if IsNoisyURL(u) {
|
|
t.Errorf("expected signal URL to pass: %s", u)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildPatternsEnv(t *testing.T) {
|
|
t.Setenv("KNOX_BROWSER_DENY", "example-webapp.io, Foo.Example")
|
|
found := map[string]bool{}
|
|
for _, p := range BuildPatterns() {
|
|
found[p] = true
|
|
}
|
|
if !found["example-webapp.io"] || !found["foo.example"] {
|
|
t.Fatalf("KNOX_BROWSER_DENY not applied lowercased")
|
|
}
|
|
}
|
|
|
|
func TestDenyKeywords(t *testing.T) {
|
|
kw := DenyKeywords()
|
|
// Derived from specific webapp domains.
|
|
for _, want := range []string{"privacy", "chatgpt", "kagi", "bankofamerica", "simplefin", "microsoftonline"} {
|
|
if !kw[want] {
|
|
t.Errorf("expected deny keyword %q", want)
|
|
}
|
|
}
|
|
// Generic labels and path patterns must NOT deny.
|
|
for _, bad := range []string{"google", "live", "apple", "opencode", "github"} {
|
|
if kw[bad] {
|
|
t.Errorf("generic label %q must not be a deny keyword", bad)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsDeniedTopic(t *testing.T) {
|
|
if !IsDeniedTopic("privacy / virtual / card") {
|
|
t.Error("expected privacy thread to be denied")
|
|
}
|
|
if IsDeniedTopic("nr-flow-validator Rego validation") {
|
|
t.Error("work thread must not be denied")
|
|
}
|
|
}
|
|
|
|
func TestDenyKeywordEnv(t *testing.T) {
|
|
t.Setenv("KNOX_THREAD_DENY", "newsletter, CouponSite")
|
|
kw := DenyKeywords()
|
|
if !kw["newsletter"] || !kw["couponsite"] {
|
|
t.Fatalf("KNOX_THREAD_DENY not applied: %v", kw)
|
|
}
|
|
}
|