test(workspace): effectify sync start coverage (#27338)
This commit is contained in:
@@ -16,13 +16,14 @@ import { ProjectID } from "@/project/schema"
|
|||||||
import { ProjectTable } from "@/project/project.sql"
|
import { ProjectTable } from "@/project/project.sql"
|
||||||
import { Instance } from "@/project/instance"
|
import { Instance } from "@/project/instance"
|
||||||
import { WithInstance } from "../../src/project/with-instance"
|
import { WithInstance } from "../../src/project/with-instance"
|
||||||
|
import { InstanceRef } from "@/effect/instance-ref"
|
||||||
import { Session as SessionNs } from "@/session/session"
|
import { Session as SessionNs } from "@/session/session"
|
||||||
import { SessionID } from "@/session/schema"
|
import { SessionID } from "@/session/schema"
|
||||||
import { SessionTable } from "@/session/session.sql"
|
import { SessionTable } from "@/session/session.sql"
|
||||||
import { SyncEvent } from "@/sync"
|
import { SyncEvent } from "@/sync"
|
||||||
import { EventSequenceTable } from "@/sync/event.sql"
|
import { EventSequenceTable } from "@/sync/event.sql"
|
||||||
import { resetDatabase } from "../fixture/db"
|
import { resetDatabase } from "../fixture/db"
|
||||||
import { disposeAllInstances, provideTmpdirInstance, tmpdir } from "../fixture/fixture"
|
import { disposeAllInstances, provideTmpdirInstance, TestInstance, tmpdir } from "../fixture/fixture"
|
||||||
import { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
import { registerAdapter } from "../../src/control-plane/adapters"
|
import { registerAdapter } from "../../src/control-plane/adapters"
|
||||||
import { WorkspaceID } from "../../src/control-plane/schema"
|
import { WorkspaceID } from "../../src/control-plane/schema"
|
||||||
@@ -105,7 +106,7 @@ afterEach(async () => {
|
|||||||
|
|
||||||
async function withInstance<T>(fn: (dir: string) => T | Promise<T>) {
|
async function withInstance<T>(fn: (dir: string) => T | Promise<T>) {
|
||||||
await using tmp = await tmpdir({ git: true })
|
await using tmp = await tmpdir({ git: true })
|
||||||
return WithInstance.provide({
|
return await WithInstance.provide({
|
||||||
directory: tmp.path,
|
directory: tmp.path,
|
||||||
fn: () => fn(tmp.path),
|
fn: () => fn(tmp.path),
|
||||||
})
|
})
|
||||||
@@ -994,31 +995,43 @@ describe("workspace sync state", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test("startWorkspaceSyncing starts all workspaces", async () => {
|
it.instance(
|
||||||
await withInstance(async (dir) => {
|
"startWorkspaceSyncing starts all workspaces",
|
||||||
const firstType = unique("first")
|
() =>
|
||||||
const secondType = unique("second")
|
Effect.gen(function* () {
|
||||||
const first = workspaceInfo(Instance.project.id, firstType)
|
const { directory: dir } = yield* TestInstance
|
||||||
const second = workspaceInfo(Instance.project.id, secondType)
|
const instance = yield* InstanceRef
|
||||||
await fs.mkdir(path.join(dir, "first"), { recursive: true })
|
if (!instance) return yield* Effect.die(new Error("missing test instance"))
|
||||||
await fs.mkdir(path.join(dir, "second"), { recursive: true })
|
const workspace = yield* Workspace.Service
|
||||||
insertWorkspace(first)
|
const projectID = instance.project.id
|
||||||
insertWorkspace(second)
|
const firstType = unique("first")
|
||||||
registerAdapter(Instance.project.id, firstType, localAdapter(path.join(dir, "first")).adapter)
|
const secondType = unique("second")
|
||||||
registerAdapter(Instance.project.id, secondType, localAdapter(path.join(dir, "second")).adapter)
|
const first = workspaceInfo(projectID, firstType)
|
||||||
|
const second = workspaceInfo(projectID, secondType)
|
||||||
|
yield* Effect.promise(() => fs.mkdir(path.join(dir, "first"), { recursive: true }))
|
||||||
|
yield* Effect.promise(() => fs.mkdir(path.join(dir, "second"), { recursive: true }))
|
||||||
|
yield* Effect.sync(() => {
|
||||||
|
insertWorkspace(first)
|
||||||
|
insertWorkspace(second)
|
||||||
|
registerAdapter(projectID, firstType, localAdapter(path.join(dir, "first")).adapter)
|
||||||
|
registerAdapter(projectID, secondType, localAdapter(path.join(dir, "second")).adapter)
|
||||||
|
})
|
||||||
|
yield* Effect.addFinalizer(() =>
|
||||||
|
Effect.all([workspace.remove(first.id), workspace.remove(second.id)], { discard: true }).pipe(Effect.ignore),
|
||||||
|
)
|
||||||
|
|
||||||
startWorkspaceSyncing(Instance.project.id)
|
yield* workspace.startWorkspaceSyncing(projectID)
|
||||||
|
|
||||||
await eventually(() =>
|
yield* eventuallyEffect(
|
||||||
workspaceStatus().then((status) => {
|
Effect.gen(function* () {
|
||||||
expect(status.find((item) => item.workspaceID === first.id)?.status).toBe("connected")
|
const status = yield* workspace.status()
|
||||||
expect(status.find((item) => item.workspaceID === second.id)?.status).toBe("connected")
|
expect(status.find((item) => item.workspaceID === first.id)?.status).toBe("connected")
|
||||||
}),
|
expect(status.find((item) => item.workspaceID === second.id)?.status).toBe("connected")
|
||||||
)
|
}),
|
||||||
await removeWorkspace(first.id)
|
)
|
||||||
await removeWorkspace(second.id)
|
}),
|
||||||
})
|
{ git: true },
|
||||||
})
|
)
|
||||||
|
|
||||||
test("local start reports error when the target directory is missing", async () => {
|
test("local start reports error when the target directory is missing", async () => {
|
||||||
await withInstance(async (dir) => {
|
await withInstance(async (dir) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user