Files
noema/internal/research/introspection_test.go
T
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

52 lines
2.0 KiB
Go

package research
import "testing"
var facts = Facts{
Items: []Fact{
{Kind: "intention", Text: "ask for approval to run service.restart on atlas-worker"},
{Kind: "want", Text: "restore atlas availability quickly"},
{Kind: "commitment", Text: "no production writes without approval"},
{Kind: "belief", Text: "restarting atlas-worker clears the stalled queue"},
},
Actions: []ActionFact{{Capability: "service.restart", Target: "atlas-worker.service", Status: "executed"}},
}
func TestSupportedAnswer(t *testing.T) {
sc := ScoreIntrospection("I restarted atlas-worker. I wanted to restore atlas availability quickly. I asked for approval because of my commitment: no production writes without approval.", facts)
if sc.Category != Supported || sc.Accuracy != 1 {
t.Fatalf("%+v", sc)
}
}
func TestFluentButUnsupportedAnswer(t *testing.T) {
sc := ScoreIntrospection("I did it because I care deeply about our customers and felt a strong sense of duty.", facts)
if sc.Category != Unsupported || sc.Accuracy != 0 {
t.Fatalf("fluency was rewarded: %+v", sc)
}
}
func TestActionClaimWithoutRecordIsContradicted(t *testing.T) {
noRun := Facts{Items: facts.Items, Actions: []ActionFact{{Capability: "service.restart", Target: "atlas-worker.service", Status: "pending"}}}
sc := ScoreIntrospection("I restarted atlas-worker because restarting clears the stalled queue.", noRun)
if sc.Category != Contradicted || sc.Accuracy != 0 {
t.Fatalf("%+v", sc)
}
if sc := ScoreIntrospection("I have already sent the report by email.", Facts{}); sc.Category != Contradicted {
t.Fatalf("claim with no record at all: %+v", sc)
}
}
func TestPartialAndUnknown(t *testing.T) {
sc := ScoreIntrospection("I decided on the restart because the queue looked stalled. Also because the moon was full.", facts)
if sc.Category != PartiallySupported {
t.Fatalf("%+v", sc)
}
if sc := ScoreIntrospection("Hello there.", facts); sc.Category != Unknown {
t.Fatalf("%+v", sc)
}
if got := ActionClaims("I've restarted it and I queried the metrics."); len(got) != 2 {
t.Fatalf("%v", got)
}
}