Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions scripts/claude-native-driver.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 14 additions & 1 deletion scripts/claude-native-driver.test.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand Down
Loading