fix(codex): harden windows light install
This commit is contained in:
@@ -30,6 +30,7 @@ export async function updateCodexConfig({
|
||||
marketplaceName,
|
||||
marketplaceSource = defaultMarketplaceSource(marketplaceName, repoRoot),
|
||||
pluginNames,
|
||||
platform = process.platform,
|
||||
trustedHookStates = [],
|
||||
agentConfigs = [],
|
||||
}) {
|
||||
@@ -53,6 +54,7 @@ export async function updateCodexConfig({
|
||||
for (const pluginName of pluginNames) {
|
||||
config = ensurePluginEnabled(config, `${pluginName}@${marketplaceName}`);
|
||||
}
|
||||
config = ensureOmoGitBashMcpPolicy(config, { marketplaceName, pluginNames, platform });
|
||||
for (const state of trustedHookStates) {
|
||||
config = ensureHookTrusted(config, state.key, state.trustedHash);
|
||||
}
|
||||
@@ -150,6 +152,19 @@ function ensurePluginEnabled(config, pluginKey) {
|
||||
return replaceOrInsertSetting(config, section, "enabled", "true");
|
||||
}
|
||||
|
||||
function ensurePluginMcpEnabled(config, pluginKey, serverName, enabled) {
|
||||
const header = `plugins.${JSON.stringify(pluginKey)}.mcp_servers.${serverName}`;
|
||||
const section = findTomlSection(config, header);
|
||||
const enabledValue = enabled ? "true" : "false";
|
||||
if (!section) return appendBlock(config, `[${header}]\nenabled = ${enabledValue}\n`);
|
||||
return replaceOrInsertSetting(config, section, "enabled", enabledValue);
|
||||
}
|
||||
|
||||
function ensureOmoGitBashMcpPolicy(config, { marketplaceName, pluginNames, platform }) {
|
||||
if (marketplaceName !== "sisyphuslabs" || !pluginNames.includes("omo")) return config;
|
||||
return ensurePluginMcpEnabled(config, "omo@sisyphuslabs", "git_bash", platform === "win32");
|
||||
}
|
||||
|
||||
function ensureHookTrusted(config, key, trustedHash) {
|
||||
const header = `hooks.state.${JSON.stringify(key)}`;
|
||||
const section = findTomlSection(config, header);
|
||||
@@ -237,7 +252,8 @@ function parseJsonString(value) {
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
return typeof parsed === "string" ? parsed : null;
|
||||
} catch {
|
||||
} catch (error) {
|
||||
if (error instanceof Error) return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,3 +128,46 @@ test("#given non-Windows platform #when preparing #then winget is never called",
|
||||
assert.deepEqual(runCalls, []);
|
||||
assert.deepEqual(result, { found: true, path: null, source: "not-required" });
|
||||
});
|
||||
|
||||
test("#given Windows without Git Bash and winget fails #when preparing #then original install hint is preserved", async () => {
|
||||
const missingResolution = {
|
||||
found: false,
|
||||
checkedPaths: [programFilesGitBash, programFilesX86GitBash],
|
||||
installHint: "install hint",
|
||||
};
|
||||
|
||||
const result = await prepareGitBashForInstall({
|
||||
platform: "win32",
|
||||
env: {},
|
||||
cwd: "C:\\repo",
|
||||
resolveGitBash: () => missingResolution,
|
||||
runCommand: async () => {
|
||||
throw new Error("winget unavailable");
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(result, missingResolution);
|
||||
});
|
||||
|
||||
test("#given Windows without Git Bash and winget succeeds but bash is still missing #when preparing #then install hint remains", async () => {
|
||||
const missingResolution = {
|
||||
found: false,
|
||||
checkedPaths: [programFilesGitBash, programFilesX86GitBash],
|
||||
installHint: "install hint",
|
||||
};
|
||||
let resolveCallCount = 0;
|
||||
|
||||
const result = await prepareGitBashForInstall({
|
||||
platform: "win32",
|
||||
env: {},
|
||||
cwd: "C:\\repo",
|
||||
resolveGitBash: () => {
|
||||
resolveCallCount += 1;
|
||||
return missingResolution;
|
||||
},
|
||||
runCommand: async () => {},
|
||||
});
|
||||
|
||||
assert.equal(resolveCallCount, 2);
|
||||
assert.deepEqual(result, missingResolution);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user