@@ -5,6 +5,7 @@ import * as Deferred from "effect/Deferred";
55import * as Effect from "effect/Effect" ;
66import * as FileSystem from "effect/FileSystem" ;
77import * as Layer from "effect/Layer" ;
8+ import * as Logger from "effect/Logger" ;
89import * as Ref from "effect/Ref" ;
910import * as Schedule from "effect/Schedule" ;
1011import {
@@ -505,14 +506,16 @@ it.layer(layerBase, { excludeTestServices: true })("PullRequestReviewGuideServic
505506 ) ,
506507 ) ;
507508
508- /** The detail a run reports when ssh to the project's remote refuses with `refusal`. */
509- const failedRunDetail = ( refusal : string ) =>
509+ const failedRunDetail = ( refusal : string , remote = "origin" ) =>
510510 Effect . gen ( function * ( ) {
511511 const repositories = yield * makeRepositories ;
512+ if ( remote !== "origin" ) {
513+ yield * git ( repositories . workspace , [ "remote" , "rename" , "origin" , remote ] ) ;
514+ }
512515 yield * git ( repositories . workspace , [
513516 "remote" ,
514517 "set-url" ,
515- "origin" ,
518+ remote ,
516519517520 ] ) ;
518521 yield * git ( repositories . workspace , [
@@ -521,6 +524,13 @@ it.layer(layerBase, { excludeTestServices: true })("PullRequestReviewGuideServic
521524 `sh -c 'echo "${ refusal } " >&2; exit 255'` ,
522525 ] ) ;
523526 const stored = yield * Deferred . make < void > ( ) ;
527+ const completed = yield * Deferred . make < void > ( ) ;
528+ const logger = Logger . make ( ( { fiber, message } ) => {
529+ if ( Array . isArray ( message ) && message . includes ( "Review guide generation failed" ) ) {
530+ // The warning precedes the state update; wait for its fiber to finish both.
531+ fiber . addObserver ( ( ) => Deferred . doneUnsafe ( completed , Effect . void ) ) ;
532+ }
533+ } ) ;
524534 const context = yield * Layer . build (
525535 makeLayer ( {
526536 ...repositories ,
@@ -532,23 +542,21 @@ it.layer(layerBase, { excludeTestServices: true })("PullRequestReviewGuideServic
532542 context ,
533543 PullRequestReviewGuideService . PullRequestReviewGuideService ,
534544 ) ;
535- yield * service . generate ( reference ) ;
536- return yield * service . get ( reference ) . pipe (
537- Effect . flatMap ( ( result ) =>
538- result . run ?. _tag === "Failed"
539- ? Effect . succeed ( result . run . detail )
540- : Effect . fail ( "still running" as const ) ,
541- ) ,
542- Effect . retry ( Schedule . spaced ( "20 millis" ) ) ,
543- ) ;
545+ yield * service
546+ . generate ( reference )
547+ . pipe ( Effect . provide ( Logger . layer ( [ logger ] , { mergeWithExisting : false } ) ) ) ;
548+ yield * Deferred . await ( completed ) ;
549+ const result = yield * service . get ( reference ) ;
550+ assert . strictEqual ( result . run ?. _tag , "Failed" ) ;
551+ return result . run ?. _tag === "Failed" ? result . run . detail : undefined ;
544552 } ) ;
545553
546554 it . effect ( "tells the reader what to fix when git does not trust the remote's host key" , ( ) =>
547555 Effect . scoped (
548556 Effect . gen ( function * ( ) {
549557 assert . strictEqual (
550558 yield * failedRunDetail ( "Host key verification failed." ) ,
551- 'Git does not trust the SSH host key of the project\'s "origin" remote. Run "git fetch origin" in the project once, then write the guide again.' ,
559+ 'Git does not trust the SSH host key of the project\'s "origin" remote. Once "git fetch origin" works in the project, write the guide again.' ,
552560 ) ;
553561 } ) ,
554562 ) ,
@@ -559,9 +567,22 @@ it.layer(layerBase, { excludeTestServices: true })("PullRequestReviewGuideServic
559567 Effect . gen ( function * ( ) {
560568 assert . strictEqual (
561569 yield * failedRunDetail ( "[email protected] : Permission denied (publickey)." ) , 562- 'Git could not sign in to the project\'s "origin" remote. Run "git fetch origin" in the project once, then write the guide again.' ,
570+ 'Git could not sign in to the project\'s "origin" remote. Check the Git credentials or SSH key it uses. Once "git fetch origin" works in the project, write the guide again.' ,
563571 ) ;
564572 } ) ,
565573 ) ,
566574 ) ;
575+
576+ it . effect ( "keeps long or unsafe remote names out of the failure detail" , ( ) =>
577+ Effect . scoped (
578+ Effect . gen ( function * ( ) {
579+ for ( const remote of [ "remote" . repeat ( 20 ) , "remote;echo-secret" ] ) {
580+ assert . strictEqual (
581+ yield * failedRunDetail ( "Host key verification failed." , remote ) ,
582+ "Git does not trust the SSH host key of the project's configured remote. Once fetching from that remote works in the project, write the guide again." ,
583+ ) ;
584+ }
585+ } ) ,
586+ ) ,
587+ ) ;
567588} ) ;
0 commit comments