mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 17:54:40 +01:00
fix(dev): use saved signing keys for empty instances
Prefer the explicitly empty instance keys during dev bootstrap, server config loading, and legacy repair. Verify actual startup with inherited source credentials. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
f712015f7f
commit
769d1f7e53
6 files changed
+57
-2
No files matched your search
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
bootstrapDevRunnerWorktreeEnv,
|
||||
applyEmptyWorktreeSigningSecrets,
|
||||
isWorktreeSeedPending,
|
||||
isLinkedGitWorktreeCheckout,
|
||||
resolveWorktreeEnvFilePath,
|
||||
@@ -25,6 +26,18 @@ function createTempRoot(prefix: string): string {
|
||||
}
|
||||
|
||||
describe("dev-runner worktree env bootstrap", () => {
|
||||
it("uses saved empty-instance signing keys instead of inherited source keys", () => {
|
||||
const root = createTempRoot("paperclip-empty-signing-keys-");
|
||||
fs.mkdirSync(path.join(root, ".paperclip"));
|
||||
fs.writeFileSync(path.join(root, ".git"), "gitdir: /tmp/paperclip/.git/worktrees/empty\n");
|
||||
fs.writeFileSync(path.join(root, ".paperclip", "seed-empty"), "explicitly empty\n");
|
||||
fs.writeFileSync(resolveWorktreeEnvFilePath(root), 'PAPERCLIP_AGENT_JWT_SECRET="fresh-jwt"\nPAPERCLIP_TOOL_ACTION_SIGNING_SECRET="fresh-actions"\n');
|
||||
const env = { PAPERCLIP_AGENT_JWT_SECRET: "source-jwt", PAPERCLIP_TOOL_ACTION_SIGNING_SECRET: "source-actions", BETTER_AUTH_SECRET: "source-auth" };
|
||||
bootstrapDevRunnerWorktreeEnv(root, env);
|
||||
expect(env).toMatchObject({ PAPERCLIP_AGENT_JWT_SECRET: "fresh-jwt", PAPERCLIP_TOOL_ACTION_SIGNING_SECRET: "fresh-actions", BETTER_AUTH_SECRET: "fresh-jwt" });
|
||||
fs.writeFileSync(resolveWorktreeEnvFilePath(root), 'PAPERCLIP_AGENT_JWT_SECRET="fresh-jwt"\n');
|
||||
expect(() => applyEmptyWorktreeSigningSecrets(root, env)).toThrow("missing its saved PAPERCLIP_TOOL_ACTION_SIGNING_SECRET");
|
||||
});
|
||||
it("guards seed-pending worktrees until a seed-complete marker exists", () => {
|
||||
const root = createTempRoot("paperclip-dev-runner-seed-pending-");
|
||||
fs.mkdirSync(path.join(root, ".paperclip"), { recursive: true });
|
||||
|
||||
@@ -2,7 +2,7 @@ import { execFile } from "node:child_process";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
@@ -107,6 +107,24 @@ describe("managed worktree seed source through the server spawn path", () => {
|
||||
process.chdir(cwd);
|
||||
await worktreeInitCommand({ empty: true, fromConfig: sourceConfigPath, home: path.join(tempRoot, "instances") });
|
||||
const configPath = path.join(cwd, ".paperclip", "config.json");
|
||||
const repoRoot = fileURLToPath(new URL("../../../", import.meta.url));
|
||||
const startup = await execFileAsync(process.execPath, [path.join(repoRoot, "cli/node_modules/tsx/dist/cli.mjs"), "--eval", `
|
||||
void (async () => {
|
||||
const fs = await import('node:fs');
|
||||
const dotenv = (await import(${JSON.stringify(pathToFileURL(path.join(repoRoot, "server/node_modules/dotenv/lib/main.js")).href)})).default;
|
||||
const envPath = ${JSON.stringify(path.join(cwd, ".paperclip", ".env"))};
|
||||
const saved = dotenv.parse(fs.readFileSync(envPath));
|
||||
await import(${JSON.stringify(pathToFileURL(path.join(repoRoot, "server/src/config.ts")).href)});
|
||||
const repaired = dotenv.parse(fs.readFileSync(envPath));
|
||||
console.log(JSON.stringify({
|
||||
jwt: process.env.PAPERCLIP_AGENT_JWT_SECRET === saved.PAPERCLIP_AGENT_JWT_SECRET,
|
||||
actions: process.env.PAPERCLIP_TOOL_ACTION_SIGNING_SECRET === saved.PAPERCLIP_TOOL_ACTION_SIGNING_SECRET,
|
||||
auth: process.env.BETTER_AUTH_SECRET === saved.PAPERCLIP_AGENT_JWT_SECRET,
|
||||
savedActions: repaired.PAPERCLIP_TOOL_ACTION_SIGNING_SECRET === saved.PAPERCLIP_TOOL_ACTION_SIGNING_SECRET
|
||||
}));
|
||||
})();
|
||||
`], { cwd, env: { ...process.env, PAPERCLIP_CONFIG: configPath, PAPERCLIP_AGENT_JWT_SECRET: "source-jwt", PAPERCLIP_TOOL_ACTION_SIGNING_SECRET: "source-actions", BETTER_AUTH_SECRET: "source-auth" } });
|
||||
expect(JSON.parse(startup.stdout.trim().split("\n").at(-1)!)).toEqual({ jwt: true, actions: true, auth: true, savedActions: true });
|
||||
const workspace = {
|
||||
baseCwd, cwd, source: "project_primary" as const, projectId: "project-1",
|
||||
workspaceId: "project-workspace-1", repoUrl: null, repoRef: "HEAD",
|
||||
|
||||
Reference in new issue
Block a user