refactor(core): centralize project and workspace schemas
This commit is contained in:
@@ -6,7 +6,7 @@ import * as Socket from "effect/unstable/socket/Socket"
|
||||
import { mkdir } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { registerAdapter } from "../../src/control-plane/adapters"
|
||||
import { WorkspaceID } from "../../src/control-plane/schema"
|
||||
import { WorkspaceV2 } from "@opencode-ai/core/workspace"
|
||||
import type { WorkspaceAdapter } from "../../src/control-plane/types"
|
||||
import { Workspace } from "../../src/control-plane/workspace"
|
||||
import { InstanceRef, WorkspaceRef } from "../../src/effect/instance-ref"
|
||||
@@ -198,7 +198,7 @@ describe("HttpApi instance context middleware", () => {
|
||||
|
||||
it.live("uses configured workspace id instead of routing to the requested workspace", () =>
|
||||
Effect.gen(function* () {
|
||||
const fixedWorkspaceID = WorkspaceID.ascending()
|
||||
const fixedWorkspaceID = WorkspaceV2.ID.ascending()
|
||||
yield* withFixedWorkspaceID(fixedWorkspaceID)
|
||||
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
@@ -226,7 +226,7 @@ describe("HttpApi instance context middleware", () => {
|
||||
|
||||
it.live("falls through to local instead of MissingWorkspace when configured workspace id is set", () =>
|
||||
Effect.gen(function* () {
|
||||
const fixedWorkspaceID = WorkspaceID.ascending()
|
||||
const fixedWorkspaceID = WorkspaceV2.ID.ascending()
|
||||
yield* withFixedWorkspaceID(fixedWorkspaceID)
|
||||
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
@@ -238,7 +238,7 @@ describe("HttpApi instance context middleware", () => {
|
||||
// MissingWorkspace response. With the env set, planRequest must skip the
|
||||
// MissingWorkspace branch and fall through to Local with the configured
|
||||
// workspace id.
|
||||
const unknownWorkspaceID = WorkspaceID.ascending()
|
||||
const unknownWorkspaceID = WorkspaceV2.ID.ascending()
|
||||
const response = yield* HttpClientRequest.get(`/probe?workspace=${unknownWorkspaceID}`).pipe(
|
||||
HttpClientRequest.setHeader("x-opencode-directory", dir),
|
||||
HttpClient.execute,
|
||||
@@ -254,7 +254,7 @@ describe("HttpApi instance context middleware", () => {
|
||||
|
||||
it.live("keeps configured workspace id on control-plane routes without remote routing", () =>
|
||||
Effect.gen(function* () {
|
||||
const fixedWorkspaceID = WorkspaceID.ascending()
|
||||
const fixedWorkspaceID = WorkspaceV2.ID.ascending()
|
||||
yield* withFixedWorkspaceID(fixedWorkspaceID)
|
||||
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
|
||||
@@ -4,12 +4,12 @@ import { describe, expect } from "bun:test"
|
||||
import { Config, Context, Effect, FileSystem, Layer, Path } from "effect"
|
||||
import { HttpClient, HttpClientRequest, HttpRouter, HttpServer } from "effect/unstable/http"
|
||||
import * as Socket from "effect/unstable/socket/Socket"
|
||||
import { WorkspaceID } from "../../src/control-plane/schema"
|
||||
import { WorkspaceV2 } from "@opencode-ai/core/workspace"
|
||||
import { ControlPaths } from "../../src/server/routes/instance/httpapi/groups/control"
|
||||
import { InstancePaths } from "../../src/server/routes/instance/httpapi/groups/instance"
|
||||
import { SessionPaths } from "../../src/server/routes/instance/httpapi/groups/session"
|
||||
import { PermissionID } from "../../src/permission/schema"
|
||||
import { ProjectID } from "../../src/project/schema"
|
||||
import { ProjectV2 } from "@opencode-ai/core/project"
|
||||
import { QuestionID } from "../../src/question/schema"
|
||||
import { HttpApiApp } from "../../src/server/routes/instance/httpapi/server"
|
||||
import { HEADER as FenceHeader } from "../../src/server/shared/fence"
|
||||
@@ -76,7 +76,7 @@ describe("instance HttpApi", () => {
|
||||
it.live("emits a sync fence header for fixed-workspace mutations", () =>
|
||||
Effect.gen(function* () {
|
||||
const originalWorkspaceID = Flag.OPENCODE_WORKSPACE_ID
|
||||
Flag.OPENCODE_WORKSPACE_ID = WorkspaceID.ascending()
|
||||
Flag.OPENCODE_WORKSPACE_ID = WorkspaceV2.ID.ascending()
|
||||
yield* Effect.addFinalizer(() =>
|
||||
Effect.sync(() => {
|
||||
Flag.OPENCODE_WORKSPACE_ID = originalWorkspaceID
|
||||
@@ -98,7 +98,7 @@ describe("instance HttpApi", () => {
|
||||
it.live("does not emit sync fence headers for fixed-workspace reads or no-op mutations", () =>
|
||||
Effect.gen(function* () {
|
||||
const originalWorkspaceID = Flag.OPENCODE_WORKSPACE_ID
|
||||
Flag.OPENCODE_WORKSPACE_ID = WorkspaceID.ascending()
|
||||
Flag.OPENCODE_WORKSPACE_ID = WorkspaceV2.ID.ascending()
|
||||
yield* Effect.addFinalizer(() =>
|
||||
Effect.sync(() => {
|
||||
Flag.OPENCODE_WORKSPACE_ID = originalWorkspaceID
|
||||
@@ -209,7 +209,7 @@ describe("instance HttpApi", () => {
|
||||
it.live("returns typed not found bodies for missing projects", () =>
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
const projectID = ProjectID.make("project_missing")
|
||||
const projectID = ProjectV2.ID.make("project_missing")
|
||||
const response = yield* Effect.promise(() =>
|
||||
HttpApiApp.webHandler().handler(
|
||||
new Request(`http://localhost/project/${projectID}`, {
|
||||
|
||||
@@ -15,7 +15,7 @@ import Http from "node:http"
|
||||
import { mkdir } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { registerAdapter } from "../../src/control-plane/adapters"
|
||||
import { WorkspaceID } from "../../src/control-plane/schema"
|
||||
import { WorkspaceV2 } from "@opencode-ai/core/workspace"
|
||||
import type { WorkspaceAdapter } from "../../src/control-plane/types"
|
||||
import { Workspace } from "../../src/control-plane/workspace"
|
||||
import { WorkspaceTable } from "@opencode-ai/core/control-plane/workspace.sql"
|
||||
@@ -161,7 +161,7 @@ const insertRemoteWorkspaceWithoutSync = (input: {
|
||||
url: string
|
||||
}) =>
|
||||
Effect.sync(() => {
|
||||
const id = WorkspaceID.ascending()
|
||||
const id = WorkspaceV2.ID.ascending()
|
||||
registerAdapter(input.projectID, input.type, remoteAdapter(path.join(input.dir, `.${input.type}`), input.url))
|
||||
Database.use((db) => db.insert(WorkspaceTable).values({ id, type: input.type, project_id: input.projectID }).run())
|
||||
return id
|
||||
@@ -286,9 +286,9 @@ describe("HttpApi workspace routing middleware", () => {
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
const project = yield* Project.use.fromDirectory(dir)
|
||||
const workspaceID = WorkspaceID.ascending()
|
||||
const workspaceID = WorkspaceV2.ID.ascending()
|
||||
const type = "remote-http-fence-target"
|
||||
const waited = yield* Ref.make<{ workspaceID: WorkspaceID; state: Record<string, number> } | undefined>(undefined)
|
||||
const waited = yield* Ref.make<{ workspaceID: WorkspaceV2.ID; state: Record<string, number> } | undefined>(undefined)
|
||||
|
||||
const remoteUrl = yield* startRemoteWorkspaceHttpServer(() =>
|
||||
HttpServerResponse.json(
|
||||
@@ -403,7 +403,7 @@ describe("HttpApi workspace routing middleware", () => {
|
||||
|
||||
it.live("returns a missing workspace response for unknown workspace ids", () =>
|
||||
Effect.gen(function* () {
|
||||
const workspaceID = WorkspaceID.ascending("wrk_missing")
|
||||
const workspaceID = WorkspaceV2.ID.ascending("wrk_missing")
|
||||
// If the middleware resolves the workspace first, this handler is never
|
||||
// reached and the response should be the middleware error response.
|
||||
yield* HttpRouter.add("GET", "/probe", HttpServerResponse.text("route called")).pipe(
|
||||
|
||||
@@ -5,7 +5,7 @@ import path from "node:path"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
import { registerAdapter } from "../../src/control-plane/adapters"
|
||||
import { WorkspaceID } from "../../src/control-plane/schema"
|
||||
import { WorkspaceV2 } from "@opencode-ai/core/workspace"
|
||||
import type { WorkspaceAdapter } from "../../src/control-plane/types"
|
||||
import { Workspace } from "../../src/control-plane/workspace"
|
||||
import { WorkspacePaths } from "../../src/server/routes/instance/httpapi/groups/workspace"
|
||||
@@ -255,7 +255,7 @@ describe("workspace HttpApi", () => {
|
||||
Effect.gen(function* () {
|
||||
const dir = yield* tmpdirScoped({ git: true })
|
||||
const session = yield* Session.use.create({}).pipe(provideInstance(dir))
|
||||
const workspaceID = WorkspaceID.ascending("wrk_missing_warp")
|
||||
const workspaceID = WorkspaceV2.ID.ascending("wrk_missing_warp")
|
||||
|
||||
const response = yield* request(WorkspacePaths.warp, dir, {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user