feat(core): add opencode integration (#33555)
This commit is contained in:
parent
c17b9557f1
commit
cf80b5c470
26 changed files with 1061 additions and 439 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { test, expect, describe, afterEach, beforeEach, spyOn } from "bun:test"
|
||||
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
|
||||
import { Cause, Effect, Exit, Layer, Option } from "effect"
|
||||
import { Cause, Effect, Exit, Layer } from "effect"
|
||||
import { NamedError } from "@opencode-ai/core/util/error"
|
||||
import { FetchHttpClient, HttpClient, HttpClientResponse } from "effect/unstable/http"
|
||||
import { NodeFileSystem, NodePath } from "@effect/platform-node"
|
||||
|
|
@ -13,7 +13,6 @@ import { InstanceRef } from "../../src/effect/instance-ref"
|
|||
import type { InstanceContext } from "../../src/project/instance-context"
|
||||
import { Auth } from "../../src/auth"
|
||||
import { Account } from "../../src/account/account"
|
||||
import { AccessToken, AccountID, OrgID } from "../../src/account/schema"
|
||||
import { FSUtil } from "@opencode-ai/core/fs-util"
|
||||
import { Env } from "../../src/env"
|
||||
import {
|
||||
|
|
@ -141,7 +140,6 @@ const clear = (wait = false) => Effect.runPromise(clearEffect(wait))
|
|||
// Get managed config directory from environment (set in preload.ts)
|
||||
const managedConfigDir = process.env.OPENCODE_TEST_MANAGED_CONFIG_DIR!
|
||||
const originalTestToken = process.env.TEST_TOKEN
|
||||
const originalConsoleToken = process.env.OPENCODE_CONSOLE_TOKEN
|
||||
|
||||
beforeEach(async () => {
|
||||
await clear(true)
|
||||
|
|
@ -151,8 +149,6 @@ afterEach(async () => {
|
|||
await fs.rm(managedConfigDir, { force: true, recursive: true }).catch(() => {})
|
||||
if (originalTestToken === undefined) delete process.env.TEST_TOKEN
|
||||
else process.env.TEST_TOKEN = originalTestToken
|
||||
if (originalConsoleToken === undefined) delete process.env.OPENCODE_CONSOLE_TOKEN
|
||||
else process.env.OPENCODE_CONSOLE_TOKEN = originalConsoleToken
|
||||
await clear(true)
|
||||
})
|
||||
|
||||
|
|
@ -564,49 +560,6 @@ it.instance("handles file inclusion with replacement tokens", () =>
|
|||
}),
|
||||
)
|
||||
|
||||
const accountTokenIt = configIt({
|
||||
account: Layer.mock(Account.Service)({
|
||||
active: () =>
|
||||
Effect.succeed(
|
||||
Option.some({
|
||||
id: AccountID.make("account-1"),
|
||||
email: "user@example.com",
|
||||
url: "https://control.example.com",
|
||||
active_org_id: OrgID.make("org-1"),
|
||||
}),
|
||||
),
|
||||
activeOrg: () =>
|
||||
Effect.succeed(
|
||||
Option.some({
|
||||
account: {
|
||||
id: AccountID.make("account-1"),
|
||||
email: "user@example.com",
|
||||
url: "https://control.example.com",
|
||||
active_org_id: OrgID.make("org-1"),
|
||||
},
|
||||
org: {
|
||||
id: OrgID.make("org-1"),
|
||||
name: "Example Org",
|
||||
},
|
||||
}),
|
||||
),
|
||||
config: () =>
|
||||
Effect.succeed(
|
||||
Option.some({
|
||||
provider: { opencode: { options: { apiKey: "{env:OPENCODE_CONSOLE_TOKEN}" } } },
|
||||
}),
|
||||
),
|
||||
token: () => Effect.succeed(Option.some(AccessToken.make("st_test_token"))),
|
||||
}),
|
||||
})
|
||||
|
||||
accountTokenIt.instance("resolves env templates in account config with account token", () =>
|
||||
Effect.gen(function* () {
|
||||
const config = yield* Config.use.get()
|
||||
expect(config.provider?.["opencode"]?.options?.apiKey).toBe("st_test_token")
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("validates config schema and throws on invalid fields", () =>
|
||||
Effect.gen(function* () {
|
||||
const test = yield* TestInstance
|
||||
|
|
|
|||
|
|
@ -68,6 +68,20 @@ function isBuiltInEndpointError(name: string) {
|
|||
}
|
||||
|
||||
describe("PublicApi OpenAPI v2 errors", () => {
|
||||
test("includes plugin-facing core schemas", () => {
|
||||
const spec = OpenApi.fromApi(PublicApi) as OpenApiSpec
|
||||
|
||||
expect(Object.keys(spec.components.schemas)).toEqual(
|
||||
expect.arrayContaining([
|
||||
"CredentialValue",
|
||||
"IntegrationInputs",
|
||||
"IntegrationMethod",
|
||||
"IntegrationRef",
|
||||
"SkillV2Source",
|
||||
]),
|
||||
)
|
||||
})
|
||||
|
||||
test("documents nested legacy global sync events", () => {
|
||||
const spec = OpenApi.fromApi(PublicApi) as OpenApiSpec
|
||||
const schema = spec.components.schemas.SyncEventSessionCreated
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue