
















@@ -301,7 +301,7 @@ describe("Integration: saveSessionStore with pruning", () => {
301301expect(Object.keys(loaded)).toHaveLength(2);
302302});
303303304-it("loadSessionStore prunes stale entries from oversized stores by default", async () => {
304+it("loadSessionStore leaves oversized stores untouched during normal reads", async () => {
305305const now = Date.now();
306306const store: Record<string, SessionEntry> = {
307307stale: makeEntry(now - 31 * DAY_MS),
@@ -319,12 +319,37 @@ describe("Integration: saveSessionStore with pruning", () => {
319319},
320320});
321321322-expect(loaded.stale).toBeUndefined();
322+expect(Object.keys(loaded)).toHaveLength(3);
323+expect(loaded.stale).toBeDefined();
323324expect(loaded.recent).toBeDefined();
324325expect(loaded.newest).toBeDefined();
325326});
326327327-it("loadSessionStore caps oversized stores by default", async () => {
328+it("loadSessionStore applies maintenance only when explicitly requested", async () => {
329+const now = Date.now();
330+const store: Record<string, SessionEntry> = {
331+stale: makeEntry(now - 31 * DAY_MS),
332+recent: makeEntry(now - DAY_MS),
333+newest: makeEntry(now),
334+};
335+await fs.writeFile(storePath, JSON.stringify(store), "utf-8");
336+337+const loaded = loadSessionStore(storePath, {
338+skipCache: true,
339+runMaintenance: true,
340+maintenanceConfig: {
341+ ...ENFORCED_MAINTENANCE_OVERRIDE,
342+maxEntries: 1,
343+pruneAfterMs: 7 * DAY_MS,
344+},
345+});
346+347+expect(loaded.stale).toBeUndefined();
348+expect(loaded.recent).toBeUndefined();
349+expect(loaded.newest).toBeDefined();
350+});
351+352+it("loadSessionStore does not cap oversized stores during normal reads", async () => {
328353const now = Date.now();
329354const store: Record<string, SessionEntry> = {
330355oldest: makeEntry(now - 3 * DAY_MS),
@@ -342,13 +367,13 @@ describe("Integration: saveSessionStore with pruning", () => {
342367},
343368});
344369345-expect(Object.keys(loaded)).toHaveLength(2);
346-expect(loaded.oldest).toBeUndefined();
370+expect(Object.keys(loaded)).toHaveLength(3);
371+expect(loaded.oldest).toBeDefined();
347372expect(loaded.recent).toBeDefined();
348373expect(loaded.newest).toBeDefined();
349374});
350375351-it("loadSessionStore batches entry-count cleanup until the high-water mark", async () => {
376+it("explicit loadSessionStore maintenance batches entry-count cleanup until the high-water mark", async () => {
352377const now = Date.now();
353378const store = Object.fromEntries(
354379Array.from({ length: 51 }, (_, index) => [`session-${index}`, makeEntry(now - index)]),
@@ -357,6 +382,7 @@ describe("Integration: saveSessionStore with pruning", () => {
357382358383const loaded = loadSessionStore(storePath, {
359384skipCache: true,
385+runMaintenance: true,
360386maintenanceConfig: {
361387 ...ENFORCED_MAINTENANCE_OVERRIDE,
362388maxEntries: 50,
@@ -367,7 +393,7 @@ describe("Integration: saveSessionStore with pruning", () => {
367393expect(Object.keys(loaded)).toHaveLength(51);
368394});
369395370-it("loadSessionStore caps production-sized stores once they reach the high-water mark", async () => {
396+it("explicit loadSessionStore maintenance caps production-sized stores once they reach the high-water mark", async () => {
371397const now = Date.now();
372398const store = Object.fromEntries(
373399Array.from({ length: 75 }, (_, index) => [`session-${index}`, makeEntry(now - index)]),
@@ -376,6 +402,7 @@ describe("Integration: saveSessionStore with pruning", () => {
376402377403const loaded = loadSessionStore(storePath, {
378404skipCache: true,
405+runMaintenance: true,
379406maintenanceConfig: {
380407 ...ENFORCED_MAINTENANCE_OVERRIDE,
381408maxEntries: 50,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。