Skip to content

Commit 39f747e

Browse files
fix(prs): keep removed stack links dismissed
1 parent 9619ccd commit 39f747e

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

‎apps/server/src/orchestration/decider.pullRequests.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,61 @@ it.layer(NodeServices.layer)("pull request link decider", (it) => {
315315
}),
316316
);
317317

318+
for (const source of ["manual", "agent", "created"] as const) {
319+
it.effect(`unlinking a ${source} member prevents its sibling rediscovering it`, () =>
320+
Effect.gen(function* () {
321+
const member = makeLink({ source });
322+
const sibling = makeLink({
323+
number: 43,
324+
source: "stack",
325+
stack: {
326+
kind: "native",
327+
id: "stack-1",
328+
number: 1,
329+
url: "https://github.com/t3tools/t3code/stack/1",
330+
base: "main",
331+
layers: [
332+
{ number: 42, headBranch: "first", state: "open" },
333+
{ number: 43, headBranch: "second", state: "open" },
334+
],
335+
},
336+
});
337+
let model = makeReadModel([member, sibling]);
338+
const decided = yield* decideOrchestrationCommand({
339+
readModel: model,
340+
command: {
341+
type: "thread.pull-request.unlink",
342+
commandId: CommandId.make("remove"),
343+
threadId: THREAD_ID,
344+
host: member.host,
345+
repository: member.repository,
346+
number: member.number,
347+
},
348+
});
349+
const event = expectSingleEvent(decided, "thread.pull-request-linked");
350+
model = yield* projectEvent(model, { ...event, sequence: 1 });
351+
expect(model.threads[0]!.pullRequests).toEqual([
352+
{ ...member, source: "stack-dismissed" },
353+
sibling,
354+
]);
355+
const rediscovered = yield* decideOrchestrationCommand({
356+
readModel: model,
357+
command: {
358+
type: "thread.pull-request.link",
359+
commandId: CommandId.make("rediscovered"),
360+
threadId: THREAD_ID,
361+
host: member.host,
362+
repository: member.repository,
363+
number: member.number,
364+
url: member.url,
365+
source: "stack",
366+
},
367+
}).pipe(Effect.result);
368+
expect(rediscovered._tag).toBe("Failure");
369+
}),
370+
);
371+
}
372+
318373
it.effect("rejects unlinking a pull request that is not linked", () =>
319374
Effect.gen(function* () {
320375
const error = yield* decideOrchestrationCommand({

‎apps/server/src/orchestration/decider.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,18 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
10751075
occurredAt,
10761076
commandId: command.commandId,
10771077
});
1078-
// A host-discovered stack member leaves a tombstone instead of a hole,
1079-
// so the next sync does not re-add what the user just removed.
1080-
if (existing.source === "stack") {
1078+
// Any known native-stack member needs a tombstone, regardless of who linked it.
1079+
// A sibling can rediscover it even before this link has its own stack snapshot.
1080+
const belongsToStack =
1081+
existing.source === "stack" ||
1082+
existing.stack !== null ||
1083+
thread.pullRequests.some(
1084+
(link) =>
1085+
link.host.toLowerCase() === key.host &&
1086+
link.repository.toLowerCase() === key.repository &&
1087+
link.stack?.layers.some((layer) => layer.number === key.number),
1088+
);
1089+
if (belongsToStack) {
10811090
return {
10821091
...eventBase,
10831092
type: "thread.pull-request-linked",

0 commit comments

Comments
 (0)