@specter-automation/test 1.0.142 → 1.0.144
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/dist/core/locators/actor-locator.d.ts +18 -7
- package/dist/core/locators/actor-locator.js +27 -4
- package/dist/core/locators/ai-controller-locator.d.ts +4 -6
- package/dist/core/locators/ai-controller-locator.js +24 -4
- package/dist/core/specter-client.d.ts +4 -0
- package/dist/core/specter-client.js +11 -1
- package/dist/matchers/locator-matchers.d.ts +6 -6
- package/dist/matchers/locator-matchers.js +74 -20
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentLocatorMap } from "../component-registry";
|
|
2
2
|
import { SpecterLocator } from "../locators/specter-locator";
|
|
3
|
-
import { Rotator, Transform, Vector3, RegisteredComponentClasses, RegisteredWidgetClasses, SpecterWorld, SpecterGrantedAbility, SpecterActiveEffect, RegisteredGameplayTags } from "../specter-client";
|
|
3
|
+
import { Rotator, Transform, Vector3, RegisteredActorClasses, RegisteredComponentClasses, RegisteredWidgetClasses, SpecterWorld, SpecterGrantedAbility, SpecterActiveEffect, RegisteredGameplayTags } from "../specter-client";
|
|
4
4
|
import { WidgetLocator, WidgetRole, WidgetRoleOptions } from "./widget-locator";
|
|
5
5
|
import { AiControllerLocator } from "./ai-controller-locator";
|
|
6
6
|
import { UnrealKey } from "../specter-keys";
|
|
@@ -8,6 +8,17 @@ import { ActorEventMap, EventPredicate, WaitForEventOptions } from "../events";
|
|
|
8
8
|
import { SpecterInputSequence } from "../specter-input-sequence";
|
|
9
9
|
import { InputConditionalOptions, SpecterCondition, ConditionFunction } from '../conditions/input-conditions';
|
|
10
10
|
import type { BehaviorTrail } from "../specter-ai-trail";
|
|
11
|
+
export interface BlackboardValueResult {
|
|
12
|
+
value: string;
|
|
13
|
+
objectName?: string;
|
|
14
|
+
objectClass?: string;
|
|
15
|
+
objectTags?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Converts this blackboard value into an ActorLocator if it represents an Actor.
|
|
18
|
+
* Returns null if no Actor is stored (e.g. value is 'None' or empty).
|
|
19
|
+
*/
|
|
20
|
+
toActor<A extends RegisteredActorClasses | (string & {}) = any>(): ActorLocator<A> | null;
|
|
21
|
+
}
|
|
11
22
|
export interface PossessAsPlayerOptions {
|
|
12
23
|
world?: SpecterWorld | {
|
|
13
24
|
world: SpecterWorld;
|
|
@@ -369,12 +380,12 @@ export declare class ActorLocator<T = any> extends SpecterLocator<T> {
|
|
|
369
380
|
/**
|
|
370
381
|
* Reads a Blackboard variable from this Actor's AIController.
|
|
371
382
|
*/
|
|
372
|
-
getBlackboardValue(keyName: string): Promise<
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}>;
|
|
383
|
+
getBlackboardValue(keyName: string): Promise<BlackboardValueResult>;
|
|
384
|
+
/**
|
|
385
|
+
* Convenience method to directly get an ActorLocator for an Actor stored in an AI Blackboard key.
|
|
386
|
+
* Returns null if the Blackboard key does not contain an Actor or is set to None.
|
|
387
|
+
*/
|
|
388
|
+
getBlackboardActor<A extends RegisteredActorClasses | (string & {}) = any>(keyName: string): Promise<ActorLocator<A> | null>;
|
|
378
389
|
/**
|
|
379
390
|
* Checks if this AI Actor / Controller has Line of Sight to a target Actor.
|
|
380
391
|
*/
|
|
@@ -900,13 +900,36 @@ class ActorLocator extends specter_locator_1.SpecterLocator {
|
|
|
900
900
|
*/
|
|
901
901
|
async getBlackboardValue(keyName) {
|
|
902
902
|
const response = await this.evaluate("GetBlackboardValue", { keyName });
|
|
903
|
+
const value = response.data?.value ?? "";
|
|
904
|
+
const objectName = response.data?.objectName;
|
|
905
|
+
const objectClass = response.data?.objectClass;
|
|
906
|
+
const objectTags = response.data?.objectTags ?? [];
|
|
903
907
|
return {
|
|
904
|
-
value
|
|
905
|
-
objectName
|
|
906
|
-
objectClass
|
|
907
|
-
objectTags
|
|
908
|
+
value,
|
|
909
|
+
objectName,
|
|
910
|
+
objectClass,
|
|
911
|
+
objectTags,
|
|
912
|
+
toActor: () => {
|
|
913
|
+
if (!objectName || value.toLowerCase() === 'none')
|
|
914
|
+
return null;
|
|
915
|
+
if (objectClass) {
|
|
916
|
+
return new ActorLocator(this.transport, [
|
|
917
|
+
{ action: 'getByClass', value: objectClass },
|
|
918
|
+
{ action: 'filterByProperty', value: JSON.stringify({ name: 'Name', value: objectName }) }
|
|
919
|
+
]);
|
|
920
|
+
}
|
|
921
|
+
return new ActorLocator(this.transport, [{ action: 'getByTag', value: objectName }]);
|
|
922
|
+
}
|
|
908
923
|
};
|
|
909
924
|
}
|
|
925
|
+
/**
|
|
926
|
+
* Convenience method to directly get an ActorLocator for an Actor stored in an AI Blackboard key.
|
|
927
|
+
* Returns null if the Blackboard key does not contain an Actor or is set to None.
|
|
928
|
+
*/
|
|
929
|
+
async getBlackboardActor(keyName) {
|
|
930
|
+
const result = await this.getBlackboardValue(keyName);
|
|
931
|
+
return result.toActor();
|
|
932
|
+
}
|
|
910
933
|
/**
|
|
911
934
|
* Checks if this AI Actor / Controller has Line of Sight to a target Actor.
|
|
912
935
|
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SpecterLocator } from "../locators/specter-locator";
|
|
2
2
|
import type { BehaviorTrail } from "../specter-ai-trail";
|
|
3
|
+
import { ActorLocator, type BlackboardValueResult } from "./actor-locator";
|
|
4
|
+
import type { RegisteredActorClasses } from "../specter-client";
|
|
3
5
|
export declare class AiControllerLocator extends SpecterLocator {
|
|
4
6
|
isRunningBehaviorTree(treePath: string): Promise<boolean>;
|
|
5
7
|
/**
|
|
@@ -10,12 +12,8 @@ export declare class AiControllerLocator extends SpecterLocator {
|
|
|
10
12
|
getBehaviorTrail(options?: {
|
|
11
13
|
limit?: number;
|
|
12
14
|
}): Promise<BehaviorTrail>;
|
|
13
|
-
getBlackboardValue(keyName: string): Promise<
|
|
14
|
-
|
|
15
|
-
objectName?: string;
|
|
16
|
-
objectClass?: string;
|
|
17
|
-
objectTags?: string[];
|
|
18
|
-
}>;
|
|
15
|
+
getBlackboardValue(keyName: string): Promise<BlackboardValueResult>;
|
|
16
|
+
getBlackboardActor<A extends RegisteredActorClasses | (string & {}) = any>(keyName: string): Promise<ActorLocator<A> | null>;
|
|
19
17
|
hasLineOfSightTo(target: any): Promise<boolean>;
|
|
20
18
|
isAINavigating(): Promise<boolean>;
|
|
21
19
|
getAINavGoal(): Promise<{
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AiControllerLocator = void 0;
|
|
4
4
|
const specter_locator_1 = require("../locators/specter-locator");
|
|
5
|
+
const actor_locator_1 = require("./actor-locator");
|
|
5
6
|
class AiControllerLocator extends specter_locator_1.SpecterLocator {
|
|
6
7
|
async isRunningBehaviorTree(treePath) {
|
|
7
8
|
const response = await this.evaluate("IsRunningBehaviorTree", { treePath });
|
|
@@ -21,13 +22,32 @@ class AiControllerLocator extends specter_locator_1.SpecterLocator {
|
|
|
21
22
|
}
|
|
22
23
|
async getBlackboardValue(keyName) {
|
|
23
24
|
const response = await this.evaluate("GetBlackboardValue", { keyName });
|
|
25
|
+
const value = response.data?.value ?? "";
|
|
26
|
+
const objectName = response.data?.objectName;
|
|
27
|
+
const objectClass = response.data?.objectClass;
|
|
28
|
+
const objectTags = response.data?.objectTags ?? [];
|
|
24
29
|
return {
|
|
25
|
-
value
|
|
26
|
-
objectName
|
|
27
|
-
objectClass
|
|
28
|
-
objectTags
|
|
30
|
+
value,
|
|
31
|
+
objectName,
|
|
32
|
+
objectClass,
|
|
33
|
+
objectTags,
|
|
34
|
+
toActor: () => {
|
|
35
|
+
if (!objectName || value.toLowerCase() === 'none')
|
|
36
|
+
return null;
|
|
37
|
+
if (objectClass) {
|
|
38
|
+
return new actor_locator_1.ActorLocator(this.transport, [
|
|
39
|
+
{ action: 'getByClass', value: objectClass },
|
|
40
|
+
{ action: 'filterByProperty', value: JSON.stringify({ name: 'Name', value: objectName }) }
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
return new actor_locator_1.ActorLocator(this.transport, [{ action: 'getByTag', value: objectName }]);
|
|
44
|
+
}
|
|
29
45
|
};
|
|
30
46
|
}
|
|
47
|
+
async getBlackboardActor(keyName) {
|
|
48
|
+
const result = await this.getBlackboardValue(keyName);
|
|
49
|
+
return result.toActor();
|
|
50
|
+
}
|
|
31
51
|
async hasLineOfSightTo(target) {
|
|
32
52
|
let payload = {};
|
|
33
53
|
if (typeof target === 'string') {
|
|
@@ -396,6 +396,10 @@ export declare class SpecterWorld {
|
|
|
396
396
|
spawnActor<T extends RegisteredActorClasses | (string & {})>(classNameOrAssetPath: T, options?: SpawnOptions): Promise<ActorLocator<T>>;
|
|
397
397
|
actor<T extends RegisteredActorClasses | (string & {})>(selector: T): ActorLocator<T>;
|
|
398
398
|
actorByTag(tagName: string): ActorLocator;
|
|
399
|
+
/**
|
|
400
|
+
* Locates an Actor by its engine Object Name (e.g. 'BP_Minion_C_1' or custom name).
|
|
401
|
+
*/
|
|
402
|
+
actorByName<T extends RegisteredActorClasses | (string & {}) = any>(actorName: string): ActorLocator<T>;
|
|
399
403
|
/**
|
|
400
404
|
* Locates the locally controlled actor for this world.
|
|
401
405
|
* Optionally filters by an actor class or selector.
|
|
@@ -704,17 +704,27 @@ class SpecterWorld {
|
|
|
704
704
|
// ==========================================
|
|
705
705
|
// THE ACTOR ENTRY POINTS
|
|
706
706
|
// ==========================================
|
|
707
|
-
// Replaces 'getByClass'. Defaults to finding an Actor by class, or supports selector prefixes like 'Tag:Tagname'
|
|
707
|
+
// Replaces 'getByClass'. Defaults to finding an Actor by class, or supports selector prefixes like 'Tag:Tagname', 'tag=Tagname', 'name:ActorName', or 'name=ActorName'.
|
|
708
708
|
actor(selector) {
|
|
709
709
|
if (typeof selector === 'string' && /^(tag[:=]|Tag[:=])/i.test(selector)) {
|
|
710
710
|
const tagName = selector.replace(/^(tag[:=]|Tag[:=])/i, '');
|
|
711
711
|
return this.actorByTag(tagName);
|
|
712
712
|
}
|
|
713
|
+
if (typeof selector === 'string' && /^(name[:=]|Name[:=])/i.test(selector)) {
|
|
714
|
+
const name = selector.replace(/^(name[:=]|Name[:=])/i, '');
|
|
715
|
+
return this.actorByName(name);
|
|
716
|
+
}
|
|
713
717
|
return new locators_1.ActorLocator(this.transport, [{ action: 'getByClass', value: selector }]);
|
|
714
718
|
}
|
|
715
719
|
actorByTag(tagName) {
|
|
716
720
|
return new locators_1.ActorLocator(this.transport, [{ action: 'getByTag', value: tagName }]);
|
|
717
721
|
}
|
|
722
|
+
/**
|
|
723
|
+
* Locates an Actor by its engine Object Name (e.g. 'BP_Minion_C_1' or custom name).
|
|
724
|
+
*/
|
|
725
|
+
actorByName(actorName) {
|
|
726
|
+
return new locators_1.ActorLocator(this.transport, [{ action: 'getByTag', value: actorName }]);
|
|
727
|
+
}
|
|
718
728
|
/**
|
|
719
729
|
* Locates the locally controlled actor for this world.
|
|
720
730
|
* Optionally filters by an actor class or selector.
|
|
@@ -3,6 +3,7 @@ declare global {
|
|
|
3
3
|
namespace PlaywrightTest {
|
|
4
4
|
interface Matchers<R, T> {
|
|
5
5
|
toHavePropertyValue(propertyName: string, expectedValue: any, options?: {
|
|
6
|
+
operator?: '>' | '<' | '>=' | '<=' | '===' | '!=' | 'regex';
|
|
6
7
|
timeout?: number;
|
|
7
8
|
}): T extends SpecterLocator ? Promise<R> : never;
|
|
8
9
|
toHaveCount(expectedCount: number, options?: {
|
|
@@ -40,16 +41,14 @@ export interface LocatorMatchers {
|
|
|
40
41
|
timeout?: number;
|
|
41
42
|
}): Promise<void>;
|
|
42
43
|
}
|
|
44
|
+
type PropertyOperator = '>' | '<' | '>=' | '<=' | '===' | '!=' | 'regex';
|
|
45
|
+
/** Compares a property value read from the engine with what the test expects. */
|
|
46
|
+
export declare function propertyMatches(actual: any, expected: any, operator: PropertyOperator): boolean;
|
|
43
47
|
export declare const locatorExpect: import("playwright/test").Expect<{
|
|
44
48
|
toHavePropertyValue(this: import("playwright/test").ExpectMatcherState, locator: SpecterLocator, propertyName: string, expectedValue: any, options?: {
|
|
45
|
-
operator?:
|
|
49
|
+
operator?: PropertyOperator;
|
|
46
50
|
timeout?: number;
|
|
47
51
|
}): Promise<{
|
|
48
|
-
pass: boolean;
|
|
49
|
-
message: () => string;
|
|
50
|
-
actual?: undefined;
|
|
51
|
-
expected?: undefined;
|
|
52
|
-
} | {
|
|
53
52
|
pass: boolean;
|
|
54
53
|
message: () => string;
|
|
55
54
|
actual: any;
|
|
@@ -78,3 +77,4 @@ export declare const locatorExpect: import("playwright/test").Expect<{
|
|
|
78
77
|
message: () => string;
|
|
79
78
|
}>;
|
|
80
79
|
}>;
|
|
80
|
+
export {};
|
|
@@ -1,37 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.locatorExpect = void 0;
|
|
4
|
+
exports.propertyMatches = propertyMatches;
|
|
4
5
|
const test_1 = require("@playwright/test");
|
|
5
6
|
const instrument_1 = require("./instrument");
|
|
6
7
|
const locators_1 = require("../core/locators");
|
|
8
|
+
const PROPERTY_POLL_INTERVALS_MS = [100, 250, 500, 1000];
|
|
9
|
+
const OPERATOR_LABELS = {
|
|
10
|
+
'===': 'to equal',
|
|
11
|
+
'!=': 'to differ from',
|
|
12
|
+
'>': 'to be >',
|
|
13
|
+
'<': 'to be <',
|
|
14
|
+
'>=': 'to be >=',
|
|
15
|
+
'<=': 'to be <=',
|
|
16
|
+
'regex': 'to match',
|
|
17
|
+
};
|
|
18
|
+
/** Compares a property value read from the engine with what the test expects. */
|
|
19
|
+
function propertyMatches(actual, expected, operator) {
|
|
20
|
+
switch (operator) {
|
|
21
|
+
case '===': return propertyEquals(actual, expected);
|
|
22
|
+
case '!=': return !propertyEquals(actual, expected);
|
|
23
|
+
case '>': return Number(actual) > Number(expected);
|
|
24
|
+
case '<': return Number(actual) < Number(expected);
|
|
25
|
+
case '>=': return Number(actual) >= Number(expected);
|
|
26
|
+
case '<=': return Number(actual) <= Number(expected);
|
|
27
|
+
case 'regex': return (expected instanceof RegExp ? expected : new RegExp(String(expected))).test(String(actual));
|
|
28
|
+
default: throw new Error(`toHavePropertyValue: unknown operator '${operator}'`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function propertyEquals(actual, expected) {
|
|
32
|
+
// Booleans come back as JSON booleans; also accept "true"/"false" written as strings
|
|
33
|
+
if (typeof actual === 'boolean' && typeof expected === 'string') {
|
|
34
|
+
return actual === (expected.trim().toLowerCase() === 'true');
|
|
35
|
+
}
|
|
36
|
+
// Structs (vectors, rotators, ...) compare deeply
|
|
37
|
+
return deepEqual(actual, expected);
|
|
38
|
+
}
|
|
39
|
+
function deepEqual(a, b) {
|
|
40
|
+
if (Object.is(a, b))
|
|
41
|
+
return true;
|
|
42
|
+
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)
|
|
43
|
+
return false;
|
|
44
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
45
|
+
return false;
|
|
46
|
+
const keysA = Object.keys(a), keysB = Object.keys(b);
|
|
47
|
+
return keysA.length === keysB.length && keysA.every(k => Object.prototype.hasOwnProperty.call(b, k) && deepEqual(a[k], b[k]));
|
|
48
|
+
}
|
|
7
49
|
exports.locatorExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
|
|
8
50
|
async toHavePropertyValue(locator, propertyName, expectedValue, options) {
|
|
9
51
|
const operator = options?.operator ?? '===';
|
|
10
|
-
const
|
|
52
|
+
const timeout = options?.timeout ?? 5000;
|
|
11
53
|
const isNot = this.isNot;
|
|
12
|
-
|
|
13
|
-
|
|
54
|
+
const deadline = Date.now() + timeout;
|
|
55
|
+
let actual;
|
|
56
|
+
let readOnce = false;
|
|
57
|
+
let lastError;
|
|
58
|
+
// The engine only reads the property; the comparison happens here. Retry until it matches (or, for
|
|
59
|
+
// .not, stops matching) or the timeout runs out. Only the first read shows as a step.
|
|
60
|
+
for (let attempt = 0;; attempt++) {
|
|
14
61
|
try {
|
|
15
|
-
await
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return lastValue.status === 'success';
|
|
23
|
-
}, { timeout: pollTimeout }).toBe(!isNot);
|
|
24
|
-
return { pass: !isNot, message: () => 'passed' };
|
|
62
|
+
const response = await locator.evaluate("GetPropertyValue", { propertyName }, propertyName, attempt > 0);
|
|
63
|
+
actual = response?.data?.value;
|
|
64
|
+
readOnce = true;
|
|
65
|
+
lastError = undefined;
|
|
66
|
+
if (propertyMatches(actual, expectedValue, operator) !== isNot) {
|
|
67
|
+
return { pass: !isNot, message: () => 'passed', actual, expected: expectedValue };
|
|
68
|
+
}
|
|
25
69
|
}
|
|
26
70
|
catch (e) {
|
|
27
|
-
|
|
28
|
-
pass: isNot,
|
|
29
|
-
message: () => `Timed out waiting for ${propertyName} ${operator} ${expectedValue}. Last value: ${lastValue?.data?.value}`,
|
|
30
|
-
actual: lastValue?.data?.value,
|
|
31
|
-
expected: expectedValue
|
|
32
|
-
};
|
|
71
|
+
lastError = e?.message ?? String(e);
|
|
33
72
|
}
|
|
34
|
-
|
|
73
|
+
if (Date.now() >= deadline)
|
|
74
|
+
break;
|
|
75
|
+
await new Promise(resolve => setTimeout(resolve, PROPERTY_POLL_INTERVALS_MS[Math.min(attempt, PROPERTY_POLL_INTERVALS_MS.length - 1)]));
|
|
76
|
+
}
|
|
77
|
+
const name = `${isNot ? 'not.' : ''}toHavePropertyValue`;
|
|
78
|
+
const hint = this.utils.matcherHint(name, locator.toString(), propertyName);
|
|
79
|
+
const wanted = `${isNot ? 'not ' : ''}${OPERATOR_LABELS[operator]} ${this.utils.printExpected(expectedValue)}`;
|
|
80
|
+
return {
|
|
81
|
+
pass: isNot,
|
|
82
|
+
message: () => lastError
|
|
83
|
+
? `${hint}\n\nCould not read "${propertyName}" within ${timeout}ms: ${lastError}` +
|
|
84
|
+
(readOnce ? `\nLast value read: ${this.utils.printReceived(actual)}` : '')
|
|
85
|
+
: `${hint}\n\nExpected "${propertyName}" ${wanted}\nReceived: ${this.utils.printReceived(actual)}\n(after ${timeout}ms)`,
|
|
86
|
+
actual,
|
|
87
|
+
expected: expectedValue,
|
|
88
|
+
};
|
|
35
89
|
},
|
|
36
90
|
async toHaveCount(locator, expectedCount, options) {
|
|
37
91
|
const pollTimeout = options?.timeout ?? 5000;
|