more diagnostics
This commit is contained in:
parent
4de1784780
commit
f4d3aa1a60
3 changed files with 251 additions and 4 deletions
166
src/e2e/windows-debug.test.ts
Normal file
166
src/e2e/windows-debug.test.ts
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
import path from "path";
|
||||
import { spawn } from "child_process";
|
||||
import { createTestContext, cleanupTestContext } from "../test-helpers/cli-helpers.js";
|
||||
|
||||
describe("Windows CI Debug", () => {
|
||||
// Only run these tests on Windows CI
|
||||
const skipTests = !(process.platform === "win32" && process.env.CI);
|
||||
|
||||
if (skipTests) {
|
||||
it.skip("only runs on Windows CI", () => {});
|
||||
return;
|
||||
}
|
||||
|
||||
it("should verify Node.js can execute the CLI file directly", async () => {
|
||||
const context = await createTestContext();
|
||||
|
||||
try {
|
||||
// Test 1: Direct Node execution with simple --version flag
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const proc = spawn(process.execPath, [context.cliPath, "--version"], {
|
||||
cwd: context.testDir,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
shell: false,
|
||||
windowsVerbatimArguments: true,
|
||||
});
|
||||
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
|
||||
proc.stdout.on("data", (data) => {
|
||||
stdout += data.toString();
|
||||
});
|
||||
|
||||
proc.stderr.on("data", (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
|
||||
proc.on("error", (error) => {
|
||||
console.error("Process spawn error:", error);
|
||||
reject(error);
|
||||
});
|
||||
|
||||
proc.on("exit", (code, signal) => {
|
||||
console.log("Process exit:", { code, signal, stdout, stderr });
|
||||
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`Process exited with code ${code}, stderr: ${stderr}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
} finally {
|
||||
await cleanupTestContext(context);
|
||||
}
|
||||
}, 30000);
|
||||
|
||||
it("should capture early CLI errors", async () => {
|
||||
const context = await createTestContext();
|
||||
|
||||
try {
|
||||
// Test 2: Try with a minimal command that should work
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const env = {
|
||||
...process.env,
|
||||
DEBUG_CLI_TESTS: "1",
|
||||
NODE_OPTIONS: "", // Clear any NODE_OPTIONS that might interfere
|
||||
};
|
||||
|
||||
const proc = spawn(process.execPath, [context.cliPath, "--help"], {
|
||||
cwd: context.testDir,
|
||||
env,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
shell: false,
|
||||
});
|
||||
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
let errorOutput = "";
|
||||
|
||||
proc.stdout.on("data", (data) => {
|
||||
const text = data.toString();
|
||||
stdout += text;
|
||||
console.log("[STDOUT]:", text);
|
||||
});
|
||||
|
||||
proc.stderr.on("data", (data) => {
|
||||
const text = data.toString();
|
||||
stderr += text;
|
||||
errorOutput += text;
|
||||
console.log("[STDERR]:", text);
|
||||
});
|
||||
|
||||
proc.on("error", (error) => {
|
||||
console.error("Process spawn error:", error);
|
||||
reject(error);
|
||||
});
|
||||
|
||||
proc.on("exit", (code, signal) => {
|
||||
console.log("Process exit details:", {
|
||||
code,
|
||||
signal,
|
||||
stdoutLength: stdout.length,
|
||||
stderrLength: stderr.length,
|
||||
hasCliStartLog: stderr.includes("[CLI_START]"),
|
||||
hasCliErrorLog: stderr.includes("[CLI_ERROR]"),
|
||||
});
|
||||
|
||||
// Even if it fails, we want to see what happened
|
||||
if (stderr.includes("[CLI_ERROR]") || stderr.includes("Error:")) {
|
||||
console.log("Full error output:", errorOutput);
|
||||
}
|
||||
|
||||
resolve(); // Always resolve to see the output
|
||||
});
|
||||
});
|
||||
} finally {
|
||||
await cleanupTestContext(context);
|
||||
}
|
||||
}, 30000);
|
||||
|
||||
it("should test module resolution", async () => {
|
||||
const context = await createTestContext();
|
||||
|
||||
try {
|
||||
// Test 3: Check if ESM modules are the issue
|
||||
const testScript = `
|
||||
console.log("Test script running on:", process.platform);
|
||||
console.log("Node version:", process.version);
|
||||
console.log("__dirname:", import.meta.url);
|
||||
|
||||
try {
|
||||
await import("commander");
|
||||
console.log("SUCCESS: commander module loaded");
|
||||
} catch (e) {
|
||||
console.error("FAILED to load commander:", e.message);
|
||||
}
|
||||
`;
|
||||
|
||||
const testFile = path.join(context.testDir, "test-esm.mjs");
|
||||
const fs = await import("fs/promises");
|
||||
await fs.writeFile(testFile, testScript);
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
const proc = spawn(process.execPath, [testFile], {
|
||||
cwd: context.testDir,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
});
|
||||
|
||||
proc.stdout.on("data", (data) => {
|
||||
console.log("[ESM Test STDOUT]:", data.toString());
|
||||
});
|
||||
|
||||
proc.stderr.on("data", (data) => {
|
||||
console.log("[ESM Test STDERR]:", data.toString());
|
||||
});
|
||||
|
||||
proc.on("exit", () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
} finally {
|
||||
await cleanupTestContext(context);
|
||||
}
|
||||
}, 30000);
|
||||
});
|
||||
38
src/index.ts
38
src/index.ts
|
|
@ -1,5 +1,13 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
// Add immediate logging to debug Windows CI issues
|
||||
if (process.env.DEBUG_CLI_TESTS || (process.platform === "win32" && process.env.CI)) {
|
||||
console.error(`[CLI_START] Node ${process.version} on ${process.platform} ${process.arch}`);
|
||||
console.error(`[CLI_START] Args: ${JSON.stringify(process.argv)}`);
|
||||
console.error(`[CLI_START] CWD: ${process.cwd()}`);
|
||||
console.error(`[CLI_START] __dirname: ${import.meta.url}`);
|
||||
}
|
||||
|
||||
import { Command } from "commander";
|
||||
import { chat } from "./commands/chat.js";
|
||||
import { login } from "./commands/login.js";
|
||||
|
|
@ -87,10 +95,32 @@ program.on("command:*", () => {
|
|||
process.exit(1);
|
||||
});
|
||||
|
||||
// Parse arguments and handle errors
|
||||
// Wrap everything in a try-catch for Windows CI debugging
|
||||
async function main() {
|
||||
try {
|
||||
await program.parseAsync();
|
||||
} catch (error: any) {
|
||||
console.error("[CLI_ERROR] Fatal error during execution:");
|
||||
console.error("[CLI_ERROR] Message:", error.message);
|
||||
console.error("[CLI_ERROR] Stack:", error.stack);
|
||||
console.error("[CLI_ERROR] Code:", error.code);
|
||||
|
||||
// More specific error messages
|
||||
if (error.code === 'MODULE_NOT_FOUND') {
|
||||
console.error("[CLI_ERROR] Missing module. This might be a build or path issue.");
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Catch any synchronous errors during startup
|
||||
try {
|
||||
program.parse();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
main().catch((error) => {
|
||||
console.error("[CLI_ERROR] Unhandled async error:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("[CLI_ERROR] Synchronous startup error:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,25 @@ export async function runCLI(
|
|||
script: context.cliPath,
|
||||
args: args,
|
||||
});
|
||||
|
||||
// Check if dist/index.js exists and is readable
|
||||
try {
|
||||
const distIndexPath = path.resolve(context.cliPath);
|
||||
const stats = await fs.stat(distIndexPath);
|
||||
console.log("CLI file stats:", {
|
||||
exists: true,
|
||||
size: stats.size,
|
||||
isFile: stats.isFile(),
|
||||
mode: stats.mode.toString(8),
|
||||
});
|
||||
|
||||
// Read first few lines to check for shebang issues
|
||||
const content = await fs.readFile(distIndexPath, 'utf8');
|
||||
const firstLines = content.split('\n').slice(0, 5).join('\n');
|
||||
console.log("First lines of CLI file:", firstLines);
|
||||
} catch (checkError) {
|
||||
console.error("Failed to check CLI file:", checkError);
|
||||
}
|
||||
}
|
||||
|
||||
const result = await execaNode(context.cliPath, args, execOptions);
|
||||
|
|
@ -150,12 +169,44 @@ export async function runCLI(
|
|||
cwd: execOptions.cwd,
|
||||
cliPath: context.cliPath,
|
||||
args,
|
||||
// Add more Windows-specific debugging info
|
||||
nodeVersion: process.version,
|
||||
platform: process.platform,
|
||||
arch: process.arch,
|
||||
// Include the full error object for debugging
|
||||
fullError: {
|
||||
name: error.name,
|
||||
stack: error.stack,
|
||||
code: error.code,
|
||||
signal: error.signal,
|
||||
killed: error.killed,
|
||||
timedOut: error.timedOut,
|
||||
}
|
||||
};
|
||||
console.error("CLI execution failed:", errorDetails);
|
||||
|
||||
// On Windows, if we get empty output, it might be a Node.js path issue
|
||||
if (process.platform === "win32" && !stdout && !stderr) {
|
||||
console.error("Windows: No output captured. This might be a Node.js execution issue.");
|
||||
console.error("Attempting direct node execution for diagnostics...");
|
||||
|
||||
// Try to run with node directly to see if we get better error info
|
||||
try {
|
||||
const { execSync } = require('child_process');
|
||||
const directResult = execSync(`${process.execPath} "${context.cliPath}" --version`, {
|
||||
cwd: context.testDir,
|
||||
encoding: 'utf8',
|
||||
stdio: 'pipe'
|
||||
});
|
||||
console.error("Direct execution succeeded:", directResult);
|
||||
} catch (directError: any) {
|
||||
console.error("Direct execution also failed:", {
|
||||
message: directError.message,
|
||||
stdout: directError.stdout?.toString(),
|
||||
stderr: directError.stderr?.toString(),
|
||||
status: directError.status,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
throw error;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue