7bcb10bfef
* feat: unarchive tasks with worktree branch recovery Archived tasks can now be restored. Unarchive works for manual/legacy archives (empty cascade id, root-only) and cascade archives. Archive deletes the local branch, so worktree recreate now falls back to fetching the branch from origin, and unarchive writes the old branch back as checkout_branch so a fresh session resumes the prior work. Unrecoverable branches (never pushed) surface a warning. WS archive now routes through the handoff cascade so it stays stamped and reversible. UI: unarchive action on /tasks archived rows and the task top bar. * fix: address PR review feedback on unarchive recovery Forward PRNumber to the recreate fetch so fork-PR heads (only reachable via pull/<N>/head) are recoverable, publish task.updated per task in the cascade unarchive loop so the UI restores without a reload, and re-publish task.updated after a checkout_branch restore since the unarchive event goes out with the pre-restore repository rows. * fix: harden unarchive recovery per review feedback Propagate branch-probe errors instead of misreporting recoverable work as gone, and reserve ErrBranchUnrecoverable for a confirmed-missing remote ref (transient fetch failures keep their own error). Validate the archive root exists so WS/HTTP archive no longer reports success for unknown task IDs, CAS-guard manual unarchive on an empty cascade stamp, detach branch recovery from the request context, and skip checkout_branch restore for multi-branch repos. UI: in-flight guard on the list unarchive button, pluralized unrecoverable-branch toast. * docs: document CAS guard on UnarchiveTask interface contract --------- Co-authored-by: Kandev Agent <agent@kandev.dev>
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { UnarchiveTaskResponse } from "@/lib/api/domains/kanban-api";
|
|
import { unarchiveToastPayload } from "./unarchive-feedback";
|
|
|
|
function response(recovery: UnarchiveTaskResponse["recovery"]): UnarchiveTaskResponse {
|
|
return {
|
|
success: true,
|
|
cascade_id: "",
|
|
unarchived_ids: ["t1"],
|
|
skipped_ids: [],
|
|
affected_group_ids: [],
|
|
recovery,
|
|
};
|
|
}
|
|
|
|
describe("unarchiveToastPayload", () => {
|
|
it("reports success when every branch is recoverable", () => {
|
|
const payload = unarchiveToastPayload(
|
|
response([{ task_id: "t1", repository_id: "r1", branch: "feat/x", status: "remote" }]),
|
|
);
|
|
expect(payload.variant).toBe("success");
|
|
expect(payload.description).toBe("The task has been restored.");
|
|
});
|
|
|
|
it("reports success when there is no recovery info at all", () => {
|
|
const payload = unarchiveToastPayload(response([]));
|
|
expect(payload.variant).toBe("success");
|
|
});
|
|
|
|
it("warns with the branch names when a branch is unrecoverable", () => {
|
|
const payload = unarchiveToastPayload(
|
|
response([
|
|
{ task_id: "t1", repository_id: "r1", branch: "feat/gone", status: "missing" },
|
|
{ task_id: "t1", repository_id: "r2", branch: "feat/ok", status: "local" },
|
|
]),
|
|
);
|
|
expect(payload.variant).toBeUndefined();
|
|
expect(payload.description).toContain("feat/gone");
|
|
expect(payload.description).not.toContain("feat/ok");
|
|
});
|
|
|
|
it("pluralizes when multiple branches are unrecoverable", () => {
|
|
const payload = unarchiveToastPayload(
|
|
response([
|
|
{ task_id: "t1", repository_id: "r1", branch: "feat/one", status: "missing" },
|
|
{ task_id: "t1", repository_id: "r2", branch: "feat/two", status: "missing" },
|
|
]),
|
|
);
|
|
expect(payload.description).toContain("Branches feat/one, feat/two no longer exist");
|
|
});
|
|
|
|
it("tolerates a response without a recovery field", () => {
|
|
const payload = unarchiveToastPayload(
|
|
response(undefined as unknown as UnarchiveTaskResponse["recovery"]),
|
|
);
|
|
expect(payload.variant).toBe("success");
|
|
});
|
|
});
|