Skip to content

Commit b61a561

Browse files
committed
fix(server): guest links no longer return file diffs
1 parent 5211acf commit b61a561

2 files changed

Lines changed: 46 additions & 13 deletions

File tree

‎apps/server/src/guest/GuestShareService.test.ts‎

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ it.effect("serves no render for an item outside the shared thread", () =>
411411
}).pipe(Effect.provide(layerTest)),
412412
);
413413

414-
/** A message from the owner, which opens a run for the command below. */
415414
const ownerRun = Effect.gen(function* () {
416415
const orchestrator = yield* Orchestrator.OrchestratorV2;
417416
yield* orchestrator.dispatch({
@@ -430,12 +429,17 @@ const ownerRun = Effect.gen(function* () {
430429
return runs[0]!.id;
431430
});
432431

433-
const writeCommand = (
432+
const writeItem = (
434433
id: string,
435-
fields: Pick<
436-
Extract<OrchestrationV2TurnItem, { type: "command_execution" }>,
437-
"status" | "output"
438-
>,
434+
fields:
435+
| Pick<
436+
Extract<OrchestrationV2TurnItem, { type: "command_execution" }>,
437+
"type" | "status" | "input" | "output"
438+
>
439+
| Pick<
440+
Extract<OrchestrationV2TurnItem, { type: "file_change" }>,
441+
"type" | "status" | "fileName" | "diffStr" | "oldStr" | "newStr"
442+
>,
439443
) =>
440444
Effect.gen(function* () {
441445
const runId = yield* ownerRun;
@@ -464,8 +468,6 @@ const writeCommand = (
464468
startedAt: now,
465469
completedAt: fields.status === "running" ? null : now,
466470
updatedAt: now,
467-
type: "command_execution",
468-
input: "ls /work/src",
469471
...fields,
470472
},
471473
},
@@ -474,17 +476,40 @@ const writeCommand = (
474476
return TurnItemId.make(id);
475477
});
476478

477-
it.effect("gives the guest a command's detail and output, as the owner's row loads them", () =>
479+
it.effect("gives the guest a command's detail and output, but no file diffs", () =>
478480
Effect.gen(function* () {
479481
const { guestShares, credential } = yield* shareThread;
480482
const { token: session } = yield* guestShares.redeem({ credential, name: "Sam" });
481-
const command = yield* writeCommand("item:command", {
483+
const command = yield* writeItem("item:command", {
484+
type: "command_execution",
482485
status: "completed",
486+
input: "ls /work/src",
483487
output: "/work/src/auth.ts\n",
484488
});
485489

486490
const detail = (yield* guestShares.item(session, command)).item;
487491
assert.deepInclude(detail, { input: "ls /work/src", output: "/work/src/auth.ts\n" });
492+
const edit = yield* writeItem("item:edit", {
493+
type: "file_change",
494+
status: "completed",
495+
fileName: "src/auth.ts",
496+
diffStr: "-const token = 1;\n+const token = 2;\n",
497+
});
498+
const write = yield* writeItem("item:write", {
499+
type: "file_change",
500+
status: "completed",
501+
fileName: "src/config.ts",
502+
oldStr: "",
503+
newStr: "export const key = 1;\n",
504+
});
505+
for (const [id, fileName] of [
506+
[edit, "src/auth.ts"],
507+
[write, "src/config.ts"],
508+
] as const) {
509+
const change = (yield* guestShares.item(session, id)).item;
510+
assert.deepInclude(change, { type: "file_change", fileName });
511+
assert.doesNotHaveAnyKeys(change, ["diffStr", "oldStr", "newStr"]);
512+
}
488513
const frames = Array.from(
489514
yield* Stream.runCollect(yield* guestShares.commandOutput(session, command)),
490515
);
@@ -508,7 +533,11 @@ it.effect("ends a running command's output once the owner stops sharing", () =>
508533
Effect.gen(function* () {
509534
const { orchestrator, guestShares, credential } = yield* shareThread;
510535
const { token: session } = yield* guestShares.redeem({ credential, name: "Sam" });
511-
const command = yield* writeCommand("item:running", { status: "running" });
536+
const command = yield* writeItem("item:running", {
537+
type: "command_execution",
538+
status: "running",
539+
input: "ls /work/src",
540+
});
512541
const collecting = yield* Stream.runCollect(
513542
yield* guestShares.commandOutput(session, command),
514543
).pipe(Effect.forkChild);

‎apps/server/src/guest/GuestShareService.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { buildBoundedThreadStreamSnapshot } from "../orchestration-v2/ThreadStre
5757
import {
5858
projectDomainEventForWire,
5959
projectTurnItemForDetail,
60+
projectTurnItemForWire,
6061
} from "../orchestration-v2/WireProjection.ts";
6162
import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
6263
import * as ServerSettings from "../serverSettings.ts";
@@ -179,7 +180,7 @@ export class GuestShareService extends Context.Service<
179180
session: string,
180181
itemId: string,
181182
) => Effect.Effect<{ readonly path: string; readonly title: string }, GuestShareAccessError>;
182-
/** One item of the shared thread, as the owner's expanded row loads it. */
183+
/** One item of the shared thread, as the owner's expanded row loads it, without file diffs. */
183184
readonly item: (
184185
session: string,
185186
itemId: string,
@@ -658,7 +659,10 @@ const make = Effect.gen(function* () {
658659

659660
const item = Effect.fn("GuestShareService.item")(function* (session: string, itemId: string) {
660661
const { item } = yield* threadItem(session, itemId);
661-
return { item: projectTurnItemForDetail(item) };
662+
return {
663+
item:
664+
item.type === "file_change" ? projectTurnItemForWire(item) : projectTurnItemForDetail(item),
665+
};
662666
});
663667

664668
const commandOutput = Effect.fn("GuestShareService.commandOutput")(function* (

0 commit comments

Comments
 (0)