Skip to content
TypeScript

test: skip symlink fixtures where the host cannot create symlinks (#9566)

Julius Marminge30f128fababb
diff --git a/apps/desktop/src/preview/BrowserImport/BrowserImport.test.ts b/apps/desktop/src/preview/BrowserImport/BrowserImport.test.ts
index 9b0a652f09f..00346108537 100644
--- a/apps/desktop/src/preview/BrowserImport/BrowserImport.test.ts
+++ b/apps/desktop/src/preview/BrowserImport/BrowserImport.test.ts
@@ -14,6 +14,7 @@ import * as Ref from "effect/Ref";
import * as BrowserSession from "../BrowserSession.ts";
import * as BrowserImport from "./BrowserImport.ts";
import { BROWSER_IMPORT_SOURCES, sourcePathContext } from "./Sources.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const helium = BROWSER_IMPORT_SOURCES.find((source) => source.id === "helium")!;
@@ -105,28 +106,30 @@ describe("BrowserImport.importCookies", () => {
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
);
- it.effect("refuses to import while the source browser holds its profile", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const { importer, root } = yield* withImporter();
- // The lock Chromium leaves while it is running, dangling target and
- // all. This must stop the import before it ever asks the keychain.
- yield* fileSystem.symlink("host-that-does-not-exist-1234", `${root}/SingletonLock`);
-
- const error = yield* importer
- .importCookies({
- input: {
- sourceId: "helium",
- sourceProfileDirectory: "Default",
- targetProfileId: "default",
- },
- scope: "persist:t3code-preview-test",
- persistent: true,
- })
- .pipe(Effect.flip);
+ it.effect.skipIf(!symlinksSupported)(
+ "refuses to import while the source browser holds its profile",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const { importer, root } = yield* withImporter();
+ // The lock Chromium leaves while it is running, dangling target and
+ // all. This must stop the import before it ever asks the keychain.
+ yield* fileSystem.symlink("host-that-does-not-exist-1234", `${root}/SingletonLock`);
+
+ const error = yield* importer
+ .importCookies({
+ input: {
+ sourceId: "helium",
+ sourceProfileDirectory: "Default",
+ targetProfileId: "default",
+ },
+ scope: "persist:t3code-preview-test",
+ persistent: true,
+ })
+ .pipe(Effect.flip);
- assert.equal(error.reason, "browserRunning");
- }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
+ assert.equal(error.reason, "browserRunning");
+ }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
);
});
diff --git a/apps/desktop/src/preview/BrowserImport/Sources.test.ts b/apps/desktop/src/preview/BrowserImport/Sources.test.ts
index feaac842cbe..282bf10d36d 100644
--- a/apps/desktop/src/preview/BrowserImport/Sources.test.ts
+++ b/apps/desktop/src/preview/BrowserImport/Sources.test.ts
@@ -32,6 +32,7 @@ import {
sourcePathContext,
windowsChromiumCookiesAreHeld,
} from "./Sources.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const helium = BROWSER_IMPORT_SOURCES.find((source) => source.id === "helium")!;
@@ -125,7 +126,7 @@ const writeFirefoxCookieDatabase = (
});
describe("Helium on Linux", () => {
- it.effect("discovers its profiles and checks the user-data lock", () =>
+ it.effect.skipIf(!symlinksSupported)("discovers its profiles and checks the user-data lock", () =>
run(
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
@@ -221,48 +222,52 @@ describe("isSourceRunning", () => {
),
);
- it.effect("reads Chromium's dangling SingletonLock symlink as a running browser", () =>
- run(
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const context = yield* withSourceHome();
- assert.isFalse(yield* isSourceRunning(helium, context));
-
- // Chromium points the lock at `<host>-<pid>`, a target that never
- // exists on disk. A check that follows the link reports a running
- // browser as closed, letting an import read a live, mid-write database.
- yield* fileSystem.symlink(
- "host-that-does-not-exist-1234",
- `${userDataDirectory(context)}/SingletonLock`,
- );
+ it.effect.skipIf(!symlinksSupported)(
+ "reads Chromium's dangling SingletonLock symlink as a running browser",
+ () =>
+ run(
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const context = yield* withSourceHome();
+ assert.isFalse(yield* isSourceRunning(helium, context));
+
+ // Chromium points the lock at `<host>-<pid>`, a target that never
+ // exists on disk. A check that follows the link reports a running
+ // browser as closed, letting an import read a live, mid-write database.
+ yield* fileSystem.symlink(
+ "host-that-does-not-exist-1234",
+ `${userDataDirectory(context)}/SingletonLock`,
+ );
- assert.isTrue(yield* isSourceRunning(helium, context));
- }),
- ),
+ assert.isTrue(yield* isSourceRunning(helium, context));
+ }),
+ ),
);
- it.effect("uses the provided hostname to classify Chromium locks", () =>
- run(
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const paths = yield* withSourceHome();
- yield* fileSystem.symlink(
- "lock-owner-99999999",
- `${helium.userDataDirectory(paths)}/SingletonLock`,
- );
+ it.effect.skipIf(!symlinksSupported)(
+ "uses the provided hostname to classify Chromium locks",
+ () =>
+ run(
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const paths = yield* withSourceHome();
+ yield* fileSystem.symlink(
+ "lock-owner-99999999",
+ `${helium.userDataDirectory(paths)}/SingletonLock`,
+ );
- assert.isTrue(
- yield* isSourceRunning(helium, paths).pipe(
- Effect.provideService(HostProcessHostname, "another-host"),
- ),
- );
- assert.isFalse(
- yield* isSourceRunning(helium, paths).pipe(
- Effect.provideService(HostProcessHostname, "lock-owner"),
- ),
- );
- }),
- ),
+ assert.isTrue(
+ yield* isSourceRunning(helium, paths).pipe(
+ Effect.provideService(HostProcessHostname, "another-host"),
+ ),
+ );
+ assert.isFalse(
+ yield* isSourceRunning(helium, paths).pipe(
+ Effect.provideService(HostProcessHostname, "lock-owner"),
+ ),
+ );
+ }),
+ ),
);
});
@@ -385,25 +390,27 @@ describe("isSourceInstalled", () => {
),
);
- it.effect("follows cookie database symlinks when detecting profiles", () =>
- run(
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const context = yield* withSourceHome();
- const root = userDataDirectory(context);
- yield* fileSystem.makeDirectory(`${root}/Default`, { recursive: true });
- yield* fileSystem.symlink("missing-cookies", `${root}/Default/Cookies`);
+ it.effect.skipIf(!symlinksSupported)(
+ "follows cookie database symlinks when detecting profiles",
+ () =>
+ run(
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const context = yield* withSourceHome();
+ const root = userDataDirectory(context);
+ yield* fileSystem.makeDirectory(`${root}/Default`, { recursive: true });
+ yield* fileSystem.symlink("missing-cookies", `${root}/Default/Cookies`);
- assert.deepEqual(yield* listSourceProfiles(helium, context), []);
- assert.isFalse(yield* isSourceInstalled(helium, context));
+ assert.deepEqual(yield* listSourceProfiles(helium, context), []);
+ assert.isFalse(yield* isSourceInstalled(helium, context));
- yield* fileSystem.writeFileString(`${root}/Default/missing-cookies`, "db");
- assert.deepEqual(yield* listSourceProfiles(helium, context), [
- { directory: "Default", name: "Default" },
- ]);
- assert.isTrue(yield* isSourceInstalled(helium, context));
- }),
- ),
+ yield* fileSystem.writeFileString(`${root}/Default/missing-cookies`, "db");
+ assert.deepEqual(yield* listSourceProfiles(helium, context), [
+ { directory: "Default", name: "Default" },
+ ]);
+ assert.isTrue(yield* isSourceInstalled(helium, context));
+ }),
+ ),
);
});
@@ -660,44 +667,48 @@ describe("cookieDatabaseCandidatePaths", () => {
const firefox = BROWSER_IMPORT_SOURCES.find((source) => source.id === "firefox")!;
describe("Firefox Snap profiles", () => {
- it.effect("finds Snap profiles with or without profiles.ini and checks their locks", () =>
- run(
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-firefox-snap-" });
- const context = yield* sourcePathContext.pipe(
- Effect.provideService(HostProcessEnvironment, { HOME: home }),
- Effect.provideService(HostProcessPlatform, "linux"),
- );
- const root = `${home}/snap/firefox/common/.mozilla/firefox`;
- const directory = `${root}/abcd.default`;
- yield* fileSystem.makeDirectory(directory, { recursive: true });
- yield* writeFirefoxCookieDatabase(`${directory}/cookies.sqlite`, 2, 1);
- yield* fileSystem.writeFileString(
- `${root}/profiles.ini`,
- "[Profile0]\nName=Personal\nIsRelative=1\nPath=abcd.default\n",
- );
+ it.effect.skipIf(!symlinksSupported)(
+ "finds Snap profiles with or without profiles.ini and checks their locks",
+ () =>
+ run(
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const home = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3code-firefox-snap-",
+ });
+ const context = yield* sourcePathContext.pipe(
+ Effect.provideService(HostProcessEnvironment, { HOME: home }),
+ Effect.provideService(HostProcessPlatform, "linux"),
+ );
+ const root = `${home}/snap/firefox/common/.mozilla/firefox`;
+ const directory = `${root}/abcd.default`;
+ yield* fileSystem.makeDirectory(directory, { recursive: true });
+ yield* writeFirefoxCookieDatabase(`${directory}/cookies.sqlite`, 2, 1);
+ yield* fileSystem.writeFileString(
+ `${root}/profiles.ini`,
+ "[Profile0]\nName=Personal\nIsRelative=1\nPath=abcd.default\n",
+ );
- assert.isTrue(yield* isSourceInstalled(firefox, context));
- assert.deepEqual(yield* listSourceProfiles(firefox, context), [
- { directory, name: "Personal", cookieCount: 2 },
- ]);
- assert.equal(
- yield* resolveCookieDatabase(firefox, context, directory),
- `${directory}/cookies.sqlite`,
- );
- assert.isFalse(yield* isSourceRunning(firefox, context));
- yield* fileSystem.symlink("foreign-host:+4242", `${directory}/lock`);
- assert.isTrue(yield* isSourceRunning(firefox, context));
- yield* fileSystem.remove(`${directory}/lock`);
- assert.isFalse(yield* isSourceRunning(firefox, context));
+ assert.isTrue(yield* isSourceInstalled(firefox, context));
+ assert.deepEqual(yield* listSourceProfiles(firefox, context), [
+ { directory, name: "Personal", cookieCount: 2 },
+ ]);
+ assert.equal(
+ yield* resolveCookieDatabase(firefox, context, directory),
+ `${directory}/cookies.sqlite`,
+ );
+ assert.isFalse(yield* isSourceRunning(firefox, context));
+ yield* fileSystem.symlink("foreign-host:+4242", `${directory}/lock`);
+ assert.isTrue(yield* isSourceRunning(firefox, context));
+ yield* fileSystem.remove(`${directory}/lock`);
+ assert.isFalse(yield* isSourceRunning(firefox, context));
- yield* fileSystem.remove(`${root}/profiles.ini`);
- assert.deepEqual(yield* listSourceProfiles(firefox, context), [
- { directory, name: "abcd.default", cookieCount: 2 },
- ]);
- }),
- ),
+ yield* fileSystem.remove(`${root}/profiles.ini`);
+ assert.deepEqual(yield* listSourceProfiles(firefox, context), [
+ { directory, name: "abcd.default", cookieCount: 2 },
+ ]);
+ }),
+ ),
);
it.effect("keeps matching profile names in native and Snap installs distinct", () =>
@@ -862,7 +873,7 @@ describe("listSourceProfiles Firefox fallback", () => {
});
describe("isSourceRunning for Firefox", () => {
- it.effect("finds the lock inside the profile, not at the root", () =>
+ it.effect.skipIf(!symlinksSupported)("finds the lock inside the profile, not at the root", () =>
run(
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
diff --git a/apps/server/scripts/t3-sqlite-state.test.ts b/apps/server/scripts/t3-sqlite-state.test.ts
index ec236f4a67c..71e592fafbd 100644
--- a/apps/server/scripts/t3-sqlite-state.test.ts
+++ b/apps/server/scripts/t3-sqlite-state.test.ts
@@ -7,6 +7,7 @@ import * as SqlClient from "effect/unstable/sql/SqlClient";
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
import { runSqliteState } from "./t3-sqlite-state.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const createFixtureDatabase = Effect.fn("createSqliteStateFixtureDatabase")(function* (
baseDir: string,
@@ -73,47 +74,49 @@ it.layer(NodeServices.layer)("t3-sqlite-state", (it) => {
}),
);
- it.effect("backs up isolated state before writes and refuses the shared home", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-sqlite-state-exec-" });
- yield* createFixtureDatabase(baseDir);
+ it.effect.skipIf(!symlinksSupported)(
+ "backs up isolated state before writes and refuses the shared home",
+ () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-sqlite-state-exec-" });
+ yield* createFixtureDatabase(baseDir);
- const mutation = yield* runSqliteState({
- operation: "exec",
- baseDir,
- sql: "INSERT INTO fixtures (id, label) VALUES (2, 'seeded')",
- });
- assert.equal(mutation.operation, "exec");
- if (mutation.operation === "exec") {
- assert.equal((yield* fs.stat(mutation.backup)).mode & 0o777, 0o600);
- }
-
- const error = yield* runSqliteState(
- {
+ const mutation = yield* runSqliteState({
operation: "exec",
baseDir,
- sql: "DELETE FROM fixtures",
- },
- { sharedHome: baseDir },
- ).pipe(Effect.flip);
- assert.equal(error._tag, "SqliteStateSharedHomeMutationError");
+ sql: "INSERT INTO fixtures (id, label) VALUES (2, 'seeded')",
+ });
+ assert.equal(mutation.operation, "exec");
+ if (mutation.operation === "exec") {
+ assert.equal((yield* fs.stat(mutation.backup)).mode & 0o777, 0o600);
+ }
- const aliasParent = yield* fs.makeTempDirectoryScoped({
- prefix: "t3-sqlite-state-alias-",
- });
- const aliasBaseDir = path.join(aliasParent, "shared-home-alias");
- yield* fs.symlink(baseDir, aliasBaseDir);
- const aliasError = yield* runSqliteState(
- {
- operation: "exec",
- baseDir: aliasBaseDir,
- sql: "DELETE FROM fixtures",
- },
- { sharedHome: baseDir },
- ).pipe(Effect.flip);
- assert.equal(aliasError._tag, "SqliteStateSharedHomeMutationError");
- }),
+ const error = yield* runSqliteState(
+ {
+ operation: "exec",
+ baseDir,
+ sql: "DELETE FROM fixtures",
+ },
+ { sharedHome: baseDir },
+ ).pipe(Effect.flip);
+ assert.equal(error._tag, "SqliteStateSharedHomeMutationError");
+
+ const aliasParent = yield* fs.makeTempDirectoryScoped({
+ prefix: "t3-sqlite-state-alias-",
+ });
+ const aliasBaseDir = path.join(aliasParent, "shared-home-alias");
+ yield* fs.symlink(baseDir, aliasBaseDir);
+ const aliasError = yield* runSqliteState(
+ {
+ operation: "exec",
+ baseDir: aliasBaseDir,
+ sql: "DELETE FROM fixtures",
+ },
+ { sharedHome: baseDir },
+ ).pipe(Effect.flip);
+ assert.equal(aliasError._tag, "SqliteStateSharedHomeMutationError");
+ }),
);
});
diff --git a/apps/server/src/assets/AssetAccess.test.ts b/apps/server/src/assets/AssetAccess.test.ts
index 251a4761705..aacd37b2b35 100644
--- a/apps/server/src/assets/AssetAccess.test.ts
+++ b/apps/server/src/assets/AssetAccess.test.ts
@@ -24,6 +24,7 @@ import { assetFileResponse } from "../http.ts";
import { ASSET_ROUTE_PREFIX, issueAssetUrl, resolveAsset } from "./AssetAccess.ts";
import * as NativeAppIconResolver from "./NativeAppIconResolver.ts";
import { openMediaFile } from "./MediaFile.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
vi.mock("node:fs/promises", async (importOriginal) => {
const actual = await importOriginal<typeof NodeFSP>();
@@ -108,216 +109,241 @@ describe("AssetAccess", () => {
}).pipe(Effect.provide(testLayer)),
);
- it.effect("rejects non-previewable files, disguised targets, and directories", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-validation-" });
- for (const name of ["report.md", "secret.txt", "secret.%70ng", "secret.png#private.txt"]) {
- const filePath = path.join(root, name);
- yield* fs.writeFileString(filePath, "not media");
- const error = yield* issueAssetUrl({
- resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
+ it.effect.skipIf(!symlinksSupported)(
+ "rejects non-previewable files, disguised targets, and directories",
+ () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-validation-" });
+ for (const name of ["report.md", "secret.txt", "secret.%70ng", "secret.png#private.txt"]) {
+ const filePath = path.join(root, name);
+ yield* fs.writeFileString(filePath, "not media");
+ const error = yield* issueAssetUrl({
+ resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
+ }).pipe(Effect.flip);
+ expect(error).toBeInstanceOf(AssetPreviewTypeValidationError);
+ }
+ const disguisedPath = path.join(root, "disguised.png");
+ yield* fs.symlink(path.join(root, "secret.txt"), disguisedPath);
+ const disguisedError = yield* issueAssetUrl({
+ resource: {
+ _tag: "media-file",
+ threadId: ThreadId.make("thread-1"),
+ path: disguisedPath,
+ },
}).pipe(Effect.flip);
- expect(error).toBeInstanceOf(AssetPreviewTypeValidationError);
- }
- const disguisedPath = path.join(root, "disguised.png");
- yield* fs.symlink(path.join(root, "secret.txt"), disguisedPath);
- const disguisedError = yield* issueAssetUrl({
- resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: disguisedPath },
- }).pipe(Effect.flip);
- expect(disguisedError).toBeInstanceOf(AssetPreviewTypeValidationError);
- const directoryPath = path.join(root, "directory.png");
- yield* fs.makeDirectory(directoryPath);
- const directoryError = yield* issueAssetUrl({
- resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: directoryPath },
- }).pipe(Effect.flip);
- expect(directoryError._tag).toBe("AssetWorkspaceAssetNotFoundError");
- }).pipe(Effect.provide(testLayer)),
- );
-
- it.effect("binds media URLs to the canonical target and rejects symlink substitution", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-symlink-" });
- const filePath = path.join(root, "actual.svg");
- const aliasPath = path.join(root, "alias.png");
- const replacementPath = path.join(root, "other.svg");
- yield* fs.writeFileString(filePath, "<svg/>");
- yield* fs.writeFileString(replacementPath, "<svg>private</svg>");
- yield* fs.symlink(filePath, aliasPath);
- const canonicalFile = yield* fs.realPath(filePath);
- const result = yield* issueAssetUrl({
- resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: aliasPath },
- });
- const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
- const separator = suffix.indexOf("/");
- const token = suffix.slice(0, separator);
- const name = suffix.slice(separator + 1);
- const expected = { kind: "file", path: canonicalFile, mimeType: "image/svg+xml" };
- expect(yield* resolveAsset(token, name)).toMatchObject(expected);
- yield* fs.remove(aliasPath);
- yield* fs.symlink(replacementPath, aliasPath);
- expect(yield* resolveAsset(token, name)).toMatchObject(expected);
- yield* fs.remove(filePath);
- yield* fs.symlink(replacementPath, filePath);
- expect(yield* resolveAsset(token, name)).toBeNull();
- }).pipe(Effect.provide(testLayer)),
+ expect(disguisedError).toBeInstanceOf(AssetPreviewTypeValidationError);
+ const directoryPath = path.join(root, "directory.png");
+ yield* fs.makeDirectory(directoryPath);
+ const directoryError = yield* issueAssetUrl({
+ resource: {
+ _tag: "media-file",
+ threadId: ThreadId.make("thread-1"),
+ path: directoryPath,
+ },
+ }).pipe(Effect.flip);
+ expect(directoryError._tag).toBe("AssetWorkspaceAssetNotFoundError");
+ }).pipe(Effect.provide(testLayer)),
);
- it.effect("keeps full and partial responses bound to the file opened during resolution", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-file-" });
- const filePath = path.join(root, "recording.mp4");
- const savedPath = path.join(root, "saved.mp4");
- const secretPath = path.join(root, "secret.txt");
- yield* fs.writeFileString(filePath, "0123456789");
- yield* fs.writeFileString(secretPath, "private information");
- const result = yield* issueAssetUrl({
- resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
- });
- const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
- const separator = suffix.indexOf("/");
- for (const [range, expected, status] of [
- [undefined, "0123456789", 200],
- ["bytes=2-5", "2345", 206],
- ] as const) {
- const asset = yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1));
- if (!asset) throw new Error("Expected a resolved media file");
-
- yield* fs.rename(filePath, savedPath);
- yield* fs.symlink(secretPath, filePath);
- const response = HttpServerResponse.toWeb(yield* assetFileResponse(asset, range));
- expect(response.status).toBe(status);
- expect(response.headers.get("content-length")).toBe(String(expected.length));
- expect(yield* Effect.promise(() => response.text())).toBe(expected);
+ it.effect.skipIf(!symlinksSupported)(
+ "binds media URLs to the canonical target and rejects symlink substitution",
+ () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-symlink-" });
+ const filePath = path.join(root, "actual.svg");
+ const aliasPath = path.join(root, "alias.png");
+ const replacementPath = path.join(root, "other.svg");
+ yield* fs.writeFileString(filePath, "<svg/>");
+ yield* fs.writeFileString(replacementPath, "<svg>private</svg>");
+ yield* fs.symlink(filePath, aliasPath);
+ const canonicalFile = yield* fs.realPath(filePath);
+ const result = yield* issueAssetUrl({
+ resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: aliasPath },
+ });
+ const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
+ const separator = suffix.indexOf("/");
+ const token = suffix.slice(0, separator);
+ const name = suffix.slice(separator + 1);
+ const expected = { kind: "file", path: canonicalFile, mimeType: "image/svg+xml" };
+ expect(yield* resolveAsset(token, name)).toMatchObject(expected);
+ yield* fs.remove(aliasPath);
+ yield* fs.symlink(replacementPath, aliasPath);
+ expect(yield* resolveAsset(token, name)).toMatchObject(expected);
yield* fs.remove(filePath);
- yield* fs.rename(savedPath, filePath);
- }
- }).pipe(Effect.provide(testLayer)),
+ yield* fs.symlink(replacementPath, filePath);
+ expect(yield* resolveAsset(token, name)).toBeNull();
+ }).pipe(Effect.provide(testLayer)),
);
- it.effect("rejects a symlink swapped in after canonical validation but before open", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-race-" });
- const filePath = path.join(root, "recording.mp4");
- const secretPath = path.join(root, "secret.txt");
- yield* fs.writeFileString(filePath, "video");
- yield* fs.writeFileString(secretPath, "secret");
- const canonicalPath = yield* fs.realPath(filePath);
- const result = yield* issueAssetUrl({
- resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
- });
- const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
- const separator = suffix.indexOf("/");
- const swappingFileSystem = FileSystem.FileSystem.of({
- ...fs,
- stat: Effect.fn(function* (requestedPath) {
- const info = yield* fs.stat(requestedPath);
- if (requestedPath === canonicalPath) {
- yield* fs.remove(filePath);
- yield* fs.symlink(secretPath, filePath);
- }
- return info;
- }),
- });
- expect(
- yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)).pipe(
- Effect.provideService(FileSystem.FileSystem, swappingFileSystem),
- ),
- ).toBeNull();
- }).pipe(Effect.provide(testLayer)),
+ it.effect.skipIf(!symlinksSupported)(
+ "keeps full and partial responses bound to the file opened during resolution",
+ () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-file-" });
+ const filePath = path.join(root, "recording.mp4");
+ const savedPath = path.join(root, "saved.mp4");
+ const secretPath = path.join(root, "secret.txt");
+ yield* fs.writeFileString(filePath, "0123456789");
+ yield* fs.writeFileString(secretPath, "private information");
+ const result = yield* issueAssetUrl({
+ resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
+ });
+ const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
+ const separator = suffix.indexOf("/");
+ for (const [range, expected, status] of [
+ [undefined, "0123456789", 200],
+ ["bytes=2-5", "2345", 206],
+ ] as const) {
+ const asset = yield* resolveAsset(
+ suffix.slice(0, separator),
+ suffix.slice(separator + 1),
+ );
+ if (!asset) throw new Error("Expected a resolved media file");
+
+ yield* fs.rename(filePath, savedPath);
+ yield* fs.symlink(secretPath, filePath);
+ const response = HttpServerResponse.toWeb(yield* assetFileResponse(asset, range));
+ expect(response.status).toBe(status);
+ expect(response.headers.get("content-length")).toBe(String(expected.length));
+ expect(yield* Effect.promise(() => response.text())).toBe(expected);
+ yield* fs.remove(filePath);
+ yield* fs.rename(savedPath, filePath);
+ }
+ }).pipe(Effect.provide(testLayer)),
);
- it.effect("closes a descriptor rejected when its path changes during open", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-rejected-" });
- const filePath = path.join(root, "recording.mp4");
- const secretPath = path.join(root, "secret.txt");
- yield* fs.writeFileString(filePath, "video");
- yield* fs.writeFileString(secretPath, "secret");
- const canonicalPath = yield* fs.realPath(filePath);
- const originalOpen = (yield* Effect.promise(() =>
- vi.importActual<typeof NodeFSP>("node:fs/promises"),
- )).open;
- let opened: NodeFSP.FileHandle | undefined;
- const openSpy = vi.mocked(NodeFSP.open).mockImplementation(async (target, flags, mode) => {
- const handle = await originalOpen(target, flags, mode);
- if (target === canonicalPath) {
- opened = handle;
- await NodeFSP.unlink(filePath);
- await NodeFSP.symlink(secretPath, filePath);
- }
- return handle;
- });
- yield* Effect.addFinalizer(() => Effect.sync(() => openSpy.mockImplementation(originalOpen)));
- expect(yield* openMediaFile(canonicalPath)).toBeNull();
- expect(opened).toBeDefined();
- expect(opened?.fd).toBe(-1);
- }).pipe(Effect.provide(testLayer)),
+ it.effect.skipIf(!symlinksSupported)(
+ "rejects a symlink swapped in after canonical validation but before open",
+ () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-race-" });
+ const filePath = path.join(root, "recording.mp4");
+ const secretPath = path.join(root, "secret.txt");
+ yield* fs.writeFileString(filePath, "video");
+ yield* fs.writeFileString(secretPath, "secret");
+ const canonicalPath = yield* fs.realPath(filePath);
+ const result = yield* issueAssetUrl({
+ resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
+ });
+ const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
+ const separator = suffix.indexOf("/");
+ const swappingFileSystem = FileSystem.FileSystem.of({
+ ...fs,
+ stat: Effect.fn(function* (requestedPath) {
+ const info = yield* fs.stat(requestedPath);
+ if (requestedPath === canonicalPath) {
+ yield* fs.remove(filePath);
+ yield* fs.symlink(secretPath, filePath);
+ }
+ return info;
+ }),
+ });
+ expect(
+ yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)).pipe(
+ Effect.provideService(FileSystem.FileSystem, swappingFileSystem),
+ ),
+ ).toBeNull();
+ }).pipe(Effect.provide(testLayer)),
);
- it.effect("rejects an ancestor symlink race even when canonical path rechecks would pass", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-parent-race-" });
- const publicDirectory = path.join(root, "public");
- const privateDirectory = path.join(root, "private");
- yield* fs.makeDirectory(publicDirectory);
- yield* fs.makeDirectory(privateDirectory);
- const filePath = path.join(publicDirectory, "recording.mp4");
- yield* fs.writeFileString(filePath, "public video");
- yield* fs.writeFileString(path.join(privateDirectory, "recording.mp4"), "private video");
- const canonicalPath = yield* fs.realPath(filePath);
- const result = yield* issueAssetUrl({
- resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
- });
- const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
- const separator = suffix.indexOf("/");
- const native = yield* Effect.promise(() =>
- vi.importActual<typeof NodeFSP>("node:fs/promises"),
- );
- const savedDirectory = path.join(root, "saved");
- const realpathSpy = vi.mocked(NodeFSP.realpath).mockImplementationOnce(async () => {
- // A pathname-only guard can see the original parents during realpath,
- // but the private file during both lstat calls and open.
- await native.unlink(publicDirectory);
- await native.rename(savedDirectory, publicDirectory);
- const canonical = await native.realpath(canonicalPath);
- await native.rename(publicDirectory, savedDirectory);
- await native.symlink(privateDirectory, publicDirectory, "junction");
- return canonical;
- });
- yield* Effect.addFinalizer(() =>
- Effect.sync(() => realpathSpy.mockReset().mockImplementation(native.realpath)),
- );
- const swappingFileSystem = FileSystem.FileSystem.of({
- ...fs,
- realPath: Effect.fn(function* (requestedPath) {
- const canonical = yield* fs.realPath(requestedPath);
- if (requestedPath === canonicalPath) {
- yield* fs.rename(publicDirectory, savedDirectory);
- yield* Effect.promise(() =>
- NodeFSP.symlink(privateDirectory, publicDirectory, "junction"),
- );
+ it.effect.skipIf(!symlinksSupported)(
+ "closes a descriptor rejected when its path changes during open",
+ () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-open-rejected-" });
+ const filePath = path.join(root, "recording.mp4");
+ const secretPath = path.join(root, "secret.txt");
+ yield* fs.writeFileString(filePath, "video");
+ yield* fs.writeFileString(secretPath, "secret");
+ const canonicalPath = yield* fs.realPath(filePath);
+ const originalOpen = (yield* Effect.promise(() =>
+ vi.importActual<typeof NodeFSP>("node:fs/promises"),
+ )).open;
+ let opened: NodeFSP.FileHandle | undefined;
+ const openSpy = vi.mocked(NodeFSP.open).mockImplementation(async (target, flags, mode) => {
+ const handle = await originalOpen(target, flags, mode);
+ if (target === canonicalPath) {
+ opened = handle;
+ await NodeFSP.unlink(filePath);
+ await NodeFSP.symlink(secretPath, filePath);
}
+ return handle;
+ });
+ yield* Effect.addFinalizer(() =>
+ Effect.sync(() => openSpy.mockImplementation(originalOpen)),
+ );
+ expect(yield* openMediaFile(canonicalPath)).toBeNull();
+ expect(opened).toBeDefined();
+ expect(opened?.fd).toBe(-1);
+ }).pipe(Effect.provide(testLayer)),
+ );
+
+ it.effect.skipIf(!symlinksSupported)(
+ "rejects an ancestor symlink race even when canonical path rechecks would pass",
+ () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-parent-race-" });
+ const publicDirectory = path.join(root, "public");
+ const privateDirectory = path.join(root, "private");
+ yield* fs.makeDirectory(publicDirectory);
+ yield* fs.makeDirectory(privateDirectory);
+ const filePath = path.join(publicDirectory, "recording.mp4");
+ yield* fs.writeFileString(filePath, "public video");
+ yield* fs.writeFileString(path.join(privateDirectory, "recording.mp4"), "private video");
+ const canonicalPath = yield* fs.realPath(filePath);
+ const result = yield* issueAssetUrl({
+ resource: { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: filePath },
+ });
+ const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
+ const separator = suffix.indexOf("/");
+ const native = yield* Effect.promise(() =>
+ vi.importActual<typeof NodeFSP>("node:fs/promises"),
+ );
+ const savedDirectory = path.join(root, "saved");
+ const realpathSpy = vi.mocked(NodeFSP.realpath).mockImplementationOnce(async () => {
+ // A pathname-only guard can see the original parents during realpath,
+ // but the private file during both lstat calls and open.
+ await native.unlink(publicDirectory);
+ await native.rename(savedDirectory, publicDirectory);
+ const canonical = await native.realpath(canonicalPath);
+ await native.rename(publicDirectory, savedDirectory);
+ await native.symlink(privateDirectory, publicDirectory, "junction");
return canonical;
- }),
- });
- expect(
- yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)).pipe(
- Effect.provideService(FileSystem.FileSystem, swappingFileSystem),
- ),
- ).toBeNull();
- }).pipe(Effect.provide(testLayer)),
+ });
+ yield* Effect.addFinalizer(() =>
+ Effect.sync(() => realpathSpy.mockReset().mockImplementation(native.realpath)),
+ );
+ const swappingFileSystem = FileSystem.FileSystem.of({
+ ...fs,
+ realPath: Effect.fn(function* (requestedPath) {
+ const canonical = yield* fs.realPath(requestedPath);
+ if (requestedPath === canonicalPath) {
+ yield* fs.rename(publicDirectory, savedDirectory);
+ yield* Effect.promise(() =>
+ NodeFSP.symlink(privateDirectory, publicDirectory, "junction"),
+ );
+ }
+ return canonical;
+ }),
+ });
+ expect(
+ yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)).pipe(
+ Effect.provideService(FileSystem.FileSystem, swappingFileSystem),
+ ),
+ ).toBeNull();
+ }).pipe(Effect.provide(testLayer)),
);
it.effect("keeps in-place edits readable but requires a new URL after atomic replacement", () =>
diff --git a/apps/server/src/cli/theme.test.ts b/apps/server/src/cli/theme.test.ts
index d3dd69b9472..33606565ffc 100644
--- a/apps/server/src/cli/theme.test.ts
+++ b/apps/server/src/cli/theme.test.ts
@@ -13,6 +13,7 @@ import * as TestConsole from "effect/testing/TestConsole";
import { Command } from "effect/unstable/cli";
import { cli } from "../bin.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const runCli = (args: ReadonlyArray<string>) =>
Command.runWith(cli, { version: "0.0.0" })(args).pipe(
@@ -185,27 +186,29 @@ describe("t3 theme", () => {
// A symlink is a normal way to hand this command a theme -- desktop hooks
// symlink the current palette -- so the source is resolved, not refused.
- it.effect("publishes a theme file through a symlinked source path", () =>
- Effect.gen(function* () {
- const baseDir = makeBaseDir();
- const realFile = NodePath.join(baseDir, "real-nightfall.json");
- NodeFS.writeFileSync(realFile, NIGHTFALL_THEME_JSON);
- const linkPath = NodePath.join(baseDir, "nightfall.json");
- NodeFS.symlinkSync(realFile, linkPath);
-
- yield* runCli(["theme", "set", linkPath, "--base-dir", baseDir]);
-
- assert.equal(
- NodeFS.existsSync(NodePath.join(baseDir, "userdata", "themes", "nightfall.json")),
- true,
- );
- assert.equal(readSettings(baseDir).defaultTheme, "nightfall");
- }),
+ it.effect.skipIf(!symlinksSupported)(
+ "publishes a theme file through a symlinked source path",
+ () =>
+ Effect.gen(function* () {
+ const baseDir = makeBaseDir();
+ const realFile = NodePath.join(baseDir, "real-nightfall.json");
+ NodeFS.writeFileSync(realFile, NIGHTFALL_THEME_JSON);
+ const linkPath = NodePath.join(baseDir, "nightfall.json");
+ NodeFS.symlinkSync(realFile, linkPath);
+
+ yield* runCli(["theme", "set", linkPath, "--base-dir", baseDir]);
+
+ assert.equal(
+ NodeFS.existsSync(NodePath.join(baseDir, "userdata", "themes", "nightfall.json")),
+ true,
+ );
+ assert.equal(readSettings(baseDir).defaultTheme, "nightfall");
+ }),
);
// The staging entry is created fresh with O_EXCL, so a symlink planted at
// its predictable name is cleared, never followed and written through.
- it.effect("never writes through a symlink at the staging path", () =>
+ it.effect.skipIf(!symlinksSupported)("never writes through a symlink at the staging path", () =>
Effect.gen(function* () {
const baseDir = makeBaseDir();
const themesDir = NodePath.join(baseDir, "userdata", "themes");
@@ -226,28 +229,30 @@ describe("t3 theme", () => {
// Rollback moves the previous directory entry aside and back, so even an
// entry the watcher would never publish -- here a symlink -- comes back
// exactly as it was when the set fails.
- it.effect("restores a non-theme destination entry when the set fails", () =>
- Effect.gen(function* () {
- const baseDir = makeBaseDir();
- writeSettings(baseDir, {});
- const userdataDir = NodePath.dirname(settingsPathFor(baseDir));
- const themesDir = NodePath.join(userdataDir, "themes");
- NodeFS.mkdirSync(themesDir, { recursive: true });
- const outside = NodePath.join(baseDir, "outside.json");
- NodeFS.writeFileSync(outside, NIGHTFALL_THEME_JSON);
- const destination = NodePath.join(themesDir, "nightfall.json");
- NodeFS.symlinkSync(outside, destination);
- const themeFile = NodePath.join(baseDir, "nightfall.json");
- NodeFS.writeFileSync(themeFile, NIGHTFALL_THEME_JSON);
-
- NodeFS.chmodSync(userdataDir, 0o555);
- try {
- yield* runCli(["theme", "set", themeFile, "--base-dir", baseDir]).pipe(Effect.flip);
- assert.equal(NodeFS.lstatSync(destination).isSymbolicLink(), true);
- } finally {
- NodeFS.chmodSync(userdataDir, 0o755);
- }
- }),
+ it.effect.skipIf(!symlinksSupported)(
+ "restores a non-theme destination entry when the set fails",
+ () =>
+ Effect.gen(function* () {
+ const baseDir = makeBaseDir();
+ writeSettings(baseDir, {});
+ const userdataDir = NodePath.dirname(settingsPathFor(baseDir));
+ const themesDir = NodePath.join(userdataDir, "themes");
+ NodeFS.mkdirSync(themesDir, { recursive: true });
+ const outside = NodePath.join(baseDir, "outside.json");
+ NodeFS.writeFileSync(outside, NIGHTFALL_THEME_JSON);
+ const destination = NodePath.join(themesDir, "nightfall.json");
+ NodeFS.symlinkSync(outside, destination);
+ const themeFile = NodePath.join(baseDir, "nightfall.json");
+ NodeFS.writeFileSync(themeFile, NIGHTFALL_THEME_JSON);
+
+ NodeFS.chmodSync(userdataDir, 0o555);
+ try {
+ yield* runCli(["theme", "set", themeFile, "--base-dir", baseDir]).pipe(Effect.flip);
+ assert.equal(NodeFS.lstatSync(destination).isSymbolicLink(), true);
+ } finally {
+ NodeFS.chmodSync(userdataDir, 0o755);
+ }
+ }),
);
it.effect("restores the previous theme when a re-publish fails to set", () =>
diff --git a/apps/server/src/entrypoint.test.ts b/apps/server/src/entrypoint.test.ts
index 56f2c119764..bf8247fd429 100644
--- a/apps/server/src/entrypoint.test.ts
+++ b/apps/server/src/entrypoint.test.ts
@@ -7,6 +7,7 @@ import * as NodeURL from "node:url";
import { describe, expect, it } from "vite-plus/test";
import { isEntrypoint } from "./entrypoint.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const makeTempDir = () => NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-entrypoint-test-"));
@@ -44,21 +45,24 @@ describe("isEntrypoint", () => {
).toBe(true);
});
- it("matches through a symlinked entrypoint, as npm and npx install it", () => {
- const dir = makeTempDir();
- const real = NodePath.join(dir, "bin.mjs");
- const link = NodePath.join(dir, "t3");
- NodeFS.writeFileSync(real, "");
- NodeFS.symlinkSync(real, link);
+ it.skipIf(!symlinksSupported)(
+ "matches through a symlinked entrypoint, as npm and npx install it",
+ () => {
+ const dir = makeTempDir();
+ const real = NodePath.join(dir, "bin.mjs");
+ const link = NodePath.join(dir, "t3");
+ NodeFS.writeFileSync(real, "");
+ NodeFS.symlinkSync(real, link);
- expect(
- isEntrypoint({
- moduleUrl: NodeURL.pathToFileURL(real).href,
- entryPath: link,
- runtimeMain: undefined,
- }),
- ).toBe(true);
- });
+ expect(
+ isEntrypoint({
+ moduleUrl: NodeURL.pathToFileURL(real).href,
+ entryPath: link,
+ runtimeMain: undefined,
+ }),
+ ).toBe(true);
+ },
+ );
it("stays false for an imported module that is not the entrypoint", () => {
// This is what keeps `bin.test.ts` from launching the CLI on import.
diff --git a/apps/server/src/environmentTheme.test.ts b/apps/server/src/environmentTheme.test.ts
index 0d50e020098..3c3f650b4c3 100644
--- a/apps/server/src/environmentTheme.test.ts
+++ b/apps/server/src/environmentTheme.test.ts
@@ -13,6 +13,7 @@ import * as Stream from "effect/Stream";
import * as ServerConfig from "./config.ts";
import * as EnvironmentTheme from "./environmentTheme.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const encodeThemeFile = Schema.encodeSync(Schema.fromJsonString(EnvironmentThemeFile));
@@ -188,7 +189,7 @@ it.layer(NodeServices.layer)("environment theme", (it) => {
// A symlinked themes directory stays usable, but a symlinked file inside it
// must not publish whatever it points at.
- it.effect("ignores a symlinked theme file", () =>
+ it.effect.skipIf(!symlinksSupported)("ignores a symlinked theme file", () =>
withEnvironmentThemes(
{},
Effect.gen(function* () {
diff --git a/apps/server/src/orchestration/workflowScriptQuery.test.ts b/apps/server/src/orchestration/workflowScriptQuery.test.ts
index 47fe888de70..311b8942769 100644
--- a/apps/server/src/orchestration/workflowScriptQuery.test.ts
+++ b/apps/server/src/orchestration/workflowScriptQuery.test.ts
@@ -5,6 +5,7 @@ import * as NodePath from "node:path";
import { it as effectIt } from "@effect/vitest";
import * as Effect from "effect/Effect";
import { afterAll, assert, describe } from "vite-plus/test";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
import { readWorkflowScript } from "./workflowScriptQuery.ts";
const root = NodePath.join(NodeOS.homedir(), ".claude", "projects", "__wf_script_test__");
@@ -14,19 +15,15 @@ NodeFS.writeFileSync(scriptPath, "export const meta = {};\n");
const outside = NodePath.join(NodeOS.tmpdir(), "wf-outside.js");
NodeFS.writeFileSync(outside, "evil\n");
const link = NodePath.join(root, "sneaky.js");
-try {
+// Planted only where the host allows it; the escape test is skipped
+// otherwise rather than passing vacuously on "not-found".
+if (symlinksSupported) {
+ NodeFS.rmSync(link, { force: true });
NodeFS.symlinkSync(outside, link);
-} catch (error) {
- // Tolerate only "already exists" from a prior run — any other failure
- // (EPERM etc.) must fail setup, or the escape test below would pass
- // vacuously on "not-found" without testing containment.
- if ((error as NodeJS.ErrnoException).code !== "EEXIST") {
- throw error;
+ if (!NodeFS.lstatSync(link).isSymbolicLink()) {
+ throw new Error("test setup: sneaky.js must be a symlink");
}
}
-if (!NodeFS.lstatSync(link).isSymbolicLink()) {
- throw new Error("test setup: sneaky.js must be a symlink");
-}
afterAll(() => {
NodeFS.rmSync(root, { recursive: true, force: true });
@@ -53,23 +50,25 @@ describe("readWorkflowScript containment", () => {
}),
);
- effectIt.effect("rejects paths outside the root and symlink escapes", () =>
- Effect.gen(function* () {
- const escaped = yield* Effect.exit(readWorkflowScript({ scriptPath: outside }));
- assert.equal(escaped._tag, "Failure");
- // A symlink INSIDE the root pointing outside must fail specifically on
- // realpath re-containment — a "not-found" would mean the link was
- // never exercised and the assertion proves nothing.
- const sneaky = yield* Effect.exit(
- readWorkflowScript({ scriptPath: link }).pipe(
- Effect.flip,
- Effect.map((error) => error.reason),
- ),
- );
- assert.equal(sneaky._tag, "Success");
- if (sneaky._tag === "Success") {
- assert.equal(sneaky.value, "outside-root");
- }
- }),
+ effectIt.effect.skipIf(!symlinksSupported)(
+ "rejects paths outside the root and symlink escapes",
+ () =>
+ Effect.gen(function* () {
+ const escaped = yield* Effect.exit(readWorkflowScript({ scriptPath: outside }));
+ assert.equal(escaped._tag, "Failure");
+ // A symlink INSIDE the root pointing outside must fail specifically on
+ // realpath re-containment — a "not-found" would mean the link was
+ // never exercised and the assertion proves nothing.
+ const sneaky = yield* Effect.exit(
+ readWorkflowScript({ scriptPath: link }).pipe(
+ Effect.flip,
+ Effect.map((error) => error.reason),
+ ),
+ );
+ assert.equal(sneaky._tag, "Success");
+ if (sneaky._tag === "Success") {
+ assert.equal(sneaky.value, "outside-root");
+ }
+ }),
);
});
diff --git a/apps/server/src/provider/Drivers/AntigravitySkills.test.ts b/apps/server/src/provider/Drivers/AntigravitySkills.test.ts
index c5e1faacf23..bb3381216d7 100644
--- a/apps/server/src/provider/Drivers/AntigravitySkills.test.ts
+++ b/apps/server/src/provider/Drivers/AntigravitySkills.test.ts
@@ -5,6 +5,7 @@ import * as FileSystem from "effect/FileSystem";
import * as Path from "effect/Path";
import { discoverAntigravitySkills } from "./AntigravitySkills.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const writeSkill = Effect.fn("writeSkill")(function* (directory: string, contents: string) {
const fileSystem = yield* FileSystem.FileSystem;
@@ -239,27 +240,29 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => {
}),
);
- it.effect("follows directory symlinks used to install shared skills", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const input = yield* makeWorkspace();
- const sourceDirectory = path.join(input.profileDirectory, "shared-review");
- yield* writeSkill(sourceDirectory, "---\nname: review\n---\n");
- const root = path.join(input.cwd, ".agents", "skills");
- const linkedDirectory = path.join(root, "review");
- yield* fileSystem.makeDirectory(root, { recursive: true });
- yield* fileSystem.symlink(sourceDirectory, linkedDirectory);
+ it.effect.skipIf(!symlinksSupported)(
+ "follows directory symlinks used to install shared skills",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const input = yield* makeWorkspace();
+ const sourceDirectory = path.join(input.profileDirectory, "shared-review");
+ yield* writeSkill(sourceDirectory, "---\nname: review\n---\n");
+ const root = path.join(input.cwd, ".agents", "skills");
+ const linkedDirectory = path.join(root, "review");
+ yield* fileSystem.makeDirectory(root, { recursive: true });
+ yield* fileSystem.symlink(sourceDirectory, linkedDirectory);
- assert.deepEqual(yield* discoverAntigravitySkills(input), [
- {
- name: "review",
- path: path.join(linkedDirectory, "SKILL.md"),
- scope: "project",
- enabled: true,
- },
- ]);
- }),
+ assert.deepEqual(yield* discoverAntigravitySkills(input), [
+ {
+ name: "review",
+ path: path.join(linkedDirectory, "SKILL.md"),
+ scope: "project",
+ enabled: true,
+ },
+ ]);
+ }),
);
it.effect("rejects an oversized skill instead of returning an incomplete catalog", () =>
diff --git a/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts b/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts
index 03c717abb14..2c78ffd1866 100644
--- a/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts
+++ b/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts
@@ -13,6 +13,7 @@ import {
materializeCodexShadowHome,
resolveCodexHomeLayout,
} from "./CodexHomeLayout.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const decodeCodexSettingsValue = Schema.decodeSync(CodexSettings);
const decodeCodexSettings = (input: {
@@ -84,130 +85,139 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
});
describe("materializeCodexShadowHome", () => {
- it.effect("materializes a shadow home with shared state links and private auth", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const sharedHome = yield* makeTempDir("t3code-codex-shared-");
- const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
- const shadowHome = path.join(shadowRoot, "shadow");
-
- yield* fileSystem.makeDirectory(path.join(sharedHome, "sessions"));
- yield* writeTextFile(path.join(sharedHome, "config.toml"), 'model = "gpt-5-codex"\n');
- yield* writeTextFile(path.join(sharedHome, "models_cache.json"), '{"models":["shared"]}\n');
- yield* writeTextFile(path.join(sharedHome, "auth.json"), '{"shared":true}\n');
- yield* fileSystem.makeDirectory(shadowHome, { recursive: true });
- yield* writeTextFile(path.join(shadowHome, "auth.json"), '{"shadow":true}\n');
- yield* fileSystem.symlink(
- path.join(sharedHome, "models_cache.json"),
- path.join(shadowHome, "models_cache.json"),
- );
-
- const layout = yield* resolveCodexHomeLayout(
- decodeCodexSettings({
- homePath: sharedHome,
- shadowHomePath: shadowHome,
- }),
- );
-
- yield* materializeCodexShadowHome(layout);
-
- const sessionsTarget = yield* fileSystem.readLink(path.join(shadowHome, "sessions"));
- const configTarget = yield* fileSystem.readLink(path.join(shadowHome, "config.toml"));
- const mcpOauthLocksTarget = yield* fileSystem.readLink(
- path.join(shadowHome, "mcp-oauth-locks"),
- );
- const modelsCacheExists = yield* fileSystem.exists(
- path.join(shadowHome, "models_cache.json"),
- );
- const authLinkResult = yield* fileSystem
- .readLink(path.join(shadowHome, "auth.json"))
- .pipe(Effect.result);
- const authContents = yield* fileSystem.readFileString(path.join(shadowHome, "auth.json"));
-
- expect(sessionsTarget).toBe(path.join(sharedHome, "sessions"));
- expect(configTarget).toBe(path.join(sharedHome, "config.toml"));
- expect(mcpOauthLocksTarget).toBe(path.join(sharedHome, "mcp-oauth-locks"));
- expect(modelsCacheExists).toBe(false);
- expect(authLinkResult._tag).toBe("Failure");
- expect(authContents).toContain("shadow");
- }),
+ it.effect.skipIf(!symlinksSupported)(
+ "materializes a shadow home with shared state links and private auth",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const sharedHome = yield* makeTempDir("t3code-codex-shared-");
+ const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
+ const shadowHome = path.join(shadowRoot, "shadow");
+
+ yield* fileSystem.makeDirectory(path.join(sharedHome, "sessions"));
+ yield* writeTextFile(path.join(sharedHome, "config.toml"), 'model = "gpt-5-codex"\n');
+ yield* writeTextFile(
+ path.join(sharedHome, "models_cache.json"),
+ '{"models":["shared"]}\n',
+ );
+ yield* writeTextFile(path.join(sharedHome, "auth.json"), '{"shared":true}\n');
+ yield* fileSystem.makeDirectory(shadowHome, { recursive: true });
+ yield* writeTextFile(path.join(shadowHome, "auth.json"), '{"shadow":true}\n');
+ yield* fileSystem.symlink(
+ path.join(sharedHome, "models_cache.json"),
+ path.join(shadowHome, "models_cache.json"),
+ );
+
+ const layout = yield* resolveCodexHomeLayout(
+ decodeCodexSettings({
+ homePath: sharedHome,
+ shadowHomePath: shadowHome,
+ }),
+ );
+
+ yield* materializeCodexShadowHome(layout);
+
+ const sessionsTarget = yield* fileSystem.readLink(path.join(shadowHome, "sessions"));
+ const configTarget = yield* fileSystem.readLink(path.join(shadowHome, "config.toml"));
+ const mcpOauthLocksTarget = yield* fileSystem.readLink(
+ path.join(shadowHome, "mcp-oauth-locks"),
+ );
+ const modelsCacheExists = yield* fileSystem.exists(
+ path.join(shadowHome, "models_cache.json"),
+ );
+ const authLinkResult = yield* fileSystem
+ .readLink(path.join(shadowHome, "auth.json"))
+ .pipe(Effect.result);
+ const authContents = yield* fileSystem.readFileString(path.join(shadowHome, "auth.json"));
+
+ expect(sessionsTarget).toBe(path.join(sharedHome, "sessions"));
+ expect(configTarget).toBe(path.join(sharedHome, "config.toml"));
+ expect(mcpOauthLocksTarget).toBe(path.join(sharedHome, "mcp-oauth-locks"));
+ expect(modelsCacheExists).toBe(false);
+ expect(authLinkResult._tag).toBe("Failure");
+ expect(authContents).toContain("shadow");
+ }),
);
- it.effect("replaces Codex-created local MCP OAuth locks with the shared lock directory", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const sharedHome = yield* makeTempDir("t3code-codex-shared-");
- const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
- const shadowHome = path.join(shadowRoot, "shadow");
- const sharedLocks = path.join(sharedHome, "mcp-oauth-locks");
- const shadowLocks = path.join(shadowHome, "mcp-oauth-locks");
-
- yield* writeTextFile(path.join(sharedLocks, "file-store.lock"), "");
- yield* writeTextFile(path.join(shadowLocks, "file-store.lock"), "");
-
- const layout = yield* resolveCodexHomeLayout(
- decodeCodexSettings({
- homePath: sharedHome,
- shadowHomePath: shadowHome,
- }),
- );
-
- yield* materializeCodexShadowHome(layout);
-
- const locksTarget = yield* fileSystem.readLink(shadowLocks);
- const sharedLockExists = yield* fileSystem.exists(
- path.join(sharedLocks, "file-store.lock"),
- );
-
- expect(locksTarget).toBe(sharedLocks);
- expect(sharedLockExists).toBe(true);
- }),
+ it.effect.skipIf(!symlinksSupported)(
+ "replaces Codex-created local MCP OAuth locks with the shared lock directory",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const sharedHome = yield* makeTempDir("t3code-codex-shared-");
+ const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
+ const shadowHome = path.join(shadowRoot, "shadow");
+ const sharedLocks = path.join(sharedHome, "mcp-oauth-locks");
+ const shadowLocks = path.join(shadowHome, "mcp-oauth-locks");
+
+ yield* writeTextFile(path.join(sharedLocks, "file-store.lock"), "");
+ yield* writeTextFile(path.join(shadowLocks, "file-store.lock"), "");
+
+ const layout = yield* resolveCodexHomeLayout(
+ decodeCodexSettings({
+ homePath: sharedHome,
+ shadowHomePath: shadowHome,
+ }),
+ );
+
+ yield* materializeCodexShadowHome(layout);
+
+ const locksTarget = yield* fileSystem.readLink(shadowLocks);
+ const sharedLockExists = yield* fileSystem.exists(
+ path.join(sharedLocks, "file-store.lock"),
+ );
+
+ expect(locksTarget).toBe(sharedLocks);
+ expect(sharedLockExists).toBe(true);
+ }),
);
- it.effect("accepts Codex-created shadow-local runtime directories", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const sharedHome = yield* makeTempDir("t3code-codex-shared-");
- const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
- const shadowHome = path.join(shadowRoot, "shadow");
-
- yield* fileSystem.makeDirectory(path.join(sharedHome, "log"));
- yield* fileSystem.makeDirectory(path.join(sharedHome, "memories"));
- yield* fileSystem.makeDirectory(path.join(sharedHome, "tmp"));
- yield* writeTextFile(path.join(sharedHome, "config.toml"), 'model = "gpt-5-codex"\n');
- yield* writeTextFile(path.join(shadowHome, "auth.json"), '{"shadow":true}\n');
- yield* fileSystem.makeDirectory(path.join(shadowHome, "log"), { recursive: true });
- yield* fileSystem.makeDirectory(path.join(shadowHome, "memories"), { recursive: true });
- yield* fileSystem.makeDirectory(path.join(shadowHome, "tmp"), { recursive: true });
-
- const layout = yield* resolveCodexHomeLayout(
- decodeCodexSettings({
- homePath: sharedHome,
- shadowHomePath: shadowHome,
- }),
- );
-
- yield* materializeCodexShadowHome(layout);
-
- const configTarget = yield* fileSystem.readLink(path.join(shadowHome, "config.toml"));
- const logLinkResult = yield* fileSystem
- .readLink(path.join(shadowHome, "log"))
- .pipe(Effect.result);
- const memoriesLinkResult = yield* fileSystem
- .readLink(path.join(shadowHome, "memories"))
- .pipe(Effect.result);
- const tmpLinkResult = yield* fileSystem
- .readLink(path.join(shadowHome, "tmp"))
- .pipe(Effect.result);
-
- expect(configTarget).toBe(path.join(sharedHome, "config.toml"));
- expect(logLinkResult._tag).toBe("Failure");
- expect(memoriesLinkResult._tag).toBe("Failure");
- expect(tmpLinkResult._tag).toBe("Failure");
- }),
+ it.effect.skipIf(!symlinksSupported)(
+ "accepts Codex-created shadow-local runtime directories",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const sharedHome = yield* makeTempDir("t3code-codex-shared-");
+ const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
+ const shadowHome = path.join(shadowRoot, "shadow");
+
+ yield* fileSystem.makeDirectory(path.join(sharedHome, "log"));
+ yield* fileSystem.makeDirectory(path.join(sharedHome, "memories"));
+ yield* fileSystem.makeDirectory(path.join(sharedHome, "tmp"));
+ yield* writeTextFile(path.join(sharedHome, "config.toml"), 'model = "gpt-5-codex"\n');
+ yield* writeTextFile(path.join(shadowHome, "auth.json"), '{"shadow":true}\n');
+ yield* fileSystem.makeDirectory(path.join(shadowHome, "log"), { recursive: true });
+ yield* fileSystem.makeDirectory(path.join(shadowHome, "memories"), { recursive: true });
+ yield* fileSystem.makeDirectory(path.join(shadowHome, "tmp"), { recursive: true });
+
+ const layout = yield* resolveCodexHomeLayout(
+ decodeCodexSettings({
+ homePath: sharedHome,
+ shadowHomePath: shadowHome,
+ }),
+ );
+
+ yield* materializeCodexShadowHome(layout);
+
+ const configTarget = yield* fileSystem.readLink(path.join(shadowHome, "config.toml"));
+ const logLinkResult = yield* fileSystem
+ .readLink(path.join(shadowHome, "log"))
+ .pipe(Effect.result);
+ const memoriesLinkResult = yield* fileSystem
+ .readLink(path.join(shadowHome, "memories"))
+ .pipe(Effect.result);
+ const tmpLinkResult = yield* fileSystem
+ .readLink(path.join(shadowHome, "tmp"))
+ .pipe(Effect.result);
+
+ expect(configTarget).toBe(path.join(sharedHome, "config.toml"));
+ expect(logLinkResult._tag).toBe("Failure");
+ expect(memoriesLinkResult._tag).toBe("Failure");
+ expect(tmpLinkResult._tag).toBe("Failure");
+ }),
);
it.effect("rejects shadow homes that point at the shared home", () =>
@@ -233,36 +243,38 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
}),
);
- it.effect("rejects shared entries that already exist in the shadow home as real files", () =>
- Effect.gen(function* () {
- const path = yield* Path.Path;
- const sharedHome = yield* makeTempDir("t3code-codex-shared-");
- const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
- const shadowHome = path.join(shadowRoot, "shadow");
- yield* writeTextFile(path.join(sharedHome, "config.toml"), 'model = "gpt-5-codex"\n');
- yield* writeTextFile(path.join(shadowHome, "config.toml"), 'model = "local"\n');
-
- const layout = yield* resolveCodexHomeLayout(
- decodeCodexSettings({
- homePath: sharedHome,
- shadowHomePath: shadowHome,
- }),
- );
-
- const error = yield* materializeCodexShadowHome(layout).pipe(Effect.flip);
-
- expect(error).toBeInstanceOf(CodexShadowHomeEntryConflictError);
- expect(error).toMatchObject({
- sharedHomePath: sharedHome,
- effectiveHomePath: shadowHome,
- entryName: "config.toml",
- linkPath: path.join(shadowHome, "config.toml"),
- targetPath: path.join(sharedHome, "config.toml"),
- });
- expect(error.message).toBe(
- `Cannot create Codex shadow home entry 'config.toml' because '${path.join(shadowHome, "config.toml")}' already exists and is not a symlink.`,
- );
- }),
+ it.effect.skipIf(!symlinksSupported)(
+ "rejects shared entries that already exist in the shadow home as real files",
+ () =>
+ Effect.gen(function* () {
+ const path = yield* Path.Path;
+ const sharedHome = yield* makeTempDir("t3code-codex-shared-");
+ const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
+ const shadowHome = path.join(shadowRoot, "shadow");
+ yield* writeTextFile(path.join(sharedHome, "config.toml"), 'model = "gpt-5-codex"\n');
+ yield* writeTextFile(path.join(shadowHome, "config.toml"), 'model = "local"\n');
+
+ const layout = yield* resolveCodexHomeLayout(
+ decodeCodexSettings({
+ homePath: sharedHome,
+ shadowHomePath: shadowHome,
+ }),
+ );
+
+ const error = yield* materializeCodexShadowHome(layout).pipe(Effect.flip);
+
+ expect(error).toBeInstanceOf(CodexShadowHomeEntryConflictError);
+ expect(error).toMatchObject({
+ sharedHomePath: sharedHome,
+ effectiveHomePath: shadowHome,
+ entryName: "config.toml",
+ linkPath: path.join(shadowHome, "config.toml"),
+ targetPath: path.join(sharedHome, "config.toml"),
+ });
+ expect(error.message).toBe(
+ `Cannot create Codex shadow home entry 'config.toml' because '${path.join(shadowHome, "config.toml")}' already exists and is not a symlink.`,
+ );
+ }),
);
it.effect("preserves filesystem operation, paths, and cause", () =>
diff --git a/apps/server/src/provider/Layers/OpenCodeAdapter.test.ts b/apps/server/src/provider/Layers/OpenCodeAdapter.test.ts
index 93382f84223..fb0e9aa9ef2 100644
--- a/apps/server/src/provider/Layers/OpenCodeAdapter.test.ts
+++ b/apps/server/src/provider/Layers/OpenCodeAdapter.test.ts
@@ -49,6 +49,7 @@ import {
makeOpenCodeAdapter,
mergeOpenCodeAssistantText,
} from "./OpenCodeAdapter.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
// Test-local service tag so the rest of the file can keep using `yield* OpenCodeAdapter`.
class OpenCodeAdapter extends Context.Service<OpenCodeAdapter, OpenCodeAdapterShape>()(
@@ -6401,30 +6402,32 @@ it.layer(OpenCodeAdapterTestLayer)("OpenCodeAdapterLive", (it) => {
}),
);
- it.effect("treats lexically or physically identical directories as the same", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const sameDirectory = (left: string, right: string) =>
- isSameOpenCodeDirectory(fileSystem, path, left, right);
-
- // Lexical-only differences (trailing slash, dot segments) short-circuit
- // without touching the filesystem — the paths need not exist.
- NodeAssert.equal(yield* sameDirectory("/repo/project/", "/repo/project"), true);
- NodeAssert.equal(yield* sameDirectory("/repo/nested/../project", "/repo/project"), true);
- // Nonexistent paths degrade to the lexical comparison instead of failing.
- NodeAssert.equal(yield* sameDirectory("/repo/project", "/repo/other"), false);
-
- // A symlinked cwd (the macOS `/tmp` → `/private/tmp` shape) resolves to
- // the directory it points at, so the two spellings compare equal.
- const base = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-opencode-dir-" });
- const real = path.join(base, "real");
- const link = path.join(base, "link");
- yield* fileSystem.makeDirectory(real);
- yield* fileSystem.symlink(real, link);
- NodeAssert.equal(yield* sameDirectory(link, real), true);
- NodeAssert.equal(yield* sameDirectory(link, path.join(base, "other")), false);
- }).pipe(Effect.scoped),
+ it.effect.skipIf(!symlinksSupported)(
+ "treats lexically or physically identical directories as the same",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const sameDirectory = (left: string, right: string) =>
+ isSameOpenCodeDirectory(fileSystem, path, left, right);
+
+ // Lexical-only differences (trailing slash, dot segments) short-circuit
+ // without touching the filesystem — the paths need not exist.
+ NodeAssert.equal(yield* sameDirectory("/repo/project/", "/repo/project"), true);
+ NodeAssert.equal(yield* sameDirectory("/repo/nested/../project", "/repo/project"), true);
+ // Nonexistent paths degrade to the lexical comparison instead of failing.
+ NodeAssert.equal(yield* sameDirectory("/repo/project", "/repo/other"), false);
+
+ // A symlinked cwd (the macOS `/tmp` → `/private/tmp` shape) resolves to
+ // the directory it points at, so the two spellings compare equal.
+ const base = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-opencode-dir-" });
+ const real = path.join(base, "real");
+ const link = path.join(base, "link");
+ yield* fileSystem.makeDirectory(real);
+ yield* fileSystem.symlink(real, link);
+ NodeAssert.equal(yield* sameDirectory(link, real), true);
+ NodeAssert.equal(yield* sameDirectory(link, path.join(base, "other")), false);
+ }).pipe(Effect.scoped),
);
it.effect("appends raw assistant text deltas and reconciles part update snapshots", () =>
diff --git a/apps/server/src/provider/providerMaintenance.test.ts b/apps/server/src/provider/providerMaintenance.test.ts
index c80b312b140..35d0c04bb08 100644
--- a/apps/server/src/provider/providerMaintenance.test.ts
+++ b/apps/server/src/provider/providerMaintenance.test.ts
@@ -20,6 +20,7 @@ import {
resolveLatestProviderVersion,
resolveProviderMaintenanceCapabilitiesEffect,
} from "./providerMaintenance.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const driver = (value: string) => ProviderDriverKind.make(value);
// These write `#!/bin/sh` stubs and resolve them through a darwin-mocked
@@ -456,100 +457,110 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
});
});
- it.effect("keeps npm updates for binaries symlinked into npm's global node_modules tree", () =>
- Effect.gen(function* () {
- const tempDir = yield* makeTempDir("t3-npm-capabilities");
- const binDir = NodePath.join(tempDir, "bin");
- const packageBinDir = NodePath.join(
- tempDir,
- "lib",
- "node_modules",
- "@example",
- "package-tool",
- "bin",
- );
- NodeFS.mkdirSync(binDir, { recursive: true });
- NodeFS.mkdirSync(packageBinDir, { recursive: true });
- const packageBinPath = NodePath.join(packageBinDir, "package-tool.js");
- const symlinkPath = NodePath.join(binDir, "package-tool");
- NodeFS.writeFileSync(packageBinPath, "#!/usr/bin/env node\n");
- NodeFS.chmodSync(packageBinPath, 0o755);
- NodeFS.symlinkSync(packageBinPath, symlinkPath);
-
- const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
- binaryPath: symlinkPath,
- env: {
- PATH: "",
- },
- });
-
- expect(capabilities).toEqual({
- provider: driver("packageTool"),
- packageName: "@example/package-tool",
- update: {
- command:
- "npm install -g --allow-scripts=@example/package-tool @example/package-tool@latest",
-
- executable: "npm",
-
- args: [
- "install",
- "-g",
- "--allow-scripts=@example/package-tool",
- "@example/package-tool@latest",
- ],
+ it.effect.skipIf(!symlinksSupported)(
+ "keeps npm updates for binaries symlinked into npm's global node_modules tree",
+ () =>
+ Effect.gen(function* () {
+ const tempDir = yield* makeTempDir("t3-npm-capabilities");
+ const binDir = NodePath.join(tempDir, "bin");
+ const packageBinDir = NodePath.join(
+ tempDir,
+ "lib",
+ "node_modules",
+ "@example",
+ "package-tool",
+ "bin",
+ );
+ NodeFS.mkdirSync(binDir, { recursive: true });
+ NodeFS.mkdirSync(packageBinDir, { recursive: true });
+ const packageBinPath = NodePath.join(packageBinDir, "package-tool.js");
+ const symlinkPath = NodePath.join(binDir, "package-tool");
+ NodeFS.writeFileSync(packageBinPath, "#!/usr/bin/env node\n");
+ NodeFS.chmodSync(packageBinPath, 0o755);
+ NodeFS.symlinkSync(packageBinPath, symlinkPath);
- lockKey: "npm-global",
- },
- });
- }),
+ const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
+ packageToolUpdate,
+ {
+ binaryPath: symlinkPath,
+ env: {
+ PATH: "",
+ },
+ },
+ );
+
+ expect(capabilities).toEqual({
+ provider: driver("packageTool"),
+ packageName: "@example/package-tool",
+ update: {
+ command:
+ "npm install -g --allow-scripts=@example/package-tool @example/package-tool@latest",
+
+ executable: "npm",
+
+ args: [
+ "install",
+ "-g",
+ "--allow-scripts=@example/package-tool",
+ "@example/package-tool@latest",
+ ],
+
+ lockKey: "npm-global",
+ },
+ });
+ }),
);
- it.effect("uses Effect FileSystem realPath when detecting pnpm global symlinks", () =>
- Effect.gen(function* () {
- const tempDir = yield* makeTempDir("t3-pnpm-realpath-capabilities");
- const binDir = NodePath.join(tempDir, "bin");
- const packageBinDir = NodePath.join(
- tempDir,
- ".local",
- "share",
- "pnpm",
- "global",
- "5",
- "node_modules",
- "@example",
- "package-tool",
- "bin",
- );
- NodeFS.mkdirSync(binDir, { recursive: true });
- NodeFS.mkdirSync(packageBinDir, { recursive: true });
- const packageBinPath = NodePath.join(packageBinDir, "package-tool.js");
- const symlinkPath = NodePath.join(binDir, "package-tool");
- NodeFS.writeFileSync(packageBinPath, "#!/usr/bin/env node\n");
- NodeFS.chmodSync(packageBinPath, 0o755);
- NodeFS.symlinkSync(packageBinPath, symlinkPath);
-
- const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(packageToolUpdate, {
- binaryPath: symlinkPath,
- env: {
- PATH: "",
- },
- });
+ it.effect.skipIf(!symlinksSupported)(
+ "uses Effect FileSystem realPath when detecting pnpm global symlinks",
+ () =>
+ Effect.gen(function* () {
+ const tempDir = yield* makeTempDir("t3-pnpm-realpath-capabilities");
+ const binDir = NodePath.join(tempDir, "bin");
+ const packageBinDir = NodePath.join(
+ tempDir,
+ ".local",
+ "share",
+ "pnpm",
+ "global",
+ "5",
+ "node_modules",
+ "@example",
+ "package-tool",
+ "bin",
+ );
+ NodeFS.mkdirSync(binDir, { recursive: true });
+ NodeFS.mkdirSync(packageBinDir, { recursive: true });
+ const packageBinPath = NodePath.join(packageBinDir, "package-tool.js");
+ const symlinkPath = NodePath.join(binDir, "package-tool");
+ NodeFS.writeFileSync(packageBinPath, "#!/usr/bin/env node\n");
+ NodeFS.chmodSync(packageBinPath, 0o755);
+ NodeFS.symlinkSync(packageBinPath, symlinkPath);
- expect(capabilities).toEqual({
- provider: driver("packageTool"),
- packageName: "@example/package-tool",
- update: {
- command: "pnpm add -g @example/package-tool@latest",
+ const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
+ packageToolUpdate,
+ {
+ binaryPath: symlinkPath,
+ env: {
+ PATH: "",
+ },
+ },
+ );
- executable: "pnpm",
+ expect(capabilities).toEqual({
+ provider: driver("packageTool"),
+ packageName: "@example/package-tool",
+ update: {
+ command: "pnpm add -g @example/package-tool@latest",
- args: ["add", "-g", "@example/package-tool@latest"],
+ executable: "pnpm",
- lockKey: "pnpm-global",
- },
- });
- }),
+ args: ["add", "-g", "@example/package-tool@latest"],
+
+ lockKey: "pnpm-global",
+ },
+ });
+ }),
);
it("allows the package's own install scripts in npm global updates", () => {
diff --git a/apps/server/src/server.test.ts b/apps/server/src/server.test.ts
index c98bc07fcd2..c853c86e5a6 100644
--- a/apps/server/src/server.test.ts
+++ b/apps/server/src/server.test.ts
@@ -199,6 +199,7 @@ import {
type TransferBudgetRun,
transferBudgetViolations,
} from "../integration/TransferBudgetReport.integration.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const defaultProjectId = ProjectId.make("project-default");
const defaultThreadId = ThreadId.make("thread-default");
@@ -6311,7 +6312,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
}).pipe(Effect.provide(NodeHttpServer.layerTest), TestClock.withLive),
);
- it.effect("preserves structured workspace rpc failures", () =>
+ it.effect.skipIf(!symlinksSupported)("preserves structured workspace rpc failures", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
diff --git a/apps/server/src/sourceControl/PrTemplateDetection.test.ts b/apps/server/src/sourceControl/PrTemplateDetection.test.ts
index 34112c9c528..5b91e631112 100644
--- a/apps/server/src/sourceControl/PrTemplateDetection.test.ts
+++ b/apps/server/src/sourceControl/PrTemplateDetection.test.ts
@@ -10,6 +10,7 @@ import { ServerConfig } from "../config.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as VcsProcess from "../vcs/VcsProcess.ts";
import { detectPrTemplate } from "./PrTemplateDetection.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const SINGLE_TEMPLATE_PATHS = [
".github/pull_request_template.md",
@@ -139,27 +140,29 @@ it.effect.each(TEMPLATE_DIRECTORIES)("recognizes the $0 directory", (relativeDir
),
);
-it.effect("skips unusable directory entries and uses the one valid template", () =>
- runWithTempDirectory((cwd) =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const templateDirectory = path.join(cwd, ".github", "PULL_REQUEST_TEMPLATE");
- yield* fileSystem.makeDirectory(path.join(templateDirectory, "b-directory.md"), {
- recursive: true,
- });
- yield* fileSystem.writeFileString(path.join(templateDirectory, "a-empty.md"), " \n");
- yield* fileSystem.symlink(
- path.join(templateDirectory, "missing.md"),
- path.join(templateDirectory, "c-broken.md"),
- );
- yield* fileSystem.writeFileString(path.join(templateDirectory, "z-valid.md"), "valid");
- yield* commitTemplates(cwd);
-
- const template = yield* detectTemplate(cwd);
- assert.strictEqual(Option.getOrUndefined(template), "valid");
- }),
- ),
+it.effect.skipIf(!symlinksSupported)(
+ "skips unusable directory entries and uses the one valid template",
+ () =>
+ runWithTempDirectory((cwd) =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const templateDirectory = path.join(cwd, ".github", "PULL_REQUEST_TEMPLATE");
+ yield* fileSystem.makeDirectory(path.join(templateDirectory, "b-directory.md"), {
+ recursive: true,
+ });
+ yield* fileSystem.writeFileString(path.join(templateDirectory, "a-empty.md"), " \n");
+ yield* fileSystem.symlink(
+ path.join(templateDirectory, "missing.md"),
+ path.join(templateDirectory, "c-broken.md"),
+ );
+ yield* fileSystem.writeFileString(path.join(templateDirectory, "z-valid.md"), "valid");
+ yield* commitTemplates(cwd);
+
+ const template = yield* detectTemplate(cwd);
+ assert.strictEqual(Option.getOrUndefined(template), "valid");
+ }),
+ ),
);
it.effect("does not guess between multiple directory templates", () =>
@@ -176,60 +179,64 @@ it.effect("does not guess between multiple directory templates", () =>
),
);
-it.effect("rejects a committed template symlink escaping the repository", () =>
- runWithTempDirectory((cwd) =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const outsideDirectory = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "t3-pr-template-outside-",
- });
- const outsideTemplate = path.join(outsideDirectory, "secret.md");
- yield* fileSystem.writeFileString(outsideTemplate, "LOCAL_SECRET_SENTINEL");
- const escapedTemplatePath = path.join(cwd, ".github", "pull_request_template.md");
- yield* fileSystem.makeDirectory(path.dirname(escapedTemplatePath), { recursive: true });
- yield* fileSystem.symlink(outsideTemplate, escapedTemplatePath);
- yield* writeTemplate(cwd, "pull_request_template.md", "safe template");
- yield* commitTemplates(cwd);
-
- const template = yield* detectTemplate(cwd);
- assert.strictEqual(Option.getOrUndefined(template), "safe template");
- assert.notInclude(
- Option.getOrElse(template, () => ""),
- "LOCAL_SECRET_SENTINEL",
- );
- }),
- ),
+it.effect.skipIf(!symlinksSupported)(
+ "rejects a committed template symlink escaping the repository",
+ () =>
+ runWithTempDirectory((cwd) =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const outsideDirectory = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-pr-template-outside-",
+ });
+ const outsideTemplate = path.join(outsideDirectory, "secret.md");
+ yield* fileSystem.writeFileString(outsideTemplate, "LOCAL_SECRET_SENTINEL");
+ const escapedTemplatePath = path.join(cwd, ".github", "pull_request_template.md");
+ yield* fileSystem.makeDirectory(path.dirname(escapedTemplatePath), { recursive: true });
+ yield* fileSystem.symlink(outsideTemplate, escapedTemplatePath);
+ yield* writeTemplate(cwd, "pull_request_template.md", "safe template");
+ yield* commitTemplates(cwd);
+
+ const template = yield* detectTemplate(cwd);
+ assert.strictEqual(Option.getOrUndefined(template), "safe template");
+ assert.notInclude(
+ Option.getOrElse(template, () => ""),
+ "LOCAL_SECRET_SENTINEL",
+ );
+ }),
+ ),
);
-it.effect("reads the committed template when a worktree parent is replaced", () =>
- runWithTempDirectory((cwd) =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const outsideDirectory = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "t3-pr-template-outside-",
- });
- const templatePath = yield* writeTemplate(
- cwd,
- ".github/pull_request_template.md",
- "committed template",
- );
- yield* commitTemplates(cwd);
- yield* writeTemplate(outsideDirectory, "pull_request_template.md", "LOCAL_SECRET_SENTINEL");
-
- const templateDirectory = path.dirname(templatePath);
- yield* fileSystem.rename(templateDirectory, path.join(cwd, ".github-original"));
- yield* fileSystem.symlink(outsideDirectory, templateDirectory);
-
- const template = yield* detectTemplate(cwd);
- assert.strictEqual(Option.getOrUndefined(template), "committed template");
- assert.notInclude(
- Option.getOrElse(template, () => ""),
- "LOCAL_SECRET_SENTINEL",
- );
- }),
- ),
+it.effect.skipIf(!symlinksSupported)(
+ "reads the committed template when a worktree parent is replaced",
+ () =>
+ runWithTempDirectory((cwd) =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const outsideDirectory = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-pr-template-outside-",
+ });
+ const templatePath = yield* writeTemplate(
+ cwd,
+ ".github/pull_request_template.md",
+ "committed template",
+ );
+ yield* commitTemplates(cwd);
+ yield* writeTemplate(outsideDirectory, "pull_request_template.md", "LOCAL_SECRET_SENTINEL");
+
+ const templateDirectory = path.dirname(templatePath);
+ yield* fileSystem.rename(templateDirectory, path.join(cwd, ".github-original"));
+ yield* fileSystem.symlink(outsideDirectory, templateDirectory);
+
+ const template = yield* detectTemplate(cwd);
+ assert.strictEqual(Option.getOrUndefined(template), "committed template");
+ assert.notInclude(
+ Option.getOrElse(template, () => ""),
+ "LOCAL_SECRET_SENTINEL",
+ );
+ }),
+ ),
);
it.effect("bounds template reads and marks truncated content", () =>
diff --git a/apps/server/src/vcs/VcsStatusBroadcaster.test.ts b/apps/server/src/vcs/VcsStatusBroadcaster.test.ts
index c7d7b79a12e..ac21a61ddf7 100644
--- a/apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+++ b/apps/server/src/vcs/VcsStatusBroadcaster.test.ts
@@ -27,6 +27,7 @@ import { GitManagerError } from "@t3tools/contracts";
import * as VcsStatusBroadcaster from "./VcsStatusBroadcaster.ts";
import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
import * as GitWorkflowService from "../git/GitWorkflowService.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
@@ -144,7 +145,7 @@ function makeBackgroundPolicyLayer(shouldRunScopeWork: (scope: BackgroundScope)
}
describe("VcsStatusBroadcaster", () => {
- it.effect(
+ it.effect.skipIf(!symlinksSupported)(
"automatically pulls an enabled clean default branch when status detects it is behind",
() => {
let remoteStatus: VcsStatusRemoteResult = { ...baseRemoteStatus, behindCount: 2 };
@@ -522,67 +523,70 @@ describe("VcsStatusBroadcaster", () => {
}).pipe(Effect.provide(makeTestLayer(state)));
});
- it.effect("normalizes symlinked CWDs before cache lookup and workflow calls", () => {
- const seenCwds: string[] = [];
- const state = {
- currentLocalStatus: baseLocalStatus,
- currentRemoteStatus: baseRemoteStatus,
- localStatusCalls: 0,
- remoteStatusCalls: 0,
- localInvalidationCalls: 0,
- remoteInvalidationCalls: 0,
- };
- const testLayer = VcsStatusBroadcaster.layer.pipe(
- Layer.provideMerge(NodeServices.layer),
- Layer.provide(makeBackgroundPolicyLayer(() => true)),
- Layer.provide(
- Layer.mock(GitWorkflowService.GitWorkflowService)({
- localStatus: (input) =>
- Effect.sync(() => {
- seenCwds.push(input.cwd);
- state.localStatusCalls += 1;
- return state.currentLocalStatus;
- }),
- remoteStatus: (input) =>
- Effect.sync(() => {
- seenCwds.push(input.cwd);
- state.remoteStatusCalls += 1;
- return state.currentRemoteStatus;
- }),
- invalidateLocalStatus: () =>
- Effect.sync(() => {
- state.localInvalidationCalls += 1;
- }),
- invalidateRemoteStatus: () =>
- Effect.sync(() => {
- state.remoteInvalidationCalls += 1;
- }),
- } satisfies Partial<GitWorkflowService.GitWorkflowService["Service"]>),
- ),
- );
+ it.effect.skipIf(!symlinksSupported)(
+ "normalizes symlinked CWDs before cache lookup and workflow calls",
+ () => {
+ const seenCwds: string[] = [];
+ const state = {
+ currentLocalStatus: baseLocalStatus,
+ currentRemoteStatus: baseRemoteStatus,
+ localStatusCalls: 0,
+ remoteStatusCalls: 0,
+ localInvalidationCalls: 0,
+ remoteInvalidationCalls: 0,
+ };
+ const testLayer = VcsStatusBroadcaster.layer.pipe(
+ Layer.provideMerge(NodeServices.layer),
+ Layer.provide(makeBackgroundPolicyLayer(() => true)),
+ Layer.provide(
+ Layer.mock(GitWorkflowService.GitWorkflowService)({
+ localStatus: (input) =>
+ Effect.sync(() => {
+ seenCwds.push(input.cwd);
+ state.localStatusCalls += 1;
+ return state.currentLocalStatus;
+ }),
+ remoteStatus: (input) =>
+ Effect.sync(() => {
+ seenCwds.push(input.cwd);
+ state.remoteStatusCalls += 1;
+ return state.currentRemoteStatus;
+ }),
+ invalidateLocalStatus: () =>
+ Effect.sync(() => {
+ state.localInvalidationCalls += 1;
+ }),
+ invalidateRemoteStatus: () =>
+ Effect.sync(() => {
+ state.remoteInvalidationCalls += 1;
+ }),
+ } satisfies Partial<GitWorkflowService.GitWorkflowService["Service"]>),
+ ),
+ );
- return Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const realDir = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "t3-vcs-status-real-",
- });
- const linkParent = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "t3-vcs-status-link-",
- });
- const linkDir = path.join(linkParent, "repo-link");
- yield* fileSystem.symlink(realDir, linkDir);
- const realPath = yield* fileSystem.realPath(realDir);
+ return Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const realDir = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-vcs-status-real-",
+ });
+ const linkParent = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-vcs-status-link-",
+ });
+ const linkDir = path.join(linkParent, "repo-link");
+ yield* fileSystem.symlink(realDir, linkDir);
+ const realPath = yield* fileSystem.realPath(realDir);
- const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
- yield* broadcaster.getStatus({ cwd: linkDir });
- yield* broadcaster.getStatus({ cwd: realDir });
+ const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
+ yield* broadcaster.getStatus({ cwd: linkDir });
+ yield* broadcaster.getStatus({ cwd: realDir });
- assert.deepStrictEqual(seenCwds, [realPath, realPath]);
- assert.equal(state.localStatusCalls, 1);
- assert.equal(state.remoteStatusCalls, 1);
- }).pipe(Effect.provide(testLayer));
- });
+ assert.deepStrictEqual(seenCwds, [realPath, realPath]);
+ assert.equal(state.localStatusCalls, 1);
+ assert.equal(state.remoteStatusCalls, 1);
+ }).pipe(Effect.provide(testLayer));
+ },
+ );
it.effect("streams a local snapshot first and remote updates later", () => {
const state = {
diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts
index 17c7f0bb050..591414f85bc 100644
--- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts
+++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts
@@ -14,6 +14,7 @@ import * as VcsProcess from "../vcs/VcsProcess.ts";
import * as WorkspaceEntries from "./WorkspaceEntries.ts";
import * as WorkspaceFileSystem from "./WorkspaceFileSystem.ts";
import * as WorkspacePaths from "./WorkspacePaths.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const ProjectLayer = WorkspaceFileSystem.layer.pipe(
Layer.provide(WorkspacePaths.layer),
@@ -138,34 +139,36 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
}),
);
- it.effect("rejects symlinks that resolve outside the workspace root", () =>
- Effect.gen(function* () {
- const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const cwd = yield* makeTempDir;
- const outsideDir = yield* makeTempDir;
- yield* writeTextFile(outsideDir, "secret.txt", "outside\n");
- yield* fileSystem.symlink(
- path.join(outsideDir, "secret.txt"),
- path.join(cwd, "linked-secret.txt"),
- );
-
- const error = yield* workspaceFileSystem
- .readFile({ cwd, relativePath: "linked-secret.txt" })
- .pipe(Effect.flip);
- const resolvedWorkspaceRoot = yield* fileSystem.realPath(cwd);
- const resolvedPath = yield* fileSystem.realPath(path.join(outsideDir, "secret.txt"));
-
- expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceFilePathEscapeError);
- expect(error).toMatchObject({
- workspaceRoot: cwd,
- relativePath: "linked-secret.txt",
- resolvedWorkspaceRoot,
- resolvedPath,
- });
- expect("cause" in error).toBe(false);
- }),
+ it.effect.skipIf(!symlinksSupported)(
+ "rejects symlinks that resolve outside the workspace root",
+ () =>
+ Effect.gen(function* () {
+ const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const cwd = yield* makeTempDir;
+ const outsideDir = yield* makeTempDir;
+ yield* writeTextFile(outsideDir, "secret.txt", "outside\n");
+ yield* fileSystem.symlink(
+ path.join(outsideDir, "secret.txt"),
+ path.join(cwd, "linked-secret.txt"),
+ );
+
+ const error = yield* workspaceFileSystem
+ .readFile({ cwd, relativePath: "linked-secret.txt" })
+ .pipe(Effect.flip);
+ const resolvedWorkspaceRoot = yield* fileSystem.realPath(cwd);
+ const resolvedPath = yield* fileSystem.realPath(path.join(outsideDir, "secret.txt"));
+
+ expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspaceFilePathEscapeError);
+ expect(error).toMatchObject({
+ workspaceRoot: cwd,
+ relativePath: "linked-secret.txt",
+ resolvedWorkspaceRoot,
+ resolvedPath,
+ });
+ expect("cause" in error).toBe(false);
+ }),
);
it.effect("rejects directories without manufacturing an I/O cause", () =>
diff --git a/packages/shared/package.json b/packages/shared/package.json
index d9233a2c54c..a5ce349a4c0 100644
--- a/packages/shared/package.json
+++ b/packages/shared/package.json
@@ -223,6 +223,10 @@
"types": "./src/hostProcess.ts",
"import": "./src/hostProcess.ts"
},
+ "./testing/symlinks": {
+ "types": "./src/testing/symlinks.ts",
+ "import": "./src/testing/symlinks.ts"
+ },
"./httpReadiness": {
"types": "./src/httpReadiness.ts",
"import": "./src/httpReadiness.ts"
diff --git a/packages/shared/src/testing/symlinks.ts b/packages/shared/src/testing/symlinks.ts
new file mode 100644
index 00000000000..4e76984ca21
--- /dev/null
+++ b/packages/shared/src/testing/symlinks.ts
@@ -0,0 +1,29 @@
+// @effect-diagnostics nodeBuiltinImport:off - one synchronous probe at module load, outside any Effect runtime.
+import * as NodeFS from "node:fs";
+import * as NodeOS from "node:os";
+import * as NodePath from "node:path";
+
+/**
+ * Whether this host lets an unprivileged process create symlinks. Windows
+ * refuses without Developer Mode or elevation, so tests that plant a symlink
+ * to prove containment or escape detection should `skipIf(!symlinksSupported)`
+ * rather than fail at setup. Probed once per process.
+ */
+export const symlinksSupported: boolean = (() => {
+ let directory: string | undefined;
+ try {
+ directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-symlink-probe-"));
+ NodeFS.symlinkSync(NodePath.join(directory, "target"), NodePath.join(directory, "link"));
+ return true;
+ } catch {
+ return false;
+ } finally {
+ // Cleanup must not decide the answer: a transient EPERM/EBUSY on the
+ // probe directory would otherwise throw out of module initialisation.
+ try {
+ if (directory !== undefined) NodeFS.rmSync(directory, { recursive: true, force: true });
+ } catch {
+ // Leave the probe directory behind rather than fail every importer.
+ }
+ }
+})();
diff --git a/scripts/build-desktop-artifact.test.ts b/scripts/build-desktop-artifact.test.ts
index 478f6ee2d21..c3d40a03d3c 100644
--- a/scripts/build-desktop-artifact.test.ts
+++ b/scripts/build-desktop-artifact.test.ts
@@ -87,6 +87,7 @@ import {
} from "./build-desktop-artifact.ts";
import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
// A minimal stand-in for the staged sidecar roots packed into the WSL archive.
const stageWslRuntimeTreeFixture = Effect.fn("stageWslRuntimeTreeFixture")(function* (
@@ -2191,7 +2192,7 @@ it("keeps the prefix of a UNC path instead of going relative", () => {
assert.deepStrictEqual(paths[0], "\\\\server\\share\\tmp\\node_modules");
});
-it.effect("rebases packaged links into the isolated tree", () =>
+it.effect.skipIf(!symlinksSupported)("rebases packaged links into the isolated tree", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
diff --git a/scripts/mock-update-server.test.ts b/scripts/mock-update-server.test.ts
index 1371ba58f44..5e060ff9013 100644
--- a/scripts/mock-update-server.test.ts
+++ b/scripts/mock-update-server.test.ts
@@ -7,6 +7,7 @@ import * as Path from "effect/Path";
import { HttpClient, HttpRouter } from "effect/unstable/http";
import { makeMockUpdateRouteLayer } from "./mock-update-server.ts";
+import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const withMockUpdateServer = <A, E, R>(rootRealPath: string, effect: Effect.Effect<A, E, R>) =>
effect.pipe(
@@ -72,35 +73,37 @@ it.layer(NodeServices.layer)("mock-update-server", (it) => {
}),
);
- it.effect("rejects symlinked files that escape the configured root", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const path = yield* Path.Path;
- const root = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "mock-update-server-root-",
- });
- const outside = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "mock-update-server-outside-",
- });
- const rootRealPath = yield* fileSystem.realPath(root);
- const outsideFile = path.join(outside, "outside.yml");
- const linksDir = path.join(root, "links");
- const symlinkPath = path.join(linksDir, "outside.yml");
+ it.effect.skipIf(!symlinksSupported)(
+ "rejects symlinked files that escape the configured root",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "mock-update-server-root-",
+ });
+ const outside = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "mock-update-server-outside-",
+ });
+ const rootRealPath = yield* fileSystem.realPath(root);
+ const outsideFile = path.join(outside, "outside.yml");
+ const linksDir = path.join(root, "links");
+ const symlinkPath = path.join(linksDir, "outside.yml");
- yield* fileSystem.writeFileString(outsideFile, "version: outside\n");
- yield* fileSystem.makeDirectory(linksDir, { recursive: true });
- yield* fileSystem.symlink(outsideFile, symlinkPath);
+ yield* fileSystem.writeFileString(outsideFile, "version: outside\n");
+ yield* fileSystem.makeDirectory(linksDir, { recursive: true });
+ yield* fileSystem.symlink(outsideFile, symlinkPath);
- yield* withMockUpdateServer(
- rootRealPath,
- Effect.gen(function* () {
- const client = yield* HttpClient.HttpClient;
- const response = yield* client.get("/links/outside.yml");
+ yield* withMockUpdateServer(
+ rootRealPath,
+ Effect.gen(function* () {
+ const client = yield* HttpClient.HttpClient;
+ const response = yield* client.get("/links/outside.yml");
- assert.equal(response.status, 404);
- assert.equal(yield* response.text, "Not Found");
- }),
- );
- }),
+ assert.equal(response.status, 404);
+ assert.equal(yield* response.text, "Not Found");
+ }),
+ );
+ }),
);
});