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
47 changes: 47 additions & 0 deletions apps/server/src/process/externalLauncher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,53 @@ it.effect("launches the default browser through the platform command", () => {
);
});

it.effect("strips file manager positions without changing existing paths", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-file-manager-" });
const commandPath = path.join(binDir, "open");
const targetPath = path.join(binDir, "CLAUDE.md");
const existingColonPath = `${targetPath}:2024`;
const missingColonPath = path.join(binDir, "missing:2024");
yield* fileSystem.writeFileString(commandPath, "#!/bin/sh\n");
yield* fileSystem.chmod(commandPath, 0o755);
yield* fileSystem.writeFileString(targetPath, "");
yield* fileSystem.writeFileString(existingColonPath, "");

const spawned: ChildProcess.StandardCommand[] = [];
yield* Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
for (const cwd of [targetPath, `${targetPath}:4`, `${targetPath}:12:4`]) {
yield* launcher.launchEditor({ editor: "file-manager", cwd });
}
yield* launcher.launchEditor({ editor: "file-manager", cwd: existingColonPath });
yield* launcher.launchEditor({ editor: "file-manager", cwd: missingColonPath });
}).pipe(
Effect.provide(
testLayer({
platform: "darwin",
env: { PATH: binDir },
onSpawn: (command) => {
spawned.push(command);
},
}),
),
);

assert.deepEqual(
spawned.map(({ command, args }) => ({ command, args })),
[
{ command: "open", args: [targetPath] },
{ command: "open", args: [targetPath] },
{ command: "open", args: [targetPath] },
{ command: "open", args: [existingColonPath] },
{ command: "open", args: [missingColonPath] },
],
);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it.effect("launches an installed editor with platform-safe arguments", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
Expand Down
18 changes: 16 additions & 2 deletions apps/server/src/process/externalLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ function parseTargetPathAndPosition(target: string): Option.Option<TargetPathAnd
});
}

const resolveFileManagerTarget = Effect.fn("externalLauncher.resolveFileManagerTarget")(function* (
target: string,
): Effect.fn.Return<string, never, FileSystem.FileSystem> {
const parsedTarget = parseTargetPathAndPosition(target);
if (Option.isNone(parsedTarget)) return target;

const fileSystem = yield* FileSystem.FileSystem;
if (yield* fileSystem.exists(target).pipe(Effect.orElseSucceed(() => false))) return target;
return (yield* fileSystem.exists(parsedTarget.value.path).pipe(Effect.orElseSucceed(() => false)))
? parsedTarget.value.path
: target;
});

function resolveCommandEditorArgs(
editor: (typeof EDITORS)[number],
target: string,
Expand Down Expand Up @@ -376,11 +389,12 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
return yield* new ExternalLauncherUnsupportedEditorError({ editor: input.editor });
}

const target = yield* resolveFileManagerTarget(input.cwd);
return {
editor: editorDef.id,
target: input.cwd,
target,
command: fileManagerCommandForPlatform(platform),
args: [input.cwd],
args: [target],
};
});

Expand Down
Loading