Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(plugins): cover model catalog cache bounds

PraiseZhufee2da657559
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostAgentModels.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostAgentModels.test.ts
index 59d8dcc672..e773e22c50 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostAgentModels.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostAgentModels.test.ts
@@ -171,4 +171,47 @@ describe('plugin model projection', () => {
});
expect(read).toHaveBeenCalledTimes(2);
});
+
+ /**
+ * 测试价值
+ * - 生产入口与可观察结果:插件目录缓存命中仍有效的目录,过期或被容量淘汰的目录重新读取。
+ * - Bug/规则依据:makecindy/cindy#7472 Greptile「旧目录一直占内存」。
+ * - 现有覆盖缺口:现有用例没有验证 TTL 过期回收,也没有跨 owner 的总目录条数上限。
+ * - 最小失败输入:63 个过期目录、1 个新鲜目录与第 65 个目录;再读新鲜项及最早插入项。
+ * - tier:unit。
+ * - 实测耗时:0.59 s(红测单文件运行,macOS arm64)。
+ */
+ it('evicts expired catalogs before enforcing a bounded cache size', async () => {
+ let now = 0;
+ const cache = createGhostAgentModelsCache({ now: () => now, ttlMs: 60_000 });
+ const readFor = (id: string) => vi.fn<() => Promise<ProviderView[]>>()
+ .mockResolvedValue([provider(id, ['high'])]);
+ const expiredReads = Array.from({ length: 63 }, (_, index) => readFor(`expired-${index}`));
+
+ for (const [index, read] of expiredReads.entries()) {
+ await cache.catalog(`expired-owner-${index}`, `expired-device-${index}`, read);
+ }
+
+ now = 1_000;
+ const freshRead = readFor('fresh');
+ await cache.catalog('fresh-owner', 'fresh-device', freshRead);
+ now = 2_000;
+ for (const [index, read] of expiredReads.entries()) {
+ await cache.catalog(`expired-owner-${index}`, `expired-device-${index}`, read);
+ }
+
+ now = 60_001;
+ const newRead = readFor('new');
+ await cache.catalog('new-owner', 'new-device', newRead);
+ await cache.catalog('fresh-owner', 'fresh-device', freshRead);
+ expect(freshRead).toHaveBeenCalledTimes(1);
+
+ const bounded = createGhostAgentModelsCache({ now: () => 0, ttlMs: 60_000 });
+ const capacityReads = Array.from({ length: 65 }, (_, index) => readFor(`capacity-${index}`));
+ for (const [index, read] of capacityReads.entries()) {
+ await bounded.catalog(`capacity-owner-${index}`, `capacity-device-${index}`, read);
+ }
+ await bounded.catalog('capacity-owner-0', 'capacity-device-0', capacityReads[0]!);
+ expect(capacityReads[0]).toHaveBeenCalledTimes(2);
+ });
});