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
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,50 @@ const PRIVATE_ARCHIVE_FIXTURES = [
versionId:
"e9ea329a25491e347cb3c1156735201a4ff7f8a299dd8990b024d31854b49050",
},
{
id: "template:black-slabs",
versionId:
"007c37df08b7a017b52fd40ebf848b14894afe08b45770b1fae06fed7b77c11f",
},
{
id: "template:blueprint-grid",
versionId:
"a8904a5dabcd9400d06732f2191ae09b26e4497eaf8628a1d6255977d8ceec01",
},
{
id: "template:coastal-hotel",
versionId:
"9f2302ccbbfeb834f1eb7671abe17bf92aa52e2dda63b7cccc0180fa4f07f3d2",
},
{
id: "template:frame-stack",
versionId:
"bb6106f6a0a56346dc53a9092a2272334fd77c9159ffff4f46426286d4fbea31",
},
{
id: "template:gallery-wall",
versionId:
"2691d0fc64b2cbd711d0678dc12ab34f268f11b11789f8d9956f35fbab3ec01f",
},
{
id: "template:glass-bloom",
versionId:
"80d5bd9e80554e1e3e71a970d1c438d0c6def79889dfcd5e5152ad1152f3b91f",
},
{
id: "template:serif-stack",
versionId:
"741f16c88c518da56cb2b0322c004a3f9c874ba7c39accf886c8444436f5b421",
},
{
id: "template:sticker-pop",
versionId:
"ef6b1b8470785c71be604d06a7eb0afe72092f2d75e4623cb700465d5e436c3f",
},
{
id: "template:warm-cards",
versionId:
"dae4ff30aaf7408ae1679d4b5eb25b7cea5c889c00e44b413a572880617e68ce",
"2b21bbf11d7d890f9e3b51db16eabff3be958773af41fed0c9163cb3c4ec89fa",
},
] as const;

Expand Down
18 changes: 17 additions & 1 deletion turbo/apps/api/src/signals/routes/registry-resources-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,24 @@ const PRIVATE_REGISTRY_RESOURCE_ARCHIVE_VERSION_IDS = {
"template:html-ppt-vantage-runbook":
"366c1c2028815fcb13b4c8798550ded9e0853cf55fd2df9124ab4327ff012362",
// Website template packages (self-contained per-template archives).
"template:black-slabs":
"007c37df08b7a017b52fd40ebf848b14894afe08b45770b1fae06fed7b77c11f",
"template:blueprint-grid":
"a8904a5dabcd9400d06732f2191ae09b26e4497eaf8628a1d6255977d8ceec01",
"template:coastal-hotel":
"9f2302ccbbfeb834f1eb7671abe17bf92aa52e2dda63b7cccc0180fa4f07f3d2",
"template:frame-stack":
"bb6106f6a0a56346dc53a9092a2272334fd77c9159ffff4f46426286d4fbea31",
"template:gallery-wall":
"2691d0fc64b2cbd711d0678dc12ab34f268f11b11789f8d9956f35fbab3ec01f",
"template:glass-bloom":
"80d5bd9e80554e1e3e71a970d1c438d0c6def79889dfcd5e5152ad1152f3b91f",
"template:serif-stack":
"741f16c88c518da56cb2b0322c004a3f9c874ba7c39accf886c8444436f5b421",
"template:sticker-pop":
"ef6b1b8470785c71be604d06a7eb0afe72092f2d75e4623cb700465d5e436c3f",
"template:warm-cards":
"dae4ff30aaf7408ae1679d4b5eb25b7cea5c889c00e44b413a572880617e68ce",
"2b21bbf11d7d890f9e3b51db16eabff3be958773af41fed0c9163cb3c4ec89fa",
} as const satisfies Record<string, string>;

function privateRegistryResourceArchive(
Expand Down
20 changes: 10 additions & 10 deletions turbo/apps/cli/src/commands/zero/generate/__tests__/website.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,24 @@ describe("zero generate website command", () => {
"cli",
"website",
"--prompt",
"Editorial landing page",
"High contrast launch page",
"--template",
"warm-cards",
"black-slabs",
"--site-slug",
"warm-cards-demo",
"black-slabs-demo",
]);

const stdout = mockConsoleLog.mock.calls.flat().join("\n");
expect(stdout).toContain(
"Selected template: template:warm-cards (Warm Cards)",
"Selected template: template:black-slabs (Black Slabs)",
);
expect(stdout).toContain(
"Selected template package: zero resource pull template:warm-cards --dir ./generated/resources",
"Selected template package: zero resource pull template:black-slabs --dir ./generated/resources",
);
expect(stdout).toContain('"id": "template:warm-cards"');
expect(stdout).toContain('"id": "template:black-slabs"');
expect(stdout).toContain('"type": "tar.gz"');
expect(stdout).toContain(
'"sha256": "1fafd9e5541dfe53ffdfafcbb6e45d525328c9a0cc5bb4afb2a06b4685e153d2"',
'"sha256": "7e2dfc9f61dc1b9d187661d36854d27b150c0be92f882d845e5adcfd4054e6ba"',
);
});

Expand All @@ -137,14 +137,14 @@ describe("zero generate website command", () => {
"cli",
"website",
"--prompt",
"Editorial landing page",
"High contrast launch page",
"--template",
"website-template:warm-cards",
"website-template:black-slabs",
]);

const stdout = mockConsoleLog.mock.calls.flat().join("\n");
expect(stdout).toContain(
"Selected template: template:warm-cards (Warm Cards)",
"Selected template: template:black-slabs (Black Slabs)",
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ describe("zero resource pull registry resolver", () => {
});

it("resolves a built-in website template package archive", () => {
expect(findRegistryResourceForPull("template:warm-cards")).toEqual(
expect(findRegistryResourceForPull("template:black-slabs")).toEqual(
expect.objectContaining({
id: "template:warm-cards",
id: "template:black-slabs",
kind: "template",
targets: ["website"],
source: expect.objectContaining({
path: "warm-cards",
path: "black-slabs",
archive: expect.objectContaining({
type: "tar.gz",
sha256:
"1fafd9e5541dfe53ffdfafcbb6e45d525328c9a0cc5bb4afb2a06b4685e153d2",
"7e2dfc9f61dc1b9d187661d36854d27b150c0be92f882d845e5adcfd4054e6ba",
}),
}),
}),
);
});

it("canonicalizes unprefixed built-in website template ids", () => {
expect(findRegistryResourceForPull("warm-cards")?.id).toBe(
"template:warm-cards",
expect(findRegistryResourceForPull("black-slabs")?.id).toBe(
"template:black-slabs",
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4159,7 +4159,10 @@ describe("chat composer templates", () => {
expect(screen.getByText("No matches")).toBeInTheDocument();
});

await fill(screen.getByLabelText("Search templates"), "warm");
await fill(
screen.getByLabelText("Search templates"),
websiteTemplate.title,
);
click(
screen.getByLabelText(`Select website template ${websiteTemplate.title}`),
);
Expand Down
156 changes: 99 additions & 57 deletions turbo/packages/core/src/__tests__/website-template-items.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,56 @@ import {
listWebsiteTemplatePackages,
} from "../resource-registry";

const EXPECTED_WEBSITE_TEMPLATE_IDS = [
"website-template:black-slabs",
"website-template:blueprint-grid",
"website-template:coastal-hotel",
"website-template:frame-stack",
"website-template:gallery-wall",
"website-template:glass-bloom",
"website-template:serif-stack",
"website-template:sticker-pop",
"website-template:warm-cards",
] as const;

const EXPECTED_WEBSITE_TEMPLATE_SHA256: Record<string, string> = {
"black-slabs":
"7e2dfc9f61dc1b9d187661d36854d27b150c0be92f882d845e5adcfd4054e6ba",
"blueprint-grid":
"ff42dcfd99f00eaa5e5d9eec58e417a4337f4f2e715aa5414d7059a419d918ab",
"coastal-hotel":
"3818e2e01616e2a3108d63bfda0453c42cc9a41805da7851333ebad28c9bd1df",
"frame-stack":
"52934dc77544e0b65e8727a7978c292e69627be1cee6b04b8ab276ee94dc11ac",
"gallery-wall":
"d5233f8c2df39753df6a40d6336516efa5db887d8a57978eb86635794040a34b",
"glass-bloom":
"60642ffe68a70d953f43b5d27fdff278b10009f4b78497d67d31a09a443e7686",
"serif-stack":
"3fcd90b0017801c431f6562c92f8469c065508840cfa85c6fc2efb392ebc0bf6",
"sticker-pop":
"1c24754b99a419eeb655cce6ad65819c1ae33b64f990e84591a7652923e4bb70",
"warm-cards":
"a11dcf83f4c6c37266905f7333ebc6faca8e82d22499b17cc50905f220b5e3a8",
};

describe("website template items", () => {
it("exposes the built-in website template catalog in picker order", () => {
expect(
WEBSITE_TEMPLATE_ITEMS.map((item) => {
return item.id;
}),
).toEqual(["website-template:warm-cards"]);
).toEqual(EXPECTED_WEBSITE_TEMPLATE_IDS);

const item = WEBSITE_TEMPLATE_ITEMS[0]!;
expect(item).toMatchObject({
id: "website-template:warm-cards",
slug: "warm-cards",
title: "Warm Cards",
templateId: "template:warm-cards",
resourceId: "template:warm-cards",
id: "website-template:black-slabs",
slug: "black-slabs",
title: "Black Slabs",
templateId: "template:black-slabs",
resourceId: "template:black-slabs",
previewKind: "iframe",
sourcePath: "warm-cards",
sourcePath: "black-slabs",
target: "website",
});
});
Expand Down Expand Up @@ -70,68 +103,77 @@ describe("website template items", () => {
);
});

it("resolves the built-in website template as a private R2 pull resource", () => {
const item = WEBSITE_TEMPLATE_ITEMS[0]!;
const [pkg] = listWebsiteTemplatePackages();

expect(pkg).toMatchObject({
templateId: item.templateId,
resourceId: item.resourceId,
slug: item.sourcePath,
name: item.title,
description: item.description,
source: {
path: item.sourcePath,
archive: {
type: "tar.gz",
sha256:
"1fafd9e5541dfe53ffdfafcbb6e45d525328c9a0cc5bb4afb2a06b4685e153d2",
},
},
});
expect(findWebsiteTemplatePackage(item.templateId)).toBe(pkg);
expect(findWebsiteTemplateResource(item.resourceId)).toEqual(
expect.objectContaining({
id: item.resourceId,
kind: "template",
targets: ["website"],
source: expect.objectContaining({
it("resolves built-in website templates as private R2 pull resources", () => {
const packages = listWebsiteTemplatePackages();

expect(packages).toHaveLength(WEBSITE_TEMPLATE_ITEMS.length);
for (const item of WEBSITE_TEMPLATE_ITEMS) {
const pkg = findWebsiteTemplatePackage(item.templateId);
expect(pkg).toMatchObject({
templateId: item.templateId,
resourceId: item.resourceId,
slug: item.sourcePath,
name: item.title,
description: item.description,
source: {
path: item.sourcePath,
archive: expect.objectContaining({ type: "tar.gz" }),
archive: {
type: "tar.gz",
sha256: EXPECTED_WEBSITE_TEMPLATE_SHA256[item.slug],
},
},
});
expect(findWebsiteTemplateResource(item.resourceId)).toEqual(
expect.objectContaining({
id: item.resourceId,
kind: "template",
targets: ["website"],
source: expect.objectContaining({
path: item.sourcePath,
archive: expect.objectContaining({ type: "tar.gz" }),
}),
}),
}),
);
);
}
});

it("keeps built-in R2 website packages out of the unscoped generic template list", () => {
const unscopedTemplateIds = new Set(
listTemplates().map((template) => {
return template.id;
}),
);

expect(
listTemplates().some((template) => {
return template.id === "template:warm-cards";
WEBSITE_TEMPLATE_ITEMS.some((item) => {
return unscopedTemplateIds.has(item.templateId);
}),
).toBe(false);
});

it("exposes built-in R2 website packages to website-targeted generation", () => {
const template = listTemplates("website").find((entry) => {
return entry.id === "template:warm-cards";
});
const websiteTemplates = listTemplates("website");

expect(template).toEqual(
expect.objectContaining({
id: "template:warm-cards",
kind: "template",
targets: ["website"],
source: expect.objectContaining({
path: "warm-cards",
archive: expect.objectContaining({ type: "tar.gz" }),
for (const item of WEBSITE_TEMPLATE_ITEMS) {
const template = websiteTemplates.find((entry) => {
return entry.id === item.templateId;
});

expect(template).toEqual(
expect.objectContaining({
id: item.templateId,
kind: "template",
targets: ["website"],
source: expect.objectContaining({
path: item.sourcePath,
archive: expect.objectContaining({ type: "tar.gz" }),
}),
}),
}),
);
expect(findWebsiteTemplateResource("website-template:warm-cards")).toEqual(
template,
);
expect(findWebsiteTemplatePackage("website-template:warm-cards")).toEqual(
findWebsiteTemplatePackage("template:warm-cards"),
);
);
expect(findWebsiteTemplateResource(item.id)).toEqual(template);
expect(findWebsiteTemplatePackage(item.id)).toEqual(
findWebsiteTemplatePackage(item.templateId),
);
}
});
});
18 changes: 17 additions & 1 deletion turbo/packages/core/src/resource-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3637,8 +3637,24 @@ export interface WebsiteTemplatePackage {
// Archive digests for uploaded private R2 website template packages. Keep these
// in sync with the private R2 version ids served by the API download route.
const WEBSITE_TEMPLATE_ARCHIVE_SHA256: Record<string, string> = {
"black-slabs":
"7e2dfc9f61dc1b9d187661d36854d27b150c0be92f882d845e5adcfd4054e6ba",
"blueprint-grid":
"ff42dcfd99f00eaa5e5d9eec58e417a4337f4f2e715aa5414d7059a419d918ab",
"coastal-hotel":
"3818e2e01616e2a3108d63bfda0453c42cc9a41805da7851333ebad28c9bd1df",
"frame-stack":
"52934dc77544e0b65e8727a7978c292e69627be1cee6b04b8ab276ee94dc11ac",
"gallery-wall":
"d5233f8c2df39753df6a40d6336516efa5db887d8a57978eb86635794040a34b",
"glass-bloom":
"60642ffe68a70d953f43b5d27fdff278b10009f4b78497d67d31a09a443e7686",
"serif-stack":
"3fcd90b0017801c431f6562c92f8469c065508840cfa85c6fc2efb392ebc0bf6",
"sticker-pop":
"1c24754b99a419eeb655cce6ad65819c1ae33b64f990e84591a7652923e4bb70",
"warm-cards":
"1fafd9e5541dfe53ffdfafcbb6e45d525328c9a0cc5bb4afb2a06b4685e153d2",
"a11dcf83f4c6c37266905f7333ebc6faca8e82d22499b17cc50905f220b5e3a8",
};

function websiteTemplateArchiveSha256(slug: string): string {
Expand Down
Loading
Loading