mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-29 04:25:52 +01:00
Bumps [jsdom](https://github.com/jsdom/jsdom) and [@types/jsdom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jsdom). These dependencies needed to be updated together. Updates `jsdom` from 28.1.0 to 30.0.1 <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/jsdom/jsdom/releases">jsdom's releases</a>.</em></p> <blockquote> <h2>v30.0.1</h2> <ul> <li>Fixed <code>getComputedStyle()</code> with <code>calc()</code> and other functions throwing an exception, which regressed in v30.0.0. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Sped up up range operations on large documents (<a href="https://github.com/leonidaz"><code>@leonidaz</code></a>)</li> </ul> <h2>v30.0.0</h2> <p>Breaking changes:</p> <ul> <li>Node.js minimum version raised to <code>^22.22.2 || ^24.15.0 || >=26.0.0</code>.</li> </ul> <p>Other changes:</p> <ul> <li>Added <code>CSS.escape()</code> and <code>CSS.supports()</code> functions. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Added <code>'background-position-x'</code> and <code>'background-position-y'</code> CSS properties. (<a href="https://github.com/olagokemills"><code>@olagokemills</code></a>)</li> <li>Fixed <code>getComputedStyle()</code> to convert length values into pixels. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Fixed CSS function serialization, e.g., in the return value of <code>getPropertyValue()</code>. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Fixed the type of error thrown by <code>document.evaluate()</code> (<a href="https://github.com/dokson"><code>@dokson</code></a>)</li> </ul> <h2>v29.1.1</h2> <ul> <li>Fixed <code>'border-radius'</code> computed style serialization. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Fixed computed style computation when using <code>'background-origin'</code> and <code>'background-clip'</code> CSS properties. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Significantly optimized initial calls to <code>getComputedStyle()</code>, before the cache warms up. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> </ul> <h2>v29.1.0</h2> <ul> <li>Added basic support for the ratio CSS type. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Fixed <code>getComputedStyle()</code> sometimes returning outdated results after CSS was modified. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> </ul> <h2>v29.0.2</h2> <ul> <li>Significantly improved and sped up <code>getComputedStyle()</code>. Computed value rules are now applied across a broader set of properties, and include fixes related to inheritance, defaulting keywords, custom properties, and color-related values such as <code>currentcolor</code> and system colors. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Fixed CSS <code>'background</code>' and <code>'border'</code> shorthand parsing. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> </ul> <h2>v29.0.1</h2> <ul> <li>Fixed CSS parsing of <code>'border'</code>, <code>'background'</code>, and their sub-shorthands containing keywords or <code>var()</code>. (<a href="https://github.com/asamuzaK"><code>@asamuzaK</code></a>)</li> <li>Fixed <code>getComputedStyle()</code> to return a more functional <code>CSSStyleDeclaration</code> object, including indexed access support, which regressed in v29.0.0.</li> </ul> <h2>v29.0.0</h2> <p>Breaking changes:</p> <ul> <li>Node.js v22.13.0+ is now the minimum supported v22 version (was v22.12.0+).</li> </ul> <p>Other changes:</p> <ul> <li>Overhauled the CSSOM implementation, replacing the <a href="https://www.npmjs.com/package/@acemir/cssom"><code>@acemir/cssom</code></a> and <a href="https://github.com/jsdom/cssstyle"><code>cssstyle</code></a> dependencies with fresh internal implementations built on webidl2js wrappers and the <a href="https://www.npmjs.com/package/css-tree"><code>css-tree</code></a> parser. Serialization, parsing, and API behavior is improved in various ways, especially around edge cases.</li> <li>Added <code>CSSCounterStyleRule</code> and <code>CSSNamespaceRule</code> to jsdom <code>Window</code>s.</li> <li>Added <code>cssMediaRule.matches</code> and <code>cssSupportsRule.matches</code> getters.</li> <li>Added proper media query parsing in <code>MediaList</code>, using <code>css-tree</code> instead of naive comma-splitting. Invalid queries become <code>"not all"</code> per spec.</li> <li>Added <code>cssKeyframeRule.keyText</code> getter/setter validation.</li> <li>Added <code>cssStyleRule.selectorText</code> setter validation: invalid selectors are now rejected.</li> <li>Added <code>styleSheet.ownerNode</code>, <code>styleSheet.href</code>, and <code>styleSheet.title</code>.</li> <li>Added bad port blocking per the <a href="https://fetch.spec.whatwg.org/#bad-port">fetch specification</a>, preventing fetches to commonly-abused ports.</li> <li>Improved <code>Document</code> initialization performance by lazily initializing the CSS selector engine, avoiding ~0.5 ms of overhead per <code>Document</code>. (<a href="https://github.com/thypon"><code>@thypon</code></a>)</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/jsdom/jsdom/commit/6584485f094d5b271553005b68804c93a455c002"><code>6584485</code></a> 30.0.1</li> <li><a href="https://github.com/jsdom/jsdom/commit/0c51df6d80567202e969ba273c32db01de43c26e"><code>0c51df6</code></a> Update dependencies and dev dependencies</li> <li><a href="https://github.com/jsdom/jsdom/commit/32adb340bf3782194099c6a7b0e0a34c05aa8f24"><code>32adb34</code></a> Bump <code>@asamuzakjp/dom-selector</code></li> <li><a href="https://github.com/jsdom/jsdom/commit/70f014aa1de06a684b4f7d123bdb832ae8c63c53"><code>70f014a</code></a> Speed up range operations on large documents</li> <li><a href="https://github.com/jsdom/jsdom/commit/250d7ee387109d9674d3e4a79fe1edac96e45476"><code>250d7ee</code></a> Partially fix getComputedStyle with calc()</li> <li><a href="https://github.com/jsdom/jsdom/commit/20a01fc4a5ca1b2a48ec9c546d230624964d2f83"><code>20a01fc</code></a> 30.0.0</li> <li><a href="https://github.com/jsdom/jsdom/commit/8c8e583c4f0130f09a1f0ba2728c9aebc4f709c5"><code>8c8e583</code></a> Precompute WPT expectation matches</li> <li><a href="https://github.com/jsdom/jsdom/commit/f32245cfedf894b933bf4625b5649c284422da45"><code>f32245c</code></a> Bump Node.js floor and dependencies</li> <li><a href="https://github.com/jsdom/jsdom/commit/03ef23b4513af92d89d59b2383c5697a0a260111"><code>03ef23b</code></a> Add background-position longhands</li> <li><a href="https://github.com/jsdom/jsdom/commit/ded056f38de1a1e3709feafd0acea57377f85f35"><code>ded056f</code></a> Test CSS.escape() with numeric IDs</li> <li>Additional commits viewable in <a href="https://github.com/jsdom/jsdom/compare/v28.1.0...v30.0.1">compare view</a></li> </ul> </details> <details> <summary>Maintainer changes</summary> <p>This version was pushed to npm by <a href="https://www.npmjs.com/~GitHub%20Actions">GitHub Actions</a>, a new releaser for jsdom since your current version.</p> </details> <details> <summary>Install script changes</summary> <p>This version modifies <code>prepare</code> script that runs during installation. Review the package contents before updating.</p> </details> <br /> Updates `@types/jsdom` from 28.0.0 to 30.0.0 <details> <summary>Commits</summary> <ul> <li>See full diff in <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jsdom">compare view</a></li> </ul> </details> <br /> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Priya Raman <priya@paperclip.ing> Co-authored-by: Paperclip <noreply@paperclip.ing>
304 lines
10 KiB
TypeScript
304 lines
10 KiB
TypeScript
import express from "express";
|
|
import request from "supertest";
|
|
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const issueId = "11111111-1111-4111-8111-111111111111";
|
|
const companyId = "22222222-2222-4222-8222-222222222222";
|
|
const ownerAgentId = "33333333-3333-4333-8333-333333333333";
|
|
const peerAgentId = "44444444-4444-4444-8444-444444444444";
|
|
const ownerRunId = "55555555-5555-4555-8555-555555555555";
|
|
|
|
const mockIssueService = vi.hoisted(() => ({
|
|
assertCheckoutOwner: vi.fn(),
|
|
getById: vi.fn(),
|
|
}));
|
|
|
|
const mockAccessService = vi.hoisted(() => ({
|
|
decide: vi.fn(),
|
|
hasPermission: vi.fn(),
|
|
}));
|
|
|
|
const mockAgentService = vi.hoisted(() => ({
|
|
list: vi.fn(),
|
|
}));
|
|
|
|
const mockExternalObjectsService = vi.hoisted(() => ({
|
|
getIssueSummary: vi.fn(),
|
|
getIssueSummaries: vi.fn(),
|
|
listForIssue: vi.fn(),
|
|
refreshIssueObjects: vi.fn(),
|
|
}));
|
|
const mockInstanceSettingsService = vi.hoisted(() => ({
|
|
getExperimental: vi.fn(),
|
|
}));
|
|
|
|
function registerRouteMocks() {
|
|
vi.doMock("../services/external-objects.js", () => ({
|
|
externalObjectService: () => mockExternalObjectsService,
|
|
}));
|
|
|
|
vi.doMock("../services/instance-settings.js", () => ({
|
|
instanceSettingsService: () => mockInstanceSettingsService,
|
|
}));
|
|
|
|
vi.doMock("../services/task-watchdog-scope.js", () => ({
|
|
TASK_WATCHDOG_ORIGIN_KIND: "task_watchdog",
|
|
resolveTaskWatchdogMutationScope: vi.fn(async () => ({ kind: "none" })),
|
|
taskWatchdogScopeAllowsIssueMutation: vi.fn(async () => ({ kind: "none" })),
|
|
}));
|
|
|
|
vi.doMock("../services/index.js", () => ({
|
|
accessService: () => mockAccessService,
|
|
agentService: () => mockAgentService,
|
|
companySkillService: () => ({}),
|
|
companyService: () => ({
|
|
getById: vi.fn(async () => null),
|
|
}),
|
|
companySearchService: () => ({}),
|
|
documentAnnotationService: () => ({}),
|
|
documentService: () => ({}),
|
|
executionWorkspaceService: () => ({}),
|
|
feedbackService: () => ({}),
|
|
goalService: () => ({}),
|
|
heartbeatService: () => ({
|
|
wakeup: vi.fn(async () => undefined),
|
|
reportRunActivity: vi.fn(async () => undefined),
|
|
getRun: vi.fn(async () => null),
|
|
getActiveRunForAgent: vi.fn(async () => null),
|
|
cancelRun: vi.fn(async () => null),
|
|
}),
|
|
issueApprovalService: () => ({}),
|
|
issueRecoveryActionService: () => ({}),
|
|
issueReferenceService: () => ({
|
|
listIssueReferenceSummary: async () => ({ outbound: [], inbound: [] }),
|
|
}),
|
|
issueService: () => mockIssueService,
|
|
issueThreadInteractionService: () => ({}),
|
|
logActivity: vi.fn(async () => undefined),
|
|
projectService: () => ({}),
|
|
routineService: () => ({}),
|
|
workProductService: () => ({}),
|
|
}));
|
|
}
|
|
|
|
function makeIssue(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
id: issueId,
|
|
companyId,
|
|
status: "in_progress",
|
|
priority: "medium",
|
|
projectId: null,
|
|
goalId: null,
|
|
parentId: null,
|
|
assigneeAgentId: ownerAgentId,
|
|
assigneeUserId: null,
|
|
identifier: "PAP-2265",
|
|
title: "External object routes",
|
|
executionWorkspaceId: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
async function createApp(actor: Express.Request["actor"]) {
|
|
const [{ errorHandler }, { issueRoutes }] = await Promise.all([
|
|
vi.importActual<typeof import("../middleware/index.js")>("../middleware/index.js"),
|
|
vi.importActual<typeof import("../routes/issues.js")>("../routes/issues.js"),
|
|
]);
|
|
const routeDb = {
|
|
select: vi.fn(() => ({
|
|
from: vi.fn(() => ({
|
|
where: vi.fn(async () => [makeIssue()]),
|
|
})),
|
|
})),
|
|
};
|
|
const app = express();
|
|
app.use(express.json());
|
|
app.use((req, _res, next) => {
|
|
req.actor = actor;
|
|
next();
|
|
});
|
|
app.use("/api", issueRoutes(routeDb as any, { provider: "local_disk" } as any));
|
|
app.use(errorHandler);
|
|
return app;
|
|
}
|
|
|
|
function boardActor(): Express.Request["actor"] {
|
|
return {
|
|
type: "board",
|
|
userId: "board-user",
|
|
userName: null,
|
|
userEmail: null,
|
|
companyIds: [companyId],
|
|
memberships: [],
|
|
isInstanceAdmin: false,
|
|
source: "local_implicit",
|
|
};
|
|
}
|
|
|
|
function ownerActor(): Express.Request["actor"] {
|
|
return {
|
|
type: "agent",
|
|
agentId: ownerAgentId,
|
|
companyId,
|
|
keyId: "key-1",
|
|
runId: ownerRunId,
|
|
source: "agent_key",
|
|
};
|
|
}
|
|
|
|
function peerActor(): Express.Request["actor"] {
|
|
return {
|
|
type: "agent",
|
|
agentId: peerAgentId,
|
|
companyId,
|
|
keyId: "key-2",
|
|
runId: "66666666-6666-4666-8666-666666666666",
|
|
source: "agent_key",
|
|
};
|
|
}
|
|
|
|
describe("external object routes", () => {
|
|
// Load the real route and middleware modules once before the tests run. The
|
|
// first import transforms a large module graph. Under the loaded serial shard
|
|
// (maxWorkers=1) that cold cost crossed the 5s testTimeout of the first test.
|
|
// The hook has a 30s budget, so it absorbs the transform cost and every later
|
|
// createApp() call hits the cached modules.
|
|
beforeAll(async () => {
|
|
await createApp(boardActor());
|
|
});
|
|
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
vi.doUnmock("../routes/issues.js");
|
|
vi.doUnmock("../services/index.js");
|
|
vi.doUnmock("../services/external-objects.js");
|
|
registerRouteMocks();
|
|
vi.resetAllMocks();
|
|
mockIssueService.getById.mockResolvedValue(makeIssue());
|
|
mockIssueService.assertCheckoutOwner.mockResolvedValue({ adoptedFromRunId: null });
|
|
mockAccessService.hasPermission.mockResolvedValue(false);
|
|
mockAccessService.decide.mockImplementation(async ({ action }: { action: string }) => ({
|
|
allowed: action === "issue:read" || action === "issue:mutate",
|
|
explanation: "Denied by test mock",
|
|
}));
|
|
mockAgentService.list.mockResolvedValue([
|
|
{ id: ownerAgentId, companyId, reportsTo: null, permissions: { canCreateAgents: false } },
|
|
{ id: peerAgentId, companyId, reportsTo: null, permissions: { canCreateAgents: false } },
|
|
]);
|
|
mockExternalObjectsService.getIssueSummary.mockResolvedValue({ total: 1, objects: [] });
|
|
mockExternalObjectsService.getIssueSummaries.mockImplementation(async (_companyId: string, issueIds: string[]) =>
|
|
new Map(issueIds.map((id) => [id, { total: 1, objects: [] }])),
|
|
);
|
|
mockExternalObjectsService.listForIssue.mockResolvedValue([]);
|
|
mockExternalObjectsService.refreshIssueObjects.mockResolvedValue([
|
|
{ object: { id: "77777777-7777-4777-8777-777777777777" }, refreshed: false, reason: "no_resolver" },
|
|
]);
|
|
mockInstanceSettingsService.getExperimental.mockResolvedValue({
|
|
enableExternalObjects: true,
|
|
});
|
|
});
|
|
|
|
it("enforces company access on read routes", async () => {
|
|
const app = await createApp({ ...ownerActor(), companyId: "other-company" });
|
|
|
|
const res = await request(app).get(`/api/issues/${issueId}/external-object-summary`);
|
|
|
|
// Uniform 404 so cross-tenant ids are indistinguishable from missing ones.
|
|
expect(res.status).toBe(404);
|
|
expect(res.body.error).toBe("Issue not found");
|
|
expect(mockExternalObjectsService.getIssueSummary).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("allows board users to read issue external object summaries", async () => {
|
|
const app = await createApp(boardActor());
|
|
|
|
const res = await request(app).get(`/api/issues/${issueId}/external-object-summary`);
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.total).toBe(1);
|
|
expect(mockExternalObjectsService.getIssueSummary).toHaveBeenCalledWith(issueId);
|
|
});
|
|
|
|
it("requires issue read access before reading issue external objects", async () => {
|
|
mockAccessService.decide.mockResolvedValue({
|
|
allowed: false,
|
|
explanation: "Denied by test mock",
|
|
});
|
|
const app = await createApp(ownerActor());
|
|
|
|
const summary = await request(app).get(`/api/issues/${issueId}/external-object-summary`);
|
|
expect(summary.status).toBe(403);
|
|
expect(mockExternalObjectsService.getIssueSummary).not.toHaveBeenCalled();
|
|
|
|
const list = await request(app).get(`/api/issues/${issueId}/external-objects`);
|
|
expect(list.status).toBe(403);
|
|
expect(mockExternalObjectsService.listForIssue).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("allows board users to fetch company-scoped external object summaries in bulk", async () => {
|
|
const app = await createApp(boardActor());
|
|
|
|
const res = await request(app)
|
|
.post(`/api/companies/${companyId}/issues/external-object-summaries`)
|
|
.send({ issueIds: [issueId] });
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.summaries[issueId].total).toBe(1);
|
|
expect(mockExternalObjectsService.getIssueSummaries).toHaveBeenCalledWith(companyId, [issueId]);
|
|
});
|
|
|
|
it("filters bulk external object summaries through issue read access", async () => {
|
|
mockAccessService.decide.mockResolvedValue({
|
|
allowed: false,
|
|
explanation: "Denied by test mock",
|
|
});
|
|
const app = await createApp(ownerActor());
|
|
|
|
const res = await request(app)
|
|
.post(`/api/companies/${companyId}/issues/external-object-summaries`)
|
|
.send({ issueIds: [issueId] });
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.summaries).toEqual({});
|
|
expect(mockExternalObjectsService.getIssueSummaries).toHaveBeenCalledWith(companyId, []);
|
|
});
|
|
|
|
it("enforces company access on bulk external object summaries", async () => {
|
|
const app = await createApp({ ...ownerActor(), companyId: "other-company" });
|
|
|
|
const res = await request(app)
|
|
.post(`/api/companies/${companyId}/issues/external-object-summaries`)
|
|
.send({ issueIds: [issueId] });
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(mockExternalObjectsService.getIssueSummaries).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("requires active checkout ownership for agent manual refresh", async () => {
|
|
const app = await createApp(peerActor());
|
|
|
|
const res = await request(app)
|
|
.post(`/api/issues/${issueId}/external-objects/refresh`)
|
|
.send({});
|
|
|
|
expect(res.status).toBe(409);
|
|
expect(res.body.details.code).toBe("issue_write_assignee_run_lock");
|
|
expect(mockExternalObjectsService.refreshIssueObjects).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("allows the checked-out agent to request manual refresh", async () => {
|
|
const app = await createApp(ownerActor());
|
|
|
|
const res = await request(app)
|
|
.post(`/api/issues/${issueId}/external-objects/refresh`)
|
|
.send({});
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(mockIssueService.assertCheckoutOwner).toHaveBeenCalledWith(issueId, ownerAgentId, ownerRunId);
|
|
expect(mockExternalObjectsService.refreshIssueObjects).toHaveBeenCalledWith(issueId, expect.objectContaining({
|
|
companyId,
|
|
actor: expect.objectContaining({ actorType: "agent", actorId: ownerAgentId }),
|
|
}));
|
|
});
|
|
});
|