惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
WordPress大学
WordPress大学
小众软件
小众软件
IT之家
IT之家
腾讯CDC
月光博客
月光博客
量子位
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(discord): bound REST entity cache growth · openclaw/o...
fede-kamel · 2026-06-01 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -0,0 +1,77 @@

1+

import { afterEach, describe, expect, it, vi } from "vitest";

2+

import { DiscordEntityCache } from "./entity-cache.js";

3+

import type { RequestClient } from "./rest.js";

4+

import type { StructureClient } from "./structures.js";

5+
6+

function makeCache(opts: { ttlMs?: number; maxEntries?: number; sweepIntervalMs?: number }) {

7+

let getCalls = 0;

8+

const rest = {

9+

get: async (route: string) => {

10+

getCalls += 1;

11+

const id = route.split("/").pop() ?? "x";

12+

return { id };

13+

},

14+

} as unknown as RequestClient;

15+

const client = {} as StructureClient;

16+

const cache = new DiscordEntityCache({ client, rest, ...opts });

17+

return { cache, getCalls: () => getCalls };

18+

}

19+
20+

describe("DiscordEntityCache eviction", () => {

21+

afterEach(() => {

22+

vi.useRealTimers();

23+

});

24+
25+

it("caps entries by dropping oldest on insert past maxEntries", async () => {

26+

const { cache } = makeCache({ ttlMs: 60_000, maxEntries: 3 });

27+
28+

await cache.fetchUser("u1");

29+

await cache.fetchUser("u2");

30+

await cache.fetchUser("u3");

31+

expect(cache.size).toBe(3);

32+
33+

await cache.fetchUser("u4");

34+

expect(cache.size).toBe(3);

35+

});

36+
37+

it("sweeps expired entries on insert when sweep interval has elapsed", async () => {

38+

vi.useFakeTimers();

39+

vi.setSystemTime(new Date("2026-01-01T00:00:00Z"));

40+

const { cache } = makeCache({ ttlMs: 1, sweepIntervalMs: 0, maxEntries: 1000 });

41+
42+

await cache.fetchUser("u1");

43+

await cache.fetchUser("u2");

44+

expect(cache.size).toBe(2);

45+
46+

vi.advanceTimersByTime(5);

47+
48+

await cache.fetchUser("u3");

49+

expect(cache.size).toBe(1);

50+

});

51+
52+

it("does not sweep before sweep interval elapses", async () => {

53+

vi.useFakeTimers();

54+

vi.setSystemTime(new Date("2026-01-01T00:00:00Z"));

55+

const { cache } = makeCache({

56+

ttlMs: 1,

57+

sweepIntervalMs: 60_000,

58+

maxEntries: 1000,

59+

});

60+
61+

await cache.fetchUser("u1");

62+

await cache.fetchUser("u2");

63+

vi.advanceTimersByTime(5);

64+

await cache.fetchUser("u3");

65+
66+

expect(cache.size).toBe(3);

67+

});

68+
69+

it("does not write when ttl is 0", async () => {

70+

const { cache } = makeCache({ ttlMs: 0 });

71+
72+

await cache.fetchUser("u1");

73+

await cache.fetchUser("u2");

74+
75+

expect(cache.size).toBe(0);

76+

});

77+

});