test(cli): batch 82 (10 files)
This commit is contained in:
@@ -9,12 +9,17 @@ function createMockSpinner(): ReturnType<typeof p.spinner> {
|
||||
start: () => undefined,
|
||||
stop: () => undefined,
|
||||
message: () => undefined,
|
||||
cancel: () => undefined,
|
||||
error: () => undefined,
|
||||
clear: () => undefined,
|
||||
isCancelled: false,
|
||||
}
|
||||
}
|
||||
|
||||
describe("runTuiInstaller", () => {
|
||||
const originalIsStdinTty = process.stdin.isTTY
|
||||
const originalIsStdoutTty = process.stdout.isTTY
|
||||
const originalPublishLazycodex = process.env.OMO_PUBLISH_LAZYCODEX
|
||||
|
||||
beforeEach(() => {
|
||||
Object.defineProperty(process.stdin, "isTTY", { configurable: true, value: true })
|
||||
@@ -24,6 +29,11 @@ describe("runTuiInstaller", () => {
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process.stdin, "isTTY", { configurable: true, value: originalIsStdinTty })
|
||||
Object.defineProperty(process.stdout, "isTTY", { configurable: true, value: originalIsStdoutTty })
|
||||
if (originalPublishLazycodex === undefined) {
|
||||
delete process.env.OMO_PUBLISH_LAZYCODEX
|
||||
} else {
|
||||
process.env.OMO_PUBLISH_LAZYCODEX = originalPublishLazycodex
|
||||
}
|
||||
})
|
||||
|
||||
it("blocks installation when OpenCode is below the minimum version", async () => {
|
||||
@@ -32,6 +42,7 @@ describe("runTuiInstaller", () => {
|
||||
spyOn(p, "spinner").mockReturnValue(createMockSpinner()),
|
||||
spyOn(p, "intro").mockImplementation(() => undefined),
|
||||
spyOn(p.log, "warn").mockImplementation(() => undefined),
|
||||
spyOn(tuiInstallPrompts, "promptInstallPlatform").mockResolvedValue("opencode"),
|
||||
spyOn(configManager, "detectCurrentConfig").mockReturnValue({
|
||||
isInstalled: false,
|
||||
installedVersion: null,
|
||||
@@ -40,11 +51,13 @@ describe("runTuiInstaller", () => {
|
||||
hasOpenAI: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: false,
|
||||
hasCodex: false,
|
||||
hasOpencodeZen: false,
|
||||
hasZaiCodingPlan: false,
|
||||
hasKimiForCoding: false,
|
||||
hasOpencodeGo: false,
|
||||
hasVercelAiGateway: false,
|
||||
codexAutonomous: false,
|
||||
}),
|
||||
spyOn(configManager, "isOpenCodeInstalled").mockResolvedValue(true),
|
||||
spyOn(configManager, "getOpenCodeVersion").mockResolvedValue("1.3.9"),
|
||||
@@ -70,6 +83,29 @@ describe("runTuiInstaller", () => {
|
||||
outroSpy.mockRestore()
|
||||
})
|
||||
|
||||
it("blocks codex platform when lazycodex publishing is disabled", async () => {
|
||||
// given
|
||||
delete process.env.OMO_PUBLISH_LAZYCODEX
|
||||
const platformSpy = spyOn(tuiInstallPrompts, "promptInstallPlatform").mockResolvedValue("codex")
|
||||
const promptConfigSpy = spyOn(tuiInstallPrompts, "promptInstallConfig")
|
||||
const logErrorSpy = spyOn(p.log, "error").mockImplementation(() => undefined)
|
||||
const outroSpy = spyOn(p, "outro").mockImplementation(() => undefined)
|
||||
|
||||
// when
|
||||
const result = await runTuiInstaller({ tui: true, platform: "codex" }, "3.16.0")
|
||||
|
||||
// then
|
||||
expect(result).toBe(1)
|
||||
expect(platformSpy).toHaveBeenCalled()
|
||||
expect(promptConfigSpy).not.toHaveBeenCalled()
|
||||
expect(logErrorSpy).toHaveBeenCalled()
|
||||
|
||||
platformSpy.mockRestore()
|
||||
promptConfigSpy.mockRestore()
|
||||
logErrorSpy.mockRestore()
|
||||
outroSpy.mockRestore()
|
||||
})
|
||||
|
||||
it("proceeds when OpenCode meets the minimum version", async () => {
|
||||
// given
|
||||
const restoreSpies = [
|
||||
@@ -81,6 +117,7 @@ describe("runTuiInstaller", () => {
|
||||
spyOn(p.log, "message").mockImplementation(() => undefined),
|
||||
spyOn(p, "note").mockImplementation(() => undefined),
|
||||
spyOn(p, "outro").mockImplementation(() => undefined),
|
||||
spyOn(tuiInstallPrompts, "promptInstallPlatform").mockResolvedValue("opencode"),
|
||||
spyOn(configManager, "detectCurrentConfig").mockReturnValue({
|
||||
isInstalled: false,
|
||||
installedVersion: null,
|
||||
@@ -89,25 +126,31 @@ describe("runTuiInstaller", () => {
|
||||
hasOpenAI: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: false,
|
||||
hasCodex: false,
|
||||
hasOpencodeZen: false,
|
||||
hasZaiCodingPlan: false,
|
||||
hasKimiForCoding: false,
|
||||
hasOpencodeGo: false,
|
||||
hasVercelAiGateway: false,
|
||||
codexAutonomous: false,
|
||||
}),
|
||||
spyOn(configManager, "isOpenCodeInstalled").mockResolvedValue(true),
|
||||
spyOn(configManager, "getOpenCodeVersion").mockResolvedValue("1.4.0"),
|
||||
spyOn(tuiInstallPrompts, "promptInstallConfig").mockResolvedValue({
|
||||
platform: "opencode",
|
||||
hasOpenCode: true,
|
||||
hasClaude: false,
|
||||
isMax20: false,
|
||||
hasOpenAI: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: false,
|
||||
hasCodex: false,
|
||||
hasOpencodeZen: false,
|
||||
hasZaiCodingPlan: false,
|
||||
hasKimiForCoding: false,
|
||||
hasOpencodeGo: false,
|
||||
hasVercelAiGateway: false,
|
||||
codexAutonomous: false,
|
||||
}),
|
||||
spyOn(configManager, "addPluginToOpenCodeConfig").mockResolvedValue({
|
||||
success: true,
|
||||
@@ -129,4 +172,60 @@ describe("runTuiInstaller", () => {
|
||||
spy.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it("skips OpenCode checks and writes when platform is codex", async () => {
|
||||
// given
|
||||
process.env.OMO_PUBLISH_LAZYCODEX = "true"
|
||||
const restoreSpies = [
|
||||
spyOn(p, "spinner").mockReturnValue(createMockSpinner()),
|
||||
spyOn(p, "intro").mockImplementation(() => undefined),
|
||||
spyOn(p.log, "info").mockImplementation(() => undefined),
|
||||
spyOn(p.log, "warn").mockImplementation(() => undefined),
|
||||
spyOn(p.log, "success").mockImplementation(() => undefined),
|
||||
spyOn(p.log, "message").mockImplementation(() => undefined),
|
||||
spyOn(p, "note").mockImplementation(() => undefined),
|
||||
spyOn(p, "outro").mockImplementation(() => undefined),
|
||||
spyOn(tuiInstallPrompts, "promptInstallPlatform").mockResolvedValue("codex"),
|
||||
spyOn(tuiInstallPrompts, "promptInstallConfig").mockResolvedValue({
|
||||
platform: "codex",
|
||||
hasOpenCode: false,
|
||||
hasClaude: false,
|
||||
isMax20: false,
|
||||
hasOpenAI: false,
|
||||
hasGemini: false,
|
||||
hasCopilot: false,
|
||||
hasCodex: false,
|
||||
hasOpencodeZen: false,
|
||||
hasZaiCodingPlan: false,
|
||||
hasKimiForCoding: false,
|
||||
hasOpencodeGo: false,
|
||||
hasVercelAiGateway: false,
|
||||
}),
|
||||
]
|
||||
const detectConfigSpy = spyOn(configManager, "detectCurrentConfig")
|
||||
const isInstalledSpy = spyOn(configManager, "isOpenCodeInstalled")
|
||||
const getVersionSpy = spyOn(configManager, "getOpenCodeVersion")
|
||||
const addPluginSpy = spyOn(configManager, "addPluginToOpenCodeConfig")
|
||||
const writeConfigSpy = spyOn(configManager, "writeOmoConfig")
|
||||
|
||||
// when
|
||||
const result = await runTuiInstaller({ tui: true, platform: "codex" }, "3.16.0")
|
||||
|
||||
// then
|
||||
expect(result).toBe(0)
|
||||
expect(detectConfigSpy).not.toHaveBeenCalled()
|
||||
expect(isInstalledSpy).not.toHaveBeenCalled()
|
||||
expect(getVersionSpy).not.toHaveBeenCalled()
|
||||
expect(addPluginSpy).not.toHaveBeenCalled()
|
||||
expect(writeConfigSpy).not.toHaveBeenCalled()
|
||||
|
||||
for (const spy of restoreSpies) {
|
||||
spy.mockRestore()
|
||||
}
|
||||
detectConfigSpy.mockRestore()
|
||||
isInstalledSpy.mockRestore()
|
||||
getVersionSpy.mockRestore()
|
||||
addPluginSpy.mockRestore()
|
||||
writeConfigSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user