fix(auto-update): handle null JSON.parse and restore mocks on test failure
This commit is contained in:
@@ -241,25 +241,27 @@ describe("syncCachePackageJsonToIntent", () => {
|
|||||||
renameSync: fs.renameSync,
|
renameSync: fs.renameSync,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const { syncCachePackageJsonToIntent } = await import("./sync-package-json")
|
try {
|
||||||
|
const { syncCachePackageJsonToIntent } = await import("./sync-package-json")
|
||||||
|
|
||||||
const pluginInfo: PluginEntryInfo = {
|
const pluginInfo: PluginEntryInfo = {
|
||||||
entry: "oh-my-opencode@latest",
|
entry: "oh-my-opencode@latest",
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
pinnedVersion: "latest",
|
pinnedVersion: "latest",
|
||||||
configPath: "/tmp/opencode.json",
|
configPath: "/tmp/opencode.json",
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = syncCachePackageJsonToIntent(pluginInfo)
|
||||||
|
|
||||||
|
expect(result.synced).toBe(false)
|
||||||
|
expect(result.error).toBe("write_error")
|
||||||
|
} finally {
|
||||||
|
mock.module("node:fs", () => ({
|
||||||
|
...fs,
|
||||||
|
writeFileSync: originalWriteFileSync,
|
||||||
|
renameSync: originalRenameSync,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = syncCachePackageJsonToIntent(pluginInfo)
|
|
||||||
|
|
||||||
expect(result.synced).toBe(false)
|
|
||||||
expect(result.error).toBe("write_error")
|
|
||||||
|
|
||||||
mock.module("node:fs", () => ({
|
|
||||||
...fs,
|
|
||||||
writeFileSync: originalWriteFileSync,
|
|
||||||
renameSync: originalRenameSync,
|
|
||||||
}))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -289,27 +291,29 @@ describe("syncCachePackageJsonToIntent", () => {
|
|||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const { syncCachePackageJsonToIntent } = await import("./sync-package-json")
|
try {
|
||||||
|
const { syncCachePackageJsonToIntent } = await import("./sync-package-json")
|
||||||
|
|
||||||
const pluginInfo: PluginEntryInfo = {
|
const pluginInfo: PluginEntryInfo = {
|
||||||
entry: "oh-my-opencode@latest",
|
entry: "oh-my-opencode@latest",
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
pinnedVersion: "latest",
|
pinnedVersion: "latest",
|
||||||
configPath: "/tmp/opencode.json",
|
configPath: "/tmp/opencode.json",
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = syncCachePackageJsonToIntent(pluginInfo)
|
||||||
|
|
||||||
|
expect(result.synced).toBe(false)
|
||||||
|
expect(result.error).toBe("write_error")
|
||||||
|
expect(tempFilePath).not.toBeNull()
|
||||||
|
expect(existsSync(tempFilePath!)).toBe(false)
|
||||||
|
} finally {
|
||||||
|
mock.module("node:fs", () => ({
|
||||||
|
...fs,
|
||||||
|
writeFileSync: originalWriteFileSync,
|
||||||
|
renameSync: originalRenameSync,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = syncCachePackageJsonToIntent(pluginInfo)
|
|
||||||
|
|
||||||
expect(result.synced).toBe(false)
|
|
||||||
expect(result.error).toBe("write_error")
|
|
||||||
expect(tempFilePath).not.toBeNull()
|
|
||||||
expect(existsSync(tempFilePath!)).toBe(false)
|
|
||||||
|
|
||||||
mock.module("node:fs", () => ({
|
|
||||||
...fs,
|
|
||||||
writeFileSync: originalWriteFileSync,
|
|
||||||
renameSync: originalRenameSync,
|
|
||||||
}))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export function syncCachePackageJsonToIntent(pluginInfo: PluginEntryInfo): SyncR
|
|||||||
return { synced: false, error: "parse_error", message: "Failed to parse cache package.json (malformed JSON)" }
|
return { synced: false, error: "parse_error", message: "Failed to parse cache package.json (malformed JSON)" }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pkgJson.dependencies?.[PACKAGE_NAME]) {
|
if (!pkgJson || !pkgJson.dependencies?.[PACKAGE_NAME]) {
|
||||||
log("[auto-update-checker] Plugin not in cache package.json dependencies, nothing to sync")
|
log("[auto-update-checker] Plugin not in cache package.json dependencies, nothing to sync")
|
||||||
return { synced: false, error: "plugin_not_in_deps", message: "Plugin not in cache package.json dependencies" }
|
return { synced: false, error: "plugin_not_in_deps", message: "Plugin not in cache package.json dependencies" }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user