|
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import type { OpenClawConfig } from "../../config/types.openclaw.js"; |
| 3 | + |
| 4 | +const inventoryMocks = vi.hoisted(() => { |
| 5 | + const runtimeModel = { |
| 6 | + id: "dynamic-chat", |
| 7 | + name: "dynamic-chat", |
| 8 | + provider: "dynamic-provider", |
| 9 | + api: "openai-responses", |
| 10 | + baseUrl: "https://example.invalid/v1", |
| 11 | + }; |
| 12 | + return { |
| 13 | + runtimeModel, |
| 14 | + resolveRuntimeModelContext: vi.fn(async () => ({ |
| 15 | + modelApi: runtimeModel.api, |
| 16 | + runtimeModel, |
| 17 | + })), |
| 18 | + resolveInventory: vi.fn((params: Record<string, unknown>) => { |
| 19 | + if (!Object.hasOwn(params, "modelApi") || !Object.hasOwn(params, "runtimeModel")) { |
| 20 | + throw new Error("runtime model facts must be explicitly owner-published"); |
| 21 | + } |
| 22 | + return { |
| 23 | + agentId: "main", |
| 24 | + profile: "coding", |
| 25 | + groups: [ |
| 26 | + { |
| 27 | + id: "core", |
| 28 | + label: "Built-in tools", |
| 29 | + source: "core", |
| 30 | + tools: [ |
| 31 | + { |
| 32 | + id: "read", |
| 33 | + label: "Read", |
| 34 | + description: "Read files", |
| 35 | + rawDescription: "Read files", |
| 36 | + source: "core", |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + ], |
| 41 | + }; |
| 42 | + }), |
| 43 | + }; |
| 44 | +}); |
| 45 | + |
| 46 | +vi.mock("../../agents/tools-effective-inventory.js", () => ({ |
| 47 | + resolveEffectiveToolInventory: inventoryMocks.resolveInventory, |
| 48 | + resolveEffectiveToolInventoryRuntimeModelContextAsync: inventoryMocks.resolveRuntimeModelContext, |
| 49 | +})); |
| 50 | + |
| 51 | +describe("resolveBareResetBootstrapFileAccess runtime model ownership", () => { |
| 52 | + beforeEach(() => { |
| 53 | + inventoryMocks.resolveInventory.mockClear(); |
| 54 | + inventoryMocks.resolveRuntimeModelContext.mockClear(); |
| 55 | + }); |
| 56 | + |
| 57 | + it("resolves runtime model context once and passes explicit facts to sync inventory", async () => { |
| 58 | + const { resolveBareResetBootstrapFileAccess } = await import("./session-reset-prompt.js"); |
| 59 | + const cfg = {} as OpenClawConfig; |
| 60 | + const params = { |
| 61 | + cfg, |
| 62 | + agentId: "main", |
| 63 | + sessionKey: "agent:main:main", |
| 64 | + workspaceDir: "/tmp/workspace-main", |
| 65 | + modelProvider: "dynamic-provider", |
| 66 | + modelId: "dynamic-chat", |
| 67 | + }; |
| 68 | + |
| 69 | + await expect(resolveBareResetBootstrapFileAccess(params)).resolves.toBe(true); |
| 70 | + |
| 71 | + expect(inventoryMocks.resolveRuntimeModelContext).toHaveBeenCalledTimes(1); |
| 72 | + expect(inventoryMocks.resolveRuntimeModelContext).toHaveBeenCalledWith({ |
| 73 | + cfg, |
| 74 | + agentId: params.agentId, |
| 75 | + workspaceDir: params.workspaceDir, |
| 76 | + modelProvider: params.modelProvider, |
| 77 | + modelId: params.modelId, |
| 78 | + }); |
| 79 | + expect(inventoryMocks.resolveInventory).toHaveBeenCalledTimes(1); |
| 80 | + const inventoryParams = inventoryMocks.resolveInventory.mock.calls[0]?.[0]; |
| 81 | + expect(inventoryParams).toMatchObject({ |
| 82 | + ...params, |
| 83 | + modelApi: inventoryMocks.runtimeModel.api, |
| 84 | + runtimeModel: inventoryMocks.runtimeModel, |
| 85 | + }); |
| 86 | + expect(Object.hasOwn(inventoryParams ?? {}, "modelApi")).toBe(true); |
| 87 | + expect(Object.hasOwn(inventoryParams ?? {}, "runtimeModel")).toBe(true); |
| 88 | + }); |
| 89 | +}); |
0 commit comments