Skip to content

Commit da21772

Browse files
authored
fix: scope plugin runtime identities to publishers (#3562)
1 parent 0699d1a commit da21772

7 files changed

Lines changed: 348 additions & 25 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
### Fixes
1111

12+
- API: scope code-plugin runtime identity claims to the owning publisher so community and official packages can retain their manifest ids under distinct scoped names, while rejecting same-owner collisions during publication, transfer, restore, and administrative repair.
1213
- UI proof: supervise isolated loopback backend and browser proof together without writing project dotenv, preserving diagnostics and private-state cleanup on failure.
1314
- CI: authenticate weekly design-audit pull request mutations with the Barnacle GitHub App while retaining the workflow token for branch publication and clean-audit closure.
1415
- API: record skipped and failed skill evaluation outcomes without passing worker tokens to internal mutations.

‎convex/packages.public.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,9 @@ function makeInsertReleaseCtx(
22832283
const runtimeId = filters.get("runtimeId");
22842284
const matches = runtimePackages.filter((pkg) => pkg.runtimeId === runtimeId);
22852285
return {
2286+
async *[Symbol.asyncIterator]() {
2287+
yield* matches;
2288+
},
22862289
collect: vi.fn().mockResolvedValue(matches),
22872290
unique: vi.fn().mockResolvedValue(matches[0] ?? null),
22882291
};
@@ -2558,6 +2561,9 @@ function makeTransferPackageOwnerCtx(options?: {
25582561
withIndex: vi.fn(() => ({
25592562
unique: vi.fn().mockResolvedValue(pkg),
25602563
collect: vi.fn().mockResolvedValue(pkg ? [pkg] : []),
2564+
async *[Symbol.asyncIterator]() {
2565+
if (pkg) yield pkg;
2566+
},
25612567
})),
25622568
};
25632569
}
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
/// <reference types="vite/client" />
2+
/* @vitest-environment edge-runtime */
3+
4+
import { convexTest } from "convex-test";
5+
import { describe, expect, it } from "vitest";
6+
import { internal } from "./_generated/api";
7+
import type { Id } from "./_generated/dataModel";
8+
import schema from "./schema";
9+
10+
const modules = import.meta.glob("./**/*.ts");
11+
type Backend = ReturnType<typeof convexTest>;
12+
type Owner = { ownerUserId: Id<"users">; ownerPublisherId?: Id<"publishers"> };
13+
14+
async function fixture() {
15+
const t = convexTest({ schema, modules, transactionLimits: true });
16+
const owners = await t.run(async (ctx) => {
17+
const admin = await ctx.db.insert("users", { role: "admin", handle: "operator" });
18+
const user = await ctx.db.insert("users", { handle: "community" });
19+
const personal = await ctx.db.insert("publishers", {
20+
kind: "user",
21+
handle: "community",
22+
displayName: "Community",
23+
linkedUserId: user,
24+
createdAt: 1,
25+
updatedAt: 1,
26+
});
27+
const org = await ctx.db.insert("publishers", {
28+
kind: "org",
29+
handle: "canonical",
30+
displayName: "Canonical",
31+
createdAt: 1,
32+
updatedAt: 1,
33+
});
34+
const secondOrg = await ctx.db.insert("publishers", {
35+
kind: "org",
36+
handle: "another",
37+
displayName: "Another",
38+
createdAt: 1,
39+
updatedAt: 1,
40+
});
41+
return {
42+
admin,
43+
community: { ownerUserId: user, ownerPublisherId: personal },
44+
legacy: { ownerUserId: user },
45+
canonical: { ownerUserId: admin, ownerPublisherId: org },
46+
another: { ownerUserId: admin, ownerPublisherId: secondOrg },
47+
};
48+
});
49+
return { t, ...owners };
50+
}
51+
52+
async function publish(
53+
t: Backend,
54+
actorUserId: Id<"users">,
55+
owner: Owner,
56+
name: string,
57+
options: { runtimeId?: string; version?: string; pending?: boolean } = {},
58+
) {
59+
return await t.mutation(internal.packages.insertReleaseInternal, {
60+
actorUserId,
61+
...owner,
62+
name,
63+
displayName: name,
64+
family: "code-plugin",
65+
version: options.version ?? "1.0.0",
66+
runtimeId: options.runtimeId ?? "voice",
67+
publicationStatus: options.pending ? "pending" : "published",
68+
changelog: "Initial release",
69+
tags: ["latest"],
70+
summary: "Voice plugin",
71+
files: [],
72+
integritySha256: "a".repeat(64),
73+
sha256hash: "b".repeat(64),
74+
extractedPluginManifest: { id: options.runtimeId ?? "voice" },
75+
});
76+
}
77+
78+
describe("owner-scoped package runtime identity", () => {
79+
it("separates organizations even when the uploader is the same", async () => {
80+
const { t, admin, canonical, another } = await fixture();
81+
await publish(t, admin, canonical, "@canonical/voice-provider");
82+
await expect(publish(t, admin, another, "@another/voice-provider")).resolves.toMatchObject({
83+
ok: true,
84+
});
85+
});
86+
87+
it("keeps one organization namespace when a different admin uploads", async () => {
88+
const { t, admin, canonical } = await fixture();
89+
await publish(t, admin, canonical, "@canonical/voice-one");
90+
const secondAdmin = await t.run(async (ctx) => ctx.db.insert("users", { role: "admin" }));
91+
await expect(
92+
publish(t, secondAdmin, { ...canonical, ownerUserId: secondAdmin }, "@canonical/voice-two"),
93+
).rejects.toThrow("already claimed");
94+
});
95+
96+
it("publishes different owners' same runtime without changing either artifact identity", async () => {
97+
const { t, admin, community, canonical } = await fixture();
98+
const original = await publish(t, admin, community, "@community/voice-tools");
99+
const before = await t.run(async (ctx) => ctx.db.get(original.releaseId));
100+
const official = await publish(t, admin, canonical, "@canonical/voice-provider");
101+
const rows = await t.run(async (ctx) => ({
102+
community: await ctx.db.get(original.packageId),
103+
canonical: await ctx.db.get(official.packageId),
104+
originalRelease: await ctx.db.get(original.releaseId),
105+
}));
106+
expect(rows.community).toMatchObject({
107+
name: "@community/voice-tools",
108+
runtimeId: "voice",
109+
...community,
110+
});
111+
expect(rows.canonical).toMatchObject({
112+
name: "@canonical/voice-provider",
113+
runtimeId: "voice",
114+
...canonical,
115+
});
116+
expect(rows.originalRelease).toEqual(before);
117+
});
118+
119+
it.each(["personal-first", "legacy-first"])(
120+
"keeps personal and legacy user ownership in one namespace (%s)",
121+
async (order) => {
122+
const { t, admin, community, legacy } = await fixture();
123+
const [first, second] =
124+
order === "personal-first" ? [community, legacy] : [legacy, community];
125+
await publish(t, admin, first, "@community/voice-one");
126+
await expect(publish(t, admin, second, "@community/voice-two")).rejects.toThrow(
127+
"already claimed",
128+
);
129+
},
130+
);
131+
132+
it("retains package ownership and runtime immutability", async () => {
133+
const { t, admin, community, canonical } = await fixture();
134+
await publish(t, admin, community, "@community/voice-tools");
135+
await expect(
136+
publish(t, admin, canonical, "@community/voice-tools", { version: "1.0.1" }),
137+
).rejects.toThrow("belongs to another publisher");
138+
await expect(
139+
publish(t, admin, community, "@community/voice-tools", {
140+
version: "1.0.1",
141+
runtimeId: "different",
142+
}),
143+
).rejects.toThrow("runtime id changes are not allowed");
144+
});
145+
146+
it("rejects a transfer into an occupied owner namespace without changing ownership", async () => {
147+
const { t, admin, community, canonical } = await fixture();
148+
const first = await publish(t, admin, community, "@community/voice-tools");
149+
await publish(t, admin, canonical, "@canonical/voice-provider");
150+
await expect(
151+
t.mutation(internal.packages.transferPackageOwnerInternal, {
152+
actorUserId: admin,
153+
name: "@community/voice-tools",
154+
...canonical,
155+
reason: "Move publisher namespace",
156+
}),
157+
).rejects.toThrow("already claimed");
158+
expect(await t.run(async (ctx) => ctx.db.get(first.packageId))).toMatchObject(community);
159+
});
160+
161+
it("rejects undelete after another package in the same owner namespace claims the runtime", async () => {
162+
const { t, admin, community } = await fixture();
163+
const original = await publish(t, admin, community, "@community/voice-old");
164+
await t.mutation(internal.packages.softDeletePackageInternal, {
165+
userId: admin,
166+
name: "@community/voice-old",
167+
});
168+
await publish(t, admin, community, "@community/voice-new");
169+
await expect(
170+
t.mutation(internal.packages.restorePackageInternal, {
171+
userId: admin,
172+
name: "@community/voice-old",
173+
}),
174+
).rejects.toThrow("already claimed");
175+
const rows = await t.run(async (ctx) => [
176+
await ctx.db.get(original.packageId),
177+
await ctx.db.get(original.releaseId),
178+
]);
179+
expect(rows.every((row) => typeof row?.softDeletedAt === "number")).toBe(true);
180+
});
181+
182+
it("restores a community package without disturbing another publisher's runtime claim", async () => {
183+
const { t, admin, community, canonical } = await fixture();
184+
const original = await publish(t, admin, community, "@community/voice-tools");
185+
await t.mutation(internal.packages.softDeletePackageInternal, {
186+
userId: admin,
187+
name: "@community/voice-tools",
188+
});
189+
await publish(t, admin, canonical, "@canonical/voice-provider");
190+
await t.mutation(internal.packages.restorePackageInternal, {
191+
userId: admin,
192+
name: "@community/voice-tools",
193+
});
194+
const restored = await t.run(async (ctx) => ctx.db.get(original.packageId));
195+
expect(restored).toMatchObject({
196+
...community,
197+
runtimeId: "voice",
198+
});
199+
expect(restored?.softDeletedAt).toBeUndefined();
200+
});
201+
202+
it("scopes an admin runtime repair by owner and rejects same-owner collisions", async () => {
203+
const { t, admin, community, canonical } = await fixture();
204+
await publish(t, admin, community, "@community/voice-tools");
205+
const repaired = await publish(t, admin, canonical, "@canonical/voice-provider", {
206+
runtimeId: "wrong-id",
207+
});
208+
await t.mutation(internal.packages.repairPackageIdentityInternal, {
209+
actorUserId: admin,
210+
name: "@canonical/voice-provider",
211+
nextRuntimeId: "voice",
212+
reason: "Correct registry identity",
213+
});
214+
expect(await t.run(async (ctx) => ctx.db.get(repaired.packageId))).toMatchObject({
215+
runtimeId: "voice",
216+
});
217+
await publish(t, admin, canonical, "@canonical/other-provider", { runtimeId: "other" });
218+
await expect(
219+
t.mutation(internal.packages.repairPackageIdentityInternal, {
220+
actorUserId: admin,
221+
name: "@canonical/other-provider",
222+
nextRuntimeId: "voice",
223+
reason: "Conflicting repair",
224+
}),
225+
).rejects.toThrow("already claimed");
226+
});
227+
228+
it.each(["first release", "older release"])(
229+
"rechecks a staged %s after the package identity was administratively changed",
230+
async (kind) => {
231+
const { t, admin, community } = await fixture();
232+
if (kind === "older release") {
233+
await publish(t, admin, community, "@community/staged", { version: "2.0.0" });
234+
}
235+
const staged = await publish(t, admin, community, "@community/staged", { pending: true });
236+
await t.mutation(internal.packages.repairPackageIdentityInternal, {
237+
actorUserId: admin,
238+
name: "@community/staged",
239+
nextRuntimeId: "repaired",
240+
reason: "Move existing claim",
241+
});
242+
await publish(t, admin, community, "@community/other");
243+
await expect(
244+
t.mutation(internal.packages.publishPendingReleaseInternal, {
245+
releaseId: staged.releaseId,
246+
}),
247+
).rejects.toThrow("already claimed");
248+
expect(await t.run(async (ctx) => ctx.db.get(staged.releaseId))).toMatchObject({
249+
publicationStatus: "pending",
250+
});
251+
},
252+
);
253+
});

0 commit comments

Comments
 (0)