feat(assessment): record capture hints and keep one window per attempt

This commit is contained in:
shira committed 2026-10-11 13:16:52 +03:00
1 parent c975a0d506
commit bb917bf62e
108 files changed
+6649 -139

No files matched your search

@@ -2,6 +2,7 @@ package domain
import (
"errors"
"strings"
"testing"
)
@@ -78,3 +79,66 @@ func TestSignalPolicyRejectsOutOfRangeAndInconsistentValues(t *testing.T) {
})
}
}
// A version published before the capture hints existed carries none of their
// fields. It must decode with the hints switched off and encode back to the same
// document, so its content hash and the bands of its attempts never change.
func TestPolicyWithoutCaptureThresholdsDecodesOffAndEncodesUnchanged(t *testing.T) {
policy := DemoProductPolicyV3()
encoded, _, err := encodeProductPolicy(policy)
if err != nil {
t.Fatalf("encodeProductPolicy() error = %v", err)
}
for _, field := range []string{"client_screenshot_keys_attention", "client_devtools_attention", "extra_agents_attention", "extra_agents_review"} {
if strings.Contains(string(encoded), field) {
t.Fatalf("the document of the published policy holds %q, want it absent", field)
}
}
decoded, err := decodeProductPolicy(encoded)
if err != nil {
t.Fatalf("decodeProductPolicy() error = %v", err)
}
signals := decoded.Assessment.Signals
if signals == nil || signals.ClientScreenshotKeysAttention != 0 || signals.ClientDevtoolsAttention != 0 || signals.ExtraAgentsAttention != 0 || signals.ExtraAgentsReview != 0 {
t.Fatalf("decoded signals = %+v, want the capture hints off", signals)
}
again, _, err := encodeProductPolicy(decoded)
if err != nil || string(again) != string(encoded) {
t.Fatalf("re-encoded document differs from the stored one (error %v)", err)
}
}
func TestCaptureThresholdsRoundTripAndAreValidated(t *testing.T) {
signals := DemoAssessmentSignalPolicyWithCaptureHints()
if signals.ClientScreenshotKeysAttention == 0 || signals.ClientDevtoolsAttention == 0 || signals.ExtraAgentsAttention == 0 {
t.Fatalf("DemoAssessmentSignalPolicyWithCaptureHints() = %+v, want the hints switched on", signals)
}
policy := DemoProductPolicyV3()
policy.Assessment.Signals = &signals
encoded, _, err := encodeProductPolicy(policy)
if err != nil {
t.Fatalf("encodeProductPolicy() error = %v", err)
}
decoded, err := decodeProductPolicy(encoded)
if err != nil || decoded.Assessment.Signals == nil || *decoded.Assessment.Signals != signals {
t.Fatalf("decoded signals = %+v, error %v, want the thresholds back", decoded.Assessment.Signals, err)
}
if DemoAssessmentSignalPolicy().ClientScreenshotKeysAttention != 0 {
t.Fatal("DemoAssessmentSignalPolicy gained a capture threshold; a stored version must not change")
}
for name, change := range map[string]func(*AssessmentSignalPolicy){
"negative threshold": func(policy *AssessmentSignalPolicy) { policy.ClientDevtoolsAttention = -1 },
"threshold beyond the bound": func(policy *AssessmentSignalPolicy) { policy.ClientScreenshotKeysAttention = maxSignalCount + 1 },
"review without attention": func(policy *AssessmentSignalPolicy) { policy.ExtraAgentsAttention, policy.ExtraAgentsReview = 0, 3 },
"review below attention": func(policy *AssessmentSignalPolicy) { policy.ExtraAgentsAttention, policy.ExtraAgentsReview = 4, 3 },
"attention without a review": func(policy *AssessmentSignalPolicy) { policy.ExtraAgentsAttention, policy.ExtraAgentsReview = 2, 0 },
} {
t.Run(name, func(t *testing.T) {
policy := DemoAssessmentSignalPolicyWithCaptureHints()
change(&policy)
if err := policy.Validate(); !errors.Is(err, ErrInvalidPolicy) {
t.Fatalf("Validate() error = %v, want ErrInvalidPolicy", err)
}
})
}
}