Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b96a27717d |
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it, describe } from "@effect/vitest";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
@@ -8,11 +9,16 @@ import * as PlatformError from "effect/PlatformError";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Sink from "effect/Sink";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import { GitCommandError } from "@t3tools/contracts";
|
||||
import { ServerConfig } from "../config.ts";
|
||||
import { splitNullSeparatedGitStdoutPaths } from "./GitVcsDriverCore.ts";
|
||||
import {
|
||||
makeGitVcsDriverCore,
|
||||
splitNullSeparatedGitStdoutPaths,
|
||||
WORKTREE_REMOVE_TIMEOUT_MS,
|
||||
} from "./GitVcsDriverCore.ts";
|
||||
import * as GitVcsDriver from "./GitVcsDriver.ts";
|
||||
|
||||
const ServerConfigLayer = ServerConfig.layerTest(process.cwd(), {
|
||||
@@ -38,6 +44,55 @@ const makeNonRepositoryHandle = () =>
|
||||
getOutputFd: () => Stream.empty,
|
||||
});
|
||||
|
||||
const makeWorktreeRemovalLayer = (input: {
|
||||
readonly exitCode: Effect.Effect<ChildProcessSpawner.ExitCode>;
|
||||
readonly commands: Array<ReadonlyArray<string>>;
|
||||
readonly timeoutMs?: number;
|
||||
}) => {
|
||||
const spawner = ChildProcessSpawner.make((command) =>
|
||||
Effect.sync(() => {
|
||||
if (!ChildProcess.isStandardCommand(command)) {
|
||||
return assert.fail("expected a standard Git command");
|
||||
}
|
||||
input.commands.push(command.args);
|
||||
let running = true;
|
||||
return ChildProcessSpawner.makeHandle({
|
||||
pid: ChildProcessSpawner.ProcessId(1),
|
||||
exitCode: input.exitCode.pipe(
|
||||
Effect.tap(() =>
|
||||
Effect.sync(() => {
|
||||
running = false;
|
||||
}),
|
||||
),
|
||||
),
|
||||
isRunning: Effect.sync(() => running),
|
||||
kill: () =>
|
||||
Effect.sync(() => {
|
||||
running = false;
|
||||
}),
|
||||
unref: Effect.succeed(Effect.void),
|
||||
stdin: Sink.drain,
|
||||
stdout: Stream.empty,
|
||||
stderr: Stream.empty,
|
||||
all: Stream.empty,
|
||||
getInputFd: () => Sink.drain,
|
||||
getOutputFd: () => Stream.empty,
|
||||
});
|
||||
}),
|
||||
);
|
||||
const nodeServicesLayer = Layer.merge(
|
||||
NodeServices.layer,
|
||||
Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
|
||||
);
|
||||
|
||||
return Layer.effect(
|
||||
GitVcsDriver.GitVcsDriver,
|
||||
makeGitVcsDriverCore(
|
||||
input.timeoutMs === undefined ? {} : { worktreeRemoveTimeoutMs: input.timeoutMs },
|
||||
),
|
||||
).pipe(Layer.provide(ServerConfigLayer), Layer.provideMerge(nodeServicesLayer));
|
||||
};
|
||||
|
||||
const makeTmpDir = (
|
||||
prefix = "git-vcs-driver-test-",
|
||||
): Effect.Effect<string, PlatformError.PlatformError, FileSystem.FileSystem | Scope.Scope> =>
|
||||
@@ -641,6 +696,53 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
|
||||
});
|
||||
|
||||
describe("worktree operations", () => {
|
||||
it.effect("uses the extended deadline while allowing a slow worktree removal", () => {
|
||||
const commands: Array<ReadonlyArray<string>> = [];
|
||||
const layer = makeWorktreeRemovalLayer({
|
||||
commands,
|
||||
exitCode: Effect.sleep(Duration.millis(50)).pipe(
|
||||
Effect.as(ChildProcessSpawner.ExitCode(0)),
|
||||
),
|
||||
timeoutMs: 100,
|
||||
});
|
||||
|
||||
return TestClock.withLive(
|
||||
Effect.gen(function* () {
|
||||
assert.equal(WORKTREE_REMOVE_TIMEOUT_MS, 300_000);
|
||||
const driver = yield* GitVcsDriver.GitVcsDriver;
|
||||
yield* driver.removeWorktree({ cwd: "/repo", path: "/repo-worktrees/feature" });
|
||||
|
||||
assert.deepStrictEqual(commands, [["worktree", "remove", "/repo-worktrees/feature"]]);
|
||||
}).pipe(Effect.provide(layer)),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("still fails a worktree removal that exceeds its cleanup deadline", () => {
|
||||
const commands: Array<ReadonlyArray<string>> = [];
|
||||
const layer = makeWorktreeRemovalLayer({
|
||||
commands,
|
||||
exitCode: Effect.never,
|
||||
timeoutMs: 25,
|
||||
});
|
||||
|
||||
return TestClock.withLive(
|
||||
Effect.gen(function* () {
|
||||
const driver = yield* GitVcsDriver.GitVcsDriver;
|
||||
const error = yield* driver
|
||||
.removeWorktree({ cwd: "/repo", path: "/repo-worktrees/stuck" })
|
||||
.pipe(Effect.flip);
|
||||
|
||||
assert.deepInclude(error, {
|
||||
_tag: "GitCommandError",
|
||||
operation: "GitVcsDriver.removeWorktree",
|
||||
detail: "Git command timed out.",
|
||||
cwd: "/repo",
|
||||
});
|
||||
assert.deepStrictEqual(commands, [["worktree", "remove", "/repo-worktrees/stuck"]]);
|
||||
}).pipe(Effect.provide(layer)),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("creates and removes a worktree for a new refName", () =>
|
||||
Effect.gen(function* () {
|
||||
const cwd = yield* makeTmpDir();
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
import { ServerConfig } from "../config.ts";
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 30_000;
|
||||
export const WORKTREE_REMOVE_TIMEOUT_MS = Duration.toMillis(Duration.minutes(5));
|
||||
const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000;
|
||||
const OUTPUT_TRUNCATED_MARKER = "\n\n[truncated]";
|
||||
const PREPARED_COMMIT_PATCH_MAX_OUTPUT_BYTES = 49_000;
|
||||
@@ -642,7 +643,13 @@ const collectOutput = Effect.fnUntraced(function* (
|
||||
};
|
||||
});
|
||||
|
||||
export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* () {
|
||||
export interface GitVcsDriverCoreOptions {
|
||||
readonly worktreeRemoveTimeoutMs?: number;
|
||||
}
|
||||
|
||||
export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* (
|
||||
options: GitVcsDriverCoreOptions = {},
|
||||
) {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
@@ -2395,7 +2402,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
|
||||
}
|
||||
args.push(input.path);
|
||||
yield* executeGit("GitVcsDriver.removeWorktree", input.cwd, args, {
|
||||
timeoutMs: 15_000,
|
||||
// Removing untracked dependency trees is filesystem-bound and can take
|
||||
// minutes on Windows. Keep the operation supervised, but give it a
|
||||
// cleanup-specific ceiling instead of the short interactive deadline.
|
||||
timeoutMs: options.worktreeRemoveTimeoutMs ?? WORKTREE_REMOVE_TIMEOUT_MS,
|
||||
fallbackErrorDetail: "git worktree remove failed",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
import { EventId, TurnId, type OrchestrationThreadActivity } from "@t3tools/contracts";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { deriveWorkLogEntries } from "./session-logic";
|
||||
|
||||
function makeCommandActivity(
|
||||
id: string,
|
||||
payload: Record<string, unknown>,
|
||||
): OrchestrationThreadActivity {
|
||||
return {
|
||||
id: EventId.make(id),
|
||||
createdAt: "2026-07-17T10:00:00.000Z",
|
||||
kind: "tool.completed",
|
||||
summary: "Ran command",
|
||||
tone: "tool",
|
||||
payload,
|
||||
turnId: TurnId.make("turn-1"),
|
||||
};
|
||||
}
|
||||
|
||||
describe("deriveWorkLogEntries command output", () => {
|
||||
it("uses Codex aggregated output instead of repeating the command", () => {
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("codex-command", {
|
||||
itemType: "command_execution",
|
||||
title: "Ran command",
|
||||
detail: "/bin/zsh -lc \"printf 'hello\\n'\"",
|
||||
data: {
|
||||
item: {
|
||||
type: "commandExecution",
|
||||
command: "/bin/zsh -lc \"printf 'hello\\n'\"",
|
||||
commandActions: [{ command: "printf 'hello\\n'", type: "unknown" }],
|
||||
aggregatedOutput: "hello\n<exited with exit code 0>",
|
||||
status: "completed",
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(entry).toMatchObject({
|
||||
command: "printf 'hello\\n'",
|
||||
rawCommand: "/bin/zsh -lc \"printf 'hello\\n'\"",
|
||||
detail: "hello",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses Claude ACP stdout instead of repeating the command", () => {
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("claude-command", {
|
||||
itemType: "command_execution",
|
||||
title: "Ran command",
|
||||
detail: "printf hello",
|
||||
data: {
|
||||
kind: "execute",
|
||||
command: "printf hello",
|
||||
rawOutput: {
|
||||
stdout: "hello from claude\n",
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(entry).toMatchObject({
|
||||
command: "printf hello",
|
||||
detail: "hello from claude",
|
||||
});
|
||||
});
|
||||
|
||||
it("drops duplicated command detail when the command has no output", () => {
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("empty-command", {
|
||||
itemType: "command_execution",
|
||||
title: "Ran command",
|
||||
detail: "true",
|
||||
data: {
|
||||
kind: "execute",
|
||||
command: "true",
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(entry?.command).toBe("true");
|
||||
expect(entry?.detail).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -1149,70 +1149,6 @@ function summarizeToolRawOutput(payload: Record<string, unknown> | null): string
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractAcpTextContent(value: unknown): string | null {
|
||||
if (!Array.isArray(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const chunks: string[] = [];
|
||||
for (const entryValue of value) {
|
||||
const entry = asRecord(entryValue);
|
||||
if (entry?.type !== "content") {
|
||||
continue;
|
||||
}
|
||||
const content = asRecord(entry.content);
|
||||
if (content?.type !== "text") {
|
||||
continue;
|
||||
}
|
||||
const text = asTrimmedString(content.text);
|
||||
if (text) {
|
||||
chunks.push(text);
|
||||
}
|
||||
}
|
||||
|
||||
return chunks.length > 0 ? chunks.join("\n") : null;
|
||||
}
|
||||
|
||||
function extractToolOutput(payload: Record<string, unknown> | null): string | null {
|
||||
const data = asRecord(payload?.data);
|
||||
const item = asRecord(data?.item);
|
||||
const itemResult = asRecord(item?.result);
|
||||
const rawOutput = asRecord(data?.rawOutput);
|
||||
|
||||
const outputStreams: string[] = [];
|
||||
const stdout = asTrimmedString(rawOutput?.stdout);
|
||||
const stderr = asTrimmedString(rawOutput?.stderr);
|
||||
if (stdout) {
|
||||
outputStreams.push(stdout);
|
||||
}
|
||||
if (stderr) {
|
||||
outputStreams.push(stderr);
|
||||
}
|
||||
|
||||
const candidates: unknown[] = [
|
||||
item?.aggregatedOutput,
|
||||
itemResult?.content,
|
||||
data?.rawOutput,
|
||||
rawOutput?.content,
|
||||
outputStreams.length > 0 ? outputStreams.join("\n") : null,
|
||||
rawOutput?.output,
|
||||
extractAcpTextContent(data?.content),
|
||||
];
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const text = asTrimmedString(candidate);
|
||||
if (!text) {
|
||||
continue;
|
||||
}
|
||||
const output = stripTrailingExitCode(text).output;
|
||||
if (output) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function isCommandToolDetail(payload: Record<string, unknown> | null, heading: string): boolean {
|
||||
const data = asRecord(payload?.data);
|
||||
const kind = asTrimmedString(data?.kind)?.toLowerCase();
|
||||
@@ -1233,37 +1169,12 @@ function extractToolDetail(
|
||||
const detail = rawDetail ? stripTrailingExitCode(rawDetail).output : null;
|
||||
const normalizedHeading = normalizePreviewForComparison(heading);
|
||||
const normalizedDetail = normalizePreviewForComparison(detail);
|
||||
const commandTool = isCommandToolDetail(payload, heading);
|
||||
const commandPreview = commandTool
|
||||
? extractToolCommand(payload)
|
||||
: { command: null, rawCommand: null };
|
||||
const command = commandPreview.command;
|
||||
const normalizedCommand = normalizePreviewForComparison(command);
|
||||
const normalizedRawCommand = normalizePreviewForComparison(commandPreview.rawCommand);
|
||||
|
||||
if (
|
||||
detail &&
|
||||
normalizedHeading !== normalizedDetail &&
|
||||
(!commandTool ||
|
||||
(normalizedCommand !== normalizedDetail && normalizedRawCommand !== normalizedDetail))
|
||||
) {
|
||||
if (detail && normalizedHeading !== normalizedDetail) {
|
||||
return detail;
|
||||
}
|
||||
|
||||
if (commandTool) {
|
||||
if (!command) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const output = extractToolOutput(payload);
|
||||
const normalizedOutput = normalizePreviewForComparison(output);
|
||||
if (
|
||||
output &&
|
||||
normalizedOutput !== normalizedHeading &&
|
||||
normalizedOutput !== normalizedCommand
|
||||
) {
|
||||
return output;
|
||||
}
|
||||
if (isCommandToolDetail(payload, heading)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user