mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 02:20:38 +09:00
Merge pull request #3386 from paperclipai/pap-1347-dev-runner-worktree-env
fix: isolate dev runner worktree env
This commit is contained in:
commit
a692e37f3e
4 changed files with 173 additions and 0 deletions
75
server/src/__tests__/dev-runner-worktree.test.ts
Normal file
75
server/src/__tests__/dev-runner-worktree.test.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
bootstrapDevRunnerWorktreeEnv,
|
||||
isLinkedGitWorktreeCheckout,
|
||||
resolveWorktreeEnvFilePath,
|
||||
} from "../dev-runner-worktree.ts";
|
||||
|
||||
const tempRoots = new Set<string>();
|
||||
|
||||
afterEach(() => {
|
||||
for (const root of tempRoots) {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
tempRoots.clear();
|
||||
});
|
||||
|
||||
function createTempRoot(prefix: string): string {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
||||
tempRoots.add(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
describe("dev-runner worktree env bootstrap", () => {
|
||||
it("detects linked git worktrees from .git files", () => {
|
||||
const root = createTempRoot("paperclip-dev-runner-worktree-");
|
||||
fs.writeFileSync(path.join(root, ".git"), "gitdir: /tmp/paperclip/.git/worktrees/feature\n", "utf8");
|
||||
|
||||
expect(isLinkedGitWorktreeCheckout(root)).toBe(true);
|
||||
});
|
||||
|
||||
it("loads repo-local Paperclip env for initialized worktrees without overriding explicit env", () => {
|
||||
const root = createTempRoot("paperclip-dev-runner-worktree-env-");
|
||||
fs.mkdirSync(path.join(root, ".paperclip"), { recursive: true });
|
||||
fs.writeFileSync(path.join(root, ".git"), "gitdir: /tmp/paperclip/.git/worktrees/feature\n", "utf8");
|
||||
fs.writeFileSync(
|
||||
resolveWorktreeEnvFilePath(root),
|
||||
[
|
||||
"PAPERCLIP_HOME=/tmp/paperclip-worktrees",
|
||||
"PAPERCLIP_INSTANCE_ID=feature-worktree",
|
||||
"PAPERCLIP_IN_WORKTREE=true",
|
||||
"PAPERCLIP_WORKTREE_NAME=feature-worktree",
|
||||
"PAPERCLIP_OPTIONAL= # comment-only value",
|
||||
"",
|
||||
].join("\n"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const env: NodeJS.ProcessEnv = {
|
||||
PAPERCLIP_INSTANCE_ID: "already-set",
|
||||
};
|
||||
const result = bootstrapDevRunnerWorktreeEnv(root, env);
|
||||
|
||||
expect(result).toEqual({
|
||||
envPath: resolveWorktreeEnvFilePath(root),
|
||||
missingEnv: false,
|
||||
});
|
||||
expect(env.PAPERCLIP_HOME).toBe("/tmp/paperclip-worktrees");
|
||||
expect(env.PAPERCLIP_INSTANCE_ID).toBe("already-set");
|
||||
expect(env.PAPERCLIP_IN_WORKTREE).toBe("true");
|
||||
expect(env.PAPERCLIP_OPTIONAL).toBe("");
|
||||
});
|
||||
|
||||
it("reports uninitialized linked worktrees so dev runner can fail fast", () => {
|
||||
const root = createTempRoot("paperclip-dev-runner-worktree-missing-");
|
||||
fs.writeFileSync(path.join(root, ".git"), "gitdir: /tmp/paperclip/.git/worktrees/feature\n", "utf8");
|
||||
|
||||
expect(bootstrapDevRunnerWorktreeEnv(root, {})).toEqual({
|
||||
envPath: resolveWorktreeEnvFilePath(root),
|
||||
missingEnv: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue