Skip to content

Commit 8003a5b

Browse files
committed
test(ui): split child-session cap cases under the max-lines budget
1 parent da2d9ac commit 8003a5b

3 files changed

Lines changed: 142 additions & 134 deletions

File tree

‎ui/src/components/app-sidebar.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import "../test-helpers/app-sidebar-cases/catalog-live-events.ts";
88
import "../test-helpers/app-sidebar-cases/catalog-live.ts";
99
import "../test-helpers/app-sidebar-cases/catalog-live-state.ts";
1010
import "../test-helpers/app-sidebar-cases/catalog-pages.ts";
11+
import "../test-helpers/app-sidebar-cases/child-sessions-cap.ts";
1112
import "../test-helpers/app-sidebar-cases/child-sessions.ts";
1213
import "../test-helpers/app-sidebar-cases/group-mutations.ts";
1314
import "../test-helpers/app-sidebar-cases/interactions.ts";
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { GatewayBrowserClient } from "../../api/gateway.ts";
3+
import { createGateway, createSessionsHarness, mountSidebar } from "../app-sidebar.ts";
4+
import { waitForFast } from "../wait-for.ts";
5+
import "../../components/app-sidebar.ts";
6+
7+
describe("AppSidebar child session cap", () => {
8+
it("caps visible children until requested and resets the cap after collapse", async () => {
9+
const gateway = createGateway({} as GatewayBrowserClient);
10+
const childKeys = Array.from(
11+
{ length: 6 },
12+
(_, index) => `agent:main:subagent:child-${index + 1}`,
13+
);
14+
const harness = createSessionsHarness("main", ["agent:main:parent"]);
15+
harness.list.mockResolvedValue({
16+
ts: 100_000,
17+
path: "",
18+
count: childKeys.length,
19+
defaults: { modelProvider: null, model: null, contextTokens: null },
20+
sessions: childKeys.map((key, index) => ({
21+
key,
22+
spawnedBy: "agent:main:parent",
23+
kind: "direct" as const,
24+
label: `Subagent: Child ${index + 1}`,
25+
updatedAt: index + 1,
26+
})),
27+
});
28+
const { sidebar } = await mountSidebar(gateway, harness.sessions);
29+
harness.publishList({
30+
result: {
31+
ts: 2,
32+
path: "",
33+
count: 1,
34+
defaults: { modelProvider: null, model: null, contextTokens: null },
35+
sessions: [
36+
{
37+
key: "agent:main:parent",
38+
kind: "direct",
39+
label: "Parent task",
40+
updatedAt: 1,
41+
childSessions: childKeys,
42+
},
43+
],
44+
},
45+
});
46+
await sidebar.updateComplete;
47+
48+
const toggle = sidebar.querySelector<HTMLButtonElement>("[data-child-session-toggle]");
49+
toggle?.click();
50+
await waitForFast(() =>
51+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(4),
52+
);
53+
const showMore = sidebar.querySelector<HTMLButtonElement>("[data-show-more-children]");
54+
expect(showMore?.textContent?.trim()).toBe("Show 2 more");
55+
expect(showMore?.getAttribute("aria-label")).toBe("Show 2 more");
56+
expect(sidebar.textContent).not.toContain("Subagent:");
57+
58+
showMore?.click();
59+
await waitForFast(() =>
60+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(6),
61+
);
62+
expect(sidebar.querySelector("[data-show-more-children]")).toBeNull();
63+
64+
toggle?.click();
65+
await sidebar.updateComplete;
66+
toggle?.click();
67+
await waitForFast(() =>
68+
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(4),
69+
);
70+
expect(sidebar.querySelector("[data-show-more-children]")?.textContent).toContain(
71+
"Show 2 more",
72+
);
73+
});
74+
75+
it("keeps live children visible past the cap", async () => {
76+
const gateway = createGateway({} as GatewayBrowserClient);
77+
const childKeys = Array.from(
78+
{ length: 6 },
79+
(_, index) => `agent:main:subagent:child-${index + 1}`,
80+
);
81+
const harness = createSessionsHarness("main", ["agent:main:parent"]);
82+
harness.list.mockResolvedValue({
83+
ts: 100_000,
84+
path: "",
85+
count: childKeys.length,
86+
defaults: { modelProvider: null, model: null, contextTokens: null },
87+
sessions: [
88+
...childKeys.map((key, index) => ({
89+
key,
90+
spawnedBy: "agent:main:parent",
91+
kind: "direct" as const,
92+
label: `Subagent: Child ${index + 1}`,
93+
updatedAt: index + 1,
94+
})),
95+
// Quiet child beyond the cap with a RUNNING grandchild: the branch
96+
// must bypass the cap via the transitive runningChildCount.
97+
{
98+
key: "agent:main:subagent:grandchild",
99+
spawnedBy: "agent:main:subagent:child-6",
100+
kind: "direct" as const,
101+
label: "Subagent: Grandchild run",
102+
updatedAt: 10,
103+
status: "running" as const,
104+
hasActiveRun: true,
105+
},
106+
],
107+
});
108+
const { sidebar } = await mountSidebar(gateway, harness.sessions);
109+
harness.publishList({
110+
result: {
111+
ts: 2,
112+
path: "",
113+
count: 1,
114+
defaults: { modelProvider: null, model: null, contextTokens: null },
115+
sessions: [
116+
{
117+
key: "agent:main:parent",
118+
kind: "direct",
119+
label: "Parent task",
120+
updatedAt: 1,
121+
childSessions: childKeys,
122+
},
123+
],
124+
},
125+
});
126+
await sidebar.updateComplete;
127+
128+
sidebar
129+
.querySelector<HTMLButtonElement>('[data-child-session-toggle="agent:main:parent"]')
130+
?.click();
131+
await waitForFast(() =>
132+
expect(
133+
sidebar.querySelector('[data-session-key="agent:main:subagent:child-6"]'),
134+
).not.toBeNull(),
135+
);
136+
expect(sidebar.querySelector('[data-session-key="agent:main:subagent:child-5"]')).toBeNull();
137+
expect(sidebar.querySelector("[data-show-more-children]")?.textContent?.trim()).toBe(
138+
"Show 1 more",
139+
);
140+
});
141+
});

‎ui/src/test-helpers/app-sidebar-cases/child-sessions.ts‎

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -12,140 +12,6 @@ import { waitForFast } from "../wait-for.ts";
1212
import "../../components/app-sidebar.ts";
1313

1414
describe("AppSidebar agent chip", () => {
15-
it("caps visible children until requested and resets the cap after collapse", async () => {
16-
const gateway = createGateway({} as GatewayBrowserClient);
17-
const childKeys = Array.from(
18-
{ length: 6 },
19-
(_, index) => `agent:main:subagent:child-${index + 1}`,
20-
);
21-
const harness = createSessionsHarness("main", ["agent:main:parent"]);
22-
harness.list.mockResolvedValue({
23-
ts: 100_000,
24-
path: "",
25-
count: childKeys.length,
26-
defaults: { modelProvider: null, model: null, contextTokens: null },
27-
sessions: childKeys.map((key, index) => ({
28-
key,
29-
spawnedBy: "agent:main:parent",
30-
kind: "direct" as const,
31-
label: `Subagent: Child ${index + 1}`,
32-
updatedAt: index + 1,
33-
})),
34-
});
35-
const { sidebar } = await mountSidebar(gateway, harness.sessions);
36-
harness.publishList({
37-
result: {
38-
ts: 2,
39-
path: "",
40-
count: 1,
41-
defaults: { modelProvider: null, model: null, contextTokens: null },
42-
sessions: [
43-
{
44-
key: "agent:main:parent",
45-
kind: "direct",
46-
label: "Parent task",
47-
updatedAt: 1,
48-
childSessions: childKeys,
49-
},
50-
],
51-
},
52-
});
53-
await sidebar.updateComplete;
54-
55-
const toggle = sidebar.querySelector<HTMLButtonElement>("[data-child-session-toggle]");
56-
toggle?.click();
57-
await waitForFast(() =>
58-
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(4),
59-
);
60-
const showMore = sidebar.querySelector<HTMLButtonElement>("[data-show-more-children]");
61-
expect(showMore?.textContent?.trim()).toBe("Show 2 more");
62-
expect(showMore?.getAttribute("aria-label")).toBe("Show 2 more");
63-
expect(sidebar.textContent).not.toContain("Subagent:");
64-
65-
showMore?.click();
66-
await waitForFast(() =>
67-
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(6),
68-
);
69-
expect(sidebar.querySelector("[data-show-more-children]")).toBeNull();
70-
71-
toggle?.click();
72-
await sidebar.updateComplete;
73-
toggle?.click();
74-
await waitForFast(() =>
75-
expect(sidebar.querySelectorAll(".sidebar-recent-session--child")).toHaveLength(4),
76-
);
77-
expect(sidebar.querySelector("[data-show-more-children]")?.textContent).toContain(
78-
"Show 2 more",
79-
);
80-
});
81-
82-
it("keeps live children visible past the cap", async () => {
83-
const gateway = createGateway({} as GatewayBrowserClient);
84-
const childKeys = Array.from(
85-
{ length: 6 },
86-
(_, index) => `agent:main:subagent:child-${index + 1}`,
87-
);
88-
const harness = createSessionsHarness("main", ["agent:main:parent"]);
89-
harness.list.mockResolvedValue({
90-
ts: 100_000,
91-
path: "",
92-
count: childKeys.length,
93-
defaults: { modelProvider: null, model: null, contextTokens: null },
94-
sessions: [
95-
...childKeys.map((key, index) => ({
96-
key,
97-
spawnedBy: "agent:main:parent",
98-
kind: "direct" as const,
99-
label: `Subagent: Child ${index + 1}`,
100-
updatedAt: index + 1,
101-
})),
102-
// Quiet child beyond the cap with a RUNNING grandchild: the branch
103-
// must bypass the cap via the transitive runningChildCount.
104-
{
105-
key: "agent:main:subagent:grandchild",
106-
spawnedBy: "agent:main:subagent:child-6",
107-
kind: "direct" as const,
108-
label: "Subagent: Grandchild run",
109-
updatedAt: 10,
110-
status: "running" as const,
111-
hasActiveRun: true,
112-
},
113-
],
114-
});
115-
const { sidebar } = await mountSidebar(gateway, harness.sessions);
116-
harness.publishList({
117-
result: {
118-
ts: 2,
119-
path: "",
120-
count: 1,
121-
defaults: { modelProvider: null, model: null, contextTokens: null },
122-
sessions: [
123-
{
124-
key: "agent:main:parent",
125-
kind: "direct",
126-
label: "Parent task",
127-
updatedAt: 1,
128-
childSessions: childKeys,
129-
},
130-
],
131-
},
132-
});
133-
await sidebar.updateComplete;
134-
135-
sidebar
136-
.querySelector<HTMLButtonElement>('[data-child-session-toggle="agent:main:parent"]')
137-
?.click();
138-
await waitForFast(() =>
139-
expect(
140-
sidebar.querySelector('[data-session-key="agent:main:subagent:child-6"]'),
141-
).not.toBeNull(),
142-
);
143-
expect(sidebar.querySelector('[data-session-key="agent:main:subagent:child-5"]')).toBeNull();
144-
expect(sidebar.querySelector("[data-show-more-children]")?.textContent?.trim()).toBe(
145-
"Show 1 more",
146-
);
147-
});
148-
14915
it("loads and expands child sessions inline without root session controls", async () => {
15016
const gateway = createGateway({} as GatewayBrowserClient);
15117
const harness = createSessionsHarness("main", ["agent:main:parent"]);

0 commit comments

Comments
 (0)