feat(assessment): add the review band of attempt signals and the disclosed collector
This commit is contained in:
1 parent
68286af8b7
commit
b3c6dc870b
124 files changed
+13522
-633
No files matched your search
@@ -0,0 +1,80 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDemoSignalPolicyIsValidAndRoundTripsThroughTheDocument(t *testing.T) {
|
||||
policy := DemoProductPolicyV3()
|
||||
if err := policy.Validate(); err != nil {
|
||||
t.Fatalf("DemoProductPolicyV3().Validate() error = %v", err)
|
||||
}
|
||||
encoded, _, err := encodeProductPolicy(policy)
|
||||
if err != nil {
|
||||
t.Fatalf("encodeProductPolicy() error = %v", err)
|
||||
}
|
||||
decoded, err := decodeProductPolicy(encoded)
|
||||
if err != nil {
|
||||
t.Fatalf("decodeProductPolicy() error = %v", err)
|
||||
}
|
||||
if decoded.Assessment.Signals == nil || *decoded.Assessment.Signals != DemoAssessmentSignalPolicy() {
|
||||
t.Fatalf("decoded signals = %+v, want the demo values", decoded.Assessment.Signals)
|
||||
}
|
||||
if DemoProductPolicyV2().Assessment.Signals != nil {
|
||||
t.Fatal("DemoProductPolicyV2 gained a signal section; a stored version must not change")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignalSectionAloneIsASchemaTwoExtensionAndNeverAcquiresDefaults(t *testing.T) {
|
||||
signals := DemoAssessmentSignalPolicy()
|
||||
policy := DemoProductPolicyV1()
|
||||
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.Attempt != nil || decoded.Support != nil {
|
||||
t.Fatalf("decode signals-only schema 2 = %+v, error %v", decoded.Assessment, err)
|
||||
}
|
||||
|
||||
legacy := editPolicySchemaDocument(t, []byte(demoProductPolicyV1Document), func(document map[string]any) {
|
||||
policySection(t, document, "assessment")["signals"] = nil
|
||||
})
|
||||
if _, err := decodeProductPolicy(legacy); !errors.Is(err, ErrInvalidPolicy) {
|
||||
t.Fatalf("decodeProductPolicy(schema 1 with a signals key) error = %v, want ErrInvalidPolicy", err)
|
||||
}
|
||||
|
||||
missingField := editPolicySchemaDocument(t, encoded, func(document map[string]any) {
|
||||
delete(policySection(t, policySection(t, document, "assessment"), "signals"), "fast_floor_integer_ms")
|
||||
})
|
||||
if _, err := decodeProductPolicy(missingField); !errors.Is(err, ErrInvalidPolicy) {
|
||||
t.Fatalf("decodeProductPolicy(missing signal field) error = %v, want ErrInvalidPolicy", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignalPolicyRejectsOutOfRangeAndInconsistentValues(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
change func(*AssessmentSignalPolicy)
|
||||
}{
|
||||
{"zero section", func(policy *AssessmentSignalPolicy) { *policy = AssessmentSignalPolicy{} }},
|
||||
{"floor in seconds instead of milliseconds", func(policy *AssessmentSignalPolicy) { policy.FastFloorIntegerMS = 5 }},
|
||||
{"review below attention", func(policy *AssessmentSignalPolicy) { policy.FastAnswersReview = policy.FastAnswersAttention - 1 }},
|
||||
{"duplicate review below attention", func(policy *AssessmentSignalPolicy) { policy.DuplicateReviewBits = policy.DuplicateAttentionBits - 1 }},
|
||||
{"deviation ratio below two", func(policy *AssessmentSignalPolicy) { policy.DeviationRatio = 15000 }},
|
||||
{"deviation needs several answers", func(policy *AssessmentSignalPolicy) { policy.DeviationMinAnswers = 2 }},
|
||||
{"evidence bits beyond a hash", func(policy *AssessmentSignalPolicy) { policy.DuplicateSequenceCapBits = 65 }},
|
||||
{"client threshold zero", func(policy *AssessmentSignalPolicy) { policy.ClientClipboardEventsAttention = 0 }},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
policy := DemoAssessmentSignalPolicy()
|
||||
test.change(&policy)
|
||||
if err := policy.Validate(); !errors.Is(err, ErrInvalidPolicy) {
|
||||
t.Fatalf("Validate() error = %v, want ErrInvalidPolicy", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user