|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { test } from 'vitest'; |
| 3 | +import { AppError } from '@agent-device/kernel/errors'; |
| 4 | +import { |
| 5 | + parseGitHubActionsArtifactInstallSourceSpec, |
| 6 | + parseInstallSourceConfig, |
| 7 | +} from './install-source-config.ts'; |
| 8 | + |
| 9 | +test('parses GitHub Actions artifact specs into the exact install source shape', () => { |
| 10 | + assert.deepEqual(parseGitHubActionsArtifactInstallSourceSpec(' acme/mobile: 12345 '), { |
| 11 | + kind: 'github-actions-artifact', |
| 12 | + owner: 'acme', |
| 13 | + repo: 'mobile', |
| 14 | + artifactId: 12345, |
| 15 | + }); |
| 16 | + assert.deepEqual(parseGitHubActionsArtifactInstallSourceSpec('acme/mobile: build-debug'), { |
| 17 | + kind: 'github-actions-artifact', |
| 18 | + owner: 'acme', |
| 19 | + repo: 'mobile', |
| 20 | + artifactName: 'build-debug', |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +test('parses config artifact names and numeric IDs with trimmed repository fields', () => { |
| 25 | + assert.deepEqual( |
| 26 | + parseInstallSourceConfig( |
| 27 | + { |
| 28 | + type: 'github-actions-artifact', |
| 29 | + repo: ' acme/mobile ', |
| 30 | + artifact: ' build-debug ', |
| 31 | + }, |
| 32 | + 'user config file', |
| 33 | + ), |
| 34 | + { |
| 35 | + kind: 'github-actions-artifact', |
| 36 | + owner: 'acme', |
| 37 | + repo: 'mobile', |
| 38 | + artifactName: 'build-debug', |
| 39 | + }, |
| 40 | + ); |
| 41 | + assert.deepEqual( |
| 42 | + parseInstallSourceConfig( |
| 43 | + { type: 'github-actions-artifact', repo: 'acme/mobile', artifact: '12345' }, |
| 44 | + 'project config file', |
| 45 | + ), |
| 46 | + { |
| 47 | + kind: 'github-actions-artifact', |
| 48 | + owner: 'acme', |
| 49 | + repo: 'mobile', |
| 50 | + artifactId: 12345, |
| 51 | + }, |
| 52 | + ); |
| 53 | +}); |
| 54 | + |
| 55 | +test('rejects empty and malformed source values with typed INVALID_ARGS errors', () => { |
| 56 | + assertInvalidArgs( |
| 57 | + () => parseGitHubActionsArtifactInstallSourceSpec(''), |
| 58 | + '--github-actions-artifact must use owner/repo:artifact, for example thymikee/RNCLI83:6635342232', |
| 59 | + ); |
| 60 | + assertInvalidArgs( |
| 61 | + () => parseGitHubActionsArtifactInstallSourceSpec('acme/mobile:'), |
| 62 | + '--github-actions-artifact must use owner/repo:artifact, for example thymikee/RNCLI83:6635342232', |
| 63 | + ); |
| 64 | + assertInvalidArgs( |
| 65 | + () => |
| 66 | + parseInstallSourceConfig( |
| 67 | + { type: 'github-actions-artifact', repo: 'acme/mobile', artifact: ' ' }, |
| 68 | + 'config', |
| 69 | + ), |
| 70 | + 'config installSource.artifact must be a non-empty string.', |
| 71 | + ); |
| 72 | + assertInvalidArgs( |
| 73 | + () => parseInstallSourceConfig({ type: 'github-actions-artifact', repo: 'acme' }, 'config'), |
| 74 | + 'config installSource.repo must use owner/repo.', |
| 75 | + ); |
| 76 | +}); |
| 77 | + |
| 78 | +function assertInvalidArgs(run: () => unknown, message: string): void { |
| 79 | + assert.throws(run, (error: unknown) => { |
| 80 | + assert.ok(error instanceof AppError); |
| 81 | + assert.equal(error.code, 'INVALID_ARGS'); |
| 82 | + assert.equal(error.message, message); |
| 83 | + assert.equal(error.cause, undefined); |
| 84 | + return true; |
| 85 | + }); |
| 86 | +} |
0 commit comments