mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
fix(coding-agent): harden project trust persistence
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import lockfile from "proper-lockfile";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { hasProjectConfig, ProjectTrustStore } from "../src/core/trust-manager.ts";
|
||||
|
||||
@@ -43,6 +44,29 @@ describe("ProjectTrustStore", () => {
|
||||
expect(readFileSync(trustPath, "utf-8")).toBe("{not json");
|
||||
});
|
||||
|
||||
it("does not read trust.json while another process holds the trust lock", () => {
|
||||
const trustPath = join(agentDir, "trust.json");
|
||||
writeFileSync(trustPath, "{partial", "utf-8");
|
||||
const release = lockfile.lockSync(agentDir, { realpath: false, lockfilePath: `${trustPath}.lock` });
|
||||
const store = new ProjectTrustStore(agentDir);
|
||||
|
||||
try {
|
||||
let error: unknown;
|
||||
try {
|
||||
store.get(cwd);
|
||||
} catch (caught) {
|
||||
error = caught;
|
||||
}
|
||||
|
||||
expect(error).toBeInstanceOf(Error);
|
||||
expect((error as { code?: unknown }).code).toBe("ELOCKED");
|
||||
} finally {
|
||||
release();
|
||||
}
|
||||
|
||||
expect(() => store.get(cwd)).toThrow(/Failed to read trust store/);
|
||||
});
|
||||
|
||||
it("detects .pi project config directories", () => {
|
||||
expect(hasProjectConfig(cwd)).toBe(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user