-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: skip CI MCP server installation when actions:read permission is missing #933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ describe("prepareMcpConfig", () => { | |
| let consoleWarningSpy: any; | ||
| let setFailedSpy: any; | ||
| let processExitSpy: any; | ||
| let fetchSpy: any; | ||
|
|
||
| // Create a mock context for tests | ||
| const mockContext: ParsedGitHubContext = { | ||
|
|
@@ -66,6 +67,10 @@ describe("prepareMcpConfig", () => { | |
| processExitSpy = spyOn(process, "exit").mockImplementation(() => { | ||
| throw new Error("Process exit"); | ||
| }); | ||
| // Mock fetch so checkActionsReadPermission succeeds (returns 200 for actions API) | ||
| fetchSpy = spyOn(global, "fetch").mockResolvedValue( | ||
| new Response(JSON.stringify({ workflow_runs: [] }), { status: 200 }), | ||
| ); | ||
|
|
||
| // Set up required environment variables | ||
| if (!process.env.GITHUB_ACTION_PATH) { | ||
|
|
@@ -78,6 +83,7 @@ describe("prepareMcpConfig", () => { | |
| consoleWarningSpy.mockRestore(); | ||
| setFailedSpy.mockRestore(); | ||
| processExitSpy.mockRestore(); | ||
| fetchSpy.mockRestore(); | ||
| }); | ||
|
|
||
| test("should return comment server when commit signing is disabled", async () => { | ||
|
|
@@ -263,6 +269,33 @@ describe("prepareMcpConfig", () => { | |
| expect(parsed.mcpServers.github_ci).not.toBeDefined(); | ||
| }); | ||
|
|
||
| test("should not include github_ci server when actions:read permission is missing", async () => { | ||
| process.env.DEFAULT_WORKFLOW_TOKEN = "workflow-token"; | ||
| // Simulate 403 from actions API | ||
| fetchSpy.mockResolvedValue( | ||
| new Response( | ||
| JSON.stringify({ message: "Resource not accessible by integration" }), | ||
| { status: 403 }, | ||
| ), | ||
| ); | ||
|
|
||
| const result = await prepareMcpConfig({ | ||
| githubToken: "test-token", | ||
| owner: "test-owner", | ||
| repo: "test-repo", | ||
| branch: "test-branch", | ||
| baseBranch: "main", | ||
| allowedTools: [], | ||
| mode: "tag", | ||
| context: mockPRContext, | ||
| }); | ||
|
|
||
| const parsed = JSON.parse(result); | ||
| expect(parsed.mcpServers.github_ci).not.toBeDefined(); | ||
|
|
||
| delete process.env.DEFAULT_WORKFLOW_TOKEN; | ||
| }); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Since this PR changed the warning text, it would be worth asserting that |
||
| test("should not include github_ci server when DEFAULT_WORKFLOW_TOKEN is missing", async () => { | ||
| delete process.env.DEFAULT_WORKFLOW_TOKEN; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The guidance here covers adding
actions: readto the workflow'spermissions:block, but users of this action also need to setadditional_permissions: 'actions: read'in the action'swith:inputs (perdocs/usage.md). Consider linking to the project's own configuration docs instead of (or in addition to) the generic GitHub token docs, so users can find both steps in one place.