
























@@ -12,6 +12,7 @@ import {
1212sweepExpiredPluginStateEntries,
1313} from "./plugin-state-store.js";
1414import { resolvePluginStateDir, resolvePluginStateSqlitePath } from "./plugin-state-store.paths.js";
15+import { seedPluginStateEntriesForTests } from "./plugin-state-store.test-helpers.js";
15161617afterEach(() => {
1718vi.useRealTimers();
@@ -126,22 +127,38 @@ describe("plugin state keyed store", () => {
126127127128it("rejects when the per-plugin live row ceiling would be exceeded without evicting siblings", async () => {
128129await withOpenClawTestState({ label: "plugin-state-plugin-limit" }, async () => {
129-const stores = Array.from({ length: 10 }, (_, index) =>
130-createPluginStateKeyedStore("discord", {
131-namespace: `ns-${index}`,
132-maxEntries: 101,
133-}),
134-);
135-for (let namespaceIndex = 0; namespaceIndex < stores.length; namespaceIndex += 1) {
136-for (let entryIndex = 0; entryIndex < 100; entryIndex += 1) {
137-await stores[namespaceIndex].register(`k-${entryIndex}`, { namespaceIndex, entryIndex });
138-}
139-}
130+seedPluginStateEntriesForTests([
131+ ...Array.from({ length: 999 }, (_, entryIndex) => ({
132+pluginId: "discord",
133+namespace: "limit",
134+key: `k-${entryIndex}`,
135+value: { namespaceIndex: 0, entryIndex },
136+})),
137+{
138+pluginId: "discord",
139+namespace: "sibling",
140+key: "k-0",
141+value: { namespaceIndex: 1, entryIndex: 0 },
142+},
143+]);
144+145+const limitStore = createPluginStateKeyedStore("discord", {
146+namespace: "limit",
147+maxEntries: 1_001,
148+});
149+const siblingStore = createPluginStateKeyedStore("discord", {
150+namespace: "sibling",
151+maxEntries: 10,
152+});
140153141-await expect(stores[0].register("overflow", { overflow: true })).rejects.toMatchObject({
154+await expect(limitStore.register("overflow", { overflow: true })).rejects.toMatchObject({
142155code: "PLUGIN_STATE_LIMIT_EXCEEDED",
143156});
144-await expect(stores[1].lookup("k-0")).resolves.toEqual({ namespaceIndex: 1, entryIndex: 0 });
157+await expect(siblingStore.lookup("k-0")).resolves.toEqual({
158+namespaceIndex: 1,
159+entryIndex: 0,
160+});
161+await expect(limitStore.lookup("overflow")).resolves.toBeUndefined();
145162});
146163});
147164此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。