From b0f9b3340a89562dc53cd6718b741527cdd3bca6 Mon Sep 17 00:00:00 2001 From: mbeaulne Date: Tue, 1 Dec 2026 10:32:27 -0500 Subject: [PATCH 1/4] Show who requested a Tangent run --- src/components/Home/RunSection/RunRow.tsx | 11 +++- src/components/PipelineRun/RunDetails.tsx | 9 +++- src/components/shared/RunSource.test.tsx | 12 +++++ src/components/shared/RunSource.tsx | 21 ++++++-- .../RunView/components/RunDetailsContent.tsx | 13 ++++- .../Tangent/components/ProjectChatArea.tsx | 2 +- .../Tangent/hooks/useChatCommands.test.tsx | 50 ++++++++++++++++--- .../v2/pages/Tangent/hooks/useChatCommands.ts | 15 ++++-- src/utils/annotationKeys.ts | 1 + 9 files changed, 114 insertions(+), 20 deletions(-) diff --git a/src/components/Home/RunSection/RunRow.tsx b/src/components/Home/RunSection/RunRow.tsx index bcbbde8433..5692d3e7dd 100644 --- a/src/components/Home/RunSection/RunRow.tsx +++ b/src/components/Home/RunSection/RunRow.tsx @@ -27,6 +27,7 @@ import { runAnnotationsQueryOptions } from "@/services/runAnnotations"; import { getAnnotationValue, getPipelineTagsFromAnnotations, + RUN_REQUESTED_BY_ANNOTATION, RUN_SOURCE_ANNOTATION, } from "@/utils/annotations"; import { formatDate } from "@/utils/date"; @@ -65,6 +66,10 @@ const RunRow = ({ const name = run.pipeline_name ?? "Unknown pipeline"; const tags = getPipelineTagsFromAnnotations(annotations); const source = getAnnotationValue(annotations, RUN_SOURCE_ANNOTATION); + const requestedBy = getAnnotationValue( + annotations, + RUN_REQUESTED_BY_ANNOTATION, + ); const createdBy = run.created_by ?? "Unknown user"; const truncatedCreatedBy = truncateMiddle(createdBy); @@ -185,7 +190,11 @@ const RunRow = ({ - + { ...runAnnotationsQueryOptions(runId, backendUrl), }); const runSource = getAnnotationValue(runAnnotations, RUN_SOURCE_ANNOTATION); + const requestedBy = getAnnotationValue( + runAnnotations, + RUN_REQUESTED_BY_ANNOTATION, + ); const handleCopyUrl = () => { copyToClipboard(window.location.href); @@ -127,7 +132,9 @@ export const RunDetails = () => { {metadata && ( } + titleAction={ + + } items={[ { label: "Run Id", value: metadata.id }, { label: "Execution Id", value: metadata.root_execution_id }, diff --git a/src/components/shared/RunSource.test.tsx b/src/components/shared/RunSource.test.tsx index eab0555164..aa4fe80405 100644 --- a/src/components/shared/RunSource.test.tsx +++ b/src/components/shared/RunSource.test.tsx @@ -28,6 +28,18 @@ describe("getRunSourceMessage", () => { expect(getRunSourceMessage("tangent")).toBe("Submitted by a Tangent agent"); }); + it.each(["tangent", "tangent-ui"])( + "names the person who requested a %s run", + (source) => { + expect(getRunSourceMessage(source, "person@example.com")).toBe( + "Submitted by person@example.com via Tangent", + ); + expect(getRunSourceMessage("web-app", "person@example.com")).toBe( + "Submitted via the Tangle web app", + ); + }, + ); + /** Anything may submit a run, so the map is a reader's vocabulary. */ it("falls back for a submitter it has never heard of", () => { expect(getRunSourceMessage("some-future-tool")).toBe( diff --git a/src/components/shared/RunSource.tsx b/src/components/shared/RunSource.tsx index bbf3065a7f..171766d954 100644 --- a/src/components/shared/RunSource.tsx +++ b/src/components/shared/RunSource.tsx @@ -61,10 +61,21 @@ export const hasRunSource = (source?: string | null): boolean => Boolean(source); /** Human-readable message describing how a run was submitted. */ -export const getRunSourceMessage = (source?: string | null): string => - getRunSourceConfig(source).message; +export const getRunSourceMessage = ( + source?: string | null, + requestedBy?: string, +): string => { + if ( + requestedBy && + (source === TANGENT_AGENT_RUN_SOURCE || source === TANGENT_UI_RUN_SOURCE) + ) { + return `Submitted by ${requestedBy} via Tangent`; + } + return getRunSourceConfig(source).message; +}; interface RunSourceIconProps { + requestedBy?: string; source?: string | null; size?: "xs" | "sm" | "md"; className?: string; @@ -72,15 +83,17 @@ interface RunSourceIconProps { export const RunSourceIcon = ({ source, + requestedBy, size = "sm", className, }: RunSourceIconProps) => { - const { icon, message } = getRunSourceConfig(source); + const { icon } = getRunSourceConfig(source); + const message = getRunSourceMessage(source, requestedBy); return ( - + diff --git a/src/routes/v2/pages/RunView/components/RunDetailsContent.tsx b/src/routes/v2/pages/RunView/components/RunDetailsContent.tsx index 023c51d51a..9a96d06a9a 100644 --- a/src/routes/v2/pages/RunView/components/RunDetailsContent.tsx +++ b/src/routes/v2/pages/RunView/components/RunDetailsContent.tsx @@ -44,6 +44,7 @@ import { isSystemRunAnnotation, PIPELINE_NOTES_ANNOTATION, PIPELINE_TAGS_ANNOTATION, + RUN_REQUESTED_BY_ANNOTATION, RUN_SOURCE_ANNOTATION, SYSTEM_ANNOTATIONS, } from "@/utils/annotations"; @@ -297,6 +298,10 @@ function RunInfoSection({ metadata }: { metadata: PipelineRunResponse }) { const { data: runAnnotations } = useRunAnnotations(metadata.id); const runSource = getAnnotationValue(runAnnotations, RUN_SOURCE_ANNOTATION); + const requestedBy = getAnnotationValue( + runAnnotations, + RUN_REQUESTED_BY_ANNOTATION, + ); const hasKnownSource = hasRunSource(runSource); return ( @@ -317,9 +322,13 @@ function RunInfoSection({ metadata }: { metadata: PipelineRunResponse }) { {hasKnownSource && ( - + - {getRunSourceMessage(runSource)} + {getRunSourceMessage(runSource, requestedBy)} )} diff --git a/src/routes/v2/pages/Tangent/components/ProjectChatArea.tsx b/src/routes/v2/pages/Tangent/components/ProjectChatArea.tsx index 261d02f411..88448148be 100644 --- a/src/routes/v2/pages/Tangent/components/ProjectChatArea.tsx +++ b/src/routes/v2/pages/Tangent/components/ProjectChatArea.tsx @@ -26,7 +26,7 @@ export const ProjectChatArea = observer(function ProjectChatArea() { const references = useChatReferences(store.projectId); const { createdBy } = useProjectAuthor(); const recordContribution = useRecordProjectContribution(); - const commands = useChatCommands(store.projectId); + const commands = useChatCommands(store.projectId, createdBy); const refreshSessionResources = useRefreshSessionResources(); const activeSessionId = store.activeSessionId; diff --git a/src/routes/v2/pages/Tangent/hooks/useChatCommands.test.tsx b/src/routes/v2/pages/Tangent/hooks/useChatCommands.test.tsx index c52bf8c22f..2106d7be03 100644 --- a/src/routes/v2/pages/Tangent/hooks/useChatCommands.test.tsx +++ b/src/routes/v2/pages/Tangent/hooks/useChatCommands.test.tsx @@ -1,4 +1,3 @@ -import type { EmbedCommand } from "@tangent/embed-react"; import { renderHook } from "@testing-library/react"; import { beforeEach, describe, expect, it, vi } from "vitest"; @@ -67,8 +66,10 @@ const TRAIN = { archived: false, }; -function commandNamed(name: string): EmbedCommand { - const { result } = renderHook(() => useChatCommands("project-1")); +function commandNamed(name: string, currentUserId = "first@example.com") { + const { result } = renderHook(() => + useChatCommands("project-1", currentUserId), + ); const command = result.current.find((candidate) => candidate.name === name); if (!command) throw new Error(`No /${name} command`); return command; @@ -121,7 +122,10 @@ describe("useChatCommands", () => { it("starts each pipeline it's given, puts it in the chat, and reports the rest", async () => { fakes.submit.mockResolvedValue({ success: true, runId: "r-9" }); - const text = await commandNamed("run").run("[p-1, nope]"); + const text = await commandNamed("run").run( + "[p-1, nope]", + "first@example.com", + ); expect(fakes.resolvePipeline).toHaveBeenCalledWith({ source: "remote", @@ -130,7 +134,10 @@ describe("useChatCommands", () => { }); const [deps] = fakes.submit.mock.calls[0] as [BridgeDeps]; expect(deps.getSpec()?.name).toBe("Train"); - expect(Object.values(deps.getRunAnnotations?.() ?? {})).toEqual(["true"]); + expect(deps.getRunAnnotations?.()).toEqual({ + "tangleml.com/project/id/project-1": "true", + requested_by: "first@example.com", + }); expect(fakes.recordSessionRun).toHaveBeenCalledWith( "chat-1", "r-9", @@ -141,13 +148,44 @@ describe("useChatCommands", () => { expect(text).toContain("- `nope`: not one of this project's pipelines"); }); + it.each([undefined, "guest@example.com"])( + "leaves the requester unset when the sender is %s", + async (authorId) => { + fakes.submit.mockResolvedValue({ success: true, runId: "r-1" }); + await commandNamed("run").run("p-1", authorId); + const [deps] = fakes.submit.mock.calls[0] as [BridgeDeps]; + expect(deps.getRunAnnotations?.()).not.toHaveProperty("requested_by"); + expect(recordContribution).not.toHaveBeenCalled(); + }, + ); + + it("keeps overlapping requests with the people who sent them", async () => { + const first = Promise.withResolvers<{ success: boolean; runId: string }>(); + fakes.submit + .mockReturnValueOnce(first.promise) + .mockResolvedValueOnce({ success: true, runId: "second" }); + const a = commandNamed("run").run("p-1", "first@example.com"); + await vi.waitFor(() => expect(fakes.submit).toHaveBeenCalledOnce()); + await commandNamed("run", "second@example.com").run( + "p-1", + "second@example.com", + ); + first.resolve({ success: true, runId: "first" }); + await a; + expect( + fakes.submit.mock.calls.map( + ([deps]: [BridgeDeps]) => deps.getRunAnnotations?.()?.requested_by, + ), + ).toEqual(["first@example.com", "second@example.com"]); + }); + it("reports why the backend didn't start a pipeline", async () => { fakes.submit.mockResolvedValue({ success: false, error: "A required input has no value.", }); - const text = await commandNamed("run").run("p-1"); + const text = await commandNamed("run").run("p-1", "first@example.com"); expect(text).toContain("`p-1` (Train): A required input has no value."); expect(fakes.recordSessionRun).not.toHaveBeenCalled(); diff --git a/src/routes/v2/pages/Tangent/hooks/useChatCommands.ts b/src/routes/v2/pages/Tangent/hooks/useChatCommands.ts index 45cdbecaaf..baa1a69243 100644 --- a/src/routes/v2/pages/Tangent/hooks/useChatCommands.ts +++ b/src/routes/v2/pages/Tangent/hooks/useChatCommands.ts @@ -43,6 +43,7 @@ import { import { useRecordProjectContribution } from "@/services/projects/useProjectContributors"; import { runExecutionStatsQuery } from "@/services/projects/useProjectRuns"; import { useTeamForSubmission } from "@/services/teams/useTeamForSubmission"; +import { RUN_REQUESTED_BY_ANNOTATION } from "@/utils/annotationKeys"; import { buildProjectRunAnnotationKey } from "@/utils/annotations"; import { getExecutionStatusLabel, @@ -56,7 +57,7 @@ import { PIPELINE_YAML_LOAD_OPTIONS } from "@/utils/yaml"; * project card does, and `/run` starts pipelines by id. None of them starts * the agent; it's sent their results with the next message. */ -export function useChatCommands(projectId: string): EmbedCommand[] { +export function useChatCommands(projectId: string, currentUserId?: string) { const store = useTangentProject(); const handlers = useProjectCardHandlers(); const storage = usePipelineStorage(); @@ -139,6 +140,7 @@ export function useChatCommands(projectId: string): EmbedCommand[] { id: string, pipelines: ProjectCardEntry[], sessionId: string | undefined, + requestedBy: string | undefined, ): Promise { const pipeline = pipelines.find(({ target }) => targetId(target) === id); if (!pipeline) return { id, error: "not one of this project's pipelines" }; @@ -153,13 +155,14 @@ export function useChatCommands(projectId: string): EmbedCommand[] { queryClient, getRunAnnotations: () => ({ [buildProjectRunAnnotationKey(projectId)]: "true", + ...(requestedBy && { [RUN_REQUESTED_BY_ANNOTATION]: requestedBy }), }), getRunTeam: () => runTeamRef.current, }).submitPipelineRun(); if (!result.success || !result.runId) { return { id, name: pipeline.name, error: result.error }; } - recordContribution(projectId); + if (requestedBy) recordContribution(projectId); if (sessionId) { // Best effort: the run has started whether or not the chat noted it. await recordSessionRun(sessionId, result.runId, pipeline.name).catch( @@ -212,7 +215,7 @@ export function useChatCommands(projectId: string): EmbedCommand[] { name: "run", description: "Start pipelines by id", argumentHint: "", - run: async (args) => { + run: async (args: string, authorId?: string) => { if (parsePipelineIds(args).length === 0) { throw new Error( "add pipeline ids separated by commas. /pipelines lists them.", @@ -220,6 +223,8 @@ export function useChatCommands(projectId: string): EmbedCommand[] { } // The person may open another chat while these start. const sessionId = store.activeSessionId; + const requestedBy = + authorId === currentUserId ? currentUserId : undefined; const { pipelines } = await handlers.listEntries(); const ids = parsePipelineIds( args, @@ -227,10 +232,10 @@ export function useChatCommands(projectId: string): EmbedCommand[] { ); const starts: RunStart[] = []; for (const id of ids) { - starts.push(await start(id, pipelines, sessionId)); + starts.push(await start(id, pipelines, sessionId, requestedBy)); } return runStartsResult(starts); }, }, - ]; + ] satisfies EmbedCommand[]; } diff --git a/src/utils/annotationKeys.ts b/src/utils/annotationKeys.ts index 26ffd52074..0f95d6554c 100644 --- a/src/utils/annotationKeys.ts +++ b/src/utils/annotationKeys.ts @@ -12,6 +12,7 @@ export const PIPELINE_TAGS_ANNOTATION = "tags"; export const PIPELINE_CANONICAL_NAME_ANNOTATION = "canonical-pipeline-name"; export const RUN_NAME_TEMPLATE_ANNOTATION = "run-name-template"; export const RUN_SOURCE_ANNOTATION = "source"; +export const RUN_REQUESTED_BY_ANNOTATION = "requested_by"; export const EDITOR_POSITION_ANNOTATION = "editor.position"; export const EDITOR_COLLAPSED_ANNOTATION = "editor.collapsed"; export const EDITOR_FLOW_DIRECTION_ANNOTATION = "editor.flow-direction"; From 69f510c1e07927236c27bdfe6548f8a5d2da8c48 Mon Sep 17 00:00:00 2001 From: mbeaulne Date: Tue, 1 Dec 2026 10:35:05 -0500 Subject: [PATCH 2/4] Type the run submission test double --- .../v2/pages/Tangent/hooks/useChatCommands.test.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/routes/v2/pages/Tangent/hooks/useChatCommands.test.tsx b/src/routes/v2/pages/Tangent/hooks/useChatCommands.test.tsx index 2106d7be03..002d613013 100644 --- a/src/routes/v2/pages/Tangent/hooks/useChatCommands.test.tsx +++ b/src/routes/v2/pages/Tangent/hooks/useChatCommands.test.tsx @@ -10,7 +10,12 @@ const fakes = vi.hoisted(() => ({ listEntries: vi.fn(), listFiles: vi.fn(), resolvePipeline: vi.fn(), - submit: vi.fn(), + submit: + vi.fn< + ( + deps: BridgeDeps, + ) => Promise<{ success: boolean; runId?: string; error?: string }> + >(), recordSessionRun: vi.fn(), })); @@ -132,7 +137,7 @@ describe("useChatCommands", () => { backendUrl: "https://backend.example", pipelineId: "p-1", }); - const [deps] = fakes.submit.mock.calls[0] as [BridgeDeps]; + const [deps] = fakes.submit.mock.calls[0]; expect(deps.getSpec()?.name).toBe("Train"); expect(deps.getRunAnnotations?.()).toEqual({ "tangleml.com/project/id/project-1": "true", @@ -153,7 +158,7 @@ describe("useChatCommands", () => { async (authorId) => { fakes.submit.mockResolvedValue({ success: true, runId: "r-1" }); await commandNamed("run").run("p-1", authorId); - const [deps] = fakes.submit.mock.calls[0] as [BridgeDeps]; + const [deps] = fakes.submit.mock.calls[0]; expect(deps.getRunAnnotations?.()).not.toHaveProperty("requested_by"); expect(recordContribution).not.toHaveBeenCalled(); }, @@ -174,7 +179,7 @@ describe("useChatCommands", () => { await a; expect( fakes.submit.mock.calls.map( - ([deps]: [BridgeDeps]) => deps.getRunAnnotations?.()?.requested_by, + ([deps]) => deps.getRunAnnotations?.()?.requested_by, ), ).toEqual(["first@example.com", "second@example.com"]); }); From c99027b8517d3178ce518d8522ce9ae74a883e2a Mon Sep 17 00:00:00 2001 From: mbeaulne Date: Tue, 1 Dec 2026 10:54:16 -0500 Subject: [PATCH 3/4] Test the run byline and keep the chat test suites compatible --- .../components/RunDetailsContent.test.tsx | 20 ++++++++ .../TangentChatPane.author.test.tsx | 48 +++++++++++++++++++ .../components/TangentChatPane.test.tsx | 44 +++-------------- 3 files changed, 75 insertions(+), 37 deletions(-) create mode 100644 src/routes/v2/pages/Tangent/components/TangentChatPane.author.test.tsx diff --git a/src/routes/v2/pages/RunView/components/RunDetailsContent.test.tsx b/src/routes/v2/pages/RunView/components/RunDetailsContent.test.tsx index 165b5aed87..2f39ad7cdf 100644 --- a/src/routes/v2/pages/RunView/components/RunDetailsContent.test.tsx +++ b/src/routes/v2/pages/RunView/components/RunDetailsContent.test.tsx @@ -130,6 +130,26 @@ afterEach(() => { }); describe("", () => { + it.each<[string, string | undefined, string]>([ + [ + "tangent", + "matt@example.test", + "Submitted by matt@example.test via Tangent", + ], + ["tangent", undefined, "Submitted by a Tangent agent"], + ])( + "shows the Run Info byline for a %s run requested by %s", + async (source, requester, expected) => { + fetchRunAnnotations.mockResolvedValue({ + source, + requested_by: requester, + }); + renderPanel(); + expect(await screen.findByText(expected)).toBeVisible(); + expect(screen.getByRole("img", { name: expected })).toBeInTheDocument(); + }, + ); + it("shows run annotations", async () => { fetchRunAnnotations.mockResolvedValue({ experiment: "baseline", diff --git a/src/routes/v2/pages/Tangent/components/TangentChatPane.author.test.tsx b/src/routes/v2/pages/Tangent/components/TangentChatPane.author.test.tsx new file mode 100644 index 0000000000..fc9fb06359 --- /dev/null +++ b/src/routes/v2/pages/Tangent/components/TangentChatPane.author.test.tsx @@ -0,0 +1,48 @@ +import { fireEvent, render, screen } from "@testing-library/react"; +import { createElement } from "react"; +import { expect, it, vi } from "vitest"; + +import { CHAT_TAB_VALUE } from "@/routes/v2/pages/Tangent/store/TangentProjectStore"; + +import { TangentChatPane } from "./TangentChatPane"; + +vi.mock("@tangent/embed-react", () => ({ + Chat: () => createElement("tangent-chat", { "data-testid": "chat-prime" }), +})); + +it("reads the local prompt sender and ignores unsigned prompts and broadcasts", () => { + const onAuthor = vi.fn(); + render( + , + ); + const chat = screen.getByTestId("chat-prime"); + fireEvent( + chat, + new CustomEvent("resources-change", { + bubbles: true, + detail: { authorId: "observer" }, + }), + ); + fireEvent( + chat, + new CustomEvent("send-prompt", { + bubbles: true, + detail: { content: "old shell" }, + }), + ); + fireEvent( + chat, + new CustomEvent("send-prompt", { + bubbles: true, + detail: { content: "hello", authorId: "writer" }, + }), + ); + expect(onAuthor).toHaveBeenCalledExactlyOnceWith("writer"); +}); diff --git a/src/routes/v2/pages/Tangent/components/TangentChatPane.test.tsx b/src/routes/v2/pages/Tangent/components/TangentChatPane.test.tsx index 6b4b1c3dfb..6b26d87515 100644 --- a/src/routes/v2/pages/Tangent/components/TangentChatPane.test.tsx +++ b/src/routes/v2/pages/Tangent/components/TangentChatPane.test.tsx @@ -1,5 +1,4 @@ import { fireEvent, render, screen } from "@testing-library/react"; -import { createElement } from "react"; import { describe, expect, it, vi } from "vitest"; import { CHAT_TAB_VALUE } from "@/routes/v2/pages/Tangent/store/TangentProjectStore"; @@ -15,12 +14,13 @@ vi.mock("@tangent/embed-react", () => ({ agentId?: string; autoFocus?: boolean; onResourcesChange?: () => void; - }) => - createElement("tangent-chat", { - "data-testid": agentId ? `chat-${agentId}` : "chat-prime", - "data-autofocus": String(Boolean(autoFocus)), - onClick: () => onResourcesChange?.(), - }), + }) => ( +
onResourcesChange?.()} + /> + ), })); const noop = () => undefined; @@ -28,7 +28,6 @@ const noop = () => undefined; function renderPane( activeTab = CHAT_TAB_VALUE, onResourcesChange: () => void = noop, - onPromptAuthor?: (authorId: string) => void, ) { return render( , ); } @@ -67,34 +65,6 @@ describe("TangentChatPane", () => { ); }); - it("reads the identified sender from the local chat and ignores unsigned prompts and broadcasts", () => { - const onAuthor = vi.fn(); - renderPane("agent-1", noop, onAuthor); - const chat = screen.getByTestId("chat-agent-1"); - fireEvent( - chat, - new CustomEvent("resources-change", { - bubbles: true, - detail: { authorId: "observer" }, - }), - ); - fireEvent( - chat, - new CustomEvent("send-prompt", { - bubbles: true, - detail: { content: "old shell" }, - }), - ); - fireEvent( - chat, - new CustomEvent("send-prompt", { - bubbles: true, - detail: { content: "hello", authorId: "writer" }, - }), - ); - expect(onAuthor).toHaveBeenCalledExactlyOnceWith("writer"); - }); - it("hears of a change once, from Prime's chat, when every chat of the session reports it", () => { const onResourcesChange = vi.fn(); renderPane("agent-1", onResourcesChange); From d8dd1018a4803ec6d4cefffa2aeedb26562024dc Mon Sep 17 00:00:00 2001 From: mbeaulne Date: Tue, 1 Dec 2026 10:58:14 -0500 Subject: [PATCH 4/4] Set the project routing mode in the directory test --- src/components/Home/ProjectsSection/ProjectsSection.test.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/Home/ProjectsSection/ProjectsSection.test.tsx b/src/components/Home/ProjectsSection/ProjectsSection.test.tsx index 76954b5380..2c5ed05927 100644 --- a/src/components/Home/ProjectsSection/ProjectsSection.test.tsx +++ b/src/components/Home/ProjectsSection/ProjectsSection.test.tsx @@ -189,9 +189,14 @@ describe("ProjectsSection", () => { afterEach(() => { vi.resetAllMocks(); + localStorage.removeItem("betaFlags"); }); it("shows every creator in a single table and pages through the directory", async () => { + localStorage.setItem( + "betaFlags", + JSON.stringify({ "tangent-shell": false }), + ); mockPagedDirectory(); const user = userEvent.setup(); renderSection();