test: make unsafe test coercion explicit
Move test coercion out of a hidden global and require each test to import the helper so review tools and runtime scripts can see the unsafe boundary. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -6,6 +6,7 @@ import { describe, expect, mock, test } from "bun:test"
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import { clearPendingStore, consumeToolMetadata } from "../../features/tool-metadata-store"
|
||||
import { createBackgroundTask } from "./create-background-task"
|
||||
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
||||
|
||||
const projectDir = "/Users/yeongyu/local-workspaces/oh-my-opencode"
|
||||
|
||||
@@ -18,7 +19,7 @@ describe("createBackgroundTask metadata", () => {
|
||||
// #given
|
||||
clearPendingStore()
|
||||
|
||||
const manager = testCoerce<BackgroundManager>({
|
||||
const manager = unsafeTestValue<BackgroundManager>({
|
||||
launch: mock(() => Promise.resolve({
|
||||
id: "task-1",
|
||||
sessionID: null,
|
||||
@@ -28,7 +29,7 @@ describe("createBackgroundTask metadata", () => {
|
||||
})),
|
||||
getTask: mock(() => undefined),
|
||||
})
|
||||
const client = testCoerce<PluginInput["client"]>({
|
||||
const client = unsafeTestValue<PluginInput["client"]>({
|
||||
session: {
|
||||
messages: mock(() => Promise.resolve({ data: [] })),
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import { describe, test, expect, mock } from "bun:test"
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { createBackgroundTask } from "./create-background-task"
|
||||
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
||||
|
||||
describe("createBackgroundTask", () => {
|
||||
const launchMock = mock(async (): Promise<{
|
||||
@@ -21,12 +22,12 @@ describe("createBackgroundTask", () => {
|
||||
}))
|
||||
const getTaskMock = mock()
|
||||
|
||||
const mockManager = testCoerce<BackgroundManager>({
|
||||
const mockManager = unsafeTestValue<BackgroundManager>({
|
||||
launch: launchMock,
|
||||
getTask: getTaskMock,
|
||||
})
|
||||
|
||||
const mockClient = testCoerce<PluginInput["client"]>({
|
||||
const mockClient = unsafeTestValue<PluginInput["client"]>({
|
||||
session: {
|
||||
messages: mock(() => Promise.resolve({ data: [] })),
|
||||
},
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { BackgroundManager, BackgroundTask } from "../../features/backgroun
|
||||
import type { ToolContext } from "@opencode-ai/plugin/tool"
|
||||
import type { BackgroundCancelClient, BackgroundOutputManager, BackgroundOutputClient } from "./tools"
|
||||
import { consumeToolMetadata, clearPendingStore } from "../../features/tool-metadata-store"
|
||||
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
||||
|
||||
const projectDir = "/Users/yeongyu/local-workspaces/oh-my-opencode"
|
||||
|
||||
@@ -66,7 +67,7 @@ describe("background_output full_session", () => {
|
||||
const manager = createMockManager(task)
|
||||
const client = createMockClient({})
|
||||
const tool = createBackgroundOutput(manager, client)
|
||||
const ctxWithCallId = testCoerce<ToolContext>({
|
||||
const ctxWithCallId = unsafeTestValue<ToolContext>({
|
||||
...mockContext,
|
||||
callID: "call-1",
|
||||
})
|
||||
@@ -93,7 +94,7 @@ describe("background_output full_session", () => {
|
||||
const manager = createMockManager(task)
|
||||
const client = createMockClient({})
|
||||
const tool = createBackgroundOutput(manager, client)
|
||||
const ctxWithCallId = testCoerce<ToolContext>({
|
||||
const ctxWithCallId = unsafeTestValue<ToolContext>({
|
||||
...mockContext,
|
||||
callID: "call-1",
|
||||
})
|
||||
@@ -387,7 +388,7 @@ describe("background_cancel", () => {
|
||||
// #given
|
||||
const task = createTask({ status: "running" })
|
||||
const cancelled: string[] = []
|
||||
const manager = testCoerce<BackgroundManager>({
|
||||
const manager = unsafeTestValue<BackgroundManager>({
|
||||
getTask: (id: string) => (id === task.id ? task : undefined),
|
||||
getAllDescendantTasks: () => [task],
|
||||
cancelTask: async (taskId: string) => {
|
||||
@@ -412,7 +413,7 @@ describe("background_cancel", () => {
|
||||
const taskA = createTask({ id: "task-a", status: "running" })
|
||||
const taskB = createTask({ id: "task-b", status: "pending" })
|
||||
const cancelled: string[] = []
|
||||
const manager = testCoerce<BackgroundManager>({
|
||||
const manager = unsafeTestValue<BackgroundManager>({
|
||||
getTask: () => undefined,
|
||||
getAllDescendantTasks: () => [taskA, taskB],
|
||||
cancelTask: async (taskId: string) => {
|
||||
@@ -437,7 +438,7 @@ describe("background_cancel", () => {
|
||||
// #given
|
||||
const taskA = createTask({ id: "task-a", status: "running", sessionId: "ses-a", description: "running task" })
|
||||
const taskB = createTask({ id: "task-b", status: "pending", sessionId: undefined, description: "pending task" })
|
||||
const manager = testCoerce<BackgroundManager>({
|
||||
const manager = unsafeTestValue<BackgroundManager>({
|
||||
getTask: () => undefined,
|
||||
getAllDescendantTasks: () => [taskA, taskB],
|
||||
cancelTask: async (taskId: string) => {
|
||||
@@ -461,7 +462,7 @@ describe("background_cancel", () => {
|
||||
// #given
|
||||
const task = createTask({ id: "task-1", status: "running" })
|
||||
const cancelOptions: Array<{ taskId: string; options: unknown }> = []
|
||||
const manager = testCoerce<BackgroundManager>({
|
||||
const manager = unsafeTestValue<BackgroundManager>({
|
||||
getTask: (id: string) => (id === task.id ? task : undefined),
|
||||
getAllDescendantTasks: () => [task],
|
||||
cancelTask: async (taskId: string, options?: unknown) => {
|
||||
@@ -487,7 +488,7 @@ describe("background_cancel", () => {
|
||||
// #given
|
||||
const task = createTask({ id: "task-1", status: "running" })
|
||||
const cancelOptions: Array<{ taskId: string; options: unknown }> = []
|
||||
const manager = testCoerce<BackgroundManager>({
|
||||
const manager = unsafeTestValue<BackgroundManager>({
|
||||
getTask: (id: string) => (id === task.id ? task : undefined),
|
||||
getAllDescendantTasks: () => [task],
|
||||
cancelTask: async (taskId: string, options?: unknown) => {
|
||||
|
||||
Reference in New Issue
Block a user