Skip to content

Commit c0f5f2b

Browse files
committed
fix(clients): keep terminology reactive across cached labels
1 parent cf2fe5c commit c0f5f2b

10 files changed

Lines changed: 210 additions & 61 deletions

File tree

‎apps/mobile/src/features/pull-requests/usePullRequestList.test.tsx‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setMergeRequestTerms } from "@t3tools/client-runtime/source-control-clients";
12
import { RegistryContext } from "@effect/atom-react";
23
import {
34
EnvironmentId,
@@ -9,7 +10,12 @@ import { act, useLayoutEffect } from "react";
910
import { createRoot } from "react-dom/client";
1011
import { expect, it, vi } from "vite-plus/test";
1112

12-
const mocks = vi.hoisted(() => ({ failPage: false }));
13+
const mocks = vi.hoisted(() => ({ failPage: false, mergeTerms: false }));
14+
15+
vi.mock("../../state/change-request-terminology", async () => {
16+
const { changeRequestTerms } = await import("@t3tools/client-runtime/source-control-clients");
17+
return { useChangeRequestTerms: () => changeRequestTerms(mocks.mergeTerms) };
18+
});
1319

1420
vi.mock("../../connection/catalog", async () => {
1521
const { Atom } = await import("effect/reactivity");
@@ -41,6 +47,7 @@ vi.mock("../../state/pull-requests", async () => {
4147
const response = page(target.input.cursors ? {} : { "github.com org/repo": "next" });
4248
return Atom.make(
4349
Effect.suspend(() => {
50+
if (target.environmentId === "untyped") return Effect.die("Unavailable");
4451
if (target.environmentId === "offline")
4552
return Effect.fail(
4653
new PullRequestListTestError({ message: "Environment is not connected." }),
@@ -73,6 +80,7 @@ import { usePullRequestList } from "./usePullRequestList";
7380

7481
function setup(ids: readonly string[]) {
7582
mocks.failPage = false;
83+
mocks.mergeTerms = false;
7684
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
7785
const registry = AtomRegistry.make();
7886
const targets = ids.map((id) => ({
@@ -88,14 +96,16 @@ function setup(ids: readonly string[]) {
8896
return null;
8997
}
9098
const root = createRoot(document.createElement("div"));
91-
act(() => {
99+
const renderProbe = () => {
92100
root.render(
93101
<RegistryContext.Provider value={registry}>
94102
<Probe />
95103
</RegistryContext.Provider>,
96104
);
97-
});
105+
};
106+
act(renderProbe);
98107
return {
108+
rerender: () => act(renderProbe),
99109
get latest() {
100110
return latest;
101111
},
@@ -107,10 +117,17 @@ function setup(ids: readonly string[]) {
107117
}
108118

109119
it("keeps a refresh failure in the source errors and allows healthy pagination", async () => {
110-
using probe = setup(["healthy", "offline"]);
120+
setMergeRequestTerms(false);
121+
using _terms = {
122+
[Symbol.dispose]() {
123+
setMergeRequestTerms(false);
124+
},
125+
};
126+
using probe = setup(["healthy", "offline", "untyped"]);
111127
await act(async () => probe.latest.onRefresh());
112128
expect(probe.latest.data.errors.map((error) => error.message)).toEqual([
113129
"Environment is not connected.",
130+
"Couldn't load pull requests.",
114131
]);
115132
expect(probe.latest.refreshing).toBe(false);
116133
expect(probe.latest.loadMoreError).toBeNull();
@@ -119,6 +136,14 @@ it("keeps a refresh failure in the source errors and allows healthy pagination",
119136
expect(probe.latest.continued).toBe(true);
120137
expect(probe.latest.hasMore).toBe(false);
121138
expect(probe.latest.loadMoreError).toBeNull();
139+
for (const enabled of [true, false]) {
140+
mocks.mergeTerms = enabled;
141+
setMergeRequestTerms(enabled);
142+
probe.rerender();
143+
expect(probe.latest.error).toContain(
144+
`Couldn't load ${enabled ? "merge requests" : "pull requests"}.`,
145+
);
146+
}
122147
});
123148

124149
it("keeps load-more failures retryable", async () => {

‎apps/mobile/src/features/pull-requests/usePullRequestList.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useChangeRequestTerms } from "../../state/change-request-terminology";
12
import { currentChangeRequestTerms } from "@t3tools/client-runtime/source-control-clients";
23
import { RegistryContext, useAtomMount, useAtomSubscribe, useAtomValue } from "@effect/atom-react";
34
import { executeAtomQuery, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
@@ -158,6 +159,7 @@ const settledError = (result: AsyncResult.AsyncResult<string | null, never>) =>
158159
AsyncResult.isSuccess(result) && !result.waiting ? result.value : null;
159160

160161
export function usePullRequestList(targets: readonly ListTarget[]) {
162+
const { plural } = useChangeRequestTerms();
161163
const registry = use(RegistryContext);
162164
const scopeKey = JSON.stringify(targets);
163165
const sources = useAtomValue(sourcesFamily(scopeKey));
@@ -311,14 +313,11 @@ export function usePullRequestList(targets: readonly ListTarget[]) {
311313
{
312314
environmentId: target.environmentId,
313315
projectTitle: "",
314-
message:
315-
cause instanceof Error
316-
? cause.message
317-
: `Couldn't load ${currentChangeRequestTerms().plural}.`,
316+
message: cause instanceof Error ? cause.message : `Couldn't load ${plural}.`,
318317
},
319318
];
320319
}),
321-
[sources],
320+
[sources, plural],
322321
);
323322
const listing = useMemo(
324323
() => ({ ...data, entries, errors: [...data.errors, ...errors] }),

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { setMergeRequestTerms } from "@t3tools/client-runtime/source-control-clients";
1+
import {
2+
setMergeRequestTerms,
3+
currentChangeRequestTerms,
4+
MERGE_REQUEST_TERMINOLOGY,
5+
PULL_REQUEST_TERMINOLOGY,
6+
} from "@t3tools/client-runtime/source-control-clients";
27
import {
38
MessageId,
49
CheckpointId,
@@ -1475,7 +1480,7 @@ describe("retained v2 feed presentation", () => {
14751480
3,
14761481
),
14771482
]);
1478-
const summary = () =>
1483+
const summary = (terms = currentChangeRequestTerms()) =>
14791484
deriveThreadFeedPresentation(
14801485
feed,
14811486
null,
@@ -1484,12 +1489,57 @@ describe("retained v2 feed presentation", () => {
14841489
null,
14851490
false,
14861491
cache,
1492+
undefined,
1493+
terms,
14871494
).find((entry) => entry.type === "work-toggle");
14881495
expect(summary()).toMatchObject({ summary: expect.stringContaining("pull request") });
14891496
setMergeRequestTerms(true);
14901497
expect(summary()).toMatchObject({ summary: expect.stringContaining("merge request") });
14911498
setMergeRequestTerms(false);
14921499
expect(summary()).toMatchObject({ summary: expect.stringContaining("pull request") });
1500+
expect(summary(MERGE_REQUEST_TERMINOLOGY)).toMatchObject({
1501+
summary: expect.stringContaining("merge request"),
1502+
});
1503+
expect(summary(MERGE_REQUEST_TERMINOLOGY)).toMatchObject({
1504+
summary: expect.stringContaining("merge request"),
1505+
});
1506+
expect(summary(PULL_REQUEST_TERMINOLOGY)).toMatchObject({
1507+
summary: expect.stringContaining("pull request"),
1508+
});
1509+
const singleFeed = feed.map((entry) =>
1510+
entry.type === "activity-group"
1511+
? { ...entry, activities: entry.activities.slice(0, 1) }
1512+
: entry,
1513+
);
1514+
for (const terms of [
1515+
MERGE_REQUEST_TERMINOLOGY,
1516+
MERGE_REQUEST_TERMINOLOGY,
1517+
PULL_REQUEST_TERMINOLOGY,
1518+
]) {
1519+
const single = deriveThreadFeedPresentation(
1520+
singleFeed,
1521+
null,
1522+
new Set([runId]),
1523+
new Set(),
1524+
null,
1525+
false,
1526+
cache,
1527+
undefined,
1528+
terms,
1529+
).find(
1530+
(entry) =>
1531+
entry.type === "activity-group" && entry.activities[0]?.groupStandIn !== undefined,
1532+
);
1533+
expect(single).toMatchObject({
1534+
activities: [
1535+
expect.objectContaining({
1536+
groupStandIn: expect.objectContaining({
1537+
label: expect.stringContaining(terms.shortLabel),
1538+
}),
1539+
}),
1540+
],
1541+
});
1542+
}
14931543
});
14941544

14951545
it("retains unchanged rows while the assistant streams", () => {

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -877,12 +877,16 @@ function toFeedActivity(
877877
};
878878
}
879879

880-
function singleToolCallLabel(activity: ThreadFeedActivity, expanded: boolean): string {
880+
function singleToolCallLabel(
881+
activity: ThreadFeedActivity,
882+
expanded: boolean,
883+
terms: ChangeRequestTerminology,
884+
): string {
881885
if (activity.workEntry.itemType === "reasoning")
882886
return expanded
883887
? "Thought"
884888
: compactWorkEntryText(activity.workEntry.detail ?? "") || "Thought";
885-
const presentation = resolveWorkEntryToolPresentation(activity.workEntry, "completed");
889+
const presentation = resolveWorkEntryToolPresentation(activity.workEntry, "completed", terms);
886890
if (presentation) return presentation.displayName;
887891
const command = activity.workEntry.command?.trim();
888892
return command ? truncate(command, WORK_LOG_LABEL_MAX_LENGTH) : activity.summary;
@@ -1930,7 +1934,15 @@ function appendPresentedFeedEntry(
19301934
)
19311935
) {
19321936
const rows: ThreadFeedEntry[] = [];
1933-
appendActivityGroupRows(rows, entry, expandedWorkGroupIds, activeRunId, isWorking, activeTail);
1937+
appendActivityGroupRows(
1938+
rows,
1939+
entry,
1940+
expandedWorkGroupIds,
1941+
activeRunId,
1942+
isWorking,
1943+
activeTail,
1944+
terms,
1945+
);
19341946
cached = { terms, activeRunId, isWorking, activeTail, rows };
19351947
presentedActivityGroupsCache.set(entry, cached);
19361948
}
@@ -1946,6 +1958,7 @@ function appendActivityGroupRows(
19461958
activeRunId: RunId | null,
19471959
isWorking: boolean,
19481960
activeTail: boolean,
1961+
terms: ChangeRequestTerminology,
19491962
): void {
19501963
const groupAnchorIdByActivityId = new Map<string, string>();
19511964
let groupAnchorId: string | null = null;
@@ -1980,6 +1993,7 @@ function appendActivityGroupRows(
19801993
activeRunId,
19811994
isWorking,
19821995
activeTail && isTrailingRun,
1996+
terms,
19831997
);
19841998
const paths = workEntriesViewedImagePaths(groupableRun.map((activity) => activity.workEntry));
19851999
if (paths.length > 0) {
@@ -2021,6 +2035,7 @@ function appendToolGroupRows(
20212035
activeRunId: RunId | null,
20222036
isWorking: boolean,
20232037
activeTail: boolean,
2038+
terms: ChangeRequestTerminology,
20242039
): void {
20252040
const expanded = expandedWorkGroupIds.has(groupId);
20262041
const latestActiveActivity = activities.findLast(
@@ -2032,7 +2047,10 @@ function appendToolGroupRows(
20322047
const latestActivity = latestActiveActivity ?? activities.at(-1)!;
20332048
const shimmer = activeTail && (active || latestActivity.status === "success");
20342049
const singleActivity = activities.length === 1 ? latestActivity : null;
2035-
const groupSummary = summarizeToolGroup(activities.map((activity) => activity.workEntry));
2050+
const groupSummary = summarizeToolGroup(
2051+
activities.map((activity) => activity.workEntry),
2052+
terms,
2053+
);
20362054
const latestThought =
20372055
live && !expanded
20382056
? activities.findLast(
@@ -2047,11 +2065,11 @@ function appendToolGroupRows(
20472065
? latestActivity.lifecycleStatus === "inProgress"
20482066
? "Thinking"
20492067
: "Thought"
2050-
: liveToolActivitySummary(latestActivity, live)
2068+
: liveToolActivitySummary(latestActivity, live, terms)
20512069
: singleActivity !== null &&
20522070
singleActivity.toolLike &&
20532071
toolGroupAction(singleActivity.workEntry) !== "edit"
2054-
? singleToolCallLabel(singleActivity, expanded)
2072+
? singleToolCallLabel(singleActivity, expanded, terms)
20552073
: singleActivity !== null && !singleActivity.toolLike
20562074
? singleActivity.workEntry.label
20572075
: groupSummary.summary;
@@ -2091,7 +2109,7 @@ function appendToolGroupRows(
20912109
activities.findLast((activity) => activity.workEntry.toolIcon !== undefined)?.workEntry
20922110
.toolIcon;
20932111
const summaryToolIcon = live
2094-
? resolveWorkEntryToolPresentation(latestActivity.workEntry)?.icon
2112+
? resolveWorkEntryToolPresentation(latestActivity.workEntry, undefined, terms)?.icon
20952113
: undefined;
20962114
result.push({
20972115
type: "work-toggle",
@@ -2136,17 +2154,25 @@ function appendToolGroupRows(
21362154
});
21372155
}
21382156

2139-
function liveToolActivitySummary(activity: ThreadFeedActivity, presentTense: boolean): string {
2157+
function liveToolActivitySummary(
2158+
activity: ThreadFeedActivity,
2159+
presentTense: boolean,
2160+
terms: ChangeRequestTerminology,
2161+
): string {
21402162
const status = liveActivityToolStatus(activity.lifecycleStatus, presentTense);
21412163
if (activity.workEntry.itemType === "reasoning") {
21422164
return compactWorkEntryText(
21432165
activity.workEntry.detail?.trim() || (status === "inProgress" ? "Thinking" : "Thought"),
21442166
);
21452167
}
2146-
const presentation = resolveWorkEntryToolPresentation({
2147-
...activity.workEntry,
2148-
toolLifecycleStatus: status,
2149-
});
2168+
const presentation = resolveWorkEntryToolPresentation(
2169+
{
2170+
...activity.workEntry,
2171+
toolLifecycleStatus: status,
2172+
},
2173+
undefined,
2174+
terms,
2175+
);
21502176
if (presentation) return presentation.displayName;
21512177
const command = activity.workEntry.command?.trim();
21522178
if (command) {

‎apps/web/src/components/composerContextPresentation.tsx‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useChangeRequestTerms } from "~/hooks/useSettings";
2+
import type { ChangeRequestTerminology } from "@t3tools/client-runtime/source-control-clients";
13
import ChatMarkdown from "./ChatMarkdown";
24
import { isSvgAttachment } from "@t3tools/shared/image";
35
import { ReadOnlySourcePreview } from "./files/AttachmentFilePreview";
@@ -254,7 +256,11 @@ function FileContextChip(props: {
254256
);
255257
}
256258

257-
function PullRequestContextChip(props: { record: ReviewCommentContext; kind: ContextChipKind }) {
259+
function PullRequestContextChip(props: {
260+
record: ReviewCommentContext;
261+
kind: ContextChipKind;
262+
terms: ChangeRequestTerminology;
263+
}) {
258264
const actions = use(ComposerContextActionsContext);
259265
const metadata = props.record.pullRequest;
260266
if (metadata === undefined) return null;
@@ -263,7 +269,7 @@ function PullRequestContextChip(props: { record: ReviewCommentContext; kind: Con
263269
metadata={metadata}
264270
environmentId={actions.environmentId}
265271
label={reviewCommentContextLabel(props.record)}
266-
kindLabel={pullRequestContextKindLabel(props.record)}
272+
kindLabel={pullRequestContextKindLabel(props.record, props.terms)}
267273
kind={props.kind}
268274
onOpen={actions.openPullRequest}
269275
/>
@@ -359,6 +365,7 @@ function UnresolvedContextChip(props: { label: string }) {
359365

360366
interface ComposerContextRenderContext {
361367
label: string;
368+
terms: ChangeRequestTerminology;
362369
}
363370

364371
const composerContextPresentationRegistry = createContextPresentationRegistry<
@@ -422,6 +429,7 @@ const composerContextPresentationRegistry = createContextPresentationRegistry<
422429
return (
423430
<PullRequestContextChip
424431
record={entry.record}
432+
terms={context.terms}
425433
kind={PULL_REQUEST_CHIP_KINDS[pullRequestState]}
426434
/>
427435
);
@@ -430,7 +438,11 @@ const composerContextPresentationRegistry = createContextPresentationRegistry<
430438
<ContextChip
431439
icon={isPullRequest ? <PullRequestGlyph.pullRequest /> : <MessageCircleIcon />}
432440
label={reviewCommentContextLabel(entry.record)}
433-
kindLabel={isPullRequest ? pullRequestContextKindLabel(entry.record) : "Review comment"}
441+
kindLabel={
442+
isPullRequest
443+
? pullRequestContextKindLabel(entry.record, context.terms)
444+
: "Review comment"
445+
}
434446
details={<ComposerReviewCommentDetails comment={entry.record} />}
435447
detailsMode={definition.capabilities.details}
436448
kind={isPullRequest ? PULL_REQUEST_CHIP_KINDS[pullRequestState] : "review-comment"}
@@ -489,8 +501,10 @@ export function ComposerContextReferenceChip(props: {
489501
contextId: string;
490502
label: string;
491503
}): ReactElement {
504+
const terms = useChangeRequestTerms();
492505
const records = use(ComposerContextRecordsContext);
493506
return composerContextPresentationRegistry.render(props.kind, records.get(props.contextId), {
494507
label: props.label,
508+
terms,
495509
});
496510
}

0 commit comments

Comments
 (0)