An open source design system that's fully customizable and agent ready
TypeScript
test(cli): G49's three claims each get their own case and budget (#9074)
Christopher Chedeauf3daac4a4e48
diff --git a/packages/cli/test/global-local.test.mjs b/packages/cli/test/global-local.test.mjsindex ba5f52bc4d..f138941a9d 100644--- a/packages/cli/test/global-local.test.mjs+++ b/packages/cli/test/global-local.test.mjs@@ -2202,56 +2202,92 @@ describe.skipIf(!POSIX)(});});- it('G49 offline, a release that failed to install is retried after 2 minutes, then after 10 once it fails again, by any copy sharing the cache; a success forgets it', () => {- const pc = computer();- const g = globalCli('npm', '9.0.0', {root: pc.home});- const dir = makeProject({core: '9.0.3', brokenCli: '9.0.3'});- const record = path.join(- pc.astryxCache,- 'releases',- '.failed-9.0.3.json',- );- const installs = (/** @type {{lines: string[]}} */ r) =>- r.lines.filter(l => l.includes('installing')).length;- /** Move the last failure `minutes` into the past. @param {number} minutes */- const age = minutes => {- const old = JSON.parse(fs.readFileSync(record, 'utf8'));- fs.writeFileSync(- record,- JSON.stringify({...old, at: old.at - minutes * 60_000}),+ // One row of the table, in three cases: each replays only the installs it+ // needs, and a failed install waits out the CLI's own bounded retry.+ describe('G49 offline, a release that failed to install is retried after 2 minutes, then after 10 once it fails again, by any copy sharing the cache; a success forgets it', () => {+ /**+ * G49's world: a global CLI and a project whose own CLI cannot start and+ * whose Core release cannot be installed (the registry is unreachable),+ * with the record of that release's failed installs. Each case below+ * replays only the installs it needs: a failed one waits out the CLI's+ * own bounded retry, a few seconds each.+ */+ const g49 = () => {+ const pc = computer();+ const g = globalCli('npm', '9.0.0', {root: pc.home});+ const dir = makeProject({core: '9.0.3', brokenCli: '9.0.3'});+ const record = path.join(+ pc.astryxCache,+ 'releases',+ '.failed-9.0.3.json',);+ const read = () => JSON.parse(fs.readFileSync(record, 'utf8'));+ return {+ pc,+ g,+ dir,+ record,+ read,+ /** Runs `astryx --version` with `bin`; the global copy by default. */+ version: (bin = g.bin) => run(bin, ['--version'], {cwd: dir, pc}),+ /** Move the last failure `minutes` into the past. @param {number} minutes */+ age: (/** @type {number} */ minutes) => {+ const old = read();+ fs.writeFileSync(+ record,+ JSON.stringify({...old, at: old.at - minutes * 60_000}),+ );+ },+ };};- expect(installs(run(g.bin, ['--version'], {cwd: dir, pc}))).toBe(1);- expect(JSON.parse(fs.readFileSync(record, 'utf8')).failures).toBe(1);- // Within 2 minutes, from this copy or another, no install starts.- const other = globalCli('npm', '9.0.1', {- root: path.join(pc.home, 'other'),- });- for (const bin of [g.bin, other.bin]) {- const again = run(bin, ['--version'], {cwd: dir, pc});- expect(again.status).toBe(0);- expect(installs(again)).toBe(0);- expect(again.lines).toEqual([- expect.stringMatching(- /^astryx: could not get Astryx 9\.0\.3 to match this project's Core \(.+; last tried 1 minute ago, tried again after 2 minutes\); answering with CLI 9\.0\.[01] instead$/u,- ),- ]);- }- // After 2 minutes it tries again; a second failure waits 10.- age(3);- expect(installs(run(g.bin, ['--version'], {cwd: dir, pc}))).toBe(1);- expect(JSON.parse(fs.readFileSync(record, 'utf8')).failures).toBe(2);- age(3);- const waiting = run(g.bin, ['--version'], {cwd: dir, pc});- expect(installs(waiting)).toBe(0);- expect(waiting.lines[0]).toMatch(/tried again after 10 minutes\)/u);- age(8);- expect(installs(run(g.bin, ['--version'], {cwd: dir, pc}))).toBe(1);- // A success forgets the record.- seedPackedRelease(pc.astryxCache, '9.0.3');- age(11);- expect(run(g.bin, ['--version'], {cwd: dir, pc}).stdout).toBe('9.0.3');- expect(fs.existsSync(record)).toBe(false);+ const installs = (/** @type {{lines: string[]}} */ r) =>+ r.lines.filter(l => l.includes('installing')).length;++ it('the first failure is recorded, and neither this copy nor another sharing the cache tries again within 2 minutes', () => {+ const {pc, version, read} = g49();+ expect(installs(version())).toBe(1);+ expect(read().failures).toBe(1);+ const other = globalCli('npm', '9.0.1', {+ root: path.join(pc.home, 'other'),+ });+ for (const bin of [undefined, other.bin]) {+ const again = version(bin);+ expect(again.status).toBe(0);+ expect(installs(again)).toBe(0);+ expect(again.lines).toEqual([+ expect.stringMatching(+ /^astryx: could not get Astryx 9\.0\.3 to match this project's Core \(.+; last tried 1 minute ago, tried again after 2 minutes\); answering with CLI 9\.0\.[01] instead$/u,+ ),+ ]);+ }+ });++ it('after 2 minutes it is tried again, and a second failure in a row waits 10', () => {+ const {version, read, age} = g49();+ expect(installs(version())).toBe(1);+ age(3);+ expect(installs(version())).toBe(1);+ expect(read().failures).toBe(2);+ age(3);+ const waiting = version();+ expect(installs(waiting)).toBe(0);+ expect(waiting.lines[0]).toMatch(/tried again after 10 minutes\)/u);+ });++ it('after 10 minutes two failures in a row are tried again, and a success forgets them', () => {+ const {pc, record, version, read, age} = g49();+ expect(installs(version())).toBe(1);+ // A second failure in a row, recorded as the CLI records it.+ fs.writeFileSync(record, JSON.stringify({...read(), failures: 2}));+ // Past 10 minutes it installs again, for real, and fails a third time.+ age(11);+ expect(installs(version())).toBe(1);+ expect(read().failures).toBe(3);+ // A release installed by then answers, and forgets the failures.+ seedPackedRelease(pc.astryxCache, '9.0.3');+ expect(version().stdout).toBe('9.0.3');+ expect(fs.existsSync(record)).toBe(false);+ });});it('G50 a global copy in a Bun global folder moved with BUN_INSTALL: global only while BUN_INSTALL names it; an app under a folder named install/global is not', () => {@@ -2712,7 +2748,9 @@ describe.skipIf(!POSIX)(it('names every row of the table exactly once', () => {const text = fs.readFileSync(new URL(import.meta.url), 'utf8');const rows = [- ...text.matchAll(/^\s+it(?:\.skipIf\([^)]*\)\()?\(?\s*['"](G\d+) /gmu),+ ...text.matchAll(+ /^\s+(?:it|describe)(?:\.skipIf\([^)]*\)\()?\(?\s*['"](G\d+) /gmu,+ ),].map(m => m[1]);expect(rows).toEqual(Array.from({length: 58}, (_, i) => `G${i + 1}`));expect(os.EOL).toBeTypeOf('string');