@specter-automation/test 1.0.117 → 1.0.118

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.
@@ -191,6 +191,15 @@ export declare class SpecterTransport {
191
191
  get port(): string;
192
192
  get friendlyPortTag(): string;
193
193
  constructor(url?: string);
194
+ /**
195
+ * Probes the Editor Control Server (default port 8079) and requests PIE to start.
196
+ * Returns true if the editor acknowledged the request, false otherwise.
197
+ */
198
+ static requestEditorPIE(editorUrl?: string): Promise<boolean>;
199
+ /**
200
+ * Sends a command to the Editor Control Server (e.g. 'stopPIE', 'getStatus').
201
+ */
202
+ static sendEditorCommand(command: string, editorUrl?: string): Promise<any>;
194
203
  connect(timeoutMs?: number): Promise<void>;
195
204
  private setupMessageRouter;
196
205
  sendCommand(payload: SpecterPayload): Promise<any>;
@@ -82,12 +82,123 @@ class SpecterTransport {
82
82
  SpecterTransport.instance = this;
83
83
  }
84
84
  }
85
+ /**
86
+ * Probes the Editor Control Server (default port 8079) and requests PIE to start.
87
+ * Returns true if the editor acknowledged the request, false otherwise.
88
+ */
89
+ static async requestEditorPIE(editorUrl = 'ws://127.0.0.1:8079') {
90
+ return new Promise((resolve) => {
91
+ let settled = false;
92
+ const finish = (result) => {
93
+ if (!settled) {
94
+ settled = true;
95
+ resolve(result);
96
+ }
97
+ };
98
+ const timer = setTimeout(() => {
99
+ try {
100
+ socket.close();
101
+ }
102
+ catch (e) { }
103
+ finish(false);
104
+ }, 2500);
105
+ let socket;
106
+ try {
107
+ socket = new ws_1.default(editorUrl);
108
+ }
109
+ catch (e) {
110
+ clearTimeout(timer);
111
+ return finish(false);
112
+ }
113
+ socket.on('open', () => {
114
+ const req = JSON.stringify({
115
+ command: 'requestPIE',
116
+ messageId: 'auto-pie-start'
117
+ });
118
+ socket.send(req);
119
+ });
120
+ socket.on('message', (data) => {
121
+ try {
122
+ const parsed = JSON.parse(data.toString('utf-8'));
123
+ if (parsed.status === 'success') {
124
+ clearTimeout(timer);
125
+ try {
126
+ socket.close();
127
+ }
128
+ catch (e) { }
129
+ finish(true);
130
+ }
131
+ }
132
+ catch (e) { }
133
+ });
134
+ socket.on('error', () => {
135
+ clearTimeout(timer);
136
+ finish(false);
137
+ });
138
+ });
139
+ }
140
+ /**
141
+ * Sends a command to the Editor Control Server (e.g. 'stopPIE', 'getStatus').
142
+ */
143
+ static async sendEditorCommand(command, editorUrl = 'ws://127.0.0.1:8079') {
144
+ return new Promise((resolve) => {
145
+ let settled = false;
146
+ const finish = (result) => {
147
+ if (!settled) {
148
+ settled = true;
149
+ resolve(result);
150
+ }
151
+ };
152
+ const timer = setTimeout(() => {
153
+ try {
154
+ socket.close();
155
+ }
156
+ catch (e) { }
157
+ finish(null);
158
+ }, 2500);
159
+ let socket;
160
+ try {
161
+ socket = new ws_1.default(editorUrl);
162
+ }
163
+ catch (e) {
164
+ clearTimeout(timer);
165
+ return finish(null);
166
+ }
167
+ socket.on('open', () => {
168
+ socket.send(JSON.stringify({
169
+ command,
170
+ messageId: `cmd-${Date.now()}`
171
+ }));
172
+ });
173
+ socket.on('message', (data) => {
174
+ try {
175
+ const parsed = JSON.parse(data.toString('utf-8'));
176
+ clearTimeout(timer);
177
+ try {
178
+ socket.close();
179
+ }
180
+ catch (e) { }
181
+ finish(parsed);
182
+ }
183
+ catch (e) {
184
+ finish(null);
185
+ }
186
+ });
187
+ socket.on('error', () => {
188
+ clearTimeout(timer);
189
+ finish(null);
190
+ });
191
+ });
192
+ }
85
193
  async connect(timeoutMs = 20000) {
86
194
  if (this.isConnected) {
87
195
  return;
88
196
  }
89
197
  const startTime = Date.now();
90
198
  let lastError = null;
199
+ let pieRequested = false;
200
+ let editorDetected = false;
201
+ const isDefaultPort = this.url.includes(':8080');
91
202
  while (Date.now() - startTime < timeoutMs) {
92
203
  try {
93
204
  await new Promise((resolve, reject) => {
@@ -127,9 +238,26 @@ class SpecterTransport {
127
238
  }
128
239
  catch (err) {
129
240
  lastError = err;
241
+ // If connecting to default game port 8080 and haven't probed Editor Control Server yet
242
+ if (isDefaultPort && !pieRequested) {
243
+ pieRequested = true;
244
+ try {
245
+ const editorPort = process.env.SPECTER_EDITOR_PORT || '8079';
246
+ const editorUrl = `ws://127.0.0.1:${editorPort}`;
247
+ const requested = await SpecterTransport.requestEditorPIE(editorUrl);
248
+ if (requested) {
249
+ editorDetected = true;
250
+ console.log(`[SPECTER] Unreal Editor detected on ${editorUrl}. Auto-started PIE session, awaiting game server...`);
251
+ }
252
+ }
253
+ catch (e) { }
254
+ }
130
255
  await new Promise(resolve => setTimeout(resolve, 1000));
131
256
  }
132
257
  }
258
+ if (isDefaultPort && !editorDetected) {
259
+ throw new Error(`Specter Connection Timeout: Could not connect to Unreal Engine on URL ${this.url} after ${timeoutMs}ms. Neither an active PIE session (port 8080) nor an open Unreal Editor (port 8079) was detected.`);
260
+ }
133
261
  throw new Error(`Specter Connection Timeout: Could not connect to Unreal Engine on URL ${this.url} after ${timeoutMs}ms. Details: ${lastError?.message}`);
134
262
  }
135
263
  // The core router that prevents race conditions and parses JSON automatically
@@ -51,6 +51,13 @@ exports.test = test_1.test.extend({
51
51
  await socket.connect();
52
52
  await use(socket);
53
53
  socket.disconnect();
54
+ if (process.env.SPECTER_AUTO_STOP_PIE === 'true') {
55
+ try {
56
+ const editorPort = process.env.SPECTER_EDITOR_PORT || '8079';
57
+ await specter_client_1.SpecterTransport.sendEditorCommand('stopPIE', `ws://127.0.0.1:${editorPort}`);
58
+ }
59
+ catch (e) { }
60
+ }
54
61
  }, { scope: 'worker' }], // <-- This is the magic flag
55
62
  // TEST FIXTURE: Runs before/after every single test block
56
63
  world: async ({ specter }, use, testInfo) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specter-automation/test",
3
- "version": "1.0.117",
3
+ "version": "1.0.118",
4
4
  "description": "Playwright integration for Unreal Engine automation via Specter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",