@specter-automation/test 1.0.137 → 1.0.139

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.
@@ -16,13 +16,18 @@ export type BehaviorTrailEvent =
16
16
  path: string[];
17
17
  from: string;
18
18
  }
19
- /** A blackboard key changed value */
19
+ /**
20
+ * A blackboard key changed value. A key that kept changing (one set every frame, like a distance) is one event:
21
+ * `from` its first value `to` its latest, with `changes` how many there were and `until` when the last one was.
22
+ */
20
23
  | {
21
24
  t: number;
22
25
  kind: 'blackboard';
23
26
  key: string;
24
27
  from: string;
25
28
  to: string;
29
+ changes?: number;
30
+ until?: number;
26
31
  }
27
32
  /** The tree it runs changed (started, stopped, or swapped for another) */
28
33
  | {
@@ -33,8 +33,10 @@ function describeEvent(event) {
33
33
  switch (event.kind) {
34
34
  case 'active':
35
35
  return `▸ ${describeNodePath(event.path)}`;
36
- case 'blackboard':
37
- return `${event.key}: ${clip(event.from)} → ${clip(event.to)}`;
36
+ case 'blackboard': {
37
+ const repeated = event.changes && event.changes > 1 ? ` (${event.changes} changes until ${(event.until ?? event.t).toFixed(2)}s)` : '';
38
+ return `${event.key}: ${clip(event.from)} → ${clip(event.to)}${repeated}`;
39
+ }
38
40
  case 'tree':
39
41
  if (!event.to)
40
42
  return `Stopped running ${event.from}`;
@@ -34,7 +34,9 @@ export declare enum SpecterEventType {
34
34
  AssertionFailure = "AssertionFailure",
35
35
  GameEvent = "GameEvent",
36
36
  GameplayTag = "GameplayTag",
37
- DiagnosticWarning = "DiagnosticWarning"
37
+ DiagnosticWarning = "DiagnosticWarning",
38
+ /** An AI's logic moved, a blackboard key changed, or its tree started or finished (the AI trail) */
39
+ AIState = "AIState"
38
40
  }
39
41
  export interface SpecterTimelineEvent {
40
42
  timestamp: number;
@@ -19,6 +19,8 @@ var SpecterEventType;
19
19
  SpecterEventType["GameEvent"] = "GameEvent";
20
20
  SpecterEventType["GameplayTag"] = "GameplayTag";
21
21
  SpecterEventType["DiagnosticWarning"] = "DiagnosticWarning";
22
+ /** An AI's logic moved, a blackboard key changed, or its tree started or finished (the AI trail) */
23
+ SpecterEventType["AIState"] = "AIState";
22
24
  })(SpecterEventType || (exports.SpecterEventType = SpecterEventType = {}));
23
25
  exports.VectorUtils = {
24
26
  addOffset: (location, direction, offset) => {
@@ -3,6 +3,11 @@ export default class SpecterReporter implements Reporter {
3
3
  private ws;
4
4
  private isConnected;
5
5
  private queue;
6
+ /** Connection attempts since the last one that opened (the engine may not be listening yet) */
7
+ private connectAttempts;
8
+ private reconnectTimer;
9
+ /** Set when the run has ended: no more reconnecting */
10
+ private runEnded;
6
11
  private testStepCounters;
7
12
  private stepIdMap;
8
13
  /** Playwright's outer `Expect "<matcher>"` steps for Specter matchers. They are shown under their wrapper step's name. */
@@ -24,6 +29,15 @@ export default class SpecterReporter implements Reporter {
24
29
  private runFrameFolders;
25
30
  constructor();
26
31
  private connect;
32
+ /**
33
+ * The engine isn't always listening when the run starts: a run started from the editor starts PIE at the same
34
+ * time, and the game's server only opens once PIE is up. Keep trying (every half second, for two minutes) so the
35
+ * run's events, queued meanwhile, still reach it. Without this the runner, the AI trail and the performance panel
36
+ * heard nothing from runs that started PIE themselves.
37
+ */
38
+ private scheduleReconnect;
39
+ private static readonly RECONNECT_DELAY_MS;
40
+ private static readonly MAX_CONNECT_ATTEMPTS;
27
41
  /**
28
42
  * The engine broadcasts everything to every client, so most messages here are other clients' command
29
43
  * responses. Only the ones about the run's replay and the tests' preview frames matter to the reporter.
@@ -134,6 +134,11 @@ class SpecterReporter {
134
134
  ws = null;
135
135
  isConnected = false;
136
136
  queue = [];
137
+ /** Connection attempts since the last one that opened (the engine may not be listening yet) */
138
+ connectAttempts = 0;
139
+ reconnectTimer = null;
140
+ /** Set when the run has ended: no more reconnecting */
141
+ runEnded = false;
137
142
  testStepCounters = new Map();
138
143
  stepIdMap = new WeakMap();
139
144
  /** Playwright's outer `Expect "<matcher>"` steps for Specter matchers. They are shown under their wrapper step's name. */
@@ -162,6 +167,7 @@ class SpecterReporter {
162
167
  this.ws = socket;
163
168
  socket.on('open', () => {
164
169
  this.isConnected = true;
170
+ this.connectAttempts = 0;
165
171
  // Send any queued messages
166
172
  while (this.queue.length > 0) {
167
173
  const msg = this.queue.shift();
@@ -174,13 +180,39 @@ class SpecterReporter {
174
180
  });
175
181
  socket.on('close', () => {
176
182
  this.isConnected = false;
177
- // Nothing more will arrive: stop waiting for the replay
183
+ if (this.ws === socket) {
184
+ this.ws = null;
185
+ }
186
+ // Nothing more will arrive on this connection: stop waiting for the replay
178
187
  this.releaseReplayWaiters();
188
+ this.scheduleReconnect();
179
189
  });
180
190
  socket.on('message', (data) => {
181
191
  this.handleEngineMessage(data);
182
192
  });
183
193
  }
194
+ /**
195
+ * The engine isn't always listening when the run starts: a run started from the editor starts PIE at the same
196
+ * time, and the game's server only opens once PIE is up. Keep trying (every half second, for two minutes) so the
197
+ * run's events, queued meanwhile, still reach it. Without this the runner, the AI trail and the performance panel
198
+ * heard nothing from runs that started PIE themselves.
199
+ */
200
+ scheduleReconnect() {
201
+ if (this.runEnded || this.reconnectTimer || this.connectAttempts >= SpecterReporter.MAX_CONNECT_ATTEMPTS) {
202
+ return;
203
+ }
204
+ this.connectAttempts++;
205
+ this.reconnectTimer = setTimeout(() => {
206
+ this.reconnectTimer = null;
207
+ if (!this.runEnded) {
208
+ this.connect();
209
+ }
210
+ }, SpecterReporter.RECONNECT_DELAY_MS);
211
+ // Waiting to reconnect never keeps the run's process alive
212
+ this.reconnectTimer.unref?.();
213
+ }
214
+ static RECONNECT_DELAY_MS = 500;
215
+ static MAX_CONNECT_ATTEMPTS = 240;
184
216
  /**
185
217
  * The engine broadcasts everything to every client, so most messages here are other clients' command
186
218
  * responses. Only the ones about the run's replay and the tests' preview frames matter to the reporter.
@@ -1004,6 +1036,11 @@ class SpecterReporter {
1004
1036
  }
1005
1037
  });
1006
1038
  await this.saveRunTrace(result);
1039
+ this.runEnded = true;
1040
+ if (this.reconnectTimer) {
1041
+ clearTimeout(this.reconnectTimer);
1042
+ this.reconnectTimer = null;
1043
+ }
1007
1044
  }
1008
1045
  }
1009
1046
  exports.default = SpecterReporter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specter-automation/test",
3
- "version": "1.0.137",
3
+ "version": "1.0.139",
4
4
  "description": "Playwright integration for Unreal Engine automation via Specter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",