Merge pull request #967 from tdurieux/fix/deployment-and-repository-errors

fix: guard GitHub App deployments and distinguish removed repositories
This commit is contained in:
Thomas Durieux authored and GitHub committed 2026-11-15 00:18:37 +01:00
commit fbb9c5fac0
9 files changed
+118 -14

No files matched your search

+1 -1
View File
@@ -155,7 +155,7 @@ describe("removal recovery", function () {
expect(repo.status).to.equal("removing");
let publicError;
try { await repo.check(); } catch (error) { publicError = error; }
expect(publicError.message).to.equal("repository_expired");
expect(publicError.message).to.equal("is_removed");
AnonymizedRepositoryModel.find = (filter) => ({
lean: async () => repo.status === filter.status ? [repo.model] : [],
+20 -3
View File
@@ -30,6 +30,7 @@ if (args[0] === "inspect") {
if (args[0] === "compose") {
if (args[1] === "build") { if (state.buildFails) finish("", 1); state.built = true; finish(); }
if (args[1] === "stop") { state.stopped = true; finish(); }
if (args[1] === "run" && args.at(-1).endsWith("check-github-app-key.js")) { finish("", args.includes(state.preflightFails) ? 1 : 0); }
if (args[1] === "run") { if (state.reconcileFails) finish("", 1); state.reconciled = true; finish(); }
if (args[1] === "up") { if (args.includes("streamer")) state.streamers = true; else state.api = true; finish(); }
if (args[1] === "ps") {
@@ -50,6 +51,22 @@ finish("unexpected docker call", 2);
} finally { fs.rmSync(directory, { recursive: true, force: true }); }
}
for (const preflightFails of ["anonymous_github", "streamer"]) it(`keeps working containers when ${preflightFails} key preflight fails`, () => {
const result = deploy({ preflightFails });
expect(result.status).not.to.equal(0);
expect(result.calls.some(args => args[0] === "compose" && ["stop", "up"].includes(args[1]))).to.equal(false);
expect(result.calls.some(args => args.includes("./build/scripts/reconcile-legacy-owner-alerts.js"))).to.equal(false);
});
it("checks both replacement services before stopping working instances", () => {
const result = deploy();
expect(result.status, result.stderr).to.equal(0);
const stop = result.calls.findIndex(args => args[1] === "stop");
for (const service of ["anonymous_github", "streamer"]) {
const check = result.calls.findIndex(args => args.includes(service) && args.includes("./build/scripts/check-github-app-key.js"));
expect(check).to.be.greaterThan(-1); expect(check).to.be.lessThan(stop);
expect(result.calls[check]).to.include.members(["--no-deps", "--rm", "--entrypoint", "node"]);
}
});
for (const sharedCache of [true, false]) it(`coordinates cache rollout with ${sharedCache ? "existing" : "new"} caching`, () => {
const result = deploy({ oldProtocol: "recipient-v2", sharedCache, coordinated: sharedCache ? 0 : 1 });
expect(result.status, result.stderr).to.equal(0);
@@ -70,7 +87,7 @@ finish("unexpected docker call", 2);
const stop = result.calls.findIndex(args => args[0] === "compose" && args[1] === "stop");
const up = result.calls.findIndex(args => args[0] === "compose" && args[1] === "up");
expect(stop).to.be.greaterThan(-1); expect(up).to.be.greaterThan(stop);
const reconcile = result.calls.findIndex(args => args[0] === "compose" && args[1] === "run");
const reconcile = result.calls.findIndex(args => args.includes("./build/scripts/reconcile-legacy-owner-alerts.js"));
expect(reconcile).to.be.greaterThan(stop); expect(reconcile).to.be.lessThan(up);
expect(result.calls[reconcile]).to.include("./build/scripts/reconcile-legacy-owner-alerts.js");
const checked = result.calls.slice(stop + 1, up).filter(args => args[0] === "inspect").map(args => args.at(-1));
@@ -87,7 +104,7 @@ finish("unexpected docker call", 2);
const result = deploy({ oldProtocol: "recipient-v1" });
expect(result.status, result.stderr).to.equal(0);
const stop = result.calls.findIndex(args => args[0] === "compose" && args[1] === "stop");
const reconcile = result.calls.findIndex(args => args[0] === "compose" && args[1] === "run");
const reconcile = result.calls.findIndex(args => args.includes("./build/scripts/reconcile-legacy-owner-alerts.js"));
const up = result.calls.findIndex(args => args[0] === "compose" && args[1] === "up");
expect(stop).to.be.greaterThan(-1); expect(reconcile).to.be.greaterThan(stop); expect(up).to.be.greaterThan(reconcile);
});
@@ -116,7 +133,7 @@ finish("unexpected docker call", 2);
for (const stopped of [true, false]) it(`reconciles legacy ${stopped ? "stopped" : "running"} containers when the replacement was already built`, () => {
const result = deploy({ built: true, stopped, force: 0 });
expect(result.status, result.stderr).to.equal(0);
const reconcile = result.calls.findIndex(args => args[0] === "compose" && args[1] === "run");
const reconcile = result.calls.findIndex(args => args.includes("./build/scripts/reconcile-legacy-owner-alerts.js"));
const up = result.calls.findIndex(args => args[0] === "compose" && args[1] === "up");
expect(reconcile).to.be.greaterThan(-1); expect(up).to.be.greaterThan(reconcile);
expect(result.stdout).not.to.include("nothing to deploy");
+35
View File
@@ -0,0 +1,35 @@
require("ts-node/register/transpile-only");
const { expect } = require("chai");
const { generateKeyPairSync } = require("crypto");
const fs = require("fs"), os = require("os"), path = require("path");
const { checkGitHubAppKey } = require("../src/scripts/check-github-app-key");
describe("GitHub App replacement key preflight", () => {
const pem = generateKeyPairSync("rsa", { modulusLength: 2048 }).privateKey.export({ type: "pkcs8", format: "pem" });
const config = (extra = {}) => ({ GITHUB_APP_ENABLED: true, GITHUB_APP_PRIVATE_KEY: "", GITHUB_APP_PRIVATE_KEY_FILE: "/missing/key.pem", ...extra });
it("allows App-disabled deployments without a key", () => {
expect(() => checkGitHubAppKey(config({ GITHUB_APP_ENABLED: false }))).not.to.throw();
});
it("fails a missing mount without disclosing the path", () => {
let error;
try { checkGitHubAppKey(config()); } catch (caught) { error = caught; }
expect(error.message).to.include("signing key is missing").and.not.to.include("/missing/key.pem");
});
it("checks mounted key contents and accepts inline key precedence", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "app-key-check-"));
const file = path.join(dir, "key.pem");
try {
fs.writeFileSync(file, pem, { mode: 0o600 });
expect(() => checkGitHubAppKey(config({ GITHUB_APP_PRIVATE_KEY_FILE: file }))).not.to.throw();
fs.writeFileSync(file, "secret-invalid-key");
let error;
try { checkGitHubAppKey(config({ GITHUB_APP_PRIVATE_KEY_FILE: file })); } catch (caught) { error = caught; }
expect(error.message).to.include("invalid").and.not.to.include("secret-invalid-key");
expect(() => checkGitHubAppKey(config({ GITHUB_APP_PRIVATE_KEY: pem }))).not.to.throw();
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
});
it("rejects a non-RSA key that cannot produce GitHub RS256 JWTs", () => {
const key = generateKeyPairSync("ec", { namedCurve: "prime256v1" }).privateKey.export({ type: "pkcs8", format: "pem" });
expect(() => checkGitHubAppKey(config({ GITHUB_APP_PRIVATE_KEY: key }))).to.throw("invalid");
});
});
+9
View File
@@ -120,6 +120,15 @@ describe("Runtime regression fixes", function () {
});
describe("Repository.check()", function () {
for (const status of ["removed", "removing", "expired", "expiring"]) it(`reports ${status} without claiming every inactive repository expired`, async () => {
const repo = new Repository({ owner: "507f191e810c19729de860ea", status,
options: { expirationMode: "remove", expirationDate: new Date(Date.now() + 86400000) }, source: {} });
let error;
try { await repo.check(); } catch (caught) { error = caught; }
expect(error?.message).to.equal(status.startsWith("remov") ? "is_removed" : "repository_expired");
expect(error?.httpStatus).to.equal(410);
expect(repo.status).to.equal(status);
});
it("records logical expiration before throwing repository_expired", async function () {
const repo = new Repository({
owner: "507f191e810c19729de860ea",