Normalize instance lifecycle wiring (#25501)

This commit is contained in:
Kit Langton
2026-05-02 20:39:20 -04:00
committed by GitHub
parent a6464062b7
commit 7d91d3b1ed
71 changed files with 852 additions and 936 deletions
@@ -5,6 +5,7 @@ import { unlink } from "fs/promises"
import { ProviderID } from "../../src/provider/schema"
import { tmpdir } from "../fixture/fixture"
import { Instance } from "../../src/project/instance"
import { WithInstance } from "../../src/project/with-instance"
import { Provider } from "@/provider/provider"
import { Env } from "../../src/env"
import { Global } from "@opencode-ai/core/global"
@@ -43,13 +44,11 @@ test("Bedrock: config region takes precedence over AWS_REGION env var", async ()
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
fn: async () => {
set("AWS_REGION", "us-east-1")
set("AWS_PROFILE", "default")
}).pipe(Effect.asVoid),
fn: async () => {
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
expect(providers[ProviderID.amazonBedrock].options?.region).toBe("eu-west-1")
@@ -68,13 +67,11 @@ test("Bedrock: falls back to AWS_REGION env var when no config region", async ()
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
fn: async () => {
set("AWS_REGION", "eu-west-1")
set("AWS_PROFILE", "default")
}).pipe(Effect.asVoid),
fn: async () => {
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
expect(providers[ProviderID.amazonBedrock].options?.region).toBe("eu-west-1")
@@ -123,14 +120,12 @@ test("Bedrock: loads when bearer token from auth.json is present", async () => {
}),
)
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
fn: async () => {
set("AWS_PROFILE", "")
set("AWS_ACCESS_KEY_ID", "")
set("AWS_BEARER_TOKEN_BEDROCK", "")
}).pipe(Effect.asVoid),
fn: async () => {
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
expect(providers[ProviderID.amazonBedrock].options?.region).toBe("eu-west-1")
@@ -169,13 +164,11 @@ test("Bedrock: config profile takes precedence over AWS_PROFILE env var", async
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
fn: async () => {
set("AWS_PROFILE", "default")
set("AWS_ACCESS_KEY_ID", "test-key-id")
}).pipe(Effect.asVoid),
fn: async () => {
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
expect(providers[ProviderID.amazonBedrock].options?.region).toBe("us-east-1")
@@ -201,12 +194,10 @@ test("Bedrock: includes custom endpoint in options when specified", async () =>
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
set("AWS_PROFILE", "default")
}).pipe(Effect.asVoid),
fn: async () => {
set("AWS_PROFILE", "default")
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
expect(providers[ProviderID.amazonBedrock].options?.endpoint).toBe(
@@ -234,15 +225,13 @@ test("Bedrock: autoloads when AWS_WEB_IDENTITY_TOKEN_FILE is present", async ()
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
fn: async () => {
set("AWS_WEB_IDENTITY_TOKEN_FILE", "/var/run/secrets/eks.amazonaws.com/serviceaccount/token")
set("AWS_ROLE_ARN", "arn:aws:iam::123456789012:role/my-eks-role")
set("AWS_PROFILE", "")
set("AWS_ACCESS_KEY_ID", "")
}).pipe(Effect.asVoid),
fn: async () => {
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
expect(providers[ProviderID.amazonBedrock].options?.region).toBe("us-east-1")
@@ -277,12 +266,10 @@ test("Bedrock: model with us. prefix should not be double-prefixed", async () =>
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
set("AWS_PROFILE", "default")
}).pipe(Effect.asVoid),
fn: async () => {
set("AWS_PROFILE", "default")
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
// The model should exist with the us. prefix
@@ -314,12 +301,10 @@ test("Bedrock: model with global. prefix should not be prefixed", async () => {
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
set("AWS_PROFILE", "default")
}).pipe(Effect.asVoid),
fn: async () => {
set("AWS_PROFILE", "default")
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
expect(providers[ProviderID.amazonBedrock].models["global.anthropic.claude-opus-4-5-20251101-v1:0"]).toBeDefined()
@@ -350,12 +335,10 @@ test("Bedrock: model with eu. prefix should not be double-prefixed", async () =>
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
set("AWS_PROFILE", "default")
}).pipe(Effect.asVoid),
fn: async () => {
set("AWS_PROFILE", "default")
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
expect(providers[ProviderID.amazonBedrock].models["eu.anthropic.claude-opus-4-5-20251101-v1:0"]).toBeDefined()
@@ -386,12 +369,10 @@ test("Bedrock: model without prefix in US region should get us. prefix added", a
)
},
})
await Instance.provide({
await WithInstance.provide({
directory: tmp.path,
init: Effect.promise(async () => {
set("AWS_PROFILE", "default")
}).pipe(Effect.asVoid),
fn: async () => {
set("AWS_PROFILE", "default")
const providers = await list()
expect(providers[ProviderID.amazonBedrock]).toBeDefined()
// Non-prefixed model should still be registered