ravensight-playtest 0.13.1 → 0.13.2
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/README.md +40 -2
- package/package.json +1 -1
- package/src/commands/run.js +35 -6
- package/src/run/aggregate.js +2 -1
- package/src/run/anygame/shared-hashes.json +2 -2
- package/src/run/claimGate.js +9 -0
- package/src/run/drivers/mobile/target.js +22 -3
- package/src/run/drivers/web.js +27 -1
- package/src/run/eventclaims.js +6 -3
- package/src/run/events.js +33 -7
- package/src/run/intent.js +604 -0
- package/src/run/personaLoop.js +119 -9
- package/src/run/thinRun.js +35 -11
- package/src/run/tools.js +52 -14
package/README.md
CHANGED
|
@@ -938,6 +938,40 @@ are the driver's, not the game's: they are recorded as `driver_error`, and a
|
|
|
938
938
|
blocker or major resting only on them is dropped before upload, as is any
|
|
939
939
|
finding resting only on the persona's "waiting for X to finish" notes.
|
|
940
940
|
|
|
941
|
+
On a game drawn in a canvas the words a player reads are in the picture, not
|
|
942
|
+
in the page, so a click by a label the page does not hold ("New Run", "START
|
|
943
|
+
RUN") is refused at once, well under a second, with where to click instead: the
|
|
944
|
+
label's grid cell, its mark, or its x and y read off the screenshot. A label the
|
|
945
|
+
page does hold (a button around the canvas) is clicked as before. Until 0.13.2
|
|
946
|
+
such a click waited the full 15 second action timeout.
|
|
947
|
+
|
|
948
|
+
Every input the persona sends with `expect` is held against the screen after
|
|
949
|
+
it: the screen not changing at all, a part of the game the run's focus or the
|
|
950
|
+
input said to stay out of ("not the Tutorial") read as the screen's state
|
|
951
|
+
("TUTORIAL 1/7"), the persona's own answer on its next tool call
|
|
952
|
+
(`intent_check` "met" or "missed", and `instead`, what the screen shows), and
|
|
953
|
+
the same input sent again for the same result. A screen that changed is not
|
|
954
|
+
enough: a key that draws a new line of dialogue each time but never does what
|
|
955
|
+
it was meant to is a miss. An input that missed the same result twice in a row
|
|
956
|
+
is not sent a third time; the persona is told what the screen showed instead
|
|
957
|
+
and asked for a different approach (move first with the arrow keys or W A S D,
|
|
958
|
+
click another target). An input that moves the game on a step at a time (the
|
|
959
|
+
next page of a story, the next tip dismissed) is never counted as a miss from
|
|
960
|
+
the record alone. Each answer, miss and refused repeat is an `intent_check` or
|
|
961
|
+
`intent_refused` line of the step log, the action list the report step reads
|
|
962
|
+
says which inputs missed, and `usage.json` carries the record as `intent`.
|
|
963
|
+
|
|
964
|
+
`report.md` says what was played under its title (**What was played**, in the
|
|
965
|
+
cloud report's words): a run that used its action or model budget "played to
|
|
966
|
+
its budget" and is never said to have stopped early, the furthest point the
|
|
967
|
+
persona confirmed or moved on from, the result it aimed at and never reached
|
|
968
|
+
with what the screen showed instead, a part of the game the focus said to stay
|
|
969
|
+
out of, and the game's own events. `usage.json` carries the same as `scope`.
|
|
970
|
+
The in-character section is held to the run's record: a sentence saying the
|
|
971
|
+
persona walked or moved to a result it only ever pressed a non-moving key for,
|
|
972
|
+
or repeating a claim the frames contradicted, is left out, and the record's own
|
|
973
|
+
fact is said instead in a line written by the runner.
|
|
974
|
+
|
|
941
975
|
An action counts as changing the screen when the URL changed, the page loaded
|
|
942
976
|
a new document, the visible tree (field values included) changed, or for typing,
|
|
943
977
|
the field's own value changed, with one short second look for a navigation
|
|
@@ -1049,7 +1083,11 @@ The rest of the price is refunded when the job finishes. The CLI prints why the
|
|
|
1049
1083
|
run was short and what to try next as soon as the run completes, writes the
|
|
1050
1084
|
same words into the run's `report.md` under "Why this run was short", and
|
|
1051
1085
|
prints what was charged and refunded when the job finishes. The dashboard's
|
|
1052
|
-
job page shows the same sentences on the run.
|
|
1086
|
+
job page shows the same sentences on the run. A run that played to its budget
|
|
1087
|
+
(its action or model budget, with the report reserve) is never called short or
|
|
1088
|
+
"stopped early": when the server still bills it at cost, the CLI says it played
|
|
1089
|
+
to its budget and writes the server's other words under "How this run was
|
|
1090
|
+
billed" instead.
|
|
1053
1091
|
|
|
1054
1092
|
A run the game itself cut short is charged in full, because that run did its
|
|
1055
1093
|
job: a blocker the persona reported with evidence, or a persona that quit in
|
|
@@ -1349,7 +1387,7 @@ which has to be refreshed by hand whenever the server's schema changes.
|
|
|
1349
1387
|
|
|
1350
1388
|
| Code | Meaning |
|
|
1351
1389
|
|---|---|
|
|
1352
|
-
| 0 | Success |
|
|
1390
|
+
| 0 | Success. A run that played (at least 15 actions, or every action it had) and wrote its report is a success even when it found nothing and the server settles the job as failed because no run counted as a result. |
|
|
1353
1391
|
| 1 | Failure |
|
|
1354
1392
|
| 2 | Budget exceeded during play. Partial results were written and uploaded. A run that ran out during the report step and was completed does not make the job exit 2. |
|
|
1355
1393
|
| 3 | Environment check failed |
|
package/package.json
CHANGED
package/src/commands/run.js
CHANGED
|
@@ -29,7 +29,8 @@ import { capabilityNoteLines } from '../run/readiness.js';
|
|
|
29
29
|
import { readBridgeConfig } from "../run/drivers/stdio.js";
|
|
30
30
|
import { WEBDRIVER_NAMES, readDriverConfig } from '../run/drivers/webdriver.js';
|
|
31
31
|
import { BROWSER_FIX, automationChecks, probeBrowser, browserFixFor, playwrightVersion } from './check.js';
|
|
32
|
-
import { runPersona } from '../run/personaLoop.js';
|
|
32
|
+
import { runPersona, MIN_SESSION_ACTIONS } from '../run/personaLoop.js';
|
|
33
|
+
import { playedToBudget } from '../run/intent.js';
|
|
33
34
|
import { runModelBudgetUsd } from '../run/budgetReserve.js';
|
|
34
35
|
import { missingScopeMessage, missingScopes } from '../auth/scopes.js';
|
|
35
36
|
import { tracesWanted } from '../run/acceptance.js';
|
|
@@ -818,7 +819,7 @@ export async function playJob({
|
|
|
818
819
|
log(`job ${jobId} ${settledState || 'finished'}: refunded ${formatCents(finished.refunded_cents)}.`);
|
|
819
820
|
// Each thin run, with what it was charged now the job has settled.
|
|
820
821
|
for (const thin of Array.isArray(finished.thin_runs) ? finished.thin_runs : []) {
|
|
821
|
-
const lines = thinRunLines(thin);
|
|
822
|
+
const lines = thinRunLines(thin, { played: Boolean(results.find(result => result && result.runId === thin.run_id)?.playedToBudget) });
|
|
822
823
|
if (lines.length > 0) log(`run ${thin.run_id}${thin.persona ? ` (${thin.persona})` : ''}: ${lines.join(' ')}`);
|
|
823
824
|
}
|
|
824
825
|
}
|
|
@@ -844,7 +845,15 @@ export async function playJob({
|
|
|
844
845
|
if (playBudgetHit) return EXIT.BUDGET;
|
|
845
846
|
// The server's settlement is the verdict on the job. A job it settled as
|
|
846
847
|
// failed (every run refunded, nothing kept) exited 0 in 0.5.0, so a script
|
|
847
|
-
// could not tell it from a success.
|
|
848
|
+
// could not tell it from a success. A run that played and wrote its report
|
|
849
|
+
// is a playtest that ran, found something or not (owner, 2026-11-20): the
|
|
850
|
+
// paid local run of that day played 39 actions, wrote a checked report with
|
|
851
|
+
// no finding, was refunded as a thin run, and exited 1.
|
|
852
|
+
const playedThrough = results.filter(result => result && result.playedThrough);
|
|
853
|
+
if (settledState === 'failed' && playedThrough.length > 0) {
|
|
854
|
+
log(`job ${jobId}: the server settled it as failed, but ${playedThrough.length === 1 ? `run ${playedThrough[0].runId} played ${playedThrough[0].actionsTaken} actions and wrote its report` : `${playedThrough.length} runs played and wrote their reports`}, so this exits 0.`);
|
|
855
|
+
return EXIT.OK;
|
|
856
|
+
}
|
|
848
857
|
if (settledState === 'failed' || settledState === 'stalled') return EXIT.FAILED;
|
|
849
858
|
return anySucceeded || reportBudgetDelivered ? EXIT.OK : EXIT.FAILED;
|
|
850
859
|
}
|
|
@@ -1134,7 +1143,25 @@ export async function playPersonaRun({
|
|
|
1134
1143
|
}
|
|
1135
1144
|
|
|
1136
1145
|
log(`run ${runId} (${persona.slug}) ${outcome.state}: ${outcome.actionsTaken} actions, ${outcome.quitReason}.`);
|
|
1137
|
-
return { runId, persona: persona.slug, state: outcome.state, quitReason: outcome.quitReason };
|
|
1146
|
+
return { runId, persona: persona.slug, state: outcome.state, quitReason: outcome.quitReason, ...playedFacts(outcome, maxActions) };
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* What the job's exit code and its thin run lines need of a run: how many actions it took, whether it played (at least the
|
|
1151
|
+
* proof bar of actions, or every action it had, and a report written that is not partial) and whether it played to its budget.
|
|
1152
|
+
*
|
|
1153
|
+
* @param {Object} outcome
|
|
1154
|
+
* @param {number} maxActions
|
|
1155
|
+
* @returns {{actionsTaken: number, playedThrough: boolean, playedToBudget: boolean}}
|
|
1156
|
+
*/
|
|
1157
|
+
export function playedFacts(outcome, maxActions) {
|
|
1158
|
+
const actionsTaken = Number(outcome && outcome.actionsTaken) || 0;
|
|
1159
|
+
const bar = Math.min(MIN_SESSION_ACTIONS, Number(maxActions) || MIN_SESSION_ACTIONS);
|
|
1160
|
+
return {
|
|
1161
|
+
actionsTaken,
|
|
1162
|
+
playedThrough: Boolean(outcome && outcome.state === 'succeeded' && outcome.report && !outcome.report.partial && actionsTaken >= bar),
|
|
1163
|
+
playedToBudget: Boolean(playedToBudget({ quitReason: outcome && outcome.quitReason, actionsTaken, maxActions }))
|
|
1164
|
+
};
|
|
1138
1165
|
}
|
|
1139
1166
|
|
|
1140
1167
|
/**
|
|
@@ -1304,10 +1331,12 @@ export async function deliver({ deps, api, gameId, jobId, runId, directory, outc
|
|
|
1304
1331
|
}
|
|
1305
1332
|
// A thin run: the server says why it was short, what to try next and how
|
|
1306
1333
|
// it is billed. Said here and written into report.md, in its words.
|
|
1307
|
-
|
|
1334
|
+
// A run that played to its budget is never said to have stopped early (./thinRun.js playedWhy).
|
|
1335
|
+
const played = Boolean(playedToBudget({ quitReason: outcome.quitReason, actionsTaken: outcome.actionsTaken, maxActions: outcome.maxActions }));
|
|
1336
|
+
const thin = thinRunLines(answer && answer.run && answer.run.thin_run, { played });
|
|
1308
1337
|
if (thin.length > 0) {
|
|
1309
1338
|
log(`run ${runId}: ${thin.join(' ')}`);
|
|
1310
|
-
await writeThinRunSection(directory, answer.run.thin_run);
|
|
1339
|
+
await writeThinRunSection(directory, answer.run.thin_run, { played });
|
|
1311
1340
|
}
|
|
1312
1341
|
// What the game's memory made of the notes this run handed on (the server's answer, only when they were sent).
|
|
1313
1342
|
const remembered = answer && answer.game_memory;
|
package/src/run/aggregate.js
CHANGED
|
@@ -802,7 +802,8 @@ export function inCharacterSection(markdown) {
|
|
|
802
802
|
if (start === -1) return null;
|
|
803
803
|
const rest = lines.slice(start + 1);
|
|
804
804
|
const end = rest.findIndex(line => /^#{1,2}\s/.test(line));
|
|
805
|
-
|
|
805
|
+
// The runner's own line under it (./intent.js holdInCharacter: what the record shows instead) is not the persona's voice.
|
|
806
|
+
const text = (end === -1 ? rest : rest.slice(0, end)).filter(line => !line.startsWith('Held to the run\'s record (written by the runner)')).join('\n').trim();
|
|
806
807
|
if (!text) return null;
|
|
807
808
|
return { text, fromLog: /written from the run log/i.test(lines[start]) };
|
|
808
809
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"sound": "8be235bda7903856cd9b1cdb5aad1c327c10af8d86c3b0dbb575f2d323999bb3",
|
|
9
9
|
"gamenotes": "d137c0951de6fa92de973b7b3e0c5db5193697bdb9b38d4c6281b1fdd63ace53",
|
|
10
10
|
"claimwords": "7571269538c4683b313bd02117023d9a4971d0956aaa3f2a7ede853357dc819d",
|
|
11
|
-
"events": "
|
|
12
|
-
"eventclaims": "
|
|
11
|
+
"events": "4f6be350898693878ec989b9a709e362cc7f2e8b78e4dca48cea76110da6ad0c",
|
|
12
|
+
"eventclaims": "24fdd77b4d4a61da8b5088c97862dcea8b27b871a0c2f2d4d69469de6393d98e"
|
|
13
13
|
}
|
|
14
14
|
}
|
package/src/run/claimGate.js
CHANGED
|
@@ -68,6 +68,15 @@ export function repeatsClaim(sentence, claim, { loose = false } = {}) {
|
|
|
68
68
|
return (title >= 1 && shared >= 5) || (title >= 2 && shared >= 4);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Whether a sentence repeats one turned-away claim (an entry of the claim judge's `turnedAway`, with its `finding`), by the
|
|
73
|
+
* same words as the sweep below. The in-character section is held to it only for a claim the frames contradicted (./intent.js).
|
|
74
|
+
*/
|
|
75
|
+
export function repeatsTurnedAway(sentence, entry) {
|
|
76
|
+
if (!entry) return false;
|
|
77
|
+
return repeatsClaim(sentence, { id: entry.finding ? entry.finding.id : entry.id, words: wordsOf(entry.finding || entry) });
|
|
78
|
+
}
|
|
79
|
+
|
|
71
80
|
/** The sections of report.md a turned-away claim is swept out of. The in-character section is the playtester's own voice and stays. */
|
|
72
81
|
const SWEPT = /^##\s+(?:What worked|Top issues|What this run didn't cover|Persona summary|Evidence)\b/i;
|
|
73
82
|
const NEXT_STEP = /^##\s+Suggested next step\b/i;
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { lstat, readdir, realpath, readlink } from 'node:fs/promises';
|
|
3
|
-
import { createReadStream } from 'node:fs';
|
|
3
|
+
import { createReadStream, realpathSync } from 'node:fs';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
5
|
|
|
6
6
|
export const MOBILE_DRIVERS = Object.freeze(['android_driver', 'ios_driver']);
|
|
7
|
+
function insideRoot(root, file) { return file === root || file.startsWith(root + path.sep); }
|
|
8
|
+
function realOrAncestor(file) {
|
|
9
|
+
let current = file; const tail = [];
|
|
10
|
+
for (;;) {
|
|
11
|
+
try { return path.join(realpathSync(current), ...tail.reverse()); } catch (error) {
|
|
12
|
+
const parent = path.dirname(current);
|
|
13
|
+
if (parent === current) return file;
|
|
14
|
+
tail.push(path.basename(current)); current = parent;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function configBuild(repoRoot, ref) {
|
|
19
|
+
const resolved = path.resolve(repoRoot, ref);
|
|
20
|
+
if (!insideRoot(path.resolve(repoRoot), resolved) || !insideRoot(realOrAncestor(path.resolve(repoRoot)), realOrAncestor(resolved))) {
|
|
21
|
+
throw new Error('The native build in the project settings must be inside the project folder.');
|
|
22
|
+
}
|
|
23
|
+
return resolved;
|
|
24
|
+
}
|
|
7
25
|
export function nativeTarget(options = {}, config = null, driverName = options.driver || config?.driver, repoRoot = process.cwd()) {
|
|
8
26
|
const explicitNative = options.nativeBuild !== undefined;
|
|
9
27
|
const nativeFlags = ['device', 'package', 'bundleId'].some(key => options[key] !== undefined) || options.portrait === true || options.landscape === true;
|
|
@@ -19,10 +37,11 @@ export function nativeTarget(options = {}, config = null, driverName = options.d
|
|
|
19
37
|
if (options.portrait && options.landscape) throw new Error('Choose --portrait or --landscape, not both.');
|
|
20
38
|
if (driverName === 'android_driver' && options.bundleId !== undefined) throw new Error('--bundle-id is for ios_driver; Android uses --package.');
|
|
21
39
|
if (driverName === 'ios_driver' && options.package !== undefined) throw new Error('--package is for android_driver; iOS uses --bundle-id.');
|
|
22
|
-
const
|
|
40
|
+
const configRef = config?.build?.kind === 'native_build' ? config.build.ref : null;
|
|
41
|
+
const build = options.nativeBuild || configRef;
|
|
23
42
|
const native = config?.native && typeof config.native === 'object' ? config.native : {};
|
|
24
43
|
return {
|
|
25
|
-
mode: 'native', driver: driverName, build: build ? path.resolve(repoRoot, build) :
|
|
44
|
+
mode: 'native', driver: driverName, build: !build ? null : options.nativeBuild ? path.resolve(repoRoot, build) : configBuild(repoRoot, build),
|
|
26
45
|
device: options.device || native.device || null,
|
|
27
46
|
package: options.package || native.package || null, bundleId: options.bundleId || native.bundleId || null,
|
|
28
47
|
orientation: options.landscape ? 'landscape' : options.portrait ? 'portrait' : native.orientation || 'portrait'
|
package/src/run/drivers/web.js
CHANGED
|
@@ -1107,6 +1107,18 @@ export function textOnScreen(nodes, target) {
|
|
|
1107
1107
|
/** What a target that is none of a ref, coordinates or visible text is told. */
|
|
1108
1108
|
export const NOT_A_TARGET_MESSAGE = 'is not a ref, coordinates or text on the current screen; use the ref the snapshot shows, such as e12';
|
|
1109
1109
|
|
|
1110
|
+
/**
|
|
1111
|
+
* How long a click by words on a canvas game looks for those words in the page before it is refused. The words of a game drawn
|
|
1112
|
+
* on a canvas are in the picture, not in the page, so there is nothing to wait for: the paid local run of 2026-11-20 waited the
|
|
1113
|
+
* full action timeout (15 s) on each of four such clicks, about a fifth of its play.
|
|
1114
|
+
*/
|
|
1115
|
+
export const CANVAS_TEXT_CHECK_MS = 400;
|
|
1116
|
+
|
|
1117
|
+
/** What a click by words that a canvas game only draws is told: where to click instead. */
|
|
1118
|
+
export function canvasTextMessage(target) {
|
|
1119
|
+
return `${JSON.stringify(String(target).trim())} is drawn on the game's canvas, not written in the page, so it cannot be clicked by its words. Click where the picture shows it instead: its grid cell (such as C3), its mark (such as m2), or x and y read off the screenshot. This is a limit of the runner, not of the game`;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1110
1122
|
/**
|
|
1111
1123
|
* A locator narrowed to visible elements when this Playwright can: a mobile
|
|
1112
1124
|
* only duplicate hidden by CSS must never be the one clicked.
|
|
@@ -1805,7 +1817,21 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
|
|
|
1805
1817
|
throw new TargetError(`${JSON.stringify(target)} ${NOT_A_TARGET_MESSAGE}`);
|
|
1806
1818
|
}
|
|
1807
1819
|
}
|
|
1808
|
-
|
|
1820
|
+
const locator = resolveLocator(current, target);
|
|
1821
|
+
// A game drawn on a canvas: words the page does not hold are in the picture, so the click is refused at once, with where to
|
|
1822
|
+
// click instead, rather than searched for until the action timeout. Words the page does hold (a button around the canvas) click.
|
|
1823
|
+
if (canvasPlay && !(await inPageNow(locator))) throw new TargetError(canvasTextMessage(target));
|
|
1824
|
+
return locator;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
/** Whether a locator matches anything in the page right now, asked once and never waited for. */
|
|
1828
|
+
async function inPageNow(locator) {
|
|
1829
|
+
if (!locator || typeof locator.count !== 'function') return true;
|
|
1830
|
+
try {
|
|
1831
|
+
return (await withTimeout(Promise.resolve(locator.count()), CANVAS_TEXT_CHECK_MS)) > 0;
|
|
1832
|
+
} catch {
|
|
1833
|
+
return false;
|
|
1834
|
+
}
|
|
1809
1835
|
}
|
|
1810
1836
|
|
|
1811
1837
|
/**
|
package/src/run/eventclaims.js
CHANGED
|
@@ -133,7 +133,10 @@ function valueKey(e, about) {
|
|
|
133
133
|
|
|
134
134
|
const propsText = props => Object.entries(props).map(([k, v]) => `${k}=${v}`).join(' ');
|
|
135
135
|
const show = e => `${e.name}${Object.keys(e.props).length ? ` (${propsText(e.props).slice(0, 80)})` : ''}`;
|
|
136
|
-
|
|
136
|
+
// An event whose timestamp was a whole second is placed at the latest step of that second, with `from` its earliest (lib/events.mjs):
|
|
137
|
+
// it is inside a claim's steps only when all of its steps are, so an event that may have come before the claim's inputs never answers it.
|
|
138
|
+
const earliest = e => (e.from === 'before' ? -1 : Number.isSafeInteger(e.from) ? e.from : e.step);
|
|
139
|
+
const atStep = e => (e.phase === 'play' && Number.isSafeInteger(e.step) ? (Number.isSafeInteger(e.from) ? ` at steps ${e.from} to ${e.step}` : e.from === 'before' ? ` before the first input or at step ${e.step}` : ` at step ${e.step}`) : '');
|
|
137
140
|
|
|
138
141
|
/** The steps a claim is about: the inputs since the playtester last looked (or a test's own inputs), or the few before it. */
|
|
139
142
|
function windowOf(claim) {
|
|
@@ -162,7 +165,7 @@ export function eventsVerdict(run, claim) {
|
|
|
162
165
|
const win = windowOf(claim);
|
|
163
166
|
if (!win) return null;
|
|
164
167
|
const title = String(claim.title || '');
|
|
165
|
-
const inWin = evs.filter(e => e.phase === 'play' && Number.isSafeInteger(e.step) && e
|
|
168
|
+
const inWin = evs.filter(e => e.phase === 'play' && Number.isSafeInteger(e.step) && earliest(e) >= win.from && e.step <= win.to);
|
|
166
169
|
const done = (verdict, why, list, extra = {}) => {
|
|
167
170
|
const v = { verdict, why: noDashes(why), events: list.slice(0, 4).map(e => ({ step: e.step, name: e.name, props: e.props })), ...extra };
|
|
168
171
|
if (!memo.has(run)) memo.set(run, new Map());
|
|
@@ -209,7 +212,7 @@ export function eventsVerdict(run, claim) {
|
|
|
209
212
|
const keyed = evs.filter(e => e.phase === 'play' && Number.isSafeInteger(e.step) && e.step <= win.to && eventMatches(e, about)).map(e => ({ e, k: valueKey(e, about) })).filter(x => x.k);
|
|
210
213
|
for (let i = 1; i < keyed.length; i++) {
|
|
211
214
|
const a = keyed[i - 1], b = keyed[i];
|
|
212
|
-
if (b.e
|
|
215
|
+
if (earliest(b.e) < win.from || a.k !== b.k) continue;
|
|
213
216
|
const from = a.e.props[a.k], to = b.e.props[b.k];
|
|
214
217
|
if (from === to) continue;
|
|
215
218
|
if (about.way === 'any' || (about.way === 'down' ? to < from : to > from)) return done('contradicted', `the game's own events show ${b.k} go from ${from}${atStep(a.e)} to ${to}${atStep(b.e)}`, [a.e, b.e]);
|
package/src/run/events.js
CHANGED
|
@@ -103,6 +103,11 @@ function timestampOf(raw) {
|
|
|
103
103
|
if (t < 1e11) t *= 1000;
|
|
104
104
|
return Math.floor(t);
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Whether an SDK timestamp is a whole second (the LÖVE SDK's os.time, and the JavaScript SDK before it sent milliseconds): the event
|
|
108
|
+
* happened somewhere in that second, which can span several steps of game time (a key press plays in about 0.65 s of it).
|
|
109
|
+
*/
|
|
110
|
+
const wholeSecond = raw => { const t = Number(raw); return Number.isFinite(t) && t > 0 && t < 1e11 && Number.isInteger(t); };
|
|
106
111
|
|
|
107
112
|
/**
|
|
108
113
|
* The events in one track request body, as the SDKs send them: `{ events: [...] }`
|
|
@@ -127,7 +132,7 @@ export function parseTrackBody(body, headers = {}) {
|
|
|
127
132
|
if (!name) continue;
|
|
128
133
|
// The SDK's own id for an event, when it sends one: a retry carries the same id.
|
|
129
134
|
const id = typeof e.data?.rs_event_id === 'string' ? e.data.rs_event_id.slice(0, 64) : null;
|
|
130
|
-
out.push({ name, props: cleanProps(e.data ?? e.properties ?? e.props), ts: timestampOf(e.timestamp), ...(id ? { id } : {}) });
|
|
135
|
+
out.push({ name, props: cleanProps(e.data ?? e.properties ?? e.props), ts: timestampOf(e.timestamp), ...(wholeSecond(e.timestamp) ? { coarse: true } : {}), ...(id ? { id } : {}) });
|
|
131
136
|
}
|
|
132
137
|
return out;
|
|
133
138
|
} catch {
|
|
@@ -183,9 +188,11 @@ export function createGameEvents({ now = Date.now, limits = EVENT_LIMITS } = {})
|
|
|
183
188
|
}
|
|
184
189
|
|
|
185
190
|
/**
|
|
186
|
-
* Where an event belongs: `{ phase: 'before' | 'play' | 'after', step, by }`.
|
|
191
|
+
* Where an event belongs: `{ phase: 'before' | 'play' | 'after', step, by, from? }`.
|
|
187
192
|
* By its own timestamp against the page clock marks when it can be (`by:
|
|
188
193
|
* 'clock'`); by when it reached the runner otherwise (`by: 'arrival'`).
|
|
194
|
+
* `from` is the earliest step a whole-second timestamp can belong to ('before'
|
|
195
|
+
* the first input, or a step) when that is not `step`.
|
|
189
196
|
*/
|
|
190
197
|
function place(e) {
|
|
191
198
|
const timed = marks.filter(m => m.pageMs !== null);
|
|
@@ -193,10 +200,22 @@ export function createGameEvents({ now = Date.now, limits = EVENT_LIMITS } = {})
|
|
|
193
200
|
const first = timed[0], last = timed.at(-1);
|
|
194
201
|
// A clock that is not the page's own (an engine that keeps its own) is read by arrival instead.
|
|
195
202
|
const sane = e.ts >= first.pageMs - 10 * 60 * 1000 && e.ts <= last.pageMs + Math.max(0, now() - last.realAt) + 2 * 60 * 1000;
|
|
196
|
-
if (sane) return at(timed, m => m.pageMs <= e.ts, 'clock');
|
|
203
|
+
if (sane && !e.coarse) return at(timed, m => m.pageMs <= e.ts, 'clock');
|
|
204
|
+
// A whole-second stamp happened somewhere in its second. Placed by the second's start, the paid run of 2026-11-20 (f408c47) put
|
|
205
|
+
// every Wish You Were Hired event one to three steps before the input that sent it. It is placed at the latest step of its second,
|
|
206
|
+
// never after the step it reached the runner by, and `from` says how early it may be.
|
|
207
|
+
if (sane) {
|
|
208
|
+
const lo = at(timed, m => m.pageMs <= e.ts, 'clock');
|
|
209
|
+
let hi = at(timed, m => m.pageMs <= e.ts + 999, 'clock');
|
|
210
|
+
const arrived = at(marks, m => m.realAt <= e.arrivedAt, 'clock');
|
|
211
|
+
if (rank(arrived) < rank(hi)) hi = rank(arrived) < rank(lo) ? lo : arrived;
|
|
212
|
+
const from = rank(lo) < rank(hi) ? (lo.phase === 'before' ? 'before' : lo.step) : null;
|
|
213
|
+
return { ...hi, ...(from !== null ? { from } : {}) };
|
|
214
|
+
}
|
|
197
215
|
}
|
|
198
216
|
return at(marks, m => m.realAt <= e.arrivedAt, 'arrival');
|
|
199
217
|
}
|
|
218
|
+
const rank = p => (p.phase === 'before' ? -1 : p.phase === 'after' ? Infinity : p.step);
|
|
200
219
|
const at = (list, before, by) => {
|
|
201
220
|
let found = null;
|
|
202
221
|
for (const m of list) if (before(m)) found = m;
|
|
@@ -247,13 +266,20 @@ export function createGameEvents({ now = Date.now, limits = EVENT_LIMITS } = {})
|
|
|
247
266
|
const by = placed.reduce((o, e) => { o[e.by] = (o[e.by] || 0) + 1; return o; }, {});
|
|
248
267
|
const names = {};
|
|
249
268
|
for (const e of events) names[e.name] = (names[e.name] || 0) + 1;
|
|
250
|
-
|
|
269
|
+
// `coarse`: events whose timestamp was a whole second, each placed across the steps of that second (`from` to `step`).
|
|
270
|
+
return { total, kept: events.length, dropped, duplicates, untimed, coarse: events.filter(e => e.coarse).length, bodies, clock: by.arrival ? (by.clock ? 'mixed' : 'arrival') : 'clock', names, marks: marks.length, events: placed };
|
|
251
271
|
}
|
|
252
272
|
|
|
253
273
|
return { tap, mark, markPage, flush, pendingForPlan, planned, record, get size() { return events.length; } };
|
|
254
274
|
}
|
|
255
275
|
|
|
256
|
-
|
|
276
|
+
/** Where an event was placed, in words: a step, or the steps a whole-second timestamp spans. */
|
|
277
|
+
const stepWords = e => {
|
|
278
|
+
if (e.phase === 'before') return 'before the first input';
|
|
279
|
+
if (e.phase === 'after') return Number.isSafeInteger(e.from) ? `at step ${e.from} or after play` : 'after play';
|
|
280
|
+
if (e.from === 'before') return `before the first input or at step ${e.step}`;
|
|
281
|
+
return Number.isSafeInteger(e.from) ? `steps ${e.from} to ${e.step}` : `step ${e.step}`;
|
|
282
|
+
};
|
|
257
283
|
|
|
258
284
|
/**
|
|
259
285
|
* Events as short lines for the planner: each kind of event on one line, in
|
|
@@ -327,7 +353,7 @@ export function eventsReportLines(run, { findings = [], turnedAway = [] } = {})
|
|
|
327
353
|
return md;
|
|
328
354
|
}
|
|
329
355
|
const names = Object.entries(g.names).sort((a, b) => b[1] - a[1]);
|
|
330
|
-
md.push(`The game sent ${g.total} analytics event${g.total === 1 ? '' : 's'} through its own Ravensight SDK during this run (${names.slice(0, 8).map(([n, c]) => `${n} ${c}`).join(', ')}${names.length > 8 ? `, and ${names.length - 8} more kinds` : ''}). The runner read them as the game sent them, so they are measured, not judged from the picture. ${g.clock === 'clock' ? 'Each is placed at the step its own timestamp falls in.' : 'Some carried no usable timestamp, so they are placed at the step they reached the runner, which can be a few steps late.'}${g.dropped ? ` ${g.dropped} more were counted and not kept.` : ''}`);
|
|
356
|
+
md.push(`The game sent ${g.total} analytics event${g.total === 1 ? '' : 's'} through its own Ravensight SDK during this run (${names.slice(0, 8).map(([n, c]) => `${n} ${c}`).join(', ')}${names.length > 8 ? `, and ${names.length - 8} more kinds` : ''}). The runner read them as the game sent them, so they are measured, not judged from the picture. ${g.clock === 'clock' ? 'Each is placed at the step its own timestamp falls in.' : 'Some carried no usable timestamp, so they are placed at the step they reached the runner, which can be a few steps late.'}${g.coarse ? ` ${g.coarse === g.kept ? 'Their timestamps are' : `${g.coarse} of them carry timestamps`} in whole seconds, so ${g.coarse === 1 ? 'it is' : 'each is'} placed across the steps of that second.` : ''}${g.dropped ? ` ${g.dropped} more were counted and not kept.` : ''}`);
|
|
331
357
|
md.push('');
|
|
332
358
|
const decided = eventsDecided(run);
|
|
333
359
|
const confirmed = (findings || []).filter(f => decided.get(f.title)?.verdict === 'confirmed');
|
|
@@ -350,5 +376,5 @@ export function eventsUsage(run) {
|
|
|
350
376
|
const g = run?.gameEvents;
|
|
351
377
|
if (!g) return null;
|
|
352
378
|
const decided = [...eventsDecided(run).entries()].map(([title, v]) => ({ title: cleanText(title, 120), verdict: v.verdict, why: v.why, ...(v.fault !== undefined ? { fault: v.fault } : {}) }));
|
|
353
|
-
return { total: g.total, kept: g.kept, dropped: g.dropped, duplicates: g.duplicates, untimed: g.untimed, clock: g.clock, names: g.names, decided, events: g.events.slice(0, EVENT_LIMITS.usageEvents).map(e => ({ step: e.step, phase: e.phase, name: e.name, props: e.props })) };
|
|
379
|
+
return { total: g.total, kept: g.kept, dropped: g.dropped, duplicates: g.duplicates, untimed: g.untimed, ...(g.coarse ? { coarse: g.coarse } : {}), clock: g.clock, names: g.names, decided, events: g.events.slice(0, EVENT_LIMITS.usageEvents).map(e => ({ step: e.step, ...(e.from !== undefined ? { from: e.from } : {}), phase: e.phase, name: e.name, props: e.props })) };
|
|
354
380
|
}
|