mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
* test(studio): add design-panel QA fixture and triage matrix Fixture project covering all panel-editable element archetypes, plus the QA findings matrix from the design-panel bug campaign. * fix(studio): make canvas selection hit intended elements - honor author pointer-events:none in hit-testing (was selecting invisible overlays) - pause playback before mousedown sampling; fall back to hover selection on null resolve - invalidate committed selection when the active composition changes - double-click keeps selection and defers to multi-candidate click cycling * fix(studio): close remaining selection-layer review findings - hoverSelection fallback now wired at all 3 mousedown call sites (box-click, blocked-drag, plain overlay click) instead of just the overlay path - pointer-events override detection reads computed style, not inline style, so a CSS-class opt-in (not just inline style=) on a descendant is honored - defensively remove the pointer-events override before the group-fallback check too, closing a theoretical gap in the no-elementsFromPoint branch - a click that resolves to nothing (dead-zone / deselect) no longer leaves playback paused if it was already playing * fix(studio-server): child-scoped patch operations with batch abort - PatchOperation gains optional childSelector/childIndex resolved under the matched parent - pre-pass resolves every op target; any miss aborts the batch with matched:false, no partial write - style-decl parsing extracted to sourceStyleMutation to stay under the file-size cap - new ./source-mutation subpath export (mirrors ./finite-mutation) * fix(studio): per-child patch op builders and persist-seam harness - buildTextFieldChildLocator indexes over the parent's full same-tag child list - buildTextFieldChildOperations emits per-field ops for same-shape multi-field edits - SDK cutover declines child-scoped batches (hfId mapping would hit the parent) - persist-seam integration harness drives real client ops through patchElementInHtml * fix(studio): fail closed on unresolved text-field child index buildTextFieldChildLocator guessed a synthetic field's position by counting same-tag "child" fields elsewhere in the array whenever sourceChildIndex was absent. That heuristic is unreachable today (the count-mismatch guard in buildTextFieldChildOperations already refuses add/remove edits before it's reached) but would silently locate the wrong element for a future caller that wires up synthetic-field support without also computing a real sourceChildIndex. Return null instead so the caller falls back to the unsupported-structure path. * fix(studio): surface persist failures with toast and guarded revert - matched:false and persist errors toast, warn structurally, and revert the optimistic write - reverts guarded by a per-property version counter so stale failures never stomp newer edits - structural text-field edits refuse persist instead of writing escaped markup - multi-field child edits persist via per-child ops; shared commit runner extracted * fix(studio): revert data-attribute and html-attribute commits on persist failure commitDataAttribute and handleDomHtmlAttributeCommit toasted on failure but never reverted the optimistic attribute write, leaving the preview showing an edit that never reached disk (the exact bug this PR closes for style commits). Extracted into useDomEditAttributeCommits.ts (useDomEditTextCommits.ts was at the file-size cap) and routed through runDomEditCommit with a per-target+ attribute version guard, mirroring handleDomStyleCommit. * fix(studio): close coupled persist-hook review findings Three findings from R2 review that must land together: a patch-rejection toast doubled up with the generic persist-failure toast (StudioSaveHttpError had no alreadyToasted marker), a failed prepareContent write (e.g. font-face injection) reverted and re-toasted a change the server had already persisted, and text-commit shouldRevert only rolled back on one narrow error type instead of any persist failure.
124 lines
3.8 KiB
TypeScript
124 lines
3.8 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import type { PatchOperation } from "../utils/sourcePatcher";
|
|
import { StudioSaveHttpError } from "../utils/studioSaveDiagnostics";
|
|
import {
|
|
DomEditPersistUnsafeValueError,
|
|
reportDomEditPersistFailure,
|
|
warnDomEditPersistNoOp,
|
|
} from "./domEditPersistFailure";
|
|
|
|
const selection = {
|
|
label: "Hero title",
|
|
hfId: "hf-hero",
|
|
id: "hero",
|
|
selector: ".hero",
|
|
selectorIndex: 0,
|
|
sourceFile: "index.html",
|
|
};
|
|
|
|
const operations: PatchOperation[] = [{ type: "inline-style", property: "color", value: "red" }];
|
|
|
|
describe("reportDomEditPersistFailure", () => {
|
|
it("toasts with the selected label and underlying error detail", () => {
|
|
const showToast = vi.fn<(message: string, tone?: "error" | "info") => void>();
|
|
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
|
|
reportDomEditPersistFailure(selection, operations, new Error("network down"), showToast);
|
|
|
|
expect(showToast).toHaveBeenCalledWith('Couldn\'t save "Hero title": network down', "error");
|
|
expect(warnSpy).toHaveBeenCalledWith(
|
|
"[Studio] DOM edit persist failed",
|
|
expect.objectContaining({
|
|
target: {
|
|
hfId: "hf-hero",
|
|
id: "hero",
|
|
selector: ".hero",
|
|
selectorIndex: 0,
|
|
sourceFile: "index.html",
|
|
},
|
|
operations: "inline-style:color",
|
|
error: "network down",
|
|
}),
|
|
);
|
|
|
|
warnSpy.mockRestore();
|
|
});
|
|
|
|
it("toasts StudioSaveHttpError and unmarked unsafe errors", () => {
|
|
const showToast = vi.fn<(message: string, tone?: "error" | "info") => void>();
|
|
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
|
|
reportDomEditPersistFailure(
|
|
selection,
|
|
operations,
|
|
new StudioSaveHttpError("Failed to patch index.html (500)", 500),
|
|
showToast,
|
|
);
|
|
reportDomEditPersistFailure(
|
|
selection,
|
|
operations,
|
|
new DomEditPersistUnsafeValueError("DOM patch contains unsafe values: style.width"),
|
|
showToast,
|
|
);
|
|
|
|
expect(showToast).toHaveBeenCalledTimes(2);
|
|
expect(showToast).toHaveBeenCalledWith(
|
|
expect.stringContaining("Failed to patch index.html"),
|
|
"error",
|
|
);
|
|
expect(showToast).toHaveBeenCalledWith(
|
|
expect.stringContaining("DOM patch contains unsafe values: style.width"),
|
|
"error",
|
|
);
|
|
expect(warnSpy).toHaveBeenCalledTimes(2);
|
|
|
|
warnSpy.mockRestore();
|
|
});
|
|
|
|
it("does not toast errors explicitly marked as already toasted", () => {
|
|
const showToast = vi.fn<(message: string, tone?: "error" | "info") => void>();
|
|
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
const error = new DomEditPersistUnsafeValueError(
|
|
"DOM patch contains unsafe values: style.width",
|
|
);
|
|
Object.defineProperty(error, "alreadyToasted", { value: true });
|
|
|
|
reportDomEditPersistFailure(selection, operations, error, showToast);
|
|
|
|
expect(showToast).not.toHaveBeenCalled();
|
|
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
expect(warnSpy).toHaveBeenCalledWith(
|
|
"[Studio] DOM edit persist failed",
|
|
expect.objectContaining({
|
|
target: expect.objectContaining({ hfId: "hf-hero", sourceFile: "index.html" }),
|
|
}),
|
|
);
|
|
|
|
warnSpy.mockRestore();
|
|
});
|
|
});
|
|
|
|
describe("warnDomEditPersistNoOp", () => {
|
|
it("logs a structured breadcrumb without requiring a toast callback", () => {
|
|
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
|
|
warnDomEditPersistNoOp(selection, operations);
|
|
|
|
expect(warnSpy).toHaveBeenCalledWith(
|
|
"[Studio] DOM edit persist no-op",
|
|
expect.objectContaining({
|
|
target: {
|
|
hfId: "hf-hero",
|
|
id: "hero",
|
|
selector: ".hero",
|
|
selectorIndex: 0,
|
|
sourceFile: "index.html",
|
|
},
|
|
operations: "inline-style:color",
|
|
}),
|
|
);
|
|
|
|
warnSpy.mockRestore();
|
|
});
|
|
});
|