mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-25 18:03:32 +00:00
refactor(agents): unify spawned metadata and extract attachments service
This commit is contained in:
81
src/agents/spawned-context.test.ts
Normal file
81
src/agents/spawned-context.test.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
mapToolContextToSpawnedRunMetadata,
|
||||
normalizeSpawnedRunMetadata,
|
||||
resolveIngressWorkspaceOverrideForSpawnedRun,
|
||||
resolveSpawnedWorkspaceInheritance,
|
||||
} from "./spawned-context.js";
|
||||
|
||||
describe("normalizeSpawnedRunMetadata", () => {
|
||||
it("trims text fields and drops empties", () => {
|
||||
expect(
|
||||
normalizeSpawnedRunMetadata({
|
||||
spawnedBy: " agent:main:subagent:1 ",
|
||||
groupId: " group-1 ",
|
||||
groupChannel: " slack ",
|
||||
groupSpace: " ",
|
||||
workspaceDir: " /tmp/ws ",
|
||||
}),
|
||||
).toEqual({
|
||||
spawnedBy: "agent:main:subagent:1",
|
||||
groupId: "group-1",
|
||||
groupChannel: "slack",
|
||||
workspaceDir: "/tmp/ws",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("mapToolContextToSpawnedRunMetadata", () => {
|
||||
it("maps agent group fields to run metadata shape", () => {
|
||||
expect(
|
||||
mapToolContextToSpawnedRunMetadata({
|
||||
agentGroupId: "g-1",
|
||||
agentGroupChannel: "telegram",
|
||||
agentGroupSpace: "topic:123",
|
||||
workspaceDir: "/tmp/ws",
|
||||
}),
|
||||
).toEqual({
|
||||
groupId: "g-1",
|
||||
groupChannel: "telegram",
|
||||
groupSpace: "topic:123",
|
||||
workspaceDir: "/tmp/ws",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveSpawnedWorkspaceInheritance", () => {
|
||||
it("prefers explicit workspaceDir when provided", () => {
|
||||
const resolved = resolveSpawnedWorkspaceInheritance({
|
||||
config: {},
|
||||
requesterSessionKey: "agent:main:subagent:parent",
|
||||
explicitWorkspaceDir: " /tmp/explicit ",
|
||||
});
|
||||
expect(resolved).toBe("/tmp/explicit");
|
||||
});
|
||||
|
||||
it("returns undefined for missing requester context", () => {
|
||||
const resolved = resolveSpawnedWorkspaceInheritance({
|
||||
config: {},
|
||||
requesterSessionKey: undefined,
|
||||
explicitWorkspaceDir: undefined,
|
||||
});
|
||||
expect(resolved).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveIngressWorkspaceOverrideForSpawnedRun", () => {
|
||||
it("forwards workspace only for spawned runs", () => {
|
||||
expect(
|
||||
resolveIngressWorkspaceOverrideForSpawnedRun({
|
||||
spawnedBy: "agent:main:subagent:parent",
|
||||
workspaceDir: "/tmp/ws",
|
||||
}),
|
||||
).toBe("/tmp/ws");
|
||||
expect(
|
||||
resolveIngressWorkspaceOverrideForSpawnedRun({
|
||||
spawnedBy: "",
|
||||
workspaceDir: "/tmp/ws",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user