diff --git a/bin/gapwise.mjs b/bin/gapwise.mjs index fe94eac..6d5204d 100755 --- a/bin/gapwise.mjs +++ b/bin/gapwise.mjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { spawnSync } from 'node:child_process'; @@ -159,6 +159,6 @@ export function main(argv = process.argv.slice(2)) { throw new Error('Usage: gapwise university create|validate|dev|test [--dry-run] [--workspace PATH]\n gapwise data validate|osm '); } -if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { +if (process.argv[1] && realpathSync(resolve(process.argv[1])) === fileURLToPath(import.meta.url)) { try { main(); } catch (error) { console.error(error instanceof Error ? error.message : error); process.exitCode = 1; } } diff --git a/tests/cli.test.mjs b/tests/cli.test.mjs index ee28f31..d60ba9d 100644 --- a/tests/cli.test.mjs +++ b/tests/cli.test.mjs @@ -1,6 +1,6 @@ import test from 'node:test'; import assert from 'node:assert/strict'; -import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { dirname, join, resolve } from 'node:path'; import { spawnSync } from 'node:child_process'; @@ -36,6 +36,18 @@ test('dry run shows integration and data files without changing the workspace', } finally { rmSync(workspace, { recursive: true, force: true }); } }); +test('installed bin symlink executes the CLI', () => { + const workspace = fixture(); + try { + const installedBin = join(workspace, 'gapwise-bin'); + symlinkSync(resolve(import.meta.dirname, '../bin/gapwise.mjs'), installedBin); + const result = spawnSync(installedBin, ['university', 'create', 'example-university', '--dry-run', '--workspace', workspace], + { encoding: 'utf8' }); + assert.equal(result.status, 0, result.stderr); + assert.match(result.stdout, /Dry run for example-university/); + } finally { rmSync(workspace, { recursive: true, force: true }); } +}); + test('scaffold creates adapter, manifest, test, and empty campus snapshots', () => { const workspace = fixture(); try {