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:
YeonGyu-Kim
2026-05-12 15:38:31 +09:00
parent ce5da13fc5
commit d5fbada13d
103 changed files with 700 additions and 554 deletions
@@ -3,6 +3,7 @@ const { describe, test, expect, beforeEach, afterEach, spyOn, mock } = require("
import { resolveCategoryExecution } from "./category-resolver"
import type { ExecutorContext } from "./executor-types"
import * as connectedProvidersCache from "../../shared/connected-providers-cache"
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
describe("resolveCategoryExecution", () => {
let connectedProvidersSpy: ReturnType<typeof spyOn> | undefined
@@ -26,8 +27,8 @@ describe("resolveCategoryExecution", () => {
})
const createMockExecutorContext = (): ExecutorContext => ({
client: testCoerce({}),
manager: testCoerce({}),
client: unsafeTestValue({}),
manager: unsafeTestValue({}),
directory: "/tmp/test",
userCategories: {},
sisyphusJuniorModel: undefined,
@@ -2,6 +2,7 @@ const { describe, test, expect } = require("bun:test")
import { executeBackgroundTask } from "./executor"
import type { DelegateTaskArgs, ToolContextWithMetadata } from "./types"
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
describe("task tool metadata awaiting", () => {
test("executeBackgroundTask awaits ctx.metadata before returning", async () => {
@@ -28,7 +29,7 @@ describe("task tool metadata awaiting", () => {
subagent_type: "explore",
}
const executorCtx = testCoerce({
const executorCtx = unsafeTestValue({
manager: {
launch: async () => ({
id: "task_1",
@@ -2,6 +2,7 @@ const { describe, test, expect } = require("bun:test")
import type { DelegateTaskArgs, ToolContextWithMetadata } from "./types"
import type { ParentContext } from "./executor-types"
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
const MODEL = { providerID: "anthropic", modelID: "claude-sonnet-4-6" }
const MODEL_WITH_VARIANT = { providerID: "google", modelID: "gemini-3.1-pro", variant: "high" }
@@ -63,7 +64,7 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, testCoerce({
await executeBackgroundTask(args, ctx, unsafeTestValue({
manager: {
launch: async () => ({
id: "bg_1", description: "test", agent: "explore",
@@ -92,7 +93,7 @@ describe("metadata model unification", () => {
}
await executeUnstableAgentTask(
args, ctx,
testCoerce({
unsafeTestValue({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -126,7 +127,7 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed",
}
await executeBackgroundContinuation(args, ctx, testCoerce({
await executeBackgroundContinuation(args, ctx, unsafeTestValue({
manager: {
resume: async () => ({
id: "bg_2", description: "continue", agent: "explore",
@@ -153,7 +154,7 @@ describe("metadata model unification", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, testCoerce({
await executeSyncContinuation(args, ctx, unsafeTestValue({
client: {
session: {
messages: async () => ({
@@ -206,7 +207,7 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, testCoerce({
await executeBackgroundTask(args, ctx, unsafeTestValue({
manager: {
launch: async () => ({
id: "bg_1", description: "test", agent: "explore",
@@ -236,7 +237,7 @@ describe("metadata model unification", () => {
await executeUnstableAgentTask(
args, ctx,
testCoerce({
unsafeTestValue({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -270,7 +271,7 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed",
}
await executeBackgroundContinuation(args, ctx, testCoerce({
await executeBackgroundContinuation(args, ctx, unsafeTestValue({
manager: {
resume: async () => ({
id: "bg_2", description: "continue", agent: "explore",
@@ -297,7 +298,7 @@ describe("metadata model unification", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, testCoerce({
await executeSyncContinuation(args, ctx, unsafeTestValue({
client: {
session: {
messages: async () => ({ data: [] }),
@@ -381,7 +382,7 @@ describe("metadata model unification", () => {
category: "visual-engineering", load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, testCoerce({
await executeBackgroundTask(args, ctx, unsafeTestValue({
manager: {
launch: async () => ({
id: "bg_variant", description: "test", agent: "explore",
@@ -411,7 +412,7 @@ describe("metadata model unification", () => {
await executeUnstableAgentTask(
args, ctx,
testCoerce({
unsafeTestValue({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -445,7 +446,7 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed_variant",
}
await executeBackgroundContinuation(args, ctx, testCoerce({
await executeBackgroundContinuation(args, ctx, unsafeTestValue({
manager: {
resume: async () => ({
id: "bg_resume_variant", description: "continue", agent: "explore",
@@ -472,7 +473,7 @@ describe("metadata model unification", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, testCoerce({
await executeSyncContinuation(args, ctx, unsafeTestValue({
client: {
session: {
messages: async () => ({
@@ -2,6 +2,7 @@ const { describe, test, expect } = require("bun:test")
import type { DelegateTaskArgs, ToolContextWithMetadata } from "./types"
import type { ParentContext } from "./executor-types"
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
const MODEL = { providerID: "anthropic", modelID: "claude-sonnet-4-6" }
@@ -64,7 +65,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, testCoerce({
await executeBackgroundTask(args, ctx, unsafeTestValue({
manager: {
launch: async () => ({
id: "bg_abc123", description: "test", agent: "explore",
@@ -98,7 +99,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
await executeUnstableAgentTask(
args, ctx,
testCoerce({
unsafeTestValue({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -136,7 +137,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed_x",
}
await executeBackgroundContinuation(args, ctx, testCoerce({
await executeBackgroundContinuation(args, ctx, unsafeTestValue({
manager: {
resume: async () => ({
id: "bg_resumed_y", description: "continue", agent: "explore",
@@ -160,7 +161,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed_x",
}
await executeBackgroundContinuation(args, ctx, testCoerce({
await executeBackgroundContinuation(args, ctx, unsafeTestValue({
manager: {
resume: async () => ({
id: "bg_resumed_y", description: "continue", agent: "explore",
@@ -187,7 +188,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
task_id: "ses_resumed_x",
}
await executeBackgroundContinuation(args, ctx, testCoerce({
await executeBackgroundContinuation(args, ctx, unsafeTestValue({
manager: {
resume: async () => ({
id: "bg_resumed_y", description: "continue", agent: "explore",
@@ -216,7 +217,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, testCoerce({
await executeSyncContinuation(args, ctx, unsafeTestValue({
client: {
session: {
messages: async () => ({
@@ -246,7 +247,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, testCoerce({
await executeSyncContinuation(args, ctx, unsafeTestValue({
client: {
session: {
messages: async () => ({
@@ -275,7 +276,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, testCoerce({
await executeSyncContinuation(args, ctx, unsafeTestValue({
client: {
session: {
messages: async () => ({
@@ -309,7 +310,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, testCoerce({
await executeSyncContinuation(args, ctx, unsafeTestValue({
client: {
session: {
messages: async () => ({
@@ -368,7 +369,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
run_in_background: true,
}
await executeBackgroundTask(args, ctx, testCoerce({
await executeBackgroundTask(args, ctx, unsafeTestValue({
manager: {
launch: async () => ({
id: "bg_abc123", description: "test", agent: "Sisyphus-Junior",
@@ -402,7 +403,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
await executeUnstableAgentTask(
args, ctx,
testCoerce({
unsafeTestValue({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -438,7 +439,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: true, task_id: "ses_resume_title",
}
await executeBackgroundContinuation(args, ctx, testCoerce({
await executeBackgroundContinuation(args, ctx, unsafeTestValue({
manager: {
resume: async () => ({
id: "bg_resume_title", description: "continue work", agent: "explore",
@@ -460,7 +461,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: false, task_id: "ses_sync_title",
}
await executeSyncContinuation(args, ctx, testCoerce({
await executeSyncContinuation(args, ctx, unsafeTestValue({
client: {
session: {
messages: async () => ({
@@ -500,8 +501,8 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
},
}
const bgOutput = createBackgroundOutput(testCoerce(manager), testCoerce(client))
await bgOutput.execute(testCoerce({ task_id: "bg_output_xyz" }), testCoerce(ctx))
const bgOutput = createBackgroundOutput(unsafeTestValue(manager), unsafeTestValue(client))
await bgOutput.execute(unsafeTestValue({ task_id: "bg_output_xyz" }), unsafeTestValue(ctx))
const meta = ctx.captured.find((m: any) => m.metadata?.backgroundTaskId)
expect(meta).toBeDefined()
+2 -1
View File
@@ -1,3 +1,4 @@
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
const { describe, expect, test } = require("bun:test")
function requireFresh<T>(modulePath: string): T {
@@ -18,7 +19,7 @@ function createDelegateTask(...args: Parameters<typeof import("./tools").createD
const toolDefinition = createDelegateTask({ manager: {} as never, client: {} as never, directory: "/tmp/test" })
//#when
const categorySchema = testCoerce<{
const categorySchema = unsafeTestValue<{
def: {
type: string
innerType: {
@@ -1,6 +1,7 @@
import { describe, expect, test } from "bun:test"
import { executeUnstableAgentTask } from "./unstable-agent-task"
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
describe("executeUnstableAgentTask session permission", () => {
test("passes question-deny session permission into background launch", async () => {
@@ -33,7 +34,7 @@ describe("executeUnstableAgentTask session permission", () => {
metadata: () => {},
abort: new AbortController().signal,
} satisfies Parameters<typeof executeUnstableAgentTask>[1]
const executorContext = testCoerce<Parameters<typeof executeUnstableAgentTask>[2]>({
const executorContext = unsafeTestValue<Parameters<typeof executeUnstableAgentTask>[2]>({
manager: mockManager,
client: {
session: {