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
+13 -12
View File
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, jest, spyOn, test } from "bun:
import * as sender from "./session-notification-sender"
import * as utils from "./session-notification-utils"
import type { PluginInput } from "@opencode-ai/plugin"
import { unsafeTestValue } from "../../test-support/unsafe-test-value"
@@ -80,7 +81,7 @@ describe("session-notification-sender", () => {
describe("#when calling ctx.$ for notifications", () => {
test("#then should call .quiet() on all shell commands to suppress stdout/stderr", async () => {
const quietCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: (cmd: TemplateStringsArray, ...values: unknown[]) => {
const cmdStr = cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
const result = { stdout: Buffer.from(""), stderr: Buffer.from(""), exitCode: 0 }
@@ -107,7 +108,7 @@ describe("session-notification-sender", () => {
spyOn(utils, "getTerminalNotifierPath").mockResolvedValue(null)
const quietCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: (cmd: TemplateStringsArray, ...values: unknown[]) => {
const cmdStr = cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
const result = { stdout: Buffer.from(""), stderr: Buffer.from(""), exitCode: 0 }
@@ -142,7 +143,7 @@ describe("session-notification-sender", () => {
spyOn(utils, "getCmuxPath").mockResolvedValue("/usr/local/bin/cmux")
const calls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: createShellPromise((cmdStr) => { calls.push(cmdStr) }),
})
@@ -157,7 +158,7 @@ describe("session-notification-sender", () => {
test("#then should fall back to terminal-notifier when cmux fails", async () => {
spyOn(utils, "getCmuxPath").mockResolvedValue("/usr/local/bin/cmux")
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: createThrowingShellPromise((cmdStr) => cmdStr.includes("cmux notify")),
})
@@ -180,7 +181,7 @@ describe("session-notification-sender", () => {
spyOn(utils, "getCmuxPath").mockResolvedValue("/usr/local/bin/cmux")
const trackingCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: createThrowingShellPromise((cmdStr) => cmdStr.includes("cmux notify") || cmdStr.includes("terminal-notifier")),
})
@@ -200,7 +201,7 @@ describe("session-notification-sender", () => {
test("#then should skip cmux when not available and use terminal-notifier", async () => {
const calls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: createShellPromise((cmdStr) => { calls.push(cmdStr) }),
})
@@ -213,7 +214,7 @@ describe("session-notification-sender", () => {
test("#then should call .quiet() on linux notify-send", async () => {
const quietCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: (cmd: TemplateStringsArray, ...values: unknown[]) => {
const cmdStr = cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
const result = { stdout: Buffer.from(""), stderr: Buffer.from(""), exitCode: 0 }
@@ -246,7 +247,7 @@ describe("session-notification-sender", () => {
test("#then should call .quiet() on win32 powershell", async () => {
const quietCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: (cmd: TemplateStringsArray, ...values: unknown[]) => {
const cmdStr = cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
const result = { stdout: Buffer.from(""), stderr: Buffer.from(""), exitCode: 0 }
@@ -283,7 +284,7 @@ describe("session-notification-sender", () => {
describe("#when calling ctx.$ for sound playback", () => {
test("#then should call .quiet() on darwin afplay", async () => {
const quietCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: (cmd: TemplateStringsArray, ...values: unknown[]) => {
const cmdStr = cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
const result = { stdout: Buffer.from(""), stderr: Buffer.from(""), exitCode: 0 }
@@ -316,7 +317,7 @@ describe("session-notification-sender", () => {
test("#then should call .quiet() on linux paplay", async () => {
const quietCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: (cmd: TemplateStringsArray, ...values: unknown[]) => {
const cmdStr = cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
const result = { stdout: Buffer.from(""), stderr: Buffer.from(""), exitCode: 0 }
@@ -351,7 +352,7 @@ describe("session-notification-sender", () => {
spyOn(utils, "getPaplayPath").mockResolvedValue(null)
const quietCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: (cmd: TemplateStringsArray, ...values: unknown[]) => {
const cmdStr = cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
const result = { stdout: Buffer.from(""), stderr: Buffer.from(""), exitCode: 0 }
@@ -384,7 +385,7 @@ describe("session-notification-sender", () => {
test("#then should call .quiet() on win32 powershell sound", async () => {
const quietCalls: string[] = []
const mockCtx = testCoerce<PluginInput>({
const mockCtx = unsafeTestValue<PluginInput>({
$: (cmd: TemplateStringsArray, ...values: unknown[]) => {
const cmdStr = cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
const result = { stdout: Buffer.from(""), stderr: Buffer.from(""), exitCode: 0 }