import test from 'node:test'; import assert from 'node:assert/strict'; import { verifyConfigReadback } from './nacos-readback.mjs'; test('retries a stale read until the restored config is visible', async () => { const responses = [ new Response('old config', { status: 200 }), new Response('restored config', { status: 200 }) ]; let calls = 0; const verified = await verifyConfigReadback('http://nacos/config', 'restored config', true, { request: async () => responses[calls++], attempts: 3, delayMs: 0 }); assert.equal(verified, true); assert.equal(calls, 2); }); test('fails closed when the config does not match after bounded retries', async () => { let calls = 0; const verified = await verifyConfigReadback('http://nacos/config', 'restored config', true, { request: async () => { calls += 1; return new Response('different config', { status: 200 }); }, attempts: 3, delayMs: 0 }); assert.equal(verified, false); assert.equal(calls, 3); }); test('confirms deletion only after the config is absent', async () => { const verified = await verifyConfigReadback('http://nacos/config', null, false, { request: async () => new Response(null, { status: 404 }), attempts: 1, delayMs: 0 }); assert.equal(verified, true); });