Skip to content

Commit 0d809db

Browse files
StiensWoutcodexclaudeGrok 4.7
authored
perf(sidebar): avoid full git status for branch labels (#32947)
Co-authored-by: GPT 6.1 Sol <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Grok 4.7 <[email protected]>
1 parent ade4730 commit 0d809db

19 files changed

Lines changed: 751 additions & 49 deletions

File tree

‎apps/mobile/src/features/threads/git/GitBranchesSheet.occupancy.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ vi.mock("../../../state/use-selected-thread-git-actions", () => ({
5151
useSelectedThreadGitActions: () => ({ canChangeThreadBranch: true }),
5252
}));
5353
vi.mock("../../../state/query", () => ({ useEnvironmentQuery: () => ({ data: null }) }));
54-
vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { status: () => null } }));
54+
vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { branch: () => null } }));
5555

5656
import { GitBranchesSheet } from "./GitBranchesSheet";
5757

‎apps/mobile/src/features/threads/git/GitBranchesSheet.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ vi.mock("../../../state/use-selected-thread-git-actions", () => ({
7171
},
7272
}),
7373
}));
74-
vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { status: () => null } }));
74+
vi.mock("../../../state/vcs", () => ({ vcsEnvironment: { branch: () => null } }));
7575
vi.mock("./gitSheetComponents", () => ({
7676
SheetActionButton: (props: ActionProps) => {
7777
state.actions.set(props.label, props);

‎apps/mobile/src/features/threads/git/GitBranchesSheet.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
3333

3434
const gitStatus = useEnvironmentQuery(
3535
selectedThread !== null && selectedThreadCwd !== null
36-
? vcsEnvironment.status({
36+
? vcsEnvironment.branch({
3737
environmentId: selectedThread.environmentId,
3838
input: { cwd: selectedThreadCwd },
3939
})

‎apps/server/src/auth/RpcAuthorization.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ describe("RPC authorization scopes", () => {
6868
}
6969
});
7070

71+
it("lets thread readers observe and refresh checkout branches", () => {
72+
for (const method of [WS_METHODS.subscribeVcsBranch, WS_METHODS.vcsRefreshBranch]) {
73+
expect(requiredScopeForRpcMethod(method)).toBe(AuthOrchestrationReadScope);
74+
}
75+
});
76+
7177
it("rejects unknown RPC method names", () => {
7278
for (const method of ["server.notRegistered", "toString", "constructor"]) {
7379
expect(() => requiredScopeForRpcMethod(method)).toThrow(
@@ -133,6 +139,61 @@ describe("RPC scope middleware", () => {
133139
);
134140
});
135141

142+
it.effect.each([WS_METHODS.subscribeVcsBranch, WS_METHODS.subscribeVcsStatus] as const)(
143+
"enforces read permission on stream %s",
144+
(method) =>
145+
Effect.gen(function* () {
146+
const group = WsRpcGroup.omit(
147+
...[...WsRpcGroup.requests.keys()].filter(
148+
(
149+
tag,
150+
): tag is Exclude<
151+
keyof typeof RPC_REQUIRED_SCOPES,
152+
typeof WS_METHODS.subscribeVcsBranch | typeof WS_METHODS.subscribeVcsStatus
153+
> => tag !== WS_METHODS.subscribeVcsBranch && tag !== WS_METHODS.subscribeVcsStatus,
154+
),
155+
);
156+
let handled = 0;
157+
const handlers = Layer.mergeAll(
158+
group.toLayerHandler(WS_METHODS.subscribeVcsBranch, () =>
159+
Stream.fromEffect(
160+
Effect.sync(() => {
161+
handled++;
162+
return { refName: "main" };
163+
}),
164+
),
165+
),
166+
group.toLayerHandler(WS_METHODS.subscribeVcsStatus, () =>
167+
Stream.fromEffect(
168+
Effect.sync(() => {
169+
handled++;
170+
}),
171+
).pipe(Stream.drain),
172+
),
173+
);
174+
const denied = yield* RpcTest.makeClient(group).pipe(
175+
Effect.provide(Layer.merge(handlers, RpcAuthorization.layer([]))),
176+
);
177+
expect(
178+
yield* Stream.runDrain(
179+
method === WS_METHODS.subscribeVcsBranch
180+
? denied[method]({ cwd: "/repo" }).pipe(Stream.drain)
181+
: denied[method]({ cwd: "/repo" }).pipe(Stream.drain),
182+
).pipe(Effect.flip),
183+
).toMatchObject({ requiredPermission: AuthOrchestrationReadScope });
184+
expect(handled).toBe(0);
185+
const granted = yield* RpcTest.makeClient(group).pipe(
186+
Effect.provide(Layer.merge(handlers, RpcAuthorization.layer([AuthOrchestrationReadScope]))),
187+
);
188+
yield* Stream.runDrain(
189+
method === WS_METHODS.subscribeVcsBranch
190+
? granted[method]({ cwd: "/repo" }).pipe(Stream.drain)
191+
: granted[method]({ cwd: "/repo" }).pipe(Stream.drain),
192+
);
193+
expect(handled).toBe(1);
194+
}).pipe(Effect.scoped),
195+
);
196+
136197
describe("settings mutation authorization", () => {
137198
const group = WsRpcGroup.omit(
138199
...[...WsRpcGroup.requests.keys()].filter(

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ export const RPC_REQUIRED_SCOPES = {
169169
[WS_METHODS.mcpAppsReadResource]: AuthOrchestrationReadScope,
170170
[WS_METHODS.mcpAppsUpdateModelContext]: AuthOrchestrationOperateScope,
171171
[WS_METHODS.subscribeVcsStatus]: AuthOrchestrationReadScope,
172+
[WS_METHODS.subscribeVcsBranch]: AuthOrchestrationReadScope,
173+
[WS_METHODS.vcsRefreshBranch]: AuthOrchestrationReadScope,
172174
[WS_METHODS.subscribeWorktreeSetup]: AuthOrchestrationReadScope,
173175
[WS_METHODS.worktreeSetupCancel]: AuthOrchestrationOperateScope,
174176
[WS_METHODS.subscribeResourceTelemetry]: AuthDiagnosticsReadScope,

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export const make = Effect.gen(function* () {
227227
pullRequests: true,
228228
pullRequestChecks: true,
229229
sideChats: true,
230+
vcsBranchStatus: true,
230231
inlineMessageContext: true,
231232
requiredWorktreeBootstrap: true,
232233
threadSettlement: true,

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ const RPC_AGGREGATES = {
173173
[WS_METHODS.mcpAppsUpdateModelContext]: "provider",
174174
[WS_METHODS.mcpAppsReadResource]: "provider",
175175
[WS_METHODS.subscribeVcsStatus]: "vcs",
176+
[WS_METHODS.subscribeVcsBranch]: "vcs",
177+
[WS_METHODS.vcsRefreshBranch]: "vcs",
176178
[WS_METHODS.subscribeWorktreeSetup]: "vcs",
177179
[WS_METHODS.worktreeSetupCancel]: "vcs",
178180
[WS_METHODS.subscribeResourceTelemetry]: "server",

0 commit comments

Comments
 (0)