Test enterprise retry path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Parker Brown
2026-03-20 23:11:27 -07:00
parent 8b90615b3f
commit de40320cff
4 changed files with 68 additions and 11 deletions
+5 -5
View File
@@ -23305,12 +23305,12 @@ async function getTokenFromEnterprise(request2, auth5, enterprise, permissions)
}
});
} catch (error2) {
if (error2.status !== 404) {
throw error2;
if (error2.status === 404) {
throw new Error(
`No enterprise installation found matching the name ${enterprise}.`
);
}
throw new Error(
`No enterprise installation found matching the name ${enterprise}.`
);
throw error2;
}
return createInstallationAuthResult(auth5, response.data, permissions);
}
+5 -6
View File
@@ -220,14 +220,13 @@ async function getTokenFromEnterprise(request, auth, enterprise, permissions) {
},
});
} catch (error) {
/* c8 ignore next 3 */
if (error.status !== 404) {
throw error;
if (error.status === 404) {
throw new Error(
`No enterprise installation found matching the name ${enterprise}.`
);
}
throw new Error(
`No enterprise installation found matching the name ${enterprise}.`
);
throw error;
}
// Get token for the enterprise installation
+19
View File
@@ -17,6 +17,25 @@ POST /api/v3/app/installations/123456/access_tokens
{"repositories":["create-github-app-token"]}
`;
exports[`main-enterprise-fail-response.test.js > stdout 1`] = `
Creating enterprise installation token for enterprise "test-enterprise".
Failed to create token for enterprise "test-enterprise" (attempt 1): GitHub API not available
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
::set-output name=installation-id::123456
::set-output name=app-slug::github-actions
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
::save-state name=expiresAt::2016-07-11T22:14:10Z
--- REQUESTS ---
GET /enterprises/test-enterprise/installation
GET /enterprises/test-enterprise/installation
POST /app/installations/123456/access_tokens
null
`;
exports[`main-enterprise-installation-not-found.test.js > stderr 1`] = `
Error: No enterprise installation found matching the name test-enterprise.
at getTokenFromEnterprise (file://<cwd>/lib/main.js:<line>:<column>)
@@ -0,0 +1,39 @@
import { test } from "./main.js";
// Verify enterprise installation lookup retries when the GitHub API returns a 500 error.
await test((mockPool) => {
process.env.INPUT_ENTERPRISE = "test-enterprise";
delete process.env.INPUT_OWNER;
delete process.env.INPUT_REPOSITORIES;
const mockInstallationId = "123456";
const mockAppSlug = "github-actions";
mockPool
.intercept({
path: "/enterprises/test-enterprise/installation",
method: "GET",
headers: {
accept: "application/vnd.github.v3+json",
"user-agent": "actions/create-github-app-token",
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
},
})
.reply(500, "GitHub API not available");
mockPool
.intercept({
path: "/enterprises/test-enterprise/installation",
method: "GET",
headers: {
accept: "application/vnd.github.v3+json",
"user-agent": "actions/create-github-app-token",
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
},
})
.reply(
200,
{ id: mockInstallationId, app_slug: mockAppSlug },
{ headers: { "content-type": "application/json" } },
);
});