perf: reduce runtime cache churn · openclaw/openclaw@1531fe2
steipete
·
2026-05-26
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -282,6 +282,40 @@ describe("Session Store Cache", () => {
|
282 | 282 | expect(Object.prototype).not.toHaveProperty("polluted"); |
283 | 283 | }); |
284 | 284 | |
| 285 | +it("preserves own __proto__ plugin JSON fields without changing clone prototypes", () => { |
| 286 | +const pluginState: { [key: string]: unknown } = { ok: true }; |
| 287 | +Object.defineProperty(pluginState, "__proto__", { |
| 288 | +value: { polluted: true }, |
| 289 | +enumerable: true, |
| 290 | +configurable: true, |
| 291 | +writable: true, |
| 292 | +}); |
| 293 | +const testStore = createSingleSessionStore( |
| 294 | +createSessionEntry({ |
| 295 | +pluginExtensions: { |
| 296 | +demo: { |
| 297 | +pluginState: pluginState as never, |
| 298 | +}, |
| 299 | +}, |
| 300 | +}), |
| 301 | +); |
| 302 | + |
| 303 | +writeSessionStoreCache({ storePath, store: testStore }); |
| 304 | + |
| 305 | +const cached = readSessionStoreCache({ storePath }); |
| 306 | +const cachedState = cached?.["session:1"].pluginExtensions?.demo?.pluginState as |
| 307 | +| Record<string, unknown> |
| 308 | +| undefined; |
| 309 | + |
| 310 | +expect(cachedState).toBeTruthy(); |
| 311 | +expect(Object.hasOwn(cachedState ?? {}, "__proto__")).toBe(true); |
| 312 | +expect(Object.getOwnPropertyDescriptor(cachedState, "__proto__")?.value).toEqual({ |
| 313 | +polluted: true, |
| 314 | +}); |
| 315 | +expect(Object.getPrototypeOf(cachedState ?? {})).toBe(Object.prototype); |
| 316 | +expect(({} as Record<string, unknown>).polluted).toBeUndefined(); |
| 317 | +}); |
| 318 | + |
285 | 319 | it("clones disk-loaded stores from the raw serialized JSON", () => { |
286 | 320 | const testStore = createSingleSessionStore( |
287 | 321 | createSessionEntry({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -285,7 +285,7 @@ describe("manifest model id normalization", () => {
|
285 | 285 | expect(normalizeDemoModelWithEnv(env)).toBe("bravo/demo-model"); |
286 | 286 | }); |
287 | 287 | |
288 | | -it("reflects manifest edits and state-dir changes on the next lookup", () => { |
| 288 | +it("keeps process metadata stable across manifest edits and reflects state-dir changes", () => { |
289 | 289 | const stateDirA = makeTempDir(); |
290 | 290 | const pluginDirA = path.join(stateDirA, "extensions", "normalizer"); |
291 | 291 | writeInstallIndex({ stateDir: stateDirA, pluginDir: pluginDirA }); |
@@ -299,8 +299,7 @@ describe("manifest model id normalization", () => {
|
299 | 299 | expect(normalizeDemoModel()).toBe("alpha/demo-model"); |
300 | 300 | |
301 | 301 | writeNormalizerManifest({ pluginDir: pluginDirA, prefix: "bravo-local" }); |
302 | | -clearPluginMetadataLifecycleCaches(); |
303 | | -expect(normalizeDemoModel()).toBe("bravo-local/demo-model"); |
| 302 | +expect(normalizeDemoModel()).toBe("alpha/demo-model"); |
304 | 303 | |
305 | 304 | const stateDirB = makeTempDir(); |
306 | 305 | const pluginDirB = path.join(stateDirB, "extensions", "normalizer"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -46,7 +46,7 @@ function resolveMetadataSnapshotForPolicies(
|
46 | 46 | env, |
47 | 47 | workspaceDir, |
48 | 48 | allowWorkspaceScopedSnapshot: true, |
49 | | -requireDefaultDiscoveryContext: params.env !== undefined, |
| 49 | +requireDefaultDiscoveryContext: true, |
50 | 50 | }); |
51 | 51 | if (currentSnapshot) { |
52 | 52 | return { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -387,7 +387,7 @@ export function isPluginMetadataSnapshotCompatible(params: {
|
387 | 387 | PluginMetadataSnapshot, |
388 | 388 | "configFingerprint" | "index" | "policyHash" | "workspaceDir" |
389 | 389 | >; |
390 | | -config: OpenClawConfig; |
| 390 | +config?: OpenClawConfig; |
391 | 391 | env?: NodeJS.ProcessEnv; |
392 | 392 | workspaceDir?: string; |
393 | 393 | index?: InstalledPluginIndex; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -57,10 +57,10 @@ export type PluginMetadataRegistryView = Pick<PluginMetadataSnapshot, "index" |
|
57 | 57 | export type PluginMetadataManifestView = Pick<PluginMetadataSnapshot, "index" | "plugins">; |
58 | 58 | |
59 | 59 | export type LoadPluginMetadataSnapshotParams = { |
60 | | -config: OpenClawConfig; |
| 60 | +config?: OpenClawConfig; |
61 | 61 | workspaceDir?: string; |
62 | 62 | stateDir?: string; |
63 | | -env: NodeJS.ProcessEnv; |
| 63 | +env?: NodeJS.ProcessEnv; |
64 | 64 | index?: InstalledPluginIndex; |
65 | 65 | preferPersisted?: boolean; |
66 | 66 | }; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。