Skip to content

Commit 6fe3571

Browse files
committed
Cover refusal notice and quiet empty corrupt path-trust warnings
1 parent bae006a commit 6fe3571

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎src/trust/path-trust.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export async function revokePathPlugin(
175175

176176
/**
177177
* One-shot migration: seed the global store from `settings.pluginPaths` when
178-
* no valid store file exists yet. Every registered entry that resolves to a
178+
* the store file is missing (first launch). Every registered entry that resolves to a
179179
* plugin on disk is granted — pluginPaths lives in the user's global settings,
180180
* so each entry was put there by the user (add-by-path or a hand edit) and
181181
* registration is taken as consent at the moment the store is created, even
@@ -208,7 +208,9 @@ export async function migratePathTrustFromPluginPaths(
208208
return existing.store;
209209
}
210210
if (existing.state === "invalid") {
211-
logger.warn`refusing path-trust migration from a corrupt store at ${pathTrustPath(home)}: delete the file to re-seed from settings.pluginPaths or re-consent through add-by-path`;
211+
if (pluginPaths.length > 0) {
212+
logger.warn`refusing path-trust migration from a corrupt store at ${pathTrustPath(home)}: delete the file to re-seed from settings.pluginPaths or re-consent through add-by-path`;
213+
}
212214
return emptyStore();
213215
}
214216
if (pluginPaths.length === 0) {

‎tests/unit/path-trust.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,20 @@ describe("path-trust (global)", () => {
248248

249249
const plugin = join(home, "shared", "plugin");
250250
let resolveCalls = 0;
251+
let migratedCalls = 0;
251252
const store = await migratePathTrustFromPluginPaths(
252253
[plugin],
253254
async (p) => {
254255
resolveCalls += 1;
255256
return [p];
256257
},
257258
home,
259+
{ onMigrated: () => (migratedCalls += 1) },
258260
);
259261
expect(isPathPluginTrusted(store, plugin)).toBe(false);
260262
expect(store.trustedPluginPaths).toEqual([]);
261263
expect(resolveCalls).toBe(0);
264+
expect(migratedCalls).toBe(0);
262265
expect((await readPathTrustStore(home)).state).toBe("invalid");
263266
} finally {
264267
await cleanup();
@@ -274,17 +277,20 @@ describe("path-trust (global)", () => {
274277

275278
const plugin = join(home, "shared", "plugin");
276279
let resolveCalls = 0;
280+
let migratedCalls = 0;
277281
const store = await migratePathTrustFromPluginPaths(
278282
[plugin],
279283
async (p) => {
280284
resolveCalls += 1;
281285
return [p];
282286
},
283287
home,
288+
{ onMigrated: () => (migratedCalls += 1) },
284289
);
285290
expect(isPathPluginTrusted(store, plugin)).toBe(false);
286291
expect(store.trustedPluginPaths).toEqual([]);
287292
expect(resolveCalls).toBe(0);
293+
expect(migratedCalls).toBe(0);
288294
expect((await readPathTrustStore(home)).state).toBe("invalid");
289295
} finally {
290296
await cleanup();
@@ -303,17 +309,20 @@ describe("path-trust (global)", () => {
303309
expect((await readPathTrustStore(home)).state).toBe("invalid");
304310

305311
let resolveCalls = 0;
312+
let migratedCalls = 0;
306313
const store = await migratePathTrustFromPluginPaths(
307314
[plugin],
308315
async (p) => {
309316
resolveCalls += 1;
310317
return [p];
311318
},
312319
home,
320+
{ onMigrated: () => (migratedCalls += 1) },
313321
);
314322
expect(isPathPluginTrusted(store, plugin)).toBe(false);
315323
expect(store.trustedPluginPaths).toEqual([]);
316324
expect(resolveCalls).toBe(0);
325+
expect(migratedCalls).toBe(0);
317326
expect((await readPathTrustStore(home)).state).toBe("invalid");
318327
} finally {
319328
await cleanup();

0 commit comments

Comments
 (0)