import { importModuleWithRetry } from "../src/platform/moduleLoading"; function assert(condition: unknown, message: string): asserts condition { if (!condition) throw new Error(message); } async function verifyModuleImportRetry() { let attempts = 0; let pauses = 0; const module = { id: "files", uiCapabilities: { "files.fileExplorer": {} } }; const imported = await importModuleWithRetry(async () => { attempts += 1; if (attempts === 1) throw new TypeError("Synthetic transient import failure"); return module; }, async () => { pauses += 1; }); assert(imported === module, "a second successful import preserves the real module descriptor"); assert(attempts === 2 && pauses === 1, "a transient failure gets exactly one bounded retry"); attempts = 0; pauses = 0; const terminal = new TypeError("Synthetic final import failure"); let observed: unknown; try { await importModuleWithRetry(async () => { attempts += 1; throw terminal; }, async () => { pauses += 1; }); } catch (error) { observed = error; } assert(observed === terminal, "a final failure must be reported, never replaced by an empty or fake module"); assert(attempts === 2 && pauses === 1, "permanent failure cannot start an unbounded retry loop"); attempts = 0; pauses = 0; await importModuleWithRetry(async () => { attempts += 1; return module; }, async () => { pauses += 1; }); assert(attempts === 1 && pauses === 0, "healthy imports do not pause or repeat"); console.log("Module import retry tests passed."); } void verifyModuleImportRetry().catch((error) => { throw error; });