GeezerVison is showing github.com — fix(server): honor sort: 'created' when merging IssueService.list ent… · pingdotgg/t3code@c2477b0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/issue/IssueService.test.ts +56Lines changed: 56 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -913,4 +913,60 @@ describe("IssueService with a standalone tracker", () => { | 913 | 913 | }); | 914 | 914 | }), | 915 | 915 | ); | | 916 | + | | 917 | + it.effect("orders merged entries by createdAt when sort is created and updatedAt otherwise", () => | | 918 | + Effect.gen(function* () { | | 919 | + const seenSorts: string[] = []; | | 920 | + const service = yield* makeService({ | | 921 | + projects: [ | | 922 | + project({ id: "web", repository: "acme/web" }), | | 923 | + project({ id: "api", repository: "acme/api" }), | | 924 | + ], | | 925 | + trackers: [ | | 926 | + fakeTracker({ | | 927 | + listIssues: (input) => { | | 928 | + seenSorts.push(input.sort); | | 929 | + if (input.scope === "acme/web") { | | 930 | + return Effect.succeed({ | | 931 | + items: [ | | 932 | + { | | 933 | + ...issue("old-created-recent-update"), | | 934 | + createdAt: "2026-07-06T01:00:00+02:00", | | 935 | + updatedAt: "2026-07-10T00:00:00Z", | | 936 | + }, | | 937 | + ], | | 938 | + nextCursor: null, | | 939 | + }); | | 940 | + } | | 941 | + return Effect.succeed({ | | 942 | + items: [ | | 943 | + { | | 944 | + ...issue("new-created-older-update"), | | 945 | + createdAt: "2026-07-05T23:30:00Z", | | 946 | + updatedAt: "2026-07-06T00:00:00Z", | | 947 | + }, | | 948 | + ], | | 949 | + nextCursor: null, | | 950 | + }); | | 951 | + }, | | 952 | + }), | | 953 | + ], | | 954 | + }); | | 955 | + | | 956 | + const byCreated = yield* service.list({ state: "open", sort: "created" }); | | 957 | + expect(seenSorts).toEqual(["created", "created"]); | | 958 | + expect(byCreated.entries.map((entry) => entry.key)).toEqual([ | | 959 | + "new-created-older-update", | | 960 | + "old-created-recent-update", | | 961 | + ]); | | 962 | + | | 963 | + seenSorts.length = 0; | | 964 | + const byUpdated = yield* service.list({ state: "open" }); | | 965 | + expect(seenSorts).toEqual(["updated", "updated"]); | | 966 | + expect(byUpdated.entries.map((entry) => entry.key)).toEqual([ | | 967 | + "old-created-recent-update", | | 968 | + "new-created-older-update", | | 969 | + ]); | | 970 | + }), | | 971 | + ); | 916 | 972 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/issue/IssueService.ts +13-2Lines changed: 13 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -380,6 +380,7 @@ const make = Effect.gen(function* () { | 380 | 380 | const nextCursors: Record<string, string> = {}; | 381 | 381 |
| 382 | 382 | const involvement = input.involvement ?? "all"; | | 383 | + const sort = input.sort ?? "updated"; | 383 | 384 | // Only a narrowed listing compares against the signed-in account; `all` never reads it. | 384 | 385 | const viewerRequests = new Map<string, Effect.Effect<string, IssueTrackerError>>(); | 385 | 386 | for (const project of involvement === "all" ? [] : scopes.values()) { | @@ -454,7 +455,7 @@ const make = Effect.gen(function* () { | 454 | 455 | query: input.query, | 455 | 456 | labels: input.labels, | 456 | 457 | assignee: input.assignee, | 457 | | - sort: input.sort ?? "updated", | | 458 | + sort, | 458 | 459 | cursor, | 459 | 460 | refresh: input.refresh, | 460 | 461 | }), | @@ -509,7 +510,17 @@ const make = Effect.gen(function* () { | 509 | 510 | detail: "Issues cannot be browsed for this host yet.", | 510 | 511 | }); | 511 | 512 | } | 512 | | - entries.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)); | | 513 | + const sortField = sort === "created" ? "createdAt" : "updatedAt"; | | 514 | + const parseSortTime = (iso: string) => { | | 515 | + const time = Date.parse(iso); | | 516 | + return Number.isNaN(time) ? Number.NEGATIVE_INFINITY : time; | | 517 | + }; | | 518 | + entries.sort((a, b) => { | | 519 | + const aTime = parseSortTime(a[sortField]); | | 520 | + const bTime = parseSortTime(b[sortField]); | | 521 | + if (aTime !== bTime) return bTime > aTime ? 1 : -1; | | 522 | + return b[sortField].localeCompare(a[sortField]); | | 523 | + }); | 513 | 524 | return { | 514 | 525 | viewers: Object.fromEntries(viewers), | 515 | 526 | trackers: [...trackers.values()], | |
Collapse file Copy file name to clipboardExpand all lines: packages/contracts/src/issue.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -332,7 +332,7 @@ export const IssueListResult = Schema.Struct({ | 332 | 332 | /** The signed-in account per host that involvement compared against. Empty for `all`. */ | 333 | 333 | viewers: Schema.Record(TrimmedNonEmptyString, TrimmedNonEmptyString), | 334 | 334 | trackers: Schema.Array(IssueTrackerSummary), | 335 | | - /** By update, newest first, across every scope this answer covers. */ | | 335 | + /** Newest first by the requested `sort` (`updated` when absent), across every scope this answer covers. */ | 336 | 336 | entries: Schema.Array(IssueListEntry), | 337 | 337 | errors: Schema.Array(IssueListProjectError), | 338 | 338 | /** Where each scope carries on, sent straight back as `cursors`. Absent once a scope is done. */ | |
|