mirror of
https://mirror.skon.top/github.com/code-yeongyu/oh-my-opencode
synced 2026-04-20 15:40:12 +08:00
fix(ci): isolate discord reply listener test
This commit is contained in:
@@ -8,6 +8,7 @@ type CiTestPlan = {
|
||||
|
||||
const TEST_ROOTS = ["bin", "script", "src"] as const
|
||||
const MODULE_MOCK_PATTERN = "mock.module("
|
||||
const ALWAYS_ISOLATED_TEST_FILES = ["src/openclaw/__tests__/reply-listener-discord.test.ts"] as const
|
||||
|
||||
async function collectTestFiles(rootDirectory: string): Promise<string[]> {
|
||||
const testFiles: string[] = []
|
||||
@@ -29,13 +30,7 @@ async function usesModuleMock(rootDirectory: string, testFile: string): Promise<
|
||||
}
|
||||
|
||||
function toIsolatedTarget(testFile: string): string {
|
||||
const pathSegments = testFile.split("/")
|
||||
|
||||
if (pathSegments.length <= 3) {
|
||||
return testFile
|
||||
}
|
||||
|
||||
return pathSegments.slice(0, -1).join("/")
|
||||
return testFile
|
||||
}
|
||||
|
||||
function isCoveredByTarget(testFile: string, isolatedTarget: string): boolean {
|
||||
@@ -60,8 +55,11 @@ export async function createCiTestPlan(rootDirectory: string = process.cwd()): P
|
||||
}
|
||||
}
|
||||
|
||||
const isolatedTestFiles = Array.from(
|
||||
new Set([...isolatedModuleMockFiles, ...ALWAYS_ISOLATED_TEST_FILES.filter((testFile) => allTestFiles.includes(testFile))]),
|
||||
)
|
||||
const isolatedTestTargets = collapseNestedTargets(
|
||||
Array.from(new Set(isolatedModuleMockFiles.map((testFile) => toIsolatedTarget(testFile)))).sort((left, right) =>
|
||||
isolatedTestFiles.map((testFile) => toIsolatedTarget(testFile)).sort((left, right) =>
|
||||
left.localeCompare(right),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { OpenClawConfig } from "../types"
|
||||
|
||||
const originalHome = process.env.HOME
|
||||
const originalUserProfile = process.env.USERPROFILE
|
||||
const originalFetch = globalThis.fetch
|
||||
|
||||
const tempHome = mkdtempSync(join(tmpdir(), "openclaw-reply-listener-discord-"))
|
||||
const stateDir = join(tempHome, ".omx", "state")
|
||||
@@ -60,12 +61,14 @@ describe("pollDiscordReplies", () => {
|
||||
beforeEach(() => {
|
||||
process.env.HOME = tempHome
|
||||
process.env.USERPROFILE = tempHome
|
||||
globalThis.fetch = originalFetch
|
||||
rmSync(stateDir, { recursive: true, force: true })
|
||||
mkdirSync(stateDir, { recursive: true })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
mock.restore()
|
||||
globalThis.fetch = originalFetch
|
||||
})
|
||||
|
||||
test("records HTTP failures in daemon state when Discord returns non-ok", async () => {
|
||||
|
||||
Reference in New Issue
Block a user