test(ci): remove suite-order mock coupling
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { execFileSync } from "node:child_process"
|
||||
import { readFileSync } from "node:fs"
|
||||
import * as childProcess from "node:child_process"
|
||||
import * as fs from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { parseGitStatusPorcelain } from "./parse-status-porcelain"
|
||||
import { parseGitDiffNumstat } from "./parse-diff-numstat"
|
||||
@@ -7,21 +7,21 @@ import type { GitFileStat } from "./types"
|
||||
|
||||
export function collectGitDiffStats(directory: string): GitFileStat[] {
|
||||
try {
|
||||
const diffOutput = execFileSync("git", ["diff", "--numstat", "HEAD"], {
|
||||
const diffOutput = childProcess.execFileSync("git", ["diff", "--numstat", "HEAD"], {
|
||||
cwd: directory,
|
||||
encoding: "utf-8",
|
||||
timeout: 5000,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
}).trimEnd()
|
||||
|
||||
const statusOutput = execFileSync("git", ["status", "--porcelain"], {
|
||||
const statusOutput = childProcess.execFileSync("git", ["status", "--porcelain"], {
|
||||
cwd: directory,
|
||||
encoding: "utf-8",
|
||||
timeout: 5000,
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
}).trimEnd()
|
||||
|
||||
const untrackedOutput = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
|
||||
const untrackedOutput = childProcess.execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
|
||||
cwd: directory,
|
||||
encoding: "utf-8",
|
||||
timeout: 5000,
|
||||
@@ -34,7 +34,7 @@ export function collectGitDiffStats(directory: string): GitFileStat[] {
|
||||
.filter(Boolean)
|
||||
.map((filePath) => {
|
||||
try {
|
||||
const content = readFileSync(join(directory, filePath), "utf-8")
|
||||
const content = fs.readFileSync(join(directory, filePath), "utf-8")
|
||||
const lineCount = content.split("\n").length - (content.endsWith("\n") ? 1 : 0)
|
||||
return `${lineCount}\t0\t${filePath}`
|
||||
} catch {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { closeSync, existsSync, fsyncSync, openSync, readFileSync, renameSync, writeFileSync } from "node:fs"
|
||||
import * as fs from "node:fs"
|
||||
|
||||
import { applyEdits, modify } from "jsonc-parser"
|
||||
|
||||
@@ -36,10 +36,10 @@ function updateJsoncPluginArray(content: string, pluginEntries: string[]): strin
|
||||
}
|
||||
|
||||
export function migrateLegacyPluginEntry(configPath: string): boolean {
|
||||
if (!existsSync(configPath)) return false
|
||||
if (!fs.existsSync(configPath)) return false
|
||||
|
||||
try {
|
||||
const content = readFileSync(configPath, "utf-8")
|
||||
const content = fs.readFileSync(configPath, "utf-8")
|
||||
if (!content.includes(LEGACY_PLUGIN_NAME)) return false
|
||||
|
||||
const parseResult = parseJsoncSafe<OpenCodeConfig>(content)
|
||||
@@ -53,15 +53,15 @@ export function migrateLegacyPluginEntry(configPath: string): boolean {
|
||||
if (!updated || updated === content) return false
|
||||
|
||||
const tempPath = `${configPath}.tmp`
|
||||
writeFileSync(tempPath, updated, "utf-8")
|
||||
const tempFileDescriptor = openSync(tempPath, "r+")
|
||||
fs.writeFileSync(tempPath, updated, "utf-8")
|
||||
const tempFileDescriptor = fs.openSync(tempPath, "r+")
|
||||
try {
|
||||
fsyncSync(tempFileDescriptor)
|
||||
fs.fsyncSync(tempFileDescriptor)
|
||||
} finally {
|
||||
closeSync(tempFileDescriptor)
|
||||
fs.closeSync(tempFileDescriptor)
|
||||
}
|
||||
|
||||
renameSync(tempPath, configPath)
|
||||
fs.renameSync(tempPath, configPath)
|
||||
log("[migrateLegacyPluginEntry] Auto-migrated opencode.json plugin entry", {
|
||||
configPath,
|
||||
from: LEGACY_PLUGIN_NAME,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path="../../../bun-test.d.ts" />
|
||||
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"
|
||||
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
@@ -68,14 +68,9 @@ describe("migrateLegacyPluginEntry", () => {
|
||||
writeFileSync(configPath, originalContent)
|
||||
|
||||
const fs = await import("node:fs")
|
||||
const originalRenameSync = fs.renameSync
|
||||
|
||||
mock.module("node:fs", () => ({
|
||||
...fs,
|
||||
renameSync: () => {
|
||||
throw new Error("simulated rename failure")
|
||||
},
|
||||
}))
|
||||
const renameSyncSpy = spyOn(fs, "renameSync").mockImplementation(() => {
|
||||
throw new Error("simulated rename failure")
|
||||
})
|
||||
|
||||
try {
|
||||
const { migrateLegacyPluginEntry } = await importFreshMigrationModule()
|
||||
@@ -87,10 +82,7 @@ describe("migrateLegacyPluginEntry", () => {
|
||||
expect(readFileSync(tempPath, "utf-8")).toContain("oh-my-openagent@latest")
|
||||
expect(readFileSync(tempPath, "utf-8")).not.toContain("oh-my-opencode")
|
||||
} finally {
|
||||
mock.module("node:fs", () => ({
|
||||
...fs,
|
||||
renameSync: originalRenameSync,
|
||||
}))
|
||||
renameSyncSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -106,13 +98,13 @@ describe("migrateLegacyPluginEntry", () => {
|
||||
const originalOpenSync = fs.openSync
|
||||
const openSyncCalls: string[] = []
|
||||
|
||||
mock.module("node:fs", () => ({
|
||||
...fs,
|
||||
openSync: (path: Parameters<typeof fs.openSync>[0], flags: Parameters<typeof fs.openSync>[1]) => {
|
||||
const openSyncSpy = spyOn(fs, "openSync").mockImplementation((
|
||||
path: Parameters<typeof fs.openSync>[0],
|
||||
flags: Parameters<typeof fs.openSync>[1],
|
||||
) => {
|
||||
openSyncCalls.push(String(flags))
|
||||
return originalOpenSync(path, flags)
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
try {
|
||||
const { migrateLegacyPluginEntry } = await importFreshMigrationModule()
|
||||
@@ -122,10 +114,7 @@ describe("migrateLegacyPluginEntry", () => {
|
||||
expect(result).toBe(true)
|
||||
expect(openSyncCalls).toContain("r+")
|
||||
} finally {
|
||||
mock.module("node:fs", () => ({
|
||||
...fs,
|
||||
openSync: originalOpenSync,
|
||||
}))
|
||||
openSyncSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user