@@ -358,58 +358,45 @@ describe.sequential("signRelayAgentActivityPublishProof", () => {
358358 ) . toEqual ( [ activeThreadId ] ) ;
359359 } ) ;
360360
361- it ( "signs the activity publish JWT and rejects tampering" , async ( ) => {
362- const keyPair = NodeCrypto . generateKeyPairSync ( "ed25519" , {
363- privateKeyEncoding : { format : "pem ", type : "pkcs8" } ,
364- publicKeyEncoding : { format : "pem" , type : "spki " } ,
365- } ) ;
366- const payload = {
367- iss : "t3-env:env" ,
368- aud : "https://relay.example.test " ,
369- sub : "env " ,
370- jti : "nonce-1 " ,
371- iat : 100 ,
372- exp : 200 ,
373- environmentId : state . environmentId ,
374- threadId : state . threadId ,
375- state,
376- } satisfies RelayAgentActivityPublishProofPayload ;
377- const proof = await Effect . runPromise (
378- AgentAwarenessRelay . signRelayAgentActivityPublishProof ( {
361+ it . effect ( "signs the activity publish JWT and rejects tampering" , ( ) =>
362+ Effect . gen ( function * ( ) {
363+ const keyPair = NodeCrypto . generateKeyPairSync ( "ed25519 ", {
364+ privateKeyEncoding : { format : "pem" , type : "pkcs8 " } ,
365+ publicKeyEncoding : { format : "pem" , type : "spki" } ,
366+ } ) ;
367+ const payload = {
368+ iss : "t3-env:env " ,
369+ aud : "https://relay.example.test " ,
370+ sub : "env " ,
371+ jti : "nonce-1" ,
372+ iat : 100 ,
373+ exp : 200 ,
374+ environmentId : state . environmentId ,
375+ threadId : state . threadId ,
376+ state ,
377+ } satisfies RelayAgentActivityPublishProofPayload ;
378+ const proof = yield * AgentAwarenessRelay . signRelayAgentActivityPublishProof ( {
379379 privateKey : keyPair . privateKey ,
380380 payload,
381- } ) ,
382- ) ;
383-
384- await expect (
385- Effect . runPromise (
386- verifyRelayJwt ( {
387- publicKey : keyPair . publicKey ,
388- token : proof ,
389- typ : RELAY_ACTIVITY_PUBLISH_TYP ,
390- issuer : "t3-env:env" ,
391- audience : "https://relay.example.test" ,
392- nowEpochSeconds : 150 ,
393- } ) ,
394- ) ,
395- ) . resolves . toMatchObject ( { jti : "nonce-1" , state } ) ;
396- await expect (
397- Effect . runPromise (
381+ } ) ;
382+ const verify = ( token : string ) =>
398383 verifyRelayJwt ( {
399384 publicKey : keyPair . publicKey ,
400- token : ( ( ) => {
401- const [ header , body , signature = "" ] = proof . split ( "." ) ;
402- const corruptedSignature = `${ signature . startsWith ( "a" ) ? "b" : "a" } ${ signature . slice ( 1 ) } ` ;
403- return `${ header } .${ body } .${ corruptedSignature } ` ;
404- } ) ( ) ,
385+ token,
405386 typ : RELAY_ACTIVITY_PUBLISH_TYP ,
406387 issuer : "t3-env:env" ,
407388 audience : "https://relay.example.test" ,
408389 nowEpochSeconds : 150 ,
409- } ) ,
410- ) ,
411- ) . rejects . toBeDefined ( ) ;
412- } ) ;
390+ } ) ;
391+
392+ expect ( yield * verify ( proof ) ) . toMatchObject ( { jti : "nonce-1" , state } ) ;
393+
394+ const [ header , body , signature = "" ] = proof . split ( "." ) ;
395+ const corruptedSignature = `${ signature . startsWith ( "a" ) ? "b" : "a" } ${ signature . slice ( 1 ) } ` ;
396+ const rejection = yield * Effect . flip ( verify ( `${ header } .${ body } .${ corruptedSignature } ` ) ) ;
397+ expect ( rejection ) . toBeDefined ( ) ;
398+ } ) ,
399+ ) ;
413400
414401 it . effect ( "keeps the orchestration listener armed until relay config is installed" , ( ) =>
415402 Effect . scoped (
@@ -557,10 +544,11 @@ describe.sequential("signRelayAgentActivityPublishProof", () => {
557544 Effect . scoped (
558545 Effect . gen ( function * ( ) {
559546 const originalFetch = globalThis . fetch ;
560- const context = yield * Effect . context < never > ( ) ;
561- const runFork = Effect . runForkWith ( context ) ;
562547 const events = yield * Queue . unbounded < OrchestrationEvent > ( ) ;
563- const fetchSeen = yield * Deferred . make < URL > ( ) ;
548+ let resolveFetchSeen : ( url : URL ) => void = ( ) => { } ;
549+ const fetchSeen = new Promise < URL > ( ( resolve ) => {
550+ resolveFetchSeen = resolve ;
551+ } ) ;
564552 const userSpans : Array < string > = [ ] ;
565553 const productSpans : Array < string > = [ ] ;
566554 const collectingTracer = ( spans : Array < string > ) =>
@@ -648,7 +636,7 @@ describe.sequential("signRelayAgentActivityPublishProof", () => {
648636 ? input
649637 : ( input as unknown as { readonly url : string } ) . url ,
650638 ) ;
651- runFork ( Deferred . succeed ( fetchSeen , url ) ) ;
639+ resolveFetchSeen ( url ) ;
652640 return Promise . resolve ( Response . json ( { ok : true , deliveries : [ ] } ) ) ;
653641 } ) as unknown as typeof fetch ;
654642 yield * Effect . addFinalizer ( ( ) =>
@@ -707,7 +695,7 @@ describe.sequential("signRelayAgentActivityPublishProof", () => {
707695 occurredAt : now ,
708696 } as unknown as OrchestrationEvent ) ;
709697
710- const url = yield * Deferred . await ( fetchSeen ) . pipe ( Effect . timeout ( "2 seconds" ) ) ;
698+ const url = yield * Effect . promise ( ( ) => fetchSeen ) . pipe ( Effect . timeout ( "2 seconds" ) ) ;
711699 expect ( url . origin ) . toBe ( "https://transport.example.test" ) ;
712700 expect ( productSpans ) . toContain ( "makePublishProof" ) ;
713701 expect ( userSpans ) . not . toContain ( "makePublishProof" ) ;
0 commit comments