- GET /api/library/media/usage: read-only occupancy report per file — every live canvas card with canvas title, project/session scope, and the real consequence of deleting that card (deletes_file / keep reason) - _path_on_canvas joins canvas: orphan nodes (canvas row gone, FK-cascade dead metadata) no longer count as occupancy; they are reported as invalid references with totals instead of blocking deletion - canvas deleteNode: keep_file=true release-only variant (card removed, file always preserved); artifact cards with a live pending/running job refuse deletion (409) so completion events cannot resurrect them - library UI: occupancy modal on kept(on_canvas) with locate / delete card (accurate impact text) / release-only actions, per-path free-file delete closing the loop, invalid-reference note, offset paging for large counts, library selection persisted across canvas round-trips - canvas UI: ?locate=<node> deep-link centers the card (computed viewport, no store.fitView — its nodes write-back looped the graph rebuild effect), gold ring highlight + dismiss, back-to-library chip - i18n keys for all 7 languages; e2e runner + 32-check real-browser regression on isolated data Co-authored-by: multica-agent <github@multica.ai>
227 lines
12 KiB
JavaScript
227 lines
12 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: [] };
|
|
const ok = (name, pass) => {
|
|
report.checks.push({ name, pass: !!pass });
|
|
assert(pass, name);
|
|
console.log("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);
|
|
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` });
|
|
|
|
await ctx.close();
|
|
await browser.close();
|
|
fs.writeFileSync(`${OUT}/report.json`, JSON.stringify(report, null, 2));
|
|
console.log(`HEL-884: ${report.checks.length} checks passed`);
|
|
})().catch((e) => {
|
|
report.errors.push(String(e));
|
|
fs.writeFileSync(`${OUT}/report.json`, JSON.stringify(report, null, 2));
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|