Skip to content
Merged
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
13 changes: 9 additions & 4 deletions test/integration/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2173,10 +2173,10 @@ describe("api routes", () => {
vi.stubGlobal("fetch", async () => new Response("Not Found", { status: 404 }));
await upsertRepositorySettings(env, {
repoFullName: "JSONbored/gittensory",
commentMode: "all_prs",
publicSurface: "comment_and_label",
autoLabelEnabled: true,
checkRunMode: "off",
});
await upsertRepoFocusManifest(env, "JSONbored/gittensory", {
settings: { commentMode: "all_prs", publicSurface: "comment_and_label", checkRunMode: "off" },
});
await upsertInstallationHealth(env, {
installationId: 777,
Expand Down Expand Up @@ -2220,7 +2220,12 @@ describe("api routes", () => {
expect(repairBody.eventDiagnostics).toEqual(expect.arrayContaining([expect.objectContaining({ event: "issue_comment", missing: true })]));
expect(JSON.stringify(repairBody)).not.toMatch(/wallet|hotkey|raw trust score|payout|reward estimate|farming|private reviewability|public score estimate|github_pat|private key/i);

await upsertRepositorySettings(env, { repoFullName: "JSONbored/gittensory", checkRunMode: "enabled" });
await upsertRepositorySettings(env, { repoFullName: "JSONbored/gittensory" });
// Re-persist the manifest snapshot (it replaces, not merges) carrying forward the unchanged
// commentMode/publicSurface fields alongside the updated checkRunMode.
await upsertRepoFocusManifest(env, "JSONbored/gittensory", {
settings: { commentMode: "all_prs", publicSurface: "comment_and_label", checkRunMode: "enabled" },
});
await upsertInstallationHealth(env, {
installationId: 777,
accountLogin: "JSONbored",
Expand Down
6 changes: 6 additions & 0 deletions test/integration/public-quality-metrics-route-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ describe("GET /v1/public/repos/:owner/:repo/quality — error path", () => {
it("returns 503 when quality metrics computation throws", async () => {
const env = createTestEnv();
await upsertRepositoryFromGitHub(env, { name: "quality", full_name: "acme/quality", private: false, owner: { login: "acme" }, default_branch: "main" }, 560);
// NOTE: publicQualityMetrics intentionally stays DB-backed here (not moved to the focus manifest)
// because the route under test (`loadPublicRepoQualityMetrics` in src/api/routes.ts) reads
// `getRepositorySettings` directly -- the same deliberate raw-DB-row bypass documented on the sibling
// `loadPublicRepoBadge` helper -- and never consults `resolveRepositorySettings`/the manifest overlay.
// Moving this field to `upsertRepoFocusManifest` would make the route see publicQualityMetrics=false
// (404) instead of true (503 via the mocked throw), which is a real behavior difference, not a wiring bug.
await upsertRepositorySettings(env, { repoFullName: "acme/quality", publicQualityMetrics: true });

const res = await createApp().request("/v1/public/repos/acme/quality/quality", {}, env);
Expand Down
7 changes: 4 additions & 3 deletions test/unit/actions-fallback-webhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { clearInstallationTokenCacheForTest } from "../../src/github/app";
import { clearGitHubResponseCacheForTest } from "../../src/github/client";
import { fallbackShotR2Key, FALLBACK_ARTIFACT_NAME, isFallbackDispatchInFlight, markFallbackDispatched } from "../../src/review/visual/actions-fallback";
import { processJob } from "../../src/queue/processors";
import { upsertRepoFocusManifest } from "../../src/signals/focus-manifest-loader";
import { createTestEnv } from "../helpers/d1";

// Mirrors test/unit/queue.test.ts's own generatePrivateKeyPem helper -- createInstallationToken mints a real
Expand Down Expand Up @@ -115,9 +116,9 @@ async function seedRepoAndPr(env: ReturnType<typeof createTestEnv>, headSha: str
autonomy: { merge: "observe", update_branch: "observe" },
aiReviewMode: "off",
gatePack: "oss-anti-slop",
checkRunMode: "off",
commentMode: "off",
publicSurface: "off",
});
await upsertRepoFocusManifest(env, "owner/fallback-repo", {
settings: { checkRunMode: "off", commentMode: "off", publicSurface: "off" },
});
await upsertPullRequestFromGitHub(env, "owner/fallback-repo", {
number: 55,
Expand Down
75 changes: 35 additions & 40 deletions test/unit/backfill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
} from "../../src/github/client";
import { normalizeRegistryPayload } from "../../src/registry/normalize";
import { persistRegistrySnapshot } from "../../src/registry/sync";
import { upsertRepoFocusManifest } from "../../src/signals/focus-manifest-loader";
import { renderMetrics, resetMetrics } from "../../src/selfhost/metrics";
import { createTestEnv } from "../helpers/d1";

Expand Down Expand Up @@ -725,7 +726,7 @@ describe("GitHub backfill", () => {
});

it("REGRESSION: broker-mode refresh replaces stale local permissions with the broker token permission snapshot", async () => {
const env = createTestEnv({ ORB_ENROLLMENT_SECRET: "orbsec_test", LOOPOVER_DRIFT_ISSUE_REPO: "unrelated-org/unrelated-repo" });
const env = createTestEnv({ ORB_ENROLLMENT_SECRET: "orbsec_test" });
await upsertInstallation(env, {
installation: {
id: 912,
Expand Down Expand Up @@ -994,7 +995,7 @@ describe("GitHub backfill", () => {
});

it("requires Checks write only for repos with check runs enabled", async () => {
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem(), LOOPOVER_DRIFT_ISSUE_REPO: "unrelated-org/unrelated-repo" });
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem() });
await seedRegisteredRepo(env);
await upsertInstallation(env, {
installation: {
Expand All @@ -1008,8 +1009,8 @@ describe("GitHub backfill", () => {
await upsertRepositoryFromGitHub(env, { name: "gittensory", full_name: "JSONbored/gittensory", private: true, owner: { login: "JSONbored" } }, 123);
await upsertRepositorySettings(env, {
repoFullName: "JSONbored/gittensory",
checkRunMode: "enabled",
});
await upsertRepoFocusManifest(env, "JSONbored/gittensory", { settings: { checkRunMode: "enabled" } });
vi.stubGlobal("fetch", async (input: RequestInfo | URL) => {
const url = input.toString();
if (url.endsWith("/app/installations/123")) {
Expand Down Expand Up @@ -1043,7 +1044,7 @@ describe("GitHub backfill", () => {
// the separate reviewCheckMode axis ("LoopOver Orb Review Agent" check) entirely -- so an installation
// whose repos only ever published the review-agent check (true for JSONbored's own 3 production repos,
// none of which set checkRunMode) was never flagged as needing the Checks permission.
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem(), LOOPOVER_DRIFT_ISSUE_REPO: "unrelated-org/unrelated-repo" });
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem() });
await seedRegisteredRepo(env);
await upsertInstallation(env, {
installation: {
Expand Down Expand Up @@ -1088,7 +1089,7 @@ describe("GitHub backfill", () => {
});

it("REGRESSION (#audit-install-health): an acting autonomy requires pull_requests:write, so read-only is needs_attention not healthy", async () => {
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem(), LOOPOVER_DRIFT_ISSUE_REPO: "unrelated-org/unrelated-repo" });
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem() });
await seedRegisteredRepo(env);
await upsertInstallation(env, {
installation: {
Expand Down Expand Up @@ -1131,7 +1132,7 @@ describe("GitHub backfill", () => {
});

it("REGRESSION: merge autonomy requires contents:write, so contents:read is needs_attention before merge 403s", async () => {
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem(), LOOPOVER_DRIFT_ISSUE_REPO: "unrelated-org/unrelated-repo" });
const env = createTestEnv({ GITHUB_APP_PRIVATE_KEY: await generatePrivateKeyPem() });
await seedRegisteredRepo(env);
await upsertInstallation(env, {
installation: {
Expand Down Expand Up @@ -1177,10 +1178,10 @@ describe("GitHub backfill", () => {
await upsertRepositoryFromGitHub(env, { name: "gittensory", full_name: "JSONbored/gittensory", private: true, owner: { login: "JSONbored" } }, 123);
await upsertRepositorySettings(env, {
repoFullName: "JSONbored/gittensory",
commentMode: "off",
publicSurface: "off",
autoLabelEnabled: false,
checkRunMode: "off",
});
await upsertRepoFocusManifest(env, "JSONbored/gittensory", {
settings: { commentMode: "off", publicSurface: "off", checkRunMode: "off" },
});
// Without this, the manifest resolver's live (unmocked) GitHub fetch for "JSONbored/gittensory"'s
// .loopover.yml actually succeeds -- GitHub's repo-rename redirect resolves it to this same repo's
Expand Down Expand Up @@ -1288,17 +1289,17 @@ describe("GitHub backfill", () => {
await upsertRepositoryFromGitHub(env, { name: "labels", full_name: "JSONbored/labels", private: true, owner: { login: "JSONbored" } }, 124);
await upsertRepositorySettings(env, {
repoFullName: "JSONbored/comments",
commentMode: "detected_contributors_only",
publicSurface: "comment_only",
autoLabelEnabled: false,
checkRunMode: "off",
});
await upsertRepoFocusManifest(env, "JSONbored/comments", {
settings: { commentMode: "detected_contributors_only", publicSurface: "comment_only", checkRunMode: "off" },
});
await upsertRepositorySettings(env, {
repoFullName: "JSONbored/labels",
commentMode: "off",
publicSurface: "label_only",
autoLabelEnabled: true,
checkRunMode: "off",
});
await upsertRepoFocusManifest(env, "JSONbored/labels", {
settings: { commentMode: "off", publicSurface: "label_only", checkRunMode: "off" },
});

const repair = await buildInstallationRepairDiagnostics(env, {
Expand Down Expand Up @@ -1423,11 +1424,9 @@ describe("GitHub backfill", () => {
await seedInstalledAndRegisteredRepo(env);
await upsertRepositorySettings(env, {
repoFullName: "JSONbored/gittensory",
commentMode: "off",
publicSignalLevel: "standard",
checkRunMode: "enabled",
checkRunDetailLevel: "standard",
backfillEnabled: false,
});
await upsertRepoFocusManifest(env, "JSONbored/gittensory", {
settings: { commentMode: "off", publicSignalLevel: "standard", checkRunMode: "enabled", checkRunDetailLevel: "standard", backfillEnabled: false },
});

const result = await backfillRegisteredRepositories(env);
Expand Down Expand Up @@ -3503,23 +3502,19 @@ describe("GitHub backfill", () => {
await seedRegisteredRepo(env);
await upsertRepositorySettings(env, {
repoFullName: "JSONbored/gittensory",
commentMode: "off",
publicSignalLevel: "standard",
checkRunMode: "enabled",
checkRunDetailLevel: "standard",
backfillEnabled: false,
});
await upsertRepoFocusManifest(env, "JSONbored/gittensory", {
settings: { commentMode: "off", publicSignalLevel: "standard", checkRunMode: "enabled", checkRunDetailLevel: "standard", backfillEnabled: false },
});

await expect(enqueueRepositoryOpenDataBackfill(env, { repoFullName: "missing/repo", requestedBy: "api" })).resolves.toMatchObject({ status: "skipped" });
await expect(enqueueRepositoryOpenDataBackfill(env, { repoFullName: "JSONbored/gittensory", requestedBy: "api" })).resolves.toMatchObject({ status: "skipped" });

await upsertRepositorySettings(env, {
repoFullName: "JSONbored/gittensory",
commentMode: "off",
publicSignalLevel: "standard",
checkRunMode: "enabled",
checkRunDetailLevel: "standard",
backfillEnabled: true,
});
await upsertRepoFocusManifest(env, "JSONbored/gittensory", {
settings: { commentMode: "off", publicSignalLevel: "standard", checkRunMode: "enabled", checkRunDetailLevel: "standard", backfillEnabled: true },
});
await upsertRepoSyncSegment(env, {
repoFullName: "JSONbored/gittensory",
Expand Down Expand Up @@ -4609,7 +4604,7 @@ describe("fetchLinkedIssueClosedByPullRequest (#5385)", () => {
}

it("returns fetch_error without ever calling fetch when no token is available", async () => {
const env = createTestEnv({});
const env = createTestEnv();
const fetchSpy = vi.fn();
vi.stubGlobal("fetch", fetchSpy);
const result = await fetchLinkedIssueClosedByPullRequest(env, "owner/repo", 100, 200, undefined);
Expand All @@ -4618,7 +4613,7 @@ describe("fetchLinkedIssueClosedByPullRequest (#5385)", () => {
});

it("returns fetch_error without ever calling fetch for a malformed repoFullName (no owner/name split)", async () => {
const env = createTestEnv({});
const env = createTestEnv();
const fetchSpy = vi.fn();
vi.stubGlobal("fetch", fetchSpy);
expect(await fetchLinkedIssueClosedByPullRequest(env, "", 100, 200, "test-token")).toBe("fetch_error");
Expand All @@ -4627,7 +4622,7 @@ describe("fetchLinkedIssueClosedByPullRequest (#5385)", () => {
});

it("returns fetch_error when GraphQL responds 200 OK with a top-level errors array (GitHub's REAL response shape for an unresolvable issue number, confirmed via gh api graphql)", async () => {
const env = createTestEnv({});
const env = createTestEnv();
vi.stubGlobal("fetch", async (input: RequestInfo | URL) =>
input.toString() === "https://github.com/ghapi/graphql"
? Response.json({ data: { repository: { issue: null } }, errors: [{ type: "NOT_FOUND", message: "Could not resolve to an issue." }] })
Expand All @@ -4638,7 +4633,7 @@ describe("fetchLinkedIssueClosedByPullRequest (#5385)", () => {
});

it("returns fetch_error when timelineItems.nodes is missing/non-array (malformed response, no top-level errors)", async () => {
const env = createTestEnv({});
const env = createTestEnv();
vi.stubGlobal("fetch", async (input: RequestInfo | URL) =>
input.toString() === "https://github.com/ghapi/graphql"
? Response.json({ data: { repository: { issue: { timelineItems: {} } } } })
Expand All @@ -4649,7 +4644,7 @@ describe("fetchLinkedIssueClosedByPullRequest (#5385)", () => {
});

it("returns fetch_error when the GraphQL request itself throws (network failure)", async () => {
const env = createTestEnv({});
const env = createTestEnv();
vi.stubGlobal("fetch", async () => {
throw new Error("network down");
});
Expand All @@ -4658,23 +4653,23 @@ describe("fetchLinkedIssueClosedByPullRequest (#5385)", () => {
});

it("returns closed_by_pull_request when the closer is a matching PullRequest", async () => {
const env = createTestEnv({});
const env = createTestEnv();
vi.stubGlobal("fetch", async (input: RequestInfo | URL) =>
input.toString() === "https://github.com/ghapi/graphql" ? Response.json(closerBody({ typename: "PullRequest", number: 200 })) : new Response("not found", { status: 404 }),
);
expect(await fetchLinkedIssueClosedByPullRequest(env, "owner/repo", 100, 200, "test-token")).toBe("closed_by_pull_request");
});

it("returns not_closed_by_pull_request when the closer is a DIFFERENT PullRequest (anti-spoofing)", async () => {
const env = createTestEnv({});
const env = createTestEnv();
vi.stubGlobal("fetch", async (input: RequestInfo | URL) =>
input.toString() === "https://github.com/ghapi/graphql" ? Response.json(closerBody({ typename: "PullRequest", number: 999 })) : new Response("not found", { status: 404 }),
);
expect(await fetchLinkedIssueClosedByPullRequest(env, "owner/repo", 100, 200, "test-token")).toBe("not_closed_by_pull_request");
});

it("returns not_closed_by_pull_request when the issue was closed manually with no closer at all (confirmed live shape via gh api graphql against JSONbored/gittensory#5130: closer: null)", async () => {
const env = createTestEnv({});
const env = createTestEnv();
vi.stubGlobal("fetch", async (input: RequestInfo | URL) =>
input.toString() === "https://github.com/ghapi/graphql"
? Response.json({ data: { repository: { issue: { timelineItems: { nodes: [{ __typename: "ClosedEvent", closer: null }] } } } } })
Expand All @@ -4684,15 +4679,15 @@ describe("fetchLinkedIssueClosedByPullRequest (#5385)", () => {
});

it("returns not_closed_by_pull_request when the closer is a Commit, not a PullRequest (issue closed via a commit message reference)", async () => {
const env = createTestEnv({});
const env = createTestEnv();
vi.stubGlobal("fetch", async (input: RequestInfo | URL) =>
input.toString() === "https://github.com/ghapi/graphql" ? Response.json(closerBody({ typename: "Commit" })) : new Response("not found", { status: 404 }),
);
expect(await fetchLinkedIssueClosedByPullRequest(env, "owner/repo", 100, 200, "test-token")).toBe("not_closed_by_pull_request");
});

it("returns not_closed_by_pull_request when there is no CLOSED_EVENT at all (nodes is an empty array)", async () => {
const env = createTestEnv({});
const env = createTestEnv();
vi.stubGlobal("fetch", async (input: RequestInfo | URL) =>
input.toString() === "https://github.com/ghapi/graphql" ? Response.json(closerBody(null)) : new Response("not found", { status: 404 }),
);
Expand Down
Loading