Default terminal.run cwd to launch project directory
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
c217a55d3d
commit
a201790c40
2 files changed
+40
-7
No files matched your search
@@ -1359,6 +1359,39 @@ describe("runtimeApiServer", () => {
|
||||
client.socket.close();
|
||||
});
|
||||
|
||||
it("defaults terminal commands to launch cwd when cwd is omitted", async () => {
|
||||
const launchCwd = path.dirname(process.cwd());
|
||||
const server = await startRuntimeApiServer({
|
||||
port: 0,
|
||||
launchCwd,
|
||||
});
|
||||
servers.push(server);
|
||||
|
||||
const client = await connectClient(server.wsUrl);
|
||||
await client.nextMessage();
|
||||
|
||||
const response = await sendRequest(
|
||||
client.socket,
|
||||
client.nextMessage,
|
||||
"terminal-default-cwd-1",
|
||||
"terminal.run",
|
||||
{
|
||||
command: "pwd",
|
||||
},
|
||||
);
|
||||
expect(response.ok).toBe(true);
|
||||
if (!response.ok) {
|
||||
throw new Error("Expected terminal default cwd response to succeed.");
|
||||
}
|
||||
|
||||
const payload = response.result as {
|
||||
stdout: string;
|
||||
};
|
||||
expect(payload.stdout.trim()).toBe(launchCwd);
|
||||
|
||||
client.socket.close();
|
||||
});
|
||||
|
||||
it("resolves relative terminal cwd paths against runtime working directory", async () => {
|
||||
const server = await startRuntimeApiServer({
|
||||
port: 0,
|
||||
|
||||
@@ -250,13 +250,13 @@ async function pickFolder(): Promise<string | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
async function runTerminalCommand(parsed: z.infer<typeof terminalCommandInputSchema>) {
|
||||
async function runTerminalCommand(
|
||||
parsed: z.infer<typeof terminalCommandInputSchema>,
|
||||
defaultCwd: string,
|
||||
) {
|
||||
const providedCwd = parsed.cwd ?? defaultCwd;
|
||||
const resolvedCwd = (() => {
|
||||
if (!parsed.cwd) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const candidate = path.resolve(parsed.cwd);
|
||||
const candidate = path.resolve(providedCwd);
|
||||
let stats: fs.Stats;
|
||||
try {
|
||||
stats = fs.statSync(candidate);
|
||||
@@ -531,7 +531,7 @@ export async function startRuntimeApiServer(
|
||||
|
||||
if (method === "dialogs.pickFolder") return pickFolder();
|
||||
if (method === "terminal.run") {
|
||||
return runTerminalCommand(terminalCommandInputSchema.parse(params));
|
||||
return runTerminalCommand(terminalCommandInputSchema.parse(params), launchCwd);
|
||||
}
|
||||
|
||||
if (method === "agent.spawn") return processManager.spawn(agentConfigSchema.parse(params));
|
||||
|
||||
Reference in new issue
Block a user