forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflag.ts
More file actions
20 lines (19 loc) · 739 Bytes
/
flag.ts
File metadata and controls
20 lines (19 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import type { WorkspaceID } from "@/control-plane/schema"
import { Flag } from "@opencode-ai/core/flag/flag"
import { Effect, Scope } from "effect"
/**
* Scoped override for `Flag.OPENCODE_WORKSPACE_ID`. Saves the previous value
* on entry and restores it via finalizer when the surrounding scope closes —
* preserves the original try/finally semantics regardless of test outcome.
*/
export function withFixedWorkspaceID(id: WorkspaceID): Effect.Effect<void, never, Scope.Scope> {
return Effect.gen(function* () {
const previous = Flag.OPENCODE_WORKSPACE_ID
Flag.OPENCODE_WORKSPACE_ID = id
yield* Effect.addFinalizer(() =>
Effect.sync(() => {
Flag.OPENCODE_WORKSPACE_ID = previous
}),
)
})
}