TypeScript
fix(server): checkpoints work in Windows workspaces with paths over 260 characters (#13538)
Keiraraac871e6f1b13
diff --git a/apps/server/src/vcs/GitVcsDriver.test.ts b/apps/server/src/vcs/GitVcsDriver.test.tsindex 3c2b62259bf..83587e65134 100644--- a/apps/server/src/vcs/GitVcsDriver.test.ts+++ b/apps/server/src/vcs/GitVcsDriver.test.ts@@ -15,6 +15,7 @@ import { ChildProcessSpawner } from "effect/process";import { assert, it } from "@effect/vitest";import { CheckpointRef, GitCommandError, VcsProcessExitError } from "@t3tools/contracts";+import * as HostProcess from "@t3tools/shared/HostProcess";import * as ServerConfig from "../config.ts";import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";import * as ProcessRunner from "../processRunner.ts";@@ -1212,3 +1213,50 @@ it.effect("GitVcsDriver flushes checkpoint objects and refs to disk before publi),);});++it.effect.each(["win32", "linux"] as const)(+ "checkpoint working-tree commands enable Git long paths only on Windows (%s)",+ (platform) =>+ Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const liveProcess = yield* VcsProcess.VcsProcess;+ const driver = yield* GitVcsDriver.makeVcsDriverShape();+ const cwd = yield* fs.makeTempDirectoryScoped({ prefix: "t3-checkpoint-long-paths-" });+ const { git, checkpointRef } = yield* makeCheckpointFixture(driver, cwd);+ // An unborn nested repository fails the first `add`, so recovery's listing runs too.+ yield* git(["init", "empty"]);+ const observedArgs: ReadonlyArray<string>[] = [];+ const platformDriver = yield* GitVcsDriver.makeVcsDriverShape().pipe(+ Effect.provideService(HostProcess.Platform, platform),+ Effect.provideService(VcsProcess.VcsProcess, {+ run: (input) => {+ observedArgs.push(input.args);+ return liveProcess.run(input);+ },+ }),+ );++ yield* platformDriver.checkpoints.captureCheckpoint({ cwd, checkpointRef });+ yield* fs.writeFileString(path.join(cwd, "file.txt"), "changed\n");+ assert.isTrue(yield* platformDriver.checkpoints.restoreCheckpoint({ cwd, checkpointRef }));++ assert.strictEqual(yield* fs.readFileString(path.join(cwd, "file.txt")), "unstaged\n");+ assert.strictEqual((yield* git(["ls-tree", checkpointRef, "--", "empty"])).stdout, "");+ for (const command of ["add", "ls-files", "restore", "clean", "reset"]) {+ const calls = observedArgs.filter(+ (args) => args.includes(command) && (command !== "ls-files" || args.includes("--others")),+ );+ assert.isNotEmpty(calls, `Expected checkpoint command: ${command}`);+ for (const args of calls) {+ const setting = args.indexOf("core.longpaths=true");+ if (platform === "win32") {+ assert.strictEqual(args[setting - 1], "-c", args.join(" "));+ assert.isBelow(setting, args.indexOf(command), args.join(" "));+ } else {+ assert.strictEqual(setting, -1, args.join(" "));+ }+ }+ }+ }).pipe(Effect.scoped, Effect.provide(layerGitContract)),+);diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.tsindex 5d382f16d2e..f08e250d58d 100644--- a/apps/server/src/vcs/GitVcsDriver.ts+++ b/apps/server/src/vcs/GitVcsDriver.ts@@ -32,6 +32,7 @@ import {type VcsStatusResult,type WorktreeSubmodules,} from "@t3tools/contracts";+import * as HostProcess from "@t3tools/shared/HostProcess";import {makeGitVcsDriverCore,PATCH_RENDER_PREFIX_ARGS,@@ -792,6 +793,10 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* ("core.fsyncMethod=fsync",] as const;+ // Checkpoints must handle existing paths beyond Windows MAX_PATH, even when+ // core.longpaths is disabled in the user's Git configuration.+ const longPaths = (yield* HostProcess.Platform) === "win32" ? ["-c", "core.longpaths=true"] : [];+const checkpoints: VcsDriver.VcsCheckpointOps = {captureCheckpoint: Effect.fn("GitVcsDriver.checkpoints.captureCheckpoint")(function* (input) {const operation = VcsProcess.CHECKPOINT_CAPTURE_OPERATION;@@ -954,6 +959,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (args: [...indexConfig,...durableWrite,+ ...longPaths,"add",...(sparseCheckout ? ["--sparse"] : []),"-A",@@ -972,7 +978,15 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (const untracked = yield* execute({operation,cwd: input.cwd,- args: ["ls-files", "--others", "--exclude-standard", "-z", "--", "."],+ args: [+ ...longPaths,+ "ls-files",+ "--others",+ "--exclude-standard",+ "-z",+ "--",+ ".",+ ],env: commitEnv,maxOutputBytes: WORKSPACE_FILES_MAX_OUTPUT_BYTES,});@@ -1092,7 +1106,16 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (yield* execute({operation,cwd: input.cwd,- args: ["restore", "--source", commitOid, "--worktree", "--staged", "--", "."],+ args: [+ ...longPaths,+ "restore",+ "--source",+ commitOid,+ "--worktree",+ "--staged",+ "--",+ ".",+ ],});}// Restoring away the last tracked file can remove a nested workspace directory.@@ -1112,7 +1135,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (const cleaned = yield* execute({operation,cwd: input.cwd,- args: ["clean", "-fd", "--", "."],+ args: [...longPaths, "clean", "-fd", "--", "."],allowNonZeroExit: true,});if (cleaned.exitCode !== 0) {@@ -1141,7 +1164,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (yield* execute({operation,cwd: input.cwd,- args: ["reset", "--quiet", "--", "."],+ args: [...longPaths, "reset", "--quiet", "--", "."],});}