Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test(desktop): keep custom prompt launch test independent of real home

Gargantua8abdd4875ee2
diff --git a/apps/desktop/test/custom-system-prompt-launch.test.mjs b/apps/desktop/test/custom-system-prompt-launch.test.mjs
index ff97b6b39..edc4311da 100644
--- a/apps/desktop/test/custom-system-prompt-launch.test.mjs
+++ b/apps/desktop/test/custom-system-prompt-launch.test.mjs
@@ -9,8 +9,10 @@ const { createSessionLaunchRuntime } = await import("../electron/main/runtime/se
// Issue #542: pi CLI's SYSTEM.md / APPEND_SYSTEM.md must be discovered at
// launch with pi's precedence (project .pi/ over ~/.pi/agent/) and reach the
-// sidecar params that compose the system prompt. The home directory is
-// redirected through the import hook below, so a real global file is read.
+// sidecar params that compose the system prompt. The global directory is the
+// developer's real ~/.pi/agent — the assertions are therefore relative to a
+// recorded baseline, never to an empty home, so leftover files on a dev
+// machine do not fail the suite.
const workspace = mkdtempSync(join(tmpdir(), "pi-csp-ws-"));
test.after(() => {
@@ -61,27 +63,27 @@ async function launchParams(runtime) {
// The global (~/.pi/agent) precedence and per-kind independence are covered
// against injectable directories in packages/agent-runtime/src/custom-system-prompt.test.ts;
// this suite covers the real user path through the launch: files on disk in
-// <workspace>/.pi reach sidecarParams, and removing them reverts to default.
+// <workspace>/.pi reach sidecarParams and win per kind, and removing them
+// reverts to whatever the global layer provides.
test("launch discovers project custom system prompt files (issue #542)", async () => {
const runtime = launchRuntime();
- // No files: no custom prompt, prompt stays the composed default.
- assert.equal((await launchParams(runtime)).customSystemPrompt, undefined);
+ // Baseline: no project files yet; may be undefined or the developer's real
+ // global files — both are valid starting points for the assertions below.
+ const baseline = (await launchParams(runtime)).customSystemPrompt;
- // Project .pi/SYSTEM.md replaces the persona.
+ // Project .pi/SYSTEM.md wins the replace kind over any global file.
mkdirSync(join(workspace, ".pi"), { recursive: true });
writeFileSync(join(workspace, ".pi", "SYSTEM.md"), "MARKER-PROJECT-PERSONA");
- assert.deepEqual((await launchParams(runtime)).customSystemPrompt, {
- replace: "MARKER-PROJECT-PERSONA",
- });
+ assert.equal((await launchParams(runtime)).customSystemPrompt?.replace, "MARKER-PROJECT-PERSONA");
- // Project .pi/APPEND_SYSTEM.md is discovered independently.
+ // Project .pi/APPEND_SYSTEM.md wins the append kind independently.
writeFileSync(join(workspace, ".pi", "APPEND_SYSTEM.md"), "MARKER-PROJECT-APPEND");
- assert.deepEqual((await launchParams(runtime)).customSystemPrompt, {
- replace: "MARKER-PROJECT-PERSONA", append: "MARKER-PROJECT-APPEND",
- });
+ const both = (await launchParams(runtime)).customSystemPrompt;
+ assert.equal(both?.replace, "MARKER-PROJECT-PERSONA");
+ assert.equal(both?.append, "MARKER-PROJECT-APPEND");
- // Deleting the files reverts the launch to the default prompt.
+ // Deleting the project files reverts the launch to the global-only state.
rmSync(join(workspace, ".pi"), { recursive: true, force: true });
- assert.equal((await launchParams(runtime)).customSystemPrompt, undefined);
+ assert.deepEqual((await launchParams(runtime)).customSystemPrompt, baseline);
});