mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
fix(config): leave environment WABT directory admission to the WASM lane
A relative REA_WABT_BIN_DIRECTORY in the environment made the whole REA configuration invalid, disabling unrelated tools, instead of returning the WASM provider's directory_not_absolute diagnostic. Validate the saved value in the user configuration owner beside REA_JADX_MCP_JAR, which follows the same rule. Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
1 parent
30bac88e18
commit
75b8a9f9eb
3 files changed
+35
-13
No files matched your search
@@ -112,11 +112,6 @@ const environmentSchema = z.object({
|
||||
.min(1)
|
||||
.refine(isAbsolute, "REA_ILSPY_CMD_PATH must be absolute")
|
||||
.optional(),
|
||||
REA_WABT_BIN_DIRECTORY: z
|
||||
.string()
|
||||
.min(1)
|
||||
.refine(isAbsolute, "REA_WABT_BIN_DIRECTORY must be absolute")
|
||||
.optional(),
|
||||
HOPPER_LAUNCHER_PATH: z.string().min(1).optional(),
|
||||
HOPPER_TARGET_PATH: z.string().min(1).optional(),
|
||||
HOPPER_TARGET_KIND: z.enum(["executable", "database"]).default("executable"),
|
||||
|
||||
@@ -27,6 +27,16 @@ export const PERSISTED_SETTINGS = [
|
||||
] as const;
|
||||
|
||||
export type PersistedSetting = (typeof PERSISTED_SETTINGS)[number];
|
||||
|
||||
/**
|
||||
* Absolute paths whose environment value the owning provider admits, so a
|
||||
* relative value there fails only that provider's lane. A saved value is
|
||||
* still refused before it is written.
|
||||
*/
|
||||
const PROVIDER_OWNED_ABSOLUTE_SETTINGS = [
|
||||
"REA_JADX_MCP_JAR",
|
||||
"REA_WABT_BIN_DIRECTORY",
|
||||
] as const satisfies readonly PersistedSetting[];
|
||||
export type UserSettings = Partial<Record<PersistedSetting, string>>;
|
||||
|
||||
type RawUserConfig = Partial<Record<PersistedSetting, unknown>>;
|
||||
@@ -79,13 +89,17 @@ export const parseUserConfig = (
|
||||
}
|
||||
const native = parseEnvironmentValues(parsed);
|
||||
if (!native.ok) return native;
|
||||
const jadx = parsed.REA_JADX_MCP_JAR;
|
||||
if (jadx !== undefined && !isAbsolute(jadx))
|
||||
const relative = PROVIDER_OWNED_ABSOLUTE_SETTINGS.filter((setting) => {
|
||||
const value = parsed[setting];
|
||||
return value !== undefined && !isAbsolute(value);
|
||||
});
|
||||
if (relative.length > 0)
|
||||
return err(
|
||||
new ConfigurationError("Invalid REA user configuration", {
|
||||
settings: [
|
||||
{ setting: "REA_JADX_MCP_JAR", constraint: "must be absolute" },
|
||||
],
|
||||
settings: relative.map((setting) => ({
|
||||
setting,
|
||||
constraint: "must be absolute",
|
||||
})),
|
||||
}),
|
||||
);
|
||||
return ok(parsed);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { join, posix, win32 } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { parseConfig } from "../../src/config/parseConfig.js";
|
||||
import {
|
||||
applyUserConfigurationDefaults,
|
||||
parseUserConfig,
|
||||
@@ -84,9 +85,21 @@ describe("parseUserConfig", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a relative REA_WABT_BIN_DIRECTORY the same way the environment schema does", () => {
|
||||
const parsed = parseUserConfig({ REA_WABT_BIN_DIRECTORY: "wabt/bin" });
|
||||
expect(parsed.ok).toBe(false);
|
||||
it("refuses to save a relative REA_WABT_BIN_DIRECTORY that the WASM lane leaves to its own admission", () => {
|
||||
expect(parseUserConfig({ REA_WABT_BIN_DIRECTORY: "wabt/bin" })).toEqual({
|
||||
ok: false,
|
||||
error: expect.objectContaining({
|
||||
settings: [
|
||||
{
|
||||
setting: "REA_WABT_BIN_DIRECTORY",
|
||||
constraint: "must be absolute",
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
// The environment value stays with the WASM provider, whose
|
||||
// directory_not_absolute diagnostic does not disable unrelated tools.
|
||||
expect(parseConfig({ REA_WABT_BIN_DIRECTORY: "wabt/bin" }).ok).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects non-string values", () => {
|
||||
|
||||
Reference in new issue
Block a user