@@ -24,6 +24,12 @@ describe("account-core", () => {
2424 expect ( riskBandForScore ( score ) ) . toBe ( "high" ) ;
2525 } ) ;
2626
27+ it ( "treats non-finite risk scores as critical" , ( ) => {
28+ expect ( riskBandForScore ( Number . NaN ) ) . toBe ( "critical" ) ;
29+ expect ( riskBandForScore ( Number . POSITIVE_INFINITY ) ) . toBe ( "critical" ) ;
30+ expect ( riskBandForScore ( Number . NEGATIVE_INFINITY ) ) . toBe ( "critical" ) ;
31+ } ) ;
32+
2733 it ( "requires approval for gated actions with matching grants" , ( ) => {
2834 const result = evaluateAccountPolicy ( {
2935 action : "email:send" ,
@@ -41,6 +47,25 @@ describe("account-core", () => {
4147 expect ( result . decision ) . toBe ( "approval_required" ) ;
4248 } ) ;
4349
50+ it . each ( [ Number . NaN , Number . POSITIVE_INFINITY , Number . NEGATIVE_INFINITY ] ) ( "fails closed for non-finite policy risk score %s" , ( riskScore ) => {
51+ const result = evaluateAccountPolicy ( {
52+ action : "social:profile:read" ,
53+ riskScore,
54+ principal : { type : "agent" , id : "reader-agent" } ,
55+ grant : {
56+ id : "grant_read" ,
57+ accountId : "account_1" ,
58+ principal : { type : "agent" , id : "reader-agent" } ,
59+ permissions : [ "social:profile:read" ] ,
60+ policy : [ ] ,
61+ createdAt : new Date ( 0 ) . toISOString ( )
62+ }
63+ } ) ;
64+
65+ expect ( result . riskScore ) . toBe ( 1 ) ;
66+ expect ( result . decision ) . toBe ( "deny" ) ;
67+ } ) ;
68+
4469 it . each ( [
4570 { principal : { type : "agent" as const , id : "trusted-agent" , trusted : true } , expected : "allow" } ,
4671 { principal : { type : "agent" as const , id : "untrusted-agent" , trusted : false } , expected : "approval_required" } ,
0 commit comments