diff --git a/web/scripts/__tests__/check-visibility.test.ts b/web/scripts/__tests__/check-visibility.test.ts index 95cc0ae6..c69bd2b1 100644 --- a/web/scripts/__tests__/check-visibility.test.ts +++ b/web/scripts/__tests__/check-visibility.test.ts @@ -1,3 +1,5 @@ +import { spawnSync } from 'node:child_process'; +import { resolve } from 'node:path'; import { describe, expect, it } from 'vitest'; import { buildRepositoryApiUrl, @@ -250,3 +252,28 @@ describe('VisibilityReport', () => { }); }); }); + +describe('direct execution', () => { + it('prints a readable error and exits non-zero when main rejects', () => { + const result = spawnSync( + process.execPath, + [ + resolve(process.cwd(), 'node_modules', 'tsx', 'dist', 'cli.mjs'), + resolve(process.cwd(), 'scripts', 'check-visibility.ts'), + ], + { + cwd: process.cwd(), + env: { + ...process.env, + COLONY_REPOSITORY: 'invalid', + }, + encoding: 'utf-8', + } + ); + + expect(result.status).toBe(1); + expect(result.stderr).toContain( + 'Invalid repository "invalid". Expected format "owner/repo".' + ); + }); +}); diff --git a/web/scripts/check-visibility.ts b/web/scripts/check-visibility.ts index 373899c0..b56deea8 100644 --- a/web/scripts/check-visibility.ts +++ b/web/scripts/check-visibility.ts @@ -826,5 +826,8 @@ if (isDirectExecution()) { console.log('Usage: npm run check-visibility'); process.exit(0); } - void main(); + main().catch((error) => { + console.error(error instanceof Error ? error.message : String(error)); + process.exit(1); + }); }