test(workspace): effectify sync state cases (#27400)
This commit is contained in:
@@ -1040,21 +1040,29 @@ describe("workspace CRUD", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("workspace sync state", () => {
|
describe("workspace sync state", () => {
|
||||||
test("startWorkspaceSyncing is disabled by the experimental workspace flag", async () => {
|
it.instance(
|
||||||
await withInstance(async (dir) => {
|
"startWorkspaceSyncing is disabled by the experimental workspace flag",
|
||||||
|
() =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const { directory: dir } = yield* TestInstance
|
||||||
|
const instance = yield* InstanceRef
|
||||||
|
if (!instance) return yield* Effect.die(new Error("missing test instance"))
|
||||||
|
const workspace = yield* Workspace.Service
|
||||||
|
const sessionSvc = yield* SessionNs.Service
|
||||||
const type = unique("flag-disabled")
|
const type = unique("flag-disabled")
|
||||||
const info = workspaceInfo(Instance.project.id, type)
|
const info = workspaceInfo(instance.project.id, type)
|
||||||
const session = await AppRuntime.runPromise(SessionNs.Service.use((svc) => svc.create({})))
|
const session = yield* sessionSvc.create({})
|
||||||
attachSessionToWorkspace(session.id, info.id)
|
attachSessionToWorkspace(session.id, info.id)
|
||||||
insertWorkspace(info)
|
insertWorkspace(info)
|
||||||
registerAdapter(Instance.project.id, type, localAdapter(path.join(dir, "flag-disabled")).adapter)
|
registerAdapter(instance.project.id, type, localAdapter(path.join(dir, "flag-disabled")).adapter)
|
||||||
|
|
||||||
await startWorkspaceSyncingWithFlag(Instance.project.id, false)
|
yield* Effect.promise(() => startWorkspaceSyncingWithFlag(instance.project.id, false))
|
||||||
await delay(25)
|
yield* Effect.sleep("25 millis")
|
||||||
|
|
||||||
expect((await workspaceStatus()).find((item) => item.workspaceID === info.id)?.status).toBeUndefined()
|
expect((yield* workspace.status()).find((item) => item.workspaceID === info.id)?.status).toBeUndefined()
|
||||||
})
|
}),
|
||||||
})
|
{ git: true },
|
||||||
|
)
|
||||||
|
|
||||||
it.instance(
|
it.instance(
|
||||||
"startWorkspaceSyncing starts all workspaces",
|
"startWorkspaceSyncing starts all workspaces",
|
||||||
@@ -1094,67 +1102,76 @@ describe("workspace sync state", () => {
|
|||||||
{ git: true },
|
{ git: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
test("local start reports error when the target directory is missing", async () => {
|
it.instance(
|
||||||
await withInstance(async (dir) => {
|
"local start reports error when the target directory is missing",
|
||||||
|
() =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const { directory: dir } = yield* TestInstance
|
||||||
|
const instance = yield* InstanceRef
|
||||||
|
if (!instance) return yield* Effect.die(new Error("missing test instance"))
|
||||||
|
const workspace = yield* Workspace.Service
|
||||||
|
const sessionSvc = yield* SessionNs.Service
|
||||||
const type = unique("missing-local")
|
const type = unique("missing-local")
|
||||||
const info = workspaceInfo(Instance.project.id, type)
|
const info = workspaceInfo(instance.project.id, type)
|
||||||
insertWorkspace(info)
|
insertWorkspace(info)
|
||||||
registerAdapter(
|
registerAdapter(
|
||||||
Instance.project.id,
|
instance.project.id,
|
||||||
type,
|
type,
|
||||||
localAdapter(path.join(dir, "missing-target"), { createDir: false }).adapter,
|
localAdapter(path.join(dir, "missing-target"), { createDir: false }).adapter,
|
||||||
)
|
)
|
||||||
attachSessionToWorkspace(
|
attachSessionToWorkspace((yield* sessionSvc.create({})).id, info.id)
|
||||||
(await AppRuntime.runPromise(SessionNs.Service.use((svc) => svc.create({})))).id,
|
|
||||||
info.id,
|
yield* workspace.startWorkspaceSyncing(instance.project.id)
|
||||||
|
|
||||||
|
yield* eventuallyEffect(
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const status = yield* workspace.status()
|
||||||
|
expect(status.find((item) => item.workspaceID === info.id)?.status).toBe("error")
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
expect(yield* workspace.isSyncing(info.id)).toBe(false)
|
||||||
|
yield* workspace.remove(info.id)
|
||||||
|
}),
|
||||||
|
{ git: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
startWorkspaceSyncing(Instance.project.id)
|
it.instance(
|
||||||
|
"duplicate local status updates are suppressed",
|
||||||
await eventually(() =>
|
() =>
|
||||||
workspaceStatus().then((status) =>
|
Effect.gen(function* () {
|
||||||
expect(status.find((item) => item.workspaceID === info.id)?.status).toBe("error"),
|
const { directory: dir } = yield* TestInstance
|
||||||
),
|
const instance = yield* InstanceRef
|
||||||
)
|
if (!instance) return yield* Effect.die(new Error("missing test instance"))
|
||||||
expect(await isWorkspaceSyncing(info.id)).toBe(false)
|
const workspace = yield* Workspace.Service
|
||||||
await removeWorkspace(info.id)
|
const sessionSvc = yield* SessionNs.Service
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test("duplicate local status updates are suppressed", async () => {
|
|
||||||
await withInstance(async (dir) => {
|
|
||||||
const captured = captureGlobalEvents()
|
const captured = captureGlobalEvents()
|
||||||
try {
|
yield* Effect.addFinalizer(() => Effect.sync(() => captured.dispose()))
|
||||||
const type = unique("dedupe-local")
|
const type = unique("dedupe-local")
|
||||||
const info = workspaceInfo(Instance.project.id, type)
|
const info = workspaceInfo(instance.project.id, type)
|
||||||
const target = path.join(dir, "dedupe-local")
|
const target = path.join(dir, "dedupe-local")
|
||||||
await fs.mkdir(target, { recursive: true })
|
yield* Effect.promise(() => fs.mkdir(target, { recursive: true }))
|
||||||
insertWorkspace(info)
|
insertWorkspace(info)
|
||||||
registerAdapter(Instance.project.id, type, localAdapter(target).adapter)
|
registerAdapter(instance.project.id, type, localAdapter(target).adapter)
|
||||||
attachSessionToWorkspace(
|
attachSessionToWorkspace((yield* sessionSvc.create({})).id, info.id)
|
||||||
(await AppRuntime.runPromise(SessionNs.Service.use((svc) => svc.create({})))).id,
|
|
||||||
info.id,
|
|
||||||
)
|
|
||||||
|
|
||||||
startWorkspaceSyncing(Instance.project.id)
|
yield* workspace.startWorkspaceSyncing(instance.project.id)
|
||||||
startWorkspaceSyncing(Instance.project.id)
|
yield* workspace.startWorkspaceSyncing(instance.project.id)
|
||||||
|
|
||||||
await eventually(() =>
|
yield* eventuallyEffect(
|
||||||
workspaceStatus().then((status) =>
|
Effect.gen(function* () {
|
||||||
expect(status.find((item) => item.workspaceID === info.id)?.status).toBe("connected"),
|
const status = yield* workspace.status()
|
||||||
),
|
expect(status.find((item) => item.workspaceID === info.id)?.status).toBe("connected")
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
expect(
|
expect(
|
||||||
captured.events.filter(
|
captured.events.filter(
|
||||||
(event) => event.workspace === info.id && event.payload.type === Workspace.Event.Status.type,
|
(event) => event.workspace === info.id && event.payload.type === Workspace.Event.Status.type,
|
||||||
),
|
),
|
||||||
).toHaveLength(1)
|
).toHaveLength(1)
|
||||||
await removeWorkspace(info.id)
|
yield* workspace.remove(info.id)
|
||||||
} finally {
|
}),
|
||||||
captured.dispose()
|
{ git: true },
|
||||||
}
|
)
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it.live("remote start emits disconnected, connecting, and connected then refuses duplicate listeners", () => {
|
it.live("remote start emits disconnected, connecting, and connected then refuses duplicate listeners", () => {
|
||||||
const calls: FetchCall[] = []
|
const calls: FetchCall[] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user