diff --git a/api/openapi.yaml b/api/openapi.yaml index e7279feb85..6b3ed60cbb 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -23950,6 +23950,9 @@ components: - 'null' format: date-time description: When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on. + canTryAgain: + type: boolean + description: Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true. workingSince: type: - string diff --git a/api/openapi/conversations.yaml b/api/openapi/conversations.yaml index 42247c3c9e..e9696f26f9 100644 --- a/api/openapi/conversations.yaml +++ b/api/openapi/conversations.yaml @@ -2451,6 +2451,9 @@ components: - 'null' format: date-time description: When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on. + canTryAgain: + type: boolean + description: Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true. workingSince: type: - string diff --git a/app/src/components/tasks/task-row.tsx b/app/src/components/tasks/task-row.tsx index ad2e6ae97a..e788a71e0f 100644 --- a/app/src/components/tasks/task-row.tsx +++ b/app/src/components/tasks/task-row.tsx @@ -27,9 +27,12 @@ import { tryTaskAgainMutationOptions, } from "@/lib/tasks/mutations"; import { + canTryAgain, couldNotFinish, + failureSentence, stoppedByYou, TASK_DONE_LABEL, + TASK_FAILED_LABEL, TASK_STATUS_LABEL, TASK_STOPPED, TASK_STOPPED_LABEL, @@ -112,6 +115,23 @@ function nextLine(listed: ListedTask): string | null { return status === "working" ? "Just started." : null; } +/** + * A task's status and line on the Needs you board. One that couldn't finish says so in its card's + * words, Couldn't finish, and its line is why, said once: the board read "Failed" beside a card + * that said "Couldn't finish", and "Couldn't finish: …" beside "Failed". + */ +function boardStatus( + listed: ListedTask, + settled = false, +): { label: string; line: string | null } { + if (listed.status === "failed" && !stopped(listed)) + return { + label: TASK_FAILED_LABEL, + line: listed.task.failure ? failureSentence(listed.task.failure) : null, + }; + return { label: statusLabel(listed, settled), line: nextLine(listed) }; +} + /** * Whether a row offers Mark done: only where it does something. Not while the task is working: * there is nothing finished to mark, and its conversation would carry on behind a row that said it @@ -210,7 +230,7 @@ export function TaskRow({ ) : null} - {status === "failed" ? ( + {canTryAgain({ ...task, status }) ? ( } - detail={nextLine(listed)} + detail={said.line} // What a waiting task waits for is what the person has to answer: read in full, never cut. readDetail={status === "needs_input"} icon={} meta={[ - {statusLabel(listed, settled)}, + {said.label}, {relativeTime(task.updatedAt)}, error ? ( diff --git a/app/src/components/tasks/task-thread.tsx b/app/src/components/tasks/task-thread.tsx index 748a22372d..9c6e0e762c 100644 --- a/app/src/components/tasks/task-thread.tsx +++ b/app/src/components/tasks/task-thread.tsx @@ -24,6 +24,7 @@ import { reactionsQueryOptions, stoppedByYou, TASK_DONE_LABEL, + TASK_FAILED_LABEL, TASK_STOPPED, TASK_STOPPED_LABEL, type TaskStatus, @@ -85,7 +86,7 @@ const STATE: Record< text: "text-emerald-700 dark:text-emerald-400", }, failed: { - label: "Couldn't finish", + label: TASK_FAILED_LABEL, icon: IconAlertTriangle, dot: "bg-destructive", text: "text-destructive", @@ -276,18 +277,16 @@ export function TaskCard({ ); /* * What it waits for is said once, on the needs-you line the task posts, not here as well: the - * card says only that it needs the person, and leads into the thread. + * card says only that it needs the person, and leads into the thread. Why it couldn't finish is + * said once too, on the line it reports under the card, which also says what to do about it: the + * card said the same reason a second time just above it. */ const next = - state === "failed" - ? task.data?.failure - ? failureSentence(task.data.failure) - : null - : state === "stopped" - ? TASK_STOPPED - : state === "working" && !taskId - ? "Starting…" - : null; + state === "stopped" + ? TASK_STOPPED + : state === "working" && !taskId + ? "Starting…" + : null; return ( @@ -431,13 +444,23 @@ export function TaskReport({ "size-3.5 shrink-0", waiting ? STATE.needs.text - : "text-emerald-600 dark:text-emerald-400", + : failedSince + ? STATE.failed.text + : "text-emerald-600 dark:text-emerald-400", )} /> {title ?? "Task"} ) : null} + {reason ? ( +

+ + {TASK_FAILED_LABEL} + + · {reason} +

+ ) : null} {children} ); @@ -515,13 +538,17 @@ export function TaskReport({ ); } -/** What a needs-you line says once the person has answered, by where the task is now. */ +/** + * What a needs-you line says once the person has answered, by where the task is now. Never where + * they answered: the thread, the Bots page's Needs you board and the inbox all answer it, and the + * line can't tell which. + */ const ANSWERED: Record = { - working: "You answered this in its thread. It's carrying on.", - needs: "You answered this in its thread. It needs you again there.", - done: "You answered this in its thread, and it's done.", - failed: "You answered this in its thread, but it couldn't finish.", - stopped: "You answered this in its thread, and stopped it after.", + working: "You answered this. It's carrying on.", + needs: "You answered this. It needs you again in its thread.", + done: "You answered this, and it's done.", + failed: "You answered this, but it couldn't finish.", + stopped: "You answered this, and stopped it after.", }; /** diff --git a/app/src/lib/api/generated/model/task.ts b/app/src/lib/api/generated/model/task.ts index 265dcc15af..a4e8d92663 100644 --- a/app/src/lib/api/generated/model/task.ts +++ b/app/src/lib/api/generated/model/task.ts @@ -65,6 +65,8 @@ export interface Task { * @nullable */ stoppedAt?: string | null; + /** Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true. */ + canTryAgain?: boolean; /** * When the work it is doing now began. Null or absent unless it is working. * @nullable diff --git a/app/src/lib/api/generated/tasks/tasks.zod.ts b/app/src/lib/api/generated/tasks/tasks.zod.ts index bbf10c8ebc..59689ef629 100644 --- a/app/src/lib/api/generated/tasks/tasks.zod.ts +++ b/app/src/lib/api/generated/tasks/tasks.zod.ts @@ -111,6 +111,12 @@ export const ListTasksResponse = zod.object({ .describe( "When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.", ), + canTryAgain: zod + .boolean() + .optional() + .describe( + "Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.", + ), workingSince: zod.iso .datetime({ offset: true }) .nullish() @@ -265,6 +271,12 @@ export const GetTaskResponse = zod.object({ .describe( "When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.", ), + canTryAgain: zod + .boolean() + .optional() + .describe( + "Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.", + ), workingSince: zod.iso .datetime({ offset: true }) .nullish() @@ -422,6 +434,12 @@ export const ResolveTaskResponse = zod.object({ .describe( "When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.", ), + canTryAgain: zod + .boolean() + .optional() + .describe( + "Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.", + ), workingSince: zod.iso .datetime({ offset: true }) .nullish() @@ -579,6 +597,12 @@ export const ReopenTaskResponse = zod.object({ .describe( "When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.", ), + canTryAgain: zod + .boolean() + .optional() + .describe( + "Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.", + ), workingSince: zod.iso .datetime({ offset: true }) .nullish() @@ -736,6 +760,12 @@ export const RetryTaskResponse = zod.object({ .describe( "When the person stopped its run. Its status is failed while this is set. Null or absent otherwise, and once it carries on.", ), + canTryAgain: zod + .boolean() + .optional() + .describe( + "Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true.", + ), workingSince: zod.iso .datetime({ offset: true }) .nullish() diff --git a/app/src/lib/approvals.ts b/app/src/lib/approvals.ts index 0bd5b1bf43..fec830f2a5 100644 --- a/app/src/lib/approvals.ts +++ b/app/src/lib/approvals.ts @@ -486,7 +486,16 @@ export const decideApprovalMutationOptions = (queryClient: QueryClient) => mutationOptions({ mutationFn: ({ id, choice }: { id: string; choice: ApprovalDecision }) => decideApproval(id, choice), - onSuccess: settle(queryClient), + /* + * The badge that counted it is read again at once, as for an answered question: left to its + * poll, it kept the old count for seconds beside a board that already showed the new one. + */ + onSuccess: () => { + void queryClient.invalidateQueries({ + queryKey: botLifecycleKeys.attention, + }); + return settle(queryClient)(); + }, }); /** Answer a question a Bot asked mid-run; the run resumes with the answer. */ export const answerPersonQuestionMutationOptions = (queryClient: QueryClient) => diff --git a/app/src/lib/tasks/queries.ts b/app/src/lib/tasks/queries.ts index 27645a915f..3adae1c503 100644 --- a/app/src/lib/tasks/queries.ts +++ b/app/src/lib/tasks/queries.ts @@ -50,6 +50,12 @@ export type BotTask = { * Stopped. Null once it carries on. */ stoppedAt?: string | null; + /** + * False when trying it again can't change how it ends: it couldn't finish for a reason asking + * again gets the same answer to (a Bot it asked isn't shared with the person). Absent from a + * server that does not say, which reads as true. + */ + canTryAgain?: boolean; /** One line on what comes next, from the last thing said in its conversation. */ next: string | null; /** When the work it is doing now began, for how long it has been working. Null unless working. */ @@ -204,9 +210,15 @@ export function couldNotFinish(failure: string | null): string { } /** - * Why a task couldn't finish, as a line of its own under its status: a sentence. The server words - * its reason to follow "Couldn't finish:" ("this Bot isn't shared with you any more"), so on its - * own it starts in capitals and ends with a full stop. + * A task that couldn't finish, in a word or two: what its card in the conversation says, and its + * row on the Needs you board, so the two never name one state twice. + */ +export const TASK_FAILED_LABEL = "Couldn't finish"; + +/** + * Why a task couldn't finish, as a line of its own after a status that already says so: a + * sentence. The server words its reason to follow "Couldn't finish:" ("Pipeline Bot isn't shared + * with you"), so on its own it starts in capitals and ends with a full stop. */ export function failureSentence(failure: string): string { const said = failure.trim(); @@ -215,6 +227,17 @@ export function failureSentence(failure: string): string { return /[.!?]$/.test(sentence) ? sentence : `${sentence}.`; } +/** + * Whether Try again is offered: only on a task that couldn't finish, and not on one the server says + * asking again can't change, which would only be refused the same way again. + */ +export function canTryAgain(task: { + status: TaskStatus; + canTryAgain?: boolean; +}): boolean { + return task.status === "failed" && task.canTryAgain !== false; +} + /** * Whether the person stopped this task. Its status is `failed` either way, and only a stop sets * `stoppedAt`. A stop is the person's own choice, so nothing that lists the task calls it a failure. diff --git a/app/src/routes/_authed/admin/people.tsx b/app/src/routes/_authed/admin/people.tsx index 28c37fe8e3..44871387d0 100644 --- a/app/src/routes/_authed/admin/people.tsx +++ b/app/src/routes/_authed/admin/people.tsx @@ -43,6 +43,7 @@ import { setPersonAccessMutationOptions, setPersonRoleMutationOptions, } from "@/lib/people/mutations"; +import { useCurrentOrganizationId } from "@/lib/organizations/current"; import { useOrganizationChoices } from "@/lib/organizations/queries"; import { type Person, peopleListQueryOptions } from "@/lib/people/queries"; import { queryClient } from "@/query-client"; @@ -122,6 +123,11 @@ function PeoplePage() { const [removing, setRemoving] = useState(null); const [removeOpen, setRemoveOpen] = useState(false); const organization = useRemovalOrganization(); + /* + * INITIAL_ADMIN_EMAILS names the admins of the deployment's first organization (`default`, as the + * API addresses it) and of no other, so only its People page says so. + */ + const inFirstOrganization = useCurrentOrganizationId() === "default"; // The server refuses these too. Disabling them here is so the screen does not offer something it // knows will be refused, not so the rule is enforced in the browser. @@ -133,7 +139,11 @@ function PeoplePage() { title="People" > {failure ? ( @@ -181,6 +191,13 @@ function PeoplePage() { {rows.map((person, index) => { const isSelf = person.id === currentUser.data?.id; const busy = setRole.isPending || setAccess.isPending; + /* + * An owner governs the organization as an admin does, so their Admin switch reads on. + * Their role is not this switch's to change (only an owner gives ownership away, in + * Organization settings), and the server keeps the owner, so neither switch nor + * Remove is offered for them. + */ + const owner = person.role === "owner"; return ( @@ -217,7 +234,9 @@ function PeoplePage() { setRole.mutate({ userId: person.id, diff --git a/app/tests/admin-people-remove.test.tsx b/app/tests/admin-people-remove.test.tsx index a69d4c550f..df57a13a78 100644 --- a/app/tests/admin-people-remove.test.tsx +++ b/app/tests/admin-people-remove.test.tsx @@ -22,6 +22,10 @@ import { within, } from "@testing-library/react"; import { deploymentKeys } from "@/lib/deployment/queries"; +import { + currentOrganizationId, + setCurrentOrganization, +} from "@/lib/organizations/current"; import { queryClient } from "@/query-client"; import { Route } from "@/routes/_authed/admin/people"; import { ME_PATH, meResponse, PEOPLE_PATH, personBody } from "./accounts-api"; @@ -72,12 +76,15 @@ let refusal: string | null = null; * and has no list of them to answer (the address is not served), as before organizations. */ let severalOrganizations = false; +/** Which of the person's organizations they are working in, where there are several. */ +let activeOrganization = "default"; beforeEach(() => { removed.clear(); writes.length = 0; refusal = null; severalOrganizations = false; + activeOrganization = "default"; queryClient.clear(); queryClient.setQueryData(deploymentKeys.capabilities(), { generativeUi: true, @@ -99,7 +106,7 @@ beforeEach(() => { name: "Acme Freight", role: "admin", personal: false, - active: true, + active: activeOrganization === "default", }, { id: "org_dana", @@ -107,7 +114,7 @@ beforeEach(() => { name: "Dana's organization", role: "owner", personal: true, - active: false, + active: activeOrganization === "org_dana", }, ], canCreate: true, @@ -254,6 +261,38 @@ test("with several organizations, Remove says it takes them out of this one alon ).toBeTruthy(); }); +/* + * INITIAL_ADMIN_EMAILS names the admins of the deployment's first organization, `default`, and + * nowhere else. On another organization's People page the line saying those addresses are always + * admins was false there. + */ +test("the INITIAL_ADMIN_EMAILS line shows in the first organization only", async () => { + const LINE = + "Addresses in INITIAL_ADMIN_EMAILS are always admins. You can't change them here."; + severalOrganizations = true; + const first = await draw(); + expect(await first.findByText(LINE)).toBeTruthy(); + cleanup(); + + activeOrganization = "org_dana"; + queryClient.clear(); + queryClient.setQueryData(deploymentKeys.capabilities(), { + generativeUi: true, + selfHostBanner: false, + localEvaluation: false, + edition: "team", + }); + try { + const second = await draw(); + await second.findByText("Who is here"); + await waitFor(() => expect(currentOrganizationId()).toBe("org_dana")); + await settleReactWork(); + expect(second.queryByText(LINE)).toBeNull(); + } finally { + setCurrentOrganization("default"); + } +}); + test("a removal the server refuses is said in the dialog, and the person stays", async () => { refusal = "You can't remove the only admin."; const view = await draw(); diff --git a/app/tests/admin-people-roles.test.tsx b/app/tests/admin-people-roles.test.tsx index 367ba950ef..a2ecfc560f 100644 --- a/app/tests/admin-people-roles.test.tsx +++ b/app/tests/admin-people-roles.test.tsx @@ -51,7 +51,7 @@ const sam = { name: "Sam Ortiz", role: "member" as const, }; -const roles: Record = {}; +const roles: Record = {}; const sent: unknown[] = []; beforeEach(() => { @@ -123,3 +123,25 @@ test("the admin switch gives a member admin and back, by the member role names", expect((await switchFor()).getAttribute("aria-checked")).toBe("false"), ); }); + +/* + * Found in testing: an organization's owner showed with the Admin switch off. An owner governs the + * organization as an admin does, and their role is not one this switch changes (only the owner + * gives ownership away, in Organization settings), so it reads on and can't be changed here. + */ +test("an owner's admin switch reads on and can't be changed, and nothing is sent", async () => { + roles.sam = "owner"; + const view = await draw(); + const owner = await view.findByRole("switch", { + name: "Admin: sam@acme.test", + }); + await waitFor(() => expect(owner.getAttribute("aria-checked")).toBe("true")); + expect( + owner.hasAttribute("disabled") || + owner.getAttribute("aria-disabled") === "true" || + owner.hasAttribute("data-disabled"), + ).toBe(true); + fireEvent.click(owner); + await new Promise((resolve) => setTimeout(resolve, 50)); + expect(sent).toEqual([]); +}); diff --git a/app/tests/audit-event-words.test.tsx b/app/tests/audit-event-words.test.tsx index 98afc4781e..6546007ffa 100644 --- a/app/tests/audit-event-words.test.tsx +++ b/app/tests/audit-event-words.test.tsx @@ -256,6 +256,37 @@ test("what happened to an organization reads in words, and none of it as blocked } }); +/* + * Found in testing: a Bot's owner switching an app on for their own Bot read "Share an app", and + * off "Stop sharing an app". Nothing was shared with anybody: they gave their Bot the app. + */ +test("an owner giving their Bot an app, and taking it back, reads as that", async () => { + const view = await renderAs("team", [ + row( + "a1", + 41, + "app_access.owner_granted", + "mcp_server", + {}, + "composio-gmail", + ), + row( + "a2", + 40, + "app_access.owner_revoked", + "mcp_server", + {}, + "composio-gmail", + ), + ]); + const lines = whats(view.container); + expect(lines.map((line) => line.textContent)).toEqual([ + "Give a Bot an app", + "Take an app from a Bot", + ]); + expect(view.container.textContent).not.toContain("Share"); +}); + /** * A real-product pass read "Started by a person" on every row a person started, with nobody named, * and searching the person's email found nothing. The server sends who in `payload.by`. diff --git a/app/tests/bots-nav-badge.test.tsx b/app/tests/bots-nav-badge.test.tsx index be1c189ec3..9d836b4661 100644 --- a/app/tests/bots-nav-badge.test.tsx +++ b/app/tests/bots-nav-badge.test.tsx @@ -1,8 +1,13 @@ import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"; import { GlobalRegistrator } from "@happy-dom/global-registrator"; -import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { + MutationObserver, + QueryClient, + QueryClientProvider, +} from "@tanstack/react-query"; import { act, cleanup, render, waitFor } from "@testing-library/react"; import { BotsNavBadge } from "@/components/bot-profile/attention"; +import { decideApprovalMutationOptions } from "@/lib/approvals"; import { botLifecycleKeys } from "@/lib/bot-lifecycle/queries"; import { answerBotAttention, attentionOf } from "./bots-api"; import { awayFromOpenBot } from "./desktop-notifications.fixture"; @@ -123,6 +128,37 @@ test("the badge adds up what waits on the person across every Bot", async () => expect(badge.getAttribute("aria-label")).toBe("3 things need you"); }); +test("allowing or denying an action reads the badge again at once, as answering a question does", async () => { + serving([attention("expenses", { approvals: 1 })]); + const answered = global.fetch; + const decided: string[] = []; + // The decision, at the API's address, and every other read as before. + global.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { + if (/\/approvals\/[^/]+\/decide$/.test(pathOf(input))) { + decided.push(pathOf(input)); + return Response.json({ id: "approval-1", status: "completed" }); + } + return answered(input, init); + }) as unknown as typeof fetch; + const { view, client } = draw(); + await view.findByText("1"); + + // Decided on the Needs you board: the server no longer counts it. + served = [attention("expenses", {})]; + await act(async () => { + await new MutationObserver( + client, + decideApprovalMutationOptions(client), + ).mutate({ id: "approval-1", choice: "deny" }); + }); + expect(decided).toHaveLength(1); + // Well inside the badge's own poll, which is 15 seconds away. + await waitFor(() => expect(view.queryByText("1")).toBeNull(), { + timeout: 2_000, + }); + expect(view.container.innerHTML).toBe(""); +}); + test("with only unread messages the badge is a dot, not a number", async () => { serving([attention("expenses", { unread: 2 })]); const { view } = draw(); diff --git a/app/tests/needs-you.test.tsx b/app/tests/needs-you.test.tsx index a5960b8200..2910ebadc5 100644 --- a/app/tests/needs-you.test.tsx +++ b/app/tests/needs-you.test.tsx @@ -107,6 +107,7 @@ type Task = { failure: string | null; failedAt: string | null; stoppedAt?: string | null; + canTryAgain?: boolean; next: string | null; resolvedAt: string | null; createdAt: string; @@ -469,9 +470,7 @@ test("tasks list what to read, answer and retry first, and each acts from its ro "Draft the board update", ]); expect(bots.getByText("I drafted a reply. Want me to send it?")).toBeTruthy(); - expect( - bots.getByText("Couldn't finish: Gmail stopped answering."), - ).toBeTruthy(); + expect(bots.getByText("Gmail stopped answering.")).toBeTruthy(); fireEvent.click(bots.getByRole("button", { name: "Try again" })); await waitFor(() => @@ -481,9 +480,7 @@ test("tasks list what to read, answer and retry first, and each acts from its ro }), ); await waitFor(() => - expect( - bots.queryByText("Couldn't finish: Gmail stopped answering."), - ).toBeNull(), + expect(bots.queryByText("Gmail stopped answering.")).toBeNull(), ); const ready = bots @@ -567,21 +564,58 @@ test("a task the person stopped reads Stopped on the board, in its card's words, row("File the expense report").querySelector(".bg-amber-50"), ).not.toBeNull(); - // One that couldn't finish on its own still says so. + // One that couldn't finish on its own still says so, in its card's words, and why. const failed = within( surface .getByText("File the expense report") .closest("[data-slot=item]") as HTMLElement, ); - expect(failed.getByText("Failed")).toBeTruthy(); - expect( - failed.getByText("Couldn't finish: Gmail stopped answering."), - ).toBeTruthy(); + expect(failed.getByText("Couldn't finish")).toBeTruthy(); + expect(failed.getByText("Gmail stopped answering.")).toBeTruthy(); expect(failed.queryByText("Stopped")).toBeNull(); expect(failed.getByRole("button", { name: "Try again" })).toBeTruthy(); } }); +test("a task refused for good reads Couldn't finish, as its card does, and is offered no Try again", async () => { + tasks = [ + task({ + id: "h", + title: "Deals closing this week", + origin: "delegated", + status: "failed", + failure: "Pipeline Bot isn't shared with you", + failedAt: now, + // Asking again gets the same answer, and the server says so. + canTryAgain: false, + }), + ]; + waitingBots = [ + attentionOf("inbox", "Inbox Bot", { + tasks: { needsInput: 0, ready: 0, failed: 1 }, + }), + ]; + serving(); + const { region } = await drawAll(); + for (const name of ["Bots page", "Bot page"]) { + const row = within( + (await region(name).findByText("Deals closing this week")).closest( + "[data-slot=item]", + ) as HTMLElement, + ); + // Its state in the card's words, and why once, as a sentence. + expect(row.getByText("Couldn't finish")).toBeTruthy(); + expect(row.getByText("Pipeline Bot isn't shared with you.")).toBeTruthy(); + expect(row.queryByText("Failed")).toBeNull(); + // What can still be done with it: read it, or put it away. + expect(row.queryByRole("button", { name: "Try again" })).toBeNull(); + expect(row.getByRole("button", { name: "Mark done" })).toBeTruthy(); + expect(row.getByRole("button", { name: "Open" }).getAttribute("href")).toBe( + "/channel/c-h", + ); + } +}); + test("the board says a task's line as plain text, and a working task is not offered Mark done", async () => { tasks = [ task({ diff --git a/app/tests/task-thread.test.tsx b/app/tests/task-thread.test.tsx index 573d406008..619baeadf0 100644 --- a/app/tests/task-thread.test.tsx +++ b/app/tests/task-thread.test.tsx @@ -235,7 +235,7 @@ test("a needs-you line asks while the task waits, and changes in place once it i expect(waiting.getByRole("button", { name: /Go to thread/ })).toBeTruthy(); cleanup(); - // Answered in the thread: the task carries on, and the line no longer says it is waiting. + // Answered: the task carries on, and the line no longer says it is waiting. task = { ...task, status: "working", next: null }; const answered = draw( @@ -244,7 +244,7 @@ test("a needs-you line asks while the task waits, and changes in place once it i ); await answered.findByText("Needed you"); expect( - answered.getByText("You answered this in its thread. It's carrying on."), + answered.getByText("You answered this. It's carrying on."), ).toBeTruthy(); expect(answered.queryByText(WAITING)).toBeNull(); expect(answered.getByRole("button", { name: /Open thread/ })).toBeTruthy(); @@ -266,6 +266,23 @@ test("a needs-you line asks while the task waits, and changes in place once it i expect(askedAgain.queryByText(WAITING)).toBeNull(); }); +/* + * Found on the re-test: a person pressed Allow on the Bots page's Needs you board, and the line in + * the conversation that asked read "You answered this in its thread, and it's done." The card can't + * know where the answer was given (the thread, the board, the inbox), so it never says. + */ +test("an answered needs-you line never claims the answer was given in the thread", async () => { + task = { ...task, status: "ready_for_review", next: null as never }; + const view = draw( + +

{WAITING}

+
, + ); + await view.findByText("Needed you"); + expect(view.getByText("You answered this, and it's done.")).toBeTruthy(); + expect(view.queryByText(/in its thread/)).toBeNull(); +}); + test("a Bot's link to a task thread opens in the app, not in a new tab", async () => { expect(inAppPath("/channel/channel_task", "http://openbot.invalid")).toBe( "/channel/channel_task", @@ -481,7 +498,7 @@ test("a card that had stopped reading its task reads it again when the conversat await view.findByText("Working", {}, { timeout: 2_000 }); expect(stateOf(view)).toBe("working"); - // It runs out of tries: Couldn't finish, with why, and not Stopped. + // It runs out of tries: Couldn't finish, and not Stopped. Why is said on the line it reports. task = { ...task, status: "failed", @@ -492,7 +509,6 @@ test("a card that had stopped reading its task reads it again when the conversat }; await view.findByText("Couldn't finish", {}, { timeout: 6_000 }); expect(stateOf(view)).toBe("failed"); - expect(view.getByText("A service didn't answer.")).toBeTruthy(); }, 20_000); test("last activity moves when the task does something, and keeps ageing when it does not", async () => { @@ -699,16 +715,18 @@ test("a stopped task's line in the conversation reads Stopped, and its link row ).toBe("stopped"); }); -test("a task that couldn't finish says why on its card as a sentence of its own", async () => { - // The server words the reason to follow "Couldn't finish:", so it starts in lower case. - for (const [failure, said] of [ +test("a task that couldn't finish says why once, on the line it reports, not on its card as well", async () => { + // What the server says on each, and the line it reports under the card with the next step. + for (const [failure, reported, reason] of [ [ "this Bot isn't shared with you any more", - "This Bot isn't shared with you any more.", + "This Bot isn't shared with you any more, so it stopped this task. Its owner or an admin can share it again.", + /isn't shared with you any more/, ], [ "Pipeline Bot isn't shared with you", - "Pipeline Bot isn't shared with you.", + "I couldn't ask Pipeline Bot because it isn't shared with you. Its owner or an admin can share it with you.", + /isn't shared with you/, ], ] as const) { task = { @@ -720,16 +738,67 @@ test("a task that couldn't finish says why on its card as a sentence of its own" stoppedAt: null, workingSince: null, }; + // As the conversation that asked draws them: the card, and the line under it. const view = draw( - , + <> + + +

{reported}

+
+ , ); - await view.findByText("Couldn't finish"); - expect(view.getByText(said)).toBeTruthy(); - expect(view.queryByText(failure)).toBeNull(); + const card = await view.findByRole("region", { name: /^Task: / }); + await waitFor(() => expect(card.textContent).toContain("Couldn't finish")); + // The card says that it couldn't finish; why, and what to do, is said once, on the line. + expect(card.textContent).not.toMatch(reason); + const line = view.getByRole("region", { name: "A task couldn't finish" }); + expect(line.textContent).toContain(reported); + expect( + view.getAllByText(reason, { exact: false, selector: "p" }), + ).toHaveLength(1); cleanup(); } }); +/* + * An admin dismissing the Request access a task waited on ends it as couldn't finish, after its + * result was already said: no failed line is reported under it. The card says only that it couldn't + * finish, so the result above the app's card says why, once, and does not read as done. + */ +test("a result whose task then couldn't finish says why, once, and doesn't read as done", async () => { + task = { + ...task, + status: "failed", + next: null, + failure: "an admin didn't give this Bot Slack", + failedAt: ago(1), + stoppedAt: null, + workingSince: null, + }; + const view = draw( + <> + + +

+ “refunds batch done” was not posted because I haven't been granted + Slack access. +

+
+ , + ); + const link = await view.findByRole("link", { + name: /Order heirloom tomato seeds/, + }); + await waitFor(() => expect(link.getAttribute("data-state")).toBe("failed")); + expect( + view.container.textContent?.match(/an admin didn't give this Bot Slack/gi), + ).toHaveLength(1); +}); + test("a result whose task now needs the person doesn't read as done above its card", async () => { task = { ...task, diff --git a/mobile/src/api/generated/model/task.ts b/mobile/src/api/generated/model/task.ts index 265dcc15af..a4e8d92663 100644 --- a/mobile/src/api/generated/model/task.ts +++ b/mobile/src/api/generated/model/task.ts @@ -65,6 +65,8 @@ export interface Task { * @nullable */ stoppedAt?: string | null; + /** Whether trying a failed task again could change how it ends. False when it couldn't finish for a reason asking again gets the same answer to, such as a Bot it asked that isn't shared with the person, or this Bot no longer being shared with them. Absent from a server that does not say, which reads as true. */ + canTryAgain?: boolean; /** * When the work it is doing now began. Null or absent unless it is working. * @nullable diff --git a/shared/audit-words.ts b/shared/audit-words.ts index 9b8e1f0e0f..e409b5a62b 100644 --- a/shared/audit-words.ts +++ b/shared/audit-words.ts @@ -97,8 +97,9 @@ export const AUDIT_EVENT_WORDS: Readonly> = { "app_access.approved": "Approve a request for an app", "app_access.dismissed": "Dismiss a request for an app", "app_access.refused": "Ask for an app", - "app_access.owner_granted": "Share an app", - "app_access.owner_revoked": "Stop sharing an app", + // A Bot's owner switching an app on or off for their own Bot: nothing is shared with anybody. + "app_access.owner_granted": "Give a Bot an app", + "app_access.owner_revoked": "Take an app from a Bot", "plugin.grants_translated": "Choose a Bot's actions from a description", "plugin.grants_changed": "Change a Bot's actions in an app", "computer.action_allowed": "Use the computer",