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:
@@ -5,6 +5,7 @@ import { tmpdir } from "node:os"
|
||||
|
||||
import { processWithCli } from "./cli-runner"
|
||||
import type { PendingCall } from "./types"
|
||||
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
||||
|
||||
function createMockInput() {
|
||||
return {
|
||||
@@ -74,7 +75,7 @@ done
|
||||
const originalSetTimeout = globalThis.setTimeout
|
||||
globalThis.setTimeout = ((fn: (...args: unknown[]) => void, _ms?: number) => {
|
||||
fn()
|
||||
return testCoerce<ReturnType<typeof setTimeout>>(0)
|
||||
return unsafeTestValue<ReturnType<typeof setTimeout>>(0)
|
||||
}) as typeof setTimeout
|
||||
|
||||
try {
|
||||
@@ -102,7 +103,7 @@ done
|
||||
const originalSetTimeout = globalThis.setTimeout
|
||||
globalThis.setTimeout = ((fn: (...args: unknown[]) => void, _ms?: number) => {
|
||||
fn()
|
||||
return testCoerce<ReturnType<typeof setTimeout>>(0)
|
||||
return unsafeTestValue<ReturnType<typeof setTimeout>>(0)
|
||||
}) as typeof setTimeout
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, test, expect } from "bun:test"
|
||||
import { unsafeTestValue } from "../../../test-support/unsafe-test-value"
|
||||
|
||||
describe("pending-calls cleanup interval", () => {
|
||||
test("starts cleanup once and unrefs timer", async () => {
|
||||
@@ -7,13 +8,13 @@ describe("pending-calls cleanup interval", () => {
|
||||
const setIntervalCalls: number[] = []
|
||||
let unrefCalled = 0
|
||||
|
||||
globalThis.setInterval = testCoerce<typeof setInterval>(((
|
||||
globalThis.setInterval = unsafeTestValue<typeof setInterval>(((
|
||||
_handler: TimerHandler,
|
||||
timeout?: number,
|
||||
..._args: unknown[]
|
||||
) => {
|
||||
setIntervalCalls.push(timeout as number)
|
||||
return testCoerce<ReturnType<typeof setInterval>>({
|
||||
return unsafeTestValue<ReturnType<typeof setInterval>>({
|
||||
unref: () => {
|
||||
unrefCalled += 1
|
||||
},
|
||||
@@ -43,16 +44,16 @@ describe("pending-calls cleanup interval", () => {
|
||||
let intervalHandle: ReturnType<typeof setInterval> | undefined
|
||||
let clearCalls = 0
|
||||
|
||||
globalThis.setInterval = testCoerce<typeof setInterval>(((
|
||||
globalThis.setInterval = unsafeTestValue<typeof setInterval>(((
|
||||
_handler: TimerHandler,
|
||||
_timeout?: number,
|
||||
..._args: unknown[]
|
||||
) => {
|
||||
intervalHandle = testCoerce<ReturnType<typeof setInterval>>({ unref: () => {} })
|
||||
intervalHandle = unsafeTestValue<ReturnType<typeof setInterval>>({ unref: () => {} })
|
||||
return intervalHandle
|
||||
}))
|
||||
|
||||
globalThis.clearInterval = testCoerce<typeof clearInterval>(((handle?: ReturnType<typeof setInterval>) => {
|
||||
globalThis.clearInterval = unsafeTestValue<typeof clearInterval>(((handle?: ReturnType<typeof setInterval>) => {
|
||||
if (handle === intervalHandle) {
|
||||
clearCalls += 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user