Merge branch 'integrate/source-errors' into fix/source-failure-classification

# Conflicts:
#	public/asset-manifest.json
#	public/script/vendor.min.js
This commit is contained in:
Thomas Durieux committed 2026-11-14 23:21:40 +00:00
commit 70e8ff15cc
22 files changed
+445 -93

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");
});
});
+47
View File
@@ -0,0 +1,47 @@
const { expect } = require("chai");
require("ts-node/register/transpile-only");
const github = require("../src/core/GitHubUtils");
const { repositoryPickerPage } = require("../src/core/github-repository-picker");
describe("repository picker bounded pages", () => {
let original;
beforeEach(() => { original = github.octokit; });
afterEach(() => { github.octokit = original; });
it("fetches only one small upstream page for browsing", async () => {
let calls = 0;
github.octokit = token => ({ request: async (route, params) => {
calls++;
expect(token).to.equal("private-token");
expect(params).to.include({ page: 2, per_page: 20, sort: "full_name" });
return { data: [{ id: 21, full_name: "org/repo" }], headers: {} };
} });
expect(await repositoryPickerPage("private-token", 20)).to.deep.equal({
items: [{ id: 21, fullName: "org/repo" }], nextCursor: null,
});
expect(calls).to.equal(1);
});
it("searches case-insensitively and resumes without skipping matches", async () => {
github.octokit = () => ({ request: async () => ({
data: Array.from({ length: 100 }, (_, id) => ({ id, full_name: `Org/${id % 2 ? "other" : "Match"}-${id}` })),
headers: { link: '<https://api.github.com/user/repos?page=2>; rel="next"' },
}) });
const first = await repositoryPickerPage("token", 0, "org/match");
expect(first.items).to.have.length(20);
expect(first.nextCursor).to.equal(39);
const second = await repositoryPickerPage("token", first.nextCursor, "org/match");
expect(second.items[0].id).to.equal(40);
expect(second.items).to.have.length(20);
});
it("returns a continuation for an empty search batch, not a false end", async () => {
github.octokit = () => ({ request: async () => ({
data: Array.from({ length: 100 }, (_, id) => ({ id, full_name: `org/repo-${id}` })),
headers: { link: '<https://api.github.com/user/repos?page=2>; rel="next"' },
}) });
expect(await repositoryPickerPage("token", 0, "missing")).to.deep.equal({ items: [], nextCursor: 100 });
});
it("propagates upstream failures so the UI can retry", async () => {
github.octokit = () => ({ request: async () => { throw new Error("rate limit"); } });
try { await repositoryPickerPage("token"); throw new Error("unexpected success"); }
catch (error) { expect(error.message).to.equal("rate limit"); }
});
});
+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",
+72
View File
@@ -394,6 +394,78 @@ describe("Vue 3 UI", function () {
expect(ui.errors).to.deep.equal([]);
});
it("pages the repository picker and searches beyond the loaded page", async () => {
ui = await browser("/anonymize", {
"/api/user/repository_picker": request => {
const cursor = Number(request.url.searchParams.get("cursor"));
const q = request.url.searchParams.get("q");
if (q && cursor === 0) return { items: [], nextCursor: 100 };
return { items: [{ id: cursor + 1, fullName: q ? "org/needle" : `org/repo-${cursor}` }], nextCursor: cursor === 0 ? 20 : null };
},
});
const picker = () => ui.window.document.querySelector(".repo-picker");
const button = text => [...picker().querySelectorAll("button")].find(b => b.textContent.trim() === text);
expect(picker().textContent).to.include("repo-0");
expect(button("Previous").disabled).to.equal(true);
button("Next").click();
await delay(30);
expect(picker().textContent).to.include("repo-20");
button("Previous").click();
await delay(30);
expect(picker().textContent).to.include("repo-0");
await ui.input(".repo-picker-filter", "needle");
await delay(350);
expect(picker().textContent).to.include("needle");
expect(picker().textContent).not.to.include("repo-0");
expect(ui.requests.some(r => r.url.searchParams.get("q") === "needle" && r.url.searchParams.get("cursor") === "100")).to.equal(true);
expect(ui.requests.some(r => r.url.pathname === "/api/user/all_repositories")).to.equal(false);
expect(ui.errors).to.deep.equal([]);
});
it("ignores stale repository responses after the search changes", async () => {
let finish;
ui = await browser("/anonymize", {
"/api/user/repository_picker": request => request.url.searchParams.get("q")
? { items: [{ id: 2, fullName: "org/current" }], nextCursor: null }
: new Promise(resolve => { finish = resolve; }),
});
await ui.input(".repo-picker-filter", "current");
await delay(350);
finish({ items: [{ id: 1, fullName: "org/stale" }], nextCursor: 20 });
await delay(30);
const picker = ui.window.document.querySelector(".repo-picker");
expect(picker.textContent).to.include("current");
expect(picker.textContent).not.to.include("stale");
expect(ui.errors).to.deep.equal([]);
});
it("bounds sparse searches and lets the user continue and retry", async () => {
let fail = false;
ui = await browser("/anonymize", {
"/api/user/repository_picker": request => {
if (fail) return { __status: 503, body: {} };
const cursor = Number(request.url.searchParams.get("cursor"));
return { items: [], nextCursor: cursor + 100 };
},
});
await ui.input(".repo-picker-filter", "absent");
await delay(350);
const searches = () => ui.requests.filter(r => r.url.searchParams.get("q") === "absent");
expect(searches()).to.have.length(5);
const button = text => [...ui.window.document.querySelectorAll(".repo-picker button")].find(b => b.textContent.trim() === text);
expect(ui.window.document.querySelector(".repo-picker").textContent).to.include("No matches yet");
fail = true;
button("Continue search").click();
await delay(30);
expect(button("Try again")).not.to.equal(undefined);
fail = false;
button("Try again").click();
await delay(30);
expect(searches()[6].url.searchParams.get("cursor")).to.equal("500");
expect(searches()).to.have.length(11);
expect(ui.errors).to.deep.equal([]);
});
it("starts a deep-linked file and editor before directory listings finish", async () => {
const pendingDirectories = [];
let releaseFile;