Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const makeTaskFile = Effect.gen(function* () {
return { root, tasks, file: path.join(tasks, `${TASK_ID}.output`) };
});

// TestClock cannot interleave with real filesystem I/O; use the live clock.
// TestClock cannot interleave with real filesystem I/O; tests that wait on a poll use the live clock.
describe("tailClaudeTaskOutput", () => {
it.live("follows a file that appears after the task starts, across split characters", () =>
Effect.scoped(
Expand Down Expand Up @@ -48,6 +48,32 @@ describe("tailClaudeTaskOutput", () => {
).pipe(Effect.provide(NodeServices.layer)),
);

it.effect("drops a split character when the file is truncated and rewritten", () =>
Effect.scoped(
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const { root, tasks, file } = yield* makeTaskFile;
yield* fileSystem.makeDirectory(tasks, { recursive: true });
// End the first read inside the two-byte é.
yield* fileSystem.writeFile(file, new TextEncoder().encode("café").subarray(0, 4));
const chunks = yield* Queue.unbounded<string>();
const stop = yield* Deferred.make<void>();
yield* tailClaudeTaskOutput({
root,
sessionId: SESSION_ID,
taskId: TASK_ID,
stop,
onChunk: (chunk) => Queue.offer(chunks, chunk),
}).pipe(Effect.forkScoped);
assert.equal(yield* Queue.take(chunks), "caf");

yield* fileSystem.writeFileString(file, "ok\n");
yield* Deferred.succeed(stop, undefined);
assert.equal(yield* Queue.take(chunks), "ok\n");
}),
).pipe(Effect.provide(NodeServices.layer)),
);

it.live("skips ahead when the command writes faster than it is read", () =>
Effect.scoped(
Effect.gen(function* () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export const tailClaudeTaskOutput = Effect.fn("ClaudeTaskOutputTail.tail")(funct
Effect.map((info) => Number(info.size)),
Effect.orElseSucceed(() => offset),
);
if (size < offset) offset = 0;
if (size < offset) {
offset = 0;
decoder = new TextDecoder("utf-8", { fatal: false });
}
if (size > offset) {
const start = size - offset > MAX_READ_BYTES ? size - MAX_READ_BYTES : offset;
const bytes = yield* Effect.scoped(
Expand Down
Loading