create-freeholder 0.2.0-beta.4 → 0.2.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/template/.changeset/blog-playground-content.md +4 -0
- package/dist/template/.changeset/blog-wordpress-structure.md +6 -0
- package/dist/template/.changeset/managed-preview-assistant.md +4 -0
- package/dist/template/.changeset/native-linux-install.md +6 -0
- package/dist/template/.changeset/public-beta-5.md +4 -0
- package/dist/template/.changeset/public-beta-6.md +4 -0
- package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
- package/dist/template/.github/workflows/release-tarballs.yml +117 -0
- package/dist/template/AGENTS.md +15 -2
- package/dist/template/Dockerfile +3 -0
- package/dist/template/MASTER.md +114 -11
- package/dist/template/README.md +1 -1
- package/dist/template/app/(admin)/admin/assistant/page.tsx +9 -1
- package/dist/template/app/(admin)/admin/blog/PostSettings.tsx +26 -0
- package/dist/template/app/(admin)/admin/blog/[kind]/page.tsx +53 -0
- package/dist/template/app/(admin)/admin/blog/actions.ts +186 -6
- package/dist/template/app/(admin)/admin/blog/comments/page.tsx +25 -0
- package/dist/template/app/(admin)/admin/blog/page.tsx +21 -5
- package/dist/template/app/(admin)/admin/imports/[id]/page.tsx +2 -0
- package/dist/template/app/(admin)/admin/pages/[id]/page.tsx +3 -0
- package/dist/template/app/(admin)/assistant-actions.ts +13 -6
- package/dist/template/app/(public)/[[...slug]]/ReaderComments.tsx +25 -0
- package/dist/template/app/(public)/[[...slug]]/blog-parts.tsx +153 -0
- package/dist/template/app/(public)/[[...slug]]/comment-actions.ts +16 -0
- package/dist/template/app/(public)/[[...slug]]/page.tsx +182 -18
- package/dist/template/app/api/chat/assistant/call/route.ts +35 -0
- package/dist/template/db/migrations/0061_blog_structure.sql +89 -0
- package/dist/template/db/migrations/0062_blog_reader_comments.sql +24 -0
- package/dist/template/db/migrations/meta/_journal.json +14 -0
- package/dist/template/deploy/README.md +26 -9
- package/dist/template/deploy/blog-wordpress-2026-11-07.md +146 -0
- package/dist/template/deploy/docker-selfhost/.env.example +11 -1
- package/dist/template/deploy/docker-selfhost/README.md +79 -50
- package/dist/template/deploy/docker-selfhost/infra/backup.sh +81 -0
- package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +37 -1
- package/dist/template/deploy/docker-selfhost/infra/compose.yml +37 -1
- package/dist/template/deploy/docker-selfhost/migrate.md +8 -5
- package/dist/template/deploy/docker-selfhost/recipe.yaml +9 -10
- package/dist/template/deploy/docker-selfhost/selfhost.sh +206 -0
- package/dist/template/deploy/docker-selfhost/verify.md +11 -4
- package/dist/template/deploy/f-criteria-matrix.md +89 -0
- package/dist/template/deploy/linux/.env.example +28 -0
- package/dist/template/deploy/linux/README.md +181 -0
- package/dist/template/deploy/linux/freeholder +655 -0
- package/dist/template/deploy/linux/install.sh +173 -0
- package/dist/template/deploy/linux/migrate.md +17 -0
- package/dist/template/deploy/linux/recipe.yaml +50 -0
- package/dist/template/deploy/linux/share/Caddyfile.template +19 -0
- package/dist/template/deploy/linux/share/systemd/freeholder-backup.service +13 -0
- package/dist/template/deploy/linux/share/systemd/freeholder-backup.timer +12 -0
- package/dist/template/deploy/linux/share/systemd/freeholder.service +41 -0
- package/dist/template/deploy/linux/verify.md +22 -0
- package/dist/template/deploy/managed-preview-assistant.md +99 -0
- package/dist/template/eslint.config.mjs +3 -1
- package/dist/template/gitignore.template +1 -0
- package/dist/template/locales/ar.json +85 -6
- package/dist/template/locales/en.json +83 -4
- package/dist/template/locales/es.json +83 -4
- package/dist/template/locales/fr.json +85 -6
- package/dist/template/next.config.ts +2 -0
- package/dist/template/package.json +3 -2
- package/dist/template/packages/cli/package.json +1 -1
- package/dist/template/packages/create-freeholder/package.json +1 -1
- package/dist/template/packages/freeholder-app/package.json +1 -1
- package/dist/template/packages/mobile-app/package.json +1 -1
- package/dist/template/packages/plugin-kit/package.json +1 -1
- package/dist/template/packages/sdk/package.json +1 -1
- package/dist/template/packages/sdk/src/generated.ts +177 -9
- package/dist/template/packages/sdk/src/version.ts +1 -1
- package/dist/template/packages/templates/package.json +1 -1
- package/dist/template/proxy.ts +18 -1
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/NOTICE.txt +117 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/audio-output-processor.js +267 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.js +847 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.wasm +0 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/encoderWorker.min.js +1 -0
- package/dist/template/public/managed-assistant/0.1.10/manifest.json +12 -0
- package/dist/template/public/managed-assistant/0.1.10/pm-ai-duplex-client.js +1376 -0
- package/dist/template/scripts/build-release.d.mts +4 -0
- package/dist/template/scripts/build-release.mjs +171 -0
- package/dist/template/scripts/launch-prepare.mjs +6 -3
- package/dist/template/scripts/license-headers.mjs +3 -0
- package/dist/template/scripts/recipe-matrix.sh +22 -7
- package/dist/template/scripts/verify-wordpress-migration.d.mts +8 -0
- package/dist/template/scripts/verify-wordpress-migration.mjs +105 -0
- package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
- package/dist/template/src/adapters/ai/types.ts +5 -0
- package/dist/template/src/adapters/paradise/assistant.ts +37 -0
- package/dist/template/src/adapters/paradise/http.ts +4 -3
- package/dist/template/src/adapters/storage/local-mode.ts +54 -0
- package/dist/template/src/adapters/storage/local.ts +53 -26
- package/dist/template/src/core/contract/json-schema.ts +8 -0
- package/dist/template/src/core/demo/playground-inserts.ts +29 -0
- package/dist/template/src/core/demo/playground-policy.ts +9 -0
- package/dist/template/src/core/doctor/index.ts +19 -10
- package/dist/template/src/core/env.ts +8 -1
- package/dist/template/src/core/http/csp.ts +10 -2
- package/dist/template/src/core/http/csrf-client.ts +10 -0
- package/dist/template/src/core/import/service.ts +217 -12
- package/dist/template/src/core/import/wordpress.ts +80 -15
- package/dist/template/src/core/notifications/service.ts +1 -0
- package/dist/template/src/core/retention/registry.ts +2 -0
- package/dist/template/src/core/search/registry.ts +2 -0
- package/dist/template/src/core/seo/feeds.ts +2 -0
- package/dist/template/src/core/seo/jsonld.ts +46 -2
- package/dist/template/src/core/seo/legacy-proxy.ts +53 -0
- package/dist/template/src/core/seo/meta.ts +10 -7
- package/dist/template/src/core/seo/service.ts +14 -1
- package/dist/template/src/core/update/preflight.ts +3 -2
- package/dist/template/src/core/update/release-declaration.json +1 -1
- package/dist/template/src/core/update/service.ts +7 -17
- package/dist/template/src/modules/assistant/contract.ts +1 -1
- package/dist/template/src/modules/assistant/limits.ts +3 -0
- package/dist/template/src/modules/assistant/preview.ts +124 -0
- package/dist/template/src/modules/assistant/provider.ts +7 -0
- package/dist/template/src/modules/assistant/service.ts +21 -5
- package/dist/template/src/modules/cms/blocks/PreviewAssistantCall.tsx +176 -0
- package/dist/template/src/modules/cms/blocks/SiteChatClient.tsx +10 -4
- package/dist/template/src/modules/cms/blocks/surfaces.tsx +10 -0
- package/dist/template/src/modules/cms/blog-comments-schema.ts +27 -0
- package/dist/template/src/modules/cms/blog-comments.ts +111 -0
- package/dist/template/src/modules/cms/blog-schema.ts +146 -0
- package/dist/template/src/modules/cms/blog-service.ts +999 -0
- package/dist/template/src/modules/cms/blog.tsx +245 -25
- package/dist/template/src/modules/cms/manifest.ts +7 -1
- package/dist/template/src/modules/cms/read.ts +18 -0
- package/dist/template/src/modules/cms/service.ts +22 -4
- package/dist/template/src/modules/cms/tables.ts +2 -0
- package/dist/template/src/modules/seed/launch.ts +31 -3
- package/dist/template/tests/browser/blog-structure.spec.ts +69 -0
- package/dist/template/tests/core/agent-launch.test.ts +7 -2
- package/dist/template/tests/core/analytics-consent.test.ts +1 -1
- package/dist/template/tests/core/blog-playground.test.ts +106 -0
- package/dist/template/tests/core/blog-structure-comments.test.ts +166 -0
- package/dist/template/tests/core/client-readiness-security.test.ts +3 -1
- package/dist/template/tests/core/csp.test.ts +1 -1
- package/dist/template/tests/core/deploy-recipe.test.ts +54 -4
- package/dist/template/tests/core/internal-services.test.ts +4 -0
- package/dist/template/tests/core/legacy-redirect-proxy.test.ts +59 -0
- package/dist/template/tests/core/linux-install.test.ts +169 -0
- package/dist/template/tests/core/local-storage-mode.test.ts +29 -0
- package/dist/template/tests/core/locale-routing.test.ts +1 -1
- package/dist/template/tests/core/playground-cache.test.ts +1 -1
- package/dist/template/tests/core/playground.test.ts +3 -3
- package/dist/template/tests/core/preview-assistant-call.test.ts +88 -0
- package/dist/template/tests/core/private-preview-webhooks.test.ts +1 -1
- package/dist/template/tests/core/private-preview.test.ts +1 -1
- package/dist/template/tests/core/proxy-locale.test.ts +1 -1
- package/dist/template/tests/core/sdk-schema.test.ts +20 -0
- package/dist/template/tests/core/seo.test.ts +1 -1
- package/dist/template/tests/core/site-chat-client.test.ts +50 -0
- package/dist/template/tests/core/storage.test.ts +38 -2
- package/dist/template/tests/core/wordpress-import-flow.test.ts +81 -18
- package/dist/template/tests/core/wordpress-import.test.ts +25 -12
- package/dist/template/tests/core/wordpress-migration-verification.test.ts +37 -0
- package/dist/template/tests/modules/preview-assistant.test.ts +164 -0
- package/dist/template-manifest.json +490 -175
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// C3.44: one rule for when production media may live on local disk.
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { describeLocalStorage, localStorageMode } from "@/adapters/storage/local-mode";
|
|
6
|
+
|
|
7
|
+
describe("local storage mode", () => {
|
|
8
|
+
it("is development outside production", () => {
|
|
9
|
+
expect(localStorageMode({ NODE_ENV: "development" })).toBe("development");
|
|
10
|
+
expect(localStorageMode({ NODE_ENV: "test", LOCAL_STORAGE_ROOT: "relative" })).toBe("development");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("accepts only an absolute directory in production, and still honours the legacy override", () => {
|
|
14
|
+
expect(localStorageMode({ NODE_ENV: "production", LOCAL_STORAGE_ROOT: "/var/lib/freeholder/media" })).toBe("persistent");
|
|
15
|
+
expect(localStorageMode({ NODE_ENV: "production", LOCAL_STORAGE_ROOT: ".data/media" })).toBe("refused");
|
|
16
|
+
expect(localStorageMode({ NODE_ENV: "production" })).toBe("refused");
|
|
17
|
+
expect(localStorageMode({ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: "1" })).toBe("unsafe");
|
|
18
|
+
// The playground's disposable tmpfs: the override wins, so the directory
|
|
19
|
+
// is still created on demand rather than required to exist.
|
|
20
|
+
expect(localStorageMode({ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: "1", LOCAL_STORAGE_ROOT: "/tmp/media" })).toBe("unsafe");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("tells the owner where the media is and that backups must include it", () => {
|
|
24
|
+
const detail = describeLocalStorage({ NODE_ENV: "production", LOCAL_STORAGE_ROOT: "/var/lib/freeholder/media" });
|
|
25
|
+
expect(detail).toContain("/var/lib/freeholder/media");
|
|
26
|
+
expect(detail).toMatch(/backup/i);
|
|
27
|
+
expect(describeLocalStorage({ NODE_ENV: "production" })).toMatch(/lose/);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// keep in step. Almost every assertion here is a consequence of that.
|
|
9
9
|
import { afterAll, beforeEach, describe, expect, it } from "vitest";
|
|
10
10
|
import { NextRequest } from "next/server";
|
|
11
|
-
import { proxy } from "../../proxy";
|
|
11
|
+
import { requestContextProxy as proxy } from "../../proxy";
|
|
12
12
|
import { LOCALE_HEADER } from "@/core/http/headers";
|
|
13
13
|
import { localePath } from "../../app/(public)/[[...slug]]/alternates";
|
|
14
14
|
import {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
playgroundSharedCacheable,
|
|
14
14
|
} from "@/core/demo/playground-cache";
|
|
15
15
|
import { ANALYTICS_BOOTSTRAP_COOKIE } from "@/modules/analytics/visitor";
|
|
16
|
-
import { proxy } from "../../proxy";
|
|
16
|
+
import { requestContextProxy as proxy } from "../../proxy";
|
|
17
17
|
|
|
18
18
|
const APP = join(__dirname, "..", "..", "app");
|
|
19
19
|
|
|
@@ -88,10 +88,10 @@ it("treats only the content modules as editable admin screens", () => {
|
|
|
88
88
|
|
|
89
89
|
describe("playground public-site policy (2026-10-22)", () => {
|
|
90
90
|
it("lets the public site's own actions through and keeps credential and provider flows out", () => {
|
|
91
|
-
for (const name of ["forms.submit", "newsletters.subscribe", "events.register", "catalog.addCartItem", "catalog.shopperCheckout", "cms.submitSiteChat", "share.shareVia", "popups.capture", "reviews.submit"]) {
|
|
91
|
+
for (const name of ["forms.submit", "newsletters.subscribe", "events.register", "catalog.addCartItem", "catalog.shopperCheckout", "cms.submitSiteChat", "cms.submitReaderComment", "share.shareVia", "popups.capture", "reviews.submit"]) {
|
|
92
92
|
expect(playgroundAllows(name, "mutation"), name).toBe(true);
|
|
93
93
|
}
|
|
94
|
-
for (const name of ["auth.requestCustomerMagicLink", "portal.requestSignIn", "invoicing.beginCustomerCheckout", "invoicing.claimCustomerCheckout", "assistant.answer", "media.signUploadClaim"]) {
|
|
94
|
+
for (const name of ["auth.requestCustomerMagicLink", "portal.requestSignIn", "invoicing.beginCustomerCheckout", "invoicing.claimCustomerCheckout", "assistant.answer", "assistant.previewCall", "assistant.saveCallCaption", "media.signUploadClaim"]) {
|
|
95
95
|
expect(playgroundAllows(name, "mutation"), name).toBe(false);
|
|
96
96
|
}
|
|
97
97
|
});
|
|
@@ -113,7 +113,7 @@ describe("playground public-site policy (2026-10-22)", () => {
|
|
|
113
113
|
}
|
|
114
114
|
// Public verbs that add a row of their own carry a cap; the community
|
|
115
115
|
// join (a member row per email) was missed once.
|
|
116
|
-
for (const name of ["forms.submit", "events.register", "community.joinBySlug", "catalog.getOrCreateCart", "reviews.submit"]) {
|
|
116
|
+
for (const name of ["forms.submit", "events.register", "community.joinBySlug", "catalog.getOrCreateCart", "reviews.submit", "cms.submitReaderComment"]) {
|
|
117
117
|
expect(PLAYGROUND_ROW_CAPS[name], name).toBeDefined();
|
|
118
118
|
}
|
|
119
119
|
// Every capped public surface is one the policy actually allows.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// @vitest-environment jsdom
|
|
4
|
+
import { act, createElement } from "react";
|
|
5
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { PreviewAssistantCall, type PreviewAssistantLabels } from "@/modules/cms/blocks/PreviewAssistantCall";
|
|
8
|
+
|
|
9
|
+
const labels: PreviewAssistantLabels = {
|
|
10
|
+
label: "AI assistant", captions: "Captions stay in this chat", video: "Start video", voice: "Start voice", leave: "Leave queue", end: "End call",
|
|
11
|
+
waiting: "Waiting", unavailable: "Use text", connecting: "Connecting", captionFailed: "Captions not saved", ended: "Ended", lost: "Connection lost", microphone: "Allow microphone",
|
|
12
|
+
voiceFallback: "Video is unavailable. Continuing by voice.",
|
|
13
|
+
};
|
|
14
|
+
const json = (body: unknown) => new Response(JSON.stringify(body), { headers: { "content-type": "application/json" } });
|
|
15
|
+
const config = (modes = ["video", "voice", "text"]) => json({ enabled: true, modes, label: "AI assistant", disclosure: "AI, family-friendly, no endorsement" });
|
|
16
|
+
const tick = async () => { await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)); }); };
|
|
17
|
+
function deferred<T>() {
|
|
18
|
+
let resolve!: (value: T) => void, reject!: (error: Error) => void;
|
|
19
|
+
const promise = new Promise<T>((yes, no) => { resolve = yes; reject = no; });
|
|
20
|
+
return { promise, resolve, reject };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("preview assistant browser lifecycle", () => {
|
|
24
|
+
let root: Root, container: HTMLDivElement;
|
|
25
|
+
const stops: Array<ReturnType<typeof vi.fn>> = [];
|
|
26
|
+
const requests: Array<Record<string, unknown>> = [];
|
|
27
|
+
let handler: (body: Record<string, unknown>) => Promise<Response>;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
(globalThis as Record<string, unknown>).IS_REACT_ACT_ENVIRONMENT = true;
|
|
31
|
+
container = document.createElement("div"); document.body.append(container); root = createRoot(container);
|
|
32
|
+
stops.length = 0; requests.length = 0;
|
|
33
|
+
vi.stubGlobal("AudioContext", class {
|
|
34
|
+
resume() { return Promise.resolve(); }
|
|
35
|
+
close() { return Promise.resolve(); }
|
|
36
|
+
});
|
|
37
|
+
vi.stubGlobal("navigator", { mediaDevices: { getUserMedia: () => {
|
|
38
|
+
const stop = vi.fn(); stops.push(stop);
|
|
39
|
+
return Promise.resolve({ getTracks: () => [{ stop }] });
|
|
40
|
+
} } });
|
|
41
|
+
vi.stubGlobal("fetch", async (_url: unknown, init?: RequestInit) => {
|
|
42
|
+
const body = typeof init?.body === "string" ? JSON.parse(init.body) as Record<string, unknown> : {};
|
|
43
|
+
requests.push(body); return handler(body);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
afterEach(async () => { await act(async () => root.unmount()); container.remove(); vi.unstubAllGlobals(); });
|
|
47
|
+
async function mount() { await act(async () => root.render(createElement(PreviewAssistantCall, { ended: false, labels }))); await tick(); }
|
|
48
|
+
async function click(text: string) {
|
|
49
|
+
const button = [...container.querySelectorAll("button")].find(item => item.textContent === text);
|
|
50
|
+
expect(button, text).toBeDefined();
|
|
51
|
+
await act(async () => button!.click()); await tick();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
it("keeps disclosure and text fallback without requesting microphone or age confirmation", async () => {
|
|
55
|
+
handler = async () => config(["text"]); await mount();
|
|
56
|
+
expect(container.textContent).toContain("no endorsement");
|
|
57
|
+
expect(container.querySelectorAll("button")).toHaveLength(0);
|
|
58
|
+
expect(container.querySelectorAll("input")).toHaveLength(0);
|
|
59
|
+
expect(stops).toHaveLength(0);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("a canceled older start cannot stop the next call when its response later fails", async () => {
|
|
63
|
+
const first = deferred<Response>(), second = deferred<Response>(); let starts = 0;
|
|
64
|
+
handler = body => body.action === "config" ? Promise.resolve(config())
|
|
65
|
+
: body.action === "start" ? (++starts === 1 ? first.promise : second.promise)
|
|
66
|
+
: Promise.resolve(json({ status: "ended" }));
|
|
67
|
+
await mount(); await click(labels.voice); expect(stops).toHaveLength(1);
|
|
68
|
+
await click(labels.end); expect(stops[0]).toHaveBeenCalledTimes(1);
|
|
69
|
+
await click(labels.voice); expect(stops).toHaveLength(2);
|
|
70
|
+
await act(async () => first.reject(new Error("old response lost"))); await tick();
|
|
71
|
+
expect(stops[1]).not.toHaveBeenCalled();
|
|
72
|
+
expect(container.textContent).toContain(labels.end);
|
|
73
|
+
expect(container.textContent).toContain(labels.connecting);
|
|
74
|
+
await act(async () => second.resolve(json({ status: "text" }))); await tick();
|
|
75
|
+
expect(stops[1]).toHaveBeenCalledTimes(1);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("leaving a queue stops local media and ends that exact bound ticket", async () => {
|
|
79
|
+
handler = async body => body.action === "config" ? config()
|
|
80
|
+
: body.action === "start" ? json({ status: "queued", session_id: "11111111-1111-4111-8111-111111111111" })
|
|
81
|
+
: json({ status: "expired" });
|
|
82
|
+
await mount(); await click(labels.video); expect(container.textContent).toContain(labels.waiting);
|
|
83
|
+
await click(labels.leave);
|
|
84
|
+
expect(stops[0]).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(requests.at(-1)).toEqual({ action: "end", sessionId: "11111111-1111-4111-8111-111111111111" });
|
|
86
|
+
expect(container.textContent).toContain(labels.video);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -29,7 +29,7 @@ process.env.STRIPE_WEBHOOK_SECRET = PAYMENTS_SECRET;
|
|
|
29
29
|
process.env.STRIPE_CONNECT_WEBHOOK_SECRET = CONNECT_SECRET;
|
|
30
30
|
const { resetEnvForTests } = await import("@/core/env");
|
|
31
31
|
resetEnvForTests();
|
|
32
|
-
const { proxy } = await import("../../proxy");
|
|
32
|
+
const { requestContextProxy: proxy } = await import("../../proxy");
|
|
33
33
|
const { previewGated } = await import("@/core/preview/private-preview");
|
|
34
34
|
const { POST: payments } = await import("../../app/api/payments/webhooks/stripe/route");
|
|
35
35
|
const { POST: payouts } = await import("../../app/api/payouts/[provider]/webhook/route");
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// routes with the key set and unset.
|
|
9
9
|
import { afterEach, describe, expect, it } from "vitest";
|
|
10
10
|
import { NextRequest } from "next/server";
|
|
11
|
-
import { proxy } from "../../proxy";
|
|
11
|
+
import { requestContextProxy as proxy } from "../../proxy";
|
|
12
12
|
import { resetEnvForTests } from "@/core/env";
|
|
13
13
|
import {
|
|
14
14
|
PREVIEW_COOKIE,
|
|
@@ -10,7 +10,7 @@ import { readdirSync } from "node:fs";
|
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { NextRequest } from "next/server";
|
|
12
12
|
import { describe, expect, it } from "vitest";
|
|
13
|
-
import { proxy } from "../../proxy";
|
|
13
|
+
import { requestContextProxy as proxy } from "../../proxy";
|
|
14
14
|
|
|
15
15
|
const ROOT = join(import.meta.dirname, "..", "..");
|
|
16
16
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright (C) 2026 Tony Aly
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// JSON Schema → TypeScript for the generated SDK (C3.03).
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { toContractJsonSchema } from "@/core/contract/json-schema";
|
|
4
6
|
import { describe, expect, it } from "vitest";
|
|
5
7
|
import { isPageableSchema, jsonSchemaToTs } from "@/core/contract/sdk";
|
|
6
8
|
|
|
@@ -104,3 +106,21 @@ describe("jsonSchemaToTs (C3.03)", () => {
|
|
|
104
106
|
).toBe(false);
|
|
105
107
|
});
|
|
106
108
|
});
|
|
109
|
+
|
|
110
|
+
// A real managed assistant action union first exposed MCP's object-only
|
|
111
|
+
// fallback. Keep one shared projection, not a hand-authored MCP action list.
|
|
112
|
+
it("retains complete action-object unions for MCP, HTTP and SDK without labeling mixed primitives objects", () => {
|
|
113
|
+
const input = z.discriminatedUnion("action", [
|
|
114
|
+
z.object({ action: z.literal("config"), token: z.string() }).strict(),
|
|
115
|
+
z.object({ action: z.literal("start"), token: z.string(), want: z.enum(["voice", "video"]) }).strict(),
|
|
116
|
+
]);
|
|
117
|
+
const schema = toContractJsonSchema(input, "input") as { type: string; oneOf: Array<{ required: string[]; properties: Record<string, unknown> }> };
|
|
118
|
+
expect(schema.type).toBe("object");
|
|
119
|
+
expect(schema.oneOf).toHaveLength(2);
|
|
120
|
+
expect(schema.oneOf[0]!.required).toEqual(["action", "token"]);
|
|
121
|
+
expect(schema.oneOf[1]!.required).toEqual(["action", "token", "want"]);
|
|
122
|
+
expect(jsonSchemaToTs(schema)).toContain('action: "config"');
|
|
123
|
+
expect(jsonSchemaToTs(schema)).toContain('action: "start"');
|
|
124
|
+
const mixed = toContractJsonSchema(z.union([z.string(), z.object({ id: z.string() })]), "input") as { type?: string };
|
|
125
|
+
expect(mixed.type).toBeUndefined();
|
|
126
|
+
});
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// not break every link to it.
|
|
10
10
|
import { afterAll, beforeEach, describe, expect, it } from "vitest";
|
|
11
11
|
import { NextRequest } from "next/server";
|
|
12
|
-
import { proxy } from "../../proxy";
|
|
12
|
+
import { requestContextProxy as proxy } from "../../proxy";
|
|
13
13
|
import {
|
|
14
14
|
breadcrumbJsonLd,
|
|
15
15
|
humanizeSegment,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// @vitest-environment jsdom
|
|
4
|
+
import { act, createElement } from "react";
|
|
5
|
+
import { createRoot } from "react-dom/client";
|
|
6
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
7
|
+
import { requireCsrf } from "@/core/http/csrf";
|
|
8
|
+
import { SiteChatClient } from "@/modules/cms/blocks/SiteChatClient";
|
|
9
|
+
|
|
10
|
+
vi.mock("../../app/(public)/inbound-actions", () => ({ postSiteChatAction: vi.fn() }));
|
|
11
|
+
|
|
12
|
+
afterEach(() => { vi.unstubAllGlobals(); document.cookie = "freeholder_csrf=; Max-Age=0; Path=/"; });
|
|
13
|
+
|
|
14
|
+
it("signed-in chat sends double-submit CSRF on message, assistant and End; other block placements offer no media admission", async () => {
|
|
15
|
+
(globalThis as Record<string, unknown>).IS_REACT_ACT_ENVIRONMENT = true;
|
|
16
|
+
document.cookie = "freeholder_csrf=fixture-token; Path=/";
|
|
17
|
+
const writes: string[] = [];
|
|
18
|
+
const transcript = { state: "open", escalated: false, messages: [], expiresAt: "2026-12-01T00:00:00Z" };
|
|
19
|
+
vi.stubGlobal("fetch", async (url: string, init?: RequestInit) => {
|
|
20
|
+
const method = init?.method ?? "GET";
|
|
21
|
+
expect(url).not.toBe("/api/chat/assistant/call");
|
|
22
|
+
if (method !== "GET") {
|
|
23
|
+
const headers = new Headers(init?.headers);
|
|
24
|
+
// The login cookie remains httpOnly. Model the HTTP guard's automatic credential attachment.
|
|
25
|
+
headers.set("cookie", `freeholder_session=fixture-session; ${document.cookie}`);
|
|
26
|
+
requireCsrf(new Request(`https://business.test${url}`, { method, headers }));
|
|
27
|
+
writes.push(`${method} ${url}`);
|
|
28
|
+
}
|
|
29
|
+
return new Response(JSON.stringify(url.endsWith("/assistant") ? { status: "answered" } : transcript), { headers: { "content-type": "application/json" } });
|
|
30
|
+
});
|
|
31
|
+
const labels = {
|
|
32
|
+
call: { label:"AI", captions:"Captions", video:"Video", voice:"Voice", leave:"Leave", end:"End call", waiting:"Waiting", unavailable:"Text", connecting:"Connecting", captionFailed:"Failed", ended:"Ended", lost:"Lost", microphone:"Microphone",voiceFallback:"Voice fallback" },
|
|
33
|
+
loading:"Loading",ended:"Ended",escalated:"Escalated",message:"Message",send:"Send",sending:"Sending",end:"End chat",fromYou:"You",fromBusiness:"Business",fromAssistant:"Assistant",failed:"Failed",
|
|
34
|
+
};
|
|
35
|
+
const container=document.createElement("div");document.body.append(container);const root=createRoot(container);
|
|
36
|
+
try {
|
|
37
|
+
await act(async () => {root.render(createElement(SiteChatClient,{locale:"fr",labels,path:"/fr/services"}));});
|
|
38
|
+
await act(async()=>{await new Promise(resolve=>setTimeout(resolve,0));});
|
|
39
|
+
expect(container.textContent).not.toContain("End call");
|
|
40
|
+
container.querySelector("textarea")!.value="A follow-up";
|
|
41
|
+
// React receives the browser's actual FormData implementation for a submitted HTML form.
|
|
42
|
+
vi.stubGlobal("FormData",window.FormData);
|
|
43
|
+
await act(async()=>{container.querySelector("form")!.dispatchEvent(new Event("submit",{bubbles:true,cancelable:true}));});
|
|
44
|
+
await act(async()=>{await new Promise(resolve=>setTimeout(resolve,0));});
|
|
45
|
+
const end=[...container.querySelectorAll("button")].find(button=>button.textContent==="End chat")!;
|
|
46
|
+
await act(async()=>{end.click();});
|
|
47
|
+
expect(writes).toEqual(["POST /api/chat","POST /api/chat/assistant","DELETE /api/chat"]);
|
|
48
|
+
expect(container.textContent).toContain("Ended");
|
|
49
|
+
} finally {await act(async()=>root.unmount());container.remove();}
|
|
50
|
+
});
|
|
@@ -291,7 +291,7 @@ describe("the local adapter refuses production (§18 storage mandate)", () => {
|
|
|
291
291
|
// is the least recoverable thing a business owns, so this fails loudly at
|
|
292
292
|
// boot instead of at restore time.
|
|
293
293
|
withEnv(
|
|
294
|
-
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined },
|
|
294
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: undefined },
|
|
295
295
|
() => {
|
|
296
296
|
expect(() =>
|
|
297
297
|
createLocalStorage({ root: ".data/media", publicPath: "/media" }),
|
|
@@ -302,13 +302,14 @@ describe("the local adapter refuses production (§18 storage mandate)", () => {
|
|
|
302
302
|
|
|
303
303
|
it("names the way out, so the error is actionable", () => {
|
|
304
304
|
withEnv(
|
|
305
|
-
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined },
|
|
305
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: undefined },
|
|
306
306
|
() => {
|
|
307
307
|
try {
|
|
308
308
|
createLocalStorage({ root: ".data/media", publicPath: "/media" });
|
|
309
309
|
} catch (error) {
|
|
310
310
|
const message = (error as Error).message;
|
|
311
311
|
expect(message).toContain("freeholder.config.ts");
|
|
312
|
+
expect(message).toContain("LOCAL_STORAGE_ROOT");
|
|
312
313
|
expect(message).toContain("FREEHOLDER_UNSAFE_LOCAL_STORAGE=1");
|
|
313
314
|
}
|
|
314
315
|
},
|
|
@@ -326,6 +327,41 @@ describe("the local adapter refuses production (§18 storage mandate)", () => {
|
|
|
326
327
|
);
|
|
327
328
|
});
|
|
328
329
|
|
|
330
|
+
it("accepts an explicit, existing persistent directory in production (C3.44)", async () => {
|
|
331
|
+
const persistent = await mkdtemp(join(tmpdir(), "freeholder-persistent-"));
|
|
332
|
+
try {
|
|
333
|
+
withEnv(
|
|
334
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: persistent },
|
|
335
|
+
() => {
|
|
336
|
+
const adapter = createLocalStorage({ root: persistent, publicPath: "/media" });
|
|
337
|
+
// Served only through the app's /media route, which re-checks access.
|
|
338
|
+
expect(adapter.isPublic).toBe(false);
|
|
339
|
+
},
|
|
340
|
+
);
|
|
341
|
+
} finally {
|
|
342
|
+
await rm(persistent, { recursive: true, force: true });
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("refuses a persistent directory that does not exist, instead of creating it in the container layer", () => {
|
|
347
|
+
const missing = join(tmpdir(), `freeholder-missing-${Date.now()}`);
|
|
348
|
+
withEnv(
|
|
349
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: missing },
|
|
350
|
+
() => {
|
|
351
|
+
expect(() => createLocalStorage({ root: missing, publicPath: "/media" })).toThrow(/existing directory/);
|
|
352
|
+
},
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("still refuses a relative directory in production", () => {
|
|
357
|
+
withEnv(
|
|
358
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: ".data/media" },
|
|
359
|
+
() => {
|
|
360
|
+
expect(() => createLocalStorage({ root: ".data/media", publicPath: "/media" })).toThrow(/LOCAL_STORAGE_ROOT/);
|
|
361
|
+
},
|
|
362
|
+
);
|
|
363
|
+
});
|
|
364
|
+
|
|
329
365
|
it("says nothing outside production", () => {
|
|
330
366
|
withEnv({ NODE_ENV: "development" }, () => {
|
|
331
367
|
expect(() =>
|
|
@@ -22,7 +22,13 @@ import {
|
|
|
22
22
|
reconcileImport,
|
|
23
23
|
rollbackImport,
|
|
24
24
|
startImport,
|
|
25
|
+
reviewImportConflicts,
|
|
26
|
+
wordpressVerificationPlan,
|
|
25
27
|
} from "@/core/import/service";
|
|
28
|
+
import { saveAuthor, setPostMeta, postMetaAt, resolveBlogArchive } from "@/modules/cms/blog-service";
|
|
29
|
+
import { listReaderComments } from "@/modules/cms/blog-comments";
|
|
30
|
+
import { blogReaderComments } from "@/modules/cms/blog-comments-schema";
|
|
31
|
+
import { resolveRedirect } from "@/core/seo/service";
|
|
26
32
|
import { closeDb, hasDatabase, OWNER, truncateSpine } from "../helpers/spine";
|
|
27
33
|
|
|
28
34
|
const getPinnedBytes = vi.hoisted(() => vi.fn());
|
|
@@ -77,9 +83,9 @@ describe.runIf(hasDatabase)("WordPress import studio", { timeout: 60_000 }, () =
|
|
|
77
83
|
const started = await startImport.call({ origin: "https://old.example.org", kind: "wordpress-wxr" }, OWNER);
|
|
78
84
|
const previewed = await previewFromSource.call({ id: started.id, payload: FIXTURE }, OWNER);
|
|
79
85
|
expect(previewed.status).toBe("previewed");
|
|
80
|
-
expect(previewed.counts).toMatchObject({ pages: 5, posts: 3, media: 2, redirects:
|
|
86
|
+
expect(previewed.counts).toMatchObject({ pages: 5, posts: 3, media: 2, redirects: 0, menus: 1, commentsSkipped: 2 });
|
|
81
87
|
// Nothing is written by a preview.
|
|
82
|
-
expect(await pageAt("
|
|
88
|
+
expect(await pageAt("2025/03/first-wood-firing")).toBeUndefined();
|
|
83
89
|
|
|
84
90
|
const committed = await commitImport.call({ id: started.id }, OWNER);
|
|
85
91
|
expect(committed.status).toBe("committed");
|
|
@@ -90,12 +96,13 @@ describe.runIf(hasDatabase)("WordPress import studio", { timeout: 60_000 }, () =
|
|
|
90
96
|
posts: 3,
|
|
91
97
|
media: 2,
|
|
92
98
|
mediaFailed: 0,
|
|
93
|
-
redirects:
|
|
99
|
+
redirects: 0,
|
|
94
100
|
menus: 1,
|
|
95
101
|
categories: 2,
|
|
96
102
|
tags: 1,
|
|
97
103
|
authors: 1,
|
|
98
|
-
|
|
104
|
+
commentsImported: 2,
|
|
105
|
+
commentsSkipped: 0,
|
|
99
106
|
skippedPages: 0,
|
|
100
107
|
});
|
|
101
108
|
// The external image is never fetched; only the two attachments are.
|
|
@@ -114,36 +121,45 @@ describe.runIf(hasDatabase)("WordPress import studio", { timeout: 60_000 }, () =
|
|
|
114
121
|
sourceUrl: "https://old.example.org/wp-content/uploads/2025/03/kiln.jpg",
|
|
115
122
|
});
|
|
116
123
|
|
|
117
|
-
const post = (await pageAt("
|
|
124
|
+
const post = (await pageAt("2025/03/first-wood-firing"))!;
|
|
118
125
|
expect(post.status).toBe("draft");
|
|
119
126
|
expect(post.seo).toEqual({
|
|
120
127
|
title: expect.stringMatching(/^Our First Wood Firing – Wood firing diary/) as unknown,
|
|
121
128
|
description: "Three days of loading and two of stoking.",
|
|
129
|
+
preserveTitle: true,
|
|
130
|
+
preserveDescription: true,
|
|
122
131
|
});
|
|
123
132
|
const blocks = post.blocks as Array<{ type: string; props: Record<string, unknown> }>;
|
|
124
133
|
expect(blocks.filter((block) => block.type === "image").map((block) => block.props.assetId)).toEqual([kiln.id]);
|
|
125
|
-
expect(JSON.stringify(blocks)).toContain('"href":"/
|
|
134
|
+
expect(JSON.stringify(blocks)).toContain('"href":"/glaze-notes"');
|
|
126
135
|
expect((await pageAt("about/team"))!.status).toBe("draft");
|
|
127
|
-
expect(JSON.stringify((await pageAt("about"))!.blocks)).toContain('"href":"/
|
|
136
|
+
expect(JSON.stringify((await pageAt("about"))!.blocks)).toContain('"href":"/2025/03/first-wood-firing"');
|
|
128
137
|
expect((await pageAt("blog"))!.blocks).toEqual(expect.arrayContaining([expect.objectContaining({ type: "blogIndex" })]));
|
|
129
138
|
|
|
130
139
|
const moved = await db().select().from(redirects);
|
|
131
|
-
expect(moved.
|
|
132
|
-
["2025/03/first-wood-firing", "blog/first-wood-firing", "import"],
|
|
133
|
-
["glaze-notes", "blog/glaze-notes", "import"],
|
|
134
|
-
]);
|
|
140
|
+
expect(moved).toEqual([]);
|
|
135
141
|
|
|
136
142
|
const reconciled = await reconcileImport.call({ id: started.id }, OWNER);
|
|
137
143
|
expect(reconciled.checkpoint).toMatchObject({
|
|
138
|
-
reconciliation: { found: { pages: 5, media: 2, redirects:
|
|
144
|
+
reconciliation: { found: { pages: 5, media: 2, redirects: 0 }, matches: true },
|
|
139
145
|
});
|
|
140
146
|
|
|
141
147
|
const published = await publishImport.call({ id: started.id }, OWNER);
|
|
142
148
|
expect(published.status).toBe("published");
|
|
143
|
-
expect((await pageAt("
|
|
149
|
+
expect((await pageAt("2025/03/first-wood-firing"))!.publishedAt?.toISOString()).toBe("2025-03-14T18:00:00.000Z");
|
|
144
150
|
expect((await pageAt("blog/upcoming-sale"))!.status).toBe("draft");
|
|
145
151
|
const listing = await listBlogPosts.call({ locale: "en", prefix: "blog", page: 1, limit: 12 }, { kind: "anonymous" });
|
|
146
|
-
expect(listing.posts.map((entry) => entry.slug)).toEqual(["
|
|
152
|
+
expect(listing.posts.map((entry) => entry.slug)).toEqual(["glaze-notes", "2025/03/first-wood-firing"]);
|
|
153
|
+
expect(await resolveRedirect.call({ path: "?p=20" }, { kind: "anonymous" })).toEqual({ toPath: post.slug, status: "301" });
|
|
154
|
+
expect(await resolveRedirect.call({ path: "?attachment_id=10" }, { kind: "anonymous" })).toEqual({ toPath: post.slug, status: "301" });
|
|
155
|
+
expect(await resolveBlogArchive.call({ path: "author/maple" }, { kind: "anonymous" })).toMatchObject({ name: "Maple Rivers", posts: 2 });
|
|
156
|
+
expect(await resolveBlogArchive.call({ path: "2025/03" }, { kind: "anonymous" })).toMatchObject({ kind: "date", posts: 1 });
|
|
157
|
+
expect(await resolveRedirect.call({ path: "author/maple/page/1" }, { kind: "anonymous" })).toEqual({ toPath: "author/maple", status: "301" });
|
|
158
|
+
expect(await resolveRedirect.call({ path: "author/maple/page/9999" }, { kind: "anonymous" })).toBeNull();
|
|
159
|
+
expect(await listReaderComments.call({ pageId: post.id }, { kind: "anonymous" })).toHaveLength(1);
|
|
160
|
+
const verification = await wordpressVerificationPlan.call({ id: started.id }, OWNER);
|
|
161
|
+
expect(verification.checks.some(check => check.requestPath === "/?p=20" && check.redirect)).toBe(true);
|
|
162
|
+
expect(verification.checks.some(check => check.destinationPath.includes("upcoming-sale"))).toBe(false);
|
|
147
163
|
const [nav] = await db()
|
|
148
164
|
.select()
|
|
149
165
|
.from(sections)
|
|
@@ -151,12 +167,12 @@ describe.runIf(hasDatabase)("WordPress import studio", { timeout: 60_000 }, () =
|
|
|
151
167
|
// Top-level items only: the nav block is flat, so "Team" stays on record.
|
|
152
168
|
expect((nav!.blocks as Array<{ props: { links: unknown[] } }>)[0]!.props.links).toEqual([
|
|
153
169
|
{ label: "About", href: "/about" },
|
|
154
|
-
{ label: "Journal", href: "/
|
|
170
|
+
{ label: "Journal", href: "/2025/03/first-wood-firing" },
|
|
155
171
|
]);
|
|
156
172
|
|
|
157
173
|
const rolled = await rollbackImport.call({ id: started.id }, OWNER);
|
|
158
174
|
expect(rolled.status).toBe("rolled_back");
|
|
159
|
-
expect(await pageAt("
|
|
175
|
+
expect(await pageAt("2025/03/first-wood-firing")).toBeUndefined();
|
|
160
176
|
expect((await pageAt("blog"))!.status).toBe("published");
|
|
161
177
|
expect(await db().select().from(redirects)).toHaveLength(0);
|
|
162
178
|
expect((await db().select().from(assets)).every((asset) => asset.status === "trashed")).toBe(true);
|
|
@@ -191,11 +207,11 @@ describe.runIf(hasDatabase)("WordPress import studio", { timeout: 60_000 }, () =
|
|
|
191
207
|
},
|
|
192
208
|
});
|
|
193
209
|
// The page still lands, without the picture it could not fetch.
|
|
194
|
-
const post = (await pageAt("
|
|
210
|
+
const post = (await pageAt("2025/03/first-wood-firing"))!;
|
|
195
211
|
expect(JSON.stringify(post.blocks)).not.toContain('"type":"image"');
|
|
196
212
|
|
|
197
213
|
await rollbackImport.call({ id: started.id }, OWNER);
|
|
198
|
-
expect(await pageAt("
|
|
214
|
+
expect(await pageAt("2025/03/first-wood-firing")).toBeUndefined();
|
|
199
215
|
expect(await pageAt("blog")).toBeUndefined();
|
|
200
216
|
});
|
|
201
217
|
|
|
@@ -213,4 +229,51 @@ describe.runIf(hasDatabase)("WordPress import studio", { timeout: 60_000 }, () =
|
|
|
213
229
|
expect(rolled.status).toBe("rolled_back");
|
|
214
230
|
expect((await db().select().from(assets)).every((asset) => asset.status === "trashed")).toBe(true);
|
|
215
231
|
});
|
|
232
|
+
|
|
233
|
+
it("stages live replacement bylines and approved comments until cutover, then restores the original date and metadata on rollback", async () => {
|
|
234
|
+
const { createPage, publishPage } = await import("@/modules/cms/service");
|
|
235
|
+
const page = await createPage.call({ slug: "2025/03/first-wood-firing", title: "Original live title", blocks: [{ id: "original-h", type: "heading", props: { text: "Original live title", level: 1 } }] }, OWNER);
|
|
236
|
+
const author = await saveAuthor.call({ name: "Original Author" }, OWNER);
|
|
237
|
+
await setPostMeta.call({ pageId: page.id, isPost: true, authorId: author.id, commentsEnabled: false }, OWNER);
|
|
238
|
+
const originalDate = "2024-01-02T12:00:00.000Z";
|
|
239
|
+
await publishPage.call({ id: page.id, published: true, publishedAt: originalDate }, OWNER);
|
|
240
|
+
const started = await startImport.call({ origin: "https://old.example.org", kind: "wordpress-wxr" }, OWNER);
|
|
241
|
+
await previewFromSource.call({ id: started.id, payload: FIXTURE }, OWNER);
|
|
242
|
+
await reviewImportConflicts.call({ id: started.id, conflicts: [{ slug: page.slug, resolution: "replace" }] }, OWNER);
|
|
243
|
+
const committed = await commitImport.call({ id: started.id }, OWNER);
|
|
244
|
+
expect(committed.counts).toMatchObject({ commentsImported: 0, commentsStaged: 2, commentsSkipped: 0 });
|
|
245
|
+
expect((await postMetaAt.call({ slug: page.slug }, { kind: "anonymous" }))?.author?.name).toBe("Original Author");
|
|
246
|
+
expect(await listReaderComments.call({ pageId: page.id }, { kind: "anonymous" })).toEqual([]);
|
|
247
|
+
await reconcileImport.call({ id: started.id }, OWNER);
|
|
248
|
+
await publishImport.call({ id: started.id }, OWNER);
|
|
249
|
+
expect((await postMetaAt.call({ slug: page.slug }, { kind: "anonymous" }))?.author?.name).toBe("Maple Rivers");
|
|
250
|
+
expect(await listReaderComments.call({ pageId: page.id }, { kind: "anonymous" })).toHaveLength(1);
|
|
251
|
+
await rollbackImport.call({ id: started.id }, OWNER);
|
|
252
|
+
const restored = await pageAt(page.slug);
|
|
253
|
+
expect(restored?.title).toBe("Original live title");
|
|
254
|
+
expect(restored?.publishedAt?.toISOString()).toBe(originalDate);
|
|
255
|
+
expect((await postMetaAt.call({ slug: page.slug }, { kind: "anonymous" }))?.author?.name).toBe("Original Author");
|
|
256
|
+
expect(await listReaderComments.call({ pageId: page.id }, { kind: "anonymous" })).toEqual([]);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("hides an old blog thread when an ordinary page replaces it, and restores the same history on rollback", async () => {
|
|
260
|
+
const { createPage, publishPage } = await import("@/modules/cms/service");
|
|
261
|
+
const page = await createPage.call({ slug: "about", title: "An old blog post", blocks: [{ id: "old-h", type: "heading", props: { text: "An old blog post", level: 1 } }] }, OWNER);
|
|
262
|
+
await setPostMeta.call({ pageId: page.id, isPost: true }, OWNER);
|
|
263
|
+
await publishPage.call({ id: page.id, published: true }, OWNER);
|
|
264
|
+
const [comment] = await db().insert(blogReaderComments).values({ pageId: page.id, authorName: "Original Reader", body: "Original approved history", status: "approved" }).returning();
|
|
265
|
+
const started = await startImport.call({ origin: "https://old.example.org", kind: "wordpress-wxr" }, OWNER);
|
|
266
|
+
await previewFromSource.call({ id: started.id, payload: FIXTURE }, OWNER);
|
|
267
|
+
await reviewImportConflicts.call({ id: started.id, conflicts: [{ slug: "about", resolution: "replace" }] }, OWNER);
|
|
268
|
+
await commitImport.call({ id: started.id }, OWNER);
|
|
269
|
+
expect(await listReaderComments.call({ pageId: page.id }, { kind: "anonymous" })).toHaveLength(1);
|
|
270
|
+
await reconcileImport.call({ id: started.id }, OWNER);
|
|
271
|
+
await publishImport.call({ id: started.id }, OWNER);
|
|
272
|
+
expect(await postMetaAt.call({ slug: page.slug }, { kind: "anonymous" })).toBeNull();
|
|
273
|
+
expect(await listReaderComments.call({ pageId: page.id }, { kind: "anonymous" })).toEqual([]);
|
|
274
|
+
expect((await db().select().from(blogReaderComments).where(eq(blogReaderComments.id, comment!.id)))[0]?.body).toBe("Original approved history");
|
|
275
|
+
await rollbackImport.call({ id: started.id }, OWNER);
|
|
276
|
+
expect((await postMetaAt.call({ slug: page.slug }, { kind: "anonymous" }))?.pageId).toBe(page.id);
|
|
277
|
+
expect((await listReaderComments.call({ pageId: page.id }, { kind: "anonymous" }))[0]?.id).toBe(comment!.id);
|
|
278
|
+
});
|
|
216
279
|
});
|
|
@@ -36,7 +36,7 @@ function context(overrides: Partial<BodyContext> = {}): BodyContext {
|
|
|
36
36
|
: wpId === "11" || src.includes("glaze")
|
|
37
37
|
? { assetId: GLAZE }
|
|
38
38
|
: null,
|
|
39
|
-
rewriteHref: (href) => href.replace("https://old.example.org/glaze-notes/", "/
|
|
39
|
+
rewriteHref: (href) => href.replace("https://old.example.org/glaze-notes/", "/glaze-notes"),
|
|
40
40
|
...overrides,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
@@ -63,6 +63,19 @@ describe("WordPress WXR export (C3.22)", () => {
|
|
|
63
63
|
expect(exported.skipped).toEqual({ "status: trash": 1, "post type: product": 1 });
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
it("preserves reader paragraph boundaries while removing executable HTML", () => {
|
|
67
|
+
const changed = FIXTURE.replace("Lovely kiln!", "<p>First paragraph.</p><p>Next<br>line.</p><script>hidden()</script>");
|
|
68
|
+
const parsed = parseWordpressExport(changed);
|
|
69
|
+
const post = parsed.items.find(item => item.comments.entries?.length);
|
|
70
|
+
expect(post?.comments.entries?.find(comment => comment.status === "approved")?.body).toBe("First paragraph.\n\nNext\nline.");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("preserves a source home page at the empty CMS path", () => {
|
|
74
|
+
const changed = FIXTURE.replace("<link>https://old.example.org/about/</link>", "<link>https://old.example.org/</link>");
|
|
75
|
+
const plan = planWordpressImport(parseWordpressExport(changed), ORIGIN);
|
|
76
|
+
expect(plan.pages.find(page => page.wpId === "30")?.slug).toBe("");
|
|
77
|
+
});
|
|
78
|
+
|
|
66
79
|
it("keeps dates, terms, SEO, featured images and comment counts", () => {
|
|
67
80
|
const post = exported.items.find((item) => item.slug === "first-wood-firing")!;
|
|
68
81
|
expect(post.publishedAt).toBe("2025-03-14T18:00:00.000Z");
|
|
@@ -71,11 +84,11 @@ describe("WordPress WXR export (C3.22)", () => {
|
|
|
71
84
|
expect(post.seo.title).toBe("Our First Wood Firing – Wood firing diary from a very small studio in the hills");
|
|
72
85
|
expect(post.seo.description).toBe("Three days of loading and two of stoking.");
|
|
73
86
|
expect(post.featuredWpId).toBe("10");
|
|
74
|
-
expect(post.comments).
|
|
87
|
+
expect(post.comments).toMatchObject({ total: 2, approved: 1 });
|
|
75
88
|
// A body that says </item> inside CDATA does not end the item.
|
|
76
89
|
expect(post.body).toContain("</item> on purpose");
|
|
77
90
|
const about = exported.items.find((item) => item.slug === "about")!;
|
|
78
|
-
expect(about.seo).
|
|
91
|
+
expect(about.seo).toMatchObject({
|
|
79
92
|
title: "About the Studio – Fernwood Kiln",
|
|
80
93
|
description: "A small studio making wood-fired stoneware by hand.",
|
|
81
94
|
});
|
|
@@ -97,12 +110,12 @@ describe("WordPress WXR export (C3.22)", () => {
|
|
|
97
110
|
describe("WordPress import plan (C3.22)", () => {
|
|
98
111
|
const plan = planWordpressImport(parseWordpressExport(FIXTURE), ORIGIN);
|
|
99
112
|
|
|
100
|
-
it("
|
|
113
|
+
it("keeps original page and post permalinks; query-only posts get a blog address", () => {
|
|
101
114
|
expect(plan.pages.map((page) => [page.slug, page.redirectFrom ?? null])).toEqual([
|
|
102
115
|
["about", null],
|
|
103
116
|
["about/team", null],
|
|
104
|
-
["
|
|
105
|
-
["
|
|
117
|
+
["2025/03/first-wood-firing", null],
|
|
118
|
+
["glaze-notes", null],
|
|
106
119
|
// `/?p=22` has no path of its own, so there is nothing to redirect.
|
|
107
120
|
["blog/upcoming-sale", null],
|
|
108
121
|
]);
|
|
@@ -116,7 +129,7 @@ describe("WordPress import plan (C3.22)", () => {
|
|
|
116
129
|
["glaze-scaled.png", true],
|
|
117
130
|
]);
|
|
118
131
|
expect(plan.media[1]!.aliases).toContain("old.example.org/wp-content/uploads/2025/04/glaze.png");
|
|
119
|
-
expect(plan.pages.find((page) => page.slug === "
|
|
132
|
+
expect(plan.pages.find((page) => page.slug === "2025/03/first-wood-firing")!.featuredMedia).toBe(plan.media[0]!.key);
|
|
120
133
|
expect(plan.report.externalImages).toEqual(["https://cdn.other.example.net/borrowed.jpg"]);
|
|
121
134
|
});
|
|
122
135
|
|
|
@@ -129,8 +142,8 @@ describe("WordPress import plan (C3.22)", () => {
|
|
|
129
142
|
{ login: "maple", displayName: "Maple Rivers", email: "maple@example.org", posts: 3 },
|
|
130
143
|
]);
|
|
131
144
|
expect(plan.report.comments).toEqual({ total: 2, approved: 1 });
|
|
132
|
-
expect(plan.report.seoTrimmed).toBe(
|
|
133
|
-
expect(plan.pages.find((page) => page.slug === "
|
|
145
|
+
expect(plan.report.seoTrimmed).toBe(0);
|
|
146
|
+
expect(plan.pages.find((page) => page.slug === "2025/03/first-wood-firing")!.seo.title).toBe("Our First Wood Firing – Wood firing diary from a very small studio in the hills");
|
|
134
147
|
});
|
|
135
148
|
|
|
136
149
|
it("maps menu items to imported pages, custom links and nesting", () => {
|
|
@@ -172,7 +185,7 @@ describe("WordPress body conversion (C3.22)", () => {
|
|
|
172
185
|
expect(title!.props).toMatchObject({ text: "Our First Wood Firing", level: 1 });
|
|
173
186
|
expect(section!.props).toMatchObject({ text: "Loading the kiln", level: 2 });
|
|
174
187
|
expect(JSON.stringify(prose!.props.body)).toContain('"marks":["strong"]');
|
|
175
|
-
expect(JSON.stringify(prose!.props.body)).toContain('"href":"/
|
|
188
|
+
expect(JSON.stringify(prose!.props.body)).toContain('"href":"/glaze-notes"');
|
|
176
189
|
expect(image!.props).toEqual({ assetId: KILN, alt: "A brick kiln stacked with bowls" });
|
|
177
190
|
expect(JSON.stringify(after!.props.body)).toContain("Packed and ready.");
|
|
178
191
|
expect(JSON.stringify(after!.props.body)).toContain('"type":"bulletList"');
|
|
@@ -253,8 +266,8 @@ describe("WordPress REST payloads (C3.22)", () => {
|
|
|
253
266
|
});
|
|
254
267
|
expect(exported.skipped).toEqual({ "post type: wp_block": 1 });
|
|
255
268
|
expect(planWordpressImport(exported, ORIGIN).pages[0]).toMatchObject({
|
|
256
|
-
slug: "
|
|
257
|
-
redirectFrom:
|
|
269
|
+
slug: "2025/01/hello",
|
|
270
|
+
redirectFrom: undefined,
|
|
258
271
|
});
|
|
259
272
|
});
|
|
260
273
|
});
|