@specter-automation/test 1.0.150 → 1.0.152

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.
@@ -0,0 +1,4 @@
1
+ export declare function setActiveWorld(world: any): void;
2
+ export declare function getActiveWorld(): any;
3
+ export declare function setAiDiagnosticsFormatter(fn: (diag: any) => string): void;
4
+ export declare function captureSpecterFailure(world: any, testInfo: any, source?: string): Promise<void>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setActiveWorld = setActiveWorld;
4
+ exports.getActiveWorld = getActiveWorld;
5
+ exports.setAiDiagnosticsFormatter = setAiDiagnosticsFormatter;
6
+ exports.captureSpecterFailure = captureSpecterFailure;
7
+ let activeWorld = null;
8
+ let diagnosticsFormatter = null;
9
+ function setActiveWorld(world) {
10
+ activeWorld = world;
11
+ }
12
+ function getActiveWorld() {
13
+ return activeWorld;
14
+ }
15
+ function setAiDiagnosticsFormatter(fn) {
16
+ diagnosticsFormatter = fn;
17
+ }
18
+ async function captureSpecterFailure(world, testInfo, source = 'test') {
19
+ if (!world || !testInfo)
20
+ return;
21
+ if (testInfo._specterFailureCaptured)
22
+ return;
23
+ testInfo._specterFailureCaptured = true;
24
+ const title = testInfo.title || 'Unknown_Test';
25
+ const safeName = `Specter_Fail_${title.replace(/[^a-zA-Z0-9]/g, '_')}`;
26
+ try {
27
+ if (typeof world.takeScreenshot === 'function') {
28
+ await world.takeScreenshot(safeName, false, { attachmentName: 'Unreal Engine Viewport' });
29
+ }
30
+ }
31
+ catch (e) {
32
+ console.error(`[Specter] Failed to capture error screenshot (${source}):`, e);
33
+ }
34
+ try {
35
+ if (typeof world.getDiagnostics === 'function') {
36
+ const diagnostics = await world.getDiagnostics({ limit: 35 });
37
+ if (diagnostics) {
38
+ const formattedSummary = diagnosticsFormatter ? diagnosticsFormatter(diagnostics) : JSON.stringify(diagnostics, null, 2);
39
+ console.log('\n' + formattedSummary + '\n');
40
+ const alreadyAttached = testInfo.attachments?.some((a) => a.name.includes('Specter AI Diagnostics'));
41
+ if (!alreadyAttached && testInfo.attachments) {
42
+ testInfo.attachments.push({
43
+ name: 'Specter AI Diagnostics (JSON)',
44
+ contentType: 'application/json',
45
+ body: Buffer.from(JSON.stringify(diagnostics, null, 2))
46
+ });
47
+ testInfo.attachments.push({
48
+ name: 'Specter AI Diagnostics (Markdown)',
49
+ contentType: 'text/markdown',
50
+ body: Buffer.from(formattedSummary)
51
+ });
52
+ }
53
+ }
54
+ }
55
+ }
56
+ catch (e) {
57
+ console.error(`[Specter] Failed to capture AI diagnostics on test failure (${source}):`, e);
58
+ }
59
+ }
@@ -44,9 +44,10 @@ const material_matchers_1 = require("../matchers/material-matchers");
44
44
  const ai_matchers_1 = require("../matchers/ai-matchers");
45
45
  const performance_matchers_1 = require("../matchers/performance-matchers");
46
46
  const visual_matchers_1 = require("../matchers/visual-matchers");
47
+ const failure_capture_1 = require("./failure-capture");
47
48
  exports.expect = (0, test_1.mergeExpects)(gas_matchers_1.gasExpect, actor_matchers_1.actorExpect, locator_matchers_1.locatorExpect, widget_matchers_1.widgetExpect, material_matchers_1.materialExpect, ai_matchers_1.aiExpect, performance_matchers_1.performanceExpect, visual_matchers_1.visualExpect);
48
49
  // 2. Define the scopes in the extend block
49
- exports.test = test_1.test.extend({
50
+ const extendedTest = test_1.test.extend({
50
51
  // OPTIONS FIXTURES: Configurable via playwright.config.ts `use: { ... }` or `test.use({ ... })`
51
52
  timeDilation: [1.0, { option: true }],
52
53
  fixedDeltaSeconds: [0, { option: true }],
@@ -70,22 +71,29 @@ exports.test = test_1.test.extend({
70
71
  const activeDilation = (envDilation !== undefined && !isNaN(envDilation) && envDilation > 0) ? envDilation : (timeDilation || 1.0);
71
72
  const world = new specter_client_1.SpecterWorld(specter);
72
73
  world.timeDilation = activeDilation;
74
+ testInfo._specterWorld = world;
75
+ (0, failure_capture_1.setActiveWorld)(world);
73
76
  if (activeDilation !== 1.0) {
74
77
  await world.setTimeScale(activeDilation);
75
78
  }
76
79
  if (fixedDeltaSeconds && fixedDeltaSeconds > 0) {
77
80
  await world.console(`r.FixedDeltaTime ${fixedDeltaSeconds}`);
78
81
  }
79
- await use(world);
80
- // Teardown: Reset fixed delta time if configured
81
- if (fixedDeltaSeconds && fixedDeltaSeconds > 0) {
82
- try {
83
- await world.console(`r.FixedDeltaTime 0`);
82
+ try {
83
+ await use(world);
84
+ }
85
+ finally {
86
+ (0, failure_capture_1.setActiveWorld)(null);
87
+ // Teardown: Reset fixed delta time if configured
88
+ if (fixedDeltaSeconds && fixedDeltaSeconds > 0) {
89
+ try {
90
+ await world.console(`r.FixedDeltaTime 0`);
91
+ }
92
+ catch (e) { }
84
93
  }
85
- catch (e) { }
94
+ // Wipe the level clean for the next test in the queue (also restores slomo 1.0 if dilated)
95
+ await world.cleanup();
86
96
  }
87
- // Wipe the level clean for the next test in the queue (also restores slomo 1.0 if dilated)
88
- await world.cleanup();
89
97
  },
90
98
  // THE MULTIPLAYER FACTORY FIXTURE
91
99
  createWorld: async ({ timeDilation }, use) => {
@@ -210,41 +218,33 @@ exports.test = test_1.test.extend({
210
218
  }
211
219
  },
212
220
  autoScreenshot: [async ({ world }, use, testInfo) => {
213
- // Yield control to run the actual test
214
- await use();
215
- // FIX: Catch 'failed', 'timedOut', and 'interrupted' statuses
216
- if (testInfo.status !== 'passed' && testInfo.status !== 'skipped') {
217
- const safeName = `Specter_Fail_${testInfo.title.replace(/[^a-zA-Z0-9]/g, '_')}`;
218
- try {
219
- // Attached by takeScreenshot itself
220
- await world.takeScreenshot(safeName, true, { attachmentName: 'Unreal Engine Viewport' });
221
+ // Capture as soon as the test function ends, before afterEach hooks and fixture teardown change the scene.
222
+ // Playwright runs these callbacks between the two (its own screenshot-on-failure uses them). Wrapping test()
223
+ // instead would make Playwright record the wrapper as every test's location (file and line).
224
+ const onTestFunctionEnd = async () => {
225
+ if (testInfo.status !== 'passed' && testInfo.status !== 'skipped') {
226
+ await (0, failure_capture_1.captureSpecterFailure)(world, testInfo, 'test-end');
221
227
  }
222
- catch (e) {
223
- console.error("[Specter] Failed to capture error screenshot:", e);
228
+ };
229
+ const callbacks = testInfo._onDidFinishTestFunctionCallbacks;
230
+ if (callbacks instanceof Set) {
231
+ callbacks.add(onTestFunctionEnd);
232
+ }
233
+ try {
234
+ await use();
235
+ }
236
+ finally {
237
+ if (callbacks instanceof Set) {
238
+ callbacks.delete(onTestFunctionEnd);
224
239
  }
225
- try {
226
- const diagnostics = await world.getDiagnostics({ limit: 35 });
227
- if (diagnostics) {
228
- const formattedSummary = (0, gas_matchers_1.formatAiDiagnostics)(diagnostics);
229
- console.log('\n' + formattedSummary + '\n');
230
- const alreadyAttached = testInfo.attachments.some(a => a.name.includes('Specter AI Diagnostics'));
231
- if (!alreadyAttached) {
232
- testInfo.attachments.push({
233
- name: 'Specter AI Diagnostics (JSON)',
234
- contentType: 'application/json',
235
- body: Buffer.from(JSON.stringify(diagnostics, null, 2))
236
- });
237
- testInfo.attachments.push({
238
- name: 'Specter AI Diagnostics (Markdown)',
239
- contentType: 'text/markdown',
240
- body: Buffer.from(formattedSummary)
241
- });
242
- }
240
+ // FIX: Catch 'failed', 'timedOut', and 'interrupted' statuses if not already captured earlier
241
+ if (testInfo.status !== 'passed' && testInfo.status !== 'skipped') {
242
+ if (!testInfo._specterFailureCaptured) {
243
+ await (0, failure_capture_1.captureSpecterFailure)(world, testInfo, 'autoScreenshot-fallback');
243
244
  }
244
245
  }
245
- catch (e) {
246
- console.error("[Specter] Failed to capture AI diagnostics on test failure:", e);
247
- }
248
246
  }
249
247
  }, { auto: true }]
250
248
  });
249
+ (0, failure_capture_1.setAiDiagnosticsFormatter)(gas_matchers_1.formatAiDiagnostics);
250
+ exports.test = extendedTest;
@@ -7,6 +7,7 @@ exports.instrumentMatchers = instrumentMatchers;
7
7
  const test_1 = __importDefault(require("@playwright/test"));
8
8
  const specter_matcher_report_1 = require("../core/specter-matcher-report");
9
9
  const specter_perf_1 = require("../core/specter-perf");
10
+ const failure_capture_1 = require("../core/failure-capture");
10
11
  const MAX_ARG_LENGTH = 60;
11
12
  const MAX_ARGS_LENGTH = 140;
12
13
  const MAX_REPORT_VALUE_LENGTH = 4000;
@@ -27,17 +28,36 @@ function instrumentMatchers(matchers) {
27
28
  // Keep the client tag ("[Server] ", "[Client 1] ") in front, as the old per-matcher titles did.
28
29
  const title = `${clientTagOf(receiver)}${isNot ? 'not.' : ''}${name}(${formatArgs(args)}) @ ${describe(receiver)}`;
29
30
  const result = await test_1.default.step(title, async () => matcher.call(this, receiver, ...args));
31
+ const passed = isNot ? !result.pass : result.pass;
30
32
  // Back in the expect step's context here, so the attachment lands on it.
31
33
  recordResult({
32
34
  matcher: name,
33
35
  isNot,
34
- pass: isNot ? !result.pass : result.pass,
36
+ pass: passed,
35
37
  locator: selectorOf(receiver),
36
38
  locatorLabel: labelOf(receiver),
37
39
  client: clientTagOf(receiver).replace(/^\[|\]\s*$/g, '') || undefined,
38
40
  expected: result.expected,
39
41
  actual: result.actual,
40
42
  });
43
+ // If the matcher failed, capture the engine failure screenshot & diagnostics immediately
44
+ // before the assertion error throws and before any afterEach cleanup hooks run.
45
+ if (!passed) {
46
+ let info;
47
+ try {
48
+ info = test_1.default.info();
49
+ }
50
+ catch { }
51
+ const targetWorld = info?._specterWorld || receiver?.world || (0, failure_capture_1.getActiveWorld)();
52
+ if (targetWorld && info) {
53
+ try {
54
+ await (0, failure_capture_1.captureSpecterFailure)(targetWorld, info, 'matcher');
55
+ }
56
+ catch (e) {
57
+ console.error('[Specter] Error capturing failure state in matcher:', e);
58
+ }
59
+ }
60
+ }
41
61
  return result;
42
62
  };
43
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specter-automation/test",
3
- "version": "1.0.150",
3
+ "version": "1.0.152",
4
4
  "description": "Playwright integration for Unreal Engine automation via Specter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",