Files
Andy Dixon 4a7dafc71f feat(agency): forensic "why", attribution and introspection accuracy
- agency.Explain answers "why did this happen?" for an execution,
  approval, capability request, plan step, intention or event from
  recorded state only: action, immediate plan step, plan, intention and
  any subordinate intention, originating wants, goal, supporting beliefs
  and their evidence, conflicting wants with their resolution,
  commitments applied, formation and reconsideration decisions, the
  expectation and its outcome, and explicit gaps where nothing is
  recorded. Hidden model reasoning is never shown because it is not
  stored.
- agency.Attribute classifies an outcome as caused (a recorded causal
  link from one of the mind's actions), followed (the mind acted on the
  same target earlier with no recorded link), independent or unknown;
  temporal order alone is never taken for causation.
- New introspection intents answer from records: why an action happened,
  what was believed at a past time (from append-only belief versions),
  which earlier state is the mind's (lineage), what would have happened
  without an event (only from completed counterfactual experiments,
  otherwise "no evidence"), how the mind changed, and what it wants,
  intends and has committed to.
- research.ScoreIntrospection compares a reply with the recorded facts
  sentence by sentence (supported, partially supported, unsupported,
  contradicted, unknown). Fluent reasons with no recorded counterpart earn
  nothing, and a claim that an action was done is checked against
  execution records. Every reply is scored; results are append-only
  research measurements (migration 0028), and failures raise
  unsupported_explanation or action_claim_without_record warnings.
2026-09-16 23:53:06 +01:00

43 lines
1.7 KiB
Go

package beliefs
import (
"context"
"testing"
"time"
"github.com/andydixon/noema/internal/minds"
"github.com/andydixon/noema/internal/storage"
"github.com/andydixon/noema/migrations"
"github.com/andydixon/noema/pkg/ids"
)
func TestAsOfReadsTheVersionHeldAtTheTime(t *testing.T) {
pool := storage.TestPool(t, migrations.FS)
ctx := context.Background()
m, _ := minds.NewStore(pool).Create(ctx, minds.CreateParams{Slug: "asof"})
s := NewStore(pool)
b := ids.New()
now := time.Now()
if _, err := pool.Exec(ctx, `INSERT INTO beliefs (id, mind_id, proposition, subject, epistemic, status, confidence, prior, source) VALUES ($1,$2,'atlas-worker is healthy','atlas','claim','rejected',0.1,0.5,'test')`, b, m.ID); err != nil {
t.Fatal(err)
}
for i, v := range []struct {
status string
conf float64
at time.Time
}{{"likely", 0.8, now.Add(-48 * time.Hour)}, {"contested", 0.45, now.Add(-12 * time.Hour)}, {"rejected", 0.1, now.Add(-time.Hour)}} {
if _, err := pool.Exec(ctx, `INSERT INTO belief_versions (id, belief_id, mind_id, version, status, confidence, proposition, created_at) VALUES ($1,$2,$3,$4,$5,$6,'atlas-worker is healthy',$7)`, ids.New(), b, m.ID, i+1, v.status, v.conf, v.at); err != nil {
t.Fatal(err)
}
}
for at, want := range map[time.Duration]string{-24 * time.Hour: "likely", -2 * time.Hour: "contested", 0: "rejected"} {
vs, err := s.AsOf(ctx, m.ID, "atlas-worker", now.Add(at), 5)
if err != nil || len(vs) != 1 || vs[0].Status != want {
t.Fatalf("as of %s: %v %+v", at, err, vs)
}
}
if vs, _ := s.AsOf(ctx, m.ID, "atlas-worker", now.Add(-72*time.Hour), 5); len(vs) != 0 {
t.Fatalf("a belief appeared before it existed: %+v", vs)
}
}