Skip to content
Merged
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: 1 addition & 15 deletions src/install/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,6 @@ export async function resolveWindowsCommandPath(
return undefined;
}

function quoteWindowsShellArgument(argument: string): string {
if (argument.length === 0) {
return '""';
}

return /[\s"&()<>^|]/u.test(argument)
? `"${argument.replaceAll('"', '""')}"`
: argument;
}

function createCommandNotFoundError(command: string): NodeJS.ErrnoException {
const error = new Error(`spawn ${command} ENOENT`) as NodeJS.ErrnoException;

Expand Down Expand Up @@ -408,12 +398,8 @@ export async function prepareInstallCommand(
};
}

const commandLine = [resolvedCommandPath, ...args]
.map(quoteWindowsShellArgument)
.join(" ");

return {
args: ["/d", "/s", "/c", commandLine],
args: ["/d", "/s", "/c", resolvedCommandPath, ...args],
command:
getEnvironmentValue(normalizedEnv, "ComSpec", platform) ?? "cmd.exe",
windowsHide: true,
Expand Down
5 changes: 4 additions & 1 deletion test/install/deps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ test("prepareInstallCommand routes Windows .cmd shims through ComSpec", async ()
"/d",
"/s",
"/c",
'"C:\\Program Files\\OpenCode\\opencode.CMD" debug config --pure',
"C:\\Program Files\\OpenCode\\opencode.CMD",
"debug",
"config",
"--pure",
]);
});

Expand Down
39 changes: 39 additions & 0 deletions test/install/verify-effective.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,3 +1192,42 @@ test("the fake opencode harness also supports plain debug config invocations for
await harness.cleanup();
}
});

test("the fake opencode harness supports debug config --pure invocations through the real command runner", async () => {
const harness = await createInstallIntegrationHarness();

try {
await harness.installFakeOpenCodeOnPath({
debugConfigPureOutput: '{\n "mode": "pure"\n}\n',
output: "opencode-ai 1.4.0",
});

const dependencies = harness.createDependencies();
const result = await dependencies.commands.run(
"opencode",
["debug", "config", "--pure"],
{
cwd: dependencies.runtime.cwd,
env: dependencies.runtime.env,
},
);

assert.equal(result.exitCode, 0);
assert.match(result.stdout, /"mode": "pure"/);

const invocations = await harness.readFakeOpenCodeInvocations();

assert.equal(
invocations.some(
(args) =>
args.length === 3 &&
args[0] === "debug" &&
args[1] === "config" &&
args[2] === "--pure",
),
true,
);
} finally {
await harness.cleanup();
}
});
Loading