mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-05 06:41:50 +09:00
Deprecated Webhook Forms reuse the existing Form execution pipeline without teaching the modern backend about WebhookForm. ## User-facing behavior and how to test it - Existing saved Webhook Forms keep their markup, action settings, and success/error feedback. Submit a published Webhook Form and check both outcomes. - URL and Resource actions preserve configured methods, headers, dependencies, body overrides, and the last submitted value for repeated field names. Test a configured action and inspect the received request. - Default owner notifications use the Email Worker, including submitted files. Submit a Webhook Form without a custom action and inspect the owner email and attachment. - Configured Email actions validate recipients and retain threading metadata. Test valid recipients and a rejected recipient limit. ## Implementation - One deprecated Webhook Form adapter calls existing bot validation, Email preparation, recipient validation, resource loading, and response handling. - Both generated route templates call that adapter. Both paths reuse an internal resource-graph traversal helper; modern submission behavior is unchanged. - Root actions use the protected, uncached request override. Dependencies reuse existing generated Assets and Resource caching behavior. - Keep reachable-resource filtering because Email preparation runs before loading: unrelated Email settings must not break the selected action. - Remove dead `getDefaultActionResource` wiring from generated templates. ## Verification - Focused SDK tests: 116 passed (11 deprecated Webhook Form adapter and 105 modern submission, Email, and handler tests), including unrelated resources, missing dependencies, cycles, Email preflight/threading, and single-attempt Email failures. - Resource generator tests: 26 passed. - Full CLI prebuild suite: 139 passed after tracked fixture regeneration; focused deprecated Webhook Form adapter tests: 9 passed. - Repository fixture pipeline (`pnpm -r fixtures:build`) passed. All tracked generated `getDefaultActionResource` references were removed, and no Builder `N8N_FORM_EMAIL_HOOK` reference remains. - Final MCP-generated local Preview E2E rerun: 3/3 passed. - Focused saved Webhook Form custom-action E2E rerun: 2/2 passed (setup and test), including a single POST through the protected test receiver after Builder reload. - SDK, CLI, and Builder typechecks, focused lint and formatting, and `git diff --check` passed. - Deprecated component picker regression test passed (2/2); verified it fails when WebhookForm deprecation is disabled, then passes with deprecation restored. - Independent Astra review found no blocker, including the 62 generated fixture changes. No production deployment or live secret change was performed. - Required staging CI checks passed on previous head `15635fc` (Main workflow, visual regression, submodules, and lint). An unrelated existing MCP success-redirect E2E assertion failed once in shard 5, passed in a focused local rerun (2/2 including setup), then shard 5 passed on GitHub rerun without code changes. - Terminology pass (`4a69ab573`): renamed the dedicated SDK adapter and migration helper, updated both route templates and generated fixtures, corrected the active identity migration marker comments, and synchronized docs and test names. Focused tests passed: SDK 35, CLI prebuild 12 plus 2 after final title change, MCP 7, migrations 8, React browser 7, CLI docs 9. Seven affected package typechecks, fixture builds, formatting, and `git diff --check` passed. That historical head was superseded; latest-head CI results are recorded below. - ResourceForm identity migration (`29a21edbb`): focused migration (23), DB patch (25), project-build DB/session (93), Builder API/import/auth/patch (60), React SDK (162), runtime/MCP (239), registry (11), CLI evaluation (90), CLI session/sync (55), and protocol (15) tests passed; full CLI prebuild (139) passed. Affected typechecks, lint, formatting, and `git diff --check` passed. Independent Astra review found no blocker. No deployment was performed. - Prepublish Webhook Form warning (`25855e8f00`): audit checks every non-draft published page and links nested/shared instances to the correct page; modern ResourceForm, native forms, draft-only forms, and orphans are excluded. Focused audit tests (13), Builder navigation tests (6), project-build and Builder typechecks, lint, formatting, and `git diff --check` passed. Independent Astra review found no blocker; publishing remains nonblocking. No deployment was performed. - ResourceForm test and CI expectation repair (`e1a527fbcc`): focused React SDK (24), Builder preview/registry (38), project-build pages (1), and CLI fixture API (8) tests passed; Remix and React Router targeted browser suites, affected package typechecks, full formatting (3375 files), lint, and `git diff --check` passed. Astra review found no blocker. Persisted identity and runtime exports were unchanged. - Project bundle fixture repair (`70889ef27d`): eight bundles now carry the current contract version; the two unmarked historical Form instances in `webstudio-features` normalize to WebhookForm. Protocol fixture tests (17), protocol typecheck, CLI fixture build, formatting, lint, and diff check passed. Independent Astra review found no blocker. - Story/MCP E2E CI repair (`483614e6c5`): SDK CLI story tests (7), ResourceForm fragment tests (34), and focused local managed-form E2E (4 including setup) passed. SDK CLI and Builder typechecks, lint, formatting, and diff check passed. Astra review found no blocker. The initial local Preview build used an ignored stale React Router `lib` artifact; rebuilding it restored the passing E2E run. - Latest PR head `483614e6c5`: Main workflow [run 39317777032](https://github.com/webstudio-is/webstudio/actions/runs/39317777032) passed, including all package matrices and six Builder E2E shards. Visual regression [run 39317796922](https://github.com/webstudio-is/webstudio/actions/runs/39317796922), submodules, and PR lint checks passed. The overlapping unapproved visual run was cancelled by the approved rerun. - Shared bot-value generator (`ecc4cad1e9`): SDK helper tests (3), React Router WebhookForm/ResourceForm browser tests (5), SDK/Router/Remix typechecks and builds, SDK browser-boundary check, formatting, and diff check passed. Brave bypasses media queries, working media queries produce a fresh timestamp per submission, and failed queries produce `jsdom`; each managed/legacy submission has one bot field. Independent Astra review found no blocker. Latest-head Main workflow [run 39325677117](https://github.com/webstudio-is/webstudio/actions/runs/39325677117) passed, including all six Builder E2E shards; approved visual regression [run 39325702835](https://github.com/webstudio-is/webstudio/actions/runs/39325702835), submodules, and PR lint passed. The superseded visual run was cancelled by the approved rerun.\n\n- Historical Form clipboard guard (`e864283d1c`): instance/page transfer parsers reject ambiguous legacy `Form` before asset import; direct fragment/page/folder mutations preflight before changes. Canonical ResourceForm, WebhookForm, and NativeForm remain accepted. Project-build tests (89), Builder paste browser tests (69), both typechecks, focused lint/formatting, and diff check passed. Independent Astra review found no blocker. Latest-head Main workflow [run 39329184890](https://github.com/webstudio-is/webstudio/actions/runs/39329184890) passed, including all six Builder E2E shards; approved visual regression [run 39329562692](https://github.com/webstudio-is/webstudio/actions/runs/39329562692), submodules, and PR lint passed. The earlier unapproved visual run reported two expected story differences.\n\n## Compatibility notes - Root HTTP actions reject private and same-origin destinations. Dependencies retain their existing fetch/cache behavior. - Routes retain the 25 MiB request limit. Shared execution applies bot validation, a 10-second Resource timeout, and one retry for eligible HTTP failures; an ambiguous failure can duplicate an HTTP action. Email actions are not retried. - Default email uses the Email Worker's sender, plain text, recipient limits, and attachment limits instead of the legacy n8n HTML/basic-auth path. - Self-hosted sites need normal Email sender configuration. Direct Builder draft Preview handling is outside this published-route change. - Coordinate this CLI release with [SaaS PR #669](https://github.com/webstudio-is/webstudio-saas/pull/669), which removes the n8n helper and `N8N_FORM_EMAIL_HOOK` from new published-site builds. Publish with a CLI artifact containing this adapter. Existing deployed workers retain their bundled code and injected hook until republished, so keep the actual n8n endpoint available while those sites remain active. ## Implementation checklist - [x] Align saved Webhook Form custom-action E2E with the protected receiver and verify one submission. - [x] Regenerate tracked published-site fixtures with the updated CLI and confirm no `getDefaultActionResource` or `N8N_FORM_EMAIL_HOOK` references remain in Builder source/config/fixtures. - [x] Review authoritative `docs/` impact of removing the obsolete Builder hook wiring; related deprecation and integration docs were updated. - [x] Route deprecated Webhook Form submissions through the shared execution pipeline with one adapter. - [x] Preserve configured actions, dependencies, repeated fields, body overrides, and saved feedback. - [x] Prepare and validate Email actions using existing shared logic. - [x] Remove duplicated orchestration and dead generated context wiring. - [x] Verify generated routes and MCP-generated Preview submissions. - [x] Mark the Webhook Form component and its dedicated dependencies visibly deprecated, while leaving shared Form infrastructure active. - [x] Group Webhook Form-only SDK code for straightforward removal while preserving public APIs and generated output. - [x] Use deprecated terminology consistently for Webhook Form-only PR code, and clarify the active identity migration marker. - [x] Confirm required staging CI checks. - [x] Use ResourceForm as the one active modern component identity across Builder, SDK, runtime, templates, generated code, and docs. - [x] Migrate historical Form, NativeForm, ResourceForm, and WebhookForm identities in one idempotent pass using the historical pages marker. - [x] Remove the marker from ordinary project and snapshot APIs while preserving historical input readers. - [x] Persist pages and instances together when a historical marked project is saved, including a pages-only edit. - [x] Verify migration, export/reimport, old CLI and server snapshots, page-only save, generation, and affected typechecks. - [x] Complete an independent architecture review before commit or push. - [x] Warn at prepublish for deprecated Webhook Forms on published pages, with a link to each affected element. - [x] Verify modern ResourceForm is excluded and nested/shared Webhook Forms navigate to the correct page. - [x] Complete independent review, focused tests, and affected typechecks before push. - [x] Remove local `ResourceForm as Form` aliases from React SDK tests and fixtures; use the canonical component name throughout. - [x] Fix stale identity expectations found in CI and verify affected tests/typechecks. - [x] Complete independent review before push. - [x] Refresh tracked project bundle fixtures to the current bundle contract and canonical WebhookForm identity; verify protocol and affected CLI flows. - [x] Align SDK CLI story assertions and MCP E2E fragment fixtures with the persisted ResourceForm component name; rerun affected checks. - [x] Share one browser bot-value generator across ResourceForm submission and deprecated Webhook Form wrappers, preserving field ownership and behavior. - [x] Verify bot timestamps, Brave/media failure handling, repeated submissions, affected typechecks, and independent review before push. - [x] Reject ambiguous historical `Form` clipboard fragments before any insertion or transfer mutation, with clear recopy guidance; preserve canonical ResourceForm action remapping.\n- [x] Verify instance/page/template/folder paste regressions, independent review, and latest-head CI.\n\n - [x] Explain Email attachment size limits in the Email action UI and give a useful error when the aggregate encoded attachments exceed the local guard. - [x] Check Preview and published behavior, boundary tests, and authoritative Form docs; verify the focused change and get independent review. Ref #4093 - [x] Preserve safe email codes/messages through MCP, including local attachment and upload limit errors. - [x] Correct Form documentation for each enforced limit and verify Preview/published/MCP paths. - [x] Verify Builder SDK and MCP focused tests, typechecks, and independent review before push. - Email limits and failure copy (`6d215f3ec3`): the shared SDK checks 32 attachments and 7 MiB aggregate Base64 data before dispatch; the 25 MiB multipart response and Email action guidance use approved copy. Managed Email error codes pass through Form and MCP results with resource IDs, while MCP still omits resource bodies. Form docs distinguish the Worker 7 MiB JSON cap from Cloudflare's 5 MiB complete message and verified-destination exception, and correct the no-retry behavior. Focused SDK tests 89, Builder API tests 44, UI browser tests 42, SDK/Builder/CLI/docs typechecks, lint, formatting, and generated MCP docs check passed. Astra found no blocker. No real email or production deployment occurred. - Latest Email limits head `6d215f3ec3`: Main workflow [run 39393037290](https://github.com/webstudio-is/webstudio/actions/runs/39393037290) passed on rerun, including all six Builder E2E shards; approved visual regression [run 39393456618](https://github.com/webstudio-is/webstudio/actions/runs/39393456618), submodules, and PR lint passed. The initial unapproved visual run showed the same two previously accepted story differences. - [x] Address review: normalize previous-Builder `Form` instance patches before persistence, preserve historical WebhookForm identity, and cover marked/unmarked cases. Documentation impact reviewed: this restores intended save behavior, so no user guide change is needed. - Review finding follow-up (`ce05dd733a`): three Form identity patch regressions passed red/green; full project build-patch tests 28/28, project typecheck, lint, formatting, and diff check passed. Independent Astra review found no blocker. Incoming PATCH `Form` is treated as the immediately previous Builder's modern form alias; already stored unmarked historical `Form` continues to migrate to WebhookForm. The old patch protocol has no client-release identifier, so pre-October-14 live clients adding new ambiguous IDs cannot be identified separately. - Latest review-fix head `ce05dd733a`: Main workflow [run 39397337356](https://github.com/webstudio-is/webstudio/actions/runs/39397337356) passed, including six E2E shards after a targeted shard-4 rerun for an unrelated MDX slash-menu timeout. Approved visual regression [run 39397395206](https://github.com/webstudio-is/webstudio/actions/runs/39397395206), submodules, and PR lint passed. The unapproved synchronize visual run was cancelled by the approved rerun.
2349 lines
68 KiB
TypeScript
2349 lines
68 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import {
|
|
collectionComponent,
|
|
defaultVisitorConfirmationBody,
|
|
createStructuredAssetQueryResourceBody,
|
|
encodeDataSourceVariable,
|
|
parseStructuredAssetQueryResourceBody,
|
|
} from "@webstudio-is/sdk";
|
|
import { mapQueryWhere } from "@webstudio-is/query-builder/runtime";
|
|
import { assetsResourceUrl } from "@webstudio-is/sdk/runtime";
|
|
import {
|
|
authenticatedPageFixture,
|
|
designInputFixture,
|
|
fontAssetsFixture,
|
|
highImpactFixtures,
|
|
managedFormAuthoringFixture,
|
|
formModesAuthoringFixture,
|
|
markdownBlogFixture,
|
|
markdownReferencesDiscoveryFixture,
|
|
validateHighImpactFixture,
|
|
type EvaluationProject,
|
|
} from "./fixtures";
|
|
import {
|
|
fontAssetFixtureFiles,
|
|
fontAssetFixtureMeta,
|
|
} from "./font-assets-fixture";
|
|
import { markdownBlogFixtureDocuments } from "./markdown-blog-fixture";
|
|
import { getMcpTraceRequest, getMcpTraceResponse } from "./mcp-trace-proxy";
|
|
import { evaluateHighImpactOutcome, type EvaluationToolCall } from "./validate";
|
|
|
|
const clone = <Value>(value: Value): Value => structuredClone(value);
|
|
|
|
const addManagedContactPage = (): EvaluationProject => {
|
|
const formId = "contact-form";
|
|
const formStateId = "contact-form-state";
|
|
const resultsId = "contact-form-results";
|
|
const errorsId = "contact-form-errors";
|
|
const projectDataSourceId = "contact-project-email-source";
|
|
const visitorDataSourceId = "contact-visitor-email-source";
|
|
const formDataBinding = encodeDataSourceVariable("contact-form-data");
|
|
const browserInfoBinding = encodeDataSourceVariable("contact-browser-info");
|
|
const formStateBinding = encodeDataSourceVariable(formStateId);
|
|
const resultsBinding = encodeDataSourceVariable(resultsId);
|
|
const errorsBinding = encodeDataSourceVariable(errorsId);
|
|
const formFields = [
|
|
{ name: "name", component: "Input" },
|
|
{ name: "email", component: "Input", type: "email" },
|
|
{ name: "subject", component: "Input" },
|
|
{ name: "message", component: "Textarea" },
|
|
];
|
|
const instances = [
|
|
{
|
|
id: formId,
|
|
component: "ResourceForm",
|
|
children: [
|
|
{ type: "id" as const, value: "form-content" },
|
|
{ type: "id" as const, value: "form-success" },
|
|
{ type: "id" as const, value: "form-error" },
|
|
],
|
|
},
|
|
{
|
|
id: "form-content",
|
|
component: "Box",
|
|
children: [
|
|
...formFields.map(({ name }) => ({
|
|
type: "id" as const,
|
|
value: `label-${name}`,
|
|
})),
|
|
{ type: "id" as const, value: "submit-button" },
|
|
],
|
|
},
|
|
...formFields.flatMap(({ name, component }) => [
|
|
{
|
|
id: `label-${name}`,
|
|
component: "Label",
|
|
children: [
|
|
{ type: "text" as const, value: name },
|
|
{ type: "id" as const, value: `field-${name}` },
|
|
],
|
|
},
|
|
{
|
|
id: `field-${name}`,
|
|
component,
|
|
children: [],
|
|
},
|
|
]),
|
|
{
|
|
id: "submit-button",
|
|
component: "Button",
|
|
children: [{ type: "text" as const, value: "Send message" }],
|
|
},
|
|
{
|
|
id: "form-success",
|
|
component: "Box",
|
|
label: "Success message",
|
|
children: [
|
|
{
|
|
type: "text" as const,
|
|
value:
|
|
"Thanks, we received your message. Our team will reply within one business day.",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "form-error",
|
|
component: "Box",
|
|
label: "Error message",
|
|
children: [
|
|
{ type: "id" as const, value: "form-error-list" },
|
|
{
|
|
type: "text" as const,
|
|
value: "We couldn't send your message. Please try again.",
|
|
},
|
|
],
|
|
},
|
|
{ id: "form-error-list", component: collectionComponent, children: [] },
|
|
];
|
|
const resources = [
|
|
{
|
|
id: "project-email",
|
|
name: "Email to owner",
|
|
control: "email",
|
|
method: "post",
|
|
url: '""',
|
|
email: {
|
|
recipientMode: "project",
|
|
subject: `"Contact form: " + (${formDataBinding}.subject ?? "New message")`,
|
|
body:
|
|
"`" +
|
|
"${" +
|
|
browserInfoBinding +
|
|
".pageUrl ? `Page: ${" +
|
|
browserInfoBinding +
|
|
'.pageUrl}\n\n` : ""}${' +
|
|
formDataBinding +
|
|
"}`",
|
|
},
|
|
},
|
|
{
|
|
id: "visitor-email",
|
|
name: "Email to visitor",
|
|
control: "email",
|
|
method: "post",
|
|
url: '""',
|
|
email: {
|
|
recipientMode: "visitor",
|
|
visitorEmailField: "email",
|
|
subject: `${formDataBinding}.subject ?? "Your message"`,
|
|
body: JSON.stringify(defaultVisitorConfirmationBody),
|
|
confirmationSubject: "formSubject",
|
|
confirmationBody: "default",
|
|
includeAttachments: false,
|
|
},
|
|
},
|
|
];
|
|
return {
|
|
...managedFormAuthoringFixture.project,
|
|
pages: [
|
|
...managedFormAuthoringFixture.project.pages,
|
|
{
|
|
id: "contact",
|
|
name: "Contact",
|
|
path: "/contact",
|
|
rootInstanceId: "contact-root",
|
|
},
|
|
],
|
|
instances: [
|
|
...managedFormAuthoringFixture.project.instances,
|
|
{
|
|
id: "contact-root",
|
|
component: "Body",
|
|
tag: "body",
|
|
children: [
|
|
{ type: "id" as const, value: "contact-heading" },
|
|
{ type: "id" as const, value: "contact-intro" },
|
|
{ type: "id" as const, value: formId },
|
|
],
|
|
},
|
|
{
|
|
id: "contact-heading",
|
|
component: "Heading",
|
|
tag: "h1",
|
|
children: [{ type: "text" as const, value: "Contact Northstar" }],
|
|
},
|
|
{
|
|
id: "contact-intro",
|
|
component: "Paragraph",
|
|
tag: "p",
|
|
children: [
|
|
{ type: "text" as const, value: "Tell our team how we can help." },
|
|
],
|
|
},
|
|
...instances,
|
|
],
|
|
props: [
|
|
{
|
|
id: "form-action",
|
|
instanceId: formId,
|
|
name: "action",
|
|
type: "json",
|
|
value: [
|
|
{ dataSourceId: projectDataSourceId },
|
|
{ dataSourceId: visitorDataSourceId },
|
|
],
|
|
},
|
|
{
|
|
id: "form-data",
|
|
instanceId: formId,
|
|
name: "formData",
|
|
type: "parameter",
|
|
value: "contact-form-data",
|
|
},
|
|
{
|
|
id: "browser-info",
|
|
instanceId: formId,
|
|
name: "browserInfo",
|
|
type: "parameter",
|
|
value: "contact-browser-info",
|
|
},
|
|
{
|
|
id: "form-state-change",
|
|
instanceId: formId,
|
|
name: "onStateChange",
|
|
type: "action",
|
|
value: [
|
|
{
|
|
type: "execute",
|
|
args: ["state"],
|
|
code: `${formStateBinding} = state`,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "form-result-change",
|
|
instanceId: formId,
|
|
name: "onResultChange",
|
|
type: "action",
|
|
value: [
|
|
{
|
|
type: "execute",
|
|
args: ["result"],
|
|
code: `({results: ${resultsBinding} = result?.results, errors: ${errorsBinding} = result?.errors})`,
|
|
},
|
|
],
|
|
},
|
|
...formFields.flatMap(({ name, type }) => [
|
|
{
|
|
id: `field-${name}-name`,
|
|
instanceId: `field-${name}`,
|
|
name: "name",
|
|
type: "string",
|
|
value: name,
|
|
},
|
|
{
|
|
id: `field-${name}-required`,
|
|
instanceId: `field-${name}`,
|
|
name: "required",
|
|
type: "boolean",
|
|
value: true,
|
|
},
|
|
...(type === undefined
|
|
? []
|
|
: [
|
|
{
|
|
id: `field-${name}-type`,
|
|
instanceId: `field-${name}`,
|
|
name: "type",
|
|
type: "string",
|
|
value: type,
|
|
},
|
|
]),
|
|
]),
|
|
{
|
|
id: "button-type",
|
|
instanceId: "submit-button",
|
|
name: "type",
|
|
type: "string",
|
|
value: "submit",
|
|
},
|
|
{
|
|
id: "success-show",
|
|
instanceId: "form-success",
|
|
name: "data-ws-show",
|
|
type: "expression",
|
|
value: `${formStateBinding} === 'success'`,
|
|
},
|
|
{
|
|
id: "error-show",
|
|
instanceId: "form-error",
|
|
name: "data-ws-show",
|
|
type: "expression",
|
|
value: `${formStateBinding} === 'error'`,
|
|
},
|
|
{
|
|
id: "errors-data",
|
|
instanceId: "form-error-list",
|
|
name: "data",
|
|
type: "expression",
|
|
value: errorsBinding,
|
|
},
|
|
],
|
|
dataSources: [
|
|
{
|
|
id: "contact-form-data",
|
|
type: "parameter",
|
|
name: "formData",
|
|
scopeInstanceId: formId,
|
|
},
|
|
{
|
|
id: "contact-browser-info",
|
|
type: "parameter",
|
|
name: "browserInfo",
|
|
scopeInstanceId: formId,
|
|
},
|
|
{
|
|
id: formStateId,
|
|
type: "variable",
|
|
name: "formState",
|
|
scopeInstanceId: formId,
|
|
},
|
|
{
|
|
id: resultsId,
|
|
type: "variable",
|
|
name: "results",
|
|
scopeInstanceId: formId,
|
|
},
|
|
{
|
|
id: errorsId,
|
|
type: "variable",
|
|
name: "errors",
|
|
scopeInstanceId: formId,
|
|
},
|
|
{
|
|
id: projectDataSourceId,
|
|
type: "resource",
|
|
name: "Email to owner",
|
|
resourceId: "project-email",
|
|
scopeInstanceId: formId,
|
|
},
|
|
{
|
|
id: visitorDataSourceId,
|
|
type: "resource",
|
|
name: "Email to visitor",
|
|
resourceId: "visitor-email",
|
|
scopeInstanceId: formId,
|
|
},
|
|
],
|
|
resources,
|
|
};
|
|
};
|
|
|
|
const managedFormCalls = () => [
|
|
traceCall("meta.guide", {}),
|
|
traceCall("insert-component", { component: "heading" }),
|
|
traceCall("components.search", { brief: "Form (Beta)" }),
|
|
traceCall("templates.get", { template: "template:form" }),
|
|
traceCall("insert-component", { component: "form" }),
|
|
traceCall("audit", {}),
|
|
traceCall("verify-page-responsive", {
|
|
path: "/contact",
|
|
viewports: [
|
|
{ width: 1440, height: 900 },
|
|
{ width: 390, height: 844 },
|
|
],
|
|
}),
|
|
];
|
|
|
|
let traceRequestId = 0;
|
|
const traceCall = (
|
|
name: string,
|
|
args: Record<string, unknown>
|
|
): EvaluationToolCall => {
|
|
const id = traceRequestId++;
|
|
const request = getMcpTraceRequest(
|
|
{
|
|
id,
|
|
method: "tools/call",
|
|
params: { name, arguments: args },
|
|
},
|
|
0,
|
|
new Set(name === "update-page" ? [name] : [])
|
|
);
|
|
if (request === undefined) {
|
|
throw new Error(`Expected a bounded trace for ${name}`);
|
|
}
|
|
const response = getMcpTraceResponse(
|
|
{
|
|
id,
|
|
result: { structuredContent: { meta: { session: { committed: true } } } },
|
|
},
|
|
new Map([[id, request.call]])
|
|
);
|
|
if (response === undefined) {
|
|
throw new Error(`Expected a completed trace for ${name}`);
|
|
}
|
|
return response;
|
|
};
|
|
|
|
const addAuthPage = (): EvaluationProject => {
|
|
const project = clone(authenticatedPageFixture.project);
|
|
project.pages.push({
|
|
id: "account",
|
|
name: "Account",
|
|
path: "/account",
|
|
rootInstanceId: "account-root",
|
|
});
|
|
project.instances.push(
|
|
{
|
|
id: "account-root",
|
|
component: "Body",
|
|
tag: "body",
|
|
children: [{ type: "id", value: "account-main" }],
|
|
},
|
|
{
|
|
id: "account-main",
|
|
component: "Box",
|
|
tag: "main",
|
|
children: [
|
|
{ type: "id", value: "signed-out" },
|
|
{ type: "id", value: "loading" },
|
|
{ type: "id", value: "signed-in" },
|
|
{ type: "id", value: "failed-auth" },
|
|
],
|
|
},
|
|
...["signed-out", "loading", "signed-in", "failed-auth"].map((state) => ({
|
|
id: state,
|
|
component: "Box",
|
|
tag: "section",
|
|
label: state.replace("-", " "),
|
|
children: [
|
|
{
|
|
type: "text" as const,
|
|
value: `${state.replaceAll("-", " ")} Supabase state`,
|
|
},
|
|
],
|
|
}))
|
|
);
|
|
project.resources.push({
|
|
id: "account-supabase-session",
|
|
name: "Supabase account session",
|
|
method: "get",
|
|
url: '"/api/auth/session"',
|
|
headers: [],
|
|
});
|
|
return project;
|
|
};
|
|
|
|
const addDesignPage = (): EvaluationProject => {
|
|
const project = clone(designInputFixture.project);
|
|
project.pages.push({
|
|
id: "summer",
|
|
name: "Summer",
|
|
path: "/summer",
|
|
rootInstanceId: "summer-root",
|
|
});
|
|
const definitions = [
|
|
[
|
|
"summer-root",
|
|
"Body",
|
|
"body",
|
|
["summer-header", "summer-main", "summer-footer"],
|
|
],
|
|
["summer-header", "Box", "header", ["summer-nav"]],
|
|
["summer-nav", "Box", "nav", []],
|
|
["summer-main", "Box", "main", ["summer-hero", "summer-trips"]],
|
|
["summer-hero", "Box", "section", ["summer-heading", "summer-copy"]],
|
|
["summer-heading", "Heading", "h1", []],
|
|
["summer-copy", "Paragraph", "p", []],
|
|
["summer-trips", "Box", "section", ["summer-trip-a", "summer-trip-b"]],
|
|
["summer-trip-a", "Box", "article", []],
|
|
["summer-trip-b", "Box", "article", []],
|
|
["summer-footer", "Box", "footer", []],
|
|
] as const;
|
|
project.instances.push(
|
|
...definitions.map(([id, component, tag, children]) => ({
|
|
id,
|
|
component,
|
|
tag,
|
|
children: children.map((value) => ({ type: "id" as const, value })),
|
|
}))
|
|
);
|
|
project.styleSources.push({ type: "local", id: "summer-layout" });
|
|
project.styleSourceSelections.push({
|
|
instanceId: "summer-main",
|
|
values: ["token-ink", "token-heading", "summer-layout"],
|
|
});
|
|
project.styles.push({
|
|
styleSourceId: "summer-layout",
|
|
breakpointId: "mobile",
|
|
property: "grid-template-columns",
|
|
value: { type: "keyword", value: "1fr" },
|
|
});
|
|
return project;
|
|
};
|
|
|
|
const addFontAssets = (): EvaluationProject => {
|
|
const project = clone(fontAssetsFixture.project);
|
|
project.assets = fontAssetFixtureFiles.map(({ name, format }) => ({
|
|
id: format,
|
|
projectId: "project",
|
|
name,
|
|
filename: name,
|
|
description: null,
|
|
size: 4,
|
|
type: "font",
|
|
format,
|
|
meta: fontAssetFixtureMeta,
|
|
createdAt: "2026-01-01T00:00:00.000Z",
|
|
}));
|
|
return project;
|
|
};
|
|
|
|
const addMarkdownBlog = (): EvaluationProject => {
|
|
const project = clone(markdownBlogFixture.project);
|
|
project.assetFolders.push({
|
|
id: "blog-folder",
|
|
projectId: "project",
|
|
name: "Blog",
|
|
createdAt: "2026-01-01T00:00:00.000Z",
|
|
});
|
|
project.assets.push(
|
|
...markdownBlogFixtureDocuments.map(({ name, format }) => ({
|
|
id: name,
|
|
projectId: "project",
|
|
name,
|
|
filename: name,
|
|
description: null,
|
|
folderId: "blog-folder",
|
|
size: 100,
|
|
type: "file" as const,
|
|
format,
|
|
meta: {},
|
|
createdAt: "2026-01-01T00:00:00.000Z",
|
|
}))
|
|
);
|
|
project.pages.push(
|
|
{
|
|
id: "blog",
|
|
name: "Blog",
|
|
path: "/blog",
|
|
rootInstanceId: "blog-root",
|
|
},
|
|
{
|
|
id: "blog-detail",
|
|
name: "Blog post",
|
|
path: "/blog/:slug",
|
|
rootInstanceId: "blog-detail-root",
|
|
title: 'post.data.properties.title ?? "Article"',
|
|
meta: {
|
|
description: 'post.data.properties.excerpt ?? ""',
|
|
socialImageUrl: 'post.data.properties.featureImage.src ?? ""',
|
|
status: "post.data ? 200 : 404",
|
|
},
|
|
}
|
|
);
|
|
project.instances.push(
|
|
{
|
|
id: "blog-root",
|
|
component: "Body",
|
|
children: [{ type: "id", value: "blog-collection" }],
|
|
},
|
|
{
|
|
id: "blog-collection",
|
|
component: collectionComponent,
|
|
children: [{ type: "id", value: "blog-card" }],
|
|
},
|
|
{
|
|
id: "blog-card",
|
|
component: "Box",
|
|
children: [
|
|
{ type: "expression", value: "collectionItem.properties.title" },
|
|
{ type: "expression", value: "collectionItem.properties.excerpt" },
|
|
{
|
|
type: "expression",
|
|
value: "collectionItem.properties.publishedAt",
|
|
},
|
|
{ type: "expression", value: "collectionItem.properties.slug" },
|
|
{
|
|
type: "expression",
|
|
value: "collectionItem.properties.author.name",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "blog-detail-root",
|
|
component: "Body",
|
|
children: [{ type: "id", value: "detail-article" }],
|
|
},
|
|
{
|
|
id: "detail-article",
|
|
component: "Box",
|
|
children: [
|
|
{ type: "id", value: "detail-title" },
|
|
{ type: "id", value: "detail-author" },
|
|
{ type: "id", value: "markdown" },
|
|
],
|
|
},
|
|
{
|
|
id: "detail-title",
|
|
component: "Heading",
|
|
children: [
|
|
{
|
|
type: "expression",
|
|
value: "post.data.properties.title",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "detail-author",
|
|
component: "Text",
|
|
children: [
|
|
{
|
|
type: "expression",
|
|
value: "post.data.properties.author.name",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "markdown",
|
|
component: "MarkdownEmbed",
|
|
children: [],
|
|
}
|
|
);
|
|
project.props.push({
|
|
id: "markdown-content",
|
|
instanceId: "markdown",
|
|
name: "code",
|
|
type: "expression",
|
|
value: "post.data.content.text",
|
|
});
|
|
const resource = (
|
|
id: string,
|
|
name: string,
|
|
body: string
|
|
): Record<string, unknown> => ({
|
|
id,
|
|
name,
|
|
control: "system",
|
|
method: "post",
|
|
url: JSON.stringify(assetsResourceUrl),
|
|
headers: [],
|
|
body,
|
|
});
|
|
project.resources.push(
|
|
resource(
|
|
"posts-resource",
|
|
"Posts",
|
|
createStructuredAssetQueryResourceBody({
|
|
where: {
|
|
all: [
|
|
{ field: ["extension"], operator: "eq", value: '"md"' },
|
|
{ field: ["folderId"], operator: "eq", value: '"blog-folder"' },
|
|
{
|
|
field: ["properties", "draft"],
|
|
operator: "ne",
|
|
value: "true",
|
|
},
|
|
],
|
|
},
|
|
sort: [
|
|
{ field: ["properties", "publishedAt"], direction: "desc" },
|
|
{ field: ["id"], direction: "asc" },
|
|
],
|
|
limit: "20",
|
|
offset: "0",
|
|
output: {
|
|
mode: "fields",
|
|
includeMetadata: false,
|
|
fields: [
|
|
["properties", "title"],
|
|
["properties", "slug"],
|
|
["properties", "publishedAt"],
|
|
["properties", "author"],
|
|
["properties", "excerpt"],
|
|
],
|
|
},
|
|
content: { mode: "none" },
|
|
})
|
|
),
|
|
resource(
|
|
"post-resource",
|
|
"Post",
|
|
createStructuredAssetQueryResourceBody({
|
|
result: "one",
|
|
where: {
|
|
all: [
|
|
{ field: ["extension"], operator: "eq", value: '"md"' },
|
|
{ field: ["folderId"], operator: "eq", value: '"blog-folder"' },
|
|
{
|
|
field: ["properties", "slug"],
|
|
operator: "eq",
|
|
value: "system.params.slug",
|
|
},
|
|
{
|
|
field: ["properties", "draft"],
|
|
operator: "ne",
|
|
value: "true",
|
|
},
|
|
],
|
|
},
|
|
sort: [],
|
|
limit: "20",
|
|
offset: "0",
|
|
output: {
|
|
mode: "fields",
|
|
includeMetadata: false,
|
|
fields: [
|
|
["properties", "title"],
|
|
["properties", "author"],
|
|
["properties", "excerpt"],
|
|
["properties", "featureImage", "src"],
|
|
],
|
|
},
|
|
content: { mode: "markdown-body-ref" },
|
|
})
|
|
)
|
|
);
|
|
project.dataSources.push(
|
|
{
|
|
id: "posts",
|
|
type: "resource",
|
|
name: "posts",
|
|
scopeInstanceId: "blog-root",
|
|
resourceId: "posts-resource",
|
|
},
|
|
{
|
|
id: "post",
|
|
type: "resource",
|
|
name: "post",
|
|
scopeInstanceId: "blog-detail-root",
|
|
resourceId: "post-resource",
|
|
}
|
|
);
|
|
return project;
|
|
};
|
|
|
|
const designCalls: EvaluationToolCall[] = [
|
|
{ name: "meta.guide" },
|
|
{ name: "list-breakpoints" },
|
|
{ name: "list-design-tokens" },
|
|
{ name: "insert-fragment" },
|
|
{ name: "update-styles" },
|
|
{ name: "audit" },
|
|
{ name: "screenshot", arguments: { viewport: { width: 1440, height: 900 } } },
|
|
{ name: "screenshot", arguments: { viewport: { width: 390, height: 844 } } },
|
|
];
|
|
|
|
describe("high-impact fixture validation", () => {
|
|
test.each(highImpactFixtures)(
|
|
"validates page ownership in $id",
|
|
(fixture) => {
|
|
expect(validateHighImpactFixture(fixture)).toEqual({
|
|
valid: true,
|
|
failures: [],
|
|
});
|
|
const broken = clone(fixture);
|
|
broken.project.instances = [];
|
|
expect(validateHighImpactFixture(broken).valid).toBe(false);
|
|
}
|
|
);
|
|
});
|
|
|
|
describe("managed Form evaluation", () => {
|
|
test("checks intended Form action IDs and order despite legacy keys", () => {
|
|
const project = addManagedContactPage();
|
|
const action = project.props.find(
|
|
({ instanceId, name }) =>
|
|
instanceId === "contact-form" && name === "action"
|
|
)!;
|
|
const selected = action.value as Array<{ dataSourceId: string }>;
|
|
action.value = selected.map((entry) => ({ ...entry, enabled: false }));
|
|
expect(
|
|
evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project,
|
|
toolCalls: managedFormCalls(),
|
|
}).checks.formActionsPreserved
|
|
).toBe("passed");
|
|
action.value = [selected[1], selected[0]];
|
|
expect(
|
|
evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project,
|
|
toolCalls: managedFormCalls(),
|
|
}).checks.formActionsPreserved
|
|
).toBe("failed");
|
|
});
|
|
|
|
test("accepts contact heading text inside an inline child", () => {
|
|
const project = addManagedContactPage();
|
|
const heading = project.instances.find(
|
|
({ id }) => id === "contact-heading"
|
|
)!;
|
|
project.instances.push({
|
|
id: "heading-text",
|
|
component: "ws:element",
|
|
tag: "span",
|
|
children: heading.children,
|
|
});
|
|
heading.children = [{ type: "id", value: "heading-text" }];
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project,
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks.contactPage).toBe("passed");
|
|
});
|
|
|
|
test("accepts harmless formatting in unchanged Email expressions", () => {
|
|
const project = addManagedContactPage();
|
|
const formData = encodeDataSourceVariable("contact-form-data");
|
|
project.resources = project.resources.map((resource) => ({
|
|
...resource,
|
|
email: {
|
|
...(resource.email as object),
|
|
subject:
|
|
resource.name === "Email to owner"
|
|
? `'Contact form: '+(${formData}.subject??'New message')`
|
|
: `(${formData}.subject??'Your message')`,
|
|
},
|
|
}));
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project,
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks.formActionsPreserved).toBe("passed");
|
|
});
|
|
|
|
test("rejects restoring externally controlled Form state", () => {
|
|
const project = addManagedContactPage();
|
|
project.props.push({
|
|
id: "controlled-state",
|
|
instanceId: "contact-form",
|
|
name: "state",
|
|
type: "expression",
|
|
value: encodeDataSourceVariable("contact-form-state"),
|
|
});
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project,
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks.formStateBinding).toBe("failed");
|
|
});
|
|
|
|
test("accepts Form discovery after an unrelated component and checks contact-route structure", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: addManagedContactPage(),
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks.formTemplateDiscovery).toBe("passed");
|
|
expect(result.checks.managedFormStructure).toBe("passed");
|
|
expect(result.checks.formActionsPreserved).toBe("passed");
|
|
expect(result.checks.responsiveEvidence).toBe("passed");
|
|
});
|
|
|
|
test.each(["name", "email", "subject", "message"])(
|
|
"rejects an empty %s label wrapper",
|
|
(name) => {
|
|
const project = addManagedContactPage();
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: {
|
|
...project,
|
|
instances: project.instances.map((instance) =>
|
|
instance.id === `label-${name}`
|
|
? {
|
|
...instance,
|
|
children: instance.children.filter(
|
|
(child) => child.type !== "text"
|
|
),
|
|
}
|
|
: instance
|
|
),
|
|
},
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks.managedFormFields).toBe("failed");
|
|
expect(result.checks.managedFormStructure).toBe("failed");
|
|
}
|
|
);
|
|
|
|
test.each([
|
|
["missing subject", "subject", undefined],
|
|
["changed subject", "subject", JSON.stringify("Another subject")],
|
|
["missing body", "body", undefined],
|
|
["changed body", "body", JSON.stringify("Another message")],
|
|
])("rejects visitor confirmation with %s", (_case, key, value) => {
|
|
const project = addManagedContactPage();
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: {
|
|
...project,
|
|
resources: project.resources.map((resource) => {
|
|
if (resource.name !== "Email to visitor") {
|
|
return resource;
|
|
}
|
|
const email = { ...(resource.email as Record<string, unknown>) };
|
|
if (value === undefined) {
|
|
delete email[key];
|
|
} else {
|
|
email[key] = value;
|
|
}
|
|
return { ...resource, email };
|
|
}),
|
|
},
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks.formActionsPreserved).toBe("failed");
|
|
});
|
|
|
|
test("rejects a changed project recipient mode", () => {
|
|
const project = addManagedContactPage();
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: {
|
|
...project,
|
|
resources: project.resources.map((resource) =>
|
|
resource.name === "Email to owner"
|
|
? { ...resource, email: { recipientMode: "custom" } }
|
|
: resource
|
|
),
|
|
},
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks.formActionsPreserved).toBe("failed");
|
|
});
|
|
|
|
test("rejects a wrong route, missing submit button, disconnected feedback, or changed email recipient", () => {
|
|
const project = addManagedContactPage();
|
|
const calls = managedFormCalls();
|
|
const form = project.instances.find(
|
|
({ component }) => component === "ResourceForm"
|
|
)!;
|
|
const button = project.instances.find(
|
|
({ component }) => component === "Button"
|
|
)!;
|
|
const buttonType = project.props.find(
|
|
({ instanceId, name }) => instanceId === button.id && name === "type"
|
|
)!;
|
|
const success = project.instances.find(
|
|
({ label }) => label === "Success message"
|
|
)!;
|
|
const successVisibility = project.props.find(
|
|
({ instanceId, name }) =>
|
|
instanceId === success.id && name === "data-ws-show"
|
|
)!;
|
|
const visitor = project.resources.find(
|
|
({ name }) => name === "Email to visitor"
|
|
)!;
|
|
const visitorEmail = visitor.email as Record<string, unknown>;
|
|
const responsive = calls.find(
|
|
({ name }) => name === "verify-page-responsive"
|
|
)!;
|
|
|
|
const changed = clone(project);
|
|
changed.props = changed.props.map((prop) =>
|
|
prop.instanceId === button.id && prop.name === "type"
|
|
? { ...prop, value: "button" }
|
|
: prop
|
|
);
|
|
changed.resources = changed.resources.map((resource) =>
|
|
resource.id === visitor.id
|
|
? { ...resource, email: { ...visitorEmail, visitorEmailField: "name" } }
|
|
: resource
|
|
);
|
|
const badCalls = calls.map((call) =>
|
|
call === responsive
|
|
? { ...call, arguments: { ...call.arguments, path: "/" } }
|
|
: call
|
|
);
|
|
const wrongRoute = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project,
|
|
toolCalls: badCalls,
|
|
});
|
|
expect(wrongRoute.checks.responsiveEvidence).toBe("failed");
|
|
|
|
const missingSubmit = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: {
|
|
...project,
|
|
props: project.props.map((prop) =>
|
|
prop.instanceId === buttonType.instanceId && prop.name === "type"
|
|
? { ...prop, value: "button" }
|
|
: prop
|
|
),
|
|
},
|
|
toolCalls: calls,
|
|
});
|
|
expect(missingSubmit.checks.managedFormStructure).toBe("failed");
|
|
|
|
const disconnectedFeedback = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: {
|
|
...project,
|
|
props: project.props.map((prop) =>
|
|
prop.instanceId === successVisibility.instanceId &&
|
|
prop.name === "data-ws-show"
|
|
? { ...prop, value: "true" }
|
|
: prop
|
|
),
|
|
},
|
|
toolCalls: calls,
|
|
});
|
|
expect(disconnectedFeedback.checks.managedFormStructure).toBe("failed");
|
|
|
|
const changedRecipient = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: changed,
|
|
toolCalls: calls,
|
|
});
|
|
expect(changedRecipient.checks.formActionsPreserved).toBe("failed");
|
|
expect(form).toBeDefined();
|
|
});
|
|
|
|
test.each([
|
|
[
|
|
"inverted success comparison",
|
|
"success-show",
|
|
"!== 'success'",
|
|
"feedbackVisibility",
|
|
],
|
|
[
|
|
"inverted error comparison",
|
|
"error-show",
|
|
"!== 'error'",
|
|
"feedbackVisibility",
|
|
],
|
|
["state callback reference", "form-state-change", "", "formStateBinding"],
|
|
[
|
|
"result callback references",
|
|
"form-result-change",
|
|
"",
|
|
"actionResultBindings",
|
|
],
|
|
[
|
|
"state callback assigning the wrong source",
|
|
"form-state-change",
|
|
"",
|
|
"formStateBinding",
|
|
],
|
|
[
|
|
"result callback assigning swapped fields",
|
|
"form-result-change",
|
|
"",
|
|
"actionResultBindings",
|
|
],
|
|
])("rejects %s", (_description, propId, replacement, check) => {
|
|
const project = addManagedContactPage();
|
|
const formState = encodeDataSourceVariable("contact-form-state");
|
|
const results = encodeDataSourceVariable("contact-form-results");
|
|
const errors = encodeDataSourceVariable("contact-form-errors");
|
|
const value =
|
|
_description === "state callback assigning the wrong source"
|
|
? `${formState} = result`
|
|
: _description === "result callback assigning swapped fields"
|
|
? `${results} = result?.errors; ${errors} = result?.results`
|
|
: propId === "success-show" || propId === "error-show"
|
|
? `${formState} ${replacement}`
|
|
: propId === "form-state-change"
|
|
? `${formState}; state`
|
|
: `${results}; ${errors}; result.results; result.errors`;
|
|
const actionValue =
|
|
propId === "form-state-change" || propId === "form-result-change"
|
|
? [
|
|
{
|
|
type: "execute",
|
|
args: [propId === "form-state-change" ? "state" : "result"],
|
|
code: value,
|
|
},
|
|
]
|
|
: value;
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: {
|
|
...project,
|
|
props: project.props.map((prop) =>
|
|
prop.id === propId ? { ...prop, value: actionValue } : prop
|
|
),
|
|
},
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks[check]).toBe("failed");
|
|
expect(result.checks.feedbackBindings).toBe("failed");
|
|
});
|
|
|
|
test.each(["form-state-change", "form-result-change", "errors-data"])(
|
|
"fails gracefully when %s has no binding value",
|
|
(propId) => {
|
|
const project = addManagedContactPage();
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project: {
|
|
...project,
|
|
props: project.props.filter((prop) => prop.id !== propId),
|
|
},
|
|
toolCalls: managedFormCalls(),
|
|
});
|
|
expect(result.checks.feedbackBindings).toBe("failed");
|
|
}
|
|
);
|
|
|
|
test("requires successful Form-template search and insertion, not unrelated insertions", () => {
|
|
const project = addManagedContactPage();
|
|
const calls = managedFormCalls().filter(
|
|
({ name }) => name !== "components.search"
|
|
);
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: managedFormAuthoringFixture,
|
|
project,
|
|
toolCalls: calls,
|
|
});
|
|
expect(result.checks.formTemplateDiscovery).toBe("failed");
|
|
});
|
|
});
|
|
|
|
describe("Form modes evaluation", () => {
|
|
test("recognizes labeled MCP instances and the native Element form tag", () => {
|
|
const project = clone(formModesAuthoringFixture.project);
|
|
project.instances.push(
|
|
{
|
|
id: "mode-contact",
|
|
component: "ResourceForm",
|
|
children: [],
|
|
},
|
|
{
|
|
id: "mode-search",
|
|
component: "ResourceForm",
|
|
children: [],
|
|
},
|
|
{
|
|
id: "mode-native",
|
|
component: "ws:element",
|
|
tag: "form",
|
|
children: [],
|
|
}
|
|
);
|
|
project.props.push(
|
|
{
|
|
id: "mode-contact-label",
|
|
instanceId: "mode-contact",
|
|
name: "aria-label",
|
|
type: "string",
|
|
value: "Contact",
|
|
},
|
|
{
|
|
id: "mode-search-label",
|
|
instanceId: "mode-search",
|
|
name: "aria-label",
|
|
type: "string",
|
|
value: "Search",
|
|
},
|
|
{
|
|
id: "mode-native-label",
|
|
instanceId: "mode-native",
|
|
name: "aria-label",
|
|
type: "string",
|
|
value: "Native",
|
|
},
|
|
{
|
|
id: "mode-contact-actions",
|
|
instanceId: "mode-contact",
|
|
name: "action",
|
|
type: "json",
|
|
value: [{ dataSourceId: "email-owner" }],
|
|
},
|
|
{
|
|
id: "mode-search-actions",
|
|
instanceId: "mode-search",
|
|
name: "action",
|
|
type: "json",
|
|
value: [],
|
|
}
|
|
);
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: formModesAuthoringFixture,
|
|
project,
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
{
|
|
name: "components.search",
|
|
arguments: { searchesForForm: true },
|
|
},
|
|
{
|
|
name: "components.search",
|
|
arguments: { searchesForElement: true },
|
|
},
|
|
{ name: "templates.get" },
|
|
{ name: "insert-component" },
|
|
{ name: "insert-component" },
|
|
{ name: "insert-component" },
|
|
],
|
|
});
|
|
expect(result.checks.resourceFormMode).toBe("passed");
|
|
expect(result.checks.navigationFormMode).toBe("passed");
|
|
expect(result.checks.nativeFormMode).toBe("passed");
|
|
expect(result.checks.formModesRegistryDiscovery).toBe("passed");
|
|
});
|
|
});
|
|
|
|
describe("font-assets evaluation", () => {
|
|
test("accepts corrected persisted metadata and deterministic font sources", () => {
|
|
const project = addFontAssets();
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: fontAssetsFixture,
|
|
project,
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
...project.assets.map(() => ({ name: "upload-asset" })),
|
|
...project.assets.map((asset) => ({
|
|
name: "update-asset",
|
|
arguments: {
|
|
assetId: asset.id,
|
|
values: { meta: fontAssetFixtureMeta },
|
|
},
|
|
})),
|
|
{
|
|
name: "verify-font-assets",
|
|
arguments: { assetIds: project.assets.map((asset) => asset.id) },
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(result).toMatchObject({ passed: true, failures: [] });
|
|
});
|
|
|
|
test("rejects verification before the final metadata update", () => {
|
|
const project = clone(fontAssetsFixture.project);
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: fontAssetsFixture,
|
|
project,
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
{ name: "update-asset" },
|
|
{
|
|
name: "verify-font-assets",
|
|
arguments: { assetIds: ["asset-1", "asset-2"] },
|
|
},
|
|
{ name: "update-asset" },
|
|
],
|
|
});
|
|
|
|
expect(result.checks.metadataWorkflow).toBe("failed");
|
|
});
|
|
});
|
|
|
|
describe("Markdown blog evaluation", () => {
|
|
const optimalContentDatabase = {
|
|
usedBytes: 6_000,
|
|
maxBytes: 500 * 1024,
|
|
unboundedBytes: 6_000,
|
|
sourceDocumentCount: markdownBlogFixtureDocuments.length,
|
|
includedDocumentCount: markdownBlogFixtureDocuments.length,
|
|
omittedDocumentCount: 0,
|
|
materializedQueryCount: 1,
|
|
documentGraphNodeCount: markdownBlogFixtureDocuments.length,
|
|
documentGraphEdgeCount: 0,
|
|
embeddedContentBytes: 0,
|
|
};
|
|
const queryFixtures = addMarkdownBlog().resources.map((resource) =>
|
|
parseStructuredAssetQueryResourceBody(String(resource.body))
|
|
);
|
|
const overviewQuery = queryFixtures[0];
|
|
const detailQuery = queryFixtures[1];
|
|
if (overviewQuery === undefined || detailQuery === undefined) {
|
|
throw new Error("Expected valid Markdown blog query fixtures");
|
|
}
|
|
const toResolvedFixtureQuery = (
|
|
query: typeof overviewQuery | typeof detailQuery,
|
|
slug = "aurora-trails"
|
|
) => ({
|
|
...query,
|
|
where: mapQueryWhere(query.where, (condition) => ({
|
|
...condition,
|
|
value:
|
|
condition.field.join(".") === "properties.slug"
|
|
? slug
|
|
: JSON.parse(condition.value),
|
|
})),
|
|
limit: Number(query.limit),
|
|
offset: Number(query.offset),
|
|
});
|
|
const overviewValidationQuery = toResolvedFixtureQuery(overviewQuery);
|
|
const detailValidationQuery = toResolvedFixtureQuery(detailQuery);
|
|
const detailPageSettingsInput = {
|
|
pageId: "blog-detail",
|
|
values: {
|
|
title: 'post.data.properties.title ?? "Article"',
|
|
meta: {
|
|
description: 'post.data.properties.excerpt ?? ""',
|
|
socialImageUrl: 'post.data.properties.featureImage.src ?? ""',
|
|
status: "post.data ? 200 : 404",
|
|
},
|
|
},
|
|
};
|
|
const successfulCalls: EvaluationToolCall[] = [
|
|
{ name: "meta.guide" },
|
|
traceCall("validate-asset-query", { query: overviewValidationQuery }),
|
|
traceCall("validate-asset-query", { query: detailValidationQuery }),
|
|
traceCall("preview-asset-query", { query: detailValidationQuery }),
|
|
{ name: "create-assets-resource" },
|
|
{ name: "create-assets-resource" },
|
|
{ name: "insert-collection" },
|
|
{ name: "insert-fragment" },
|
|
traceCall("update-page", detailPageSettingsInput),
|
|
{
|
|
name: "verify-page-responsive",
|
|
arguments: {
|
|
path: "/blog",
|
|
viewports: [{ width: 1440 }, { width: 390 }],
|
|
},
|
|
},
|
|
{
|
|
name: "verify-page-responsive",
|
|
arguments: {
|
|
path: "/blog/aurora-trails",
|
|
viewports: [{ width: 1440 }, { width: 390 }],
|
|
},
|
|
},
|
|
];
|
|
|
|
test("accepts a bounded two-route Markdown blog with a resolved JSON author", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
expect(result).toMatchObject({ passed: true, failures: [] });
|
|
expect(result.checks).toMatchObject({
|
|
documentGraphSources: "passed",
|
|
documentGraphQueries: "passed",
|
|
optimalBlogDatabase: "passed",
|
|
});
|
|
});
|
|
|
|
test("accepts persisted MCP expressions and boolean query operands", () => {
|
|
const project = addMarkdownBlog();
|
|
const postIdentifier = encodeDataSourceVariable("post");
|
|
project.dataSources.push({
|
|
id: "collection-item",
|
|
type: "parameter",
|
|
name: "collectionItem",
|
|
scopeInstanceId: "blog-collection",
|
|
});
|
|
project.resources = project.resources.map((resource, index) => ({
|
|
...resource,
|
|
body:
|
|
index === 0
|
|
? resource.body
|
|
: String(resource.body).replace(
|
|
"value: system.params.slug",
|
|
"value: $ws$system.params.slug"
|
|
),
|
|
}));
|
|
project.instances = project.instances.map((instance) => ({
|
|
...instance,
|
|
children: instance.children.map((child) =>
|
|
child.type === "expression"
|
|
? {
|
|
...child,
|
|
value: child.value
|
|
.replace(
|
|
"collectionItem",
|
|
"$ws$dataSource$collection__DASH__item?"
|
|
)
|
|
.replace("post", postIdentifier),
|
|
}
|
|
: child
|
|
),
|
|
}));
|
|
project.props = project.props.map((prop) =>
|
|
prop.type === "expression"
|
|
? {
|
|
...prop,
|
|
value: String(prop.value)
|
|
.replace(
|
|
"collectionItem",
|
|
"$ws$dataSource$collection__DASH__item?"
|
|
)
|
|
.replace("post", postIdentifier),
|
|
}
|
|
: prop
|
|
);
|
|
const markdownCodeProp = project.props.find(
|
|
(prop) => prop.id === "markdown-content"
|
|
);
|
|
if (markdownCodeProp === undefined) {
|
|
throw new Error("Expected Markdown Embed code prop");
|
|
}
|
|
markdownCodeProp.value = `${postIdentifier}?.data?.content?.text`;
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result).toMatchObject({ passed: true, failures: [] });
|
|
});
|
|
|
|
test("rejects wrapping a result-one detail resource in a Collection", () => {
|
|
const project = addMarkdownBlog();
|
|
const detailArticle = project.instances.find(
|
|
(instance) => instance.id === "detail-article"
|
|
);
|
|
if (detailArticle === undefined) {
|
|
throw new Error("Expected detail article fixture");
|
|
}
|
|
detailArticle.component = collectionComponent;
|
|
project.instances = project.instances.map((instance) => ({
|
|
...instance,
|
|
children: instance.children.map((child) =>
|
|
child.type === "expression"
|
|
? {
|
|
...child,
|
|
value: child.value.replaceAll("post.data", "collectionItem"),
|
|
}
|
|
: child
|
|
),
|
|
}));
|
|
project.props = project.props.map((prop) => ({
|
|
...prop,
|
|
value:
|
|
prop.type === "expression"
|
|
? String(prop.value).replaceAll("post.data", "collectionItem")
|
|
: prop.value,
|
|
}));
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.editableBlogBindings).toBe("failed");
|
|
});
|
|
|
|
test("requires both insertion paths and the detail page settings", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: successfulCalls.filter(
|
|
(call) => call.name !== "insert-fragment" && call.name !== "update-page"
|
|
),
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks).toMatchObject({
|
|
bindingVerification: "failed",
|
|
detailPageSettings: "failed",
|
|
});
|
|
});
|
|
|
|
test("rejects a duplicate overview Collection and successful insertion", () => {
|
|
const project = addMarkdownBlog();
|
|
const overviewRoot = project.instances.find(
|
|
(instance) => instance.id === "blog-root"
|
|
);
|
|
if (overviewRoot === undefined) {
|
|
throw new Error("Expected blog overview root");
|
|
}
|
|
overviewRoot.children.push({
|
|
type: "id",
|
|
value: "duplicate-blog-collection",
|
|
});
|
|
project.instances.push({
|
|
id: "duplicate-blog-collection",
|
|
component: collectionComponent,
|
|
children: [],
|
|
});
|
|
const toolCalls = successfulCalls.flatMap((call) =>
|
|
call.name === "insert-collection"
|
|
? [call, { name: "insert-collection" }]
|
|
: [call]
|
|
);
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks).toMatchObject({
|
|
editableBlogBindings: "failed",
|
|
bindingVerification: "failed",
|
|
});
|
|
});
|
|
|
|
test("accepts a supporting fragment in addition to the bound detail fragment", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: successfulCalls.flatMap((call) =>
|
|
call.name === "insert-fragment"
|
|
? [{ name: "insert-fragment" }, call]
|
|
: [call]
|
|
),
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.bindingVerification).toBe("passed");
|
|
});
|
|
|
|
test("requires validating both queries and previewing the detail query before binding", () => {
|
|
for (const omittedCall of ["validate-asset-query", "preview-asset-query"]) {
|
|
let omitted = false;
|
|
const toolCalls = successfulCalls.filter((call) => {
|
|
if (call.name === omittedCall && omitted === false) {
|
|
omitted = true;
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.queryVerification).toBe("failed");
|
|
}
|
|
});
|
|
|
|
test("accepts preview after resource creation when it still precedes binding", () => {
|
|
const previewCall = successfulCalls.find(
|
|
(call) => call.name === "preview-asset-query"
|
|
);
|
|
if (previewCall === undefined) {
|
|
throw new Error("Expected detail query preview call");
|
|
}
|
|
const toolCalls = successfulCalls.filter((call) => call !== previewCall);
|
|
const insertionIndex = toolCalls.findIndex(
|
|
(call) => call.name === "insert-collection"
|
|
);
|
|
toolCalls.splice(insertionIndex, 0, previewCall);
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.queryVerification).toBe("passed");
|
|
});
|
|
|
|
test("rejects validation calls for incomplete placeholder queries", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: successfulCalls.map((call, index) =>
|
|
index === 2
|
|
? traceCall("validate-asset-query", {
|
|
query: {
|
|
result: "one",
|
|
content: { mode: "markdown-body-ref" },
|
|
},
|
|
})
|
|
: call
|
|
),
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.queryVerification).toBe("failed");
|
|
});
|
|
|
|
test("requires previewing the detail query with the concrete article slug", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: successfulCalls.map((call) =>
|
|
call.name === "preview-asset-query"
|
|
? traceCall("preview-asset-query", {
|
|
query: toResolvedFixtureQuery(detailQuery, "wrong-article"),
|
|
})
|
|
: call
|
|
),
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.queryVerification).toBe("failed");
|
|
});
|
|
|
|
test("requires the detail query draft filter and every consumed metadata field", () => {
|
|
const project = addMarkdownBlog();
|
|
project.resources[1] = {
|
|
...project.resources[1],
|
|
body: String(project.resources[1]?.body)
|
|
.replaceAll("draft", "omitted")
|
|
.replaceAll("excerpt", "omitted")
|
|
.replaceAll("featureImage", "omitted"),
|
|
};
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.detailQuery).toBe("failed");
|
|
});
|
|
|
|
test.each([
|
|
["overview", 0, "listingQuery"],
|
|
["detail", 1, "detailQuery"],
|
|
] as const)(
|
|
"requires the %s resource filters to use one top-level all group",
|
|
(_resourceName, resourceIndex, check) => {
|
|
const project = addMarkdownBlog();
|
|
const resource = project.resources[resourceIndex];
|
|
const configuration = parseStructuredAssetQueryResourceBody(
|
|
String(resource?.body)
|
|
);
|
|
if (resource === undefined || configuration === undefined) {
|
|
throw new Error("Expected a structured Assets resource fixture");
|
|
}
|
|
if (!("all" in configuration.where)) {
|
|
throw new Error("Expected an all query fixture");
|
|
}
|
|
resource.body = createStructuredAssetQueryResourceBody({
|
|
...configuration,
|
|
where: { any: configuration.where.all },
|
|
});
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks[check]).toBe("failed");
|
|
}
|
|
);
|
|
|
|
test("rejects an extra stale Assets resource", () => {
|
|
const project = addMarkdownBlog();
|
|
project.resources.push({
|
|
id: "stale-post-resource",
|
|
name: "Placeholder",
|
|
control: "system",
|
|
method: "post",
|
|
url: JSON.stringify(assetsResourceUrl),
|
|
headers: [],
|
|
body: "",
|
|
});
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.scopedBlogResources).toBe("failed");
|
|
});
|
|
|
|
test("requires persisted detail settings and an update targeting that page", () => {
|
|
const wrongSettingsProject = addMarkdownBlog();
|
|
const detailPage = wrongSettingsProject.pages.find(
|
|
(page) => page.id === "blog-detail"
|
|
);
|
|
if (detailPage === undefined) {
|
|
throw new Error("Expected detail page fixture");
|
|
}
|
|
detailPage.title = "Static article";
|
|
const wrongSettings = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: wrongSettingsProject,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
const wrongTarget = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: successfulCalls.map((call) =>
|
|
call.name === "update-page"
|
|
? traceCall("update-page", {
|
|
...detailPageSettingsInput,
|
|
pageId: "blog",
|
|
})
|
|
: call
|
|
),
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(wrongSettings.checks.detailPageSettings).toBe("failed");
|
|
expect(wrongTarget.checks.detailPageSettings).toBe("failed");
|
|
});
|
|
|
|
test("requires the Markdown Embed instance itself to own the code binding", () => {
|
|
const project = addMarkdownBlog();
|
|
const codeProp = project.props.find(
|
|
(prop) => prop.id === "markdown-content"
|
|
);
|
|
if (codeProp === undefined) {
|
|
throw new Error("Expected Markdown Embed code prop");
|
|
}
|
|
codeProp.instanceId = "detail-article";
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.editableBlogBindings).toBe("failed");
|
|
});
|
|
|
|
test.each([
|
|
["blog-collection", "FakeCollection"],
|
|
["markdown", "FakeMarkdownEmbed"],
|
|
])(
|
|
"requires the exact component identity for %s",
|
|
(instanceId, component) => {
|
|
const project = addMarkdownBlog();
|
|
const instance = project.instances.find(
|
|
(candidate) => candidate.id === instanceId
|
|
);
|
|
if (instance === undefined) {
|
|
throw new Error(`Expected ${instanceId} fixture`);
|
|
}
|
|
instance.component = component;
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.editableBlogBindings).toBe("failed");
|
|
}
|
|
);
|
|
|
|
test("requires the Markdown Embed code prop to be the direct content expression", () => {
|
|
const project = addMarkdownBlog();
|
|
const codeProp = project.props.find(
|
|
(prop) => prop.id === "markdown-content"
|
|
);
|
|
if (codeProp === undefined) {
|
|
throw new Error("Expected Markdown Embed code prop");
|
|
}
|
|
codeProp.value = 'post.data.content.text && "not markdown"';
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.editableBlogBindings).toBe("failed");
|
|
});
|
|
|
|
test("rejects blog resources that do not select the referenced author", () => {
|
|
const project = addMarkdownBlog();
|
|
project.resources = project.resources.map((resource) => ({
|
|
...resource,
|
|
body: String(resource.body).replaceAll("author", "omitted"),
|
|
}));
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
});
|
|
expect(result.checks.documentGraphQueries).toBe("failed");
|
|
});
|
|
|
|
test("matches required query fields structurally instead of by substring", () => {
|
|
const project = addMarkdownBlog();
|
|
project.resources[0] = {
|
|
...project.resources[0],
|
|
body: String(project.resources[0]?.body)
|
|
.replace('["properties", "title"]', '["properties", "title-slug"]')
|
|
.replace('["properties", "slug"]', '["properties", "excerpt-slug"]'),
|
|
};
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
});
|
|
expect(result.checks.listingQuery).toBe("failed");
|
|
});
|
|
|
|
test("does not treat dynamic computed members as static bindings", () => {
|
|
const project = addMarkdownBlog();
|
|
project.instances = project.instances.map((instance) => ({
|
|
...instance,
|
|
children: instance.children.map((child) =>
|
|
child.type === "expression"
|
|
? {
|
|
...child,
|
|
value: child.value.replace(
|
|
"collectionItem.properties",
|
|
"collectionItem[properties]"
|
|
),
|
|
}
|
|
: child
|
|
),
|
|
}));
|
|
project.props = project.props.map((prop) =>
|
|
prop.type === "expression"
|
|
? {
|
|
...prop,
|
|
value: String(prop.value).replace(
|
|
"collectionItem.properties",
|
|
"collectionItem[properties]"
|
|
),
|
|
}
|
|
: prop
|
|
);
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
});
|
|
|
|
expect(result.checks.editableBlogBindings).toBe("failed");
|
|
});
|
|
|
|
test("rejects missing detail content and route evidence", () => {
|
|
const project = addMarkdownBlog();
|
|
project.resources = project.resources.slice(0, 1);
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls.slice(0, -1),
|
|
});
|
|
expect(result.checks).toMatchObject({
|
|
detailQuery: "failed",
|
|
blogRouteEvidence: "failed",
|
|
});
|
|
});
|
|
|
|
test("requires a route verification as the terminal call", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: [...successfulCalls, { name: "list-pages" }],
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.blogRouteEvidence).toBe("failed");
|
|
});
|
|
|
|
test("accepts route checks separated by work when verification is terminal", () => {
|
|
const toolCalls = [
|
|
...successfulCalls.slice(0, -1),
|
|
{ name: "list-pages" },
|
|
successfulCalls.at(-1)!,
|
|
];
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.blogRouteEvidence).toBe("passed");
|
|
});
|
|
|
|
test("accepts corrected settings followed by a final consecutive route check", () => {
|
|
const finalVerificationIndex = successfulCalls.findIndex(
|
|
(call) => call.name === "verify-page-responsive"
|
|
);
|
|
const toolCalls = successfulCalls.slice(0, finalVerificationIndex);
|
|
toolCalls.push(
|
|
{
|
|
name: "verify-page-responsive",
|
|
arguments: {
|
|
path: "/blog",
|
|
viewports: [{ width: 1440 }, { width: 390 }],
|
|
},
|
|
},
|
|
traceCall("update-page", detailPageSettingsInput),
|
|
...successfulCalls.slice(finalVerificationIndex)
|
|
);
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownReferencesDiscoveryFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: [{ name: "meta.get-more-tools" }, ...toolCalls],
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks).toMatchObject({
|
|
detailPageSettings: "passed",
|
|
blogRouteEvidence: "passed",
|
|
});
|
|
});
|
|
|
|
test("accepts the two terminal route checks in either order", () => {
|
|
const toolCalls = [...successfulCalls];
|
|
const firstVerificationIndex = toolCalls.findIndex(
|
|
(call) => call.name === "verify-page-responsive"
|
|
);
|
|
const firstVerification = toolCalls[firstVerificationIndex];
|
|
const secondVerification = toolCalls[firstVerificationIndex + 1];
|
|
if (firstVerification === undefined || secondVerification === undefined) {
|
|
throw new Error("Expected two route verification calls");
|
|
}
|
|
toolCalls.splice(
|
|
firstVerificationIndex,
|
|
2,
|
|
secondVerification,
|
|
firstVerification
|
|
);
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.blogRouteEvidence).toBe("passed");
|
|
});
|
|
|
|
test("rejects pages beyond the fixture and the two requested blog routes", () => {
|
|
const project = addMarkdownBlog();
|
|
project.pages.push({
|
|
id: "unrequested-page",
|
|
name: "Unrequested",
|
|
path: "/unrequested",
|
|
rootInstanceId: "blog-root",
|
|
});
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.blogRoutes).toBe("failed");
|
|
});
|
|
|
|
test("rejects asset folders beyond the fixture and the requested Blog folder", () => {
|
|
const project = addMarkdownBlog();
|
|
project.assetFolders.push({
|
|
id: "unrequested-folder",
|
|
projectId: "project",
|
|
name: "Unrequested",
|
|
createdAt: "2026-01-01T00:00:00.000Z",
|
|
});
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: optimalContentDatabase,
|
|
});
|
|
|
|
expect(result.checks.blogAssetFolder).toBe("failed");
|
|
});
|
|
|
|
test("requires documentation discovery for the unprompted reference workflow", () => {
|
|
const project = addMarkdownBlog();
|
|
const withoutDiscovery = evaluateHighImpactOutcome({
|
|
fixture: markdownReferencesDiscoveryFixture,
|
|
project,
|
|
toolCalls: successfulCalls,
|
|
});
|
|
expect(withoutDiscovery.checks.referenceDocumentationDiscovery).toBe(
|
|
"failed"
|
|
);
|
|
|
|
const withDiscovery = evaluateHighImpactOutcome({
|
|
fixture: markdownReferencesDiscoveryFixture,
|
|
project,
|
|
contentDatabase: optimalContentDatabase,
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
{ name: "meta.get-more-tools" },
|
|
...successfulCalls.slice(1),
|
|
],
|
|
});
|
|
expect(withDiscovery).toMatchObject({ passed: true, failures: [] });
|
|
expect(withDiscovery.checks.referenceDocumentationDiscovery).toBe("passed");
|
|
|
|
const withTwoFocusedDiscoveryCalls = evaluateHighImpactOutcome({
|
|
fixture: markdownReferencesDiscoveryFixture,
|
|
project,
|
|
contentDatabase: optimalContentDatabase,
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
{ name: "meta.get-more-tools" },
|
|
{ name: "meta.get-more-tools" },
|
|
...successfulCalls.slice(1),
|
|
],
|
|
});
|
|
expect(
|
|
withTwoFocusedDiscoveryCalls.checks.referenceDocumentationDiscovery
|
|
).toBe("passed");
|
|
});
|
|
|
|
test("rejects a duplicated or oversized compiled blog database", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownBlogFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: successfulCalls,
|
|
contentDatabase: {
|
|
...optimalContentDatabase,
|
|
usedBytes: 6_501,
|
|
unboundedBytes: 6_501,
|
|
materializedQueryCount: 2,
|
|
},
|
|
});
|
|
|
|
expect(result.checks.optimalBlogDatabase).toBe("failed");
|
|
});
|
|
|
|
test("rejects a document-reference workflow that retries a failed tool", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownReferencesDiscoveryFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
{ name: "meta.get-more-tools" },
|
|
{ name: "upload-assets", isError: true },
|
|
{ name: "upload-assets" },
|
|
...successfulCalls.slice(1),
|
|
],
|
|
});
|
|
|
|
expect(result.checks.retryFreeExecution).toBe("failed");
|
|
});
|
|
|
|
test("rejects a document-reference workflow that plans mutations", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: markdownReferencesDiscoveryFixture,
|
|
project: addMarkdownBlog(),
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
{ name: "meta.get-more-tools" },
|
|
{ name: "create-page", planned: true },
|
|
...successfulCalls,
|
|
],
|
|
});
|
|
|
|
expect(result.checks.retryFreeExecution).toBe("failed");
|
|
});
|
|
});
|
|
|
|
describe("authenticated-page evaluation", () => {
|
|
test("accepts four editable states using the existing provider convention", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: authenticatedPageFixture,
|
|
project: addAuthPage(),
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
{ name: "list-resources" },
|
|
{ name: "list-instances" },
|
|
{ name: "insert-fragment" },
|
|
{ name: "create-resource" },
|
|
{ name: "verify-bindings" },
|
|
{ name: "audit" },
|
|
{
|
|
name: "screenshot",
|
|
arguments: { viewport: { width: 1440, height: 900 } },
|
|
},
|
|
],
|
|
});
|
|
expect(result).toMatchObject({ passed: true, failures: [] });
|
|
});
|
|
|
|
test("rejects persisted credentials and a conflicting provider", () => {
|
|
const project = addAuthPage();
|
|
project.resources.push({
|
|
id: "firebase-auth",
|
|
name: "Firebase",
|
|
method: "get",
|
|
url: '"/auth"',
|
|
headers: [
|
|
{
|
|
name: "Authorization",
|
|
value: '"Bearer sk-abcdefghijklmnopqrstuvwxyz"',
|
|
},
|
|
],
|
|
});
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: authenticatedPageFixture,
|
|
project,
|
|
toolCalls: [{ name: "audit" }],
|
|
});
|
|
expect(result.passed).toBe(false);
|
|
expect(result.checks).toMatchObject({
|
|
privacy: "failed",
|
|
providerConvention: "failed",
|
|
});
|
|
});
|
|
|
|
test("requires guidance, binding verification, audit, and visual evidence", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: authenticatedPageFixture,
|
|
project: addAuthPage(),
|
|
toolCalls: [{ name: "insert-fragment" }],
|
|
});
|
|
|
|
expect(result.checks).toMatchObject({
|
|
guidance: "failed",
|
|
bindingVerification: "failed",
|
|
audit: "failed",
|
|
visualEvidence: "failed",
|
|
});
|
|
});
|
|
|
|
test("requires guidance before every other operation", () => {
|
|
const lateGuidance = evaluateHighImpactOutcome({
|
|
fixture: authenticatedPageFixture,
|
|
project: addAuthPage(),
|
|
toolCalls: [{ name: "audit" }, { name: "meta.guide" }],
|
|
});
|
|
expect(lateGuidance.checks.guidance).toBe("failed");
|
|
|
|
const repeatedGuidance = evaluateHighImpactOutcome({
|
|
fixture: authenticatedPageFixture,
|
|
project: addAuthPage(),
|
|
toolCalls: [
|
|
{ name: "meta.guide" },
|
|
{ name: "inspect-auth-context" },
|
|
{ name: "meta.guide" },
|
|
],
|
|
});
|
|
expect(repeatedGuidance.checks.guidance).toBe("passed");
|
|
});
|
|
});
|
|
|
|
describe("design-input evaluation", () => {
|
|
test("accepts semantic token-preserving responsive output with visual evidence", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: designInputFixture,
|
|
project: addDesignPage(),
|
|
toolCalls: designCalls,
|
|
});
|
|
expect(result).toMatchObject({ passed: true, failures: [] });
|
|
});
|
|
|
|
test("accepts one responsive page verification as audit and viewport evidence", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: designInputFixture,
|
|
project: addDesignPage(),
|
|
toolCalls: [
|
|
...designCalls.filter(
|
|
(call) => call.name !== "screenshot" && call.name !== "audit"
|
|
),
|
|
{
|
|
name: "verify-page-responsive",
|
|
arguments: {
|
|
viewports: [
|
|
{ width: 1440, height: 900 },
|
|
{ width: 390, height: 844 },
|
|
],
|
|
},
|
|
},
|
|
],
|
|
});
|
|
expect(result).toMatchObject({ passed: true, failures: [] });
|
|
});
|
|
|
|
test("rejects unsupported components", () => {
|
|
const project = addDesignPage();
|
|
project.instances.find(
|
|
(instance) => instance.id === "summer-hero"
|
|
)!.component = "HtmlEmbed";
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: designInputFixture,
|
|
project,
|
|
toolCalls: designCalls,
|
|
});
|
|
expect(result.checks.supportedComponents).toBe("failed");
|
|
});
|
|
|
|
test("rejects invalid expressions", () => {
|
|
const project = addDesignPage();
|
|
project.props.push({
|
|
id: "bad-expression",
|
|
instanceId: "summer-heading",
|
|
name: "hidden",
|
|
type: "expression",
|
|
value: "user &&",
|
|
});
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: designInputFixture,
|
|
project,
|
|
toolCalls: designCalls,
|
|
});
|
|
expect(result.checks.expressions).toBe("failed");
|
|
});
|
|
|
|
test("accepts a parenthesized object expression", () => {
|
|
const project = addDesignPage();
|
|
project.props.push({
|
|
id: "style-expression",
|
|
instanceId: "summer-heading",
|
|
name: "style",
|
|
type: "expression",
|
|
value: '({ display: state === "ready" ? "block" : "none" })',
|
|
});
|
|
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: designInputFixture,
|
|
project,
|
|
toolCalls: designCalls,
|
|
});
|
|
|
|
expect(result.checks.expressions).toBe("passed");
|
|
});
|
|
|
|
test("rejects broad or unnecessarily verbose reads", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: designInputFixture,
|
|
project: addDesignPage(),
|
|
toolCalls: [{ name: "snapshot" }, ...designCalls],
|
|
});
|
|
expect(result.checks.boundedReads).toBe("failed");
|
|
});
|
|
|
|
test("requires both desktop and mobile evidence", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: designInputFixture,
|
|
project: addDesignPage(),
|
|
toolCalls: designCalls.filter(
|
|
(call) =>
|
|
(call.arguments?.viewport as { width?: number } | undefined)
|
|
?.width !== 390
|
|
),
|
|
});
|
|
expect(result.checks.viewportEvidence).toBe("failed");
|
|
});
|
|
|
|
test("accepts a successful rendered manifest as local audit evidence", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: designInputFixture,
|
|
project: addDesignPage(),
|
|
toolCalls: designCalls.filter((call) => call.name !== "audit"),
|
|
artifacts: [{ kind: "audit", passed: true }],
|
|
});
|
|
|
|
expect(result.checks.audit).toBe("passed");
|
|
});
|
|
});
|
|
|
|
describe("Form modes authoring evaluation", () => {
|
|
const project = (): EvaluationProject => ({
|
|
...formModesAuthoringFixture.project,
|
|
instances: [
|
|
{
|
|
id: "contact",
|
|
component: "ResourceForm",
|
|
label: "Contact",
|
|
children: [],
|
|
},
|
|
{
|
|
id: "search",
|
|
component: "ResourceForm",
|
|
label: "Search",
|
|
children: [],
|
|
},
|
|
{
|
|
id: "native",
|
|
component: "Element",
|
|
tag: "form",
|
|
label: "Native",
|
|
children: [],
|
|
},
|
|
],
|
|
props: [
|
|
{
|
|
id: "contact-action",
|
|
instanceId: "contact",
|
|
name: "action",
|
|
type: "json",
|
|
value: [{ dataSourceId: "email" }],
|
|
},
|
|
{
|
|
id: "search-action",
|
|
instanceId: "search",
|
|
name: "action",
|
|
type: "json",
|
|
value: [],
|
|
},
|
|
],
|
|
});
|
|
const calls = [
|
|
{
|
|
name: "components.search",
|
|
arguments: { searchesForForm: true },
|
|
},
|
|
{
|
|
name: "components.search",
|
|
arguments: { searchesForElement: true },
|
|
},
|
|
{ name: "templates.get" },
|
|
...Array.from({ length: 3 }, () => ({ name: "insert-component" })),
|
|
];
|
|
test("accepts distinct Resource, navigation, and native forms", () => {
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: formModesAuthoringFixture,
|
|
project: project(),
|
|
toolCalls: calls,
|
|
});
|
|
expect(result.checks.resourceFormMode).toBe("passed");
|
|
expect(result.checks.navigationFormMode).toBe("passed");
|
|
expect(result.checks.nativeFormMode).toBe("passed");
|
|
expect(result.checks.formModesRegistryDiscovery).toBe("passed");
|
|
});
|
|
test("rejects the legacy identity and navigation with connected actions", () => {
|
|
const invalid = project();
|
|
invalid.instances[0].component = "WebhookForm";
|
|
invalid.props[1].value = [{ dataSourceId: "email" }];
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: formModesAuthoringFixture,
|
|
project: invalid,
|
|
toolCalls: calls,
|
|
});
|
|
expect(result.checks.resourceFormMode).toBe("failed");
|
|
expect(result.checks.navigationFormMode).toBe("failed");
|
|
});
|
|
test("rejects a managed marker on the native form", () => {
|
|
const invalid = project();
|
|
invalid.props.push({
|
|
id: "native-action",
|
|
instanceId: "native",
|
|
name: "action",
|
|
type: "string",
|
|
value: "?__webstudio__=navigate",
|
|
});
|
|
const result = evaluateHighImpactOutcome({
|
|
fixture: formModesAuthoringFixture,
|
|
project: invalid,
|
|
toolCalls: calls,
|
|
});
|
|
expect(result.checks.nativeFormMode).toBe("failed");
|
|
});
|
|
});
|