fix: drop the auto_thread marker when a thread is rewritten (#29)
Editorial rewrites went through UpdateThread, which touched title, motivation, priority and tags but never provenance. isAutoThreaded keys off the auto_thread provenance marker (or an 'Auto-detected' motivation prefix), so every polished thread kept reporting as a draft with no way out of the queue. A rewritten title or motivation now clears the marker and records groomed=true, keeping the cluster/score/sources that provenance also carries. Tag-only edits deliberately do not count as an editorial pass.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -734,3 +736,72 @@ func TestRebuildEntriesDeterministicFold(t *testing.T) {
|
||||
t.Errorf("first/last seen = %q/%q", results[0].FirstSeen, results[0].LastSeen)
|
||||
}
|
||||
}
|
||||
|
||||
// A polished auto-thread has to leave the draft queue. Drafts are detected by
|
||||
// the auto_thread provenance marker (or an "Auto-detected" motivation), and
|
||||
// nothing cleared either of them before: an edited thread was a draft forever.
|
||||
func TestUpdateThreadClearsAutoThreadMarker(t *testing.T) {
|
||||
k := newTestDB(t)
|
||||
|
||||
prov := `{"cluster":"plant / care / dashboard","score":3.9,"sources":["git","gitea"],"trigger":"auto_thread"}`
|
||||
id, err := k.CreateThread("plant / care / dashboard", "Auto-detected cluster of 4 observations",
|
||||
"medium", "[]", prov)
|
||||
if err != nil {
|
||||
t.Fatalf("create: %v", err)
|
||||
}
|
||||
|
||||
changed, err := k.UpdateThread(id, "plant-care: watering analytics", "", "", "")
|
||||
if err != nil {
|
||||
t.Fatalf("update: %v", err)
|
||||
}
|
||||
if !changed {
|
||||
t.Fatal("update reported no change")
|
||||
}
|
||||
|
||||
got, err := k.GetThread(id)
|
||||
if err != nil || got == nil {
|
||||
t.Fatalf("get: %v", err)
|
||||
}
|
||||
if strings.Contains(got.Provenance, "auto_thread") {
|
||||
t.Fatalf("auto_thread marker survived a retitle: %s", got.Provenance)
|
||||
}
|
||||
var meta map[string]any
|
||||
if err := json.Unmarshal([]byte(got.Provenance), &meta); err != nil {
|
||||
t.Fatalf("provenance is not JSON: %v (%s)", err, got.Provenance)
|
||||
}
|
||||
if meta["cluster"] != "plant / care / dashboard" {
|
||||
t.Fatalf("cluster dropped from provenance: %v", meta)
|
||||
}
|
||||
if meta["groomed"] != true {
|
||||
t.Fatalf("groomed flag not recorded: %v", meta)
|
||||
}
|
||||
|
||||
// A motivation rewrite alone is also an editorial pass.
|
||||
other, _ := k.CreateThread("zigbee / docker / stack", "Auto-detected cluster", "medium", "[]",
|
||||
`{"trigger":"auto_thread","cluster":"zigbee"}`)
|
||||
if _, err := k.UpdateThread(other, "", "Build the klubhaus Zigbee stack", "", ""); err != nil {
|
||||
t.Fatalf("update motivation: %v", err)
|
||||
}
|
||||
if got, _ := k.GetThread(other); strings.Contains(got.Provenance, "auto_thread") {
|
||||
t.Fatalf("auto_thread marker survived a motivation rewrite: %s", got.Provenance)
|
||||
}
|
||||
|
||||
// Tag-only edits are not editorial: the thread is still a draft.
|
||||
third, _ := k.CreateThread("kuma / uptime", "Auto-detected cluster", "medium", "[]",
|
||||
`{"trigger":"auto_thread"}`)
|
||||
if _, err := k.UpdateThread(third, "", "", "", "uptime monitoring"); err != nil {
|
||||
t.Fatalf("update tags: %v", err)
|
||||
}
|
||||
if got, _ := k.GetThread(third); !strings.Contains(got.Provenance, "auto_thread") {
|
||||
t.Fatalf("a tag-only edit cleared the draft marker: %s", got.Provenance)
|
||||
}
|
||||
|
||||
// Provenance that was never auto-generated is left alone.
|
||||
own, _ := k.CreateThread("manual thread", "by hand", "high", "[]", `{"trigger":"display-watch","host":"surf"}`)
|
||||
if _, err := k.UpdateThread(own, "manual thread, renamed", "", "", ""); err != nil {
|
||||
t.Fatalf("update manual: %v", err)
|
||||
}
|
||||
if got, _ := k.GetThread(own); got.Provenance != `{"trigger":"display-watch","host":"surf"}` {
|
||||
t.Fatalf("unrelated provenance was rewritten: %s", got.Provenance)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user