mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-27 16:25:50 +00:00
chore: fix flaky test
This commit is contained in:
@@ -1,6 +1,25 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { type Session } from "@opencode-ai/sdk/v2/client"
|
||||
import { collectOpenProjectDeepLinks, drainPendingDeepLinks, parseDeepLink } from "./deep-links"
|
||||
import { displayName, errorMessage, getDraggableId, syncWorkspaceOrder, workspaceKey } from "./helpers"
|
||||
import {
|
||||
displayName,
|
||||
errorMessage,
|
||||
getDraggableId,
|
||||
latestRootSession,
|
||||
syncWorkspaceOrder,
|
||||
workspaceKey,
|
||||
} from "./helpers"
|
||||
|
||||
const session = (input: Partial<Session> & Pick<Session, "id" | "directory">) =>
|
||||
({
|
||||
title: "",
|
||||
version: "v2",
|
||||
parentID: undefined,
|
||||
messageCount: 0,
|
||||
permissions: { session: {}, share: {} },
|
||||
time: { created: 0, updated: 0, archived: undefined },
|
||||
...input,
|
||||
}) as Session
|
||||
|
||||
describe("layout deep links", () => {
|
||||
test("parses open-project deep links", () => {
|
||||
@@ -73,6 +92,61 @@ describe("layout workspace helpers", () => {
|
||||
expect(result).toEqual(["/root", "/c", "/b"])
|
||||
})
|
||||
|
||||
test("finds the latest root session across workspaces", () => {
|
||||
const result = latestRootSession(
|
||||
[
|
||||
{
|
||||
path: { directory: "/root" },
|
||||
session: [session({ id: "root", directory: "/root", time: { created: 1, updated: 1, archived: undefined } })],
|
||||
},
|
||||
{
|
||||
path: { directory: "/workspace" },
|
||||
session: [
|
||||
session({
|
||||
id: "workspace",
|
||||
directory: "/workspace",
|
||||
time: { created: 2, updated: 2, archived: undefined },
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
120_000,
|
||||
)
|
||||
|
||||
expect(result?.id).toBe("workspace")
|
||||
})
|
||||
|
||||
test("ignores archived and child sessions when finding latest root session", () => {
|
||||
const result = latestRootSession(
|
||||
[
|
||||
{
|
||||
path: { directory: "/workspace" },
|
||||
session: [
|
||||
session({
|
||||
id: "archived",
|
||||
directory: "/workspace",
|
||||
time: { created: 10, updated: 10, archived: 10 },
|
||||
}),
|
||||
session({
|
||||
id: "child",
|
||||
directory: "/workspace",
|
||||
parentID: "parent",
|
||||
time: { created: 20, updated: 20, archived: undefined },
|
||||
}),
|
||||
session({
|
||||
id: "root",
|
||||
directory: "/workspace",
|
||||
time: { created: 30, updated: 30, archived: undefined },
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
120_000,
|
||||
)
|
||||
|
||||
expect(result?.id).toBe("root")
|
||||
})
|
||||
|
||||
test("extracts draggable id safely", () => {
|
||||
expect(getDraggableId({ draggable: { id: "x" } })).toBe("x")
|
||||
expect(getDraggableId({ draggable: { id: 42 } })).toBeUndefined()
|
||||
|
||||
Reference in New Issue
Block a user