From 4150092e9aa31a10065e2e478abe3d4db139d078 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Tue, 12 May 2026 15:30:45 +0900 Subject: [PATCH] test: run suite through isolated mock runner --- package.json | 2 +- script/run-ci-tests.test.ts | 11 +++++++++++ src/index.telemetry.test.ts | 8 ++++++-- src/index.test.ts | 10 ++++++++-- src/index.ts | 4 +++- 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 script/run-ci-tests.test.ts diff --git a/package.json b/package.json index 31c90024e..322dc9024 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "prepublishOnly": "bun run clean && bun run build", "test:model-capabilities": "bun test src/shared/model-capability-aliases.test.ts src/shared/model-capability-guardrails.test.ts src/shared/model-capabilities.test.ts src/cli/doctor/checks/model-resolution.test.ts --bail", "typecheck": "tsc --noEmit", - "test": "bun test bin script src" + "test": "bun run script/run-ci-tests.ts" }, "keywords": [ "opencode", diff --git a/script/run-ci-tests.test.ts b/script/run-ci-tests.test.ts new file mode 100644 index 000000000..22ad433b2 --- /dev/null +++ b/script/run-ci-tests.test.ts @@ -0,0 +1,11 @@ +import { describe, expect, test } from "bun:test" + +describe("test script isolation", () => { + test("#given mock.module tests in the suite #then bun run test uses the isolated CI runner", async () => { + //#given + const packageJson = await Bun.file("package.json").json() + + //#then + expect(packageJson.scripts.test).toBe("bun run script/run-ci-tests.ts") + }) +}) diff --git a/src/index.telemetry.test.ts b/src/index.telemetry.test.ts index e93f8694d..83e0f748a 100644 --- a/src/index.telemetry.test.ts +++ b/src/index.telemetry.test.ts @@ -38,11 +38,15 @@ function installModuleMocks(): void { detectExternalSkillPlugin: mock(() => ({ detected: false, pluginName: null })), getSkillPluginConflictWarning: mock(() => ""), })) - mock.module("./shared", () => ({ - injectServerAuthIntoClient: mockInjectServerAuthIntoClient, + mock.module("./shared/logger", () => ({ log: mock(() => {}), + })) + mock.module("./shared/log-legacy-plugin-startup-warning", () => ({ logLegacyPluginStartupWarning: mockLogLegacyPluginStartupWarning, })) + mock.module("./shared/opencode-server-auth", () => ({ + injectServerAuthIntoClient: mockInjectServerAuthIntoClient, + })) mock.module("./plugin-config", () => ({ loadPluginConfig: mockLoadPluginConfig, })) diff --git a/src/index.test.ts b/src/index.test.ts index 0b8499983..b1f5e2a73 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -52,12 +52,18 @@ function installIndexModuleMocks(): void { getSkillPluginConflictWarning: mockGetSkillPluginConflictWarning, })) - mock.module("./shared", () => ({ - injectServerAuthIntoClient: mockInjectServerAuthIntoClient, + mock.module("./shared/logger", () => ({ log: mock(() => {}), + })) + + mock.module("./shared/log-legacy-plugin-startup-warning", () => ({ logLegacyPluginStartupWarning: mockLogLegacyPluginStartupWarning, })) + mock.module("./shared/opencode-server-auth", () => ({ + injectServerAuthIntoClient: mockInjectServerAuthIntoClient, + })) + mock.module("./plugin-config", () => ({ loadPluginConfig: mockLoadPluginConfig, })) diff --git a/src/index.ts b/src/index.ts index 808141b32..7d229a134 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,9 @@ import { import { loadPluginConfig } from "./plugin-config" import { createModelCacheState } from "./plugin-state" import { createFirstMessageVariantGate } from "./shared/first-message-variant" -import { injectServerAuthIntoClient, log, logLegacyPluginStartupWarning } from "./shared" +import { log } from "./shared/logger" +import { logLegacyPluginStartupWarning } from "./shared/log-legacy-plugin-startup-warning" +import { injectServerAuthIntoClient } from "./shared/opencode-server-auth" import { installAgentSortShim, setAgentSortOrder } from "./shared/agent-sort-shim" import { detectExternalSkillPlugin, getSkillPluginConflictWarning } from "./shared/external-plugin-detector" import { startBackgroundCheck as startTmuxCheck } from "./tools/interactive-bash"