Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.
Merged
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
76 changes: 76 additions & 0 deletions packages/core/src/archive/archiveListView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
deriveUniqueRepos,
filterAndSortArchivedTasks,
getRepoName,
mergeArchivedWithTasks,
withRepoNames,
} from "./archiveListView";

Expand Down Expand Up @@ -58,6 +59,63 @@ describe("deriveUniqueRepos", () => {
});
});

describe("mergeArchivedWithTasks", () => {
it("resolves details fetched directly for an archived task", () => {
const archived = makeArchived("older-task", "2024-01-02T00:00:00.000Z");
const task = makeTask("older-task", { title: "Recover me" });

expect(mergeArchivedWithTasks([archived], [task])).toEqual([
{ archived, task },
]);
});

it.each([
{
name: "creation date",
patch: { taskCreatedAt: undefined },
expected: {
title: "Recovered title",
created_at: null,
repository: "posthog/code",
},
},
{
name: "title",
patch: { title: undefined },
expected: {
title: "Unknown task (older-ta)",
created_at: "2024-01-01T00:00:00.000Z",
repository: "posthog/code",
},
},
{
name: "repository",
patch: { repository: undefined },
expected: {
title: "Recovered title",
created_at: "2024-01-01T00:00:00.000Z",
repository: null,
},
},
])(
"preserves other archived metadata when $name is missing",
({ patch, expected }) => {
const archived = {
...makeArchived("older-task", "2024-01-02T00:00:00.000Z"),
title: "Recovered title",
taskCreatedAt: "2024-01-01T00:00:00.000Z",
repository: "posthog/code",
...patch,
};

expect(mergeArchivedWithTasks([archived], [])[0].task).toEqual({
id: "older-task",
...expected,
});
},
);
});

describe("filterAndSortArchivedTasks", () => {
const items: ArchivedTaskWithDetails[] = [
{
Expand All @@ -79,6 +137,15 @@ describe("filterAndSortArchivedTasks", () => {
expect(result.map((i) => i.archived.taskId)).toEqual(["b"]);
});

it("filters by task id when the original title is unavailable", () => {
const result = filterAndSortArchivedTasks(withRepoNames(items), {
searchQuery: "b",
repoFilter: null,
sort: { column: "archived", direction: "desc" },
});
expect(result.map((i) => i.archived.taskId)).toEqual(["b"]);
});

it("filters by repo name", () => {
const result = filterAndSortArchivedTasks(withRepoNames(items), {
searchQuery: "",
Expand All @@ -88,6 +155,15 @@ describe("filterAndSortArchivedTasks", () => {
expect(result.map((i) => i.archived.taskId)).toEqual(["a"]);
});

it("does not include repository names in the title and task ID search", () => {
const result = filterAndSortArchivedTasks(withRepoNames(items), {
searchQuery: "two",
repoFilter: null,
sort: { column: "archived", direction: "desc" },
});
expect(result).toEqual([]);
});

it("sorts by archivedAt descending", () => {
const result = filterAndSortArchivedTasks(withRepoNames(items), {
searchQuery: "",
Expand Down
28 changes: 23 additions & 5 deletions packages/core/src/archive/archiveListView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import type { ArchivedTask } from "@posthog/shared";
import { formatRelativeTimeLong } from "@posthog/shared";
import type { Task } from "@posthog/shared/domain-types";

export interface ArchivedTaskDetails
extends Pick<Task, "id" | "title" | "repository"> {
created_at: Task["created_at"] | null;
}

export interface ArchivedTaskWithDetails {
archived: ArchivedTask;
task: Task | null;
task: ArchivedTaskDetails | null;
}

export interface ArchivedTaskWithRepo extends ArchivedTaskWithDetails {
Expand All @@ -27,16 +32,27 @@ export interface ArchiveFilterSortInput {

export function mergeArchivedWithTasks(
archivedTasks: ArchivedTask[],
tasks: Task[],
tasks: ArchivedTaskDetails[],
): ArchivedTaskWithDetails[] {
const taskMap = new Map(tasks.map((task) => [task.id, task]));
return archivedTasks.map((archived) => ({
archived,
task: taskMap.get(archived.taskId) ?? null,
task:
taskMap.get(archived.taskId) ??
(archived.title || archived.taskCreatedAt || archived.repository
? {
id: archived.taskId,
title:
archived.title ??
`Unknown task (${archived.branchName ?? archived.worktreeName ?? archived.taskId.slice(0, 8)})`,
created_at: archived.taskCreatedAt ?? null,
repository: archived.repository ?? null,
}
: null),
Comment thread
richardsolomou marked this conversation as resolved.
}));
}

export function formatRelativeDate(isoDate: string | undefined): string {
export function formatRelativeDate(isoDate: string | null | undefined): string {
if (!isoDate) return "—";
return formatRelativeTimeLong(isoDate);
}
Expand Down Expand Up @@ -81,7 +97,9 @@ export function filterAndSortArchivedTasks(
const query = searchQuery.trim().toLowerCase();
if (query) {
result = result.filter((item) =>
(item.task?.title?.toLowerCase() ?? "").includes(query),
[item.task?.title, item.archived.taskId].some((value) =>
value?.toLowerCase().includes(query),
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/host-router/src/routers/archive.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const archiveRouter = router({
list: publicProcedure
.output(listArchivedTasksOutput)
.query(({ ctx }) =>
ctx.container.get<ArchiveService>(ARCHIVE_SERVICE).getArchivedTasks(),
ctx.container.get<ArchiveService>(ARCHIVE_SERVICE).listArchivedTasks(),
),

archivedTaskIds: publicProcedure
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/archive-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export const archivedTaskSchema = z.object({
worktreeName: z.string().nullable(),
branchName: z.string().nullable(),
checkpointId: z.string().nullable(),
title: z.string().nullable().optional(),
taskCreatedAt: z.string().nullable().optional(),
repository: z.string().nullable().optional(),
recoveryPending: z.boolean().optional(),
});

export type ArchivedTask = z.infer<typeof archivedTaskSchema>;
Loading
Loading