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 @@
import { describe, expect, test, spyOn, beforeEach, afterEach } from "bun:test"
import * as childProcess from "node:child_process"
import * as fs from "node:fs"
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
describe("collectGitDiffStats", () => {
let execFileSyncSpy: ReturnType<typeof spyOn>
@@ -52,7 +53,7 @@ describe("collectGitDiffStats", () => {
expect(execSyncSpy).not.toHaveBeenCalled()
expect(execFileSyncSpy.mock.calls.length).toBeGreaterThanOrEqual(3)
const calls = testCoerce<Array<[string, string[], { cwd?: string }]>>(execFileSyncSpy.mock.calls)
const calls = unsafeTestValue<Array<[string, string[], { cwd?: string }]>>(execFileSyncSpy.mock.calls)
const diffCall = calls.find(([, args]) => args[0] === "diff")
const statusCall = calls.find(([, args]) => args[0] === "status")
const untrackedCall = calls.find(([, args]) => args[0] === "ls-files")
+14 -13
View File
@@ -1,5 +1,6 @@
import { describe, it, expect, mock } from "bun:test"
import { parseModelSuggestion, promptWithModelSuggestionRetry, promptSyncWithModelSuggestionRetry } from "./model-suggestion-retry"
import { unsafeTestValue } from "../../test-support/unsafe-test-value"
describe("parseModelSuggestion", () => {
describe("structured NamedError format", () => {
@@ -217,7 +218,7 @@ describe("promptWithModelSuggestionRetry", () => {
const client = { session: { promptAsync: promptMock } }
// when calling promptWithModelSuggestionRetry
await promptWithModelSuggestionRetry(testCoerce(client), {
await promptWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -244,7 +245,7 @@ describe("promptWithModelSuggestionRetry", () => {
// when calling promptWithModelSuggestionRetry
// then should throw the error without retrying
await expect(
promptWithModelSuggestionRetry(testCoerce(client), {
promptWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
agent: "explore",
@@ -267,7 +268,7 @@ describe("promptWithModelSuggestionRetry", () => {
// when calling promptWithModelSuggestionRetry
// then should throw the original error
await expect(
promptWithModelSuggestionRetry(testCoerce(client), {
promptWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -288,7 +289,7 @@ describe("promptWithModelSuggestionRetry", () => {
// when calling promptWithModelSuggestionRetry
// then should throw the error
await expect(
promptWithModelSuggestionRetry(testCoerce(client), {
promptWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -307,7 +308,7 @@ describe("promptWithModelSuggestionRetry", () => {
const client = { session: { promptAsync: promptMock } }
// when calling with additional body fields
await promptWithModelSuggestionRetry(testCoerce(client), {
await promptWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
agent: "explore",
@@ -341,7 +342,7 @@ describe("promptWithModelSuggestionRetry", () => {
// when calling promptWithModelSuggestionRetry
// then should throw the error
await expect(
promptWithModelSuggestionRetry(testCoerce(client), {
promptWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -365,7 +366,7 @@ describe("promptWithModelSuggestionRetry", () => {
// when calling without model in body
// then should throw the error
await expect(
promptWithModelSuggestionRetry(testCoerce(client), {
promptWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -386,7 +387,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
const client = { session: { prompt: promptMock, promptAsync: promptAsyncMock } }
// when calling promptSyncWithModelSuggestionRetry
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
await promptSyncWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -424,7 +425,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
// when calling with short timeout
// then should abort the request and throw timeout error
await expect(
promptSyncWithModelSuggestionRetry(testCoerce(client), {
promptSyncWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -451,7 +452,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
const client = { session: { prompt: promptMock } }
// when calling promptSyncWithModelSuggestionRetry
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
await promptSyncWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -477,7 +478,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
// when calling promptSyncWithModelSuggestionRetry
// then should throw the original error
await expect(
promptSyncWithModelSuggestionRetry(testCoerce(client), {
promptSyncWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -504,7 +505,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
// when calling without model in body
// then should throw (cannot retry without original model)
await expect(
promptSyncWithModelSuggestionRetry(testCoerce(client), {
promptSyncWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
parts: [{ type: "text", text: "hello" }],
@@ -521,7 +522,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
const client = { session: { prompt: promptMock } }
// when calling with additional body fields
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
await promptSyncWithModelSuggestionRetry(unsafeTestValue(client), {
path: { id: "session-1" },
body: {
agent: "multimodal-looker",