Skip to content

Commit 0aa8115

Browse files
author
Zoo (VP)
committed
test(b10): add 6 coverage tests, restore eslint-suppressions format
1 parent 9ea9755 commit 0aa8115

3 files changed

Lines changed: 1871 additions & 1761 deletions

File tree

src/core/task-persistence/__tests__/TaskOrganizationStore.spec.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,81 @@ describe("TaskOrganizationStore", () => {
668668
})
669669
})
670670

671+
describe("resolveTarget autoGroup path (coverage)", () => {
672+
it("resolves autoGroup target via setPinned with parent/child tasks", async () => {
673+
const parent = makeHistoryItem({ id: "parent" })
674+
const child = makeHistoryItem({ id: "child", parentTaskId: "parent" })
675+
history.add(parent)
676+
history.add(child)
677+
await store.initialize()
678+
679+
const result = await store.mutate(
680+
{ kind: "setPinned", target: { kind: "autoGroup", rootTaskId: "child" }, pinned: true },
681+
0,
682+
)
683+
684+
expect(result.success).toBe(true)
685+
expect(store.getState().pins).toHaveLength(1)
686+
// The autoGroup should resolve to the root parent
687+
expect(store.getState().pins[0].target).toEqual({ kind: "autoGroup", rootTaskId: "parent" })
688+
})
689+
690+
it("resolves autoGroup target when rootTaskId is already the root", async () => {
691+
const parent = makeHistoryItem({ id: "root" })
692+
const child = makeHistoryItem({ id: "child-1", parentTaskId: "root" })
693+
history.add(parent)
694+
history.add(child)
695+
await store.initialize()
696+
697+
const result = await store.mutate(
698+
{ kind: "setPinned", target: { kind: "autoGroup", rootTaskId: "root" }, pinned: true },
699+
0,
700+
)
701+
702+
expect(result.success).toBe(true)
703+
expect(store.getState().pins[0].target).toEqual({ kind: "autoGroup", rootTaskId: "root" })
704+
})
705+
})
706+
707+
describe("mapError paths (coverage)", () => {
708+
it("returns TASK_ORG/PERSISTENCE/005 when save throws a non-Error object with ENOENT code", async () => {
709+
await store.initialize()
710+
711+
// A plain object with `code` but no `message` bypasses isTaskOrganizationError
712+
// (which requires both `code` and `message` as string properties), then falls
713+
// through to the generic error branch in mapError.
714+
const { safeUpdateJson } = await import("../../../utils/safeWriteJson")
715+
vi.mocked(safeUpdateJson).mockRejectedValueOnce({ code: "ENOENT" } as NodeJS.ErrnoException)
716+
717+
const result = await store.mutate(
718+
{ kind: "setPinned", target: { kind: "task", taskId: "t1" }, pinned: true },
719+
0,
720+
)
721+
722+
expect(result.success).toBe(false)
723+
if (!result.success) {
724+
expect(result.error!.code).toBe("TASK_ORG/PERSISTENCE/005")
725+
}
726+
})
727+
728+
it("returns TASK_ORG/PERSISTENCE/005 for generic Error during save", async () => {
729+
await store.initialize()
730+
731+
const { safeUpdateJson } = await import("../../../utils/safeWriteJson")
732+
vi.mocked(safeUpdateJson).mockRejectedValueOnce(new Error("disk full"))
733+
734+
const result = await store.mutate(
735+
{ kind: "setPinned", target: { kind: "task", taskId: "t1" }, pinned: true },
736+
0,
737+
)
738+
739+
expect(result.success).toBe(false)
740+
if (!result.success) {
741+
expect(result.error!.code).toBe("TASK_ORG/PERSISTENCE/005")
742+
}
743+
})
744+
})
745+
671746
describe("concurrent mutations", () => {
672747
it("serializes concurrent mutations so revisions are sequential", async () => {
673748
await store.initialize()

0 commit comments

Comments
 (0)