From 293b52d81c142896a80aaf1664be81130b7a2cda Mon Sep 17 00:00:00 2001 From: ArthurKing Date: Mon, 23 Nov 2026 01:01:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Claude=20=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E9=A9=B1=E5=8A=A8=E4=BB=8E=E7=9B=AE=E5=BD=95=E8=81=94?= =?UTF-8?q?=E6=8E=A5=E5=90=AF=E5=8A=A8=E6=97=B6=E9=9D=99=E9=BB=98=E9=80=80?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/claude-native-driver.mjs | 16 ++++++++++++---- scripts/claude-native-driver.test.mjs | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/scripts/claude-native-driver.mjs b/scripts/claude-native-driver.mjs index ed0c40f31..806069188 100644 --- a/scripts/claude-native-driver.mjs +++ b/scripts/claude-native-driver.mjs @@ -1,5 +1,6 @@ #!/usr/bin/env node +import { realpathSync } from 'node:fs'; import { createRequire } from 'node:module'; import os from 'node:os'; import path from 'node:path'; @@ -1209,11 +1210,18 @@ export function startClaudeNativeDriverStdioServer({ return { server, readline: rl }; } -const isDirectEntry = - Boolean(process.argv[1]) && - import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href; +function isDirectEntry() { + if (!process.argv[1]) return false; + const entry = pathToFileURL(path.resolve(process.argv[1])).href; + if (entry === import.meta.url) return true; + try { + return pathToFileURL(realpathSync.native(process.argv[1])).href === import.meta.url; + } catch { + return false; + } +} -if (isDirectEntry) { +if (isDirectEntry()) { if (process.argv.includes('--probe')) { process.stdout.write(`${PROBE_OK}\n`); process.exit(0); diff --git a/scripts/claude-native-driver.test.mjs b/scripts/claude-native-driver.test.mjs index 5e3ae553f..0d4d5cedc 100644 --- a/scripts/claude-native-driver.test.mjs +++ b/scripts/claude-native-driver.test.mjs @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { spawn } from 'node:child_process'; +import { execFileSync, spawn } from 'node:child_process'; import fs from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; @@ -20,6 +20,19 @@ import { const __dirname = path.dirname(fileURLToPath(import.meta.url)); const DRIVER_SCRIPT = path.join(__dirname, 'claude-native-driver.mjs'); +test('从目录联接启动驱动可以通过探测', async () => { + const root = await fs.mkdtemp(path.join(os.tmpdir(), 'claude-entry-')); + const alias = path.join(root, 'scripts'); + try { + await fs.symlink(__dirname, alias, process.platform === 'win32' ? 'junction' : 'dir'); + const output = execFileSync(process.execPath, [path.join(alias, path.basename(DRIVER_SCRIPT)), '--probe'], { encoding: 'utf8' }); + assert.equal(output.trim(), PROBE_OK); + } finally { + await fs.rm(alias, { force: true }); + await fs.rmdir(root); + } +}); + function createHarness({ env = {}, sdkLoader, now, fetchImpl } = {}) { const stdin = new PassThrough(); const stdout = new PassThrough();