Skip to content

Commit ba92322

Browse files
test(server): trim git lock rollback regression coverage
1 parent 5fcf35c commit ba92322

3 files changed

Lines changed: 24 additions & 171 deletions

File tree

‎apps/server/src/orchestration-v2/CheckpointRollbackService.test.ts‎

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
ProviderSessionId,
1010
ProviderThreadId,
1111
ThreadId,
12-
VcsProcessExitError,
1312
} from "@t3tools/contracts";
1413
import * as Effect from "effect/Effect";
1514
import * as Deferred from "effect/Deferred";
@@ -38,7 +37,6 @@ import * as ProjectStore from "./ProjectStore.ts";
3837
import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
3938
import * as ProviderSessionManager from "./ProviderSessionManager.ts";
4039
import * as RuntimePolicy from "./RuntimePolicy.ts";
41-
import { GIT_INDEX_LOCKED_DETAIL } from "../vcs/VcsProcess.ts";
4240

4341
const unrelatedProject = Option.some({
4442
workspaceRoot: "/nonexistent/t3-rollback-project",
@@ -396,123 +394,6 @@ it.effect("rejects an unavailable rollback target before opening a session", ()
396394
}).pipe(Effect.provide(layerTest));
397395
});
398396

399-
it.effect.each([
400-
{
401-
name: "a held Git index lock",
402-
restoreCause: new VcsProcessExitError({
403-
operation: "GitVcsDriverCore.restoreCheckpoint",
404-
command: "git",
405-
cwd: process.cwd(),
406-
exitCode: 128,
407-
detail: GIT_INDEX_LOCKED_DETAIL,
408-
failureKind: "command-failed",
409-
retryable: true,
410-
}),
411-
expectedMessage: GIT_INDEX_LOCKED_DETAIL,
412-
},
413-
{
414-
name: "raw Git output",
415-
restoreCause: new VcsProcessExitError({
416-
operation: "GitVcsDriver.restoreCheckpoint",
417-
command: "git",
418-
cwd: process.cwd(),
419-
exitCode: 1,
420-
detail: "error: could not clean /home/user/project/secret.txt",
421-
failureKind: "command-failed",
422-
}),
423-
expectedMessage: CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
424-
},
425-
{
426-
name: "an unclassified Git failure",
427-
restoreCause: new VcsProcessExitError({
428-
operation: "GitVcsDriverCore.restoreCheckpoint",
429-
command: "git",
430-
cwd: process.cwd(),
431-
exitCode: 128,
432-
detail: "Process exited with a non-zero status.",
433-
failureKind: "command-failed",
434-
}),
435-
expectedMessage: CheckpointRollbackService.ROLLBACK_FAILED_MESSAGE,
436-
},
437-
])(
438-
"tells clients about $name only when it is a held index lock",
439-
({ restoreCause, expectedMessage }) => {
440-
const threadId = ThreadId.make("thread:rollback-restore-failed");
441-
const providerThreadId = ProviderThreadId.make("provider-thread:rollback-restore-failed");
442-
const providerSessionId = ProviderSessionId.make("provider-session:rollback-restore-failed");
443-
const checkpointId = CheckpointId.make("checkpoint:rollback-restore-failed");
444-
const scopeId = CheckpointScopeId.make("checkpoint-scope:rollback-restore-failed");
445-
const providerInstanceId = ProviderInstanceId.make("provider_rollback_restore_failed");
446-
// Checkpoint has no appRunOrdinal, so rollback targets thread_start and
447-
// never needs a provider turn; it still goes through checkpoints.restore.
448-
const restore = vi.fn(() =>
449-
Effect.fail(
450-
new CheckpointService.CheckpointRestoreError({
451-
scopeId,
452-
checkpointId,
453-
cause: restoreCause,
454-
}),
455-
),
456-
);
457-
const projection = {
458-
thread: {
459-
worktreePath: process.cwd(),
460-
activeProviderThreadId: providerThreadId,
461-
modelSelection: { instanceId: providerInstanceId, model: "test-model" },
462-
},
463-
providerThreads: [{ id: providerThreadId, providerSessionId, providerInstanceId }],
464-
providerSessions: [],
465-
checkpoints: [{ id: checkpointId, scopeId, status: "ready", appRunOrdinal: null }],
466-
checkpointScopes: [{ id: scopeId, cwd: process.cwd() }],
467-
runs: [],
468-
attempts: [],
469-
providerTurns: [],
470-
} as unknown as OrchestrationV2ThreadProjection;
471-
const layerTest = layerCheckpointRollbackService.pipe(
472-
Layer.provide(
473-
Layer.mergeAll(
474-
ThreadCommandExecutor.layer,
475-
Layer.mock(CheckpointService.CheckpointServiceV2)({ restore }),
476-
Layer.mock(EventSink.EventSinkV2)({}),
477-
IdAllocator.layer,
478-
Layer.mock(ProjectionStore.ProjectionStoreV2)({
479-
getThreadRecords: () => Effect.succeed(projection),
480-
getShellSnapshot: () =>
481-
Effect.succeed({
482-
schemaVersion: 1,
483-
snapshotSequence: 0,
484-
threads: [],
485-
archivedThreads: [],
486-
}),
487-
}),
488-
Layer.mock(ProviderSessionManager.ProviderSessionManagerV2)({
489-
open: () => Effect.succeed({} as never),
490-
}),
491-
Layer.mock(RuntimePolicy.RuntimePolicyV2)({
492-
resolve: () => Effect.succeed({} as never),
493-
}),
494-
),
495-
),
496-
);
497-
498-
return Effect.gen(function* () {
499-
const service = yield* CheckpointRollbackService.CheckpointRollbackServiceV2;
500-
const error = yield* service
501-
.execute({
502-
threadId,
503-
providerThreadId,
504-
checkpointId,
505-
scopeId,
506-
})
507-
.pipe(Effect.flip);
508-
509-
assert.equal(error.reason, "unexpected-failure");
510-
assert.equal(CheckpointRollbackService.rollbackFailureClientMessage(error), expectedMessage);
511-
assert.equal(restore.mock.calls.length, 1);
512-
}).pipe(Effect.provide(layerTest));
513-
},
514-
);
515-
516397
it.effect.each([
517398
{ order: "normal", restoreFiles: true },
518399
{ order: "cleanup-first", restoreFiles: true },

‎apps/server/src/orchestration-v2/EffectWorker.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import * as RuntimeRequestService from "./RuntimeRequestService.ts";
3535
import * as ThreadTitleRegenerationService from "./ThreadTitleRegenerationService.ts";
3636
import * as ThreadManagementService from "./ThreadManagementService.ts";
3737
import * as ServerSettings from "../serverSettings.ts";
38-
import { GIT_INDEX_LOCKED_DETAIL } from "../vcs/VcsProcess.ts";
3938

4039
const threadId = ThreadId.make("thread:effect-worker-restart");
4140
const oldSessionId = ProviderSessionId.make("provider-session:effect-worker-restart:old");
@@ -239,6 +238,8 @@ it.effect("settles a stopped run when its adapter has already lost the native tu
239238
}),
240239
);
241240

241+
const lockedIndexMessage =
242+
"Git's index is locked. Wait for other Git operations to finish, then try again.";
242243
const rollbackCheckpointId = CheckpointId.make("checkpoint:effect-worker-rollback");
243244
const rollbackScopeId = CheckpointScopeId.make("checkpoint-scope:effect-worker-rollback");
244245
const restoreFailure = (detail: string) =>
@@ -264,8 +265,8 @@ const restoreFailure = (detail: string) =>
264265
it.effect.each([
265266
{
266267
name: "a held Git index lock",
267-
failure: restoreFailure(GIT_INDEX_LOCKED_DETAIL),
268-
message: GIT_INDEX_LOCKED_DETAIL,
268+
failure: restoreFailure(lockedIndexMessage),
269+
message: lockedIndexMessage,
269270
},
270271
{
271272
name: "raw Git output",

‎apps/server/src/vcs/VcsProcess.test.ts‎

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -57,47 +57,6 @@ const captureProcessResult = (
5757
);
5858

5959
describe("VcsProcess.run", () => {
60-
it.effect.each([
61-
{
62-
name: "Windows index lock",
63-
stderr: "fatal: Unable to create 'C:\\private\\repo\\.git\\index.lock': File exists.\n",
64-
locked: true,
65-
},
66-
{
67-
name: "index permission error",
68-
stderr: "fatal: Unable to create '/private/repo/.git/index.lock': Permission denied\n",
69-
locked: false,
70-
},
71-
{
72-
name: "a different Git lock",
73-
stderr: "fatal: Unable to create '/private/repo/.git/config.lock': File exists.\n",
74-
locked: false,
75-
},
76-
])("distinguishes $name without retaining raw stderr", ({ stderr, locked }) =>
77-
Effect.gen(function* () {
78-
const error = yield* captureProcessResult(
79-
Effect.succeed({
80-
code: ChildProcessSpawner.ExitCode(128),
81-
stdout: "",
82-
stderr,
83-
stdoutTruncated: false,
84-
stderrTruncated: false,
85-
stdoutInvalidUtf8: false,
86-
stderrInvalidUtf8: false,
87-
timedOut: false,
88-
}),
89-
);
90-
expect(error).toMatchObject({
91-
failureKind: "command-failed",
92-
detail: locked
93-
? "Git's index is locked. Wait for other Git operations to finish, then try again."
94-
: "Process exited with a non-zero status.",
95-
});
96-
expect(error.message).not.toContain("private");
97-
expect(error).not.toHaveProperty("stderr");
98-
}),
99-
);
100-
10160
it.effect("explains a locked Git index and allows restore after the lock is released", () =>
10261
Effect.gen(function* () {
10362
const fs = yield* FileSystem.FileSystem;
@@ -120,7 +79,7 @@ describe("VcsProcess.run", () => {
12079
]);
12180
yield* fs.writeFileString(file, "after\n");
12281
const lock = path.join(cwd, ".git", "index.lock");
123-
yield* fs.writeFileString(lock, "");
82+
yield* fs.writeFileString(lock, "held by another process\n");
12483
const restore = ["restore", "--source=HEAD", "--worktree", "--staged", "--", "README.md"];
12584

12685
const error = yield* Effect.flip(git(restore));
@@ -131,10 +90,8 @@ describe("VcsProcess.run", () => {
13190
detail: "Git's index is locked. Wait for other Git operations to finish, then try again.",
13291
});
13392
expect(error.message).not.toContain("index.lock");
134-
expect(error.message).toContain("Git's index is locked.");
135-
expect(error).not.toHaveProperty("stderr");
13693
expect(yield* fs.readFileString(file)).toBe("after\n");
137-
expect(yield* fs.exists(lock)).toBe(true);
94+
expect(yield* fs.readFileString(lock)).toBe("held by another process\n");
13895

13996
yield* fs.remove(lock);
14097
yield* git(restore);
@@ -143,7 +100,20 @@ describe("VcsProcess.run", () => {
143100
);
144101

145102
it.effect.each([
146-
{ stderr: "fatal: Unable to create '/private/repo/index.lock': File exists", retryable: true },
103+
{
104+
stderr: "fatal: Unable to create '/private/repo/index.lock': File exists",
105+
retryable: true,
106+
detail: "Git's index is locked. Wait for other Git operations to finish, then try again.",
107+
},
108+
{
109+
stderr: "fatal: Unable to create 'C:\\private\\repo\\.git\\index.lock': File exists.",
110+
retryable: true,
111+
detail: "Git's index is locked. Wait for other Git operations to finish, then try again.",
112+
},
113+
{
114+
stderr: "fatal: Unable to create '/private/repo/.git/config.lock': File exists.",
115+
retryable: true,
116+
},
147117
{
148118
stderr: "fatal: Unable to create '/private/repo/index.lock': Permission denied",
149119
retryable: false,
@@ -160,8 +130,8 @@ describe("VcsProcess.run", () => {
160130
},
161131
{ stderr: "fatal: index file corrupt", retryable: false },
162132
])(
163-
"classifies Git exit retryability without retaining stderr: $stderr",
164-
({ stderr, retryable }) =>
133+
"classifies Git exit retryability and safe detail without retaining stderr: $stderr",
134+
({ stderr, retryable, detail = "Process exited with a non-zero status." }) =>
165135
Effect.gen(function* () {
166136
const error = yield* captureProcessResult(
167137
Effect.succeed({
@@ -177,8 +147,9 @@ describe("VcsProcess.run", () => {
177147
);
178148
assert.instanceOf(error, VcsProcessExitError);
179149
expect(error.retryable === true).toBe(retryable);
150+
expect(error.detail).toBe(detail);
180151
const encoded = yield* encodeExitError(error);
181-
expect(encoded).not.toContain("/private/repo");
152+
expect(encoded).not.toContain("private");
182153
}),
183154
);
184155

0 commit comments

Comments
 (0)