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
7 changes: 6 additions & 1 deletion test/helpers/d1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ export function createTestEnv(overrides: Partial<Env> = {}): Env {
GITTENSOR_UPSTREAM_REF: "test",
GITTENSOR_REGISTRY_URL: "https://github.com/ghraw/entrius/gittensor/test/gittensor/validator/weights/master_repositories.json",
LOOPOVER_AUTO_FILE_DRIFT_ISSUES: "false",
LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory",
// Deliberately NOT "JSONbored/gittensory" (the old pre-rename repo name most test fixtures use as their
// generic placeholder repoFullName) and NOT "JSONbored/loopover" (the real self-repo default) -- either
// would make isLoopOverSelfRepo() accidentally match a fixture that has no intent to exercise self-repo
// manifest resolution, silently merging the bundled autonomy:{...auto} block into that test's settings.
// Tests that DO want self-repo matching set this explicitly to their own fixture's repo name.
LOOPOVER_DRIFT_ISSUE_REPO: "test-harness/no-self-repo-match",
PUBLIC_API_ORIGIN: "https://api.loopover.ai",
PUBLIC_SITE_ORIGIN: "https://loopover.ai",
INTERNAL_JOB_TOKEN: "dev-internal-token",
Expand Down
4 changes: 4 additions & 0 deletions test/integration/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,10 @@ describe("api routes", () => {
repositories: [repoPayload],
});
await upsertRepositoryFromGitHub(env, repoPayload, 777);
// Force a deterministic 404 -- otherwise the manifest resolver's live fetch for "JSONbored/gittensory"'s
// .loopover.yml succeeds via GitHub's repo-rename redirect and returns the CURRENT (broader) autonomy
// grant, which would upgrade requiredPermissions beyond what this test asserts.
vi.stubGlobal("fetch", async () => new Response("Not Found", { status: 404 }));
await upsertRepositorySettings(env, {
repoFullName: "JSONbored/gittensory",
commentMode: "all_prs",
Expand Down
4 changes: 2 additions & 2 deletions test/integration/public-stats-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ describe("GET /v1/public/stats (#1059)", () => {
});

it("a present publicStats manifest override turns the endpoint ON even when LOOPOVER_PUBLIC_STATS is OFF (#6275)", async () => {
const env = createTestEnv(); // flag unset → OFF
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory" }); // flag unset → OFF
await upsertRepoFocusManifest(env, "JSONbored/gittensory", { publicStats: { enabled: true } });
const res = await createApp().request("/v1/public/stats", {}, env);
expect(res.status).toBe(200);
});

it("a present publicStats manifest override turns the endpoint OFF even when LOOPOVER_PUBLIC_STATS is ON (#6275)", async () => {
const env = createTestEnv({ LOOPOVER_PUBLIC_STATS: "1" });
const env = createTestEnv({ LOOPOVER_PUBLIC_STATS: "1", LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory" });
await upsertRepoFocusManifest(env, "JSONbored/gittensory", { publicStats: { enabled: false } });
const res = await createApp().request("/v1/public/stats", {}, env);
expect(res.status).toBe(404);
Expand Down
1 change: 1 addition & 0 deletions test/integration/routes-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ describe("api route guards and error branches", () => {
queued.push(message);
},
} as unknown as Queue,
LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory",
});
vi.stubGlobal("fetch", async (input: RequestInfo | URL) => {
const url = input.toString();
Expand Down
9 changes: 9 additions & 0 deletions test/unit/backfill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,11 @@ describe("GitHub backfill", () => {
autoLabelEnabled: false,
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
// CURRENT .loopover.yml, which now grants full agent autonomy -- silently upgrading the required
// permissions this test asserts are absent. Force the fetch to a deterministic 404 instead.
vi.stubGlobal("fetch", async () => new Response("Not Found", { status: 404 }));

const repair = await buildInstallationRepairDiagnostics(env, {
installationId: 123,
Expand Down Expand Up @@ -1248,6 +1253,10 @@ describe("GitHub backfill", () => {
const env = createTestEnv();
await upsertRepositoryFromGitHub(env, { name: "gittensory", full_name: "JSONbored/gittensory", private: true, owner: { login: "JSONbored" } }, 123);
await upsertRepositorySettings(env, { repoFullName: "JSONbored/gittensory", autonomy: { merge: "auto" } });
// Force a deterministic 404 -- otherwise the manifest resolver's live fetch for "JSONbored/gittensory"'s
// .loopover.yml succeeds via GitHub's repo-rename redirect and returns the CURRENT (broader) autonomy
// grant, which would upgrade requiredPermissions.pull_requests beyond what this test is isolating.
vi.stubGlobal("fetch", async () => new Response("Not Found", { status: 404 }));

const repair = await buildInstallationRepairDiagnostics(env, {
installationId: 123,
Expand Down
12 changes: 6 additions & 6 deletions test/unit/draft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ describe("resolveDraftFlowManifestOverride — config-as-code lookup (#6275)", (
const SELF_REPO = "JSONbored/gittensory";

it("returns the self-repo's configured draftFlow block when present", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { draftFlow: { enabled: true } });

expect(await resolveDraftFlowManifestOverride(env)).toEqual({ present: true, enabled: true });
});

it("returns present: false when the self-repo has no draftFlow block configured", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { wantedPaths: ["src/"] });

expect(await resolveDraftFlowManifestOverride(env)).toEqual({ present: false, enabled: false });
Expand Down Expand Up @@ -147,7 +147,7 @@ describe("draft flow — config-as-code override end-to-end (#6275)", () => {
const SELF_REPO = "JSONbored/gittensory";

it("handleDraftCreate: a present draftFlow override enables the flow even when the env var is off", async () => {
const env = createTestEnv({ GITHUB_OAUTH_CLIENT_ID: "Iv-test-client-id", GITHUB_OAUTH_CLIENT_SECRET: "test-oauth-client-secret", DRAFT_TOKEN_ENCRYPTION_SECRET: DRAFT_SECRET });
const env = createTestEnv({ GITHUB_OAUTH_CLIENT_ID: "Iv-test-client-id", GITHUB_OAUTH_CLIENT_SECRET: "test-oauth-client-secret", DRAFT_TOKEN_ENCRYPTION_SECRET: DRAFT_SECRET, LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { draftFlow: { enabled: true } });

const res = await handleDraftCreate(new Request(`${ORIGIN}/v1/drafts`, { method: "POST", headers: jsonHeaders(), body: JSON.stringify(SAMPLE_FIELDS) }), env);
Expand All @@ -156,7 +156,7 @@ describe("draft flow — config-as-code override end-to-end (#6275)", () => {
});

it("handleDraftCreate: a present draftFlow override disables the flow even when the env var is on", async () => {
const env = draftEnv();
const env = draftEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { draftFlow: { enabled: false } });

const res = await handleDraftCreate(new Request(`${ORIGIN}/v1/drafts`, { method: "POST", headers: jsonHeaders(), body: JSON.stringify(SAMPLE_FIELDS) }), env);
Expand All @@ -165,7 +165,7 @@ describe("draft flow — config-as-code override end-to-end (#6275)", () => {
});

it("processSubmitDraft: a present draftFlow override enables submission even when the env var is off", async () => {
const env = createTestEnv({ DRAFT_TOKEN_ENCRYPTION_SECRET: DRAFT_SECRET });
const env = createTestEnv({ DRAFT_TOKEN_ENCRYPTION_SECRET: DRAFT_SECRET, LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { draftFlow: { enabled: true } });
const id = await seedQueuedDraftWithToken(env);
// A deterministic GitHub 500 (not a real network call) is enough to prove the guard did NOT fire: a fresh,
Expand All @@ -180,7 +180,7 @@ describe("draft flow — config-as-code override end-to-end (#6275)", () => {
});

it("processSubmitDraft: a present draftFlow override disables submission even when the env var is on (no-op, draft stays queued)", async () => {
const env = draftEnv();
const env = draftEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { draftFlow: { enabled: false } });
const id = await seedQueuedDraftWithToken(env);

Expand Down
2 changes: 2 additions & 0 deletions test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ describe("worker entrypoint", () => {
sent.push(message);
},
} as unknown as Queue,
LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory",
});
await upsertRepoFocusManifest(env, "JSONbored/gittensory", { ops: { enabled: true } });
const waitUntil: Promise<unknown>[] = [];
Expand All @@ -788,6 +789,7 @@ describe("worker entrypoint", () => {
sent.push(message);
},
} as unknown as Queue,
LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory",
});
await upsertRepoFocusManifest(env, "JSONbored/gittensory", { ops: { enabled: false } });
const waitUntil: Promise<unknown>[] = [];
Expand Down
4 changes: 2 additions & 2 deletions test/unit/maintainer-recap-wire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ describe("shouldFireMaintainerRecap — cadence gate (#2248)", () => {

describe("resolveMaintainerRecapManifestOverride — config-as-code lookup (#2250)", () => {
it("returns the self-repo's configured maintainerRecap block when present", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { maintainerRecap: { enabled: true, cadence: "daily", channel: "discord" } });

expect(await resolveMaintainerRecapManifestOverride(env)).toEqual({ present: true, enabled: true, cadence: "daily" });
});

it("returns present: false when the self-repo has no maintainerRecap block configured", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { wantedPaths: ["src/"] });

expect(await resolveMaintainerRecapManifestOverride(env)).toEqual({ present: false, enabled: false, cadence: "weekly" });
Expand Down
14 changes: 7 additions & 7 deletions test/unit/ops-wire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ describe("resolveOpsManifestOverride — config-as-code lookup (#6275)", () => {
});

it("returns the self-repo's configured ops block when present", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { ops: { enabled: true } });

expect(await resolveOpsManifestOverride(env)).toEqual({ present: true, enabled: true });
});

it("returns present: false when the self-repo has no ops block configured", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { wantedPaths: ["src/"] });

expect(await resolveOpsManifestOverride(env)).toEqual({ present: false, enabled: false });
});

it("degrades to present: false (never throws) when the manifest load itself fails", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
// loadRepoFocusManifest reads signal_snapshots (the persisted-record cache) before any live fetch fallback.
const realPrepare = env.DB.prepare.bind(env.DB);
env.DB.prepare = ((sql: string) => {
Expand All @@ -105,7 +105,7 @@ describe("resolveOpsManifestOverride — config-as-code lookup (#6275)", () => {
});

it("within the 60s TTL, reuses the cached override instead of re-reading the manifest (#6372 perf)", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { ops: { enabled: true } });
const t0 = Date.parse("2026-07-16T00:00:00Z");
expect(await resolveOpsManifestOverride(env, t0)).toEqual({ present: true, enabled: true });
Expand All @@ -118,7 +118,7 @@ describe("resolveOpsManifestOverride — config-as-code lookup (#6275)", () => {
});

it("re-reads the manifest once the 60s TTL has elapsed", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { ops: { enabled: true } });
const t0 = Date.parse("2026-07-16T00:00:00Z");
expect(await resolveOpsManifestOverride(env, t0)).toEqual({ present: true, enabled: true });
Expand Down Expand Up @@ -717,15 +717,15 @@ describe("GET /v1/internal/ops/stats — bearer-gated, flag-gated endpoint", ()

it("a present ops manifest override turns the endpoint ON even when LOOPOVER_REVIEW_OPS is OFF (#6275)", async () => {
const app = createApp();
const env = createTestEnv(); // flag unset → OFF
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO }); // flag unset → OFF
await upsertRepoFocusManifest(env, SELF_REPO, { ops: { enabled: true } });
const res = await app.request("/v1/internal/ops/stats", { headers: bearer(env) }, env);
expect(res.status).toBe(200);
});

it("a present ops manifest override turns the endpoint OFF even when LOOPOVER_REVIEW_OPS is ON (#6275)", async () => {
const app = createApp();
const env = createTestEnv({ LOOPOVER_REVIEW_OPS: "true" });
const env = createTestEnv({ LOOPOVER_REVIEW_OPS: "true", LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { ops: { enabled: false } });
const res = await app.request("/v1/internal/ops/stats", { headers: bearer(env) }, env);
expect(res.status).toBe(404);
Expand Down
8 changes: 4 additions & 4 deletions test/unit/public-stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ describe("resolvePublicStatsManifestOverride — config-as-code lookup (#6275)",
});

it("returns the self-repo's configured publicStats block when present", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { publicStats: { enabled: true } });

expect(await resolvePublicStatsManifestOverride(env)).toEqual({ present: true, enabled: true });
});

it("returns present: false when the self-repo has no publicStats block configured", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { wantedPaths: ["src/"] });

expect(await resolvePublicStatsManifestOverride(env)).toEqual({ present: false, enabled: false });
Expand All @@ -117,7 +117,7 @@ describe("resolvePublicStatsManifestOverride — config-as-code lookup (#6275)",
});

it("within the 60s TTL, reuses the cached override instead of re-reading the manifest (#6372 perf)", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { publicStats: { enabled: true } });
const t0 = Date.parse("2026-07-16T00:00:00Z");
expect(await resolvePublicStatsManifestOverride(env, t0)).toEqual({ present: true, enabled: true });
Expand All @@ -130,7 +130,7 @@ describe("resolvePublicStatsManifestOverride — config-as-code lookup (#6275)",
});

it("re-reads the manifest once the 60s TTL has elapsed", async () => {
const env = createTestEnv();
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: SELF_REPO });
await upsertRepoFocusManifest(env, SELF_REPO, { publicStats: { enabled: true } });
const t0 = Date.parse("2026-07-16T00:00:00Z");
expect(await resolvePublicStatsManifestOverride(env, t0)).toEqual({ present: true, enabled: true });
Expand Down
2 changes: 1 addition & 1 deletion test/unit/queue-5.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5862,7 +5862,7 @@ describe("queue processors", () => {
});

it("ops-alerts job runs the scan when a present ops manifest override turns it ON even though LOOPOVER_REVIEW_OPS is OFF (#6275)", async () => {
const env = createTestEnv(); // flag unset → OFF
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory" }); // flag unset → OFF
await upsertRepoFocusManifest(env, "JSONbored/gittensory", { ops: { enabled: true } });
await env.DB.prepare("INSERT INTO repositories (full_name, owner, name, is_installed, is_registered) VALUES (?, ?, ?, 1, 1)")
.bind("owner/repo", "owner", "repo")
Expand Down
4 changes: 2 additions & 2 deletions test/unit/queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ describe("queue processors", () => {
});

it("dispatch-level gate: resolves the upstreamDriftIssues manifest override and threads it into fileUpstreamDriftIssues (#6275)", async () => {
const env = createTestEnv(); // LOOPOVER_AUTO_FILE_DRIFT_ISSUES defaults to "false"
const env = createTestEnv({ LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory" }); // LOOPOVER_AUTO_FILE_DRIFT_ISSUES defaults to "false"
await upsertRepoFocusManifest(env, "JSONbored/gittensory", { upstreamDriftIssues: { enabled: true } });
const spy = vi.spyOn(rulesetModule, "fileUpstreamDriftIssues").mockResolvedValue({ status: "completed", created: 0, updated: 0, skipped: 0 });

Expand All @@ -697,7 +697,7 @@ describe("queue processors", () => {
});

it("dispatch-level gate: skips fileUpstreamDriftIssues entirely when a present override disables it (env var otherwise on)", async () => {
const env = createTestEnv({ LOOPOVER_AUTO_FILE_DRIFT_ISSUES: "true" });
const env = createTestEnv({ LOOPOVER_AUTO_FILE_DRIFT_ISSUES: "true", LOOPOVER_DRIFT_ISSUE_REPO: "JSONbored/gittensory" });
await upsertRepoFocusManifest(env, "JSONbored/gittensory", { upstreamDriftIssues: { enabled: false } });
const spy = vi.spyOn(rulesetModule, "fileUpstreamDriftIssues");

Expand Down
Loading