Skip to content

Commit 75d90de

Browse files
committed
test: align session permission fixtures
1 parent 488b7a8 commit 75d90de

2 files changed

Lines changed: 83 additions & 4 deletions

File tree

‎ui/src/pages/chat/chat-pane.test.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,85 @@ describe("chat pane header state", () => {
180180
expect(patch).not.toHaveBeenCalled();
181181
});
182182

183+
it("refuses header rename when sessions.patch is unavailable or lacks write scope", () => {
184+
for (const hello of [
185+
{
186+
auth: { role: "operator", scopes: ["operator.write"] },
187+
features: { methods: ["sessions.create"] },
188+
},
189+
{
190+
auth: { role: "operator", scopes: ["operator.read"] },
191+
features: { methods: ["sessions.patch"] },
192+
},
193+
]) {
194+
const patch = vi.fn(async () => ({}));
195+
const sessions = { patch } as unknown as SessionCapability;
196+
const { pane, state, requestUpdate } = createTestChatPane({
197+
client: {} as GatewayBrowserClient,
198+
sessions,
199+
});
200+
pane.context.gateway.snapshot.hello =
201+
hello as ApplicationContext["gateway"]["snapshot"]["hello"];
202+
const session = {
203+
key: "agent:main:current",
204+
kind: "direct",
205+
updatedAt: 0,
206+
} satisfies GatewaySessionRow;
207+
208+
pane.beginHeaderRename(session);
209+
210+
expect(pane.headerEditing).toBe(false);
211+
expect(state.chatError).toBeTruthy();
212+
expect(requestUpdate).toHaveBeenCalledOnce();
213+
expect(patch).not.toHaveBeenCalled();
214+
}
215+
});
216+
217+
it("rechecks header rename access before committing", () => {
218+
const patch = vi.fn(async () => ({}));
219+
const sessions = { patch } as unknown as SessionCapability;
220+
const { pane, state } = createTestChatPane({
221+
client: {} as GatewayBrowserClient,
222+
sessions,
223+
});
224+
const session = {
225+
key: "agent:main:current",
226+
kind: "direct",
227+
updatedAt: 0,
228+
} satisfies GatewaySessionRow;
229+
230+
pane.beginHeaderRename(session);
231+
pane.headerRenameValue = "Blocked rename";
232+
pane.context.gateway.snapshot.hello = {
233+
auth: { role: "operator", scopes: ["operator.read"] },
234+
features: { methods: ["sessions.patch"] },
235+
} as ApplicationContext["gateway"]["snapshot"]["hello"];
236+
pane.commitHeaderRename();
237+
238+
expect(state.chatError).toBeTruthy();
239+
expect(patch).not.toHaveBeenCalled();
240+
});
241+
242+
it("refuses archived-session restore without exact sessions.patch access", async () => {
243+
const patch = vi.fn(async () => ({}));
244+
const sessions = { patch } as unknown as SessionCapability;
245+
const { pane, state, requestUpdate } = createTestChatPane({
246+
client: {} as GatewayBrowserClient,
247+
sessions,
248+
});
249+
pane.context.gateway.snapshot.hello = {
250+
auth: { role: "operator", scopes: ["operator.read"] },
251+
features: { methods: ["sessions.patch"] },
252+
} as ApplicationContext["gateway"]["snapshot"]["hello"];
253+
254+
await pane.restoreArchivedSession(state.sessionKey);
255+
256+
expect(state.chatError).toBeTruthy();
257+
expect(state.lastError).toBe(state.chatError);
258+
expect(requestUpdate).toHaveBeenCalledOnce();
259+
expect(patch).not.toHaveBeenCalled();
260+
});
261+
183262
it("copies the resolved workspace path and branch", async () => {
184263
const { pane } = createTestChatPane({
185264
client: {} as GatewayBrowserClient,

‎ui/src/pages/chat/components/chat-session-sharing.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe("chat session sharing menu", () => {
145145
loading: false,
146146
result: {
147147
sessionKey: "agent:main:main",
148-
members: [{ identityId: "alice", addedAt: 1 }],
148+
members: [{ identityId: "alice", addedBy: "owner", addedAt: 1 }],
149149
identities: [
150150
{ type: "human", id: "alice", label: "Alice" },
151151
{ type: "human", id: "bob", label: "Bob" },
@@ -164,9 +164,9 @@ describe("chat session sharing menu", () => {
164164
);
165165
const dropdown = root.querySelector("wa-dropdown");
166166
expect(dropdown).not.toBeNull();
167-
expect(root.querySelector('wa-dropdown-item[value="visibility:read-only"]')?.title).toBe(
168-
"Requires write",
169-
);
167+
expect(
168+
root.querySelector<HTMLElement>('wa-dropdown-item[value="visibility:read-only"]')?.title,
169+
).toBe("Requires write");
170170
expect(
171171
root.querySelector('wa-dropdown-item[value="member:alice"]')?.hasAttribute("disabled"),
172172
).toBe(true);

0 commit comments

Comments
 (0)