GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(gitlab): mark threads outdated after their diff line changes by shivamhwp · Pull Request #30451 · pingdotgg/t3code

fix(gitlab): mark threads outdated after their diff line changes #30451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shivamhwp wants to merge 3 commits into pingdotgg:main from shivamhwp:issue-watch/30422

Uh oh!

There was an error while loading. Please reload this page.

Closed

fix(gitlab): mark threads outdated after their diff line changes #30451

Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
fac7f71
fix(gitlab): mark threads outdated after their diff line changes
shivamhwp Nov 3, 2026
8a773f0
fix(gitlab): preserve rate limits when reading thread refs
shivamhwp Nov 3, 2026
72fe517
chore(gitlab): integrate current main and preserve discussion coverage
shivamhwp Nov 5, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

193 changes: 151 additions & 42 deletions 193 packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -831,63 +831,172 @@ layer("GitLabPullRequestCli.layer", (it) => {
}),
);

it.effect("reads a positioned discussion as a thread anchored to its line", () =>
it.effect("reads positioned discussions as threads, outdated once their line left the diff", () =>
Effect.gen(function* () {
mockedExecute.mockReturnValueOnce(
Effect.succeed(
output(
JSON.stringify([
const position = (newLine: number, refs: Record<string, string>) => ({
position_type: "text",
new_path: "src/a.ts",
old_path: "src/a.ts",
new_line: newLine,
old_line: null,
...refs,
});
const pushed = { base_sha: "base", start_sha: "base", head_sha: "head2" };
// GitLab moves a position onto each new diff while its line survives.
const discussionsAfterPush = (untouchedRefs: Record<string, string>) =>
JSON.stringify([
{
id: "untouched",
notes: [
{
id: "abc123",
notes: [
{
id: 1,
body: "rename this",
author: { username: "bilal", avatar_url: "https://avatars/b.png" },
created_at: "2026-07-01T00:00:00Z",
resolvable: true,
resolved: true,
position: {
position_type: "text",
new_path: "src/a.ts",
old_path: "src/a.ts",
new_line: 12,
old_line: null,
},
},
{
id: 2,
body: "done",
author: { username: "julius" },
created_at: "2026-07-01T01:00:00Z",
},
],
id: 1,
body: "rename this",
author: { username: "bilal", avatar_url: "https://avatars/b.png" },
created_at: "2026-07-01T00:00:00Z",
resolvable: true,
resolved: true,
position: position(12, untouchedRefs),
},
{ id: "def456", notes: [{ id: 3, body: "ship it", created_at: "2026-07-01Z" }] },
]),
{
id: 2,
body: "done",
author: { username: "julius" },
created_at: "2026-07-01T01:00:00Z",
},
],
},
{
id: "changed",
notes: [
{
id: 4,
body: "this line",
created_at: "2026-07-01Z",
position: position(20, { base_sha: "base", start_sha: "base", head_sha: "head1" }),
},
],
},
{
id: "unknown",
notes: [
{
id: 5,
body: "no refs",
created_at: "2026-07-01Z",
position: position(30, { base_sha: "base", head_sha: "head1" }),
},
],
},
{ id: "def456", notes: [{ id: 3, body: "ship it", created_at: "2026-07-01Z" }] },
]);
const host = { refs: { base_sha: "base", start_sha: "base", head_sha: "head1" }, after: "" };
mockedExecute.mockImplementation(({ args }) =>
Effect.succeed(
output(
args[1]?.includes("/discussions")
? host.after
: mergeRequestJson({ diff_refs: host.refs }),
),
),
);
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;

const { threads } = yield* cli.listDiscussions({
cwd: "/w",
repository: "acme/web",
number: 7,
});

assert.strictEqual(threads.length, 1);
expect(threads[0]).toMatchObject({
id: "abc123",
const read = () => cli.listDiscussions({ cwd: "/w", repository: "acme/web", number: 7 });

host.after = discussionsAfterPush({ base_sha: "base", start_sha: "base", head_sha: "head1" });
const before = yield* read();
host.refs = pushed;
host.after = discussionsAfterPush(pushed);
const after = yield* read();

expect(before.threads.map((thread) => [thread.id, thread.isOutdated])).toEqual([
["untouched", false],
["changed", false],
["unknown", false],
]);
expect(after.threads.map((thread) => [thread.id, thread.isOutdated])).toEqual([
["untouched", false],
["changed", true],
["unknown", false],
]);
expect(after.threads[0]).toMatchObject({
id: "untouched",
path: "src/a.ts",
line: 12,
side: "right",
isResolved: true,
});
assert.strictEqual(threads[0]?.comments.length, 2);
assert.strictEqual(after.threads[0]?.comments.length, 2);
}),
);

it.effect(
"keeps discussions current for unreadable refs but propagates CLI requirements and rate limits",
() =>
Effect.gen(function* () {
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
for (const diffRefs of [null, { base_sha: null, start_sha: "base", head_sha: "new" }]) {
mockedExecute.mockImplementation(({ args }) =>
Effect.succeed(
output(
args[1]?.includes("/discussions")
? JSON.stringify([
{
id: "abc",
notes: [
{
id: 1,
created_at: "2026-07-01Z",
position: {
position_type: "text",
new_path: "src/a.ts",
new_line: 3,
base_sha: "base",
start_sha: "base",
head_sha: "old",
},
},
],
},
])
: mergeRequestJson({ diff_refs: diffRefs }),
),
),
);

const { threads } = yield* cli.listDiscussions({
cwd: "/w",
repository: "acme/web",
number: 7,
});

expect(threads.map((thread) => [thread.id, thread.isOutdated])).toEqual([["abc", false]]);
}
const context = {
operation: "execute" as const,
command: "glab" as const,
cwd: "/w",
cause: new Error("unavailable"),
};
for (const error of [
new GitLabCli.GitLabCliUnavailableError(context),
new GitLabCli.GitLabCliAuthenticationError(context),
new GitLabCli.GitLabCliRateLimitError(context),
]) {
mockedExecute.mockImplementation(({ args }) =>
args[1]?.includes("/discussions") ? Effect.succeed(output("[]")) : Effect.fail(error),
);
expect(
yield* Effect.result(
cli.listDiscussions({ cwd: "/w", repository: "acme/web", number: 7 }),
),
).toMatchObject({
_tag: "Failure",
failure: error,
});
}
}),
);

it.effect("sends a review as its comments, then its summary, then the verdict", () =>
Effect.gen(function* () {
mockedExecute.mockReturnValueOnce(
Expand Down
53 changes: 47 additions & 6 deletions 53 packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,13 @@ export const make = Effect.gen(function* () {
readonly number: number;
readonly page: number;
readonly collected: ReadonlyArray<PullRequestReviewThread>;
readonly diffRefsByThreadId: ReadonlyMap<string, GitLabDiffRefs>;
}): Effect.Effect<
{ readonly threads: ReadonlyArray<PullRequestReviewThread>; readonly truncated: boolean },
{
readonly threads: ReadonlyArray<PullRequestReviewThread>;
readonly diffRefsByThreadId: ReadonlyMap<string, GitLabDiffRefs>;
readonly truncated: boolean;
},
GitLabPullRequestCliError
> =>
api({
Expand All @@ -898,13 +903,17 @@ export const make = Effect.gen(function* () {
);
}
const collected = [...input.collected, ...decoded.success.threads];
const diffRefsByThreadId = new Map([
...input.diffRefsByThreadId,
...decoded.success.diffRefsByThreadId,
]);
// Plain notes count toward the page size even when no positioned threads survive decoding.
if (decoded.success.rawCount < MAX_PAGE_SIZE) {
return Effect.succeed({ threads: collected, truncated: false });
return Effect.succeed({ threads: collected, diffRefsByThreadId, truncated: false });
}
return input.page >= CONVERSATION_PAGES
? Effect.succeed({ threads: collected, truncated: true })
: discussionsPage({ ...input, page: input.page + 1, collected });
? Effect.succeed({ threads: collected, diffRefsByThreadId, truncated: true })
: discussionsPage({ ...input, page: input.page + 1, collected, diffRefsByThreadId });
}),
);

Expand Down Expand Up @@ -1716,8 +1725,40 @@ export const make = Effect.gen(function* () {
}).pipe(Effect.asVoid);
}),

listDiscussions: Effect.fn("GitLabPullRequestCli.listDiscussions")(function (input) {
return discussionsPage({ ...input, page: 1, collected: [] });
listDiscussions: Effect.fn("GitLabPullRequestCli.listDiscussions")(function* (input) {
const [discussions, current] = yield* Effect.all(
[
discussionsPage({ ...input, page: 1, collected: [], diffRefsByThreadId: new Map() }),
// Fresh beside the discussions: cached refs from before a push would invert every flag.
// Unreadable refs leave threads current rather than hiding them.
getDiffRefs(input).pipe(
Effect.catchTags(
{
GitLabCliUnavailableError: (error) => Effect.fail(error),
GitLabCliAuthenticationError: (error) => Effect.fail(error),
GitLabCliRateLimitError: (error) => Effect.fail(error),
},
() => Effect.succeed(null),
),
),
],
{ concurrency: 2 },
);
return {
threads: discussions.threads.map((thread) => {
const refs = discussions.diffRefsByThreadId.get(thread.id);
return refs === undefined || current === null
? thread
: {
...thread,
isOutdated:
refs.baseSha !== current.baseSha ||
refs.startSha !== current.startSha ||
refs.headSha !== current.headSha,
};
}),
truncated: discussions.truncated,
};
}),

submitReview: Effect.fn("GitLabPullRequestCli.submitReview")(function* (input) {
Expand Down
14 changes: 13 additions & 1 deletion 14 packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ const RawDiscussionNoteSchema = Schema.Struct({
old_path: Schema.optional(Schema.NullOr(Schema.String)),
new_line: Schema.optional(Schema.NullOr(Schema.Int)),
old_line: Schema.optional(Schema.NullOr(Schema.Int)),
base_sha: Schema.optional(Schema.NullOr(Schema.String)),
start_sha: Schema.optional(Schema.NullOr(Schema.String)),
head_sha: Schema.optional(Schema.NullOr(Schema.String)),
}),
),
),
Expand Down Expand Up @@ -530,6 +533,8 @@ export interface GitLabDiffRefs {

export interface GitLabDiscussions {
readonly threads: ReadonlyArray<PullRequestReviewThread>;
/** The last diff each thread's line survived into; GitLab stops moving it once the line changes. */
readonly diffRefsByThreadId: ReadonlyMap<string, GitLabDiffRefs>;
readonly rawCount: number;
}

Expand All @@ -541,6 +546,7 @@ export function decodeDiscussionsJson(
return Result.fail(decoded.failure);
}
const threads: PullRequestReviewThread[] = [];
const diffRefsByThreadId = new Map<string, GitLabDiffRefs>();
for (const entry of decoded.success) {
const discussion = decodeDiscussionEntry(entry);
if (!Exit.isSuccess(discussion)) continue;
Expand All @@ -552,6 +558,12 @@ export function decodeDiscussionsJson(
const path = trimmed(side === "left" ? position.old_path : position.new_path);
const line = side === "left" ? position.old_line : position.new_line;
if (path === null) continue;
const baseSha = trimmed(position.base_sha);
const startSha = trimmed(position.start_sha);
const headSha = trimmed(position.head_sha);
if (baseSha !== null && startSha !== null && headSha !== null) {
diffRefsByThreadId.set(discussion.value.id, { baseSha, startSha, headSha });
}
threads.push({
id: discussion.value.id,
path,
Expand All @@ -568,7 +580,7 @@ export function decodeDiscussionsJson(
})),
});
}
return Result.succeed({ threads, rawCount: decoded.success.length });
return Result.succeed({ threads, diffRefsByThreadId, rawCount: decoded.success.length });
}

export function decodeDiffRefsJson(
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.