@devries-cameron20 / t3code Mirror · read-only / commits / 3bd6709181
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 01:45 UTC

fix(bitbucket): advance pull request pages through tied updates (#18813)

Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 07:27 UTC 3bd670918127b3af15dcbb0102ad87fbca28ccaf
4 files changed +98 -9
apps/server/src/pullRequest/PullRequestService.test.ts
+83 -2
@@ -36,6 +36,9 @@ import * as SourceControlProviderRegistry from "../sourceControl/SourceControlPr
36 import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
37 import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";
38 import * as ForgejoPullRequestProvider from "@t3tools/source-control-forgejo/server/ForgejoPullRequestProvider";
39 +import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";
40 +import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestApi";
41 +import * as BitbucketPullRequestProvider from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestProvider";
42 import * as GitHubRest from "@t3tools/source-control-github/server/GitHubRest";
43 import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";
44 import * as GitHubPullRequestApi from "@t3tools/source-control-github/server/GitHubPullRequestApi";
@@ -921,6 +924,82 @@ it.effect("uses a provider's raw cursor advance when it consumed malformed rows"
924 }),
925 );
926
927 +it.effect("continues Bitbucket listings through tied timestamps and terminates", () =>
928 + Effect.gen(function* () {
929 + const boundary = "2026-10-12T00:00:00.000Z";
930 + const older = "2026-10-11T00:00:00.000Z";
931 + const rows = [1, 2, 3, 4, 5].map((id) => ({
932 + id,
933 + title: `Pull request ${id}`,
934 + state: "OPEN",
935 + created_on: older,
936 + updated_on: id <= 3 ? boundary : older,
937 + source: { branch: { name: `feat/${id}` } },
938 + destination: { branch: { name: "main" } },
939 + links: { html: { href: `https://bitbucket.org/acme/web/pull-requests/${id}` } },
940 + }));
941 + const provider = yield* BitbucketPullRequestProvider.make.pipe(
942 + Effect.provide(
943 + BitbucketPullRequestApi.layer.pipe(
944 + Layer.provide(
945 + Layer.mock(BitbucketApi.BitbucketApi)({
946 + request: ({ url }) => {
947 + if (url === "/user") {
948 + return Effect.succeed({
949 + body: JSON.stringify({ nickname: "bilal" }),
950 + truncated: false,
951 + });
952 + }
953 + const filter =
954 + new URL(url, "https://api.bitbucket.org").searchParams.get("q") ?? "";
955 + const updatedBefore = /updated_on <= (\S+)/.exec(filter)?.[1];
956 + const excluded = new Set(
957 + Array.from(filter.matchAll(/id != (\d+)/g), (match) => Number(match[1])),
958 + );
959 + const values = rows.filter(
960 + (row) =>
961 + (updatedBefore === undefined || row.updated_on <= updatedBefore) &&
962 + !excluded.has(row.id),
963 + );
964 + return Effect.succeed({ body: JSON.stringify({ values }), truncated: false });
965 + },
966 + }),
967 + ),
968 + ),
969 + ),
970 + );
971 + const service = yield* makeService({
972 + projects: [
973 + project({
974 + id: "p1",
975 + title: "web",
976 + workspaceRoot: "/w",
977 + repository: "acme/web",
978 + provider: "bitbucket",
979 + host: "bitbucket.org",
980 + }),
981 + ],
982 + providers: [provider],
983 + });
984 + let page = yield* service.list({ state: "open", limit: 2 });
985 + assert.deepStrictEqual(
986 + page.entries.map((entry) => entry.number),
987 + [1, 2],
988 + );
989 + for (const expected of [[3, 4], [5]]) {
990 + assert.isTrue(page.truncated);
991 + assert.isNotEmpty(page.nextCursors);
992 + page = yield* service.list({ state: "open", limit: 2, cursors: page.nextCursors });
993 + assert.deepStrictEqual(
994 + page.entries.map((entry) => entry.number),
995 + expected,
996 + );
997 + }
998 + assert.isFalse(page.truncated);
999 + assert.deepStrictEqual(page.nextCursors, {});
1000 + }),
1001 +);
1002 +
1003 it.effect("reads only the repositories it was asked to carry on with", () =>
1004 Effect.gen(function* () {
1005 const listed: string[] = [];
@@ -947,7 +1026,9 @@ it.effect("reads only the repositories it was asked to carry on with", () =>
1026 });
1027
1028 assert.deepStrictEqual(listed, ["acme/web"]);
950 - assert.deepStrictEqual(cursors, [{ updatedBefore: "2026-07-02T00:00:00Z", delivered: 99 }]);
1029 + assert.deepStrictEqual(cursors, [
1030 + { updatedBefore: "2026-07-02T00:00:00Z", delivered: 99, seenAt: [7] },
1031 + ]);
1032 assert.strictEqual(result.providers.length, 1);
1033 }),
1034 );
@@ -4554,7 +4635,7 @@ it.effect("carries a slice on without sending the rows it already sent", () =>
4635 [4],
4636 );
4637 assert.deepStrictEqual(result.nextCursors, {
4557 - "github.com acme/web": "2026-07-02T00:00:00Z|2|3,3,4",
4638 + "github.com acme/web": "2026-07-02T00:00:00Z|2|3,4",
4639 });
4640 }),
4641 );
apps/server/src/pullRequest/PullRequestService.ts
+8 -4
@@ -376,11 +376,11 @@ function listCursorAt(
376 fetched: ReadonlyArray<ProviderChangeRequest>,
377 deliveredCount: number,
378 ): string {
379 - const seenAt = [
379 + const seenAt = new Set([
380 ...(previous?.updatedBefore === boundary ? previous.seenAt : []),
381 ...fetched.filter((item) => item.updatedAt === boundary).map((item) => item.number),
382 - ];
383 - return `${boundary}|${(previous?.delivered ?? 0) + deliveredCount}|${seenAt.join(",")}`;
382 + ]);
383 + return `${boundary}|${(previous?.delivered ?? 0) + deliveredCount}|${[...seenAt].join(",")}`;
384 }
385
386 function isProviderUnusable(error: PullRequestProviderError): boolean {
@@ -1176,7 +1176,11 @@ export const make = Effect.gen(function* () {
1176 ...(cursor === undefined
1177 ? {}
1178 : {
1179 - cursor: { updatedBefore: cursor.updatedBefore, delivered: cursor.delivered },
1179 + cursor: {
1180 + updatedBefore: cursor.updatedBefore,
1181 + delivered: cursor.delivered,
1182 + seenAt: cursor.seenAt,
1183 + },
1184 }),
1185 })
1186 .pipe(
packages/source-control-bitbucket/src/server/BitbucketPullRequestApi.ts
+2 -3
@@ -561,12 +561,11 @@ export const make = Effect.gen(function* () {
561 listPullRequests: (input) =>
562 withRepository(input.repository, (path) => {
563 const search = input.query?.trim() ?? "";
564 - // The boundary instant is read inclusively — the rows already sent at it come back and
565 - // the caller drops them, which is what keeps their neighbours at the same instant from
566 - // being skipped.
564 + // Exclude already-sent IDs at the inclusive timestamp before applying the page limit.
565 const predicates = [
566 ...(search.length === 0 ? [] : [searchFilter(search)]),
567 ...(input.cursor === undefined ? [] : [`updated_on <= ${input.cursor.updatedBefore}`]),
568 + ...(input.cursor?.seenAt ?? []).map((number) => `id != ${number}`),
569 ];
570 return listPage({
571 // Reviewers are not on a listing by default, and `viewerReviewRequested` needs them.
packages/source-control-core/src/server/PullRequestProvider.ts
+5
@@ -155,6 +155,11 @@ export interface ProviderListCursor {
155 */
156 readonly updatedBefore: string;
157 readonly delivered: number;
158 + /**
159 + * Rows already handed over at `updatedBefore`. Timestamp-paged hosts can exclude these before
160 + * applying their limit so a full page of tied updates does not repeat the same prefix.
161 + */
162 + readonly seenAt?: ReadonlyArray<number> | undefined;
163 }
164
165 export interface ProviderBatchedChangeRequest extends ProviderChangeRequest {