diff --git a/packages/opencode/src/sync/index.ts b/packages/opencode/src/sync/index.ts index bfff84031f..185e88a893 100644 --- a/packages/opencode/src/sync/index.ts +++ b/packages/opencode/src/sync/index.ts @@ -39,6 +39,12 @@ export namespace SyncEvent { const Bus = new EventEmitter<{ event: [{ def: Definition; event: Event }] }>() + export function reset() { + frozen = false + projectors = undefined + convertEvent = (_, data) => data + } + export function init(input: { projectors: Array<[Definition, ProjectorFunc]>; convertEvent?: typeof convertEvent }) { projectors = new Map(input.projectors) diff --git a/packages/opencode/test/sync/index.test.ts b/packages/opencode/test/sync/index.test.ts index ed617927d8..7336352299 100644 --- a/packages/opencode/test/sync/index.test.ts +++ b/packages/opencode/test/sync/index.test.ts @@ -1,4 +1,4 @@ -import { describe, test, expect, beforeEach } from "bun:test" +import { describe, test, expect, beforeEach, afterEach } from "bun:test" import { tmpdir } from "../fixture/fixture" import z from "zod" import { Bus } from "../../src/bus" @@ -7,11 +7,21 @@ import { SyncEvent } from "../../src/sync" import { Database } from "../../src/storage/db" import { EventTable } from "../../src/sync/event.sql" import { Identifier } from "../../src/id/id" +import { Flag } from "../../src/flag/flag" beforeEach(() => { Database.Client.reset() }) +const original = Flag.OPENCODE_EXPERIMENTAL_WORKSPACES +// @ts-expect-error don't do this normally, but it works +Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = true + +afterEach(() => { + // @ts-expect-error don't do this normally, but it works + Flag.OPENCODE_EXPERIMENTAL_WORKSPACES = original +}) + function withInstance(fn: () => void | Promise) { return async () => { await using tmp = await tmpdir() @@ -26,6 +36,8 @@ function withInstance(fn: () => void | Promise) { } describe("SyncEvent", () => { + SyncEvent.reset() + const Created = SyncEvent.define({ type: "item.created", version: 1,