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);
|
const worktreeEnvBootstrap = bootstrapDevRunnerWorktreeEnv(repoRoot, process.env);
|
||||||
if (worktreeEnvBootstrap.missingEnv) {
|
if (worktreeEnvBootstrap.missingEnv) {
|
||||||
console.error(
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ describe("dev-runner worktree env bootstrap", () => {
|
|||||||
"PAPERCLIP_INSTANCE_ID=feature-worktree",
|
"PAPERCLIP_INSTANCE_ID=feature-worktree",
|
||||||
"PAPERCLIP_IN_WORKTREE=true",
|
"PAPERCLIP_IN_WORKTREE=true",
|
||||||
"PAPERCLIP_WORKTREE_NAME=feature-worktree",
|
"PAPERCLIP_WORKTREE_NAME=feature-worktree",
|
||||||
|
"PAPERCLIP_OPTIONAL= # comment-only value",
|
||||||
"",
|
"",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
"utf8",
|
"utf8",
|
||||||
@@ -59,6 +60,7 @@ describe("dev-runner worktree env bootstrap", () => {
|
|||||||
expect(env.PAPERCLIP_HOME).toBe("/tmp/paperclip-worktrees");
|
expect(env.PAPERCLIP_HOME).toBe("/tmp/paperclip-worktrees");
|
||||||
expect(env.PAPERCLIP_INSTANCE_ID).toBe("already-set");
|
expect(env.PAPERCLIP_INSTANCE_ID).toBe("already-set");
|
||||||
expect(env.PAPERCLIP_IN_WORKTREE).toBe("true");
|
expect(env.PAPERCLIP_IN_WORKTREE).toBe("true");
|
||||||
|
expect(env.PAPERCLIP_OPTIONAL).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports uninitialized linked worktrees so dev runner can fail fast", () => {
|
it("reports uninitialized linked worktrees so dev runner can fail fast", () => {
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ function parseEnvFile(contents: string): Record<string, string> {
|
|||||||
entries[key] = "";
|
entries[key] = "";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (value.startsWith("#")) {
|
||||||
|
entries[key] = "";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(value.startsWith("\"") && value.endsWith("\"")) ||
|
(value.startsWith("\"") && value.endsWith("\"")) ||
|
||||||
@@ -32,6 +36,11 @@ function parseEnvFile(contents: string): Record<string, string> {
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WorktreeEnvBootstrapResult =
|
||||||
|
| { envPath: null; missingEnv: false }
|
||||||
|
| { envPath: string; missingEnv: true }
|
||||||
|
| { envPath: string; missingEnv: false };
|
||||||
|
|
||||||
export function isLinkedGitWorktreeCheckout(rootDir: string): boolean {
|
export function isLinkedGitWorktreeCheckout(rootDir: string): boolean {
|
||||||
const gitMetadataPath = path.join(rootDir, ".git");
|
const gitMetadataPath = path.join(rootDir, ".git");
|
||||||
if (!existsSync(gitMetadataPath)) return false;
|
if (!existsSync(gitMetadataPath)) return false;
|
||||||
@@ -49,10 +58,7 @@ export function resolveWorktreeEnvFilePath(rootDir: string): string {
|
|||||||
export function bootstrapDevRunnerWorktreeEnv(
|
export function bootstrapDevRunnerWorktreeEnv(
|
||||||
rootDir: string,
|
rootDir: string,
|
||||||
env: NodeJS.ProcessEnv = process.env,
|
env: NodeJS.ProcessEnv = process.env,
|
||||||
): {
|
): WorktreeEnvBootstrapResult {
|
||||||
envPath: string | null;
|
|
||||||
missingEnv: boolean;
|
|
||||||
} {
|
|
||||||
if (!isLinkedGitWorktreeCheckout(rootDir)) {
|
if (!isLinkedGitWorktreeCheckout(rootDir)) {
|
||||||
return {
|
return {
|
||||||
envPath: null,
|
envPath: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user