diff --git a/src/commands/test/browser.ts b/src/commands/test/browser.ts index e043011..5993bb2 100644 --- a/src/commands/test/browser.ts +++ b/src/commands/test/browser.ts @@ -39,8 +39,9 @@ import { Command } from 'commander' import { chromium, Browser, BrowserContext, Page } from 'playwright' import { execSync } from 'child_process' import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs' -import { dirname, join } from 'node:path' +import { dirname, join, resolve } from 'node:path' import { homedir } from 'node:os' +import { fileURLToPath } from 'node:url' import { log } from '../../core/log.ts' import { JnpfClient } from '../../core/client.ts' @@ -809,8 +810,14 @@ Prerequisites (workflow module): } // 拿 token (dacli app context --json, 备用 — JnpfClient.fromToken 已用 cached) + // Fix: 用绝对路径 + dacli 源码根目录 cwd, 不要用 process.cwd() 相对 src/cli.ts (会 ERR_MODULE_NOT_FOUND) + // Path: dacli/src/commands/test/browser.ts → ../../../ 才是 cli.ts + // ESM: __dirname 不可用, 用 import.meta.url 替代 + const __filename = fileURLToPath(import.meta.url) + const __dirname2 = dirname(__filename) + const DACLI_ROOT = resolve(__dirname2, '..', '..', '..') const tokenRaw = execSync('npx tsx src/cli.ts app context --json', { - cwd: process.cwd(), + cwd: DACLI_ROOT, encoding: 'utf-8', }) const ctx = JSON.parse(tokenRaw)