



























@@ -2288,6 +2288,93 @@ describe("gateway agent handler", () => {
22882288});
22892289});
229022902291+it.each(["all", "non-main"] as const)(
2292+"does not preload startup memory from inherited workspaces for spawned sandboxed sessions in %s mode",
2293+async (sandboxMode) => {
2294+vi.useFakeTimers();
2295+vi.setSystemTime(new Date("2026-04-27T12:00:00.000Z"));
2296+try {
2297+await withTempDir(
2298+{ prefix: "openclaw-gateway-startup-canonical-" },
2299+async (canonicalWorkspaceDir) => {
2300+await withTempDir(
2301+{ prefix: "openclaw-gateway-startup-inherited-" },
2302+async (inheritedWorkspaceDir) => {
2303+await fs.mkdir(`${inheritedWorkspaceDir}/memory`, { recursive: true });
2304+const inheritedMarker = "OC_INHERITED_WORKSPACE_MEMORY_MARKER";
2305+await fs.writeFile(
2306+`${inheritedWorkspaceDir}/memory/2026-04-27.md`,
2307+inheritedMarker,
2308+"utf-8",
2309+);
2310+mocks.loadConfigReturn = {
2311+agents: {
2312+defaults: {
2313+workspace: canonicalWorkspaceDir,
2314+userTimezone: "UTC",
2315+startupContext: {
2316+enabled: true,
2317+applyOn: ["new"],
2318+dailyMemoryDays: 1,
2319+},
2320+sandbox: {
2321+mode: sandboxMode,
2322+scope: "session",
2323+workspaceAccess: "none",
2324+},
2325+},
2326+},
2327+};
2328+mockSessionResetSuccess({
2329+reason: "new",
2330+key: "agent:main:subagent:sandbox-child",
2331+});
2332+mocks.loadSessionEntry.mockReturnValue({
2333+cfg: mocks.loadConfigReturn,
2334+storePath: "/tmp/sessions.json",
2335+entry: {
2336+sessionId: "existing-child-session",
2337+updatedAt: Date.now(),
2338+spawnedBy: "agent:main:main",
2339+spawnedWorkspaceDir: inheritedWorkspaceDir,
2340+},
2341+canonicalKey: "agent:main:subagent:sandbox-child",
2342+});
2343+mocks.updateSessionStore.mockResolvedValue(undefined);
2344+mocks.agentCommand.mockResolvedValue({
2345+payloads: [{ text: "ok" }],
2346+meta: { durationMs: 100 },
2347+});
2348+2349+await invokeAgent(
2350+{
2351+message: "/new",
2352+sessionKey: "agent:main:subagent:sandbox-child",
2353+idempotencyKey: `test-idem-new-spawned-sandbox-memory-${sandboxMode}`,
2354+},
2355+{
2356+reqId: `4-startup-spawned-sandbox-memory-${sandboxMode}`,
2357+client: {
2358+connect: { scopes: ["operator.admin"] },
2359+} as AgentHandlerArgs["client"],
2360+},
2361+);
2362+2363+await waitForAssertion(() => expect(mocks.agentCommand).toHaveBeenCalled());
2364+const call = readLastAgentCommandCall();
2365+expect(call?.message).toContain("Execute your Session Startup sequence now");
2366+expect(call?.message).not.toContain("[Startup context loaded by runtime]");
2367+expect(call?.message).not.toContain(inheritedMarker);
2368+},
2369+);
2370+},
2371+);
2372+} finally {
2373+vi.useRealTimers();
2374+}
2375+},
2376+);
2377+22912378it("uses /reset suffix as the post-reset message and still injects timestamp", async () => {
22922379setupNewYorkTimeConfig("2026-01-29T01:30:00.000Z");
22932380mockSessionResetSuccess({ reason: "reset" });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。