peppa/packages/testkit/test/claude-trust.test.ts
peppa-bot ec45617e0f
All checks were successful
peppa/lint lint: success за 2с
peppa/typecheck typecheck: success за 47с
peppa/build build: success за 33с
peppa/test test: success за 1414с
peppa-ci / ci (pull_request) Successful in 26m2s
PEP-263: доверие Claude для worktree — и на основную копию репозитория
Claude Code 2.1.330 ищет доверие worktree по корню основного репозитория
(git common dir), а PEP-241 писал его только на папку worktree: агенты
висели на «Is this a project you trust?» (QLFW-80). Проверено на сервере:
с ключом на основную копию CLI сразу открывает рабочий экран.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 21:51:33 +05:00

52 lines
3.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// PEP-263: Claude Code 2.1.33x looks a git worktree's trust up by the MAIN repository's root. Trust
// written only for the worktree folder left agents on «Is this a project you trust?» (QLFW-80).
import { strict as assert } from "node:assert";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, test } from "node:test";
import { claudeConfigFor, markClaudeTrusted } from "@peppa/runner";
const git = (cwd: string, ...a: string[]) => execFileSync("git", a, { cwd, stdio: "pipe" });
describe("Доверие Claude к папке worktree (PEP-263)", () => {
test("Доверие ставится и на worktree, и на основную копию репозитория — не на HOME", () => {
const base = realpathSync(mkdtempSync(join(tmpdir(), "claude-trust-")));
try {
const repo = join(base, "workspaces", "proj");
git(base, "init", "-q", repo);
git(repo, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "--allow-empty", "-m", "init");
const wt = join(base, "worktrees", "proj", "s1");
git(repo, "worktree", "add", "-q", "-b", "task/x", wt);
const cfg = JSON.parse(claudeConfigFor(null, wt)) as { projects: Record<string, { hasTrustDialogAccepted?: boolean; enabledMcpjsonServers?: string[] }> };
assert.deepEqual(Object.keys(cfg.projects).sort(), [repo, wt].sort());
for (const p of Object.values(cfg.projects)) {
assert.equal(p.hasTrustDialogAccepted, true);
assert.deepEqual(p.enabledMcpjsonServers, ["peppa"]);
}
// Без этого ключа Claude 2.1.330 показывает вопрос о доверии (до исправления был только wt).
assert.equal(cfg.projects[repo]?.hasTrustDialogAccepted, true);
// Обычная папка (не worktree) — только она сама.
const plain = JSON.parse(claudeConfigFor(null, repo)) as { projects: Record<string, unknown> };
assert.deepEqual(Object.keys(plain.projects), [repo]);
// Повтор ничего не меняет; уже доверенное сохраняется.
const again: Record<string, any> = cfg;
assert.equal(markClaudeTrusted(again, wt), false);
// trustWorkspace (агент без контейнера) пишет тот же набор в ~/.claude.json.
const file = join(base, "claude.json");
writeFileSync(file, JSON.stringify({ projects: { "/other": { hasTrustDialogAccepted: true } } }));
const out = execFileSync(process.execPath, ["-e", `import("@peppa/runner").then((r) => r.trustWorkspace(${JSON.stringify(wt)}))`], { env: { ...process.env, PEPPA_CLAUDE_CONFIG: file }, stdio: "pipe" });
void out;
const saved = JSON.parse(readFileSync(file, "utf8")) as { projects: Record<string, unknown> };
assert.deepEqual(Object.keys(saved.projects).sort(), ["/other", repo, wt].sort());
} finally {
rmSync(base, { recursive: true, force: true });
}
});
});