Skip to content
TypeScript

test: skip POSIX mode-bit assertions on a Windows host (#9571)

Julius Marminge1108be0fc862
diff --git a/apps/server/scripts/t3-sqlite-state.test.ts b/apps/server/scripts/t3-sqlite-state.test.ts
index 71e592fafbd..fa5471bfa8c 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 { HostProcessPlatform } from "@t3tools/shared/hostProcess";
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
const createFixtureDatabase = Effect.fn("createSqliteStateFixtureDatabase")(function* (
@@ -89,7 +90,8 @@ it.layer(NodeServices.layer)("t3-sqlite-state", (it) => {
sql: "INSERT INTO fixtures (id, label) VALUES (2, 'seeded')",
});
assert.equal(mutation.operation, "exec");
- if (mutation.operation === "exec") {
+ if (mutation.operation === "exec" && (yield* HostProcessPlatform) !== "win32") {
+ // NTFS has no POSIX mode bits to report.
assert.equal((yield* fs.stat(mutation.backup)).mode & 0o777, 0o600);
}
diff --git a/apps/server/src/cli/theme.test.ts b/apps/server/src/cli/theme.test.ts
index 33606565ffc..7935f5e51b4 100644
--- a/apps/server/src/cli/theme.test.ts
+++ b/apps/server/src/cli/theme.test.ts
@@ -14,6 +14,11 @@ import { Command } from "effect/unstable/cli";
import { cli } from "../bin.ts";
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
+import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
+
+// These force a failure with chmod, which Windows ignores for directories and
+// cannot use to make a file unreadable, so the failure never happens there.
+const windowsHost = HostProcessPlatform.defaultValue() === "win32";
const runCli = (args: ReadonlyArray<string>) =>
Command.runWith(cli, { version: "0.0.0" })(args).pipe(
@@ -161,7 +166,7 @@ describe("t3 theme", () => {
// rolled back rather than left mutating the environment's theme set. The
// userdata directory is made read-only while themes stays writable, so the
// failure lands after the publish -- the case the rollback exists for.
- it.effect("rolls back a publish when the default cannot be written", () =>
+ it.effect.skipIf(windowsHost)("rolls back a publish when the default cannot be written", () =>
Effect.gen(function* () {
const baseDir = makeBaseDir();
writeSettings(baseDir, {});
@@ -229,7 +234,7 @@ 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.skipIf(!symlinksSupported)(
+ it.effect.skipIf(!symlinksSupported || windowsHost)(
"restores a non-theme destination entry when the set fails",
() =>
Effect.gen(function* () {
@@ -255,7 +260,7 @@ describe("t3 theme", () => {
}),
);
- it.effect("restores the previous theme when a re-publish fails to set", () =>
+ it.effect.skipIf(windowsHost)("restores the previous theme when a re-publish fails to set", () =>
Effect.gen(function* () {
const baseDir = makeBaseDir();
writeSettings(baseDir, {});
@@ -352,7 +357,7 @@ describe("t3 theme", () => {
// An unreadable settings file must never read as "no settings": writing a
// fresh sparse file over it would discard every key the user had.
- it.effect("refuses to write when the settings file cannot be read", () =>
+ it.effect.skipIf(windowsHost)("refuses to write when the settings file cannot be read", () =>
Effect.gen(function* () {
const baseDir = makeBaseDir();
writeSettings(baseDir, { enableProviderUpdateChecks: false });
diff --git a/apps/server/src/keybindings.test.ts b/apps/server/src/keybindings.test.ts
index 6c32235c27f..160755a8f9b 100644
--- a/apps/server/src/keybindings.test.ts
+++ b/apps/server/src/keybindings.test.ts
@@ -12,6 +12,7 @@ import * as Schema from "effect/Schema";
import * as ServerConfig from "./config.ts";
import * as Keybindings from "./keybindings.ts";
import { KeybindingsConfigError } from "@t3tools/contracts";
+import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
const KeybindingsConfigJson = Schema.fromJsonString(KeybindingsConfig);
const encodeKeybindingsConfigJson = Schema.encodeEffect(KeybindingsConfigJson);
@@ -511,31 +512,34 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
}).pipe(Effect.provide(makeKeybindingsLayer())),
);
- it.effect("fails when config directory is not writable", () =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
- const { dirname } = yield* Path.Path;
- yield* writeKeybindingsConfig(keybindingsConfigPath, [
- { key: "mod+j", command: "terminal.toggle" },
- ]);
- yield* fs.chmod(dirname(keybindingsConfigPath), 0o500);
+ // chmod cannot make a directory unwritable on Windows, so the write succeeds.
+ it.effect.skipIf(HostProcessPlatform.defaultValue() === "win32")(
+ "fails when config directory is not writable",
+ () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
+ const { dirname } = yield* Path.Path;
+ yield* writeKeybindingsConfig(keybindingsConfigPath, [
+ { key: "mod+j", command: "terminal.toggle" },
+ ]);
+ yield* fs.chmod(dirname(keybindingsConfigPath), 0o500);
- const result = yield* Effect.gen(function* () {
- const keybindings = yield* Keybindings.Keybindings;
- return yield* keybindings.upsertKeybindingRule({
- key: "mod+shift+r",
- command: "script.run-tests.run",
- });
- }).pipe(toDetailResult);
- assertFailure(result, "failed to write keybindings config");
+ const result = yield* Effect.gen(function* () {
+ const keybindings = yield* Keybindings.Keybindings;
+ return yield* keybindings.upsertKeybindingRule({
+ key: "mod+shift+r",
+ command: "script.run-tests.run",
+ });
+ }).pipe(toDetailResult);
+ assertFailure(result, "failed to write keybindings config");
- yield* fs.chmod(dirname(keybindingsConfigPath), 0o700);
+ yield* fs.chmod(dirname(keybindingsConfigPath), 0o700);
- const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
- const persistedView = persisted.map(({ key, command }) => ({ key, command }));
- assert.deepEqual(persistedView, [{ key: "mod+j", command: "terminal.toggle" }]);
- }).pipe(Effect.provide(makeKeybindingsLayer())),
+ const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
+ const persistedView = persisted.map(({ key, command }) => ({ key, command }));
+ assert.deepEqual(persistedView, [{ key: "mod+j", command: "terminal.toggle" }]);
+ }).pipe(Effect.provide(makeKeybindingsLayer())),
);
it.effect("caches loaded resolved config across repeated reads", () =>
diff --git a/packages/shared/src/logging.test.ts b/packages/shared/src/logging.test.ts
index 4b19bd291da..0e294bbe29b 100644
--- a/packages/shared/src/logging.test.ts
+++ b/packages/shared/src/logging.test.ts
@@ -3,6 +3,7 @@ import * as NodeFS from "node:fs";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";
import { afterEach, describe, expect, it } from "vite-plus/test";
+import { HostProcessPlatform } from "./hostProcess.ts";
import {
RotatingFileSink,
@@ -10,6 +11,7 @@ import {
RotatingFileSinkError,
} from "./logging.ts";
+const windowsHost = HostProcessPlatform.defaultValue() === "win32";
const tempDirectories: string[] = [];
const makeTempDirectory = (): string => {
@@ -69,7 +71,10 @@ describe("RotatingFileSink", () => {
expect((thrown as RotatingFileSinkError).cause).toBeInstanceOf(Error);
});
- it("only treats a missing log file as an empty current size", () => {
+ // An over-long name is the one stat failure that is neither ENOENT nor a
+ // permission problem on posix. Windows reports it as ENOENT, so the sink
+ // correctly treats it as an absent file and there is nothing to assert.
+ it.skipIf(windowsHost)("only treats a missing log file as an empty current size", () => {
const directory = makeTempDirectory();
const filePath = NodePath.join(directory, "a".repeat(300));
diff --git a/packages/shared/src/relayClient.test.ts b/packages/shared/src/relayClient.test.ts
index df39ef0b161..1d556ed6dc3 100644
--- a/packages/shared/src/relayClient.test.ts
+++ b/packages/shared/src/relayClient.test.ts
@@ -18,6 +18,10 @@ import {
makeCloudflaredRelayClient,
} from "./relayClient.ts";
+// The suite runs the linux code path against the real filesystem, checking
+// POSIX exec bits that NTFS never reports; the win32 branch skips that check.
+const windowsHost = HostProcessPlatform.defaultValue() === "win32";
+
const hostRuntimeLayer = (env: Record<string, string> = {}) =>
Layer.mergeAll(
Layer.succeed(HostProcessPlatform, "linux"),
@@ -63,102 +67,106 @@ const makeSpawnerLayer = (commands: Array<string>) =>
);
describe("RelayClient", () => {
- it.effect("resolves explicit overrides before managed and PATH executables", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const baseDir = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "t3-cloudflared-test-",
- });
- const overridePath = `${baseDir}/override-cloudflared`;
- yield* fileSystem.writeFileString(overridePath, "override");
- yield* fileSystem.chmod(overridePath, 0o755);
- const manager = yield* makeCloudflaredRelayClient({
- baseDir,
- });
+ it.effect.skipIf(windowsHost)(
+ "resolves explicit overrides before managed and PATH executables",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const baseDir = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-cloudflared-test-",
+ });
+ const overridePath = `${baseDir}/override-cloudflared`;
+ yield* fileSystem.writeFileString(overridePath, "override");
+ yield* fileSystem.chmod(overridePath, 0o755);
+ const manager = yield* makeCloudflaredRelayClient({
+ baseDir,
+ });
- expect(
- yield* manager.resolve.pipe(
- Effect.provideService(
- ConfigProvider.ConfigProvider,
- ConfigProvider.fromEnv({
- env: { PATH: "", T3CODE_CLOUDFLARED_PATH: overridePath },
- }),
+ expect(
+ yield* manager.resolve.pipe(
+ Effect.provideService(
+ ConfigProvider.ConfigProvider,
+ ConfigProvider.fromEnv({
+ env: { PATH: "", T3CODE_CLOUDFLARED_PATH: overridePath },
+ }),
+ ),
+ ),
+ ).toEqual({
+ status: "available",
+ executablePath: overridePath,
+ source: "override",
+ version: CLOUDFLARED_VERSION,
+ });
+ }).pipe(
+ Effect.scoped,
+ Effect.provide(
+ Layer.mergeAll(
+ NodeServices.layer,
+ makeHttpClientLayer(new Uint8Array()),
+ makeSpawnerLayer([]),
+ hostRuntimeLayer(),
),
- ),
- ).toEqual({
- status: "available",
- executablePath: overridePath,
- source: "override",
- version: CLOUDFLARED_VERSION,
- });
- }).pipe(
- Effect.scoped,
- Effect.provide(
- Layer.mergeAll(
- NodeServices.layer,
- makeHttpClientLayer(new Uint8Array()),
- makeSpawnerLayer([]),
- hostRuntimeLayer(),
),
),
- ),
);
- it.effect("downloads, verifies, validates, and atomically installs the managed executable", () =>
- Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const baseDir = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "t3-cloudflared-test-",
- });
- const bytes = new TextEncoder().encode("test-cloudflared-binary");
- const manager = yield* makeCloudflaredRelayClient({
- baseDir,
- releaseAsset: {
- url: "https://example.test/cloudflared",
- sha256: Encoding.encodeHex(sha256(bytes)),
- archive: "binary",
- },
- });
+ it.effect.skipIf(windowsHost)(
+ "downloads, verifies, validates, and atomically installs the managed executable",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const baseDir = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-cloudflared-test-",
+ });
+ const bytes = new TextEncoder().encode("test-cloudflared-binary");
+ const manager = yield* makeCloudflaredRelayClient({
+ baseDir,
+ releaseAsset: {
+ url: "https://example.test/cloudflared",
+ sha256: Encoding.encodeHex(sha256(bytes)),
+ archive: "binary",
+ },
+ });
- const progress: Array<string> = [];
- const installed = yield* manager.installWithProgress((event) =>
- Effect.sync(() => {
- if (event.type === "progress") {
- progress.push(event.stage);
- }
- }),
- );
- const managedPath = `${baseDir}/tools/cloudflared/${CLOUDFLARED_VERSION}/linux-x64/cloudflared`;
- expect(installed).toEqual({
- status: "available",
- executablePath: managedPath,
- source: "managed",
- version: CLOUDFLARED_VERSION,
- });
- expect(new TextDecoder().decode(yield* fileSystem.readFile(managedPath))).toBe(
- "test-cloudflared-binary",
- );
- expect(progress).toEqual([
- "checking",
- "waiting_for_lock",
- "downloading",
- "verifying",
- "installing",
- "validating",
- "activating",
- ]);
- expect(yield* manager.resolve).toEqual(installed);
- }).pipe(
- Effect.scoped,
- Effect.provide(
- Layer.mergeAll(
- NodeServices.layer,
- makeHttpClientLayer(new TextEncoder().encode("test-cloudflared-binary")),
- makeSpawnerLayer([]),
- hostRuntimeLayer(),
+ const progress: Array<string> = [];
+ const installed = yield* manager.installWithProgress((event) =>
+ Effect.sync(() => {
+ if (event.type === "progress") {
+ progress.push(event.stage);
+ }
+ }),
+ );
+ const managedPath = `${baseDir}/tools/cloudflared/${CLOUDFLARED_VERSION}/linux-x64/cloudflared`;
+ expect(installed).toEqual({
+ status: "available",
+ executablePath: managedPath,
+ source: "managed",
+ version: CLOUDFLARED_VERSION,
+ });
+ expect(new TextDecoder().decode(yield* fileSystem.readFile(managedPath))).toBe(
+ "test-cloudflared-binary",
+ );
+ expect(progress).toEqual([
+ "checking",
+ "waiting_for_lock",
+ "downloading",
+ "verifying",
+ "installing",
+ "validating",
+ "activating",
+ ]);
+ expect(yield* manager.resolve).toEqual(installed);
+ }).pipe(
+ Effect.scoped,
+ Effect.provide(
+ Layer.mergeAll(
+ NodeServices.layer,
+ makeHttpClientLayer(new TextEncoder().encode("test-cloudflared-binary")),
+ makeSpawnerLayer([]),
+ hostRuntimeLayer(),
+ ),
),
),
- ),
);
it.effect("rejects downloads whose checksum does not match the pinned manifest", () =>
@@ -192,7 +200,7 @@ describe("RelayClient", () => {
),
);
- it.effect("serializes concurrent installs within one runtime", () => {
+ it.effect.skipIf(windowsHost)("serializes concurrent installs within one runtime", () => {
const commands: Array<string> = [];
const bytes = new TextEncoder().encode("test-cloudflared-binary");
return Effect.gen(function* () {
@@ -227,45 +235,48 @@ describe("RelayClient", () => {
);
});
- it.effect("observes PATH changes after the manager has been constructed", () => {
- const env = { PATH: "" };
- return Effect.gen(function* () {
- const fileSystem = yield* FileSystem.FileSystem;
- const baseDir = yield* fileSystem.makeTempDirectoryScoped({
- prefix: "t3-cloudflared-test-",
- });
- const binDir = `${baseDir}/bin`;
- const executablePath = `${binDir}/cloudflared`;
- const manager = yield* makeCloudflaredRelayClient({
- baseDir,
- });
+ it.effect.skipIf(windowsHost)(
+ "observes PATH changes after the manager has been constructed",
+ () => {
+ const env = { PATH: "" };
+ return Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const baseDir = yield* fileSystem.makeTempDirectoryScoped({
+ prefix: "t3-cloudflared-test-",
+ });
+ const binDir = `${baseDir}/bin`;
+ const executablePath = `${binDir}/cloudflared`;
+ const manager = yield* makeCloudflaredRelayClient({
+ baseDir,
+ });
- expect(yield* manager.resolve).toEqual({
- status: "missing",
- version: CLOUDFLARED_VERSION,
- });
+ expect(yield* manager.resolve).toEqual({
+ status: "missing",
+ version: CLOUDFLARED_VERSION,
+ });
- yield* fileSystem.makeDirectory(binDir);
- yield* fileSystem.writeFileString(executablePath, "cloudflared");
- yield* fileSystem.chmod(executablePath, 0o755);
- env.PATH = binDir;
+ yield* fileSystem.makeDirectory(binDir);
+ yield* fileSystem.writeFileString(executablePath, "cloudflared");
+ yield* fileSystem.chmod(executablePath, 0o755);
+ env.PATH = binDir;
- expect(yield* manager.resolve).toEqual({
- status: "available",
- executablePath,
- source: "path",
- version: CLOUDFLARED_VERSION,
- });
- }).pipe(
- Effect.scoped,
- Effect.provide(
- Layer.mergeAll(
- NodeServices.layer,
- makeHttpClientLayer(new Uint8Array()),
- makeSpawnerLayer([]),
- hostRuntimeLayer(env),
+ expect(yield* manager.resolve).toEqual({
+ status: "available",
+ executablePath,
+ source: "path",
+ version: CLOUDFLARED_VERSION,
+ });
+ }).pipe(
+ Effect.scoped,
+ Effect.provide(
+ Layer.mergeAll(
+ NodeServices.layer,
+ makeHttpClientLayer(new Uint8Array()),
+ makeSpawnerLayer([]),
+ hostRuntimeLayer(env),
+ ),
),
- ),
- );
- });
+ );
+ },
+ );
});