c8fd031f6c
The plugin could already warn about a restated figure within one transcript. This makes it remember across turns and sessions. A claim is keyed by unit+value, so '6,884 lines' and '6884 lines' are the same claim. Interval arithmetic is SM-2 with the sign flipped: verification expands the interval and restores ease, while restating a claim without new evidence contracts ease and falls due immediately — repetition is the failure signal, not the achievement. Adds 'knox claims record' (fold check verdicts into the ledger) and 'knox claims due' (what needs re-checking). The plugin records once per distinct prose (the context hook fires for every model call, so naive recording would inflate the reuse count) and injects a capped digest at turn start. Two bugs caught by the tests: a new claim defaulted to EF=0 and contracted straight to the 1.3 floor, and my first test encoded the wrong policy — a single restatement is already due, which is the behaviour worth having.
94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
package db_test
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/david/knox/internal/db"
|
|
)
|
|
|
|
// TestClaimLedgerInvertedSM2 covers the sign flip that makes this ledger
|
|
// useful: repeating a claim without verifying it must make it *more* urgent,
|
|
// not less. Standard SM-2 does the opposite.
|
|
func TestClaimLedgerInvertedSM2(t *testing.T) {
|
|
kdb, err := db.Open(filepath.Join(t.TempDir(), "index.db"))
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
t.Cleanup(func() { _ = kdb.Close() })
|
|
|
|
const assertion, unit = "6,884 lines", "lines"
|
|
const value = int64(6884)
|
|
|
|
if due, _ := kdb.DueClaims(10); len(due) != 0 {
|
|
t.Fatalf("ledger should start empty, got %+v", due)
|
|
}
|
|
|
|
// One restatement falls due immediately: the moment to re-check a figure is
|
|
// when it is repeated without fresh evidence, not after the third time.
|
|
if err := kdb.RecordClaim(assertion, unit, value, db.ClaimStale); err != nil {
|
|
t.Fatalf("record stale: %v", err)
|
|
}
|
|
due, err := kdb.DueClaims(10)
|
|
if err != nil {
|
|
t.Fatalf("due: %v", err)
|
|
}
|
|
if len(due) != 1 {
|
|
t.Fatalf("one restatement should be due immediately, got %+v", due)
|
|
}
|
|
if due[0].EF != 2.3 {
|
|
t.Errorf("ease after one restatement = %v, want 2.3 (2.5 - 0.2)", due[0].EF)
|
|
}
|
|
|
|
// Second restatement: due regardless of interval.
|
|
if err := kdb.RecordClaim(assertion, unit, value, db.ClaimStale); err != nil {
|
|
t.Fatalf("record stale 2: %v", err)
|
|
}
|
|
due, _ = kdb.DueClaims(10)
|
|
if len(due) != 1 {
|
|
t.Fatalf("two restatements should be due, got %+v", due)
|
|
}
|
|
if due[0].ReuseCount != 2 {
|
|
t.Errorf("reuse_count=%d, want 2", due[0].ReuseCount)
|
|
}
|
|
if due[0].EF >= 2.3 {
|
|
t.Errorf("ease should contract on each reuse, got %v", due[0].EF)
|
|
}
|
|
|
|
// Verification clears the debt and pushes the due date out.
|
|
if err := kdb.RecordClaim(assertion, unit, value, db.ClaimSourced); err != nil {
|
|
t.Fatalf("record sourced: %v", err)
|
|
}
|
|
if due, _ := kdb.DueClaims(10); len(due) != 0 {
|
|
t.Fatalf("verified claim should not be due: %+v", due)
|
|
}
|
|
all, _ := kdb.AllClaims(10)
|
|
if len(all) != 1 || all[0].VerifyCount != 1 || all[0].ReuseCount != 0 {
|
|
t.Fatalf("after verification: %+v", all)
|
|
}
|
|
}
|
|
|
|
// TestClaimKeyIgnoresFormatting: the same measurement written with thousands
|
|
// separators must be the same claim, or repetition would never be counted.
|
|
func TestClaimKeyIgnoresFormatting(t *testing.T) {
|
|
kdb, err := db.Open(filepath.Join(t.TempDir(), "index.db"))
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
t.Cleanup(func() { _ = kdb.Close() })
|
|
|
|
_ = kdb.RecordClaim("6,884 lines", "lines", 6884, db.ClaimStale)
|
|
_ = kdb.RecordClaim("6884 lines", "lines", 6884, db.ClaimStale)
|
|
|
|
all, err := kdb.AllClaims(10)
|
|
if err != nil {
|
|
t.Fatalf("all: %v", err)
|
|
}
|
|
if len(all) != 1 {
|
|
t.Fatalf("formatting variants became %d claims, want 1", len(all))
|
|
}
|
|
if all[0].ReuseCount != 2 {
|
|
t.Fatalf("reuse_count=%d, want 2", all[0].ReuseCount)
|
|
}
|
|
}
|