test(session): migrate structured output integration test (#27143)
This commit is contained in:
@@ -1,39 +1,22 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import path from "path"
|
|
||||||
import { Effect, Layer } from "effect"
|
import { Effect, Layer } from "effect"
|
||||||
import { Session } from "@/session/session"
|
import { Session } from "@/session/session"
|
||||||
import { SessionPrompt } from "../../src/session/prompt"
|
import { SessionPrompt } from "../../src/session/prompt"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { Instance } from "../../src/project/instance"
|
|
||||||
import { WithInstance } from "../../src/project/with-instance"
|
|
||||||
import { MessageV2 } from "../../src/session/message-v2"
|
import { MessageV2 } from "../../src/session/message-v2"
|
||||||
|
import { testEffect } from "../lib/effect"
|
||||||
|
|
||||||
const projectRoot = path.join(__dirname, "../..")
|
|
||||||
void Log.init({ print: false })
|
void Log.init({ print: false })
|
||||||
|
|
||||||
// Skip tests if no API key is available
|
// Skip tests if no API key is available
|
||||||
const hasApiKey = !!process.env.ANTHROPIC_API_KEY
|
const hasApiKey = !!process.env.ANTHROPIC_API_KEY
|
||||||
|
const it = testEffect(Layer.mergeAll(SessionPrompt.defaultLayer, Session.defaultLayer))
|
||||||
// Helper to run test within Instance context
|
const live = hasApiKey ? it.instance : it.instance.skip
|
||||||
async function withInstance<T>(fn: () => Promise<T>): Promise<T> {
|
|
||||||
return WithInstance.provide({
|
|
||||||
directory: projectRoot,
|
|
||||||
fn,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function run<A, E>(fx: Effect.Effect<A, E, SessionPrompt.Service | Session.Service>) {
|
|
||||||
return Effect.runPromise(
|
|
||||||
fx.pipe(Effect.scoped, Effect.provide(Layer.mergeAll(SessionPrompt.defaultLayer, Session.defaultLayer))),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("StructuredOutput Integration", () => {
|
describe("StructuredOutput Integration", () => {
|
||||||
test.skipIf(!hasApiKey)(
|
live(
|
||||||
"produces structured output with simple schema",
|
"produces structured output with simple schema",
|
||||||
async () => {
|
() =>
|
||||||
await withInstance(() =>
|
|
||||||
run(
|
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const prompt = yield* SessionPrompt.Service
|
const prompt = yield* SessionPrompt.Service
|
||||||
const sessions = yield* Session.Service
|
const sessions = yield* Session.Service
|
||||||
@@ -77,17 +60,13 @@ describe("StructuredOutput Integration", () => {
|
|||||||
// Clean up
|
// Clean up
|
||||||
// Note: Not removing session to avoid race with background SessionSummary.summarize
|
// Note: Not removing session to avoid race with background SessionSummary.summarize
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true },
|
||||||
)
|
|
||||||
},
|
|
||||||
60000,
|
60000,
|
||||||
)
|
)
|
||||||
|
|
||||||
test.skipIf(!hasApiKey)(
|
live(
|
||||||
"produces structured output with nested objects",
|
"produces structured output with nested objects",
|
||||||
async () => {
|
() =>
|
||||||
await withInstance(() =>
|
|
||||||
run(
|
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const prompt = yield* SessionPrompt.Service
|
const prompt = yield* SessionPrompt.Service
|
||||||
const sessions = yield* Session.Service
|
const sessions = yield* Session.Service
|
||||||
@@ -146,17 +125,13 @@ describe("StructuredOutput Integration", () => {
|
|||||||
// Clean up
|
// Clean up
|
||||||
// Note: Not removing session to avoid race with background SessionSummary.summarize
|
// Note: Not removing session to avoid race with background SessionSummary.summarize
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true },
|
||||||
)
|
|
||||||
},
|
|
||||||
60000,
|
60000,
|
||||||
)
|
)
|
||||||
|
|
||||||
test.skipIf(!hasApiKey)(
|
live(
|
||||||
"works with text outputFormat (default)",
|
"works with text outputFormat (default)",
|
||||||
async () => {
|
() =>
|
||||||
await withInstance(() =>
|
|
||||||
run(
|
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const prompt = yield* SessionPrompt.Service
|
const prompt = yield* SessionPrompt.Service
|
||||||
const sessions = yield* Session.Service
|
const sessions = yield* Session.Service
|
||||||
@@ -188,17 +163,13 @@ describe("StructuredOutput Integration", () => {
|
|||||||
// Clean up
|
// Clean up
|
||||||
// Note: Not removing session to avoid race with background SessionSummary.summarize
|
// Note: Not removing session to avoid race with background SessionSummary.summarize
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true },
|
||||||
)
|
|
||||||
},
|
|
||||||
60000,
|
60000,
|
||||||
)
|
)
|
||||||
|
|
||||||
test.skipIf(!hasApiKey)(
|
live(
|
||||||
"stores outputFormat on user message",
|
"stores outputFormat on user message",
|
||||||
async () => {
|
() =>
|
||||||
await withInstance(() =>
|
|
||||||
run(
|
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const prompt = yield* SessionPrompt.Service
|
const prompt = yield* SessionPrompt.Service
|
||||||
const sessions = yield* Session.Service
|
const sessions = yield* Session.Service
|
||||||
@@ -242,9 +213,7 @@ describe("StructuredOutput Integration", () => {
|
|||||||
// Clean up
|
// Clean up
|
||||||
// Note: Not removing session to avoid race with background SessionSummary.summarize
|
// Note: Not removing session to avoid race with background SessionSummary.summarize
|
||||||
}),
|
}),
|
||||||
),
|
{ git: true },
|
||||||
)
|
|
||||||
},
|
|
||||||
60000,
|
60000,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user