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

推荐订阅源

J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
C
Check Point Blog
D
Docker
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
量子位
有赞技术团队
有赞技术团队
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
M
MIT News - Artificial intelligence
B
Blog
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
月光博客
月光博客

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: pin plugin workspace dir for sessions.list to avoid ...
lsr911 · 2026-06-17 · via Recent Commits to openclaw:main
1+

// Verifies request-scoped plugin workspace pins under concurrent registry mutation.

2+

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

3+

import { createEmptyPluginRegistry } from "./registry-empty.js";

4+

import { getActivePluginRegistryWorkspaceDirFromState } from "./runtime-state.js";

5+

import { withPinnedActivePluginRegistryWorkspaceDir } from "./runtime-workspace-state.js";

6+

import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "./runtime.js";

7+8+

function setActiveWorkspace(workspaceDir: string): void {

9+

setActivePluginRegistry(

10+

createEmptyPluginRegistry(),

11+

workspaceDir,

12+

"gateway-bindable",

13+

workspaceDir,

14+

);

15+

}

16+17+

function createDeferred(): { promise: Promise<void>; resolve: () => void } {

18+

let resolve: (() => void) | undefined;

19+

const promise = new Promise<void>((done) => {

20+

resolve = done;

21+

});

22+

if (!resolve) {

23+

throw new Error("Expected deferred resolver");

24+

}

25+

return { promise, resolve };

26+

}

27+28+

describe("runtime workspace state pin", () => {

29+

afterEach(() => {

30+

resetPluginRuntimeStateForTest();

31+

});

32+33+

it("reads the live global workspace dir when no pin is active", () => {

34+

setActiveWorkspace("/workspace/a");

35+

expect(getActivePluginRegistryWorkspaceDirFromState()).toBe("/workspace/a");

36+37+

setActiveWorkspace("/workspace/b");

38+

expect(getActivePluginRegistryWorkspaceDirFromState()).toBe("/workspace/b");

39+

});

40+41+

it("isolates overlapping pins and restores live state after success", async () => {

42+

const firstPinned = createDeferred();

43+

const resumeFirst = createDeferred();

44+

const firstObserved: Array<string | undefined> = [];

45+46+

setActiveWorkspace("/workspace/a");

47+

const firstRequest = withPinnedActivePluginRegistryWorkspaceDir(async () => {

48+

firstObserved.push(getActivePluginRegistryWorkspaceDirFromState());

49+

firstPinned.resolve();

50+

await resumeFirst.promise;

51+

firstObserved.push(getActivePluginRegistryWorkspaceDirFromState());

52+

});

53+

await firstPinned.promise;

54+55+

setActiveWorkspace("/workspace/b");

56+

const secondObserved = await withPinnedActivePluginRegistryWorkspaceDir(async () => {

57+

const observed = [getActivePluginRegistryWorkspaceDirFromState()];

58+

setActiveWorkspace("/workspace/c");

59+

await new Promise<void>((resolve) => {

60+

setImmediate(resolve);

61+

});

62+

observed.push(getActivePluginRegistryWorkspaceDirFromState());

63+

return observed;

64+

});

65+66+

resumeFirst.resolve();

67+

await firstRequest;

68+69+

expect(firstObserved).toEqual(["/workspace/a", "/workspace/a"]);

70+

expect(secondObserved).toEqual(["/workspace/b", "/workspace/b"]);

71+

expect(getActivePluginRegistryWorkspaceDirFromState()).toBe("/workspace/c");

72+

});

73+74+

it("reuses the outer pin for nested scopes", async () => {

75+

setActiveWorkspace("/workspace/a");

76+77+

await withPinnedActivePluginRegistryWorkspaceDir(async () => {

78+

setActiveWorkspace("/workspace/b");

79+

await withPinnedActivePluginRegistryWorkspaceDir(async () => {

80+

expect(getActivePluginRegistryWorkspaceDirFromState()).toBe("/workspace/a");

81+

});

82+

});

83+84+

expect(getActivePluginRegistryWorkspaceDirFromState()).toBe("/workspace/b");

85+

});

86+87+

it("preserves the pin across module reloads", async () => {

88+

setActiveWorkspace("/workspace/a");

89+90+

await withPinnedActivePluginRegistryWorkspaceDir(async () => {

91+

setActiveWorkspace("/workspace/b");

92+

const reloaded = await import(

93+

new URL("./runtime-workspace-state.ts?workspace-pin-reload", import.meta.url).href

94+

);

95+96+

expect(reloaded.getActivePluginRegistryWorkspaceDirFromState()).toBe("/workspace/a");

97+

});

98+

});

99+100+

it("propagates rejections without leaking the pin", async () => {

101+

setActiveWorkspace("/workspace/a");

102+103+

await expect(

104+

withPinnedActivePluginRegistryWorkspaceDir(async () => {

105+

setActiveWorkspace("/workspace/b");

106+

throw new Error("workspace request failed");

107+

}),

108+

).rejects.toThrow("workspace request failed");

109+110+

expect(getActivePluginRegistryWorkspaceDirFromState()).toBe("/workspace/b");

111+

});

112+

});