@specter-automation/test 1.0.117 → 1.0.119

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.
@@ -1,40 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.aiExpect = void 0;
37
- const test_1 = __importStar(require("@playwright/test"));
4
+ const test_1 = require("@playwright/test");
5
+ const instrument_1 = require("./instrument");
38
6
  function formatTarget(target) {
39
7
  if (typeof target === 'string')
40
8
  return `'${target}'`;
@@ -46,15 +14,12 @@ function formatTarget(target) {
46
14
  }
47
15
  return JSON.stringify(target);
48
16
  }
49
- exports.aiExpect = test_1.expect.extend({
17
+ exports.aiExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
50
18
  async toHaveBlackboardValue(locator, keyName, expectedValue, options) {
51
19
  const isNot = this.isNot;
52
20
  const timeout = options?.timeout ?? 5000;
53
21
  const startTime = Date.now();
54
- const prefix = isNot ? 'not.toHaveBlackboardValue' : 'toHaveBlackboardValue';
55
- const portStr = locator?.transport?.port ? `[Port ${locator.transport.port}] ` : '';
56
- const stepName = `${portStr}expect(${locator.toString()}).${prefix}('${keyName}', ${formatTarget(expectedValue)})`;
57
- return await test_1.default.step(stepName, async () => {
22
+ return await (async () => {
58
23
  let lastValue = null;
59
24
  let lastObjName = undefined;
60
25
  let lastObjTags = [];
@@ -102,17 +67,14 @@ exports.aiExpect = test_1.expect.extend({
102
67
  message: () => `Expected Blackboard key '${keyName}' to ${isNot ? 'not ' : ''}match '${expectedValue}'.\n` +
103
68
  `Received value: '${lastValue}'${lastObjName ? ` (Object: '${lastObjName}', Tags: [${lastObjTags.join(', ')}])` : ''}`
104
69
  };
105
- });
70
+ })();
106
71
  },
107
72
  async toHaveAIState(locator, expectedState, options) {
108
73
  const isNot = this.isNot;
109
74
  const timeout = options?.timeout ?? 5000;
110
75
  const keyName = options?.keyName ?? 'AIState';
111
76
  const startTime = Date.now();
112
- const prefix = isNot ? 'not.toHaveAIState' : 'toHaveAIState';
113
- const portStr = locator?.transport?.port ? `[Port ${locator.transport.port}] ` : '';
114
- const stepName = `${portStr}expect(${locator.toString()}).${prefix}('${expectedState}')`;
115
- return await test_1.default.step(stepName, async () => {
77
+ return await (async () => {
116
78
  let lastState = '';
117
79
  while (Date.now() - startTime < timeout) {
118
80
  try {
@@ -132,17 +94,14 @@ exports.aiExpect = test_1.expect.extend({
132
94
  message: () => `Expected AI state to ${isNot ? 'not ' : ''}be '${expectedState}'.\n` +
133
95
  `Received state: '${lastState}' (Key: '${keyName}')`
134
96
  };
135
- });
97
+ })();
136
98
  },
137
99
  async toBeMovingTowards(locator, target, options) {
138
100
  const isNot = this.isNot;
139
101
  const timeout = options?.timeout ?? 5000;
140
102
  const minSpeed = options?.minSpeed ?? 10.0;
141
103
  const startTime = Date.now();
142
- const prefix = isNot ? 'not.toBeMovingTowards' : 'toBeMovingTowards';
143
- const portStr = locator?.transport?.port ? `[Port ${locator.transport.port}] ` : '';
144
- const stepName = `${portStr}expect(${locator.toString()}).${prefix}(${formatTarget(target)})`;
145
- return await test_1.default.step(stepName, async () => {
104
+ return await (async () => {
146
105
  let lastInfo = null;
147
106
  while (Date.now() - startTime < timeout) {
148
107
  try {
@@ -167,17 +126,14 @@ exports.aiExpect = test_1.expect.extend({
167
126
  `Facing Dot: ${lastInfo?.facingDot.toFixed(2) ?? 0} (facing: ${lastInfo?.isFacingTarget ? 'yes' : 'no'})\n` +
168
127
  `Distance: ${lastInfo?.distance2D.toFixed(1) ?? 0} units`
169
128
  };
170
- });
129
+ })();
171
130
  },
172
131
  async toBeMovingAwayFrom(locator, target, options) {
173
132
  const isNot = this.isNot;
174
133
  const timeout = options?.timeout ?? 5000;
175
134
  const minSpeed = options?.minSpeed ?? 10.0;
176
135
  const startTime = Date.now();
177
- const prefix = isNot ? 'not.toBeMovingAwayFrom' : 'toBeMovingAwayFrom';
178
- const portStr = locator?.transport?.port ? `[Port ${locator.transport.port}] ` : '';
179
- const stepName = `${portStr}expect(${locator.toString()}).${prefix}(${formatTarget(target)})`;
180
- return await test_1.default.step(stepName, async () => {
136
+ return await (async () => {
181
137
  let lastInfo = null;
182
138
  while (Date.now() - startTime < timeout) {
183
139
  try {
@@ -201,17 +157,14 @@ exports.aiExpect = test_1.expect.extend({
201
157
  `Velocity Dot: ${lastInfo?.velocityDot.toFixed(2) ?? 0}\n` +
202
158
  `Distance: ${lastInfo?.distance2D.toFixed(1) ?? 0} units`
203
159
  };
204
- });
160
+ })();
205
161
  },
206
162
  async toBeWithinDistance(locator, target, distance, options) {
207
163
  const isNot = this.isNot;
208
164
  const timeout = options?.timeout ?? 5000;
209
165
  const planar = options?.planar ?? true;
210
166
  const startTime = Date.now();
211
- const prefix = isNot ? 'not.toBeWithinDistance' : 'toBeWithinDistance';
212
- const portStr = locator?.transport?.port ? `[Port ${locator.transport.port}] ` : '';
213
- const stepName = `${portStr}expect(${locator.toString()}).${prefix}(${formatTarget(target)}, ${distance})`;
214
- return await test_1.default.step(stepName, async () => {
167
+ return await (async () => {
215
168
  let lastDistance = Infinity;
216
169
  while (Date.now() - startTime < timeout) {
217
170
  try {
@@ -230,16 +183,13 @@ exports.aiExpect = test_1.expect.extend({
230
183
  message: () => `Expected Actor to ${isNot ? 'not ' : ''}be within ${distance} units of target.\n` +
231
184
  `Current distance: ${lastDistance.toFixed(1)} units (${planar ? '2D planar' : '3D'})`
232
185
  };
233
- });
186
+ })();
234
187
  },
235
188
  async toBeFollowing(locator, target, options) {
236
189
  const isNot = this.isNot;
237
190
  const timeout = options?.timeout ?? 5000;
238
191
  const startTime = Date.now();
239
- const prefix = isNot ? 'not.toBeFollowing' : 'toBeFollowing';
240
- const portStr = locator?.transport?.port ? `[Port ${locator.transport.port}] ` : '';
241
- const stepName = `${portStr}expect(${locator.toString()}).${prefix}(${formatTarget(target)})`;
242
- return await test_1.default.step(stepName, async () => {
192
+ return await (async () => {
243
193
  let lastInfo = null;
244
194
  while (Date.now() - startTime < timeout) {
245
195
  try {
@@ -263,16 +213,13 @@ exports.aiExpect = test_1.expect.extend({
263
213
  `Navigating Towards Destination: ${lastInfo?.isNavigatingTowards ? 'yes' : 'no'}\n` +
264
214
  `Distance: ${lastInfo?.distance2D.toFixed(1) ?? 0} units${options?.maxDistance ? ` (max: ${options.maxDistance})` : ''}`
265
215
  };
266
- });
216
+ })();
267
217
  },
268
218
  async toHaveLineOfSightTo(locator, target, options) {
269
219
  const isNot = this.isNot;
270
220
  const timeout = options?.timeout ?? 5000;
271
221
  const startTime = Date.now();
272
- const prefix = isNot ? 'not.toHaveLineOfSightTo' : 'toHaveLineOfSightTo';
273
- const portStr = locator?.transport?.port ? `[Port ${locator.transport.port}] ` : '';
274
- const stepName = `${portStr}expect(${locator.toString()}).${prefix}(${formatTarget(target)})`;
275
- return await test_1.default.step(stepName, async () => {
222
+ return await (async () => {
276
223
  let lastLOS = false;
277
224
  while (Date.now() - startTime < timeout) {
278
225
  try {
@@ -288,16 +235,13 @@ exports.aiExpect = test_1.expect.extend({
288
235
  pass: isNot,
289
236
  message: () => `Expected AI to ${isNot ? 'not ' : ''}have Line of Sight to target '${formatTarget(target)}', but hasLOS was ${lastLOS}.`
290
237
  };
291
- });
238
+ })();
292
239
  },
293
240
  async toBeRunningBehaviorTree(locator, treePath, options) {
294
241
  const isNot = this.isNot;
295
242
  const timeout = options?.timeout ?? 5000;
296
243
  const startTime = Date.now();
297
- const prefix = isNot ? 'not.toBeRunningBehaviorTree' : 'toBeRunningBehaviorTree';
298
- const portStr = locator?.transport?.port ? `[Port ${locator.transport.port}] ` : '';
299
- const stepName = `${portStr}expect(${locator.toString()}).${prefix}('${treePath}')`;
300
- return await test_1.default.step(stepName, async () => {
244
+ return await (async () => {
301
245
  let lastRunning = false;
302
246
  while (Date.now() - startTime < timeout) {
303
247
  try {
@@ -313,6 +257,6 @@ exports.aiExpect = test_1.expect.extend({
313
257
  pass: isNot,
314
258
  message: () => `Expected AI to ${isNot ? 'not ' : ''}be running BehaviorTree '${treePath}', but isRunning was ${lastRunning}.`
315
259
  };
316
- });
260
+ })();
317
261
  }
318
- });
262
+ }));
@@ -37,6 +37,7 @@ exports.gasExpect = void 0;
37
37
  exports.formatAiDiagnostics = formatAiDiagnostics;
38
38
  exports.formatCausalityTimeline = formatCausalityTimeline;
39
39
  const test_1 = __importStar(require("@playwright/test"));
40
+ const instrument_1 = require("./instrument");
40
41
  const specter_client_1 = require("../core/specter-client");
41
42
  function formatAiDiagnostics(diagnostics) {
42
43
  if (!diagnostics)
@@ -177,20 +178,18 @@ function formatCausalityTimeline(events) {
177
178
  lines.push('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
178
179
  return '\n\n' + lines.join('\n');
179
180
  }
180
- exports.gasExpect = test_1.expect.extend({
181
+ exports.gasExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)({
181
182
  async toHaveAttributeValue(locator, attributeSet, attributeName, expectedValue, options) {
182
183
  const assertionName = 'toHaveAttributeValue';
183
184
  const isNot = this.isNot;
184
- const prefix = isNot ? 'not.toHaveAttributeValue' : 'toHaveAttributeValue';
185
185
  const timeout = options?.timeout ?? 5000;
186
186
  const tolerance = options?.tolerance ?? 0.01;
187
- const stepName = `${prefix}('${attributeSet}', '${attributeName}', ${expectedValue}) @ ${locator.toString()}`;
188
187
  const isMatch = (val) => {
189
188
  if (val === expectedValue)
190
189
  return true;
191
190
  return Math.abs(val - expectedValue) <= tolerance;
192
191
  };
193
- return await test_1.default.step(stepName, async () => {
192
+ return await (async () => {
194
193
  let lastValue;
195
194
  let valueHistory = [];
196
195
  const startTime = Date.now();
@@ -334,12 +333,11 @@ exports.gasExpect = test_1.expect.extend({
334
333
  expected: expectedValue
335
334
  };
336
335
  }
337
- });
336
+ })();
338
337
  },
339
338
  async toHaveAttributeChange(locator, attributeSet, attributeName, expectedChange, triggerAction) {
340
339
  const assertionName = 'toHaveAttributeChange';
341
340
  const isNot = this.isNot;
342
- const prefix = isNot ? 'not.toHaveAttributeChange' : 'toHaveAttributeChange';
343
341
  const timeout = expectedChange.timeout ?? 10000;
344
342
  const tolerance = expectedChange.tolerance ?? 0.01;
345
343
  const startTime = Date.now();
@@ -359,8 +357,7 @@ exports.gasExpect = test_1.expect.extend({
359
357
  expectedParts.push(`gameplayEffect: ${expectedChange.gameplayEffect}`);
360
358
  if (expectedChange.ability !== undefined)
361
359
  expectedParts.push(`ability: ${expectedChange.ability}`);
362
- const stepName = `${prefix}('${attributeSet}', '${attributeName}', { ${expectedParts.join(', ')} }) @ ${locator.toString()}`;
363
- return await test_1.default.step(stepName, async () => {
360
+ return await (async () => {
364
361
  const transport = locator.transport;
365
362
  let lastEvent;
366
363
  let lastFailedReasons = [];
@@ -642,14 +639,12 @@ exports.gasExpect = test_1.expect.extend({
642
639
  transport.removeEventListener('GLOBAL_timeline-event', liveListener);
643
640
  }
644
641
  }
645
- });
642
+ })();
646
643
  },
647
644
  async toHaveGameplayTag(locator, tag) {
648
645
  const assertionName = 'toHaveGameplayTag';
649
646
  const isNot = this.isNot;
650
- const prefix = isNot ? 'not.toHaveGameplayTag' : 'toHaveGameplayTag';
651
- const stepName = `${prefix}('${tag}') @ ${locator.toString()}`;
652
- return await test_1.default.step(stepName, async () => {
647
+ return await (async () => {
653
648
  const timeout = 5000;
654
649
  let hasTag = false;
655
650
  try {
@@ -676,14 +671,12 @@ exports.gasExpect = test_1.expect.extend({
676
671
  expected: !isNot
677
672
  };
678
673
  }
679
- });
674
+ })();
680
675
  },
681
676
  async toHaveGameplayEffect(locator, effectClassPath) {
682
677
  const assertionName = 'toHaveGameplayEffect';
683
678
  const isNot = this.isNot;
684
- const prefix = isNot ? 'not.toHaveGameplayEffect' : 'toHaveGameplayEffect';
685
- const stepName = `${prefix}('${effectClassPath}') @ ${locator.toString()}`;
686
- return await test_1.default.step(stepName, async () => {
679
+ return await (async () => {
687
680
  const timeout = 5000;
688
681
  const startTime = Date.now();
689
682
  let hasEffect = false;
@@ -708,12 +701,11 @@ exports.gasExpect = test_1.expect.extend({
708
701
  actual: hasEffect,
709
702
  expected: !isNot
710
703
  };
711
- });
704
+ })();
712
705
  },
713
706
  async toHaveAppliedGameplayEffect(locator, effectNameOrClass, options) {
714
707
  const assertionName = 'toHaveAppliedGameplayEffect';
715
708
  const isNot = this.isNot;
716
- const prefix = isNot ? 'not.toHaveAppliedGameplayEffect' : 'toHaveAppliedGameplayEffect';
717
709
  const timeout = options?.timeout ?? 5000;
718
710
  const expectedCount = options?.count;
719
711
  const startTime = Date.now();
@@ -724,8 +716,7 @@ exports.gasExpect = test_1.expect.extend({
724
716
  const instName = typeof options.instigator === 'string' ? options.instigator : options.instigator.toString();
725
717
  expectedParts.push(`instigator: ${instName}`);
726
718
  }
727
- const stepName = `${prefix}('${effectNameOrClass}'${expectedCount !== undefined ? `, { count: ${expectedCount} }` : ''}) @ ${locator.toString()}`;
728
- return await test_1.default.step(stepName, async () => {
719
+ return await (async () => {
729
720
  const transport = locator.transport;
730
721
  const capturedEvents = [];
731
722
  const matchingApplications = [];
@@ -964,14 +955,12 @@ exports.gasExpect = test_1.expect.extend({
964
955
  actual: matchingApplications.length,
965
956
  expected: expectedCount ?? 1
966
957
  };
967
- });
958
+ })();
968
959
  },
969
960
  async toHaveGameplayAbility(locator, abilityClassPath, options) {
970
961
  const assertionName = 'toHaveGameplayAbility';
971
962
  const isNot = this.isNot;
972
- const prefix = isNot ? 'not.toHaveGameplayAbility' : 'toHaveGameplayAbility';
973
- const stepName = `${prefix}('${abilityClassPath}') @ ${locator.toString()}`;
974
- return await test_1.default.step(stepName, async () => {
963
+ return await (async () => {
975
964
  const timeout = options?.timeout ?? 5000;
976
965
  const startTime = Date.now();
977
966
  let hasAbility = false;
@@ -996,16 +985,14 @@ exports.gasExpect = test_1.expect.extend({
996
985
  actual: hasAbility,
997
986
  expected: !isNot
998
987
  };
999
- });
988
+ })();
1000
989
  },
1001
990
  async toHaveAbilityCooldown(locator, abilityClassPath, options) {
1002
991
  const assertionName = 'toHaveAbilityCooldown';
1003
992
  const isNot = this.isNot;
1004
- const prefix = isNot ? 'not.toHaveAbilityCooldown' : 'toHaveAbilityCooldown';
1005
993
  const operator = options?.operator ?? '>';
1006
994
  const expectedValue = options?.expectedValue ?? 0;
1007
- const stepName = `${prefix}('${abilityClassPath}', '${operator}', ${expectedValue}) @ ${locator.toString()}`;
1008
- return await test_1.default.step(stepName, async () => {
995
+ return await (async () => {
1009
996
  const timeout = options?.timeout ?? 5000;
1010
997
  const startTime = Date.now();
1011
998
  let cooldown = 0;
@@ -1056,11 +1043,11 @@ exports.gasExpect = test_1.expect.extend({
1056
1043
  actual: cooldown,
1057
1044
  expected: `${operator} ${expectedValue}`
1058
1045
  };
1059
- });
1046
+ })();
1060
1047
  },
1061
1048
  async toHaveGameplayEffectStackCount(locator, effectClassPath, expectedCount) {
1062
1049
  const isNot = this.isNot;
1063
- return await test_1.default.step(`${isNot ? 'not.' : ''}toHaveGameplayEffectStackCount('${effectClassPath}', ${expectedCount})`, async () => {
1050
+ return await (async () => {
1064
1051
  const timeout = 5000;
1065
1052
  const startTime = Date.now();
1066
1053
  let count = 0;
@@ -1074,11 +1061,11 @@ exports.gasExpect = test_1.expect.extend({
1074
1061
  await new Promise(r => setTimeout(r, 100));
1075
1062
  }
1076
1063
  return { pass: isNot, message: () => `Expected stack count: ${expectedCount}. Got: ${count}`, actual: count, expected: expectedCount };
1077
- });
1064
+ })();
1078
1065
  },
1079
1066
  async toHaveGameplayEffectLevel(locator, effectClassPath, expectedLevel) {
1080
1067
  const isNot = this.isNot;
1081
- return await test_1.default.step(`${isNot ? 'not.' : ''}toHaveGameplayEffectLevel('${effectClassPath}', ${expectedLevel})`, async () => {
1068
+ return await (async () => {
1082
1069
  const timeout = 5000;
1083
1070
  const startTime = Date.now();
1084
1071
  let level = 0;
@@ -1092,11 +1079,11 @@ exports.gasExpect = test_1.expect.extend({
1092
1079
  await new Promise(r => setTimeout(r, 100));
1093
1080
  }
1094
1081
  return { pass: isNot, message: () => `Expected level: ${expectedLevel}. Got: ${level}`, actual: level, expected: expectedLevel };
1095
- });
1082
+ })();
1096
1083
  },
1097
1084
  async toHaveAttributeBaseValue(locator, attributeSet, attributeName, expectedValue) {
1098
1085
  const isNot = this.isNot;
1099
- return await test_1.default.step(`${isNot ? 'not.' : ''}toHaveAttributeBaseValue('${attributeSet}', '${attributeName}', ${expectedValue})`, async () => {
1086
+ return await (async () => {
1100
1087
  const timeout = 5000;
1101
1088
  const startTime = Date.now();
1102
1089
  let val = 0;
@@ -1110,11 +1097,11 @@ exports.gasExpect = test_1.expect.extend({
1110
1097
  await new Promise(r => setTimeout(r, 100));
1111
1098
  }
1112
1099
  return { pass: isNot, message: () => `Expected base value: ${expectedValue}. Got: ${val}`, actual: val, expected: expectedValue };
1113
- });
1100
+ })();
1114
1101
  },
1115
1102
  async toBeExecutingAbility(locator, abilityClassPath) {
1116
1103
  const isNot = this.isNot;
1117
- return await test_1.default.step(`${isNot ? 'not.' : ''}toBeExecutingAbility('${abilityClassPath}')`, async () => {
1104
+ return await (async () => {
1118
1105
  const timeout = 5000;
1119
1106
  const startTime = Date.now();
1120
1107
  let exec = false;
@@ -1128,12 +1115,11 @@ exports.gasExpect = test_1.expect.extend({
1128
1115
  await new Promise(r => setTimeout(r, 100));
1129
1116
  }
1130
1117
  return { pass: isNot, message: () => `Expected executing: ${!isNot}. Got: ${exec}`, actual: exec, expected: !isNot };
1131
- });
1118
+ })();
1132
1119
  },
1133
1120
  async toHaveActivatedAbility(locator, ability, optionsOrTrigger, triggerAction) {
1134
1121
  const assertionName = 'toHaveActivatedAbility';
1135
1122
  const isNot = this.isNot;
1136
- const prefix = isNot ? 'not.toHaveActivatedAbility' : 'toHaveActivatedAbility';
1137
1123
  let timeout = 5000;
1138
1124
  let action;
1139
1125
  let expectedTimes;
@@ -1147,8 +1133,7 @@ exports.gasExpect = test_1.expect.extend({
1147
1133
  if (triggerAction && typeof triggerAction === 'function') {
1148
1134
  action = triggerAction;
1149
1135
  }
1150
- const stepName = `${prefix}('${ability}'${expectedTimes !== undefined ? `, { times: ${expectedTimes} }` : ''}) @ ${locator.toString()}`;
1151
- return await test_1.default.step(stepName, async () => {
1136
+ return await (async () => {
1152
1137
  const transport = locator.transport;
1153
1138
  const capturedEvents = [];
1154
1139
  const activations = [];
@@ -1399,11 +1384,11 @@ exports.gasExpect = test_1.expect.extend({
1399
1384
  actual: activations.length,
1400
1385
  expected: expectedTimes ?? !isNot
1401
1386
  };
1402
- });
1387
+ })();
1403
1388
  },
1404
1389
  async toHaveGameplayTagCount(locator, tag, expectedCount) {
1405
1390
  const isNot = this.isNot;
1406
- return await test_1.default.step(`${isNot ? 'not.' : ''}toHaveGameplayTagCount('${tag}', ${expectedCount})`, async () => {
1391
+ return await (async () => {
1407
1392
  const timeout = 5000;
1408
1393
  const startTime = Date.now();
1409
1394
  let count = 0;
@@ -1417,11 +1402,11 @@ exports.gasExpect = test_1.expect.extend({
1417
1402
  await new Promise(r => setTimeout(r, 100));
1418
1403
  }
1419
1404
  return { pass: isNot, message: () => `Expected count: ${expectedCount}. Got: ${count}`, actual: count, expected: expectedCount };
1420
- });
1405
+ })();
1421
1406
  },
1422
1407
  async toHaveAnyGameplayTags(locator, tags) {
1423
1408
  const isNot = this.isNot;
1424
- return await test_1.default.step(`${isNot ? 'not.' : ''}toHaveAnyGameplayTags([${tags.join(',')}])`, async () => {
1409
+ return await (async () => {
1425
1410
  const timeout = 5000;
1426
1411
  const startTime = Date.now();
1427
1412
  let has = false;
@@ -1435,11 +1420,11 @@ exports.gasExpect = test_1.expect.extend({
1435
1420
  await new Promise(r => setTimeout(r, 100));
1436
1421
  }
1437
1422
  return { pass: isNot, message: () => `Expected any tags: ${!isNot}. Got: ${has}`, actual: has, expected: !isNot };
1438
- });
1423
+ })();
1439
1424
  },
1440
1425
  async toHaveAllGameplayTags(locator, tags) {
1441
1426
  const isNot = this.isNot;
1442
- return await test_1.default.step(`${isNot ? 'not.' : ''}toHaveAllGameplayTags([${tags.join(',')}])`, async () => {
1427
+ return await (async () => {
1443
1428
  const timeout = 5000;
1444
1429
  const startTime = Date.now();
1445
1430
  let has = false;
@@ -1453,6 +1438,6 @@ exports.gasExpect = test_1.expect.extend({
1453
1438
  await new Promise(r => setTimeout(r, 100));
1454
1439
  }
1455
1440
  return { pass: isNot, message: () => `Expected all tags: ${!isNot}. Got: ${has}`, actual: has, expected: !isNot };
1456
- });
1441
+ })();
1457
1442
  },
1458
- });
1443
+ }));
@@ -0,0 +1,13 @@
1
+ import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';
2
+ type SpecterMatcherFn = (this: ExpectMatcherState, receiver: any, ...args: any[]) => MatcherReturnType | Promise<MatcherReturnType>;
3
+ /**
4
+ * Wraps every matcher passed to expect.extend so that each call:
5
+ * 1. runs inside one step titled `<matcher>(<args>) @ <locator>`, which the
6
+ * SpecterReporter shows under the outer `Expect "<matcher>"` step, and
7
+ * 2. records a structured result (matcher, locator, expected, actual) as a
8
+ * hidden attachment on the expect step, for the in-engine results grid.
9
+ *
10
+ * Matchers should not open their own step for the whole body; this does it for them.
11
+ */
12
+ export declare function instrumentMatchers<T extends Record<string, SpecterMatcherFn>>(matchers: T): T;
13
+ export {};
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.instrumentMatchers = instrumentMatchers;
7
+ const test_1 = __importDefault(require("@playwright/test"));
8
+ const specter_matcher_report_1 = require("../core/specter-matcher-report");
9
+ const MAX_ARG_LENGTH = 60;
10
+ const MAX_ARGS_LENGTH = 140;
11
+ const MAX_REPORT_VALUE_LENGTH = 4000;
12
+ /**
13
+ * Wraps every matcher passed to expect.extend so that each call:
14
+ * 1. runs inside one step titled `<matcher>(<args>) @ <locator>`, which the
15
+ * SpecterReporter shows under the outer `Expect "<matcher>"` step, and
16
+ * 2. records a structured result (matcher, locator, expected, actual) as a
17
+ * hidden attachment on the expect step, for the in-engine results grid.
18
+ *
19
+ * Matchers should not open their own step for the whole body; this does it for them.
20
+ */
21
+ function instrumentMatchers(matchers) {
22
+ const instrumented = {};
23
+ for (const [name, matcher] of Object.entries(matchers)) {
24
+ instrumented[name] = async function (receiver, ...args) {
25
+ const isNot = this.isNot;
26
+ // Keep the client tag ("[Server] ", "[Client 1] ") in front, as the old per-matcher titles did.
27
+ const title = `${clientTagOf(receiver)}${isNot ? 'not.' : ''}${name}(${formatArgs(args)}) @ ${describe(receiver)}`;
28
+ const result = await test_1.default.step(title, async () => matcher.call(this, receiver, ...args));
29
+ // Back in the expect step's context here, so the attachment lands on it.
30
+ recordResult({
31
+ matcher: name,
32
+ isNot,
33
+ pass: isNot ? !result.pass : result.pass,
34
+ locator: selectorOf(receiver),
35
+ locatorLabel: labelOf(receiver),
36
+ client: clientTagOf(receiver).replace(/^\[|\]\s*$/g, '') || undefined,
37
+ expected: result.expected,
38
+ actual: result.actual,
39
+ });
40
+ return result;
41
+ };
42
+ }
43
+ return instrumented;
44
+ }
45
+ function recordResult(report) {
46
+ let info;
47
+ try {
48
+ info = test_1.default.info();
49
+ }
50
+ catch {
51
+ return; // Called outside a running test (e.g. a plain script); nothing to report to.
52
+ }
53
+ const body = JSON.stringify({
54
+ ...report,
55
+ expected: limitSize(toReportValue(report.expected)),
56
+ actual: limitSize(toReportValue(report.actual)),
57
+ });
58
+ // attachments.push attaches to the current step without adding an "Attach" step.
59
+ info.attachments.push({
60
+ name: specter_matcher_report_1.SPECTER_MATCHER_ATTACHMENT,
61
+ contentType: 'application/json',
62
+ body: Buffer.from(body, 'utf-8'),
63
+ });
64
+ }
65
+ function isLocatorLike(value) {
66
+ return !!value && typeof value === 'object' && Array.isArray(value.pipeline);
67
+ }
68
+ function describe(receiver) {
69
+ if (isLocatorLike(receiver))
70
+ return receiver.toString();
71
+ return formatArg(receiver);
72
+ }
73
+ function selectorOf(receiver) {
74
+ if (isLocatorLike(receiver)) {
75
+ return typeof receiver.toSelectorString === 'function' ? receiver.toSelectorString() : receiver.toString();
76
+ }
77
+ return formatArg(receiver);
78
+ }
79
+ function clientTagOf(receiver) {
80
+ try {
81
+ return isLocatorLike(receiver) && typeof receiver.portTag === 'string' ? receiver.portTag : '';
82
+ }
83
+ catch {
84
+ return '';
85
+ }
86
+ }
87
+ function labelOf(receiver) {
88
+ return isLocatorLike(receiver) && receiver.label ? receiver.label : undefined;
89
+ }
90
+ function formatArgs(args) {
91
+ // Drop trailing undefined (optional args that were not passed).
92
+ const trimmed = [...args];
93
+ while (trimmed.length && trimmed[trimmed.length - 1] === undefined)
94
+ trimmed.pop();
95
+ return truncate(trimmed.map(formatArg).join(', '), MAX_ARGS_LENGTH);
96
+ }
97
+ function formatArg(value) {
98
+ if (value === undefined)
99
+ return 'undefined';
100
+ if (value === null)
101
+ return 'null';
102
+ if (typeof value === 'string')
103
+ return `'${truncate(value, MAX_ARG_LENGTH)}'`;
104
+ if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint')
105
+ return String(value);
106
+ if (typeof value === 'function')
107
+ return '() => …';
108
+ if (isLocatorLike(value))
109
+ return value.toString();
110
+ return truncate(safeStringify(toReportValue(value)), MAX_ARG_LENGTH);
111
+ }
112
+ /** Converts values into something JSON-safe and readable: locators become their description, functions a placeholder. */
113
+ function toReportValue(value, seen = new WeakSet()) {
114
+ if (value === undefined || value === null)
115
+ return value;
116
+ if (typeof value === 'bigint')
117
+ return value.toString();
118
+ if (typeof value === 'function')
119
+ return '[Function]';
120
+ if (typeof value !== 'object')
121
+ return value;
122
+ if (isLocatorLike(value))
123
+ return value.toString();
124
+ if (seen.has(value))
125
+ return '[Circular]';
126
+ seen.add(value);
127
+ if (Array.isArray(value))
128
+ return value.map(v => toReportValue(v, seen));
129
+ const out = {};
130
+ for (const [key, v] of Object.entries(value)) {
131
+ out[key] = toReportValue(v, seen);
132
+ }
133
+ return out;
134
+ }
135
+ function safeStringify(value) {
136
+ try {
137
+ return JSON.stringify(value) ?? 'undefined';
138
+ }
139
+ catch {
140
+ return String(value);
141
+ }
142
+ }
143
+ /** Keeps the attachment small: oversized values are replaced by a truncated JSON string. */
144
+ function limitSize(value) {
145
+ const text = safeStringify(value);
146
+ return text.length > MAX_REPORT_VALUE_LENGTH ? `${text.slice(0, MAX_REPORT_VALUE_LENGTH)}…` : value;
147
+ }
148
+ function truncate(text, max) {
149
+ return text.length > max ? `${text.slice(0, max - 1)}…` : text;
150
+ }