@open-qa/qa-studio 0.0.0-stage → 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +204 -0
- package/NOTICE +7 -0
- package/THIRD_PARTY.md +13 -0
- package/THIRD_PARTY_NOTICES.md +11 -0
- package/package.json +45 -4
- package/runtime/licenses/geist/LICENSE.txt +92 -0
- package/runtime/licenses/react/LICENSE +21 -0
- package/runtime/licenses/react-dom/LICENSE +21 -0
- package/runtime/standalone.tar.gz +0 -0
- package/scripts/demo-assets/README.md +3 -0
- package/scripts/demo-assets/after.png +0 -0
- package/scripts/demo-assets/before.png +0 -0
- package/scripts/demo-data.mjs +148 -0
- package/scripts/launch.mjs +155 -0
- package/scripts/manifest.mjs +100 -0
- package/scripts/multi-view-fixture.mjs +283 -0
- package/scripts/run-fixture.mjs +261 -0
- package/scripts/runtime-keys.mjs +71 -0
- package/scripts/unpack.mjs +21 -0
- package/src/files.mjs +66 -0
- package/src/launch-support.mjs +31 -0
- package/src/parent-watch.mjs +6 -0
- package/src/security.mjs +60 -0
- package/src/ui/SHADCN-LICENSE.txt +21 -0
- package/studio-manifest.json +1 -0
- package/README.md +0 -3
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { createServer } from "node:net";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import { readProject } from "../src/files.mjs";
|
|
9
|
+
import { createSession } from "../src/security.mjs";
|
|
10
|
+
import { unpack } from "./unpack.mjs";
|
|
11
|
+
import { protocol, verifyBuild } from "./manifest.mjs";
|
|
12
|
+
import { checkReady, waitForExit } from "../src/launch-support.mjs";
|
|
13
|
+
|
|
14
|
+
const appRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
15
|
+
async function availablePort(requested) {
|
|
16
|
+
const server = createServer();
|
|
17
|
+
await new Promise((resolve, reject) => {
|
|
18
|
+
server.once("error", reject);
|
|
19
|
+
server.listen(requested, "127.0.0.1", resolve);
|
|
20
|
+
});
|
|
21
|
+
const port = server.address().port;
|
|
22
|
+
await new Promise((resolve) => server.close(resolve));
|
|
23
|
+
return port;
|
|
24
|
+
}
|
|
25
|
+
let child;
|
|
26
|
+
let runtime;
|
|
27
|
+
let stopping = false;
|
|
28
|
+
async function stop() {
|
|
29
|
+
stopping = true;
|
|
30
|
+
if (!child?.pid || child.exitCode !== null || child.signalCode) return;
|
|
31
|
+
child.kill("SIGTERM");
|
|
32
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), 2000);
|
|
33
|
+
await waitForExit(child);
|
|
34
|
+
clearTimeout(timer);
|
|
35
|
+
}
|
|
36
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"])
|
|
37
|
+
process.on(signal, () => {
|
|
38
|
+
void stop();
|
|
39
|
+
});
|
|
40
|
+
if (process.channel) {
|
|
41
|
+
process.once("disconnect", () => void stop());
|
|
42
|
+
process.channel.unref();
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const { values } = parseArgs({
|
|
46
|
+
options: {
|
|
47
|
+
root: { type: "string" },
|
|
48
|
+
port: { type: "string" },
|
|
49
|
+
"no-open": { type: "boolean" },
|
|
50
|
+
"ready-timeout": { type: "string", default: "30000" },
|
|
51
|
+
dev: { type: "boolean" },
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const portNumber = Number(values.port ?? 0),
|
|
55
|
+
timeout = Number(values["ready-timeout"]);
|
|
56
|
+
if (
|
|
57
|
+
!Number.isInteger(portNumber) ||
|
|
58
|
+
portNumber < 0 ||
|
|
59
|
+
portNumber > 65535 ||
|
|
60
|
+
!Number.isInteger(timeout) ||
|
|
61
|
+
timeout < 1 ||
|
|
62
|
+
timeout > 300000
|
|
63
|
+
)
|
|
64
|
+
throw new Error("Invalid port or ready timeout");
|
|
65
|
+
if (values.dev) await (await import("./replay-runtime.mjs")).buildReplay(appRoot);
|
|
66
|
+
const manifest = values.dev
|
|
67
|
+
? { protocol, fingerprint: "development" }
|
|
68
|
+
: await verifyBuild(appRoot);
|
|
69
|
+
let project;
|
|
70
|
+
try {
|
|
71
|
+
project = await readProject(path.resolve(values.root ?? ".qa"));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new Error(`Cannot read project. ${error.message}`);
|
|
74
|
+
}
|
|
75
|
+
let port;
|
|
76
|
+
try {
|
|
77
|
+
port = await availablePort(portNumber);
|
|
78
|
+
} catch {
|
|
79
|
+
throw new Error("Studio port is unavailable. Choose another --port");
|
|
80
|
+
}
|
|
81
|
+
const config = {
|
|
82
|
+
...createSession(project.projectId),
|
|
83
|
+
...project,
|
|
84
|
+
port,
|
|
85
|
+
protocol,
|
|
86
|
+
fingerprint: manifest.fingerprint,
|
|
87
|
+
readyToken: randomBytes(32).toString("hex"),
|
|
88
|
+
};
|
|
89
|
+
const env = {
|
|
90
|
+
PATH: process.env.PATH,
|
|
91
|
+
NODE_ENV: values.dev ? "development" : "production",
|
|
92
|
+
HOSTNAME: "127.0.0.1",
|
|
93
|
+
PORT: String(port),
|
|
94
|
+
QA_STUDIO_SESSION: JSON.stringify(config),
|
|
95
|
+
NEXT_TELEMETRY_DISABLED: "1",
|
|
96
|
+
// Flow lifecycle states are read with SELECT only; no other database variable is forwarded.
|
|
97
|
+
...(process.env.QA_DATABASE_URL && { QA_DATABASE_URL: process.env.QA_DATABASE_URL }),
|
|
98
|
+
};
|
|
99
|
+
if (manifest.distribution) runtime = await unpack(appRoot);
|
|
100
|
+
const args = values.dev
|
|
101
|
+
? [
|
|
102
|
+
fileURLToPath(import.meta.resolve("next/dist/bin/next")),
|
|
103
|
+
"dev",
|
|
104
|
+
"--hostname",
|
|
105
|
+
"127.0.0.1",
|
|
106
|
+
"--port",
|
|
107
|
+
String(port),
|
|
108
|
+
]
|
|
109
|
+
: [runtime?.server ?? path.join(appRoot, ".next/standalone/apps/qa-studio/server.js")];
|
|
110
|
+
console.log("Starting Studio…");
|
|
111
|
+
const started = performance.now();
|
|
112
|
+
if (stopping) throw new Error("Studio startup cancelled");
|
|
113
|
+
child = spawn(
|
|
114
|
+
process.execPath,
|
|
115
|
+
["--import", path.join(appRoot, "src/parent-watch.mjs"), ...args],
|
|
116
|
+
{
|
|
117
|
+
cwd: appRoot,
|
|
118
|
+
env,
|
|
119
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
let childError = false;
|
|
123
|
+
child.on("error", () => {
|
|
124
|
+
childError = true;
|
|
125
|
+
});
|
|
126
|
+
const origin = `http://127.0.0.1:${port}`;
|
|
127
|
+
let ready = false;
|
|
128
|
+
while (!stopping && performance.now() - started < timeout) {
|
|
129
|
+
if (childError || child.exitCode !== null || child.signalCode)
|
|
130
|
+
throw new Error("Studio could not start. Check the port and rebuild Studio");
|
|
131
|
+
if (await checkReady(origin, config, timeout)) {
|
|
132
|
+
if (childError || child.exitCode !== null || child.signalCode)
|
|
133
|
+
throw new Error("Studio stopped during readiness handshake");
|
|
134
|
+
ready = true;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
138
|
+
}
|
|
139
|
+
if (!ready) {
|
|
140
|
+
if (!stopping)
|
|
141
|
+
throw new Error("Studio ready timeout. Rebuild or increase --ready-timeout <milliseconds>");
|
|
142
|
+
} else {
|
|
143
|
+
const url = `${origin}/session#${config.nonce}`;
|
|
144
|
+
console.log(`Studio ready in ${Math.round(performance.now() - started)} ms`);
|
|
145
|
+
console.log(url);
|
|
146
|
+
await waitForExit(child);
|
|
147
|
+
if (!stopping) throw new Error("Studio stopped unexpectedly");
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error(error instanceof Error ? error.message : "Studio could not start");
|
|
151
|
+
process.exitCode = 1;
|
|
152
|
+
} finally {
|
|
153
|
+
await stop();
|
|
154
|
+
await runtime?.cleanup();
|
|
155
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
export const protocol = 1;
|
|
6
|
+
export const buildInstruction = "Run the Studio workspace build command";
|
|
7
|
+
export async function fingerprint(appRoot) {
|
|
8
|
+
const repo = path.resolve(appRoot, "../..");
|
|
9
|
+
const hash = createHash("sha256");
|
|
10
|
+
async function visit(relative) {
|
|
11
|
+
const full = path.join(repo, relative);
|
|
12
|
+
const info = await stat(full);
|
|
13
|
+
if (info.isDirectory()) {
|
|
14
|
+
for (const entry of (await readdir(full)).sort()) {
|
|
15
|
+
if (
|
|
16
|
+
["node_modules", ".next", "docs", ".turbo"].includes(entry) ||
|
|
17
|
+
/\.(test|spec)\./.test(entry) ||
|
|
18
|
+
/\.(md|png|tsbuildinfo)$/.test(entry) ||
|
|
19
|
+
entry === "next-env.d.ts"
|
|
20
|
+
)
|
|
21
|
+
continue;
|
|
22
|
+
await visit(path.join(relative, entry));
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
hash.update(relative);
|
|
26
|
+
hash.update(await readFile(full));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (const entry of [
|
|
30
|
+
"apps/qa-studio/app",
|
|
31
|
+
"apps/qa-studio/src",
|
|
32
|
+
"apps/qa-studio/scripts/launch.mjs",
|
|
33
|
+
"apps/qa-studio/scripts/build.mjs",
|
|
34
|
+
"apps/qa-studio/scripts/replay-runtime.mjs",
|
|
35
|
+
"packages/qa-replay/src",
|
|
36
|
+
"packages/qa-replay/package.json",
|
|
37
|
+
"apps/qa-studio/scripts/manifest.mjs",
|
|
38
|
+
"apps/qa-studio/proxy.ts",
|
|
39
|
+
"apps/qa-studio/next.config.ts",
|
|
40
|
+
"apps/qa-studio/postcss.config.mjs",
|
|
41
|
+
"apps/qa-studio/package.json",
|
|
42
|
+
"apps/qa-studio/tsconfig.json",
|
|
43
|
+
"packages/tsconfig/nextjs.json",
|
|
44
|
+
"packages/tsconfig/base.json",
|
|
45
|
+
"packages/qa-inspect/src",
|
|
46
|
+
"packages/qa-inspect/package.json",
|
|
47
|
+
"packages/qa-engine/src",
|
|
48
|
+
"packages/qa-engine/package.json",
|
|
49
|
+
"pnpm-lock.yaml",
|
|
50
|
+
"pnpm-workspace.yaml",
|
|
51
|
+
])
|
|
52
|
+
await visit(entry);
|
|
53
|
+
return hash.digest("hex");
|
|
54
|
+
}
|
|
55
|
+
export async function verifyBuild(appRoot) {
|
|
56
|
+
let packaged;
|
|
57
|
+
try {
|
|
58
|
+
packaged = await readFile(path.join(appRoot, "studio-manifest.json"), "utf8");
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error.code !== "ENOENT") throw new Error("Cannot read Studio manifest");
|
|
61
|
+
if (existsSync(path.join(appRoot, "runtime/standalone.tar.gz")))
|
|
62
|
+
throw new Error("Studio distribution manifest is missing. Reinstall the matching artifact.");
|
|
63
|
+
}
|
|
64
|
+
if (packaged !== undefined) {
|
|
65
|
+
let manifest;
|
|
66
|
+
try {
|
|
67
|
+
manifest = JSON.parse(packaged);
|
|
68
|
+
if (!manifest || typeof manifest !== "object") throw new Error();
|
|
69
|
+
} catch {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"Studio distribution is incompatible or damaged. Reinstall the matching artifact."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const digest = createHash("sha256")
|
|
75
|
+
.update(await readFile(path.join(appRoot, "runtime/standalone.tar.gz")))
|
|
76
|
+
.digest("hex");
|
|
77
|
+
if (
|
|
78
|
+
manifest.distribution !== true ||
|
|
79
|
+
manifest.protocol !== protocol ||
|
|
80
|
+
manifest.fingerprint !== digest ||
|
|
81
|
+
manifest.platform !== process.platform ||
|
|
82
|
+
manifest.arch !== process.arch
|
|
83
|
+
)
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Studio distribution is incompatible or damaged. Reinstall the matching artifact."
|
|
86
|
+
);
|
|
87
|
+
return manifest;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const manifest = JSON.parse(
|
|
91
|
+
await readFile(path.join(appRoot, ".next/studio-manifest.json"), "utf8")
|
|
92
|
+
);
|
|
93
|
+
if (manifest.protocol !== protocol || manifest.fingerprint !== (await fingerprint(appRoot)))
|
|
94
|
+
throw new Error();
|
|
95
|
+
await stat(path.join(appRoot, ".next/standalone/apps/qa-studio/server.js"));
|
|
96
|
+
return manifest;
|
|
97
|
+
} catch {
|
|
98
|
+
throw new Error(`Studio build is missing or stale. ${buildInstruction}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { gzipSync } from "node:zlib";
|
|
5
|
+
|
|
6
|
+
/** Deterministic fake run: independent browser clocks, navigation, scroll and sparse cursors. */
|
|
7
|
+
export async function multiViewFixture(root, id = "multi") {
|
|
8
|
+
const directory = join(root, "runs", id),
|
|
9
|
+
stage = join(directory, "stage");
|
|
10
|
+
await mkdir(join(stage, "assets"), { recursive: true });
|
|
11
|
+
await writeFile(join(stage, "assets/index.json"), "{}");
|
|
12
|
+
const events = [
|
|
13
|
+
{
|
|
14
|
+
kind: "run_phase",
|
|
15
|
+
by: "conductor",
|
|
16
|
+
t: 0,
|
|
17
|
+
phase: "queued",
|
|
18
|
+
runtime: "codex",
|
|
19
|
+
modelAccess: "login",
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
const anchors = [],
|
|
23
|
+
views = [];
|
|
24
|
+
const descriptors = [
|
|
25
|
+
{ view: "alice.web", actor: "alice", type: "page", start: 50, offset: 0, base: 100000 },
|
|
26
|
+
{
|
|
27
|
+
view: "alice.email",
|
|
28
|
+
actor: "alice",
|
|
29
|
+
type: "rendered",
|
|
30
|
+
start: 600,
|
|
31
|
+
offset: 170,
|
|
32
|
+
base: 900000,
|
|
33
|
+
},
|
|
34
|
+
{ view: "bob.web", actor: "bob", type: "page", start: 1000, offset: 310, base: 500000 },
|
|
35
|
+
{ view: "observer", actor: null, type: "page", start: 1500, offset: 500, base: 1200000 },
|
|
36
|
+
];
|
|
37
|
+
const text = (id, textContent) => ({ id, type: 3, textContent });
|
|
38
|
+
const element = (id, tagName, attributes = {}, childNodes = []) => ({
|
|
39
|
+
id,
|
|
40
|
+
type: 2,
|
|
41
|
+
tagName,
|
|
42
|
+
attributes,
|
|
43
|
+
childNodes,
|
|
44
|
+
});
|
|
45
|
+
for (const d of descriptors) {
|
|
46
|
+
const dir = join(stage, "views", d.view);
|
|
47
|
+
await mkdir(dir, { recursive: true });
|
|
48
|
+
if (d.actor)
|
|
49
|
+
events.push({
|
|
50
|
+
kind: "view_opened",
|
|
51
|
+
by: "conductor",
|
|
52
|
+
t: d.start - 20,
|
|
53
|
+
actor: d.actor,
|
|
54
|
+
view: d.view,
|
|
55
|
+
type: d.type,
|
|
56
|
+
url: "https://fixture.invalid/clock",
|
|
57
|
+
});
|
|
58
|
+
const anchor = {
|
|
59
|
+
kind: "record_started",
|
|
60
|
+
by: "conductor",
|
|
61
|
+
t: d.start,
|
|
62
|
+
view: d.view,
|
|
63
|
+
format: "rrweb",
|
|
64
|
+
index: `views/${d.view}/index.json`,
|
|
65
|
+
};
|
|
66
|
+
events.push(anchor);
|
|
67
|
+
anchors.push({ ...anchor, t: d.start - d.offset });
|
|
68
|
+
const index = { schemaVersion: 1, view: d.view, calibrations: [], checkpoints: [], blocks: [] };
|
|
69
|
+
let seq = 0,
|
|
70
|
+
chunk = 0;
|
|
71
|
+
const end = d.actor ? 30000 : 24000;
|
|
72
|
+
for (let cp = d.start; cp < end; cp += 5000) {
|
|
73
|
+
const base = cp < 15000 ? d.base + cp : d.base - 70000 + cp;
|
|
74
|
+
const doc = cp < 15000 ? "before" : "after";
|
|
75
|
+
index.calibrations.push({ document: doc, seq: seq + 1, browserTime: base, t: cp - d.offset });
|
|
76
|
+
const row = (t, type, data) => ({
|
|
77
|
+
seq: ++seq,
|
|
78
|
+
t: t - d.offset,
|
|
79
|
+
view: d.view,
|
|
80
|
+
event: { type, timestamp: base + t - cp, data },
|
|
81
|
+
});
|
|
82
|
+
const scroll = cp >= 10000 ? 320 : 0;
|
|
83
|
+
const snapshots = [
|
|
84
|
+
row(cp, 4, { href: "https://fixture.invalid/clock", width: 800, height: 460 }),
|
|
85
|
+
row(cp + 1, 2, {
|
|
86
|
+
initialOffset: { top: 0, left: 0 },
|
|
87
|
+
node: {
|
|
88
|
+
type: 0,
|
|
89
|
+
id: 1,
|
|
90
|
+
childNodes: [
|
|
91
|
+
element(2, "html", {}, [
|
|
92
|
+
element(3, "head", {}, [
|
|
93
|
+
element(4, "style", {}, [
|
|
94
|
+
text(
|
|
95
|
+
5,
|
|
96
|
+
"body{margin:0;padding:28px;font:18px system-ui;background:#f4f5f7;color:#20242a}h1{font-size:28px}#clock{font:42px monospace}#scroll{height:120px;overflow:auto;border:1px solid #aaa;border-radius:8px;padding:12px;background:white}"
|
|
97
|
+
),
|
|
98
|
+
]),
|
|
99
|
+
]),
|
|
100
|
+
element(6, "body", {}, [
|
|
101
|
+
element(7, "h1", {}, [text(8, d.view)]),
|
|
102
|
+
element(9, "p", {}, [text(10, "Run clock")]),
|
|
103
|
+
element(11, "output", { id: "clock" }, [text(12, String(cp))]),
|
|
104
|
+
element(13, "div", { id: "scroll", rr_scrollTop: scroll }, [
|
|
105
|
+
element(14, "div", { style: "height:700px" }, [
|
|
106
|
+
text(15, "Recorded scroll region"),
|
|
107
|
+
]),
|
|
108
|
+
]),
|
|
109
|
+
element(16, "script", {}, [
|
|
110
|
+
text(17, 'window.pwned=true;top.location="https://escape.invalid"'),
|
|
111
|
+
]),
|
|
112
|
+
element(18, "img", {
|
|
113
|
+
src: "https://exfil.invalid/private",
|
|
114
|
+
alt: "",
|
|
115
|
+
onerror: "window.pwned=true",
|
|
116
|
+
}),
|
|
117
|
+
]),
|
|
118
|
+
]),
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
}),
|
|
122
|
+
];
|
|
123
|
+
const checkpoint = {
|
|
124
|
+
meta: { block: `${String(chunk + 1).padStart(6, "0")}.ndjson.gz`, seq: snapshots[0].seq },
|
|
125
|
+
snapshot: {
|
|
126
|
+
block: `${String(chunk + 1).padStart(6, "0")}.ndjson.gz`,
|
|
127
|
+
seq: snapshots[1].seq,
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
index.checkpoints.push(checkpoint);
|
|
131
|
+
const updates = [];
|
|
132
|
+
for (let t = cp + 50; t < Math.min(cp + 5000, end); t += 50) {
|
|
133
|
+
updates.push(
|
|
134
|
+
row(t, 3, {
|
|
135
|
+
source: 0,
|
|
136
|
+
texts: [{ id: 12, value: String(t) }],
|
|
137
|
+
attributes: [],
|
|
138
|
+
adds: [],
|
|
139
|
+
removes: [],
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
if (d.view === "alice.web" && (t - cp) % 500 === 0)
|
|
143
|
+
updates.push(
|
|
144
|
+
row(t, 3, {
|
|
145
|
+
source: 1,
|
|
146
|
+
positions: [{ x: 80 + (t % 2000) / 10, y: 160, id: 11, timeOffset: 0 }],
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
if (t === d.start + 10050) updates.push(row(t, 3, { source: 3, id: 13, x: 0, y: 320 }));
|
|
150
|
+
}
|
|
151
|
+
for (const rows of [snapshots, updates]) {
|
|
152
|
+
const raw = Buffer.from(rows.map((r) => JSON.stringify(r)).join("\n") + "\n"),
|
|
153
|
+
bytes = gzipSync(raw),
|
|
154
|
+
path = `${String(++chunk).padStart(6, "0")}.ndjson.gz`;
|
|
155
|
+
await writeFile(join(dir, path), bytes);
|
|
156
|
+
index.blocks.push({
|
|
157
|
+
path,
|
|
158
|
+
bytes: bytes.length,
|
|
159
|
+
rawBytes: raw.length,
|
|
160
|
+
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
161
|
+
seq: { first: rows[0].seq, last: rows.at(-1).seq },
|
|
162
|
+
t: { first: rows[0].t, last: rows.at(-1).t },
|
|
163
|
+
timestamp: { first: rows[0].event.timestamp, last: rows.at(-1).event.timestamp },
|
|
164
|
+
checkpoint,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
await writeFile(join(dir, "index.json"), JSON.stringify(index));
|
|
169
|
+
views.push({
|
|
170
|
+
view: d.view,
|
|
171
|
+
index: `views/${d.view}/index.json`,
|
|
172
|
+
browser: "chromium",
|
|
173
|
+
viewport: { width: 800, height: 460 },
|
|
174
|
+
segments: [{ document: "before", firstSeq: 1, lastSeq: seq, missing: [] }],
|
|
175
|
+
});
|
|
176
|
+
if (!d.actor) events.push({ kind: "view_closed", by: "conductor", t: end, view: d.view });
|
|
177
|
+
if (d.actor)
|
|
178
|
+
for (const [t, x] of [
|
|
179
|
+
[2000, 80],
|
|
180
|
+
[4000, 280],
|
|
181
|
+
[6000, 160],
|
|
182
|
+
])
|
|
183
|
+
events.push({
|
|
184
|
+
kind: "action",
|
|
185
|
+
by: "agent",
|
|
186
|
+
actor: d.actor,
|
|
187
|
+
view: d.view,
|
|
188
|
+
t,
|
|
189
|
+
tool: "web_click",
|
|
190
|
+
args: {},
|
|
191
|
+
ok: true,
|
|
192
|
+
ms: 0,
|
|
193
|
+
target:
|
|
194
|
+
d.actor === "bob"
|
|
195
|
+
? {
|
|
196
|
+
layer: "pixel",
|
|
197
|
+
x: x * 2,
|
|
198
|
+
y: 360,
|
|
199
|
+
viewport: { width: 800, height: 460 },
|
|
200
|
+
image: { width: 1600, height: 920 },
|
|
201
|
+
path: [],
|
|
202
|
+
}
|
|
203
|
+
: { layer: "semantic", point: { x, y: 180 } },
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
events.push(
|
|
207
|
+
{ kind: "step_started", by: "conductor", actor: "alice", step: "review-order", t: 1800 },
|
|
208
|
+
{ kind: "step_started", by: "conductor", actor: "bob", step: "confirm-delivery", t: 1900 },
|
|
209
|
+
{
|
|
210
|
+
kind: "expect_result",
|
|
211
|
+
by: "conductor",
|
|
212
|
+
actor: "bob",
|
|
213
|
+
step: "confirm-delivery",
|
|
214
|
+
view: "bob.web",
|
|
215
|
+
t: 18100,
|
|
216
|
+
condition: { type: "web.visible", text: "Delivered" },
|
|
217
|
+
result: { passed: false, evidence: {}, reason: "Delivery confirmation missing" },
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
kind: "step_finished",
|
|
221
|
+
by: "conductor",
|
|
222
|
+
actor: "bob",
|
|
223
|
+
step: "confirm-delivery",
|
|
224
|
+
t: 18125,
|
|
225
|
+
status: "failed",
|
|
226
|
+
reason: "Delivery confirmation missing",
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
kind: "step_finished",
|
|
230
|
+
by: "conductor",
|
|
231
|
+
actor: "alice",
|
|
232
|
+
step: "review-order",
|
|
233
|
+
t: 20000,
|
|
234
|
+
status: "passed",
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
kind: "run_finished",
|
|
238
|
+
by: "conductor",
|
|
239
|
+
t: 30000,
|
|
240
|
+
verdict: "failed",
|
|
241
|
+
reason: "Delivery confirmation missing",
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
events.sort((a, b) => a.t - b.t);
|
|
245
|
+
const rows = events.map((e, i) => ({ ...e, seq: i + 1 })),
|
|
246
|
+
log = rows.map((e) => JSON.stringify(e)).join("\n") + "\n";
|
|
247
|
+
anchors.sort((a, b) => a.t - b.t);
|
|
248
|
+
await writeFile(
|
|
249
|
+
join(stage, "events.ndjson"),
|
|
250
|
+
anchors.map((e, i) => JSON.stringify({ ...e, seq: i + 1 })).join("\n") + "\n"
|
|
251
|
+
);
|
|
252
|
+
await writeFile(
|
|
253
|
+
join(stage, "manifest.json"),
|
|
254
|
+
JSON.stringify({
|
|
255
|
+
schemaVersion: 1,
|
|
256
|
+
format: "rrweb",
|
|
257
|
+
recorder: { name: "@rrweb/record", version: "2.1.7" },
|
|
258
|
+
player: { name: "@rrweb/replay", version: "2.1.7" },
|
|
259
|
+
assets: "assets/index.json",
|
|
260
|
+
views,
|
|
261
|
+
warnings: [],
|
|
262
|
+
})
|
|
263
|
+
);
|
|
264
|
+
await writeFile(join(directory, "events.ndjson"), log);
|
|
265
|
+
await writeFile(
|
|
266
|
+
join(directory, "run.json"),
|
|
267
|
+
JSON.stringify({
|
|
268
|
+
run: { id, flow: "Multi-view delivery", startedAt: 1792978200000 },
|
|
269
|
+
eventIndex: {
|
|
270
|
+
bytes: Buffer.byteLength(log),
|
|
271
|
+
count: rows.length,
|
|
272
|
+
lastSeq: rows.length,
|
|
273
|
+
lastT: 30000,
|
|
274
|
+
},
|
|
275
|
+
result: {
|
|
276
|
+
verdict: "failed",
|
|
277
|
+
finishedAt: 1792978230000,
|
|
278
|
+
reason: "Delivery confirmation missing",
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
);
|
|
282
|
+
return { directory, stage, descriptors };
|
|
283
|
+
}
|