Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion e2e/console/render-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ const holders = [
"claude-code:3f2a9c1e-7b44-4d0e-a2f1-0c9d8e7f91c4",
];

function lease(index: number, requesterId = holders[index]) {
function lease(
index: number,
requesterId = holders[index],
): Record<string, unknown> & {
readonly ttlDeadline: number;
} {
return {
id: `lse_${index + 1}`,
deviceId: `dev_${index + 1}`,
Expand Down Expand Up @@ -168,6 +173,9 @@ function leasesBody(scenario: Scenario, onOverview: boolean): unknown {
if (record !== undefined) records[index] = { ...record, ttlDeadline: NOW + left };
}
}
const [oldest, third] = [13, 11].map((index) => records[index]);
if (oldest !== undefined) records[13] = { ...oldest, label: "feature-checkout-flow" };
if (third !== undefined) records[11] = { ...third, label: "fix-push-retries" };
return { leases: scenario === "long" ? [lease(0, "x".repeat(256))] : records };
}

Expand Down
11 changes: 9 additions & 2 deletions ui/src/model/leases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export interface LeaseRowView {
readonly model: string;
readonly worker?: string;
readonly sub: string;
// why: the side list's second line leads with the label, the table's device title does not.
readonly listSub: string;
readonly label?: string;
// why: the OS the device runs, as the table's second line names it ("iOS 18.4").
readonly runtime?: string;
readonly platform?: string;
Expand Down Expand Up @@ -164,8 +167,10 @@ export function leaseRows(input: {
remaining: formatCountdown(lease.ttlDeadline - now),
remainingMs: lease.ttlDeadline - now,
renewedAgo: `${formatAgo(now - lease.lastRenewedAt)}`,
listSub: [lease.label, sub].filter((part) => part !== undefined).join(" · "),
sub,
to: leasePath(lease.id),
...(lease.label === undefined ? {} : { label: lease.label }),
...(worker === undefined ? {} : { worker }),
...(device === undefined ? {} : { platform: device.spec.platform }),
...runtimeOf(device),
Expand Down Expand Up @@ -199,7 +204,7 @@ export function searchLeaseRows(
const wanted = query.toLowerCase();
if (wanted === "") return rows;
return rows.filter((row) =>
[row.holder, row.model, row.worker, row.id].some((field) =>
[row.holder, row.label, row.model, row.worker, row.id].some((field) =>
field?.toLowerCase().includes(wanted),
),
);
Expand Down Expand Up @@ -232,6 +237,7 @@ export interface LeaseInspection {
readonly udid: string;
};
readonly holder?: Holder;
readonly label?: string;
readonly ownerId?: string;
readonly requestId?: string;
}
Expand Down Expand Up @@ -303,13 +309,14 @@ function recordFacts(
id: string,
): Pick<
LeaseInspection,
"renewed" | "title" | "kind" | "percent" | "holder" | "ownerId" | "ttl" | "token"
"renewed" | "title" | "kind" | "percent" | "holder" | "label" | "ownerId" | "ttl" | "token"
> {
if (record === undefined) return { kind: "unknown", renewed: "—", title: id };
const holder = holderOf(record.requesterId, tokens);
return {
holder,
kind: agentKind(record.requesterId),
...(record.label === undefined ? {} : { label: record.label }),
percent: percentLeft(deadline, now, record.ttlMs),
token: record.ownerId,
ttl: formatDuration(record.ttlMs),
Expand Down
20 changes: 20 additions & 0 deletions ui/src/model/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ describe("the search results", () => {
});
});

describe("a labelled lease in the search", () => {
it("reads `<label> · <holder> · <model>` and is found by its label", () => {
const labelled = { ...LEASE, label: "feature-x" } as LeaseRecord;
const workers = [worker("wrk_2", "mac-studio-2", { devices: [PHONE] })];
const results = buildResults({
leases: leaseRows({ leases: [labelled], now: NOW, tokens: [], workers }),
mode: "gateway",
pages: PAGES,
requests: [],
workers,
});
const found = (typed: string) =>
searchGroups(results, typed)
.filter((group) => group.name === "Leases")
.flatMap((group) => group.results.map((result) => result.label));
expect(found("feature")).toEqual(["feature-x · agent-1 · iPhone 17 Pro"]);
expect(found("feature-x")).toEqual(["feature-x · agent-1 · iPhone 17 Pro"]);
});
});

describe("the update actions in the search", () => {
it("offers Update… for a worker behind the latest and Update now for one that waits, as its menu does", () => {
const behind = worker("wrk_2", "mac-studio-2", { latestVersion: "0.4.0", version: "0.3.0" });
Expand Down
4 changes: 3 additions & 1 deletion ui/src/model/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export function buildResults(input: SearchInput): readonly SearchResult[] {
...input.leases.map((lease): SearchResult => ({
group: "Leases",
id: `lease:${lease.key}`,
label: `${lease.holder} · ${lease.model}`,
label: [lease.label, lease.holder, lease.model]
.filter((part) => part !== undefined)
.join(" · "),
target: { kind: "go", to: lease.to as `/${string}` },
})),
...input.requests.map((request): SearchResult => ({
Expand Down
15 changes: 11 additions & 4 deletions ui/src/screens/leases/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function LeasesScreen() {
/>
<SearchField
label="Search leases"
placeholder="Filter by holder, device, worker"
placeholder="Filter by holder, label, device, worker"
className="lease-search"
value={query}
onChange={search}
Expand Down Expand Up @@ -92,9 +92,16 @@ const COLUMNS: readonly Column<LeaseRowView>[] = [
cell: (row) => (
<span className="lease-holder">
<AgentChip kind={row.holderKind} />
<Link to={row.to} title={row.holderTitle}>
{row.holderDisplay}
</Link>
<span className="lease-holder-text">
{row.label === undefined ? null : (
<span className="lease-ellipsis lease-holder-label" title={row.label}>
{row.label}
</span>
)}
<Link to={row.to} title={row.holderTitle}>
{row.holderDisplay}
</Link>
</span>
</span>
),
header: "Held by",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/screens/leases/inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ export function LeaseFacts({ lease }: { readonly lease: LeaseInspection }) {
),
},
{ label: "Granted", value: `${lease.heldFor} ago · ${lease.granted}` },
...(lease.label === undefined
? []
: [{ label: "Label", value: <span className="lease-id">{lease.label}</span> }]),
...(lease.holder?.label === undefined
? []
: [{ label: "Holder", value: <span className="mono lease-id">{lease.holder.id}</span> }]),
Expand Down
11 changes: 11 additions & 0 deletions ui/src/screens/leases/leases.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@
min-width: 0;
}

.lease-holder-text {
display: flex;
flex-direction: column;
min-width: 0;
}

.lease-holder-label {
color: var(--text-muted);
font-size: 11.5px;
}

.lease-holder a {
overflow: hidden;
color: var(--text);
Expand Down
57 changes: 57 additions & 0 deletions ui/src/screens/leases/leases.dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,63 @@ describe("the leases page", () => {
expect(tableRow(/ci-runner-3/)).not.toHaveTextContent("tok_ci");
});

it("a labelled lease shows its label in the Held by cell, the side list and the drawer, the page filter finds it, a long label is cut with the whole label in title, and an unlabelled lease reads as today", async () => {
const longLabel = "a-very-long-feature-label-that-would-not-fit-on-one-line-of-the-cell-x";
const { user } = renderConsole({
path: "/leases",
routes: {
...hostWith([
lease({
id: "lse_labelled",
label: "feature-x",
requesterId: "agent-labelled",
ttlDeadline: NOW + 120_000,
}),
lease({
deviceId: "dev_2",
id: "lse_long",
label: longLabel,
requesterId: "agent-long",
}),
lease({
deviceId: "dev_3",
id: "lse_plain",
requesterId: "agent-plain",
ttlDeadline: NOW + 180_000,
}),
]),
...detailsOf(leaseDetails({ id: "lse_labelled" })),
},
});
expect(await screen.findByRole("link", { name: "agent-labelled" })).toBeVisible();

const labelled = tableRow(/agent-labelled/);
const cell = within(labelled).getByText("feature-x");
expect(cell).toHaveAttribute("title", "feature-x");
expect(cell.nextElementSibling).toHaveTextContent("agent-labelled");
const long = within(tableRow(/agent-long/)).getByText(longLabel);
expect(long).toHaveAttribute("title", longLabel);
expect(long).toHaveClass("lease-ellipsis");
expect(tableRow(/agent-plain/)).not.toHaveTextContent("feature-x");
expect(tableRow(/agent-plain/).querySelector(".lease-holder-label")).toBeNull();
const subs = [...leaseSummary().querySelectorAll(".lease-list-sub")].map(
(el) => el.textContent,
);
expect(subs.filter((text) => text?.startsWith("renewed") !== true)).toEqual([
"feature-x · iPhone 16 · mac-studio-01",
"dev_3 · mac-studio-01",
]);
expect(within(leaseSummary()).getByText(/^feature-x · iPhone 16/)).toBeVisible();

await user.type(screen.getByRole("searchbox", { name: "Search leases" }), "feature-x");
expect(screen.getAllByRole("row")).toHaveLength(1 + 1);
expect(tableRow(/agent-labelled/)).toBeVisible();

await user.click(tableRow(/agent-labelled/));
expect(await within(leasePane()).findByText("lse_labelled")).toBeVisible();
expect(fact(leasePane(), "Label")).toHaveTextContent("feature-x");
});

it("a lease row opens its inspector beside the table at the lease's address", async () => {
const { user } = renderConsole({
path: "/leases",
Expand Down
1 change: 1 addition & 0 deletions ui/src/screens/leases/leases.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function row(overrides: Partial<LeaseRowView> = {}): LeaseRowView {
renewedAgo: "30 s ago",
runtime: "iOS 18.4",
worker: "mac-mini-1",
listSub: "iPhone 16 · mac-mini-1",
sub: "iPhone 16 · mac-mini-1",
to: "/leases/lse_1/",
...overrides,
Expand Down
4 changes: 2 additions & 2 deletions ui/src/screens/leases/summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export function LeaseSummaryPane({ summary }: { readonly summary: LeaseSummary }
<div className="mono lease-ellipsis" title={row.holderTitle}>
{row.holderDisplay}
</div>
<div className="muted lease-ellipsis lease-list-sub" title={row.sub}>
{row.sub}
<div className="muted lease-ellipsis lease-list-sub" title={row.listSub}>
{row.listSub}
</div>
</div>
<Countdown row={row} />
Expand Down
2 changes: 1 addition & 1 deletion website/src/content/docs/docs/worker/console.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ While the daemon is still starting, devices, capacity and the warm pool are left

## Leases

**Leases** lists every lease on the worker, the same leases `simlock list --leases` shows. Each row has the holder (**Held by**), the device and its runtime, the worker, and the time left (**Expires in**) as a countdown with a bar. A lease with less than 5 minutes left turns amber. **Ending < 5 min**, **iOS** and **Android** narrow the list, and the box beside them searches by holder, device and worker. Under the table, a line counts the rows shown; a list longer than one page gets a pager.
**Leases** lists every lease on the worker, the same leases `simlock list --leases` shows. Each row has the holder (**Held by**), with the lease's label above it when the lease has one (see `simlock lease --label`), the device and its runtime, the worker, and the time left (**Expires in**) as a countdown with a bar. A lease with less than 5 minutes left turns amber. **Ending < 5 min**, **iOS** and **Android** narrow the list, and the box beside them searches by holder, label, device and worker. The search (⌘K) finds a lease by its label too, and shows it as `<label> · <holder> · <device>`. The lease's pane lists the label as **Label**. Under the table, a line counts the rows shown; a list longer than one page gets a pager.

The holder is the identity that took the lease. A lease taken over the HTTP API shows the label of the token that took it, so give each agent's token a label:

Expand Down
Loading