Skip to content

Commit fe7e3a1

Browse files
committed
fix(server): keep the folder picker working beside a whitespace-only directory
1 parent 163c174 commit fe7e3a1

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎apps/server/src/workspace/WorkspaceEntries.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import * as FileSystem from "effect/FileSystem";
99
import * as Layer from "effect/Layer";
1010
import * as Path from "effect/Path";
1111
import * as PlatformError from "effect/PlatformError";
12+
import * as Schema from "effect/Schema";
1213
import * as TestClock from "effect/testing/TestClock";
14+
import { FilesystemBrowseResult } from "@t3tools/contracts";
1315
import { vi } from "vite-plus/test";
1416

1517
import * as ServerConfig from "../config.ts";
@@ -35,6 +37,8 @@ const layerTest = Layer.empty.pipe(
3537
Layer.provideMerge(NodeServices.layer),
3638
);
3739

40+
const encodeFilesystemBrowseResult = Schema.encodeEffect(FilesystemBrowseResult);
41+
3842
const makeTempDir = Effect.fn(function* (opts?: { prefix?: string; git?: boolean }) {
3943
const fileSystem = yield* FileSystem.FileSystem;
4044
const dir = yield* fileSystem.makeTempDirectoryScoped({
@@ -1224,6 +1228,27 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
12241228
}),
12251229
);
12261230

1231+
it.effect("lists siblings of whitespace-only folders with exact names", () =>
1232+
Effect.gen(function* () {
1233+
if ((yield* HostProcess.Platform) === "win32") return;
1234+
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
1235+
const path = yield* Path.Path;
1236+
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-browse-blank-" });
1237+
for (const name of [" ", "padded ", " lead", "normal"]) {
1238+
yield* writeTextFile(cwd, `${name}/README.md`, "");
1239+
}
1240+
1241+
const encoded = yield* encodeFilesystemBrowseResult(
1242+
yield* workspaceEntries.browse({ partialPath: yield* appendSeparator(cwd) }),
1243+
);
1244+
1245+
expect(encoded.entries).toEqual([
1246+
{ name: " lead", fullPath: path.join(cwd, " lead") },
1247+
{ name: "normal", fullPath: path.join(cwd, "normal") },
1248+
]);
1249+
}),
1250+
);
1251+
12271252
it.effect("lists symlinks to directories under their link path", () =>
12281253
Effect.gen(function* () {
12291254
if ((yield* HostProcess.Platform) === "win32") return;

‎apps/server/src/workspace/WorkspaceEntries.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,11 @@ export const make = Effect.gen(function* () {
276276
const entries: Array<{ readonly name: string; readonly fullPath: string }> = [];
277277
const symlinkCandidates: Array<{ readonly name: string; readonly fullPath: string }> = [];
278278
for (const dirent of dirents) {
279+
// Clients trim project paths before adding them, so these would resolve to another path.
279280
if (
280281
!dirent.name.toLowerCase().startsWith(lowerPrefix) ||
281-
(!showHidden && dirent.name.startsWith("."))
282+
(!showHidden && dirent.name.startsWith(".")) ||
283+
dirent.name.trimEnd() !== dirent.name
282284
) {
283285
continue;
284286
}

‎packages/contracts/src/filesystem.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export const FilesystemBrowseInput = Schema.Struct({
3333
export type FilesystemBrowseInput = typeof FilesystemBrowseInput.Type;
3434

3535
export const FilesystemBrowseEntry = Schema.Struct({
36-
name: TrimmedNonEmptyString,
37-
fullPath: TrimmedNonEmptyString,
36+
name: Schema.NonEmptyString,
37+
fullPath: Schema.NonEmptyString,
3838
});
3939
export type FilesystemBrowseEntry = typeof FilesystemBrowseEntry.Type;
4040

0 commit comments

Comments
 (0)