Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ework-web",
"version": "0.10.200",
"version": "0.10.201",
"type": "module",
"description": "ework-web — standalone multi-project issue tracker. Local SQLite-backed, no external API dependency. Bun + TypeScript + SSR HTML.",
"license": "MIT",
Expand Down
38 changes: 23 additions & 15 deletions packages/web/src/upstream-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1411,22 +1411,30 @@ export class UpstreamSync {
private async importDiscussionComments(d: GithubDiscussion, emit: boolean): Promise<number> {
const local = await getIssueByUpstreamNumber(this.project.id, d.number, "discussion");
if (!local) return 0;
const comments = await this.fetchJson<GiteaComment[]>(`/discussions/${d.number}/comments?per_page=50`);
if (!comments) return 0;
// Walk every page until a short one (same class of bug as issue comments,
// owner fix 2026-11-07; the discussion variant missed it 2026-11-14):
// a single fixed page truncated long threads FOREVER — newer comments
// sat beyond it, were never imported, and the updated_at cursor advanced
// past them so they could never be retried (awesome-dsh-plugin/5795).
let n = 0;
for (const gc of comments) {
if (await getCommentByUpstreamId(gc.id)) continue;
if ((gc.body ?? "").includes("<!-- ework-mirror -->")) continue;
const gcAuthor = gc.user?.login ?? "upstream";
await ensureUser(gcAuthor, fromGithubBot(gcAuthor) ? "bot" : "human");
const body = (gc.body ?? "") + "\n\n<!-- upstream-sync -->";
const row = await postComment(local.id, body, gcAuthor, {
createdAt: gc.created_at,
updatedAt: gc.updated_at,
upstreamCommentId: gc.id,
});
if (emit) void emitCommentEvent(this.project.id, local.id, row.id, this.origin);
n++;
for (let page = 1; page <= 50; page++) {
const comments = await this.fetchJson<GiteaComment[]>(`/discussions/${d.number}/comments?per_page=100&page=${page}`);
if (!comments || comments.length === 0) break;
for (const gc of comments) {
if (await getCommentByUpstreamId(gc.id)) continue;
if ((gc.body ?? "").includes("<!-- ework-mirror -->")) continue;
const gcAuthor = gc.user?.login ?? "upstream";
await ensureUser(gcAuthor, fromGithubBot(gcAuthor) ? "bot" : "human");
const body = (gc.body ?? "") + "\n\n<!-- upstream-sync -->";
const row = await postComment(local.id, body, gcAuthor, {
createdAt: gc.created_at,
updatedAt: gc.updated_at,
upstreamCommentId: gc.id,
});
if (emit) void emitCommentEvent(this.project.id, local.id, row.id, this.origin);
n++;
}
if (comments.length < 100) break;
}
return n;
}
Expand Down
44 changes: 42 additions & 2 deletions packages/web/tests/discussions-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ function mockFetch() {
hookCalls.push({ url, body: JSON.parse(String(init?.body ?? "{}")) });
return new Response("{}", { status: 200 });
}
const slicePaged = <T,>(arr: T[]): T[] => {
const lm = url.match(/[?&](?:limit|per_page)=(\d+)/);
const limit = lm ? Number(lm[1]) : 100;
const pm = url.match(/[?&]page=(\d+)/);
const page = pm ? Number(pm[1]) : 1;
return arr.slice((page - 1) * limit, page * limit);
};
const perDiscussion = url.match(/\/discussions\/(\d+)\/comments/);
if (perDiscussion) {
return Response.json(discussionComments[Number(perDiscussion[1])] ?? []);
return Response.json(slicePaged(discussionComments[Number(perDiscussion[1])] ?? []));
}
if (/\/discussions(\?|$)/.test(url)) {
return Response.json(discussionList);
return Response.json(slicePaged(discussionList));
}
if (/\/issues(\?|$)/.test(url)) {
return Response.json(issueList);
Expand Down Expand Up @@ -206,4 +213,37 @@ describe("discussions sync", () => {
const local = await getIssueByUpstreamNumber(sync.project_id, 51, "discussion");
expect(local?.state).toBe("closed");
});

test("live poll walks every discussion comment page (thread > one page, 2026-11-14 discussion 5795 class)", async () => {
const { sync } = await setup();
const ts = (day: number, i: number) => new Date(Date.UTC(2026, 9, day, 1, 0, i)).toISOString();
mockFetch();
// Round 1 (backfill): discussion 61 with 100 comments — all must land
discussionList = [discussion(61, { created_at: "2026-10-01T00:00:00Z", updated_at: "2026-10-02T00:00:00Z" })];
discussionComments[61] = Array.from({ length: 100 }, (_, i) =>
dcomment(6100 + i, 61, { created_at: ts(2, i), updated_at: ts(2, i) })
);
await (await makeSyncer(sync.project_id)).pollOnce();
await settle();
expect(await getCommentByUpstreamId(6199)).toBeTruthy();
expect((await getUpstreamSync(sync.project_id))?.discussion_cursor).toBe("2026-10-02T00:00:00Z");

// Round 2 (live): 20 more comments land on page 2 and updated_at moves past
// the cursor. The old single-page fetch (per_page=50, page 1) saw only the
// already-imported comments, emitted no webhook, and still advanced the
// cursor — the 20 new comments were lost forever (discussion 5795).
discussionList = [discussion(61, { created_at: "2026-10-01T00:00:00Z", updated_at: "2026-10-05T00:00:00Z" })];
discussionComments[61] = [
...discussionComments[61],
...Array.from({ length: 20 }, (_, i) => dcomment(6200 + i, 61, { created_at: ts(5, i), updated_at: ts(5, i) })),
];
hookCalls = [];
await (await makeSyncer(sync.project_id)).pollOnce();
await settle();

for (const id of [6200, 6209, 6210, 6219]) expect(await getCommentByUpstreamId(id)).toBeTruthy();
const created = hookCalls.filter((c) => c.body.action === "created" && c.body.issue?.kind === "discussion");
expect(created.length).toBe(20);
expect((await getUpstreamSync(sync.project_id))?.discussion_cursor).toBe("2026-10-05T00:00:00Z");
});
});
Loading