|
1 | 1 | import { describe, test, expect } from "bun:test"; |
2 | | -import { mkdtemp, readFile, rm } from "node:fs/promises"; |
| 2 | +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; |
3 | 3 | import { tmpdir } from "node:os"; |
4 | | -import { join } from "node:path"; |
| 4 | +import { dirname, join } from "node:path"; |
5 | 5 |
|
6 | 6 | import { |
7 | 7 | loadProjectTrust, |
8 | 8 | projectTrustPath, |
| 9 | + readProjectTrustStore, |
9 | 10 | trustMcpServer, |
10 | 11 | trustPlugin, |
11 | 12 | type ProjectTrustStore, |
@@ -99,4 +100,32 @@ describe("project trust store", () => { |
99 | 100 | expect(exists).toBe(false); |
100 | 101 | }); |
101 | 102 | }); |
| 103 | + |
| 104 | + test("store without a repo field is invalid, not defaulted to empty-but-valid", async () => { |
| 105 | + await withTempHome(async (home, cwd) => { |
| 106 | + const path = projectTrustPath(cwd, home); |
| 107 | + await mkdir(dirname(path), { recursive: true }); |
| 108 | + await writeFile( |
| 109 | + path, |
| 110 | + JSON.stringify({ trustedPluginPaths: ["/plugins/a"], trustedMcpFingerprints: [] }), |
| 111 | + ); |
| 112 | + |
| 113 | + const result = await readProjectTrustStore(cwd, home); |
| 114 | + expect(result.state).toBe("invalid"); |
| 115 | + expect(result.store.trustedPluginPaths).toEqual([]); |
| 116 | + expect(result.store.trustedMcpFingerprints).toEqual([]); |
| 117 | + }); |
| 118 | + }); |
| 119 | + |
| 120 | + test("store with a non-string repo field is invalid", async () => { |
| 121 | + await withTempHome(async (home, cwd) => { |
| 122 | + const path = projectTrustPath(cwd, home); |
| 123 | + await mkdir(dirname(path), { recursive: true }); |
| 124 | + await writeFile(path, JSON.stringify({ repo: 12345, trustedPluginPaths: [] })); |
| 125 | + |
| 126 | + const result = await readProjectTrustStore(cwd, home); |
| 127 | + expect(result.state).toBe("invalid"); |
| 128 | + expect(result.store).toEqual({ trustedPluginPaths: [], trustedMcpFingerprints: [] }); |
| 129 | + }); |
| 130 | + }); |
102 | 131 | }); |
0 commit comments