|
1 | 1 | import { describe, expect, it, vi } from 'vitest'; |
2 | 2 |
|
3 | 3 | // @ts-expect-error -- plain .mjs build script, no type declarations |
4 | | -import { classifyError, publishEachTarget, withRetry } from '../scripts/publish-retry.mjs'; |
| 4 | +import { classifyError, publishEachTarget, SUMMARY_LIMIT, summaryLine, withRetry } from '../scripts/publish-retry.mjs'; |
5 | 5 |
|
6 | 6 | const TARGETS = ['darwin-x64', 'darwin-arm64', 'linux-x64']; |
7 | 7 | const FILES = TARGETS.map((target) => `/tmp/${target}.vsix`); |
@@ -50,7 +50,63 @@ describe('withRetry', () => { |
50 | 50 | }); |
51 | 51 | }); |
52 | 52 |
|
| 53 | +describe('summaryLine', () => { |
| 54 | + /** |
| 55 | + * The exact shape `runLocalCli` throws, and the exact reason the 0.12.0 release |
| 56 | + * printed six `FAILED <target>: Local ovsx exited with code 1:` lines with no |
| 57 | + * cause: the summary kept only the wrapper line and dropped the output after it. |
| 58 | + */ |
| 59 | + it('keeps the registry error that follows the CLI wrapper line', () => { |
| 60 | + const error = new Error( |
| 61 | + 'Local ovsx exited with code 1:\nERROR Unknown namespace: pythoughts\n', |
| 62 | + ); |
| 63 | + |
| 64 | + const line = summaryLine(error); |
| 65 | + |
| 66 | + expect(line).toContain('Unknown namespace: pythoughts'); |
| 67 | + expect(line).toContain('exited with code 1'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('caps a long error whether or not it has a second line', () => { |
| 71 | + // The cap used to bind only to the joined branch, so a registry answering |
| 72 | + // with one long JSON line printed in full. |
| 73 | + expect(summaryLine(new Error('x'.repeat(500)))).toHaveLength(SUMMARY_LIMIT); |
| 74 | + expect(summaryLine(new Error(`wrapper:\n${'y'.repeat(500)}`))).toHaveLength(SUMMARY_LIMIT); |
| 75 | + }); |
| 76 | + |
| 77 | + it('leaves a single-line error alone and survives a blank one', () => { |
| 78 | + expect(summaryLine(new Error('Response code 401 (Unauthorized)'))) |
| 79 | + .toBe('Response code 401 (Unauthorized)'); |
| 80 | + // A CLI that failed without writing anything: every line is blank. |
| 81 | + expect(summaryLine(' \n \n')).toBe(''); |
| 82 | + }); |
| 83 | +}); |
| 84 | + |
53 | 85 | describe('publishEachTarget', () => { |
| 86 | + it('reports the underlying cause for a failed target, not just the wrapper', async () => { |
| 87 | + const publishOne = vi.fn().mockRejectedValue( |
| 88 | + new Error('Local ovsx exited with code 1:\nERROR Unknown namespace: pythoughts'), |
| 89 | + ); |
| 90 | + const logged: string[] = []; |
| 91 | + const log = vi.spyOn(console, 'log').mockImplementation((...args) => { |
| 92 | + logged.push(args.join(' ')); |
| 93 | + }); |
| 94 | + |
| 95 | + try { |
| 96 | + await expect( |
| 97 | + publishEachTarget({ targets: TARGETS, files: FILES, registry: 'Open VSX', publishOne }), |
| 98 | + ).rejects.toThrow('3 of 3 target(s) failed'); |
| 99 | + } finally { |
| 100 | + log.mockRestore(); |
| 101 | + } |
| 102 | + |
| 103 | + const failures = logged.filter((line) => line.includes('FAILED')); |
| 104 | + expect(failures).toHaveLength(3); |
| 105 | + for (const failure of failures) { |
| 106 | + expect(failure).toContain('Unknown namespace: pythoughts'); |
| 107 | + } |
| 108 | + }); |
| 109 | + |
54 | 110 | it('keeps publishing after one target fails, so a flake cannot strand the rest', async () => { |
55 | 111 | const publishOne = vi.fn(async (_file: string, target: string) => { |
56 | 112 | if (target === 'darwin-arm64') throw new Error('Extension rejected'); |
|
0 commit comments