Skip to content

Commit be19487

Browse files
johnmatthewtennantPoppyclaude
committed
fix(attention): confirm deleting an Interest with only skipped watches
The confirmation counted only readable watches, so deleting an Interest whose remaining watches were skipped removed them without asking. Signed-off-by: John Tennant <[email protected]> Co-authored-by: Poppy <ace4dfe51b23bb4244ab9117dfd5e13b8239445e333225608c352e68cb3fe2b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a2199a6 commit be19487

2 files changed

Lines changed: 66 additions & 7 deletions

File tree

‎src/bundled/watching/Tab.test.tsx‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,16 @@ it.each(["source", "event", "timer"] as const)(
410410
});
411411
fireEvent.click(removeInterest);
412412
fireEvent.click(screen.getByRole("menuitem", { name: "Delete" }));
413+
// Its skipped watch is deleted with it, so this still confirms.
414+
fireEvent.click(screen.getByRole("button", { name: "Delete" }));
413415
await waitFor(() =>
414416
expect(screen.getByRole("alert").textContent).toBe(
415417
"Interest save failed",
416418
),
417419
);
418420
expect(agent.attention["interest/release"]).toBeTruthy();
419421
rejectInterest = false;
420-
fireEvent.click(screen.getByRole("menuitem", { name: "Delete" }));
422+
fireEvent.click(screen.getByRole("button", { name: "Delete" }));
421423
await waitFor(() =>
422424
expect(screen.getByRole("heading", { name: "Attention" })).toBeTruthy(),
423425
);
@@ -1575,3 +1577,55 @@ it("does not repeat consecutive sonar messages across sweeps", () => {
15751577
random.mockRestore();
15761578
}
15771579
});
1580+
1581+
it("confirms deleting an Interest whose only watch was skipped", () => {
1582+
const agent = {
1583+
key: "membership-a",
1584+
pubkey: "a",
1585+
owner: viewer,
1586+
relay: "wss://example.com",
1587+
name: "Ada",
1588+
attentionEnabled: true,
1589+
timers: {},
1590+
attention: {
1591+
"interest/release": {
1592+
slug: "interest/release",
1593+
modifiedAt: 1,
1594+
value: { type: "interest", instructions: "Keep releases moving." },
1595+
},
1596+
},
1597+
skipped: {
1598+
"watch/over": {
1599+
slug: "watch/over",
1600+
modifiedAt: 1,
1601+
value: { type: "event", interest_id: "release", enabled: true },
1602+
problem: "Over the limit of 100 watches and timers",
1603+
},
1604+
},
1605+
};
1606+
const save = vi.fn(async () => {});
1607+
const snapshot = { status: "ready", running: [agent] };
1608+
const disconnected = { status: "disconnected", ...community };
1609+
const ctx = {
1610+
react: React,
1611+
agents: {
1612+
presentWatch: () => undefined,
1613+
snapshot: () => snapshot,
1614+
subscribe: () => () => {},
1615+
save,
1616+
},
1617+
relay: {
1618+
snapshot: () => disconnected,
1619+
subscribe: () => () => {},
1620+
},
1621+
} as unknown as Context;
1622+
render(
1623+
React.createElement(createTab(ctx), { agent: { key: "membership-a" } }),
1624+
);
1625+
fireEvent.click(
1626+
screen.getByRole("button", { name: "Interest status for release" }),
1627+
);
1628+
fireEvent.click(screen.getByRole("menuitem", { name: "Delete" }));
1629+
expect(screen.getByRole("alertdialog")).toBeTruthy();
1630+
expect(save).not.toHaveBeenCalled();
1631+
});

‎src/bundled/watching/Tab.tsx‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export { heading, describe } from "./presentation";
2525
import "./AttentionPage.css";
2626

2727
const button = { variant: "ghost" as const, size: "sm" as const };
28+
/** The watches of an Interest that this app skipped, such as ones over the
29+
* limit. They still belong to it. */
30+
const skippedWatches = (agent: Agent, id: string) =>
31+
Object.values(agent.skipped ?? {}).filter(
32+
(object) =>
33+
(object.value as { interest_id?: unknown } | null)?.interest_id === id,
34+
);
2835
/** Uses the host’s controls and surface roles. */
2936
export function createAttentionComponents({
3037
agents,
@@ -91,11 +98,7 @@ export function createAttentionComponents({
9198
);
9299
// A watch skipped here, such as one over the limit, still belongs to
93100
// this Interest and could run once there is room for it.
94-
const skipped = Object.values(agent.skipped ?? {}).filter(
95-
(object) =>
96-
(object.value as { interest_id?: unknown } | null)?.interest_id ===
97-
id,
98-
);
101+
const skipped = skippedWatches(agent, id);
99102
await agents.save(agent.key, {
100103
attentionExpected: Object.fromEntries([
101104
...watches.map((watch) => [watch.slug, watch]),
@@ -260,7 +263,9 @@ export function createAttentionComponents({
260263
agent={agent}
261264
slug={object.slug}
262265
label={label}
263-
hasWatches={subscriptions.length > 0}
266+
hasWatches={
267+
subscriptions.length > 0 || skippedWatches(agent, id).length > 0
268+
}
264269
returnFocus={returnFocus}
265270
/>
266271
</div>

0 commit comments

Comments
 (0)