feat: audit session transcripts for numeric claims with no tool evidence (#13)
feat: audit session transcripts for numeric claims with no tool evidence (#13) Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #13.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package claims
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestExtract(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
want []int64
|
||||
units []string
|
||||
skipped string
|
||||
}{
|
||||
{in: "that file is 6,884 lines long", want: []int64{6884}, units: []string{"lines"}},
|
||||
{in: "took 200ms over the wire", want: []int64{200}, units: []string{"ms"}},
|
||||
{in: "11 files changed and 3 commits", want: []int64{11}, units: []string{"files"}, skipped: "3 commits is below the noise floor"},
|
||||
{in: "no numbers to see here", want: nil},
|
||||
{in: "version 2.31 of the thing", want: nil, skipped: "no unit"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := Extract(c.in)
|
||||
if len(got) != len(c.want) {
|
||||
t.Errorf("%q: got %d findings (%v), want %d", c.in, len(got), got, len(c.want))
|
||||
continue
|
||||
}
|
||||
for i := range got {
|
||||
if got[i].Value != c.want[i] || got[i].Unit != c.units[i] {
|
||||
t.Errorf("%q: finding %d = (%d,%q), want (%d,%q)", c.in, i, got[i].Value, got[i].Unit, c.want[i], c.units[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestMarkRequiresUnit: the failure this guards against is subtle — matching a
|
||||
// bare number is so loose that "200MB" counts as backed by any output
|
||||
// containing 200. The unit has to agree.
|
||||
func TestMarkRequiresUnit(t *testing.T) {
|
||||
f := Extract("6884 lines")
|
||||
|
||||
if got := Mark(append([]Finding(nil), f...), []string{"44 files changed, 6884 deletions(-)"}); got[0].Sourced {
|
||||
t.Error("6884 lines must not be backed by '6884 deletions'")
|
||||
}
|
||||
if got := Mark(append([]Finding(nil), f...), []string{"6884 lines (12%)"}); !got[0].Sourced {
|
||||
t.Error("6884 lines should be backed by an output saying 6884 lines")
|
||||
}
|
||||
if got := Mark(append([]Finding(nil), f...), []string{"6,884 lines"}); !got[0].Sourced {
|
||||
t.Error("thousands separators must not defeat the match")
|
||||
}
|
||||
}
|
||||
|
||||
// TestLintClassification walks the three outcomes the CLI reports.
|
||||
func TestLintClassification(t *testing.T) {
|
||||
s := &Session{
|
||||
ID: "s1",
|
||||
Messages: []Message{
|
||||
{Role: "user", Seq: 1, Text: []string{"how many files?"}},
|
||||
{Role: "assistant", Seq: 2, Outputs: []string{"44 files changed"}},
|
||||
// Same turn as the tool result: legitimately sourced.
|
||||
{Role: "assistant", Seq: 3, Text: []string{"that is 44 files"}},
|
||||
{Role: "user", Seq: 4, Text: []string{"thanks"}},
|
||||
// New turn, no tool call: restating the earlier figure.
|
||||
{Role: "assistant", Seq: 5, Text: []string{"as I said, 44 files"}},
|
||||
// Never observed anywhere.
|
||||
{Role: "assistant", Seq: 6, Text: []string{"probably 999 files"}},
|
||||
},
|
||||
}
|
||||
|
||||
got := map[int64]Status{}
|
||||
for _, r := range Lint(s) {
|
||||
got[r.Seq] = r.Status
|
||||
}
|
||||
|
||||
if got[3] != Sourced {
|
||||
t.Errorf("seq 3: got %v, want sourced (tool result in the same turn)", got[3])
|
||||
}
|
||||
if got[5] != Stale {
|
||||
t.Errorf("seq 5: got %v, want stale (restated from an earlier turn without re-checking)", got[5])
|
||||
}
|
||||
if got[6] != Unsupported {
|
||||
t.Errorf("seq 6: got %v, want unsupported (never printed by a tool)", got[6])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user