Files
aigc-home/e2e/hel884.cjs
T
施工员2号andmultica-agent e88dc0ae40 fix(HEL-887): keep selection for kept files, unblock invalid-only delete, composited locate pulse
- library deleteMutation.onSuccess: only paths the server really deleted
  leave the selection (accumulated across 200-path chunks); kept files
  stay checked, current focus cleared only when its file is gone;
  in-modal freed-file delete and card-delete-with-file prune the same way
- usage modal: direct delete offered whenever valid_total === 0,
  regardless of invalid_total (dead references never block); invalid
  count note kept in both branches
- e2e runner: isolated_data_removed recorded after the
  TemporaryDirectory context exits and exact child PIDs are waited on
  (daemon PID compared first); isolated dir recorded for verification
- locate gold ring: static ring kept, pulse moved to a ::before feedback
  layer animated with transform/opacity only (no box-shadow repaint),
  gated to data-motion=full; calm/off/reduced-motion stay static
- e2e: +14 checks (46 total) — mixed kept/deleted selection, failed
  request retry, cross-200-batch with kept file, invalid-only in-modal
  delete, ring computed-style/keyframe evidence; HEL884_STRICT=0 records
  the full before-fix failure table

Co-authored-by: multica-agent <github@multica.ai>
2026-10-27 01:02:12 +08:00

374 lines
20 KiB
JavaScript

// HEL-884 — real-page locate-and-delete loop regression (isolated data).
// Drives /library → kept-on-canvas occupancy modal → locate on the canvas
// (centered + highlighted card + back chip) → per-card delete with accurate
// impact text → release-only (file preserved) → orphan no longer blocks →
// running card blocked → nothing resurrects after reload.
const { chromium } = require(
process.env.PLAYWRIGHT_MODULE_PATH || "playwright",
);
const fs = require("node:fs"),
assert = require("node:assert/strict");
const OUT = "../evidence/hel884";
const WEB = "http://127.0.0.1:15274";
const report = { checks: [], errors: [] };
// HEL884_STRICT=0 records every failure instead of aborting at the first —
// used to capture the full before-fix failure table in one base-build run.
const STRICT = process.env.HEL884_STRICT !== "0";
const ok = (name, pass) => {
report.checks.push({ name, pass: !!pass });
console.log(pass ? "PASS" : "FAIL", name);
if (STRICT) assert(pass, name);
};
const pause = (ms) => new Promise((r) => setTimeout(r, ms));
const lastToast = (p) =>
p.evaluate(() => {
const els = document.querySelectorAll(".toast, [class*='toast']");
return els.length ? els[els.length - 1].textContent : "";
});
const usageModal = (p) => p.getByRole("dialog").filter({ hasText: "画布占用详情" });
(async () => {
fs.mkdirSync(OUT, { recursive: true });
const seeded = JSON.parse(fs.readFileSync(`${OUT}/seed-ids.json`, "utf8"));
const browser = await chromium.launch({
channel: "chromium", // full build — headless shell lacks host libs
args: ["--no-sandbox", "--disable-dev-shm-usage"],
});
const ctx = await browser.newContext({
viewport: { width: 1440, height: 900 },
recordVideo: { dir: `${OUT}/video` },
});
const p = await ctx.newPage();
p.on("pageerror", (e) => report.errors.push(e.stack));
p.setDefaultTimeout(15000);
await ctx.addInitScript(() => {
localStorage.setItem("aigc-lang", "zh");
localStorage.setItem("aigc-motion", "off");
});
const names = await (await fetch("http://127.0.0.1:18274/api/library/media")).json();
const byName = Object.fromEntries(names.map((i) => [i.name, i.path]));
for (const n of ["locate-main.png", "free-upload.png", "release-only.png",
"orphan-only.png", "running-held.png"])
ok(`seed: ${n} visible in library`, !!byName[n]);
// helper: open the occupancy modal for one file via a real delete attempt
async function openUsage(name) {
await p.getByRole("button", { name: `查看 ${name}` }).click();
await p.getByRole("button", { name: "删除此文件" }).click();
await p.getByRole("dialog").getByRole("button", { name: "确认删除" }).click();
const modal = usageModal(p);
await modal.waitFor();
await pause(600);
return modal;
}
// ── 1. orphan-only reference never blocks deletion ─────────────────
await p.goto(WEB + "/library");
await p.getByRole("button", { name: /查看 orphan-only/ }).waitFor();
await p.getByRole("button", { name: "选择", exact: true }).click();
await p.getByRole("button", { name: /选择 orphan-only/, exact: true }).click();
await p.getByRole("button", { name: "删除", exact: true }).click();
await p.getByRole("dialog").getByRole("button", { name: "确认删除" }).click();
await pause(900);
ok("orphan: deleted directly (dead reference not occupancy)",
/已删除 1 个文件/.test(await lastToast(p)) && !fs.existsSync(byName["orphan-only.png"]));
await p.getByRole("button", { name: "选择", exact: true }).click(); // leave select mode
// ── 2. kept-on-canvas → occupancy modal with the real locations ────
const modal1 = await openUsage("locate-main.png");
await modal1.getByText("沙盒画布A").waitFor();
await modal1.getByText("项目画布B").waitFor();
await modal1.getByText(/会话「定位沙盒会话」/).waitFor();
await modal1.getByText(/项目「占用项目」/).waitFor();
await modal1.getByText("主占用卡").waitFor();
await modal1.getByText("第二处占用").waitFor();
ok("modal: both usages listed with canvas+scope, not just the first",
(await modal1.locator(".usage-card").count()) === 2);
ok("modal: multi-reference keeps-file note",
(await modal1.getByText(/文件仍被其他卡片或项目使用/).count()) >= 1);
ok("kept: file survives on disk", fs.existsSync(byName["locate-main.png"]));
await p.screenshot({ path: `${OUT}/01-usage-modal.png` });
await modal1.getByRole("button", { name: "关闭对话框" }).click();
await pause(300);
ok("modal: closable", !(await usageModal(p).count()));
// ── 3. locate navigates to the right canvas & card, in view ────────
const modal2 = await openUsage("locate-main.png");
const sandboxRow = modal2.locator(".usage-card", { hasText: "沙盒画布A" });
await sandboxRow.getByRole("button", { name: /定位/ }).click();
await p.waitForURL(new RegExp(`/canvas/${seeded.canvas_a}`));
await p.getByTestId("locate-chip").waitFor();
await p.getByTestId("located-card").waitFor();
await pause(1300);
ok("locate: ?locate param consumed", !p.url().includes("locate="));
const inView = await p.evaluate(() => {
const el = document.querySelector("[data-testid='located-card']");
if (!el) return null;
const r = el.getBoundingClientRect();
return { x: r.x, y: r.y, w: r.width, h: r.height, vw: innerWidth, vh: innerHeight };
});
ok("locate: correct canvas reached", new RegExp(`/canvas/${seeded.canvas_a}`).test(p.url()));
ok("locate: card named 主占用卡 is the located one",
(await p.getByTestId("located-card").textContent()).includes("主占用卡"));
ok("locate: viewport-out card brought into view", inView && inView.x > 0 &&
inView.y > 0 && inView.x + inView.w < inView.vw && inView.y + inView.h < inView.vh);
// HEL-887: the gold ring is a static layer; the pulse breathes on a
// ::before feedback layer animated with transform/opacity only, and only
// under data-motion=full — calm/off (and reduced-motion → off) stay static.
const ring = await p.evaluate(async () => {
const el = document.querySelector("[data-testid='located-card']");
if (!el) return null;
const raf = () => new Promise((r) => requestAnimationFrame(() => r()));
// Mirror exactly what reduceMotion.apply() writes per mode — data-reduce=1
// carries a global animation:none kill-switch, so motion alone is not the
// whole state.
const setMode = (mode) => {
const root = document.documentElement;
root.dataset.motion = mode;
root.dataset.reduce = mode === "off" ? "1" : "0";
root.classList.toggle("calm", mode === "calm");
root.classList.toggle("reduce", mode === "off");
};
const staticRing = getComputedStyle(el).boxShadow;
const layerName = () => getComputedStyle(el, "::before").animationName;
setMode("off");
const off = { name: layerName(), opacity: getComputedStyle(el, "::before").opacity };
setMode("calm");
const calm = layerName();
setMode("full");
await raf();
await raf();
const full = layerName();
// Element.getAnimations() skips pseudo targets in Chromium;
// document.getAnimations() carries them with effect.pseudoElement set.
const anims = document.getAnimations()
.filter((a) => a.effect?.target === el && a.effect?.pseudoElement === "::before")
.map((a) => ({
name: a.animationName,
props: [...new Set(a.effect.getKeyframes().flatMap((f) =>
Object.keys(f).filter((k) =>
!["offset", "computedOffset", "easing", "composite"].includes(k))))].sort(),
}));
setMode("off");
return { staticRing, off, calm, full, anims };
});
ok("ring: static gold ring stays on the located card",
!!ring && /0px 0px 0px 3px/.test(ring.staticRing));
ok("ring: pulse layer runs only under motion=full",
!!ring && ring.full === "located-pulse" &&
ring.calm === "none" &&
ring.off.name === "none" && ring.off.opacity === "0");
ok("ring: pulse keyframes animate transform/opacity only",
!!ring && ring.anims.length === 1 &&
ring.anims[0].name === "located-pulse" &&
JSON.stringify(ring.anims[0].props) === JSON.stringify(["opacity", "transform"]));
await p.screenshot({ path: `${OUT}/02-canvas-located.png` });
// ── 4. back chip returns to the library; selection round-trip ──────
await p.getByTestId("locate-chip").getByRole("button", { name: "返回素材库" }).click();
await p.waitForURL(/\/library/);
await pause(500);
ok("back: usage modal not reopened", !(await usageModal(p).count()));
// selection survives a canvas round-trip (persisted selection)
await p.getByRole("button", { name: "选择", exact: true }).click();
await p.getByRole("button", { name: /选择 free-upload/, exact: true }).click();
await p.getByText("已选 1").waitFor();
await p.goto(`${WEB}/canvas/${seeded.canvas_b}`);
await p.getByTestId("titlecard").waitFor();
await p.goBack();
await p.getByRole("button", { name: /查看 free-upload/ }).waitFor();
await p.getByText("已选 1").waitFor();
ok("back: library selection restored after canvas round-trip",
(await p.getByText("已选 1").count()) === 1);
await p.getByRole("button", { name: "取消", exact: true }).click();
// ── 5. delete one card: accurate text, cancel unchanged, confirm ───
const modal3 = await openUsage("locate-main.png");
const projectRow = modal3.locator(".usage-card", { hasText: "项目画布B" });
await projectRow.getByRole("button", { name: "删除卡片…" }).click();
await modal3.getByText(/文件仍被其他卡片或项目使用/).first().waitFor();
await p.screenshot({ path: `${OUT}/03-confirm-keep.png` });
await modal3.getByRole("button", { name: "取消", exact: true }).click();
await pause(400);
ok("cancel: card untouched", (await modal3.getByText("第二处占用").count()) === 1);
await projectRow.getByRole("button", { name: "删除卡片…" }).click();
await modal3.getByRole("button", { name: "确认删除卡片" }).click();
await pause(1300);
ok("card delete: file kept toast (other reference alive)",
/卡片已删除,文件保留/.test(await lastToast(p)));
await modal3.getByText("第二处占用").waitFor({ state: "detached" });
ok("card delete: other usage still listed",
(await modal3.locator(".usage-card", { hasText: "沙盒画布A" }).count()) === 1);
ok("card delete: file survives on disk", fs.existsSync(byName["locate-main.png"]));
await p.screenshot({ path: `${OUT}/04-one-usage-left.png` });
// ── 6. last card: warn the file goes too, then it does ─────────────
const lastRow = modal3.locator(".usage-card", { hasText: "沙盒画布A" });
await lastRow.getByRole("button", { name: "删除卡片…" }).click();
await modal3.getByText(/同时删除文件/).first().waitFor();
await modal3.getByRole("button", { name: "确认删除卡片" }).click();
await pause(1500);
ok("last card: file deleted with the card",
/卡片已删除,文件已一并删除/.test(await lastToast(p)) &&
!fs.existsSync(byName["locate-main.png"]));
await usageModal(p).waitFor({ state: "detached" });
ok("loop closed: modal auto-dismissed (file gone from list)",
!(await usageModal(p).count()));
ok("loop closed: file gone from library list",
!(await p.getByRole("button", { name: /查看 locate-main/ }).count()));
// ── 7. release-only keeps the file, then library delete finishes ───
const modal4 = await openUsage("release-only.png");
await modal4.getByText("沙盒画布A").waitFor();
await modal4.getByRole("button", { name: "仅移除卡片" }).click();
await modal4.getByText(/原文件保留/).waitFor();
await p.screenshot({ path: `${OUT}/05-release-confirm.png` });
await modal4.getByRole("button", { name: "确认仅移除" }).click();
await pause(1300);
ok("release: card removed, file preserved",
/已仅移除卡片,原文件保留/.test(await lastToast(p)) &&
fs.existsSync(byName["release-only.png"]));
await modal4.getByText("当前没有画布卡片占用此文件了,现在可以删除。").waitFor();
await modal4.getByRole("button", { name: "删除此文件" }).click();
await pause(1200);
ok("release: freed file deletable in-modal",
/文件已删除/.test(await lastToast(p)) && !fs.existsSync(byName["release-only.png"]));
// ── 8. running card is visible but not processable ─────────────────
const modal5 = await openUsage("running-held.png");
await modal5.getByText("生成画布C").waitFor();
await modal5.getByText(/生成中,完成后才能处理这张卡/).waitFor();
ok("running: no delete/release action offered",
!(await modal5.getByRole("button", { name: "删除卡片…" }).count()) &&
!(await modal5.getByRole("button", { name: "仅移除卡片" }).count()));
ok("running: file survives", fs.existsSync(byName["running-held.png"]));
await p.screenshot({ path: `${OUT}/06-running-card.png` });
await modal5.getByRole("button", { name: "关闭对话框" }).click();
// ── 9. nothing resurrects after a full reload ──────────────────────
await p.reload();
await p.getByRole("button", { name: /查看 free-upload/ }).waitFor();
ok("reload: locate-main stays gone",
!(await p.getByRole("button", { name: /查看 locate-main/ }).count()));
ok("reload: release-only stays gone",
!(await p.getByRole("button", { name: /查看 release-only/ }).count()));
ok("reload: orphan-only stays gone",
!(await p.getByRole("button", { name: /查看 orphan-only/ }).count()));
ok("reload: untouched control file still listed",
(await p.getByRole("button", { name: /查看 free-upload/ }).count()) === 1);
await p.screenshot({ path: `${OUT}/07-final-library.png` });
// ── 10. canvas A no longer shows the deleted card after refresh ────
await p.goto(`${WEB}/canvas/${seeded.canvas_a}`);
await p.getByTestId("titlecard").waitFor();
await pause(1500);
ok("canvas: deleted card not resurrected",
!(await p.getByText("主占用卡").count()));
await p.screenshot({ path: `${OUT}/08-canvas-after.png` });
// ── 11. HEL-887 mixed delete: kept stays checked, deleted leaves ────
const pickedPaths = () => p.evaluate(() =>
[...document.querySelectorAll(".lt.picked")].map((el) =>
el.querySelector(".bd b")?.textContent ?? ""));
await p.goto(WEB + "/library");
await p.getByRole("button", { name: /查看 running-held/ }).waitFor();
await p.getByRole("button", { name: "选择", exact: true }).click();
await p.getByRole("button", { name: /选择 running-held/ }).click();
await p.getByRole("button", { name: /选择 free-upload/ }).click();
await p.getByText("已选 2", { exact: true }).waitFor();
// transport failure: the whole selection must survive for a retry
await p.route("**/api/library/media", async (route) => {
if (route.request().method() === "DELETE") await route.abort("failed");
else await route.continue();
});
await p.getByRole("button", { name: "删除", exact: true }).click();
await p.getByRole("dialog").getByRole("button", { name: "确认删除" }).click();
await pause(700);
ok("retry: failed delete keeps every checked path",
/删除请求失败/.test(await lastToast(p)) &&
(await p.getByText("已选 2", { exact: true }).count()) === 1);
// retry the same modal: deleted leaves the selection, kept stays checked
await p.unroute("**/api/library/media");
await p.getByRole("dialog").getByRole("button", { name: "确认删除" }).click();
await pause(1400);
ok("mixed: only the deleted path leaves the selection",
/已删除 1 个文件/.test(await lastToast(p)) &&
(await p.getByText("已选 1").count()) === 1 &&
!fs.existsSync(byName["free-upload.png"]) &&
fs.existsSync(byName["running-held.png"]));
report.mixedSelection = await pickedPaths();
// kept selection survives a canvas round-trip and a full refresh
await p.goto(`${WEB}/canvas/${seeded.canvas_b}`);
await p.getByTestId("titlecard").waitFor();
await p.goBack();
await p.getByRole("button", { name: /查看 running-held/ }).waitFor();
ok("mixed: kept selection restored after canvas round-trip",
(await p.getByText("已选 1").count()) === 1);
await p.reload();
await p.getByRole("button", { name: /查看 running-held/ }).waitFor();
ok("mixed: kept selection restored after full refresh",
(await p.getByText("已选 1").count()) === 1 &&
!(await p.getByRole("button", { name: /查看 free-upload/ }).count()));
if (await p.getByRole("button", { name: "取消", exact: true }).count())
await p.getByRole("button", { name: "取消", exact: true }).click();
// ── 12. HEL-887 invalid-only references still allow in-modal delete ─
const modal6 = await openUsage("mixed-free.png");
await modal6.getByText("混合占用卡").waitFor();
ok("mixed-free: live card listed with the invalid-reference note",
(await modal6.getByText(/另有 1 条已失效引用/).count()) === 1);
await modal6.getByRole("button", { name: "仅移除卡片" }).click();
await modal6.getByRole("button", { name: "确认仅移除" }).click();
await pause(1400);
// last live card released → only a dead reference remains: the direct
// delete must still be offered (invalid_total must not block it)
const freed = await modal6.getByText("当前没有画布卡片占用此文件了,现在可以删除。")
.waitFor({ timeout: 4000 }).then(() => true).catch(() => false);
ok("mixed-free: direct delete offered with only invalid refs left",
freed &&
(await modal6.getByRole("button", { name: "删除此文件" }).count()) === 1 &&
(await modal6.getByText(/另有 1 条已失效引用/).count()) === 1);
await p.screenshot({ path: `${OUT}/09-invalid-only-direct.png` });
if ((await modal6.getByRole("button", { name: "删除此文件" }).count()))
await modal6.getByRole("button", { name: "删除此文件" }).click();
await pause(1300);
ok("mixed-free: file really deleted, invalid refs don't resurrect",
/文件已删除/.test(await lastToast(p)) &&
!fs.existsSync(byName["mixed-free.png"]));
await usageModal(p).waitFor({ state: "detached", timeout: 4000 }).catch(() => {});
// ── 13. HEL-887 cross-200-batch delete with a kept file in the batch ─
await p.goto(WEB + "/library");
await p.getByRole("button", { name: /查看 running-held/ }).waitFor();
const remaining = (await (await fetch("http://127.0.0.1:18274/api/library/media")).json()).length;
await p.getByRole("button", { name: "选择本组" }).click();
await p.getByText(`已选 ${remaining}`, { exact: true }).waitFor();
ok("batch: 206-path selection crosses the 200-path chunk boundary",
remaining === 206);
await p.getByRole("button", { name: "删除", exact: true }).click();
await p.getByRole("dialog").getByRole("button", { name: "确认删除" }).click();
await pause(2200);
ok("batch: 205 files deleted across both chunks",
/已删除 205 个文件/.test(await lastToast(p)) &&
!fs.existsSync(byName["sel-000.png"]) && !fs.existsSync(byName["sel-204.png"]));
ok("batch: kept file stays checked after the cross-batch delete",
(await p.getByText("已选 1").count()) === 1 &&
fs.existsSync(byName["running-held.png"]));
report.batchSelection = await pickedPaths();
ok("batch: library lists only the kept file afterwards",
(await (await fetch("http://127.0.0.1:18274/api/library/media")).json()).length === 1);
await p.screenshot({ path: `${OUT}/10-final-library.png` });
await ctx.close();
await browser.close();
fs.writeFileSync(`${OUT}/report.json`, JSON.stringify(report, null, 2));
console.log(`HEL-884: ${report.checks.filter((c) => c.pass).length}/${report.checks.length} checks passed`);
if (report.checks.some((c) => !c.pass)) process.exit(1);
})().catch((e) => {
report.errors.push(String(e));
fs.writeFileSync(`${OUT}/report.json`, JSON.stringify(report, null, 2));
console.error(e);
process.exit(1);
});