Skip to content

Commit 0f18c01

Browse files
fix(server): only the app sign-in subscribes to GitHub event streams
The API is a GitHub preview; users without the opt-in app sign-in keep polling. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7892fcd commit 0f18c01

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎packages/source-control-github/src/server/gitHubPullRequestEvents.test.ts‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { assert, it } from "@effect/vitest";
22
import * as Effect from "effect/Effect";
33
import * as Fiber from "effect/Fiber";
4+
import * as Option from "effect/Option";
45
import * as Redacted from "effect/Redacted";
56
import * as Stream from "effect/Stream";
67
import * as TestClock from "effect/testing/TestClock";
@@ -14,7 +15,7 @@ const target = { host: "github.com", repository: "pingdotgg/t3code", number: 15
1415
const sse = (...frames: ReadonlyArray<readonly [string, string]>) =>
1516
frames.map(([event, data]) => `event: ${event}\ndata: ${data}\n\n`).join("");
1617

17-
function fakeRest(subscribe: (count: number) => Effect.Effect<string>) {
18+
function fakeRest(subscribe: (count: number) => Effect.Effect<string>, signedIn = true) {
1819
const posts: Array<unknown> = [];
1920
const deletes: Array<string> = [];
2021
const rest = GitHubRest.GitHubRest.of({
@@ -42,7 +43,16 @@ function fakeRest(subscribe: (count: number) => Effect.Effect<string>) {
4243
? { token: Redacted.make("user-token"), fingerprint: "user", source: "gh" as const }
4344
: { token: Redacted.make("app-token"), fingerprint: "app", source: "app" as const },
4445
),
45-
appCredential: () => Effect.succeedNone,
46+
appCredential: () =>
47+
Effect.succeed(
48+
signedIn
49+
? Option.some({
50+
token: Redacted.make("app-token"),
51+
fingerprint: "app",
52+
source: "app" as const,
53+
})
54+
: Option.none(),
55+
),
4656
});
4757
return { rest, posts, deletes };
4858
}
@@ -103,3 +113,22 @@ it.effect("follows a pull request across a refused app token, reconnects, and re
103113
assert.deepEqual(deletes, ["event-subscriptions/1", "event-subscriptions/2"]);
104114
}),
105115
);
116+
117+
it.effect("leaves users without the app sign-in, and other hosts, to polling", () =>
118+
Effect.gen(function* () {
119+
const httpClient = HttpClient.make(() => Effect.die("no stream without a subscription"));
120+
const signedOut = fakeRest(subscription, false);
121+
assert.equal(
122+
yield* Stream.runCount(GitHubPullRequestEvents.make(signedOut.rest, httpClient)(target)),
123+
0,
124+
);
125+
126+
const signedIn = fakeRest(subscription);
127+
const enterprise = { ...target, host: "ghe.example.com" };
128+
assert.equal(
129+
yield* Stream.runCount(GitHubPullRequestEvents.make(signedIn.rest, httpClient)(enterprise)),
130+
0,
131+
);
132+
assert.equal(signedOut.posts.length + signedIn.posts.length, 0);
133+
}),
134+
);

‎packages/source-control-github/src/server/gitHubPullRequestEvents.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ export const make = (rest: GitHubRest.GitHubRest["Service"], httpClient: HttpCli
228228
),
229229
);
230230

231-
return subscribed();
231+
// Event streams are a GitHub preview, so only the app sign-in, itself opt-in, uses them.
232+
return Stream.unwrap(
233+
rest.appCredential(target.host).pipe(
234+
Effect.map((app) => (Option.isSome(app) ? subscribed() : Stream.empty)),
235+
Effect.orElseSucceed(() => Stream.empty),
236+
),
237+
);
232238
};
233239
};

0 commit comments

Comments
 (0)