@@ -11,6 +11,7 @@ import { ModelV2 } from "@opencode-ai/core/model"
1111import { ProviderV2 } from "@opencode-ai/core/provider"
1212import { createLLMEventPublisher } from "@opencode-ai/core/session/runner/publish-llm-event"
1313import { ToolPayload } from "@opencode-ai/core/session/tool-payload"
14+ import { assertDefined } from "./lib/assert"
1415
1516const sessionID = SessionV2 . ID . make ( "ses_tool_event_test" )
1617const base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB"
@@ -78,15 +79,13 @@ test("local tool success stores media in the payload blob and omits base64 from
7879 await Effect . runPromise ( publisher . publish ( result ) )
7980
8081 const success = published . find ( ( event ) => event . type === "session.tool.success.1" )
81- expect ( success ) . toBeDefined ( )
82- if ( ! success ) throw new Error ( "Expected session.tool.success.1" )
82+ assertDefined ( success )
8383 const data = Schema . decodeUnknownSync ( SessionEvent . Tool . Success . data ) ( success . data )
84- expect ( data . payloadHash ) . toBeDefined ( )
84+ assertDefined ( data . payloadHash )
8585 expect ( JSON . stringify ( success ) . includes ( base64 ) ) . toBe ( false )
8686 expect ( success . data ) . not . toHaveProperty ( "result" )
8787 expect ( data . content ) . toEqual ( [ { type : "text" , text : "Image read successfully" } ] )
8888
89- if ( ! data . payloadHash ) throw new Error ( "Expected payloadHash on thin success" )
9089 const body = payloads . get ( data . payloadHash )
9190 expect ( body ?. content ) . toEqual ( [
9291 { type : "text" , text : "Image read successfully" } ,
@@ -100,12 +99,10 @@ test("provider-executed success keeps raw provider result in the payload blob on
10099 await Effect . runPromise ( publisher . publish ( LLMEvent . toolCall ( { ...call , providerExecuted : true } ) ) )
101100 await Effect . runPromise ( publisher . publish ( LLMEvent . toolResult ( { ...result , providerExecuted : true } ) ) )
102101 const success = published . find ( ( event ) => event . type === "session.tool.success.1" )
103- expect ( success ) . toBeDefined ( )
104- if ( ! success ) throw new Error ( "Expected session.tool.success.1" )
102+ assertDefined ( success )
105103 expect ( success . data ) . not . toHaveProperty ( "result" )
106104 const data = Schema . decodeUnknownSync ( SessionEvent . Tool . Success . data ) ( success . data )
107- expect ( data . payloadHash ) . toBeDefined ( )
108- if ( ! data . payloadHash ) throw new Error ( "Expected payloadHash on thin success" )
105+ assertDefined ( data . payloadHash )
109106 expect ( payloads . get ( data . payloadHash ) ?. result ) . toBeDefined ( )
110107} )
111108
@@ -268,7 +265,7 @@ test("content-filter finish retains failure evidence until step closeout", async
268265 finish : "content-filter" ,
269266 tokens : { input : 8 , output : 2 , reasoning : 1 } ,
270267 } )
271- if ( ! settlement ) throw new Error ( "Expected content-filter settlement" )
268+ assertDefined ( settlement )
272269 await Effect . runPromise (
273270 publisher . publishStepFailure ( {
274271 cost : Money . USD . make ( 1.25 ) ,
0 commit comments