|
| 1 | +import path from "node:path"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import type { OpenClawConfig } from "../../config/types.openclaw.js"; |
| 4 | +import { listAgentIds } from "../agent-scope-config.js"; |
| 5 | +import { makeAttemptResult } from "./run.overflow-compaction.fixture.js"; |
| 6 | +import { |
| 7 | + loadRunOverflowCompactionHarness, |
| 8 | + mockedAcquireAgentRunPreparedModelRuntime, |
| 9 | + mockedBuildEmbeddedRunPayloads, |
| 10 | + mockedRunEmbeddedAttempt, |
| 11 | + overflowBaseRunParams, |
| 12 | +} from "./run.overflow-compaction.harness.js"; |
| 13 | + |
| 14 | +function projectSetupExecutionConfig(source: OpenClawConfig): OpenClawConfig { |
| 15 | + return { |
| 16 | + ...source, |
| 17 | + agents: { |
| 18 | + ...source.agents, |
| 19 | + entries: { |
| 20 | + ...(source.agents?.entries ?? { main: {} }), |
| 21 | + openclaw: {}, |
| 22 | + }, |
| 23 | + }, |
| 24 | + }; |
| 25 | +} |
| 26 | + |
| 27 | +describe("embedded setup inference inherited auth owner", () => { |
| 28 | + it.each([ |
| 29 | + { name: "a pre-roster config", source: {} }, |
| 30 | + { name: "a sole-agent config", source: { agents: { entries: { main: {} } } } }, |
| 31 | + ] satisfies Array<{ name: string; source: OpenClawConfig }>)( |
| 32 | + "prepares the explicit main agent from $name", |
| 33 | + async ({ name, source }) => { |
| 34 | + const config = projectSetupExecutionConfig(source); |
| 35 | + expect(listAgentIds(config)).toEqual(["main", "openclaw"]); |
| 36 | + |
| 37 | + const { runEmbeddedAgent } = await loadRunOverflowCompactionHarness(); |
| 38 | + mockedBuildEmbeddedRunPayloads.mockReturnValue([{ text: "OK" }]); |
| 39 | + mockedRunEmbeddedAttempt.mockResolvedValueOnce(makeAttemptResult({ assistantTexts: ["OK"] })); |
| 40 | + |
| 41 | + await runEmbeddedAgent({ |
| 42 | + ...overflowBaseRunParams, |
| 43 | + agentId: "main", |
| 44 | + config, |
| 45 | + runId: `run-setup-inference-owner-${name}`, |
| 46 | + }); |
| 47 | + |
| 48 | + const preparedInput = mockedAcquireAgentRunPreparedModelRuntime.mock.calls[0]?.[0]; |
| 49 | + expect(preparedInput).toMatchObject({ agentId: "main", config }); |
| 50 | + expect(String(preparedInput?.inheritedAuthDir)).toSatisfy((value: string) => |
| 51 | + value.endsWith(path.join("agents", "main", "agent")), |
| 52 | + ); |
| 53 | + expect(mockedRunEmbeddedAttempt).toHaveBeenCalledOnce(); |
| 54 | + }, |
| 55 | + ); |
| 56 | +}); |
0 commit comments