Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: trust hash covers where the formatter config sits

ogsamrat24eab59b3e50
diff --git a/apps/server/src/editor-format.e2e.test.ts b/apps/server/src/editor-format.e2e.test.ts
index fc948dc8..70b24b36 100644
--- a/apps/server/src/editor-format.e2e.test.ts
+++ b/apps/server/src/editor-format.e2e.test.ts
@@ -149,8 +149,9 @@ describe("format on save: arguments, configuration and the sandbox switch", () =
await writeFile(join(root, "--plugin=..cjs"), "const a=1\n");
const ask = await formatRequest({ root, path: "--plugin=..cjs", text: "const a=1\n", trust: null, hash: null, store, sandboxOn: false });
if (!("trust" in ask) || ask.trust !== "ask") return; // not a Prettier file type here
- await formatRequest({ root, path: "--plugin=..cjs", text: "const a=1\n", trust: "once", hash: ask.hash, store, sandboxOn: false }).catch(() => null);
+ const done = await formatRequest({ root, path: "--plugin=..cjs", text: "const a=1\n", trust: "once", hash: ask.hash, store, sandboxOn: false });
expect(existsSync(join(root, "PWNED"))).toBe(false);
+ expect("text" in done ? done.text : null).toBe("const a = 1;\n");
});
test("a Prettier config added in a subfolder asks again", async () => {
diff --git a/apps/server/src/routes/editor-format.ts b/apps/server/src/routes/editor-format.ts
index 6f22d99a..29e498e2 100644
--- a/apps/server/src/routes/editor-format.ts
+++ b/apps/server/src/routes/editor-format.ts
@@ -172,12 +172,13 @@ export function formatterFor(root: string, file: string, env: NodeJS.ProcessEnv
}
/** The trust hash: what runs and every configuration file's content (a change asks again). */
-export function formatterHash(formatter: Formatter, sandbox = false): string {
+export function formatterHash(formatter: Formatter, sandbox = false, root?: string): string {
const hash = createHash("sha256");
// Where it runs is part of what was allowed: turning the sandbox off asks again.
hash.update(`${formatter.name}\0${formatter.command}\0${formatter.args.slice(0, 1).join(" ")}\0${sandbox ? "box" : "host"}\0`);
for (const file of formatter.configFiles) {
- hash.update(`${basename(file)}\0`);
+ // Where the file sits matters (relative plugin paths resolve from it), not only its name.
+ hash.update(`${root ? relative(root, file) : basename(file)}\0`);
hash.update(readText(file) ?? "\u0000missing");
hash.update("\0");
}
@@ -324,7 +325,7 @@ export async function formatRequest(options: {
const formatter = formatterFor(root, file, env);
if (!formatter) return { formatter: null, text: null };
const sandbox = options.sandboxOn;
- const hash = formatterHash(formatter, sandbox);
+ const hash = formatterHash(formatter, sandbox, root);
const stored = options.store.get(root);
const current = stored && stored.hash === hash ? stored : null;
if (options.trust) {