Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@muse-code/sdk": "1.4.6",
"@napi-rs/keyring": "^1.3.0",
"@opencode-ai/sdk": "^1.3.15",
"@t3tools/issue-tracker-core": "workspace:*",
"@t3tools/provider-acp": "workspace:*",
"@t3tools/provider-acp-registry": "workspace:*",
"@t3tools/provider-core": "workspace:*",
Expand Down
53 changes: 53 additions & 0 deletions apps/server/src/auth/RpcAuthorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
AuthSettingsWriteScope,
DEFAULT_SERVER_SETTINGS,
ProviderInstanceId,
ProjectId,
IssueTrackerKind,
ThreadId,
AuthOrchestrationOperateScope,
ORCHESTRATION_V2_WS_METHODS,
Expand Down Expand Up @@ -281,6 +283,57 @@ describe("RPC scope middleware", () => {
);
});

it.effect("allows issue reads but requires a source-control grant before commenting", () =>
Effect.gen(function* () {
const tested = [WS_METHODS.issuesList, WS_METHODS.issuesComment] as const;
const group = WsRpcGroup.omit(
...[...WsRpcGroup.requests.keys()].filter(
(tag): tag is Exclude<keyof typeof RPC_REQUIRED_SCOPES, (typeof tested)[number]> =>
!(tested as ReadonlyArray<string>).includes(tag),
),
);
const comments: string[] = [];
const handlers = Layer.mergeAll(
group.toLayerHandler(WS_METHODS.issuesList, () =>
Effect.succeed({ entries: [], trackers: [], errors: [], viewers: {}, nextCursors: {} }),
),
group.toLayerHandler(WS_METHODS.issuesComment, ({ body }) =>
Effect.sync(() => {
comments.push(body);
}),
),
);
const reader = yield* RpcTest.makeClient(group).pipe(
Effect.provide(Layer.merge(handlers, RpcAuthorization.layer([AuthOrchestrationReadScope]))),
);
const comment = {
projectId: ProjectId.make("web"),
tracker: IssueTrackerKind.make("github"),
scope: "acme/web",
key: "42",
body: "Repro attached.",
};

expect((yield* reader[WS_METHODS.issuesList]({ state: "open" })).entries).toEqual([]);
expect(yield* reader[WS_METHODS.issuesComment](comment).pipe(Effect.flip)).toMatchObject({
_tag: "EnvironmentAuthorizationError",
requiredPermission: AuthSourceControlWriteScope,
});
expect(comments).toEqual([]);

const writer = yield* RpcTest.makeClient(group).pipe(
Effect.provide(
Layer.merge(
handlers,
RpcAuthorization.layer([AuthOrchestrationReadScope, AuthSourceControlWriteScope]),
),
),
);
yield* writer[WS_METHODS.issuesComment](comment);
expect(comments).toEqual(["Repro attached."]);
}).pipe(Effect.scoped),
);

describe("settings mutation authorization", () => {
const group = WsRpcGroup.omit(
...[...WsRpcGroup.requests.keys()].filter(
Expand Down
5 changes: 5 additions & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.pullRequestsStack]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsLinkedThreads]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsDetail]: AuthOrchestrationReadScope,
[WS_METHODS.issuesList]: AuthOrchestrationReadScope,
[WS_METHODS.issuesDetail]: AuthOrchestrationReadScope,
[WS_METHODS.issuesComments]: AuthOrchestrationReadScope,
[WS_METHODS.issuesTemplates]: AuthOrchestrationReadScope,
[WS_METHODS.issuesCandidates]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsPreview]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsChecks]: AuthOrchestrationReadScope,
[WS_METHODS.pullRequestsActivity]: AuthOrchestrationReadScope,
Expand Down
Loading
Loading