Repository navigation
Expand file tree
/
Copy pathqa-editor-package-upgrade.mts
More file actions
394 lines (391 loc) · 14 KB
/
Copy pathqa-editor-package-upgrade.mts
File metadata and controls
394 lines (391 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
// Real host + browser acceptance using only synthetic accounts and in-memory data.
import assert from "node:assert/strict";
import { randomBytes } from "node:crypto";
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { setTimeout as delay } from "node:timers/promises";
import { createServer } from "vite";
import { chromium, type Page } from "playwright-core";
import sharp from "sharp";
import { projectExlsxWorkbook } from "@smartdoca/sheet/model";
import { openDatabase } from "../packages/db/src/index.js";
import { createUser } from "../packages/core/src/modules/identity/passwords.js";
const root = await mkdtemp(join(tmpdir(), "doca-editor-upgrade-"));
process.env.DOCA_CREDENTIAL_MASTER_KEY = randomBytes(32).toString("hex");
process.env.DOCA_FILE_STORE_ID = "local";
process.env.DOCA_FILE_STORES_JSON = JSON.stringify({
version: 1,
stores: { local: { provider: "local", root } },
});
const { createApp } = await import("../apps/server/src/app/create-app.js");
const { storageRuntime } =
await import("../apps/server/src/adapters/storage.js");
const db = await openDatabase({ driver: "sqlite", path: ":memory:" });
await createUser(
db,
{
login: "editorupgrade",
displayName: "Editor upgrade QA",
password: "isolated-editor-upgrade-2026",
},
{ bootstrap: true },
);
const origin = "http://127.0.0.1:39418";
const app = await createApp(db, {
origin,
storage: { ...storageRuntime(), root },
ai: { memory: { driver: "sqlite", url: ":memory:" } },
});
await app.listen({ host: "127.0.0.1", port: 0 });
const address = app.server.address();
assert(address && typeof address !== "string");
const web = await createServer({
configFile: resolve("apps/web/vite.config.ts"),
server: {
host: "127.0.0.1",
port: 39418,
strictPort: true,
proxy: { "/api": { target: `http://127.0.0.1:${address.port}`, ws: true } },
},
});
const output = resolve(
process.env.DOCA_QA_OUTPUT ?? "artifacts/editor-package-upgrade-2026-10-16",
);
await mkdir(output, { recursive: true });
const checks: string[] = [],
errors: string[] = [];
const pass = (label: string) => {
checks.push(label);
console.log("PASS " + label);
};
const until = async (predicate: () => Promise<boolean>, label: string) => {
for (let n = 0; n < 100; n++) {
if (await predicate()) return;
await delay(100);
}
throw Error("Timed out: " + label);
};
let diagnosticPage: Page | undefined;
await web.listen();
const browser = await chromium.launch({
channel: "chrome",
headless: true,
args: [
"--disable-background-timer-throttling",
"--disable-renderer-backgrounding",
"--disable-backgrounding-occluded-windows",
],
});
try {
const context = await browser.newContext({
viewport: { width: 1600, height: 1000 },
});
const request = async (path: string, data?: unknown, method = "GET") => {
const response = await context.request.fetch(origin + "/api/v1" + path, {
method,
headers: { origin },
data,
});
assert.equal(response.status(), 200, await response.text());
return response.json();
};
const preview = async (id: string) => {
const data = await request(`/ai/resources/${id}/preview`);
if (data.resource.format === "spreadsheet")
data.value = await projectExlsxWorkbook({
baseline: data.surface.baseline,
update: new Uint8Array(Buffer.from(data.surface.update, "base64")),
checkpointSeq: 0,
});
const state = await db
.selectFrom("document_states")
.select("seq")
.where("resource_id", "=", id)
.executeTakeFirstOrThrow();
return { ...data, seq: state.seq };
};
await request(
"/auth/login",
{ login: "editorupgrade", password: "isolated-editor-upgrade-2026" },
"POST",
);
const watch = async () => {
const page = await context.newPage(),
updates: unknown[] = [];
page.on("pageerror", (error) => errors.push(error.message));
page.on("websocket", (socket) =>
socket.on("framesent", ({ payload }) => {
try {
const frame = JSON.parse(String(payload));
if (frame.type === "update") updates.push(frame);
} catch {}
}),
);
return { page, updates };
};
const rich = await request(
"/resources",
{ title: "Native rotation QA", kind: "document", format: "rich_text" },
"POST",
);
const a = await watch(),
peer = await watch();
diagnosticPage = a.page;
await a.page.goto(origin + "/#/r/" + rich.id);
await peer.page.goto(origin + "/#/r/" + rich.id);
const editor = a.page.locator('.sk-editable[contenteditable="true"]');
await editor.waitFor();
await peer.page.locator(".sk-editable").waitFor();
await a.page.bringToFront();
await editor.click();
await a.page.keyboard.press("End");
await a.page.keyboard.press("Enter");
const insert = a.page
.locator(".editor-fixed-toolbar")
.getByRole("button", { name: "流程图", exact: true });
if (!(await insert.isVisible()))
await a.page.locator(".toolbar-overflow > summary").click();
await insert.click();
await a.page.locator(".sk-block-flowchart img").waitFor();
await peer.page.locator(".sk-block-flowchart img").waitFor();
await a.page
.getByText("已保存到云端", { exact: true })
.waitFor({ state: "attached" });
await a.page
.locator(".sk-block-flowchart")
.getByRole("button", { name: "编辑流程图", exact: true })
.click();
const dialog = a.page.locator(".sk-diagram-dialog");
await dialog.waitFor();
const node = dialog.locator(".sk-x6-canvas .x6-node").first();
await node.click();
const nodeId = await node.getAttribute("data-cell-id");
assert(nodeId);
await dialog.getByRole("tab", { name: "排列", exact: true }).click();
await dialog.getByLabel("旋转角度(°)", { exact: true }).fill("30");
await dialog.getByLabel("旋转角度(°)", { exact: true }).press("Control+s");
await a.page.screenshot({ path: join(output, "rotation-editor.png") });
console.log("Saved a focused native rotation draft with Control+S");
await a.page.bringToFront();
await dialog.waitFor({ state: "hidden" });
await until(
async () =>
(await preview(rich.id)).value.some(
(block: any) =>
block.type === "flowchart" &&
block.nodes.some((n: any) => n.id === nodeId && n.angle === 30),
),
"rotation commit",
);
await a.page
.getByText("已保存到云端", { exact: true })
.waitFor({ state: "attached" });
await peer.page.bringToFront();
await peer.page
.locator(".sk-block-flowchart")
.getByRole("button", { name: "编辑流程图", exact: true })
.click();
const peerDialog = peer.page.locator(".sk-diagram-dialog");
await peerDialog
.locator(`.sk-x6-canvas .x6-node[data-cell-id="${nodeId}"]`)
.click();
await peerDialog.getByRole("tab", { name: "排列", exact: true }).click();
assert.equal(
await peerDialog.getByLabel("旋转角度(°)", { exact: true }).inputValue(),
"30",
);
// Cancel closes view state without introducing a second diagram commit.
await peerDialog
.getByRole("button", { name: "关闭图示编辑器", exact: true })
.click();
await peerDialog.waitFor({ state: "detached" });
assert.equal(peer.updates.length, 0, "Remote rotation echoed a write");
pass(
"native rotation persists through host ACK and reaches a same-user peer without echo",
);
await a.page.bringToFront();
await a.page.reload();
await editor.waitFor();
await a.page
.locator(".sk-block-flowchart")
.getByRole("button", { name: "编辑流程图", exact: true })
.click();
await dialog
.locator(`.sk-x6-canvas .x6-node[data-cell-id="${nodeId}"]`)
.click();
await dialog.getByRole("tab", { name: "排列", exact: true }).click();
assert.equal(
await dialog.getByLabel("旋转角度(°)", { exact: true }).inputValue(),
"30",
);
const paperWidth = await dialog
.locator(".sk-draw-paper")
.evaluate((el) => el.getBoundingClientRect().width);
await dialog.getByLabel("左", { exact: true }).fill("2000");
await dialog.getByLabel("左", { exact: true }).press("Enter");
await until(
async () =>
(await dialog
.locator(".sk-draw-paper")
.evaluate((el) => el.getBoundingClientRect().width)) > paperWidth,
"native paper expands with moved node",
);
await dialog.getByLabel("旋转角度(°)", { exact: true }).fill("45");
await dialog.getByLabel("旋转角度(°)", { exact: true }).press("Meta+s");
await dialog.waitFor({ state: "detached" });
await until(
async () =>
(await preview(rich.id)).value.some(
(block: any) =>
block.type === "flowchart" &&
block.nodes.some(
(n: any) => n.id === nodeId && n.angle === 45 && n.x === 2000,
),
),
"Meta+S commits the focused draft",
);
pass(
"reload retains rotation; native paper expands and Meta+S commits focused drafts",
);
await editor.locator(".sk-block-paragraph").last().click();
await a.page.keyboard.press("End");
await a.page.keyboard.press("Enter");
const image = await sharp({
create: { width: 160, height: 90, channels: 3, background: "#3b82f6" },
})
.png()
.toBuffer();
await a.page
.locator('.editor-fixed-toolbar input[type="file"]')
.setInputFiles({
name: "isolated-image.png",
mimeType: "image/png",
buffer: image,
});
await a.page.locator(".sk-image img").waitFor();
await until(
async () =>
(await preview(rich.id)).value.some(
(block: any) => block.type === "image" && block.path,
),
"image upload",
);
await a.page
.getByText("已保存到云端", { exact: true })
.waitFor({ state: "attached" });
const figure = a.page.locator(".sk-image");
await editor.locator(".sk-block-paragraph").first().click();
await figure.locator("img").click();
assert.equal(await a.page.locator(".sk-media-lightbox").count(), 0);
await figure.locator("img").click();
await a.page.locator(".sk-media-lightbox").waitFor();
await a.page.keyboard.press("Escape");
await a.page.locator(".sk-media-lightbox").waitFor({ state: "detached" });
await editor.locator(".sk-block-paragraph").first().click();
await figure.locator("img").click();
assert.equal(await a.page.locator(".sk-media-lightbox").count(), 0);
pass(
"host-authorized image selects first, previews second and resets selection after an outside click",
);
await a.page.screenshot({ path: join(output, "rich-host.png") });
const sheet = await request(
"/resources",
{ title: "Select-all QA", kind: "document", format: "spreadsheet" },
"POST",
);
const s = await watch();
diagnosticPage = s.page;
await s.page.goto(origin + "/#/r/" + sheet.id);
const corner = s.page.locator(".uos-editor__select-all");
await corner.waitFor();
const original = await preview(sheet.id),
first = original.value.sheetOrder[0];
assert.equal(original.value.sheets[first].defaultRowHeight, 19.8);
assert.equal(original.value.sheets[first].defaultColumnWidth, 79.2);
const box = await corner.boundingBox();
assert(box);
await s.page.mouse.dblclick(box.x + box.width + 36, box.y + box.height + 9);
await s.page.keyboard.insertText("表格升级验收");
await s.page.keyboard.press("Enter");
await until(
async () =>
JSON.stringify(
(await preview(sheet.id)).value.sheets[first].cellData,
).includes("表格升级验收"),
"native cell edit",
);
await s.page
.getByText("已保存到云端", { exact: true })
.waitFor({ state: "attached" });
const sheetBefore = await preview(sheet.id),
sheetWrites = s.updates.length;
await corner.click();
// A huge ALL selection would stall this interaction/statistics pass.
await s.page
.getByRole("combobox", { name: "文档模式", exact: true })
.click({ timeout: 5000 });
await s.page.getByRole("option", { name: "阅读", exact: true }).click();
await corner.click();
await s.page.setViewportSize({ width: 1440, height: 900 });
await s.page.screenshot({
path: join(output, "sheet-readonly-select-all.png"),
});
await s.page.getByRole("combobox", { name: "文档模式", exact: true }).click();
await s.page.getByRole("option", { name: "编辑", exact: true }).click();
assert.deepEqual((await preview(sheet.id)).value, sheetBefore.value);
assert.equal(s.updates.length, sheetWrites);
pass(
"native select-all remains responsive in edit/readonly mode and keeps worksheet content unchanged",
);
await s.page.reload();
await corner.waitFor();
assert.deepEqual((await preview(sheet.id)).value, sheetBefore.value);
pass("new 19.8/79.2 dimensions and edited cells survive host reload");
const richBefore = await preview(rich.id),
idleSheet = await preview(sheet.id);
const counts = [a.updates.length, peer.updates.length, s.updates.length];
await corner.click();
await a.page.locator(".sk-diagram-figure").click();
for (let n = 0; n < 2; n++) {
await delay(30_000);
console.log("Idle observation " + (n + 1) * 30 + " seconds");
}
assert.deepEqual(
[a.updates.length, peer.updates.length, s.updates.length],
counts,
);
assert.equal((await preview(rich.id)).seq, richBefore.seq);
assert.equal((await preview(sheet.id)).seq, idleSheet.seq);
assert.deepEqual(errors, []);
pass(
"60 seconds of idle, selection and resize produces zero rich-text/spreadsheet writes or peer echo",
);
await writeFile(
join(output, "browser.json"),
JSON.stringify(
{ result: "passed", checks, errors, idleSeconds: 60 },
null,
2,
) + "\n",
);
} catch (error) {
await diagnosticPage
?.screenshot({ path: join(output, "browser-failure.png"), fullPage: true })
.catch(() => {});
await writeFile(
join(output, "browser.json"),
JSON.stringify(
{ result: "failed", checks, errors, failure: String(error) },
null,
2,
) + "\n",
);
throw error;
} finally {
await browser.close();
await web.close();
await app.close();
await db.destroy();
await rm(root, { recursive: true, force: true });
}