@typeonce/ritmo-devtools 0.24.0 → 0.26.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.
- package/CHANGELOG.md +35 -0
- package/README.md +197 -1
- package/dist/Fuzz.d.ts +38 -6
- package/dist/Fuzz.d.ts.map +1 -1
- package/dist/Fuzz.js +37 -11
- package/dist/Fuzz.js.map +1 -1
- package/dist/Replay.d.ts +1 -1
- package/dist/cli.js +171 -3
- package/dist/cli.js.map +1 -1
- package/dist/internal/dependencyScan.js +1 -1
- package/dist/internal/dependencyScan.js.map +1 -1
- package/dist/internal/fuzzNetwork.d.ts +15 -2
- package/dist/internal/fuzzNetwork.d.ts.map +1 -1
- package/dist/internal/fuzzNetwork.js +30 -7
- package/dist/internal/fuzzNetwork.js.map +1 -1
- package/dist/internal/keyboardPage.d.ts +29 -0
- package/dist/internal/keyboardPage.d.ts.map +1 -0
- package/dist/internal/keyboardPage.js +199 -0
- package/dist/internal/keyboardPage.js.map +1 -0
- package/dist/internal/keyboardWalk.d.ts +91 -0
- package/dist/internal/keyboardWalk.d.ts.map +1 -0
- package/dist/internal/keyboardWalk.js +373 -0
- package/dist/internal/keyboardWalk.js.map +1 -0
- package/dist/internal/layoutPage.d.ts +35 -0
- package/dist/internal/layoutPage.d.ts.map +1 -0
- package/dist/internal/layoutPage.js +535 -0
- package/dist/internal/layoutPage.js.map +1 -0
- package/dist/internal/layoutWalk.d.ts +84 -0
- package/dist/internal/layoutWalk.d.ts.map +1 -0
- package/dist/internal/layoutWalk.js +252 -0
- package/dist/internal/layoutWalk.js.map +1 -0
- package/dist/internal/pageOpen.d.ts +86 -0
- package/dist/internal/pageOpen.d.ts.map +1 -0
- package/dist/internal/pageOpen.js +166 -0
- package/dist/internal/pageOpen.js.map +1 -0
- package/dist/internal/route.d.ts +94 -0
- package/dist/internal/route.d.ts.map +1 -0
- package/dist/internal/route.js +230 -0
- package/dist/internal/route.js.map +1 -0
- package/dist/internal/version.d.ts +1 -1
- package/dist/internal/version.js +1 -1
- package/package.json +3 -3
- package/src/Fuzz.ts +62 -11
- package/src/cli.ts +165 -3
- package/src/internal/dependencyScan.ts +1 -1
- package/src/internal/fuzzNetwork.ts +33 -7
- package/src/internal/keyboardPage.ts +198 -0
- package/src/internal/keyboardWalk.ts +474 -0
- package/src/internal/layoutPage.ts +534 -0
- package/src/internal/layoutWalk.ts +365 -0
- package/src/internal/pageOpen.ts +225 -0
- package/src/internal/route.ts +276 -0
- package/src/internal/version.ts +1 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The route file `ritmo-devtools keyboard` and `ritmo-devtools layout` both
|
|
3
|
+
* read: the screens of a game's page, how to reach each one, and what each
|
|
4
|
+
* walk needs to know about them. Each walk ignores the fields that belong to
|
|
5
|
+
* the other (`noPress` is the keyboard walk's; `viewports`, `minTarget`, and
|
|
6
|
+
* `allow` are the layout audit's), so one route serves both.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
import * as Result from "@typeonce/ritmo/Result";
|
|
11
|
+
/** A control a route names: by accessible name, and by role when given. */
|
|
12
|
+
export interface ControlName {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly role?: string;
|
|
15
|
+
}
|
|
16
|
+
/** One thing a route does to reach a screen. */
|
|
17
|
+
export type Step = {
|
|
18
|
+
readonly press: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: string;
|
|
21
|
+
} | {
|
|
22
|
+
readonly click: {
|
|
23
|
+
readonly role: string;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
readonly waitFor: {
|
|
28
|
+
readonly role: string;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
readonly wait: number;
|
|
33
|
+
};
|
|
34
|
+
/** The layout audit's checks that a route may allow, by selector. */
|
|
35
|
+
export type LayoutCheckId = "overlap" | "cut-text" | "off-screen" | "safe-area" | "small-target" | "layout-shift" | "truncated-text" | "scroll-edge";
|
|
36
|
+
export declare const layoutChecks: ReadonlyArray<LayoutCheckId>;
|
|
37
|
+
/**
|
|
38
|
+
* A finding the game means: the layout audit does not report a finding of
|
|
39
|
+
* `check` whose element (or the other element of an overlap) matches
|
|
40
|
+
* `selector` or is inside an element that does.
|
|
41
|
+
*/
|
|
42
|
+
export interface Allow {
|
|
43
|
+
readonly check: LayoutCheckId;
|
|
44
|
+
readonly selector: string;
|
|
45
|
+
}
|
|
46
|
+
/** One screen of the walk: where it starts, how to reach it, what not to press, and what is meant. */
|
|
47
|
+
export interface Screen {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
/** Appended to the URL: `/`, `?map=8`, `#settings`. */
|
|
50
|
+
readonly path: string;
|
|
51
|
+
readonly steps: ReadonlyArray<Step>;
|
|
52
|
+
/** `true` presses nothing on this screen (no `focus-dropped`); a list skips those controls. */
|
|
53
|
+
readonly noPress: true | ReadonlyArray<ControlName>;
|
|
54
|
+
/** Layout findings the game means on this screen (with the route's own `allow`). */
|
|
55
|
+
readonly allow: ReadonlyArray<Allow>;
|
|
56
|
+
}
|
|
57
|
+
/** Space the device keeps for itself on each side (a notch, a home bar), in CSS pixels. */
|
|
58
|
+
export interface Insets {
|
|
59
|
+
readonly top: number;
|
|
60
|
+
readonly right: number;
|
|
61
|
+
readonly bottom: number;
|
|
62
|
+
readonly left: number;
|
|
63
|
+
}
|
|
64
|
+
/** A screen size the layout audit measures every screen at. */
|
|
65
|
+
export interface Viewport {
|
|
66
|
+
readonly name: string;
|
|
67
|
+
readonly width: number;
|
|
68
|
+
readonly height: number;
|
|
69
|
+
/** A touch screen (a phone or a tablet): `hasTouch` and a mobile viewport. */
|
|
70
|
+
readonly touch: boolean;
|
|
71
|
+
readonly insets: Insets;
|
|
72
|
+
}
|
|
73
|
+
export interface Route {
|
|
74
|
+
readonly screens: ReadonlyArray<Screen>;
|
|
75
|
+
/** The sizes the layout audit measures at (`defaultViewports` when the route names none). */
|
|
76
|
+
readonly viewports: ReadonlyArray<Viewport>;
|
|
77
|
+
/** The smallest tap area, in CSS pixels, either side (44 by default). */
|
|
78
|
+
readonly minTarget: number;
|
|
79
|
+
/** Layout findings the game means on every screen. */
|
|
80
|
+
readonly allow: ReadonlyArray<Allow>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A small phone and a phone with a notch, held sideways and upright, and a
|
|
84
|
+
* desktop window. The notch insets are an iPhone's (the camera on one side
|
|
85
|
+
* when sideways, at the top when upright, and the home bar at the bottom).
|
|
86
|
+
*/
|
|
87
|
+
export declare const defaultViewports: ReadonlyArray<Viewport>;
|
|
88
|
+
/** The route of a game that writes none: the start page, as one screen. */
|
|
89
|
+
export declare const startRoute: Route;
|
|
90
|
+
/** Validates a route file's JSON; the error names the field that is wrong. */
|
|
91
|
+
export declare const parseRoute: (value: unknown) => Result.Result<Route, string>;
|
|
92
|
+
/** Joins a screen's path to the base URL, keeping the base's own path. */
|
|
93
|
+
export declare const screenUrl: (base: string, path: string) => string;
|
|
94
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/internal/route.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAEhD,2EAA2E;AAC3E,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,gDAAgD;AAChD,MAAM,MAAM,IAAI,GACZ;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,M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,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACvC,6FAA6F;IAC7F,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC3C,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;CACrC;AAID;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC,QAAQ,CAKpD,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,UAAU,EAAE,KAKxB,CAAA;AA8HD,8EAA8E;AAC9E,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CA+BtE,CAAA;AAED,0EAA0E;AAC1E,eAAO,MAAM,SAAS,SAAU,MAAM,QAAQ,MAAM,KAAG,MAItD,CAAA"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The route file `ritmo-devtools keyboard` and `ritmo-devtools layout` both
|
|
3
|
+
* read: the screens of a game's page, how to reach each one, and what each
|
|
4
|
+
* walk needs to know about them. Each walk ignores the fields that belong to
|
|
5
|
+
* the other (`noPress` is the keyboard walk's; `viewports`, `minTarget`, and
|
|
6
|
+
* `allow` are the layout audit's), so one route serves both.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
import * as Result from "@typeonce/ritmo/Result";
|
|
11
|
+
export const layoutChecks = ["overlap", "cut-text", "off-screen", "safe-area", "small-target", "layout-shift", "truncated-text", "scroll-edge"];
|
|
12
|
+
const isLayoutCheck = (value) => typeof value === "string" && layoutChecks.includes(value);
|
|
13
|
+
const noInsets = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
14
|
+
/**
|
|
15
|
+
* A small phone and a phone with a notch, held sideways and upright, and a
|
|
16
|
+
* desktop window. The notch insets are an iPhone's (the camera on one side
|
|
17
|
+
* when sideways, at the top when upright, and the home bar at the bottom).
|
|
18
|
+
*/
|
|
19
|
+
export const defaultViewports = [
|
|
20
|
+
{ name: "small-phone-landscape", width: 667, height: 375, touch: true, insets: noInsets },
|
|
21
|
+
{ name: "phone-landscape", width: 844, height: 390, touch: true, insets: { top: 0, right: 47, bottom: 21, left: 47 } },
|
|
22
|
+
{ name: "phone-portrait", width: 390, height: 844, touch: true, insets: { top: 47, right: 0, bottom: 34, left: 0 } },
|
|
23
|
+
{ name: "desktop", width: 1280, height: 800, touch: false, insets: noInsets }
|
|
24
|
+
];
|
|
25
|
+
/** The route of a game that writes none: the start page, as one screen. */
|
|
26
|
+
export const startRoute = {
|
|
27
|
+
screens: [{ name: "start", path: "", steps: [], noPress: [], allow: [] }],
|
|
28
|
+
viewports: defaultViewports,
|
|
29
|
+
minTarget: 44,
|
|
30
|
+
allow: []
|
|
31
|
+
};
|
|
32
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
const onlyKeys = (value, keys, at) => {
|
|
34
|
+
const extra = Object.keys(value).find((key) => !keys.includes(key));
|
|
35
|
+
return extra === undefined ? undefined : `${at}.${extra} is not a field (expected ${keys.join(", ")})`;
|
|
36
|
+
};
|
|
37
|
+
const nonEmpty = (value) => typeof value === "string" && value.trim() !== "";
|
|
38
|
+
const wholeIn = (value, least, most) => typeof value === "number" && Number.isInteger(value) && value >= least && value <= most;
|
|
39
|
+
const parseControlName = (value, at) => {
|
|
40
|
+
if (!isRecord(value))
|
|
41
|
+
return Result.failure(`${at} must be an object { "name": string, "role"?: string }`);
|
|
42
|
+
const extra = onlyKeys(value, ["name", "role"], at);
|
|
43
|
+
if (extra !== undefined)
|
|
44
|
+
return Result.failure(extra);
|
|
45
|
+
if (!nonEmpty(value["name"]))
|
|
46
|
+
return Result.failure(`${at}.name must be a non-empty string: the control's accessible name`);
|
|
47
|
+
if (value["role"] !== undefined && !nonEmpty(value["role"]))
|
|
48
|
+
return Result.failure(`${at}.role must be a non-empty string when given: an ARIA role such as "button"`);
|
|
49
|
+
return Result.success(value["role"] === undefined ? { name: value["name"] } : { name: value["name"], role: value["role"] });
|
|
50
|
+
};
|
|
51
|
+
const stepKinds = `{ "press": "Escape" }, { "type": "Ada" }, { "click": { "role": "button", "name": "Play" } }, { "waitFor": { "role": "button", "name": "Play" } }, { "wait": 500 }`;
|
|
52
|
+
const parseStep = (value, at) => {
|
|
53
|
+
if (!isRecord(value) || Object.keys(value).length !== 1)
|
|
54
|
+
return Result.failure(`${at} must be one of ${stepKinds}`);
|
|
55
|
+
if ("press" in value) {
|
|
56
|
+
return nonEmpty(value["press"]) ? Result.success({ press: value["press"] }) : Result.failure(`${at}.press must be a key name, as Playwright's keyboard.press takes it ("Enter", "Escape", "a")`);
|
|
57
|
+
}
|
|
58
|
+
if ("type" in value) {
|
|
59
|
+
return typeof value["type"] === "string" && value["type"] !== "" ? Result.success({ type: value["type"] }) : Result.failure(`${at}.type must be the text to type into the focused field ("Ada")`);
|
|
60
|
+
}
|
|
61
|
+
if ("wait" in value) {
|
|
62
|
+
const wait = value["wait"];
|
|
63
|
+
return wholeIn(wait, 0, 60_000) ? Result.success({ wait }) : Result.failure(`${at}.wait must be a whole number of milliseconds from 0 to 60000`);
|
|
64
|
+
}
|
|
65
|
+
for (const kind of ["click", "waitFor"]) {
|
|
66
|
+
if (!(kind in value))
|
|
67
|
+
continue;
|
|
68
|
+
const named = value[kind];
|
|
69
|
+
if (!isRecord(named))
|
|
70
|
+
return Result.failure(`${at}.${kind} must be an object { "role": string, "name": string }`);
|
|
71
|
+
const extra = onlyKeys(named, ["role", "name"], `${at}.${kind}`);
|
|
72
|
+
if (extra !== undefined)
|
|
73
|
+
return Result.failure(extra);
|
|
74
|
+
if (!nonEmpty(named["role"]))
|
|
75
|
+
return Result.failure(`${at}.${kind}.role must be a non-empty string: an ARIA role such as "button"`);
|
|
76
|
+
if (!nonEmpty(named["name"]))
|
|
77
|
+
return Result.failure(`${at}.${kind}.name must be a non-empty string: the control's accessible name`);
|
|
78
|
+
const control = { role: named["role"], name: named["name"] };
|
|
79
|
+
return Result.success(kind === "click" ? { click: control } : { waitFor: control });
|
|
80
|
+
}
|
|
81
|
+
return Result.failure(`${at} must be one of ${stepKinds}; ${Object.keys(value)[0]} is not a step`);
|
|
82
|
+
};
|
|
83
|
+
const parseAllow = (value, at) => {
|
|
84
|
+
const raw = value ?? [];
|
|
85
|
+
if (!Array.isArray(raw))
|
|
86
|
+
return Result.failure(`${at} must be an array of { "check", "selector" }`);
|
|
87
|
+
const allow = [];
|
|
88
|
+
for (const [index, entry] of raw.entries()) {
|
|
89
|
+
const where = `${at}[${index}]`;
|
|
90
|
+
if (!isRecord(entry))
|
|
91
|
+
return Result.failure(`${where} must be an object { "check": string, "selector": string }`);
|
|
92
|
+
const extra = onlyKeys(entry, ["check", "selector"], where);
|
|
93
|
+
if (extra !== undefined)
|
|
94
|
+
return Result.failure(extra);
|
|
95
|
+
if (!isLayoutCheck(entry["check"]))
|
|
96
|
+
return Result.failure(`${where}.check must be one of ${layoutChecks.join(", ")}`);
|
|
97
|
+
if (!nonEmpty(entry["selector"]))
|
|
98
|
+
return Result.failure(`${where}.selector must be a CSS selector of the element the finding names, such as ".card .badge"`);
|
|
99
|
+
allow.push({ check: entry["check"], selector: entry["selector"] });
|
|
100
|
+
}
|
|
101
|
+
return Result.success(allow);
|
|
102
|
+
};
|
|
103
|
+
const parseScreen = (value, at) => {
|
|
104
|
+
if (!isRecord(value))
|
|
105
|
+
return Result.failure(`${at} must be an object { "name", "path"?, "steps"?, "noPress"?, "allow"? }`);
|
|
106
|
+
const extra = onlyKeys(value, ["name", "path", "steps", "noPress", "allow"], at);
|
|
107
|
+
if (extra !== undefined)
|
|
108
|
+
return Result.failure(extra);
|
|
109
|
+
if (!nonEmpty(value["name"]))
|
|
110
|
+
return Result.failure(`${at}.name must be a non-empty string`);
|
|
111
|
+
const path = value["path"] ?? "";
|
|
112
|
+
if (typeof path !== "string")
|
|
113
|
+
return Result.failure(`${at}.path must be a string appended to the URL ("/", "?map=8")`);
|
|
114
|
+
const rawSteps = value["steps"] ?? [];
|
|
115
|
+
if (!Array.isArray(rawSteps))
|
|
116
|
+
return Result.failure(`${at}.steps must be an array`);
|
|
117
|
+
const steps = [];
|
|
118
|
+
for (const [index, raw] of rawSteps.entries()) {
|
|
119
|
+
const step = parseStep(raw, `${at}.steps[${index}]`);
|
|
120
|
+
if (!step.ok)
|
|
121
|
+
return step;
|
|
122
|
+
steps.push(step.value);
|
|
123
|
+
}
|
|
124
|
+
const allow = parseAllow(value["allow"], `${at}.allow`);
|
|
125
|
+
if (!allow.ok)
|
|
126
|
+
return allow;
|
|
127
|
+
const rawNoPress = value["noPress"] ?? [];
|
|
128
|
+
if (rawNoPress === true)
|
|
129
|
+
return Result.success({ name: value["name"], path, steps, noPress: true, allow: allow.value });
|
|
130
|
+
if (!Array.isArray(rawNoPress))
|
|
131
|
+
return Result.failure(`${at}.noPress must be true (press nothing on this screen) or an array of { "name", "role"? }`);
|
|
132
|
+
const noPress = [];
|
|
133
|
+
for (const [index, raw] of rawNoPress.entries()) {
|
|
134
|
+
const control = parseControlName(raw, `${at}.noPress[${index}]`);
|
|
135
|
+
if (!control.ok)
|
|
136
|
+
return control;
|
|
137
|
+
noPress.push(control.value);
|
|
138
|
+
}
|
|
139
|
+
return Result.success({ name: value["name"], path, steps, noPress, allow: allow.value });
|
|
140
|
+
};
|
|
141
|
+
const parseViewport = (value, at) => {
|
|
142
|
+
if (!isRecord(value))
|
|
143
|
+
return Result.failure(`${at} must be an object { "name", "width", "height", "touch"?, "insets"? }`);
|
|
144
|
+
const extra = onlyKeys(value, ["name", "width", "height", "touch", "insets"], at);
|
|
145
|
+
if (extra !== undefined)
|
|
146
|
+
return Result.failure(extra);
|
|
147
|
+
if (!nonEmpty(value["name"]))
|
|
148
|
+
return Result.failure(`${at}.name must be a non-empty string`);
|
|
149
|
+
if (!wholeIn(value["width"], 200, 4000))
|
|
150
|
+
return Result.failure(`${at}.width must be a whole number of CSS pixels from 200 to 4000`);
|
|
151
|
+
if (!wholeIn(value["height"], 200, 4000))
|
|
152
|
+
return Result.failure(`${at}.height must be a whole number of CSS pixels from 200 to 4000`);
|
|
153
|
+
const touch = value["touch"] ?? false;
|
|
154
|
+
if (typeof touch !== "boolean")
|
|
155
|
+
return Result.failure(`${at}.touch must be true (a phone or tablet) or false`);
|
|
156
|
+
const rawInsets = value["insets"] ?? noInsets;
|
|
157
|
+
if (!isRecord(rawInsets))
|
|
158
|
+
return Result.failure(`${at}.insets must be an object { "top", "right", "bottom", "left" } of CSS pixels`);
|
|
159
|
+
const insetsExtra = onlyKeys(rawInsets, ["top", "right", "bottom", "left"], `${at}.insets`);
|
|
160
|
+
if (insetsExtra !== undefined)
|
|
161
|
+
return Result.failure(insetsExtra);
|
|
162
|
+
const sides = ["top", "right", "bottom", "left"];
|
|
163
|
+
for (const side of sides) {
|
|
164
|
+
if (!wholeIn(rawInsets[side] ?? 0, 0, 200))
|
|
165
|
+
return Result.failure(`${at}.insets.${side} must be a whole number of CSS pixels from 0 to 200`);
|
|
166
|
+
}
|
|
167
|
+
const inset = (side) => {
|
|
168
|
+
const given = rawInsets[side];
|
|
169
|
+
return typeof given === "number" ? given : 0;
|
|
170
|
+
};
|
|
171
|
+
return Result.success({
|
|
172
|
+
name: value["name"],
|
|
173
|
+
width: value["width"],
|
|
174
|
+
height: value["height"],
|
|
175
|
+
touch,
|
|
176
|
+
insets: { top: inset("top"), right: inset("right"), bottom: inset("bottom"), left: inset("left") }
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/** Validates a route file's JSON; the error names the field that is wrong. */
|
|
180
|
+
export const parseRoute = (value) => {
|
|
181
|
+
if (!isRecord(value))
|
|
182
|
+
return Result.failure(`the route must be an object { "screens": [...] }`);
|
|
183
|
+
const extra = onlyKeys(value, ["screens", "viewports", "minTarget", "allow"], "route");
|
|
184
|
+
if (extra !== undefined)
|
|
185
|
+
return Result.failure(extra);
|
|
186
|
+
const raw = value["screens"];
|
|
187
|
+
if (!Array.isArray(raw) || raw.length === 0)
|
|
188
|
+
return Result.failure(`route.screens must be a non-empty array`);
|
|
189
|
+
const screens = [];
|
|
190
|
+
for (const [index, entry] of raw.entries()) {
|
|
191
|
+
const screen = parseScreen(entry, `route.screens[${index}]`);
|
|
192
|
+
if (!screen.ok)
|
|
193
|
+
return screen;
|
|
194
|
+
if (screens.some((other) => other.name === screen.value.name))
|
|
195
|
+
return Result.failure(`route.screens[${index}].name "${screen.value.name}" is already the name of another screen`);
|
|
196
|
+
screens.push(screen.value);
|
|
197
|
+
}
|
|
198
|
+
let viewports = defaultViewports;
|
|
199
|
+
if (value["viewports"] !== undefined) {
|
|
200
|
+
const rawViewports = value["viewports"];
|
|
201
|
+
if (!Array.isArray(rawViewports) || rawViewports.length === 0)
|
|
202
|
+
return Result.failure(`route.viewports must be a non-empty array of { "name", "width", "height", "touch"?, "insets"? }`);
|
|
203
|
+
const parsed = [];
|
|
204
|
+
for (const [index, entry] of rawViewports.entries()) {
|
|
205
|
+
const viewport = parseViewport(entry, `route.viewports[${index}]`);
|
|
206
|
+
if (!viewport.ok)
|
|
207
|
+
return viewport;
|
|
208
|
+
if (parsed.some((other) => other.name === viewport.value.name))
|
|
209
|
+
return Result.failure(`route.viewports[${index}].name "${viewport.value.name}" is already the name of another viewport`);
|
|
210
|
+
parsed.push(viewport.value);
|
|
211
|
+
}
|
|
212
|
+
viewports = parsed;
|
|
213
|
+
}
|
|
214
|
+
const minTarget = value["minTarget"] ?? 44;
|
|
215
|
+
if (!wholeIn(minTarget, 1, 200))
|
|
216
|
+
return Result.failure(`route.minTarget must be a whole number of CSS pixels from 1 to 200 (the smallest tap area either side)`);
|
|
217
|
+
const allow = parseAllow(value["allow"], "route.allow");
|
|
218
|
+
if (!allow.ok)
|
|
219
|
+
return allow;
|
|
220
|
+
return Result.success({ screens, viewports, minTarget, allow: allow.value });
|
|
221
|
+
};
|
|
222
|
+
/** Joins a screen's path to the base URL, keeping the base's own path. */
|
|
223
|
+
export const screenUrl = (base, path) => {
|
|
224
|
+
if (path === "")
|
|
225
|
+
return base;
|
|
226
|
+
if (path.startsWith("?") || path.startsWith("#"))
|
|
227
|
+
return base.replace(/[?#].*$/, "") + path;
|
|
228
|
+
return new URL(path, base).href;
|
|
229
|
+
};
|
|
230
|
+
//# sourceMappingURL=route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/internal/route.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AA2BhD,MAAM,CAAC,MAAM,YAAY,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAAA;AAE7K,MAAM,aAAa,GAAG,CAAC,KAAc,EAA0B,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAK,YAAsC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAoDtJ,MAAM,QAAQ,GAAW,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;AAEjE;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA4B;IACvD,EAAE,IAAI,EAAE,uBAAuB,EAAE,KA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AAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,CAAA;IACvD,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,OAAO,KAAK,CAAA;IAC3B,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA;AAC9E,CAAC,CAAA;AAED,0EAA0E;AAC1E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE;IAC9D,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,IAAI,CAAA;IAC5B,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,IAAI,CAAA;IAC3F,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,CAAA;AACjC,CAAC,CAAA"}
|
package/dist/internal/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typeonce/ritmo-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Headless debug sessions, trace history, text reports, replays, and fuzzing for Ritmo runtimes",
|
|
5
5
|
"author": "Sandro Maglione",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"provenance": true
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@typeonce/ritmo": "^0.
|
|
55
|
-
"@typeonce/ritmo-netcode": "^0.
|
|
54
|
+
"@typeonce/ritmo": "^0.26.0",
|
|
55
|
+
"@typeonce/ritmo-netcode": "^0.26.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"oxlint": ">=1.86.0",
|
package/src/Fuzz.ts
CHANGED
|
@@ -24,9 +24,11 @@
|
|
|
24
24
|
* from `make`, joined to the others by a seeded `MemoryNetworkLink`
|
|
25
25
|
* (latency, jitter, loss) and driven by a `Netcode.rollback` session. A
|
|
26
26
|
* desync, or any other session failure, is a `SessionFailed` violation, and
|
|
27
|
-
* shrinking shrinks the input timeline with the network seed fixed.
|
|
28
|
-
* `
|
|
29
|
-
*
|
|
27
|
+
* shrinking shrinks the input timeline with the network seed fixed. With
|
|
28
|
+
* `network.leave`, seats also leave the match for good on frames drawn from
|
|
29
|
+
* the run's seed, so what the game does with a seat that has no driver is
|
|
30
|
+
* fuzzed too. Run `Netcode.syncTest` first: it finds state a rewind cannot
|
|
31
|
+
* put back on one peer, faster.
|
|
30
32
|
*
|
|
31
33
|
* @module Fuzz
|
|
32
34
|
* @docGroup devtools
|
|
@@ -111,13 +113,16 @@ export interface Seats<Name extends string = string, Data = unknown> extends Inp
|
|
|
111
113
|
readonly count: number
|
|
112
114
|
/** The input of a seat that pressed nothing, as given to `Netcode.seats`. */
|
|
113
115
|
readonly idle: Data
|
|
116
|
+
/** The input of a seat that left the match, as given to `Netcode.seats` (`idle` when the game gives none). */
|
|
117
|
+
readonly left: Data
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
/**
|
|
117
121
|
* Declares how to fuzz the seats of a networked game: the
|
|
118
|
-
* `Netcode.Source` service its simulation captures, the input `codec
|
|
119
|
-
* `idle` input
|
|
120
|
-
* `generate` for one seat's input on a
|
|
122
|
+
* `Netcode.Source` service its simulation captures, the input `codec`,
|
|
123
|
+
* `idle` input, and `left` input (when it has one) the game gives
|
|
124
|
+
* `Netcode.seats`, `count` seats, and `generate` for one seat's input on a
|
|
125
|
+
* frame. Pass it as the only input of a
|
|
121
126
|
* `run` with `network`; `make` provides the service with
|
|
122
127
|
* `playback.source(descriptor)` (over a network, that is the peer's
|
|
123
128
|
* `seats.source`). Use `input` for a game without seats.
|
|
@@ -129,12 +134,14 @@ export const seats = <const Name extends string, const C extends CoreDescriptor.
|
|
|
129
134
|
readonly count: number
|
|
130
135
|
readonly generate: (random: Random.Random, frame: number, seat: number) => NoInfer<CoreDescriptor.CodecType<C>>
|
|
131
136
|
readonly idle: NoInfer<CoreDescriptor.CodecType<C>>
|
|
137
|
+
readonly left?: NoInfer<CoreDescriptor.CodecType<C>>
|
|
132
138
|
}
|
|
133
139
|
): Seats<Name, CoreDescriptor.CodecType<C>> => ({
|
|
134
140
|
name: descriptor.name,
|
|
135
141
|
codec: options.codec,
|
|
136
142
|
count: options.count,
|
|
137
143
|
idle: options.idle,
|
|
144
|
+
left: options.left === undefined ? options.idle : options.left,
|
|
138
145
|
neutral: Array.from({ length: options.count }, () => options.idle),
|
|
139
146
|
generate: (random, frame) => Array.from({ length: options.count }, (_, seat) => options.generate(random, frame, seat))
|
|
140
147
|
})
|
|
@@ -160,6 +167,21 @@ export interface Network {
|
|
|
160
167
|
readonly maxRollback?: number
|
|
161
168
|
/** Ticks between checksum comparisons (10 by default here, to find a desync close to its cause). */
|
|
162
169
|
readonly checksumEvery?: number
|
|
170
|
+
/**
|
|
171
|
+
* Makes up to `seats` seats leave the match for good in each run (a whole
|
|
172
|
+
* number from 1 to the seats' `count - 2`, so two peers always play on):
|
|
173
|
+
* which ones, and on which frame, are drawn from the run's seed. Such a
|
|
174
|
+
* seat's page is gone (its link closes and it runs no more), and every
|
|
175
|
+
* peer still there is told with `session.drop` once the link's latency
|
|
176
|
+
* passed, as a relay that saw the socket close tells them. From the tick
|
|
177
|
+
* the peers agree on, the simulation reads the seats' `left` input for it:
|
|
178
|
+
* invariants are checked on the peers still there, and a peer that halts
|
|
179
|
+
* or ends is a `SessionFailed` violation, so a rule of the game that
|
|
180
|
+
* breaks without a driver, or a system that is not deterministic about
|
|
181
|
+
* it, is found like any other bug. Shrinking keeps the seats and frames
|
|
182
|
+
* of the run that failed.
|
|
183
|
+
*/
|
|
184
|
+
readonly leave?: { readonly seats: number }
|
|
163
185
|
}
|
|
164
186
|
|
|
165
187
|
/** What `run` fuzzes, how long, and how hard it shrinks. */
|
|
@@ -231,6 +253,12 @@ export interface Found {
|
|
|
231
253
|
* (the failing frame, but over a `network`, where a desync shows a few frames after its cause).
|
|
232
254
|
*/
|
|
233
255
|
readonly shrink: { readonly attempts: number; readonly steps: number; readonly fromFrames: number; readonly toFrames: number }
|
|
256
|
+
/**
|
|
257
|
+
* With `network.leave`: the seats that left in the failing run, and the
|
|
258
|
+
* frame each one's page was gone from. The replay holds the seats' `left`
|
|
259
|
+
* input for them from that frame on. Empty otherwise.
|
|
260
|
+
*/
|
|
261
|
+
readonly left: ReadonlyArray<{ readonly seat: number; readonly frame: number }>
|
|
234
262
|
}
|
|
235
263
|
|
|
236
264
|
/** A run failed, but the same input did not fail again: the simulation reads something besides its input. */
|
|
@@ -404,8 +432,11 @@ export const run = <
|
|
|
404
432
|
const seated = only as Seats
|
|
405
433
|
const settle = network.settle ?? 120
|
|
406
434
|
if (!Number.isSafeInteger(settle) || settle < 0) return invalid("network.settle must be a whole number, 0 or more")
|
|
435
|
+
if (network.leave !== undefined && (!Number.isSafeInteger(network.leave.seats) || network.leave.seats < 1 || network.leave.seats > seated.count - 2)) {
|
|
436
|
+
return invalid(`network.leave.seats must be a whole number from 1 to ${seated.count - 2}: two of the ${seated.count} seats play on, or a session ends for want of another seat`)
|
|
437
|
+
}
|
|
407
438
|
plan = {
|
|
408
|
-
name: seated.name, codec: seated.codec, count: seated.count, idle: seated.idle,
|
|
439
|
+
name: seated.name, codec: seated.codec, count: seated.count, idle: seated.idle, left: seated.left,
|
|
409
440
|
make, schedule: options.schedule, setup: options.setup, invariants: options.invariants ?? [],
|
|
410
441
|
step: network.step, seed: network.seed, latencyMS: network.latencyMS, jitterMS: network.jitterMS ?? 0, loss: network.loss ?? 0, settle,
|
|
411
442
|
inputDelay: network.inputDelay, maxRollback: network.maxRollback, checksumEvery: network.checksumEvery ?? 10
|
|
@@ -483,13 +514,21 @@ export const run = <
|
|
|
483
514
|
return { kind: "violated", violation: found, frame, file }
|
|
484
515
|
}
|
|
485
516
|
|
|
486
|
-
/**
|
|
517
|
+
/** The seats that leave in the run being played, and the frame each one's page is gone from. */
|
|
518
|
+
let leaves: ReadonlyArray<FuzzNetwork.Leave> = []
|
|
519
|
+
|
|
520
|
+
/** Over the network: every seat on its own peer. The replay plays the same timeline on one runtime, with the `left` input for a seat from the frame it left on. */
|
|
487
521
|
const simulate = (timeline: Timeline, record: ((violation: Violation, frame: number) => string) | undefined): Outcome => {
|
|
488
522
|
if (plan === undefined) return simulateOne(timeline, record)
|
|
489
|
-
const played = FuzzNetwork.play(plan, timeline)
|
|
523
|
+
const played = FuzzNetwork.play(plan, timeline, leaves)
|
|
490
524
|
if (played.kind === "invalid") return { kind: "invalid", error: { _tag: "InvalidOptions", message: played.message } }
|
|
491
525
|
if (played.kind === "passed") return played
|
|
492
|
-
const
|
|
526
|
+
const { left } = plan
|
|
527
|
+
// With seats that left, the replay runs to the failing frame, so it shows the ticks they sat out after the last press.
|
|
528
|
+
const without = leaves.length === 0 ? timeline : Array.from({ length: played.frame }, (_, frame) => [
|
|
529
|
+
((timeline[frame] ?? neutral)[0] as ReadonlyArray<unknown>).map((value, seat) => leaves.some((leave) => leave.seat === seat && leave.frame <= frame) ? left : value)
|
|
530
|
+
])
|
|
531
|
+
const one = record === undefined ? undefined : simulateOne(without.slice(0, played.frame), record(played.violation, played.frame))
|
|
493
532
|
return { kind: "violated", violation: played.violation, frame: played.frame, file: one?.kind === "invalid" ? undefined : one?.file }
|
|
494
533
|
}
|
|
495
534
|
|
|
@@ -498,6 +537,17 @@ export const run = <
|
|
|
498
537
|
const random = Random.make(seed)
|
|
499
538
|
const timeline: Array<ReadonlyArray<unknown>> = []
|
|
500
539
|
for (let frame = 1; frame <= options.frames; frame++) timeline.push(inputs.map((entry) => entry.generate(random, frame)))
|
|
540
|
+
// Drawn after the timeline, so the same seed presses the same inputs with and without `leave`.
|
|
541
|
+
leaves = []
|
|
542
|
+
if (plan !== undefined && network?.leave !== undefined) {
|
|
543
|
+
const seats = Array.from({ length: plan.count }, (_, seat) => seat)
|
|
544
|
+
const drawn: Array<FuzzNetwork.Leave> = []
|
|
545
|
+
for (let left = random.integer(1, network.leave.seats + 1); left > 0; left--) {
|
|
546
|
+
const [seat] = seats.splice(random.integer(0, seats.length), 1)
|
|
547
|
+
drawn.push({ seat: seat!, frame: random.integer(0, options.frames) })
|
|
548
|
+
}
|
|
549
|
+
leaves = drawn.sort((one, other) => one.frame - other.frame || one.seat - other.seat)
|
|
550
|
+
}
|
|
501
551
|
const first = simulate(timeline, undefined)
|
|
502
552
|
if (first.kind === "invalid") return Result.failure(first.error)
|
|
503
553
|
if (first.kind === "passed") continue
|
|
@@ -555,7 +605,8 @@ export const run = <
|
|
|
555
605
|
frame: final.frame,
|
|
556
606
|
replay: final.file,
|
|
557
607
|
reproduces: replayed !== undefined && replayed._tag !== "InvalidOptions" && signature(replayed) === target,
|
|
558
|
-
shrink: { attempts, steps, fromFrames: Math.min(first.frame, timeline.length), toFrames: best.length }
|
|
608
|
+
shrink: { attempts, steps, fromFrames: Math.min(first.frame, timeline.length), toFrames: best.length },
|
|
609
|
+
left: leaves
|
|
559
610
|
})
|
|
560
611
|
}
|
|
561
612
|
return Result.success(Rendered.make(
|