roamwright 0.61.21 → 0.61.23
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/examples/fliers.html +1 -0
- package/examples/fliers.js +41 -1
- package/examples/town-fittings.js +17 -8
- package/geometry/crawl-shapes.js +86 -1
- package/geometry/crawler-giant-spider.js +100 -0
- package/geometry/harbour-kit.js +178 -8
- package/geometry/plant-garden.js +88 -0
- package/geometry/road-bridges.js +74 -0
- package/geometry/town-garden.js +3 -44
- package/index.js +18 -4
- package/motion/crawler-pack.js +110 -0
- package/package.json +1 -1
- package/rendering/crawler-pack.js +91 -0
- package/scripts/bundle.mjs +17 -5
- package/scripts/vendor.mjs +209 -36
- package/tools/README.md +34 -25
- package/tools/cpu-profile.cjs +117 -0
- package/tools/cpu-profile.test.cjs +31 -1
- package/tools/figure-inspect.cjs +475 -0
- package/tools/figure-inspect.test.cjs +153 -0
- package/tools/geometry-hash.cjs +361 -0
- package/tools/geometry-hash.test.cjs +146 -0
- package/tools/load-audit.cjs +199 -2
- package/tools/load-audit.test.cjs +68 -0
- package/tools/quiet-bench.cjs +202 -0
- package/tools/quiet-bench.test.cjs +91 -0
- package/tools/scene-detail.cjs +355 -0
- package/tools/scene-detail.test.cjs +162 -0
- package/tools/scrub-clear.cjs +191 -0
- package/tools/scrub-clear.test.cjs +100 -0
- package/tools/tree-inspect.cjs +271 -0
- package/tools/tree-inspect.test.cjs +123 -0
- package/tools/world-tour.cjs +223 -0
- package/tools/world-tour.test.cjs +77 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// Multi-land, interior, and scene smoke tour runner built on a Roamwright page driver.
|
|
2
|
+
// Visits configured lands, interior visions, and scenes in one browser session, printing page and console errors
|
|
3
|
+
// tagged with the stage where they happened.
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Normalizes tour runner options with defaults.
|
|
8
|
+
*
|
|
9
|
+
* @param {object} [options]
|
|
10
|
+
* @param {Array<object>} [options.stops=[]] Ordered tour steps (`enter`, `visions`, `sceneIndex`, `sceneMatch`).
|
|
11
|
+
* @param {number} [options.timeoutSeconds=7200] Maximum run time before the driver aborts.
|
|
12
|
+
* @param {{ width: number, height: number }} [options.viewport]
|
|
13
|
+
* @returns {{ stops: Array<object>, timeoutSeconds: number, viewport: { width: number, height: number } }}
|
|
14
|
+
*/
|
|
15
|
+
function parseTourOptions({ stops = [], timeoutSeconds = 7200, viewport = { width: 1280, height: 720 } } = {}) {
|
|
16
|
+
if (!Array.isArray(stops)) throw new Error('world-tour: stops must be an array');
|
|
17
|
+
return {
|
|
18
|
+
stops,
|
|
19
|
+
timeoutSeconds: +timeoutSeconds || 7200,
|
|
20
|
+
viewport: { width: +viewport.width || 1280, height: +viewport.height || 720 },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether the page is in play mode inside the requested space id.
|
|
26
|
+
* Passed to `page.waitForFunction`; must remain self-contained.
|
|
27
|
+
*
|
|
28
|
+
* @param {{ debug: string, spaceId: string }} arg
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
31
|
+
function waitSpaceInPage({ debug, spaceId }) {
|
|
32
|
+
const app = window[debug];
|
|
33
|
+
return !!(app && app.space && app.space.id === spaceId && app.state.mode === 'play');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Enters a vision/interior space by id.
|
|
38
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
39
|
+
*
|
|
40
|
+
* @param {{ debug: string, id: string }} arg
|
|
41
|
+
*/
|
|
42
|
+
function enterVisionInPage({ debug, id }) {
|
|
43
|
+
window[debug].enterVision(id);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Leaves the current vision/interior space back to the parent world.
|
|
48
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
49
|
+
*
|
|
50
|
+
* @param {{ debug: string }} arg
|
|
51
|
+
*/
|
|
52
|
+
function leaveVisionInPage({ debug }) {
|
|
53
|
+
window[debug].leaveVision();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Starts a catalog event scene either by 1-based index or by matching space/book/title/where substrings.
|
|
58
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
59
|
+
*
|
|
60
|
+
* @param {{ debug: string, index?: number, space?: string, book?: number, titleIncludes?: string, textIncludes?: string }} arg
|
|
61
|
+
*/
|
|
62
|
+
function startTourSceneInPage({ debug, index, space, book, titleIncludes, textIncludes }) {
|
|
63
|
+
const app = window[debug];
|
|
64
|
+
const events = app.CONFIG.events;
|
|
65
|
+
const ev =
|
|
66
|
+
index !== undefined
|
|
67
|
+
? events[index - 1]
|
|
68
|
+
: events.find(e => {
|
|
69
|
+
if (space !== undefined && e.space !== space) return false;
|
|
70
|
+
if (book !== undefined && e.book !== book) return false;
|
|
71
|
+
if (titleIncludes && !String(e.title || '').includes(titleIncludes)) return false;
|
|
72
|
+
if (textIncludes && !`${e.title || ''} ${e.where || ''}`.includes(textIncludes)) return false;
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
if (!ev) throw new Error(`world-tour: no scene matched ${JSON.stringify({ index, space, book, titleIncludes, textIncludes })}`);
|
|
76
|
+
app.startScene(ev, true);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Checks whether the scene director has reached past `minTime` seconds.
|
|
81
|
+
* Passed to `page.waitForFunction`; must remain self-contained.
|
|
82
|
+
*
|
|
83
|
+
* @param {{ debug: string, minTime: number }} arg
|
|
84
|
+
* @returns {boolean}
|
|
85
|
+
*/
|
|
86
|
+
function waitSceneTimeInPage({ debug, minTime }) {
|
|
87
|
+
const app = window[debug];
|
|
88
|
+
return !!(app && app.director && app.director.ev && app.director.t > minTime);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Ends the currently playing scene.
|
|
93
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
94
|
+
*
|
|
95
|
+
* @param {{ debug: string }} arg
|
|
96
|
+
*/
|
|
97
|
+
function endTourSceneInPage({ debug }) {
|
|
98
|
+
window[debug].endScene();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Reads the active scene title from the scene director.
|
|
103
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
104
|
+
*
|
|
105
|
+
* @param {{ debug: string }} arg
|
|
106
|
+
* @returns {string}
|
|
107
|
+
*/
|
|
108
|
+
function readTourTitleInPage({ debug }) {
|
|
109
|
+
return window[debug].director.ev.title;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Reads the step durations from `loadTimes`.
|
|
114
|
+
* Passed to `page.evaluate`; must remain self-contained.
|
|
115
|
+
*
|
|
116
|
+
* @param {{ debug: string }} arg
|
|
117
|
+
* @returns {number[]}
|
|
118
|
+
*/
|
|
119
|
+
function readTourLoadTimesInPage({ debug }) {
|
|
120
|
+
return window[debug].loadTimes.map(x => x[1]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Runs a configured multi-land, interior, and scene smoke tour through a Roamwright page driver.
|
|
125
|
+
*
|
|
126
|
+
* @param {object} driver Page driver from `createPageDriver`.
|
|
127
|
+
* @param {object} [options] Tour options (`stops`, `timeoutSeconds`, `viewport`).
|
|
128
|
+
* @returns {Promise<{ errors: string[] }>}
|
|
129
|
+
*/
|
|
130
|
+
async function runWorldTour(driver, options = {}) {
|
|
131
|
+
const { stops, timeoutSeconds, viewport } = parseTourOptions(options);
|
|
132
|
+
driver.longRun(timeoutSeconds);
|
|
133
|
+
const debug = driver.debug;
|
|
134
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
135
|
+
const page = await browser.newPage({ viewport });
|
|
136
|
+
const errs = new Set();
|
|
137
|
+
const seen = new Set();
|
|
138
|
+
let stage = 'start';
|
|
139
|
+
page.on('pageerror', e => {
|
|
140
|
+
const k = e.message.slice(0, 60);
|
|
141
|
+
if (!seen.has(k)) {
|
|
142
|
+
seen.add(k);
|
|
143
|
+
console.log('PAGE ERROR at stage', stage, '\n', (e.stack || '').split('\n').slice(0, 6).join('\n'));
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
page.on('console', m => {
|
|
147
|
+
if (m.type() === 'error') errs.add('console ' + m.text().slice(0, 200));
|
|
148
|
+
});
|
|
149
|
+
const enterLand = async address => {
|
|
150
|
+
await driver.enter(page, driver.routeUrl(address || ''), { waitUntil: 'load', titledMs: 180000 });
|
|
151
|
+
await page.waitForTimeout(2500);
|
|
152
|
+
};
|
|
153
|
+
const waitSpace = spaceId => page.waitForFunction(waitSpaceInPage, { debug, spaceId }, { timeout: 120000 });
|
|
154
|
+
|
|
155
|
+
for (const stop of stops) {
|
|
156
|
+
if (stop.stage) stage = stop.stage;
|
|
157
|
+
if (stop.type === 'enter') {
|
|
158
|
+
await enterLand(stop.address || '');
|
|
159
|
+
if (stop.space) await waitSpace(stop.space);
|
|
160
|
+
if (stop.logLoadTimes) {
|
|
161
|
+
const times = await page.evaluate(readTourLoadTimesInPage, { debug });
|
|
162
|
+
console.log(`${stop.label || stop.space || stop.address || 'page'} ok`, JSON.stringify(times));
|
|
163
|
+
}
|
|
164
|
+
} else if (stop.type === 'visions') {
|
|
165
|
+
const returnSpace = stop.returnSpace || 'world';
|
|
166
|
+
for (const id of stop.ids || []) {
|
|
167
|
+
await page.evaluate(enterVisionInPage, { debug, id });
|
|
168
|
+
await waitSpace(id);
|
|
169
|
+
await page.waitForTimeout(1500);
|
|
170
|
+
console.log('entered', id);
|
|
171
|
+
stage = 'after ' + id;
|
|
172
|
+
await page.evaluate(leaveVisionInPage, { debug });
|
|
173
|
+
await waitSpace(returnSpace);
|
|
174
|
+
await page.waitForTimeout(800);
|
|
175
|
+
}
|
|
176
|
+
} else if (stop.type === 'sceneIndex') {
|
|
177
|
+
const minTime = stop.minTime ?? 9;
|
|
178
|
+
await page.evaluate(startTourSceneInPage, { debug, index: stop.index });
|
|
179
|
+
await page.waitForFunction(waitSceneTimeInPage, { debug, minTime }, { timeout: 90000 });
|
|
180
|
+
stage = 'scene ' + stop.index;
|
|
181
|
+
console.log('scene', stop.index, await page.evaluate(readTourTitleInPage, { debug }));
|
|
182
|
+
if (stop.endAfter !== false) {
|
|
183
|
+
await page.evaluate(endTourSceneInPage, { debug });
|
|
184
|
+
await page.waitForTimeout(3500);
|
|
185
|
+
}
|
|
186
|
+
} else if (stop.type === 'sceneMatch') {
|
|
187
|
+
if (stop.endBefore) {
|
|
188
|
+
await page.evaluate(endTourSceneInPage, { debug });
|
|
189
|
+
await page.waitForTimeout(3500);
|
|
190
|
+
}
|
|
191
|
+
const minTime = stop.minTime ?? 4;
|
|
192
|
+
await page.evaluate(startTourSceneInPage, {
|
|
193
|
+
debug,
|
|
194
|
+
space: stop.space,
|
|
195
|
+
book: stop.book,
|
|
196
|
+
titleIncludes: stop.titleIncludes,
|
|
197
|
+
textIncludes: stop.textIncludes,
|
|
198
|
+
});
|
|
199
|
+
await page.waitForFunction(waitSceneTimeInPage, { debug, minTime }, { timeout: 60000 });
|
|
200
|
+
console.log('scene', await page.evaluate(readTourTitleInPage, { debug }));
|
|
201
|
+
} else {
|
|
202
|
+
throw new Error(`world-tour: unknown stop type "${stop.type}"`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const errors = [...errs];
|
|
207
|
+
console.log(errors.length ? errors.join('\n') : 'no errors');
|
|
208
|
+
await browser.close();
|
|
209
|
+
return { errors };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
module.exports = {
|
|
213
|
+
endTourSceneInPage,
|
|
214
|
+
enterVisionInPage,
|
|
215
|
+
leaveVisionInPage,
|
|
216
|
+
parseTourOptions,
|
|
217
|
+
readTourLoadTimesInPage,
|
|
218
|
+
readTourTitleInPage,
|
|
219
|
+
runWorldTour,
|
|
220
|
+
startTourSceneInPage,
|
|
221
|
+
waitSceneTimeInPage,
|
|
222
|
+
waitSpaceInPage,
|
|
223
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const {
|
|
5
|
+
endTourSceneInPage,
|
|
6
|
+
enterVisionInPage,
|
|
7
|
+
leaveVisionInPage,
|
|
8
|
+
parseTourOptions,
|
|
9
|
+
readTourLoadTimesInPage,
|
|
10
|
+
readTourTitleInPage,
|
|
11
|
+
startTourSceneInPage,
|
|
12
|
+
waitSceneTimeInPage,
|
|
13
|
+
waitSpaceInPage,
|
|
14
|
+
} = require('./world-tour.cjs');
|
|
15
|
+
|
|
16
|
+
test('parseTourOptions validates stops and applies defaults', () => {
|
|
17
|
+
const opts = parseTourOptions({ stops: [{ type: 'enter', address: '' }] });
|
|
18
|
+
assert.equal(opts.stops.length, 1);
|
|
19
|
+
assert.equal(opts.timeoutSeconds, 7200);
|
|
20
|
+
assert.deepEqual(opts.viewport, { width: 1280, height: 720 });
|
|
21
|
+
assert.throws(() => parseTourOptions({ stops: 'bad' }), /stops must be an array/);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('world-tour in-page helpers talk strictly through window[debug]', () => {
|
|
25
|
+
const calls = [];
|
|
26
|
+
const events = [
|
|
27
|
+
{ id: 'opening', book: 1, space: 'valley', title: 'Dawn crossing', where: 'River' },
|
|
28
|
+
{ id: 'harbour', book: 2, space: 'coast', title: 'Storm tide', where: 'Pier' },
|
|
29
|
+
];
|
|
30
|
+
globalThis.window = {
|
|
31
|
+
APP: {
|
|
32
|
+
space: { id: 'valley' },
|
|
33
|
+
state: { mode: 'play' },
|
|
34
|
+
CONFIG: { events },
|
|
35
|
+
director: { ev: events[1], t: 5.5 },
|
|
36
|
+
loadTimes: [
|
|
37
|
+
['Boot', 100],
|
|
38
|
+
['Build', 420],
|
|
39
|
+
],
|
|
40
|
+
enterVision(id) {
|
|
41
|
+
calls.push(['enterVision', id]);
|
|
42
|
+
},
|
|
43
|
+
leaveVision() {
|
|
44
|
+
calls.push(['leaveVision']);
|
|
45
|
+
},
|
|
46
|
+
startScene(ev, ui) {
|
|
47
|
+
calls.push(['startScene', ev.id, ui]);
|
|
48
|
+
},
|
|
49
|
+
endScene() {
|
|
50
|
+
calls.push(['endScene']);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
assert.equal(waitSpaceInPage({ debug: 'APP', spaceId: 'valley' }), true);
|
|
56
|
+
assert.equal(waitSpaceInPage({ debug: 'APP', spaceId: 'coast' }), false);
|
|
57
|
+
enterVisionInPage({ debug: 'APP', id: 'keep' });
|
|
58
|
+
leaveVisionInPage({ debug: 'APP' });
|
|
59
|
+
startTourSceneInPage({ debug: 'APP', index: 1 });
|
|
60
|
+
startTourSceneInPage({ debug: 'APP', book: 2, textIncludes: 'Pier' });
|
|
61
|
+
assert.throws(() => startTourSceneInPage({ debug: 'APP', book: 2, textIncludes: 'Missing' }), /no scene matched/);
|
|
62
|
+
assert.equal(waitSceneTimeInPage({ debug: 'APP', minTime: 4 }), true);
|
|
63
|
+
assert.equal(waitSceneTimeInPage({ debug: 'APP', minTime: 9 }), false);
|
|
64
|
+
assert.equal(readTourTitleInPage({ debug: 'APP' }), 'Storm tide');
|
|
65
|
+
assert.deepEqual(readTourLoadTimesInPage({ debug: 'APP' }), [100, 420]);
|
|
66
|
+
endTourSceneInPage({ debug: 'APP' });
|
|
67
|
+
assert.deepEqual(calls, [
|
|
68
|
+
['enterVision', 'keep'],
|
|
69
|
+
['leaveVision'],
|
|
70
|
+
['startScene', 'opening', true],
|
|
71
|
+
['startScene', 'harbour', true],
|
|
72
|
+
['endScene'],
|
|
73
|
+
]);
|
|
74
|
+
} finally {
|
|
75
|
+
delete globalThis.window;
|
|
76
|
+
}
|
|
77
|
+
});
|