@@ -3,20 +3,11 @@ import * as NodePath from "node:path";
33
44import * as NodeServices from "@effect/platform-node/NodeServices" ;
55import { it } from "@effect/vitest" ;
6- import {
7- ThreadId ,
8- VcsProcessExitError ,
9- VcsProcessSpawnError ,
10- VcsProcessTimeoutError ,
11- VcsUnsupportedOperationError ,
12- type VcsError ,
13- } from "@t3tools/contracts" ;
6+ import { ThreadId , type VcsError } from "@t3tools/contracts" ;
147import { HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
15- import * as DateTime from "effect/DateTime" ;
168import * as Effect from "effect/Effect" ;
179import * as FileSystem from "effect/FileSystem" ;
1810import * as Layer from "effect/Layer" ;
19- import * as Option from "effect/Option" ;
2011import * as PlatformError from "effect/PlatformError" ;
2112import * as Scope from "effect/Scope" ;
2213import { describe , expect } from "vite-plus/test" ;
@@ -25,7 +16,6 @@ import { checkpointRefForThreadTurn } from "./Utils.ts";
2516import { parseTurnDiffFilesFromNumstat } from "./Diffs.ts" ;
2617import * as CheckpointStore from "./CheckpointStore.ts" ;
2718import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts" ;
28- import * as VcsDriver from "../vcs/VcsDriver.ts" ;
2919import * as VcsProcess from "../vcs/VcsProcess.ts" ;
3020import * as ServerConfig from "../config.ts" ;
3121
@@ -442,184 +432,3 @@ it.layer(TestLayer)("CheckpointStore.layer", (it) => {
442432 ) ;
443433 } ) ;
444434} ) ;
445-
446- const RetryCwd = "/tmp/checkpoint-retry-test" ;
447-
448- function makeCaptureExitError ( ) : VcsProcessExitError {
449- return new VcsProcessExitError ( {
450- operation : "CheckpointStore.captureCheckpoint" ,
451- command : "git" ,
452- cwd : RetryCwd ,
453- exitCode : 128 ,
454- detail : "Process exited with a non-zero status." ,
455- } ) ;
456- }
457-
458- function makeFakeRegistryLayer (
459- capture : ( ) => Effect . Effect < void , VcsError > ,
460- ) : Layer . Layer < VcsDriverRegistry . VcsDriverRegistry > {
461- const driver = {
462- checkpoints : {
463- captureCheckpoint : ( ) => capture ( ) ,
464- } ,
465- } as unknown as VcsDriver . VcsDriver [ "Service" ] ;
466- return Layer . succeed (
467- VcsDriverRegistry . VcsDriverRegistry ,
468- VcsDriverRegistry . VcsDriverRegistry . of ( {
469- get : ( ) => Effect . die ( "not used in this test" ) ,
470- detect : ( ) => Effect . succeed ( null ) ,
471- resolve : ( ) =>
472- Effect . succeed ( {
473- kind : "git" ,
474- repository : {
475- kind : "git" ,
476- rootPath : RetryCwd ,
477- metadataPath : null ,
478- freshness : {
479- source : "live-local" ,
480- observedAt : DateTime . makeUnsafe ( 0 ) ,
481- expiresAt : Option . none ( ) ,
482- } ,
483- } ,
484- driver,
485- } ) ,
486- } ) ,
487- ) ;
488- }
489-
490- function makeStoreWithCapture (
491- capture : ( ) => Effect . Effect < void , VcsError > ,
492- ) : Effect . Effect < CheckpointStore . CheckpointStore [ "Service" ] , never , Scope . Scope > {
493- return Effect . provide (
494- CheckpointStore . CheckpointStore ,
495- CheckpointStore . layer . pipe ( Layer . provide ( makeFakeRegistryLayer ( capture ) ) ) ,
496- ) ;
497- }
498-
499- describe ( "captureCheckpoint retry" , ( ) => {
500- it . live ( "retries transient capture failures until they succeed" , ( ) =>
501- Effect . scoped (
502- Effect . gen ( function * ( ) {
503- let attempts = 0 ;
504- const error = makeCaptureExitError ( ) ;
505- const checkpointStore = yield * makeStoreWithCapture ( ( ) => {
506- attempts += 1 ;
507- return attempts < 3 ? Effect . fail ( error ) : Effect . void ;
508- } ) ;
509-
510- yield * checkpointStore . captureCheckpoint ( {
511- cwd : RetryCwd ,
512- checkpointRef : checkpointRefForThreadTurn ( ThreadId . make ( "thread-capture-retry" ) , 0 ) ,
513- } ) ;
514-
515- expect ( attempts ) . toBe ( 3 ) ;
516- } ) ,
517- ) ,
518- ) ;
519-
520- it . live ( "gives up after retries and keeps the last failure" , ( ) =>
521- Effect . scoped (
522- Effect . gen ( function * ( ) {
523- let attempts = 0 ;
524- const error = makeCaptureExitError ( ) ;
525- const checkpointStore = yield * makeStoreWithCapture ( ( ) => {
526- attempts += 1 ;
527- return Effect . fail ( error ) ;
528- } ) ;
529-
530- const failure = yield * Effect . flip (
531- checkpointStore . captureCheckpoint ( {
532- cwd : RetryCwd ,
533- checkpointRef : checkpointRefForThreadTurn ( ThreadId . make ( "thread-capture-retry" ) , 0 ) ,
534- } ) ,
535- ) ;
536-
537- expect ( attempts ) . toBe ( 3 ) ;
538- expect ( failure ) . toBe ( error ) ;
539- } ) ,
540- ) ,
541- ) ;
542-
543- it . live ( "does not retry permanent unsupported-driver failures" , ( ) =>
544- Effect . scoped (
545- Effect . gen ( function * ( ) {
546- let attempts = 0 ;
547- const error = new VcsUnsupportedOperationError ( {
548- operation : "CheckpointStore.captureCheckpoint" ,
549- kind : "unknown" ,
550- detail : "unknown driver does not implement checkpoint operations." ,
551- } ) ;
552- const checkpointStore = yield * makeStoreWithCapture ( ( ) => {
553- attempts += 1 ;
554- return Effect . fail ( error ) ;
555- } ) ;
556-
557- const failure = yield * Effect . flip (
558- checkpointStore . captureCheckpoint ( {
559- cwd : RetryCwd ,
560- checkpointRef : checkpointRefForThreadTurn ( ThreadId . make ( "thread-capture-retry" ) , 0 ) ,
561- } ) ,
562- ) ;
563-
564- expect ( attempts ) . toBe ( 1 ) ;
565- expect ( failure ) . toBe ( error ) ;
566- } ) ,
567- ) ,
568- ) ;
569-
570- it . live ( "does not retry spawn failures" , ( ) =>
571- Effect . scoped (
572- Effect . gen ( function * ( ) {
573- let attempts = 0 ;
574- const error = new VcsProcessSpawnError ( {
575- operation : "CheckpointStore.captureCheckpoint" ,
576- command : "git" ,
577- cwd : RetryCwd ,
578- cause : new Error ( "spawn EAGAIN" ) ,
579- } ) ;
580- const checkpointStore = yield * makeStoreWithCapture ( ( ) => {
581- attempts += 1 ;
582- return Effect . fail ( error ) ;
583- } ) ;
584-
585- const failure = yield * Effect . flip (
586- checkpointStore . captureCheckpoint ( {
587- cwd : RetryCwd ,
588- checkpointRef : checkpointRefForThreadTurn ( ThreadId . make ( "thread-capture-retry" ) , 0 ) ,
589- } ) ,
590- ) ;
591-
592- expect ( attempts ) . toBe ( 1 ) ;
593- expect ( failure ) . toBe ( error ) ;
594- } ) ,
595- ) ,
596- ) ;
597-
598- it . live ( "does not retry timeout failures" , ( ) =>
599- Effect . scoped (
600- Effect . gen ( function * ( ) {
601- let attempts = 0 ;
602- const error = new VcsProcessTimeoutError ( {
603- operation : "CheckpointStore.captureCheckpoint" ,
604- command : "git" ,
605- cwd : RetryCwd ,
606- timeoutMs : 30_000 ,
607- } ) ;
608- const checkpointStore = yield * makeStoreWithCapture ( ( ) => {
609- attempts += 1 ;
610- return Effect . fail ( error ) ;
611- } ) ;
612-
613- const failure = yield * Effect . flip (
614- checkpointStore . captureCheckpoint ( {
615- cwd : RetryCwd ,
616- checkpointRef : checkpointRefForThreadTurn ( ThreadId . make ( "thread-capture-retry" ) , 0 ) ,
617- } ) ,
618- ) ;
619-
620- expect ( attempts ) . toBe ( 1 ) ;
621- expect ( failure ) . toBe ( error ) ;
622- } ) ,
623- ) ,
624- ) ;
625- } ) ;
0 commit comments