@@ -15,7 +15,7 @@ import { fileURLToPath } from "node:url";
1515import { spawn } from "node:child_process" ;
1616import test from "node:test" ;
1717
18- import { TOOLS , resolveTool , toolList } from "../src/tools.mjs" ;
18+ import { TOOLS , resolveTool , retry , toolList } from "../src/tools.mjs" ;
1919
2020const BIN = fileURLToPath ( new URL ( "../bin/moshcode.mjs" , import . meta. url ) ) ;
2121
@@ -204,3 +204,25 @@ test("moshcode install reports an Object.prototype name as unknown", async () =>
204204 assert . match ( result . stderr , / u s a g e : m o s h c o d e i n s t a l l < e n g i n e \| t o o l > / ) ;
205205 assert . doesNotMatch ( result . stderr , / T y p e E r r o r / ) ;
206206} ) ;
207+
208+ test ( "retry rejects non-positive attempt limits" , async ( ) => {
209+ let calls = 0 ;
210+
211+ await assert . rejects (
212+ retry ( ( ) => { calls ++ ; } , 0 , 1 ) ,
213+ / m a x A t t e m p t s m u s t b e a p o s i t i v e i n t e g e r / ,
214+ ) ;
215+ assert . equal ( calls , 0 ) ;
216+ } ) ;
217+
218+ test ( "retry retries until a later attempt succeeds" , async ( ) => {
219+ let calls = 0 ;
220+ const result = await retry ( ( ) => {
221+ calls ++ ;
222+ if ( calls < 2 ) throw new Error ( "not yet" ) ;
223+ return "ok" ;
224+ } , 2 , 1 ) ;
225+
226+ assert . equal ( result , "ok" ) ;
227+ assert . equal ( calls , 2 ) ;
228+ } ) ;
0 commit comments