@@ -3,30 +3,17 @@ import { Schema } from "effect"
33import { LLM , SessionError } from "../src/index.js"
44
55describe ( "SessionError" , ( ) => {
6- test ( "exports one identified closed union " , ( ) => {
6+ test ( "exports one identified open envelope " , ( ) => {
77 expect ( SessionError . Error . ast . annotations ?. identifier ) . toBe ( "Session.StructuredError" )
88 expect ( Object . keys ( SessionError ) . filter ( ( key ) => key !== "SessionError" ) ) . toEqual ( [ "Error" ] )
99 } )
1010
11- test ( "round trips every closed error type through JSON" , ( ) => {
11+ test ( "round trips current and future error types through JSON" , ( ) => {
1212 const values : SessionError . Error [ ] = [
13- { type : "provider.rate-limit" , message : "Slow down" , retryAfterMs : 2_500 } ,
13+ { type : "provider.rate-limit" , message : "Slow down" } ,
1414 { type : "provider.auth" , message : "Authentication failed" } ,
15- { type : "provider.quota" , message : "Quota exhausted" } ,
16- { type : "provider.content-filter" , message : "Response blocked" } ,
17- { type : "provider.transport" , message : "Connection failed" } ,
18- { type : "provider.internal" , message : "Provider failed" } ,
19- { type : "provider.invalid-output" , message : "Malformed response" } ,
20- { type : "provider.invalid-request" , message : "Invalid request" } ,
21- { type : "provider.no-route" , message : "No route" } ,
22- { type : "provider.unknown" , message : "Unknown provider failure" } ,
23- { type : "permission.rejected" , message : "Permission rejected" , permission : "read" , resources : [ "a" ] } ,
24- { type : "tool.unknown" , message : "Unknown tool" , name : "missing" } ,
25- { type : "tool.stale" , message : "Stale tool" , name : "old" } ,
26- { type : "tool.execution" , message : "Tool failed" } ,
27- { type : "tool.result-missing" , message : "Missing result" , callID : "call_1" } ,
28- { type : "aborted" , message : "Interrupted" , reason : "user" } ,
29- { type : "unknown" , message : "Unexpected" , agent : "build" } ,
15+ { type : "provider.future-condition" , message : "A future provider failure" } ,
16+ { type : "unknown" , message : "Unexpected" } ,
3017 ]
3118 const codec = Schema . fromJsonString ( SessionError . Error )
3219
@@ -36,11 +23,19 @@ describe("SessionError", () => {
3623 }
3724 } )
3825
39- test ( "rejects unknown types and missing messages" , ( ) => {
40- expect ( ( ) =>
41- Schema . decodeUnknownSync ( SessionError . Error ) ( { type : "provider.timeout" , message : "Timeout" } ) ,
42- ) . toThrow ( )
26+ test ( "accepts future fields while exposing only the stable envelope" , ( ) => {
27+ expect (
28+ Schema . decodeUnknownSync ( SessionError . Error ) ( {
29+ type : "provider.timeout" ,
30+ message : "Timeout" ,
31+ retryAfterMs : 2_500 ,
32+ } ) ,
33+ ) . toEqual ( { type : "provider.timeout" , message : "Timeout" } )
34+ } )
35+
36+ test ( "rejects missing envelope fields" , ( ) => {
4337 expect ( ( ) => Schema . decodeUnknownSync ( SessionError . Error ) ( { type : "provider.auth" } ) ) . toThrow ( )
38+ expect ( ( ) => Schema . decodeUnknownSync ( SessionError . Error ) ( { message : "Missing type" } ) ) . toThrow ( )
4439 } )
4540} )
4641
0 commit comments