ravensight-playtest 0.8.3 → 0.10.0

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.
Files changed (66) hide show
  1. package/README.md +280 -66
  2. package/addons/ravensight_driver/driver.gd +666 -21
  3. package/docs/ADAPTERS.md +11 -7
  4. package/docs/NATIVE_RUNNER.md +3 -1
  5. package/docs/godot-driver.md +127 -13
  6. package/package.json +8 -6
  7. package/src/api/client.js +4 -3
  8. package/src/cli.js +84 -25
  9. package/src/commands/check.js +30 -4
  10. package/src/commands/fakeCore.js +1 -0
  11. package/src/commands/hosted.js +41 -12
  12. package/src/commands/init.js +17 -1
  13. package/src/commands/run.js +209 -14
  14. package/src/commands/upload.js +6 -2
  15. package/src/commands/validate.js +1 -1
  16. package/src/commands/validateHosted.js +50 -5
  17. package/src/config.js +33 -2
  18. package/src/hosted/archivePreflight.js +7 -7
  19. package/src/hosted/buildUpload.js +89 -8
  20. package/src/hosted/recordedRun.js +141 -26
  21. package/src/hosted/status.js +19 -10
  22. package/src/run/actionSelector.js +14 -3
  23. package/src/run/aggregate.js +57 -3
  24. package/src/run/anygame/controlbook.js +179 -0
  25. package/src/run/anygame/genre.js +179 -0
  26. package/src/run/anygame/index.js +258 -0
  27. package/src/run/anygame/language.js +336 -0
  28. package/src/run/anygame/memory.js +330 -0
  29. package/src/run/anygame/shared-hashes.json +10 -0
  30. package/src/run/anygame/shared.js +24 -0
  31. package/src/run/anygame/sound.js +342 -0
  32. package/src/run/args.js +75 -8
  33. package/src/run/choiceCheck.js +312 -0
  34. package/src/run/context.js +254 -13
  35. package/src/run/drivers/godot-observation.js +93 -6
  36. package/src/run/drivers/godot.js +769 -46
  37. package/src/run/drivers/recording.js +24 -4
  38. package/src/run/drivers/web.js +1242 -77
  39. package/src/run/edgePass.js +731 -0
  40. package/src/run/fixLoop.js +5 -4
  41. package/src/run/focus.js +65 -0
  42. package/src/run/gamepad.js +108 -0
  43. package/src/run/godotEdgePass.js +235 -0
  44. package/src/run/godotTesterProbes.js +192 -0
  45. package/src/run/headings.js +21 -0
  46. package/src/run/honesty.js +544 -0
  47. package/src/run/inputs.js +256 -0
  48. package/src/run/marks.js +142 -0
  49. package/src/run/personaLoop.js +1000 -79
  50. package/src/run/phone.js +7 -0
  51. package/src/run/pixels.js +215 -0
  52. package/src/run/playClock.js +162 -0
  53. package/src/run/readiness.js +585 -0
  54. package/src/run/refusal.js +67 -0
  55. package/src/run/regions.js +119 -0
  56. package/src/run/report.js +14 -2
  57. package/src/run/reportChecks.js +472 -0
  58. package/src/run/resume.js +3 -2
  59. package/src/run/screenshots.js +161 -0
  60. package/src/run/strip.js +114 -0
  61. package/src/run/testerLedger.js +312 -0
  62. package/src/run/testerProbes.js +584 -0
  63. package/src/run/thinRun.js +102 -0
  64. package/src/run/timeFreeze.js +79 -0
  65. package/src/run/tools.js +454 -29
  66. package/src/runDefaults.js +24 -2
@@ -0,0 +1,102 @@
1
+ // A thin run, as the CLI says it.
2
+ //
3
+ // A persona run that ended with fewer actions than a full playtest shows,
4
+ // through no fault of the game, is billed at what it cost to run and the rest
5
+ // of its price is refunded when the job settles. The server decides that from
6
+ // its own records and writes every sentence (`thin_run` on the run it answers
7
+ // a `complete` with, `thin_runs` on a finish or cancel); this module only
8
+ // puts those sentences on the terminal and into the run's report.md, so the
9
+ // CLI, the report and the dashboard all say the same thing.
10
+ //
11
+ // Nothing here decides anything, and nothing here can change what is charged.
12
+ import fs from 'node:fs/promises';
13
+ import path from 'node:path';
14
+
15
+ /** The heading the explanation is written under in report.md. */
16
+ export const THIN_RUN_HEADING = '## Why this run was short';
17
+
18
+ /**
19
+ * The capability notes a `complete` may carry: what the playtester could not
20
+ * read or press, as `{ input, reason }`. The server bounds them again and only
21
+ * ever shows them back; they change no charge.
22
+ *
23
+ * @param {any} outcome a run outcome; `capabilityNotes` is absent on a run that met no limit
24
+ * @returns {Array<{input: string, reason: string}>}
25
+ */
26
+ export function capabilityNotesBody(outcome) {
27
+ const notes = outcome && Array.isArray(outcome.capabilityNotes) ? outcome.capabilityNotes : [];
28
+ return notes
29
+ .filter(note => note && typeof note.input === 'string' && typeof note.reason === 'string' && note.input && note.reason)
30
+ .slice(0, 5)
31
+ .map(note => ({ input: note.input.slice(0, 60), reason: note.reason.slice(0, 200) }));
32
+ }
33
+
34
+ /**
35
+ * The server's thin run record, when the answer carries one with words in it.
36
+ *
37
+ * @param {any} record `run.thin_run`, or one entry of `thin_runs`
38
+ * @returns {{why: string, next: string, money: string|null, limited: boolean}|null}
39
+ */
40
+ export function thinRunOf(record) {
41
+ if (!record || typeof record.why !== 'string' || !record.why) return null;
42
+ return {
43
+ why: record.why,
44
+ next: typeof record.next === 'string' ? record.next : '',
45
+ money: typeof record.money === 'string' && record.money ? record.money : null,
46
+ limited: record.limited === true
47
+ };
48
+ }
49
+
50
+ /**
51
+ * The lines a thin run prints: why, what to try, then the money.
52
+ *
53
+ * @param {any} record
54
+ * @returns {Array<string>} empty when the run is not a thin run
55
+ */
56
+ export function thinRunLines(record) {
57
+ const thin = thinRunOf(record);
58
+ if (!thin) return [];
59
+ return [thin.why, thin.next, thin.money].filter(Boolean);
60
+ }
61
+
62
+ /**
63
+ * The section report.md gets, so the report itself says why it is short.
64
+ *
65
+ * @param {any} record
66
+ * @returns {string} '' when the run is not a thin run
67
+ */
68
+ export function thinRunSection(record) {
69
+ const lines = thinRunLines(record);
70
+ if (lines.length === 0) return '';
71
+ return `${THIN_RUN_HEADING}\n\n${lines.join('\n\n')}\n`;
72
+ }
73
+
74
+ /**
75
+ * Write the explanation into the run's report.md, once. A report that already
76
+ * has the section gets it replaced, so a settled figure takes the place of the
77
+ * line written before settlement. Never throws: a report that cannot be
78
+ * written must not fail a run that completed.
79
+ *
80
+ * @param {string} directory the run directory
81
+ * @param {any} record
82
+ * @returns {Promise<boolean>} whether the section was written
83
+ */
84
+ export async function writeThinRunSection(directory, record) {
85
+ const section = thinRunSection(record);
86
+ if (!section || !directory) return false;
87
+ const file = path.join(directory, 'report.md');
88
+ try {
89
+ let text = '';
90
+ try {
91
+ text = await fs.readFile(file, 'utf8');
92
+ } catch (error) {
93
+ if (!error || error.code !== 'ENOENT') throw error;
94
+ }
95
+ const at = text.indexOf(THIN_RUN_HEADING);
96
+ const kept = (at === -1 ? text : text.slice(0, at)).replace(/\s+$/, '');
97
+ await fs.writeFile(file, `${kept}${kept ? '\n\n' : ''}${section}`);
98
+ return true;
99
+ } catch {
100
+ return false;
101
+ }
102
+ }
@@ -0,0 +1,79 @@
1
+ // Game time that stops while the persona thinks.
2
+ //
3
+ // Ported from the cloud runner. A real-time web game keeps running while a
4
+ // model decides: with a decision gap of seconds against key holds of half a
5
+ // second, the player stood still most of the time while the game's clock ran.
6
+ // The Godot driver already parks the game between actions; this is the same
7
+ // for a web build. An init script gates the page's animation frames and
8
+ // clocks: paused, no requestAnimationFrame callback runs and performance.now
9
+ // and Date.now stand still; resumed, the queued frames run and the clocks go
10
+ // on from where they stopped, with the paused time taken out. Engines that
11
+ // drive their main loop from requestAnimationFrame and read time from
12
+ // performance.now (Godot, Unity, LOVE, Emscripten) stop and go with it.
13
+ // Timers (setTimeout) and workers are not gated: their own clocks keep
14
+ // running, and a game driven by them alone only sees its clock stand still.
15
+
16
+ /* c8 ignore start */
17
+ /** Serialised by Playwright into every document, so it closes over nothing. */
18
+ export function timeFreezeInit() {
19
+ if (window.__rsTime) return;
20
+ const rAF = window.requestAnimationFrame.bind(window);
21
+ const cAF = window.cancelAnimationFrame.bind(window);
22
+ const pnow = performance.now.bind(performance);
23
+ const dnow = Date.now;
24
+ let paused = false;
25
+ let pausedAt = 0;
26
+ let offset = 0;
27
+ let next = 1e9;
28
+ const queue = new Map();
29
+ const now = () => (paused ? pausedAt : pnow()) - offset;
30
+ try { performance.now = () => now(); } catch { /* read only */ }
31
+ Date.now = () => dnow() - offset - (paused ? pnow() - pausedAt : 0);
32
+ // A frame asked for while running but due after a pause waits for the resume too.
33
+ const run = (k, cb) => () => { if (paused) queue.set(k, cb); else cb(now()); };
34
+ window.requestAnimationFrame = cb => {
35
+ if (!paused) { let k = 0; k = rAF(() => run(k, cb)()); return k; }
36
+ next += 1;
37
+ queue.set(next, cb);
38
+ return next;
39
+ };
40
+ window.cancelAnimationFrame = k => { if (!queue.delete(k)) cAF(k); };
41
+ Object.defineProperty(window, '__rsTime', { value: Object.freeze({
42
+ pause() { if (!paused) { paused = true; pausedAt = pnow(); } return true; },
43
+ resume() {
44
+ if (!paused) return true;
45
+ offset += pnow() - pausedAt;
46
+ paused = false;
47
+ const waiting = [...queue.values()];
48
+ queue.clear();
49
+ for (const cb of waiting) window.requestAnimationFrame(cb);
50
+ return true;
51
+ },
52
+ get paused() { return paused; }
53
+ }), enumerable: false });
54
+ }
55
+ /* c8 ignore stop */
56
+
57
+ /**
58
+ * The runner's handle on a page's game time, in every frame of it (a game is
59
+ * often inside an iframe). Best effort: a frame that cannot answer, or a page
60
+ * that replaced the gate, just keeps running.
61
+ *
62
+ * @param {() => Object|null} getPage
63
+ */
64
+ export function gameTime(getPage) {
65
+ const each = async fn => {
66
+ const page = getPage();
67
+ if (!page) return false;
68
+ const frames = typeof page.frames === 'function' ? page.frames() : [page];
69
+ await Promise.all(frames.map(frame => Promise.resolve().then(() => frame.evaluate(fn)).catch(() => false)));
70
+ return true;
71
+ };
72
+ return {
73
+ /* c8 ignore next 2 */
74
+ pause: () => each(() => (window.__rsTime ? window.__rsTime.pause() : false)),
75
+ resume: () => each(() => (window.__rsTime ? window.__rsTime.resume() : false))
76
+ };
77
+ }
78
+
79
+ export default { timeFreezeInit, gameTime };