forked from farhoodlabs/paperclip
fix(dev-runner): tighten worktree env bootstrap
This commit is contained in:
@@ -23,7 +23,7 @@ type BindMode = (typeof BIND_MODES)[number];
|
||||
const worktreeEnvBootstrap = bootstrapDevRunnerWorktreeEnv(repoRoot, process.env);
|
||||
if (worktreeEnvBootstrap.missingEnv) {
|
||||
console.error(
|
||||
`[paperclip] linked git worktree at ${repoRoot} is missing ${path.relative(repoRoot, worktreeEnvBootstrap.envPath ?? "")}. Run \`paperclipai worktree init\` in this worktree before \`pnpm dev\`.`,
|
||||
`[paperclip] linked git worktree at ${repoRoot} is missing ${path.relative(repoRoot, worktreeEnvBootstrap.envPath)}. Run \`paperclipai worktree init\` in this worktree before \`pnpm dev\`.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ describe("dev-runner worktree env bootstrap", () => {
|
||||
"PAPERCLIP_INSTANCE_ID=feature-worktree",
|
||||
"PAPERCLIP_IN_WORKTREE=true",
|
||||
"PAPERCLIP_WORKTREE_NAME=feature-worktree",
|
||||
"PAPERCLIP_OPTIONAL= # comment-only value",
|
||||
"",
|
||||
].join("\n"),
|
||||
"utf8",
|
||||
@@ -59,6 +60,7 @@ describe("dev-runner worktree env bootstrap", () => {
|
||||
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", () => {
|
||||
|
||||
@@ -17,6 +17,10 @@ function parseEnvFile(contents: string): Record<string, string> {
|
||||
entries[key] = "";
|
||||
continue;
|
||||
}
|
||||
if (value.startsWith("#")) {
|
||||
entries[key] = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
(value.startsWith("\"") && value.endsWith("\"")) ||
|
||||
@@ -32,6 +36,11 @@ function parseEnvFile(contents: string): Record<string, string> {
|
||||
return entries;
|
||||
}
|
||||
|
||||
type WorktreeEnvBootstrapResult =
|
||||
| { envPath: null; missingEnv: false }
|
||||
| { envPath: string; missingEnv: true }
|
||||
| { envPath: string; missingEnv: false };
|
||||
|
||||
export function isLinkedGitWorktreeCheckout(rootDir: string): boolean {
|
||||
const gitMetadataPath = path.join(rootDir, ".git");
|
||||
if (!existsSync(gitMetadataPath)) return false;
|
||||
@@ -49,10 +58,7 @@ export function resolveWorktreeEnvFilePath(rootDir: string): string {
|
||||
export function bootstrapDevRunnerWorktreeEnv(
|
||||
rootDir: string,
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): {
|
||||
envPath: string | null;
|
||||
missingEnv: boolean;
|
||||
} {
|
||||
): WorktreeEnvBootstrapResult {
|
||||
if (!isLinkedGitWorktreeCheckout(rootDir)) {
|
||||
return {
|
||||
envPath: null,
|
||||
|
||||
Reference in New Issue
Block a user