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,37 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { afterAll, describe, expect, it } from "vitest";
|
|
4
|
+
import { createServer, type Server } from "node:http";
|
|
5
|
+
import { htmlMetadata, verifyMigration } from "../../scripts/verify-wordpress-migration.mjs";
|
|
6
|
+
const servers: Server[] = [];
|
|
7
|
+
async function fixture(mode: "source" | "destination") {
|
|
8
|
+
const server = createServer((request, response) => {
|
|
9
|
+
if (request.url === "/old" || request.url === "/two") { response.writeHead(301, { location: request.url === "/old" ? "/story" : "/old" }).end(); return; }
|
|
10
|
+
response.writeHead(200, { "content-type": "text/html; charset=utf-8" }).end(`<html><head><title>A complete original title & its brand</title><meta name="description" content="A description."><link rel="canonical" href="/story"><meta property="og:title" content="A social title"><meta property="og:description" content="A social description"><meta property="og:image" content="https://images.example.test/owned.jpg">${request.url === "/mismatch" && mode === "destination" ? '<meta name="robots" content="noindex">' : ''}<link rel="alternate" hreflang="fr" href="/fr/story"></head><body>Story</body></html>`);
|
|
11
|
+
});
|
|
12
|
+
await new Promise<void>(resolve => server.listen(0, "127.0.0.1", resolve)); servers.push(server);
|
|
13
|
+
const address = server.address(); if (!address || typeof address === "string") throw new Error("No fixture port.");
|
|
14
|
+
return `http://127.0.0.1:${address.port}`;
|
|
15
|
+
}
|
|
16
|
+
afterAll(async () => { await Promise.all(servers.map(server => new Promise<void>((resolve, reject) => server.close(error => error ? reject(error) : resolve())))); });
|
|
17
|
+
|
|
18
|
+
describe("WordPress migration HTTP acceptance report", () => {
|
|
19
|
+
it("reads entities and metadata from parsed HTML", () => {
|
|
20
|
+
expect(htmlMetadata('<title>Full & exact</title><meta name="robots" content="noindex"><link rel="alternate" hreflang="ar" href="/ar/story">')).toMatchObject({ title: "Full & exact", robots: "noindex", hreflang: { ar: "/ar/story" } });
|
|
21
|
+
});
|
|
22
|
+
it("accepts preserved pages and one literal301 alias, but fails two-hop redirects and unresolved source decisions", async () => {
|
|
23
|
+
const source = await fixture("source"), destination = await fixture("destination");
|
|
24
|
+
const plan = { sourceOrigin: source, status: "published", warnings: [] as string[], checks: [
|
|
25
|
+
{ sourceUrl: `${source}/story`, requestPath: "/story", destinationPath: "/story", redirect: false, expected: { title: "A complete original title & its brand" } },
|
|
26
|
+
{ sourceUrl: `${source}/old`, requestPath: "/old", destinationPath: "/story", redirect: true, expected: {} },
|
|
27
|
+
] };
|
|
28
|
+
expect(await verifyMigration(plan, destination)).toMatchObject({ accepted: true });
|
|
29
|
+
const failed = await verifyMigration({ ...plan, checks: [{ ...plan.checks[1]!, requestPath: "/two" }] }, destination);
|
|
30
|
+
expect(failed.accepted).toBe(false);
|
|
31
|
+
expect(failed.rows[0]!.errors.join(" ")).toContain("301");
|
|
32
|
+
expect(await verifyMigration({ ...plan, warnings: ["Choose a destination for an orphan attachment."] }, destination)).toMatchObject({ accepted: false });
|
|
33
|
+
const changed = await verifyMigration({ ...plan, checks: [{ ...plan.checks[0]!, sourceUrl: `${source}/mismatch`, requestPath: "/mismatch" }] }, destination);
|
|
34
|
+
expect(changed.accepted).toBe(false);
|
|
35
|
+
expect(changed.rows[0]!.errors).toContain("noindex changed from the source.");
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
|
6
|
+
import { db } from "@/core/db";
|
|
7
|
+
import { ready } from "@/core/runtime";
|
|
8
|
+
import { updateBusiness } from "@/core/settings/service";
|
|
9
|
+
import { getSiteChat, startSiteChat } from "@/core/messaging/chat";
|
|
10
|
+
import { assistantTurns } from "@/modules/assistant/schema";
|
|
11
|
+
import { answer, updateSettings, previewCall, settings, managedDetails, syncManagedSettings } from "@/modules/assistant/service";
|
|
12
|
+
import { setParadiseFetchForTests } from "@/adapters/paradise/http";
|
|
13
|
+
import { contentSecurityPolicy, isPreviewAssistantContactPath } from "@/core/http/csp";
|
|
14
|
+
import { installLaunch, launchPages, launchSpecSchema } from "@/modules/seed/launch";
|
|
15
|
+
import { ANONYMOUS, OWNER, closeDb, failure, hasDatabase, truncateSpine } from "../helpers/spine";
|
|
16
|
+
import { openTransactions } from "../helpers/open-transactions";
|
|
17
|
+
import { resetEnvForTests } from "@/core/env";
|
|
18
|
+
|
|
19
|
+
const requestBody = (value: BodyInit | null | undefined): Record<string, unknown> =>
|
|
20
|
+
typeof value === "string" ? JSON.parse(value) as Record<string, unknown> : {};
|
|
21
|
+
|
|
22
|
+
describe("managed preview consumer contracts", () => {
|
|
23
|
+
it("keeps v1/v2 unchanged and requires explicit v3 assistant/SFW settings", () => {
|
|
24
|
+
const base = JSON.parse(readFileSync("seed/launch/example-v2.json", "utf8")) as Record<string, unknown>;
|
|
25
|
+
expect(launchSpecSchema.parse(base).version).toBe(2);
|
|
26
|
+
expect(launchSpecSchema.safeParse({ ...base, version: 3 }).success).toBe(false);
|
|
27
|
+
const v3 = launchSpecSchema.parse({ ...base, version: 3, assistant: { provider: "paradise", enabled: true, dailyCapUsd: 1, contentMode: "sfw" } });
|
|
28
|
+
expect(JSON.stringify(launchPages(v3))).toContain('"type":"siteChat"');
|
|
29
|
+
expect(JSON.stringify(launchPages(v3))).toContain("not an endorsement");
|
|
30
|
+
expect(launchSpecSchema.safeParse({ ...v3, version: 2 }).success).toBe(false);
|
|
31
|
+
expect(launchSpecSchema.safeParse({ ...v3, assistant: { ...v3.assistant, contentMode: "adult" } }).success).toBe(false);
|
|
32
|
+
expect(JSON.stringify(v3)).not.toContain("age_confirmed");
|
|
33
|
+
});
|
|
34
|
+
it("pins the distributed shared transport and every same-origin codec byte", () => {
|
|
35
|
+
const root = "public/managed-assistant/0.1.10/";
|
|
36
|
+
const manifest = JSON.parse(readFileSync(`${root}manifest.json`, "utf8")) as { codecs: Record<string, string>; moduleSha256: string };
|
|
37
|
+
for (const [name, hash] of Object.entries(manifest.codecs)) {
|
|
38
|
+
expect(createHash("sha256").update(readFileSync(`${root}duplex-codec/${name}`)).digest("hex")).toBe(hash);
|
|
39
|
+
}
|
|
40
|
+
const bundle = readFileSync(`${root}pm-ai-duplex-client.js`, "utf8");
|
|
41
|
+
expect(bundle).toContain('"0.1.10"');
|
|
42
|
+
expect(createHash("sha256").update(bundle.split("\n").slice(3).join("\n")).digest("hex")).toBe(manifest.moduleSha256);
|
|
43
|
+
});
|
|
44
|
+
it("only opens configured call origins and wasm on the assistant surface", () => {
|
|
45
|
+
const options = { nonce: "fixture", production: true, assistantOrigins: ["https://voice.test", "wss://voice.test"] };
|
|
46
|
+
expect(contentSecurityPolicy({ ...options, path: "/contact" })).toContain("https://voice.test wss://voice.test");
|
|
47
|
+
expect(contentSecurityPolicy({ ...options, path: "/contact" })).toContain("'wasm-unsafe-eval'");
|
|
48
|
+
for (const path of ["/fr/contact", "/ar/contact", "/en-CA/contact/"]) {
|
|
49
|
+
expect(isPreviewAssistantContactPath(path)).toBe(true);
|
|
50
|
+
expect(contentSecurityPolicy({ ...options, path })).toContain("https://voice.test wss://voice.test");
|
|
51
|
+
expect(contentSecurityPolicy({ ...options, path })).toContain("'wasm-unsafe-eval'");
|
|
52
|
+
}
|
|
53
|
+
for (const path of ["/", "/fr/services", "/admin", "/contact/other", "/fr/admin/contact"]) {
|
|
54
|
+
expect(isPreviewAssistantContactPath(path)).toBe(false);
|
|
55
|
+
expect(contentSecurityPolicy({ ...options, path })).not.toContain("voice.test");
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe.runIf(hasDatabase)("managed assistants on the existing chat spine", () => {
|
|
61
|
+
beforeAll(async () => ready(), 180000);
|
|
62
|
+
beforeEach(async () => {
|
|
63
|
+
await truncateSpine();
|
|
64
|
+
await updateBusiness.call({ name: "Harbour Studio", country: "CA", baseCurrency: "CAD", timezone: "America/Vancouver" }, OWNER);
|
|
65
|
+
process.env.PARADISEMODERN_API_KEY = "test-only-managed-key";
|
|
66
|
+
process.env.PARADISEMODERN_URL = "https://pm.test";
|
|
67
|
+
process.env.PARADISEMODERN_ASSISTANT_ORIGINS = "https://voice.test";
|
|
68
|
+
resetEnvForTests();
|
|
69
|
+
await updateSettings.call({ enabled: true, provider: "paradise", model: "paradise-managed-assistant", maxOutputTokens: 600, spendCapCents: 100, spendPeriod: "day" }, OWNER);
|
|
70
|
+
});
|
|
71
|
+
afterEach(() => { setParadiseFetchForTests(undefined); });
|
|
72
|
+
afterAll(async () => {
|
|
73
|
+
delete process.env.PARADISEMODERN_API_KEY; delete process.env.PARADISEMODERN_URL; delete process.env.PARADISEMODERN_ASSISTANT_ORIGINS;
|
|
74
|
+
await closeDb();
|
|
75
|
+
});
|
|
76
|
+
const chat = () => startSiteChat.call({ name: "Visitor", email: `${randomUUID()}@example.com`, message: "Hello", locale: "en" }, ANONYMOUS);
|
|
77
|
+
const reply = (body: unknown) => new Response(JSON.stringify(body), { headers: { "content-type": "application/json" } });
|
|
78
|
+
|
|
79
|
+
it("binds text to the cookie, holds the consumer cap and records its actual receipt on the canonical transcript", async () => {
|
|
80
|
+
const session = await chat(); let sent: Record<string, unknown> = {};
|
|
81
|
+
setParadiseFetchForTests(async (_url, init) => {
|
|
82
|
+
expect(await openTransactions()).toBe(0);
|
|
83
|
+
sent = requestBody(init.body);
|
|
84
|
+
return reply({ text: "Hello! How can I help?", model: "managed-model", metered_list_usd: .04, content_mode: "sfw" });
|
|
85
|
+
});
|
|
86
|
+
expect((await answer.call({ token: session.token }, ANONYMOUS)).status).toBe("answered");
|
|
87
|
+
expect(sent.visitor_ref).toBe(createHash("sha256").update(`pm-preview-assistant-visitor-v1\n${session.token}`).digest("hex"));
|
|
88
|
+
expect(sent.max_charge_usd).toBe(1);
|
|
89
|
+
expect((await db().select().from(assistantTurns))[0]?.costCents).toBe(4);
|
|
90
|
+
const transcript = await getSiteChat.call({ token: session.token }, ANONYMOUS);
|
|
91
|
+
expect(transcript.messages.at(-1)?.channel).toBe("assistant");
|
|
92
|
+
expect(transcript.messages.at(-1)?.body).toContain("Hello!");
|
|
93
|
+
expect(JSON.stringify(transcript)).not.toContain("test-only-managed-key");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("retains the held budget after an unknown model timeout", async () => {
|
|
97
|
+
let calls = 0;
|
|
98
|
+
setParadiseFetchForTests(async () => { calls++; throw Error("lost response"); });
|
|
99
|
+
const one = await chat();
|
|
100
|
+
expect((await answer.call({ token: one.token }, ANONYMOUS)).status).toBe("failed");
|
|
101
|
+
expect((await db().select().from(assistantTurns))[0]?.costCents).toBe(100);
|
|
102
|
+
const two = await chat();
|
|
103
|
+
expect((await answer.call({ token: two.token }, ANONYMOUS)).status).toBe("refused");
|
|
104
|
+
expect(calls).toBe(1);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("serializes claims so two visitors cannot spend the same remaining managed budget", async () => {
|
|
108
|
+
const one = await chat(), two = await chat(); let invoked!: () => void, complete!: () => void;
|
|
109
|
+
const started = new Promise<void>(resolve => { invoked = resolve; });
|
|
110
|
+
const release = new Promise<void>(resolve => { complete = resolve; });
|
|
111
|
+
let calls = 0;
|
|
112
|
+
setParadiseFetchForTests(async () => { calls++; invoked(); await release; return reply({ text: "Hello!", model: "managed-model", metered_list_usd: .04, content_mode: "sfw" }); });
|
|
113
|
+
const first = answer.call({ token: one.token }, ANONYMOUS);
|
|
114
|
+
await started;
|
|
115
|
+
try { expect((await answer.call({ token: two.token }, ANONYMOUS)).status).toBe("refused"); }
|
|
116
|
+
finally { complete(); }
|
|
117
|
+
expect((await first).status).toBe("answered"); expect(calls).toBe(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("proxies only visitor-bound controls, fails to text without worker origins, and keeps End available after off", async () => {
|
|
121
|
+
const session = await chat(), id = randomUUID(); const requests: Array<{ url: string; body: Record<string, unknown> }> = [];
|
|
122
|
+
setParadiseFetchForTests(async (url, init) => {
|
|
123
|
+
expect(await openTransactions()).toBe(0);
|
|
124
|
+
requests.push({ url, body: requestBody(init.body) });
|
|
125
|
+
return reply(url.endsWith("/config") ? { enabled: true, modes: ["video", "voice", "text"] } : { session_id: id, status: "ending" });
|
|
126
|
+
});
|
|
127
|
+
delete process.env.PARADISEMODERN_ASSISTANT_ORIGINS;
|
|
128
|
+
resetEnvForTests();
|
|
129
|
+
expect(await previewCall.call({ action: "config", token: session.token }, ANONYMOUS)).toMatchObject({ modes: ["text"] });
|
|
130
|
+
await previewCall.call({ action: "poll", token: session.token, sessionId: id }, ANONYMOUS);
|
|
131
|
+
expect(requests.at(-1)?.url).toMatch(/visitor_ref=[a-f0-9]{64}$/);
|
|
132
|
+
expect((await failure(previewCall.call({ action: "poll", token: "x".repeat(40), sessionId: id }, ANONYMOUS))).code).toBe("not_found");
|
|
133
|
+
await updateSettings.call({ enabled: false, provider: "paradise", model: "paradise-managed-assistant" }, OWNER);
|
|
134
|
+
await previewCall.call({ action: "end", token: session.token, sessionId: id }, ANONYMOUS);
|
|
135
|
+
expect(requests.at(-1)?.url).toContain("/end");
|
|
136
|
+
expect((await failure(previewCall.call({ action: "start", token: session.token, want: "video" }, ANONYMOUS))).code).toBe("not_found");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("puts bounded browser captions on the same conversation once, after PM verifies its visitor-bound session", async () => {
|
|
140
|
+
const session = await chat(); const id = randomUUID();
|
|
141
|
+
setParadiseFetchForTests(async () => reply({ status: "live", mode: "video" }));
|
|
142
|
+
const input = { action: "caption" as const, token: session.token, sessionId: id, caption: { speaker: "muse" as const, text: "Hello from the call", startedAt: Date.now(), endedAt: Date.now() } };
|
|
143
|
+
await previewCall.call(input, ANONYMOUS); await previewCall.call(input, ANONYMOUS);
|
|
144
|
+
const transcript = await getSiteChat.call({ token: session.token }, ANONYMOUS);
|
|
145
|
+
expect(transcript.messages.filter(message => message.body.includes("Hello from the call"))).toHaveLength(1);
|
|
146
|
+
expect(transcript.messages.at(-1)?.body).toContain("browser-observed");
|
|
147
|
+
});
|
|
148
|
+
it("keeps managed talent and settings on the authorized service path", async () => {
|
|
149
|
+
const remote = { enabled: true, talentSlug: "sienna-rodriguez", dailyCapUsd: 1 };
|
|
150
|
+
setParadiseFetchForTests(async (url, init) => {
|
|
151
|
+
expect(await openTransactions()).toBe(0);
|
|
152
|
+
return reply(url.endsWith("/talent") ? { talent: [] } : { settings: init.method === "PATCH" ? requestBody(init.body) : remote });
|
|
153
|
+
});
|
|
154
|
+
expect((await failure(managedDetails.call({}, ANONYMOUS))).code).toBe("permission");
|
|
155
|
+
expect((await managedDetails.call({}, OWNER)).settings).toEqual(remote);
|
|
156
|
+
expect(await syncManagedSettings.call({ ...remote, enabled: false, dailyCapUsd: 2 }, OWNER)).toMatchObject({ settings: { enabled: false, dailyCapUsd: 2 } });
|
|
157
|
+
expect((await failure(syncManagedSettings.call(remote, ANONYMOUS))).code).toBe("permission");
|
|
158
|
+
});
|
|
159
|
+
it("installs v3 through normal services and leaves v1/v2 behavior available", async () => {
|
|
160
|
+
const base = JSON.parse(readFileSync("seed/launch/example-v2.json", "utf8")) as Record<string, unknown>;
|
|
161
|
+
await installLaunch.call({ ...base, version: 3, assistant: { provider: "paradise", enabled: true, dailyCapUsd: 1, contentMode: "sfw" } }, { kind: "system" });
|
|
162
|
+
expect(await settings.call({}, OWNER)).toMatchObject({ enabled: true, provider: "paradise", spendCapCents: 100, spendPeriod: "day" });
|
|
163
|
+
});
|
|
164
|
+
});
|