Skip to content

Commit 519877a

Browse files
steipeteampagent
andauthored
1 parent a4ae339 commit 519877a

4 files changed

Lines changed: 266 additions & 6 deletions

File tree

‎ui/src/components/session-organizer-operations.runtime.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ export async function renameSession(
395395
}
396396

397397
export async function assignSessionOwner(
398-
host: SessionOrganizerControllerHost,
399-
session: SidebarRecentSession,
398+
host: SessionActionHost,
399+
session: Pick<SidebarRecentSession, "key">,
400400
owner: Pick<SessionOwnerOption, "type" | "id">,
401401
scope: SidebarSessionMutationScope,
402402
): Promise<void> {
@@ -409,9 +409,16 @@ export async function assignSessionOwner(
409409
) {
410410
return;
411411
}
412-
await scope.sessions.assignOwner(session.key, owner, {
412+
const assigned = await scope.sessions.assignOwner(session.key, owner, {
413413
agentId: parseAgentSessionKey(session.key)?.agentId ?? scope.selectedAgentId,
414414
});
415+
if (
416+
host.sessionData.isSessionMutationScopeCurrent(scope) &&
417+
!assigned &&
418+
scope.sessions.state.error
419+
) {
420+
host.sessionData.publishSessionMutationError(scope, scope.sessions.state.error);
421+
}
415422
}
416423

417424
export async function createSessionGroup(
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* @vitest-environment jsdom */
2+
3+
import { describe, expect, it, vi } from "vitest";
4+
import type { ApplicationGatewaySnapshot } from "../app/gateway.ts";
5+
import type { SessionCapability } from "../lib/sessions/index.ts";
6+
import { gatewayHelloForMethods } from "../test-helpers/gateway-methods.ts";
7+
import type { SidebarSessionMutationScope } from "./app-sidebar-session-types.ts";
8+
import type { SessionActionHost } from "./session-organizer-batch-mutations.ts";
9+
import { assignSessionOwner } from "./session-organizer-operations.runtime.ts";
10+
11+
function createHarness() {
12+
let current = true;
13+
let sessionError: string | null = null;
14+
let settleAssignment: ((result: null) => void) | undefined;
15+
const assignOwner = vi.fn(
16+
() =>
17+
new Promise<null>((resolve) => {
18+
settleAssignment = resolve;
19+
}),
20+
);
21+
const publishSessionMutationError = vi.fn();
22+
const snapshot = {
23+
client: {},
24+
phase: "connected",
25+
hello: gatewayHelloForMethods(["sessions.assignOwner"], ["operator.write"]),
26+
} as ApplicationGatewaySnapshot;
27+
const scope = {
28+
gateway: { snapshot },
29+
sessions: {
30+
assignOwner,
31+
get state() {
32+
return { error: sessionError };
33+
},
34+
} as unknown as SessionCapability,
35+
selectedAgentId: "main",
36+
} as SidebarSessionMutationScope;
37+
const host = {
38+
sessionData: {
39+
isSessionMutationScopeCurrent: vi.fn(() => current),
40+
publishSessionMutationError,
41+
},
42+
} as unknown as SessionActionHost;
43+
const session = {
44+
key: "agent:main:owner-proof",
45+
};
46+
return {
47+
assignOwner,
48+
host,
49+
publishSessionMutationError,
50+
retire: () => {
51+
current = false;
52+
},
53+
scope,
54+
session,
55+
setError: (error: string) => {
56+
sessionError = error;
57+
},
58+
settle: () => settleAssignment?.(null),
59+
};
60+
}
61+
62+
describe("assignSessionOwner", () => {
63+
it("publishes a current capability rejection at the action surface", async () => {
64+
const harness = createHarness();
65+
const pending = assignSessionOwner(
66+
harness.host,
67+
harness.session,
68+
{ type: "human", id: "profile-ada" },
69+
harness.scope,
70+
);
71+
72+
harness.setError("Owner assignment rejected.");
73+
harness.settle();
74+
await pending;
75+
76+
expect(harness.publishSessionMutationError).toHaveBeenCalledWith(
77+
harness.scope,
78+
"Owner assignment rejected.",
79+
);
80+
});
81+
82+
it("keeps a retired assignment rejection silent", async () => {
83+
const harness = createHarness();
84+
const pending = assignSessionOwner(
85+
harness.host,
86+
harness.session,
87+
{ type: "human", id: "profile-ada" },
88+
harness.scope,
89+
);
90+
91+
harness.setError("Retired assignment rejection.");
92+
harness.retire();
93+
harness.settle();
94+
await pending;
95+
96+
expect(harness.assignOwner).toHaveBeenCalledOnce();
97+
expect(harness.publishSessionMutationError).not.toHaveBeenCalled();
98+
});
99+
});
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
import { mkdir } from "node:fs/promises";
2+
import path from "node:path";
3+
import type { Page } from "playwright";
4+
import { expect as expectBrowser } from "playwright/test";
5+
import { expect, it } from "vitest";
6+
import { controlUiSessionUrl, installMockGateway } from "../test-helpers/control-ui-e2e.ts";
7+
import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts";
8+
9+
const suite = createControlUiE2eSuite({
10+
name: "Control UI session owner assignment mocked Gateway E2E",
11+
startServerBeforeBrowser: true,
12+
});
13+
const sessionKey = "agent:main:owner-outcome";
14+
const proofPhase = process.env.OPENCLAW_OWNER_ASSIGNMENT_PROOF_PHASE;
15+
const proofDir = path.resolve(".artifacts/control-ui-e2e/session-owner-assignment");
16+
17+
function sessionsListResponse() {
18+
return {
19+
count: 2,
20+
owners: [
21+
{ type: "human" as const, id: "profile-ada", label: "Ada" },
22+
{ type: "human" as const, id: "profile-bob", label: "Bob" },
23+
],
24+
defaults: { contextTokens: null, model: null, modelProvider: null },
25+
path: "",
26+
sessions: [
27+
{
28+
key: "agent:main:ada-research",
29+
kind: "direct",
30+
label: "Ada research",
31+
createdActor: { type: "human", id: "profile-ada", label: "Ada" },
32+
owner: { actor: { type: "human", id: "profile-ada", label: "Ada" } },
33+
updatedAt: 2,
34+
},
35+
{
36+
key: sessionKey,
37+
kind: "direct",
38+
label: "Owner outcome",
39+
createdActor: { type: "human", id: "profile-bob", label: "Bob" },
40+
owner: { actor: { type: "human", id: "profile-bob", label: "Bob" } },
41+
updatedAt: 1,
42+
},
43+
],
44+
ts: 1,
45+
};
46+
}
47+
48+
async function installOwnerGateway(page: Page) {
49+
const gateway = await installMockGateway(page, {
50+
featureMethods: ["chat.startup", "sessions.assignOwner"],
51+
historyMessages: [{ role: "assistant", content: "Owner assignment outcome proof." }],
52+
methodResponses: { "sessions.list": sessionsListResponse() },
53+
operatorScopes: ["operator.read", "operator.write"],
54+
presenceUsers: [{ self: true, id: "profile-ada", name: "Ada" }],
55+
sessionKey,
56+
});
57+
await page.goto(controlUiSessionUrl(suite.server.baseUrl, sessionKey));
58+
await page.getByText("Owner assignment outcome proof.", { exact: true }).waitFor();
59+
await gateway.deferNext("sessions.assignOwner");
60+
return gateway;
61+
}
62+
63+
async function expectAssignmentRequest(
64+
gateway: Awaited<ReturnType<typeof installOwnerGateway>>,
65+
): Promise<void> {
66+
const request = await gateway.waitForRequest("sessions.assignOwner");
67+
expect(request.params).toEqual({
68+
agentId: "main",
69+
key: sessionKey,
70+
owner: { type: "human", id: "profile-ada" },
71+
});
72+
}
73+
74+
async function captureProof(page: Page, surface: string): Promise<void> {
75+
if (!proofPhase) {
76+
return;
77+
}
78+
await mkdir(proofDir, { recursive: true });
79+
await page.screenshot({
80+
animations: "disabled",
81+
fullPage: true,
82+
path: path.join(proofDir, `${surface}-${proofPhase}.png`),
83+
});
84+
}
85+
86+
async function chooseAssignToMe(page: Page): Promise<void> {
87+
const action = page.locator('wa-dropdown-item[value="assign-owner:human:profile-ada"]:visible');
88+
await action.waitFor({ state: "visible" });
89+
await action.click();
90+
}
91+
92+
suite.define(() => {
93+
it("keeps a rejected header owner assignment visible", async () => {
94+
await suite.withPage(
95+
{
96+
colorScheme: "dark",
97+
locale: "en-US",
98+
serviceWorkers: "block",
99+
viewport: { height: 900, width: 1280 },
100+
},
101+
async ({ page }) => {
102+
const gateway = await installOwnerGateway(page);
103+
const activePane = page.locator("openclaw-chat-pane.chat-pane-cache__pane--active");
104+
const menuTrigger = activePane.getByRole("button", { name: "Actions for Owner outcome" });
105+
await menuTrigger.press("Enter");
106+
await chooseAssignToMe(page);
107+
await expectAssignmentRequest(gateway);
108+
109+
const message = "Owner assignment rejected for visible outcome proof.";
110+
await gateway.rejectDeferred("sessions.assignOwner", {
111+
code: "INVALID_REQUEST",
112+
message,
113+
});
114+
await captureProof(page, "header");
115+
116+
await expectBrowser(
117+
activePane.getByRole("alert").filter({ hasText: message }),
118+
).toBeVisible();
119+
await expectBrowser(
120+
activePane.getByRole("img", { name: "Created by Bob", exact: true }),
121+
).toHaveCount(1);
122+
},
123+
);
124+
});
125+
126+
it("keeps a rejected sidebar owner assignment visible", async () => {
127+
await suite.withPage(
128+
{
129+
locale: "en-US",
130+
serviceWorkers: "block",
131+
viewport: { height: 900, width: 1280 },
132+
},
133+
async ({ page }) => {
134+
const gateway = await installOwnerGateway(page);
135+
const row = page.locator(`[data-session-key="${sessionKey}"]`);
136+
await row.hover();
137+
await row
138+
.getByRole("button", { name: "Open session menu: Owner outcome", exact: true })
139+
.click();
140+
await chooseAssignToMe(page);
141+
await expectAssignmentRequest(gateway);
142+
143+
const message = "Sidebar owner assignment rejected for visible outcome proof.";
144+
await gateway.rejectDeferred("sessions.assignOwner", {
145+
code: "INVALID_REQUEST",
146+
message,
147+
});
148+
149+
await expectBrowser(page.getByRole("alert").filter({ hasText: message })).toBeVisible();
150+
await expectBrowser(
151+
row.getByRole("img", { name: "Created by Bob", exact: true }),
152+
).toHaveCount(1);
153+
},
154+
);
155+
});
156+
});

‎ui/src/pages/chat/chat-pane-session-menu.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
113113
};
114114
switch (action.kind) {
115115
case "assign-owner":
116-
await scope.sessions.assignOwner(row.key, action.owner, {
117-
agentId: parseAgentSessionKey(row.key)?.agentId ?? scope.selectedAgentId,
118-
});
116+
await operations.assignSessionOwner(host, session, action.owner, scope);
119117
break;
120118
case "fork":
121119
await operations.forkSession(host, session, scope);

0 commit comments

Comments
 (0)