@specter-automation/test 1.0.144 → 1.0.145

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.
@@ -206,6 +206,15 @@ export declare class ActorLocator<T = any> extends SpecterLocator<T> {
206
206
  * Presses or releases a hardware key on this Actor's PlayerController, optionally holding until/while a condition is met.
207
207
  */
208
208
  pressKey(key: UnrealKey, eventType?: 'Pressed' | 'Released', options?: boolean | InputConditionalOptions): Promise<void>;
209
+ /**
210
+ * Taps a key: presses it, holds it briefly, then releases it. Use this for actions bound to Started or
211
+ * Completed (jump, interact, fire). pressKey on its own leaves the key held down.
212
+ * @param options.holdMs How long to hold the key before releasing it (default 100 ms, a few frames)
213
+ */
214
+ tapKey(key: UnrealKey, options?: {
215
+ holdMs?: number;
216
+ bHideStep?: boolean;
217
+ }): Promise<void>;
209
218
  /**
210
219
  * Holds a key down until/while a condition is satisfied on this Actor.
211
220
  */
@@ -595,9 +595,11 @@ class ActorLocator extends specter_locator_1.SpecterLocator {
595
595
  await (0, input_conditions_1.runConditionalInputLoop)({
596
596
  driveFn: async () => {
597
597
  await this.evaluate("PressKey", { key, eventType: 'Pressed' }, undefined, true);
598
+ this.transport.heldKeys.add(key);
598
599
  },
599
600
  releaseFn: async () => {
600
601
  await this.evaluate("PressKey", { key, eventType: 'Released' }, undefined, true);
602
+ this.transport.heldKeys.delete(key);
601
603
  },
602
604
  options,
603
605
  actor: this
@@ -614,6 +616,31 @@ class ActorLocator extends specter_locator_1.SpecterLocator {
614
616
  }
615
617
  const bHideStep = typeof options === 'boolean' ? options : false;
616
618
  await this.evaluate("PressKey", { key, eventType }, undefined, bHideStep);
619
+ if (eventType === 'Pressed') {
620
+ this.transport.heldKeys.add(key);
621
+ }
622
+ else {
623
+ this.transport.heldKeys.delete(key);
624
+ }
625
+ }
626
+ /**
627
+ * Taps a key: presses it, holds it briefly, then releases it. Use this for actions bound to Started or
628
+ * Completed (jump, interact, fire). pressKey on its own leaves the key held down.
629
+ * @param options.holdMs How long to hold the key before releasing it (default 100 ms, a few frames)
630
+ */
631
+ async tapKey(key, options) {
632
+ const holdMs = options?.holdMs ?? 100;
633
+ const tap = async () => {
634
+ await this.pressKey(key, 'Pressed', true);
635
+ await new Promise(resolve => setTimeout(resolve, holdMs));
636
+ await this.pressKey(key, 'Released', true);
637
+ };
638
+ if (options?.bHideStep) {
639
+ await tap();
640
+ return;
641
+ }
642
+ const portStr = this.port ? `[Client ${this.port}] ` : '';
643
+ await test_1.default.step(`${portStr}tapKey [${key}] @ ${this.toString()}`, tap);
617
644
  }
618
645
  /**
619
646
  * Holds a key down until/while a condition is satisfied on this Actor.
@@ -227,6 +227,8 @@ export declare class SpecterTransport {
227
227
  private url;
228
228
  currentMap: string;
229
229
  clientName?: string;
230
+ /** Keys pressed through pressKey and not released yet. World cleanup releases them after each test. */
231
+ readonly heldKeys: Set<string>;
230
232
  private pendingRequests;
231
233
  private eventListeners;
232
234
  recentEvents: Array<{
@@ -42,6 +42,8 @@ class SpecterTransport {
42
42
  url;
43
43
  currentMap = 'Unknown';
44
44
  clientName;
45
+ /** Keys pressed through pressKey and not released yet. World cleanup releases them after each test. */
46
+ heldKeys = new Set();
45
47
  // The Enterprise Fix: Routing responses to the correct Promise
46
48
  pendingRequests = new Map();
47
49
  eventListeners = new Map();
@@ -1141,6 +1143,17 @@ class SpecterWorld {
1141
1143
  async cleanup() {
1142
1144
  if (!this.transport.isConnected)
1143
1145
  return;
1146
+ // Release keys the test left held (pressKey without a matching release). Otherwise the next test, or a
1147
+ // retry in the same game, starts with the key already down, and actions bound to Started never fire.
1148
+ for (const key of [...this.transport.heldKeys]) {
1149
+ try {
1150
+ await this.evaluate("PressKey", { key, eventType: 'Released' }, key);
1151
+ }
1152
+ catch (e) {
1153
+ // Ignore during teardown, as below
1154
+ }
1155
+ }
1156
+ this.transport.heldKeys.clear();
1144
1157
  try {
1145
1158
  await this.evaluate("ClearAllSpawned", {});
1146
1159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specter-automation/test",
3
- "version": "1.0.144",
3
+ "version": "1.0.145",
4
4
  "description": "Playwright integration for Unreal Engine automation via Specter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",