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
2 changes: 2 additions & 0 deletions convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ import type * as lib_packageArtifacts from "../lib/packageArtifacts.js";
import type * as lib_packageIcons from "../lib/packageIcons.js";
import type * as lib_packagePublishRecovery from "../lib/packagePublishRecovery.js";
import type * as lib_packageRegistry from "../lib/packageRegistry.js";
import type * as lib_packageReleaseFamily from "../lib/packageReleaseFamily.js";
import type * as lib_packageReleaseVisibility from "../lib/packageReleaseVisibility.js";
import type * as lib_packageRuntimeIdentity from "../lib/packageRuntimeIdentity.js";
import type * as lib_packageSdkUsage from "../lib/packageSdkUsage.js";
Expand Down Expand Up @@ -414,6 +415,7 @@ declare const fullApi: ApiFromModules<{
"lib/packageIcons": typeof lib_packageIcons;
"lib/packagePublishRecovery": typeof lib_packagePublishRecovery;
"lib/packageRegistry": typeof lib_packageRegistry;
"lib/packageReleaseFamily": typeof lib_packageReleaseFamily;
"lib/packageReleaseVisibility": typeof lib_packageReleaseVisibility;
"lib/packageRuntimeIdentity": typeof lib_packageRuntimeIdentity;
"lib/packageSdkUsage": typeof lib_packageSdkUsage;
Expand Down
38 changes: 30 additions & 8 deletions convex/githubImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,33 @@ const originalGitHubAppEnv = {
privateKey: process.env.GITHUB_APP_PRIVATE_KEY,
};

function corruptZipEntry(zip: Uint8Array, path: string) {
function corruptZipEntry(zip: Uint8Array, path: string, originalSize?: number) {
const header = new DataView(zip.buffer, zip.byteOffset, zip.byteLength);
for (let offset = 0; header.getUint32(offset, true) === 0x04034b50;) {
const nameLength = header.getUint16(offset + 26, true);
const dataOffset = offset + 30 + nameLength + header.getUint16(offset + 28, true);
const name = new TextDecoder().decode(zip.subarray(offset + 30, offset + 30 + nameLength));
if (name === path) {
if (originalSize !== undefined) {
// Generated fixtures have no ZIP comment. Update both size records so
// the same valid boundary archive can model a declared byte overflow.
header.setUint32(offset + 22, originalSize, true);
let central = header.getUint32(zip.byteLength - 6, true);
while (header.getUint32(central, true) === 0x02014b50) {
if (header.getUint32(central + 42, true) === offset) {
header.setUint32(central + 24, originalSize, true);
break;
}
central +=
46 +
header.getUint16(central + 28, true) +
header.getUint16(central + 30, true) +
header.getUint16(central + 32, true);
}
if (header.getUint32(central, true) !== 0x02014b50) {
throw new Error(`Missing central ZIP fixture entry: ${path}`);
}
}
// An invalid DEFLATE block makes any attempted inflation of this entry fail.
zip[dataOffset] = 0x07;
return zip;
Expand Down Expand Up @@ -235,19 +255,21 @@ describe("githubImport", () => {
});

it("rejects excessive total bytes before inflating the over-limit entry", () => {
const contents = new Uint8Array(10 * 1024 * 1024);
const files = Object.fromEntries(
Array.from({ length: 8 }, (_, index) => [
`demo-repo/${index}.bin`,
new Uint8Array(10 * 1024 * 1024),
]),
Array.from({ length: 8 }, (_, index) => [`demo-repo/${index}.bin`, contents]),
);
const entries = __test.unzipToEntries(zipSync(files));
files["demo-repo/overflow.md"] = new Uint8Array();
const zip = zipSync(files);
const entries = __test.unzipToEntries(zip);
expect(Object.values(entries).reduce((sum, bytes) => sum + bytes.byteLength, 0)).toBe(
80 * 1024 * 1024,
);
expect(entries["demo-repo/overflow.md"]).toHaveLength(0);

files["demo-repo/overflow.md"] = new TextEncoder().encode("x");
const zip = corruptZipEntry(zipSync(files), "demo-repo/overflow.md");
// Keep the real DEFLATE payloads and 80MiB acceptance boundary; avoid
// allocating and recompressing that entire archive a second time in CI.
corruptZipEntry(zip, "demo-repo/overflow.md", 1);
expect(() => __test.unzipToEntries(zip)).toThrow("Repo archive is too large");
});

Expand Down
2 changes: 1 addition & 1 deletion convex/httpApiV1/packagesV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4728,7 +4728,7 @@ export async function packagesGetRouterV1Handler(ctx: ActionCtx, request: Reques
package: {
name: publicPackage!.name,
displayName: publicPackage!.displayName,
family: publicPackage!.family,
family: result!.package.family,
},
version: release.version,
artifact: {
Expand Down
29 changes: 29 additions & 0 deletions convex/lib/packageReleaseFamily.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from "vitest";
import { resolvePackageReleaseFamily } from "./packageReleaseFamily";

describe("admitted plugin release family", () => {
it.each(["code-plugin", "bundle-plugin"] as const)(
"keeps legacy %s fallback without a release snapshot",
(family) => {
expect(resolvePackageReleaseFamily(family, null)).toBe(family);
expect(resolvePackageReleaseFamily(family, {})).toBe(family);
},
);

it("keeps an original bundle distinct from a later native package", () => {
expect(resolvePackageReleaseFamily("code-plugin", { pluginFamily: "bundle-plugin" })).toBe(
"bundle-plugin",
);
expect(resolvePackageReleaseFamily("code-plugin", { pluginFamily: "code-plugin" })).toBe(
"code-plugin",
);
});

it.each(["claw", "skill"] as const)(
"never loosens the %s boundary using optional plugin metadata",
(family) => {
expect(resolvePackageReleaseFamily(family, { pluginFamily: "bundle-plugin" })).toBe(family);
expect(resolvePackageReleaseFamily(family, { pluginFamily: "code-plugin" })).toBe(family);
},
);
});
14 changes: 14 additions & 0 deletions convex/lib/packageReleaseFamily.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Doc } from "../_generated/dataModel";

/** A plugin release's admitted family survives a guarded parent-family repair. */
export function resolvePackageReleaseFamily(
family: Doc<"packages">["family"],
release: Pick<Doc<"packageReleases">, "pluginFamily"> | null | undefined,
): Doc<"packages">["family"] {
// Plugin-only metadata must never select the less restrictive plugin projection
// for a Claw or skill package. Legacy rows retain their existing parent fallback.
if (family === "code-plugin" || family === "bundle-plugin") {
return release?.pluginFamily ?? family;
}
return family;
}
38 changes: 38 additions & 0 deletions convex/packages.publicationSelection.runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,44 @@ const withheld = [
] satisfies Array<Partial<Doc<"packageReleases">>>;

describe("checked package release selections", () => {
it("preserves an old bundle release family under a native current package", async () => {
const { t, selected } = await fixture();
await t.run((ctx) => ctx.db.patch(selected, { pluginFamily: "bundle-plugin" }));
const version = await t.query(internal.packages.getVersionByNameForViewerInternal, {
name,
version: "2.0.0",
});
expect(version?.package.family).toBe("bundle-plugin");
const security = await t.query(internal.packages.getVersionSecurityByNameForViewerInternal, {
name,
version: "2.0.0",
});
expect(security?.package.family).toBe("bundle-plugin");
const detailSnapshot = await t.query(internal.packages.getPluginDetailForViewerInternal, {
name,
version: "2.0.0",
});
expect(detailSnapshot?.package.family).toBe("bundle-plugin");
const queued = await t.mutation(internal.securityScan.enqueuePackageReleaseScanInternal, {
releaseId: selected,
source: "manual",
priority: 0,
waitForVtMs: 0,
});
expect(queued.jobId).toBeDefined();
const target = await t.query(internal.securityScan.getJobTargetInternal, {
jobId: queued.jobId!,
});
expect(target && "package" in target ? target.package?.family : null).toBe("bundle-plugin");
for (const suffix of ["", "/security", "/artifact"]) {
const response = await t.fetch(`/api/v1/packages/${name}/versions/2.0.0${suffix}`);
expect(response.status).toBe(200);
expect((await response.json()).package.family).toBe("bundle-plugin");
}
const detail = await t.fetch(`/api/v1/packages/${name}`);
expect((await detail.json()).package.family).toBe("code-plugin");
});

it.each(withheld)("withholds %j across version, tag, bytes and metadata", async (patch) => {
const { t, selected, pkg } = await fixture();
await t.run((ctx) => ctx.db.patch(selected, patch));
Expand Down
22 changes: 19 additions & 3 deletions convex/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import {
summarizePackageForSearch,
toConvexSafeJsonValue,
} from "./lib/packageRegistry";
import { resolvePackageReleaseFamily } from "./lib/packageReleaseFamily";
import { isPublishedPackageRelease } from "./lib/packageReleaseVisibility";
import { assertPackageRuntimeIdAvailable } from "./lib/packageRuntimeIdentity";
import {
Expand Down Expand Up @@ -1314,7 +1315,9 @@ function toPublicPackage(
}

function toPublicPackageRelease(release: Doc<"packageReleases">, family: PackageFamily) {
// Package family owns this boundary; optional release metadata must not select a looser projection.
// Plugin snapshots may distinguish historical bundles from current native
// releases. They can never loosen the Claw/skill projection boundary.
family = resolvePackageReleaseFamily(family, release);
if (family === "claw") {
const sourcePath = release.verification?.sourcePath ?? getReleaseSourcePath(release);
return {
Expand Down Expand Up @@ -3575,7 +3578,11 @@ export const getPluginDetailForViewerInternal = internalQuery({
: false,
]);
return {
package: { ...publicPackage, publicDownloadBlocked },
package: {
...publicPackage,
family: resolvePackageReleaseFamily(pkg.family, selectedRelease),
publicDownloadBlocked,
},
owner,
tags,
release: selectedRelease ? toPublicPluginRelease(selectedRelease) : null,
Expand Down Expand Up @@ -3770,7 +3777,12 @@ async function readPackageReleaseSnapshotForViewer(
? await ctx.db.get(pkg.latestReleaseId)
: null;
const publicPackage = toPublicPackage(pkg, latestRelease);
return publicPackage ? { package: publicPackage, release } : null;
return publicPackage
? {
package: { ...publicPackage, family: resolvePackageReleaseFamily(pkg.family, release) },
release,
}
: null;
}

export const getReleaseForViewerInternal = internalQuery({
Expand Down Expand Up @@ -3913,6 +3925,7 @@ export const getVersionSecurityByNameForViewerInternal = internalQuery({
return {
package: {
...publicPackage,
family: resolvePackageReleaseFamily(pkg.family, release),
publicDownloadBlocked,
},
version: toPublicPackageRelease(release, pkg.family),
Expand Down Expand Up @@ -12597,6 +12610,9 @@ export const insertReleaseInternal = internalMutation({
const releaseId = await ctx.db.insert("packageReleases", {
packageId: pkgId,
version: args.version,
...(args.family === "code-plugin" || args.family === "bundle-plugin"
? { pluginFamily: args.family }
: {}),
publicationStatus,
pendingPublication: pendingPublication
? {
Expand Down
73 changes: 73 additions & 0 deletions convex/publishAttempts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,79 @@ describe("publishAttempts", () => {
},
);

it.each([
{
snapshot: "bundle-plugin",
stored: "bundle-plugin",
fingerprint: "exact",
expected: "bundle-plugin",
},
{
snapshot: "code-plugin",
stored: "code-plugin",
fingerprint: "exact",
expected: "code-plugin",
},
{
snapshot: "bundle-plugin",
stored: "code-plugin",
fingerprint: "exact",
error: "registry family",
},
{
snapshot: "bundle-plugin",
stored: "bundle-plugin",
fingerprint: "changed",
error: "original publish artifact",
},
])(
"binds historical check claims to admitted release family $snapshot/$stored/$fingerprint",
async ({ snapshot, stored, fingerprint, expected, error }) => {
const attempt = {
_id: "publishAttempts:historical",
kind: "package",
status: "pending_checks",
userId: "users:publisher",
packageId: "packages:native",
packageReleaseId: "packageReleases:old",
slug: "native",
version: "1.0.0",
artifactFingerprint: "exact",
files: [],
scanContext: { package: { family: stored } },
createdAt: Date.now(),
};
const ctx = {
db: {
get: vi.fn(async (id: string) =>
id === attempt.packageId
? { family: "code-plugin" }
: id === attempt.packageReleaseId
? {
packageId: attempt.packageId,
pluginFamily: snapshot,
integritySha256: fingerprint,
}
: null,
),
normalizeId: vi.fn(),
patch: vi.fn(),
query: vi.fn(() => ({
withIndex: vi.fn(() => ({
order: vi.fn(() => ({ take: vi.fn(async () => [attempt]) })),
})),
})),
},
};
const claim = claimPendingChecksHandler(ctx, { claimId: "checks:historical" });
if (error) await expect(claim).rejects.toThrow(error);
else
await expect(claim).resolves.toMatchObject({
scanContext: { package: { family: expected } },
});
},
);

it("claims fresh staged publishes before older scanner retries", async () => {
const now = Date.now();
const freshAttempt = {
Expand Down
22 changes: 18 additions & 4 deletions convex/publishAttempts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { MutationCtx, QueryCtx } from "./_generated/server";
import { action, internalAction, internalMutation, internalQuery } from "./functions";
import { reusableAigAnalysis } from "./lib/aigAnalysis";
import { manualPackageRecovery } from "./lib/packagePublishRecovery";
import { resolvePackageReleaseFamily } from "./lib/packageReleaseFamily";
import { sdkUsageReportStorageId } from "./lib/packageSdkUsageStorage";
import { finalizeSkillPublishAttempt } from "./lib/skillPublish";
import { requestPublishAttemptDispatch } from "./publishAttemptDispatch";
Expand Down Expand Up @@ -1064,10 +1065,23 @@ export const claimPendingPublishAttemptChecksInternal = internalMutation({
}
}

const packageFamily =
attempt.kind === "package" && attempt.packageId
? (await ctx.db.get(attempt.packageId))?.family
: undefined;
let packageFamily: Doc<"packages">["family"] | undefined;
if (attempt.kind === "package" && attempt.packageId) {
const pkg = await ctx.db.get(attempt.packageId);
const release = attempt.packageReleaseId
? await ctx.db.get(attempt.packageReleaseId)
: null;
if (
release?.pluginFamily !== undefined &&
(release.packageId !== attempt.packageId ||
release.integritySha256 !== attempt.artifactFingerprint)
) {
throw new ConvexError(
"Package release family does not match the original publish artifact",
);
}
packageFamily = pkg ? resolvePackageReleaseFamily(pkg.family, release) : undefined;
}
return {
attemptId: attempt._id,
status: attempt.status,
Expand Down
2 changes: 2 additions & 0 deletions convex/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,8 @@ const packages = defineTable({

const packageReleases = defineTable({
packageId: v.id("packages"),
// Immutable admitted plugin family; absent legacy releases use their parent.
pluginFamily: v.optional(v.union(v.literal("code-plugin"), v.literal("bundle-plugin"))),
version: v.string(),
publicationStatus: v.optional(
v.union(v.literal("pending"), v.literal("published"), v.literal("blocked")),
Expand Down
3 changes: 2 additions & 1 deletion convex/securityScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { reusableAigAnalysis } from "./lib/aigAnalysis";
import { endorAnalysisValidator, type EndorAnalysis } from "./lib/endorAnalysis";
import { Events, logEvent } from "./lib/observabilityEvents";
import { normalizePackageName } from "./lib/packageRegistry";
import { resolvePackageReleaseFamily } from "./lib/packageReleaseFamily";
import { normalizePackageScanStatus } from "./lib/packageSecurity";
import { assertCanManageOwnedResource } from "./lib/publishers";
import {
Expand Down Expand Up @@ -3709,7 +3710,7 @@ export const getJobTargetInternal = internalQuery({
const ownerPublisher = pkg?.ownerPublisherId ? await ctx.db.get(pkg.ownerPublisherId) : null;
return {
job,
package: pkg,
package: pkg ? { ...pkg, family: resolvePackageReleaseFamily(pkg.family, release) } : pkg,
release,
trustedOpenClawPlugin: isOpenClawPluginPackage(pkg, ownerPublisher),
};
Expand Down
8 changes: 8 additions & 0 deletions specs/plans/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ New pending attempts carry the admitted package family into worker metadata.
Claims for older attempts recover that metadata from their existing registry
record, never by guessing from filenames; contradictory stored claims fail.

Plugin releases persist an optional admitted `pluginFamily` snapshot. A legacy
release without one retains its parent-family fallback. Version-specific public,
security, detail and scanner metadata use the snapshot for plugin parents;
package-wide listing and admission keep the current registry family. Plugin
snapshots cannot change Claw or skill projection boundaries. A future guarded
parent-family repair must snapshot historical releases before changing the
parent, preserving genuine bundle history and all original artifacts.

Already-admitted scan jobs are distinct from new publication admission. Retained
legacy bundles may contain several supported harness manifests or only a native
envelope. Workers preserve deterministic Codex/Claude/Cursor precedence for those
Expand Down
Loading