fix(pull-requests): shared state + not settling? (#9332)

Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
mariaandmaria-rcks authored and GitHub committed 2026-09-03 01:47:41 -04:00
1 parent 48ba76bc26
commit 854541a04e
9 files changed
+440 -166

No files matched your search

@@ -1,7 +1,10 @@
import { assert, it } from "@effect/vitest";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";
import type {
OrchestrationProjectShell,
@@ -1002,6 +1005,41 @@ it.effect("refuses an action the host never claimed it could run", () =>
}),
);
it.effect("publishes a successful merge for immediate settlement", () =>
Effect.scoped(
Effect.gen(function* () {
const mergedAt = "2026-09-03T02:00:00.000Z";
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
const service = yield* makeService({
projects: [
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
],
providers: [
fakeProvider("github", {
runAction: () => TestClock.setTime(Date.parse(mergedAt)),
}),
],
});
const merges = yield* service.subscribeMerges;
const observedMerge = yield* Stream.runHead(merges).pipe(
Effect.forkChild({ startImmediately: true }),
);
yield* service.runAction({
...reference,
repository: " ACME/WEB ",
action: "merge",
mergeMethod: "merge",
});
assert.deepStrictEqual(Option.getOrThrow(yield* Fiber.join(observedMerge)), {
...reference,
mergedAt,
});
}),
),
);
it.effect("refuses an action this viewer may not take, and says what access it takes", () =>
Effect.gen(function* () {
let ran: string | null = null;
@@ -3192,6 +3230,32 @@ it.effect("does not ask the host again for a linked summary it already holds", (
}),
);
it.effect("reuses an observed merged state for strict settlement reads", () =>
Effect.gen(function* () {
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
const service = yield* makeService({
projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
providers: [
fakeProvider("github", {
getChangeRequest: () =>
Effect.succeed({
...hostedChangeRequest("merged body", 4),
state: "merged",
updatedAt: "2026-07-03T00:00:00Z",
}),
getChangeRequestSummary: () => Effect.die("strict merged state must not refresh"),
}),
],
});
yield* service.detail(reference);
const summary = yield* service.summary(reference, { recoverTransientFailure: false });
assert.strictEqual(summary.state, "merged");
assert.strictEqual(summary.updatedAt, "2026-07-03T00:00:00Z");
}),
);
it.effect("does not let a stale detail reopen overwrite a fresher linked summary", () =>
Effect.gen(function* () {
const gate = yield* Deferred.make<void>();