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
53 changes: 19 additions & 34 deletions server/src/__tests__/issue-list-assignee-filter-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
import express from "express";
import request from "supertest";
import { eq } from "drizzle-orm";
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
import { activityLog, agents, companies, companyMemberships, createDb, heartbeatRuns, issues, principalPermissionGrants } from "@paperclipai/db";
import {
getEmbeddedPostgresTestSupport,
Expand All @@ -12,6 +12,7 @@ import { errorHandler } from "../middleware/index.js";
import {
__clearIssueListResponseCacheForTests,
__getIssueListResponseCacheSizeForTests,
__setIssueListResponseCacheEntryForTests,
ISSUE_LIST_SERVER_CACHE_MAX_ENTRIES,
issueRoutes,
} from "../routes/issues.js";
Expand Down Expand Up @@ -550,40 +551,24 @@ describeEmbeddedPostgres("issue list routes assigneeAgentId filter", () => {
expect(second.headers["x-paperclip-request-cache"]).toBe("hit");
});

it("bounds compact issue-list server cache entries", async () => {
const companyId = randomUUID();
const issueId = randomUUID();

await db.insert(companies).values({
id: companyId,
name: "Paperclip",
issuePrefix: uniqueIssuePrefix(),
requireBoardApprovalForNewAgents: false,
});
await seedCloudTenantMember(companyId);
await db.insert(issues).values({
id: issueId,
companyId,
title: "Bounded cache issue",
status: "todo",
priority: "medium",
});

const app = createApp(companyId);
const fixedNow = Date.now();
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(fixedNow);
try {
for (let index = 0; index < ISSUE_LIST_SERVER_CACHE_MAX_ENTRIES + 5; index += 1) {
const res = await request(app)
.get(`/api/companies/${companyId}/issues`)
.query({ view: "compact", limit: "20", q: `cache-key-${index}` });
expect(res.status, JSON.stringify(res.body)).toBe(200);
}

expect(__getIssueListResponseCacheSizeForTests()).toBe(ISSUE_LIST_SERVER_CACHE_MAX_ENTRIES);
} finally {
nowSpy.mockRestore();
it("bounds compact issue-list server cache entries", () => {
// Drive the exact same insert-and-trim path a real request takes
// (setIssueListResponseCacheEntry), but with synthetic entries inserted
// synchronously instead of 261 real HTTP round trips against Postgres.
// No DB, no HTTP, no awaits — nothing here can time out under a loaded
// runner, and there's no module-global override left to leak into a
// later test if it did.
const syntheticEntry = {
response: { kind: "compact" as const, body: [], etag: "test-etag", cacheControl: "no-store" },
expiresAt: Date.now() + 1_000,
staleUntil: Date.now() + 5_000,
};

for (let index = 0; index < ISSUE_LIST_SERVER_CACHE_MAX_ENTRIES + 5; index += 1) {
__setIssueListResponseCacheEntryForTests(`cache-key-${index}`, syntheticEntry);
}

expect(__getIssueListResponseCacheSizeForTests()).toBe(ISSUE_LIST_SERVER_CACHE_MAX_ENTRIES);
});

it("logs request_storm_detected for identical in-flight compact issue-list fanout without query values", async () => {
Expand Down
4 changes: 4 additions & 0 deletions server/src/routes/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,10 @@ function setIssueListResponseCacheEntry(key: string, entry: IssueListCacheEntry)
trimIssueListResponseCache();
}

export function __setIssueListResponseCacheEntryForTests(key: string, entry: IssueListCacheEntry) {
setIssueListResponseCacheEntry(key, entry);
}

function decrementIssueListActorClientInflight(actorClientKey: string) {
const next = (issueListActorClientInflight.get(actorClientKey) ?? 1) - 1;
if (next <= 0) issueListActorClientInflight.delete(actorClientKey);
Expand Down
Loading