@specter-automation/test 1.0.128 → 1.0.129

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.
@@ -11,8 +11,23 @@ export default class SpecterReporter implements Reporter {
11
11
  private sentImages;
12
12
  /** The step each test failed at (the first failing step outside hooks), so the failure screenshot can sit next to it. */
13
13
  private failedSteps;
14
+ private runStartedAt;
15
+ /** Where tests are staged until the run ends: specter-traces/.run-<stamp> */
16
+ private runStageDir;
17
+ /** Staged tests by name. A retried test replaces its earlier attempt. */
18
+ private runTests;
19
+ private runTestCounter;
20
+ private runHasFailure;
21
+ private runReplay;
22
+ private runReplayWaiters;
14
23
  constructor();
15
24
  private connect;
25
+ /**
26
+ * The engine broadcasts everything to every client, so most messages here are other clients' command
27
+ * responses. Only the two about the run's replay matter to the reporter.
28
+ */
29
+ private handleEngineMessage;
30
+ private releaseReplayWaiters;
16
31
  private recordedEvents;
17
32
  private send;
18
33
  onBegin(config: FullConfig, suite: Suite): void;
@@ -40,5 +55,13 @@ export default class SpecterReporter implements Reporter {
40
55
  onStdErr(chunk: string | Buffer, test: void | TestCase, result: void | TestResult): void;
41
56
  onTestEnd(test: TestCase, result: TestResult): void;
42
57
  private saveTraceFile;
43
- onEnd(result: FullResult): void;
58
+ private runTraceMode;
59
+ private stageTestForRunTrace;
60
+ /**
61
+ * Waits for the engine to say the replay is finished, then for the file to stop growing (the engine
62
+ * writes it in the background). Returns the file to pack, or null when there is no replay to include.
63
+ */
64
+ private waitForRunReplay;
65
+ private saveRunTrace;
66
+ onEnd(result: FullResult): Promise<void>;
44
67
  }
@@ -42,6 +42,17 @@ const fs = __importStar(require("fs"));
42
42
  const os = __importStar(require("os"));
43
43
  const path = __importStar(require("path"));
44
44
  const specter_matcher_report_1 = require("./specter-matcher-report");
45
+ const specter_zip_1 = require("./specter-zip");
46
+ function pad(value, length = 2) {
47
+ return String(value).padStart(length, '0');
48
+ }
49
+ /** 20261006-114502, in local time: sorts by name in recording order */
50
+ function fileStamp(date) {
51
+ return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
52
+ }
53
+ function sleep(ms) {
54
+ return new Promise(resolve => setTimeout(resolve, ms));
55
+ }
45
56
  function extractLocatorFromExpectTitle(title) {
46
57
  if (!title.startsWith('expect('))
47
58
  return '';
@@ -104,6 +115,16 @@ class SpecterReporter {
104
115
  sentImages = new Map();
105
116
  /** The step each test failed at (the first failing step outside hooks), so the failure screenshot can sit next to it. */
106
117
  failedSteps = new Map();
118
+ // --- Run trace: one archive holding every test of the run and the run's replay ---
119
+ runStartedAt = new Date();
120
+ /** Where tests are staged until the run ends: specter-traces/.run-<stamp> */
121
+ runStageDir = null;
122
+ /** Staged tests by name. A retried test replaces its earlier attempt. */
123
+ runTests = new Map();
124
+ runTestCounter = 0;
125
+ runHasFailure = false;
126
+ runReplay = null;
127
+ runReplayWaiters = [];
107
128
  constructor() {
108
129
  this.connect();
109
130
  }
@@ -124,8 +145,63 @@ class SpecterReporter {
124
145
  });
125
146
  socket.on('close', () => {
126
147
  this.isConnected = false;
148
+ // Nothing more will arrive: stop waiting for the replay
149
+ this.releaseReplayWaiters();
150
+ });
151
+ socket.on('message', (data) => {
152
+ this.handleEngineMessage(data);
127
153
  });
128
154
  }
155
+ /**
156
+ * The engine broadcasts everything to every client, so most messages here are other clients' command
157
+ * responses. Only the two about the run's replay matter to the reporter.
158
+ */
159
+ handleEngineMessage(data) {
160
+ try {
161
+ const buffer = Array.isArray(data) ? Buffer.concat(data) : Buffer.isBuffer(data) ? data : Buffer.from(data);
162
+ if (!buffer.includes('run-replay')) {
163
+ return;
164
+ }
165
+ const message = JSON.parse(buffer.toString('utf-8'));
166
+ if (message?.type !== 'event' || !message.data) {
167
+ return;
168
+ }
169
+ if (message.eventName === 'run-replay-started' && message.data.replayName) {
170
+ // Recording began. Remember where the file will be in case the engine goes away before the run ends.
171
+ this.runReplay = {
172
+ name: String(message.data.replayName),
173
+ file: String(message.data.replayFile ?? ''),
174
+ tests: new Map(),
175
+ finished: false
176
+ };
177
+ }
178
+ else if (message.eventName === 'run-replay' && message.data.replayName) {
179
+ const tests = new Map();
180
+ for (const entry of Array.isArray(message.data.tests) ? message.data.tests : []) {
181
+ if (entry?.testName) {
182
+ tests.set(String(entry.testName), { start: Number(entry.start ?? -1), end: Number(entry.end ?? -1) });
183
+ }
184
+ }
185
+ this.runReplay = {
186
+ name: String(message.data.replayName),
187
+ file: String(message.data.replayFile ?? this.runReplay?.file ?? ''),
188
+ tests,
189
+ finished: true
190
+ };
191
+ this.releaseReplayWaiters();
192
+ }
193
+ }
194
+ catch {
195
+ // Not ours, or not JSON
196
+ }
197
+ }
198
+ releaseReplayWaiters() {
199
+ const waiters = this.runReplayWaiters;
200
+ this.runReplayWaiters = [];
201
+ for (const resolve of waiters) {
202
+ resolve();
203
+ }
204
+ }
129
205
  recordedEvents = new Map();
130
206
  send(payload) {
131
207
  const msg = JSON.stringify(payload);
@@ -151,6 +227,7 @@ class SpecterReporter {
151
227
  }
152
228
  }
153
229
  onBegin(config, suite) {
230
+ this.runStartedAt = new Date();
154
231
  this.send({
155
232
  event: 'run_started',
156
233
  payload: {}
@@ -564,6 +641,8 @@ class SpecterReporter {
564
641
  status: result.status
565
642
  }
566
643
  });
644
+ // Every test goes into the run trace, passed or not (before the events are dropped below)
645
+ this.stageTestForRunTrace(uniqueTestKey, test, result);
567
646
  // Determine if portable trace should be saved:
568
647
  // Default: save on failure, on CI, or when SPECTER_TRACE !== 'off'
569
648
  const isFailure = result.status !== 'passed';
@@ -622,13 +701,222 @@ class SpecterReporter {
622
701
  this.recordedEvents.delete(testKey);
623
702
  }
624
703
  }
625
- onEnd(result) {
704
+ // ------------------------------------------------------------------------------------------------
705
+ // Run trace
706
+ //
707
+ // One file for the whole run: specter-traces/run-<stamp>.specter-trace.zip
708
+ //
709
+ // run.json what ran, and where everything is
710
+ // tests/001_<name>/trace.json one test: the same content as a single-test trace
711
+ // tests/001_<name>/screenshots/*.png its images
712
+ // replay/<name>.replay the engine's replay of the run, when it recorded one
713
+ //
714
+ // Tests are staged on disk as they finish, so a long run doesn't sit in memory, and the archive is
715
+ // written when the run ends. Saved when a test failed, on CI, or with SPECTER_TRACE=on; never with
716
+ // SPECTER_TRACE=off.
717
+ // ------------------------------------------------------------------------------------------------
718
+ runTraceMode() {
719
+ const traceEnv = process.env.SPECTER_TRACE;
720
+ if (traceEnv === 'off')
721
+ return 'off';
722
+ if (traceEnv === 'on' || traceEnv === 'always')
723
+ return 'on';
724
+ return 'auto';
725
+ }
726
+ stageTestForRunTrace(testKey, test, result) {
727
+ if (this.runTraceMode() === 'off') {
728
+ return;
729
+ }
730
+ try {
731
+ if (!this.runStageDir) {
732
+ this.runStageDir = path.resolve(process.cwd(), 'specter-traces', `.run-${fileStamp(this.runStartedAt)}-${process.pid}`);
733
+ fs.rmSync(this.runStageDir, { recursive: true, force: true });
734
+ }
735
+ // A retry replaces the earlier attempt and keeps its place in the run
736
+ const previous = this.runTests.get(testKey);
737
+ const folder = previous?.folder
738
+ ?? `tests/${pad(++this.runTestCounter, 3)}_${testKey.replace(/[^a-zA-Z0-9_-]/g, '_').substring(0, 60)}`;
739
+ const testDir = path.join(this.runStageDir, folder);
740
+ fs.rmSync(testDir, { recursive: true, force: true });
741
+ fs.mkdirSync(testDir, { recursive: true });
742
+ // Images are copied now: Playwright clears a test's output folder on retry and on the next run.
743
+ // They are listed by the path the events refer to, so two images with the same name stay apart.
744
+ const events = this.recordedEvents.get(testKey) || [];
745
+ const screenshotFiles = {};
746
+ const addImage = (name, sourcePath) => {
747
+ if (!sourcePath || screenshotFiles[sourcePath] || !fs.existsSync(sourcePath)) {
748
+ return;
749
+ }
750
+ const index = Object.keys(screenshotFiles).length + 1;
751
+ const safeName = (name || path.basename(sourcePath)).replace(/\.[a-zA-Z0-9]+$/, '').replace(/[^a-zA-Z0-9_-]/g, '_').substring(0, 60);
752
+ const relative = `screenshots/${pad(index)}_${safeName}.png`;
753
+ try {
754
+ fs.mkdirSync(path.join(testDir, 'screenshots'), { recursive: true });
755
+ fs.copyFileSync(sourcePath, path.join(testDir, relative));
756
+ screenshotFiles[sourcePath] = relative;
757
+ }
758
+ catch { }
759
+ };
760
+ for (const recorded of events) {
761
+ if (recorded.event === 'attachment') {
762
+ addImage(recorded.payload?.name, recorded.payload?.path);
763
+ }
764
+ }
765
+ for (const attachment of result.attachments) {
766
+ if (attachment.contentType.startsWith('image/')) {
767
+ addImage(attachment.name, attachment.path);
768
+ }
769
+ }
770
+ const tracePayload = {
771
+ specterTraceVersion: '1.0',
772
+ testName: testKey,
773
+ file: test.location?.file,
774
+ line: test.location?.line,
775
+ status: result.status,
776
+ durationMs: result.duration,
777
+ error: result.error ? this.formatError(result.error, result) : undefined,
778
+ recordedAt: new Date().toISOString(),
779
+ events,
780
+ screenshotFiles
781
+ };
782
+ fs.writeFileSync(path.join(testDir, 'trace.json'), JSON.stringify(tracePayload), 'utf-8');
783
+ this.runTests.set(testKey, {
784
+ testName: testKey,
785
+ folder,
786
+ file: test.location?.file,
787
+ line: test.location?.line,
788
+ status: result.status,
789
+ durationMs: result.duration
790
+ });
791
+ if (result.status !== 'passed' && result.status !== 'skipped') {
792
+ this.runHasFailure = true;
793
+ }
794
+ }
795
+ catch (e) {
796
+ console.error(`[Specter Trace] Failed to stage ${testKey} for the run trace:`, e);
797
+ }
798
+ }
799
+ /**
800
+ * Waits for the engine to say the replay is finished, then for the file to stop growing (the engine
801
+ * writes it in the background). Returns the file to pack, or null when there is no replay to include.
802
+ */
803
+ async waitForRunReplay() {
804
+ // The engine announces a recording when the run starts. No announcement: no replay, and no waiting.
805
+ if (!this.runReplay) {
806
+ return null;
807
+ }
808
+ if (!this.runReplay.finished && this.isConnected) {
809
+ await Promise.race([
810
+ new Promise(resolve => this.runReplayWaiters.push(resolve)),
811
+ sleep(5000)
812
+ ]);
813
+ }
814
+ const replayFile = this.runReplay.file;
815
+ if (!replayFile) {
816
+ return null;
817
+ }
818
+ let lastSize = -1;
819
+ for (let attempt = 0; attempt < 20; attempt++) {
820
+ let size = -1;
821
+ try {
822
+ size = fs.statSync(replayFile).size;
823
+ }
824
+ catch { }
825
+ if (size > 0 && size === lastSize) {
826
+ return replayFile;
827
+ }
828
+ lastSize = size;
829
+ await sleep(150);
830
+ }
831
+ // Not on this machine (the game runs elsewhere), or it never settled
832
+ return lastSize > 0 ? replayFile : null;
833
+ }
834
+ async saveRunTrace(result) {
835
+ const stageDir = this.runStageDir;
836
+ if (!stageDir) {
837
+ return;
838
+ }
839
+ const mode = this.runTraceMode();
840
+ const shouldSave = this.runTests.size > 0
841
+ && (mode === 'on' || (mode === 'auto' && (this.runHasFailure || process.env.CI !== undefined)));
842
+ let zip = null;
843
+ let partialPath = '';
844
+ try {
845
+ if (!shouldSave) {
846
+ return;
847
+ }
848
+ const replayFile = await this.waitForRunReplay();
849
+ const replay = this.runReplay;
850
+ const replayEntry = replay && replayFile
851
+ ? `replay/${replay.name.replace(/[^a-zA-Z0-9._-]/g, '_')}.replay`
852
+ : null;
853
+ const tests = [...this.runTests.values()].sort((a, b) => a.folder.localeCompare(b.folder));
854
+ const manifest = {
855
+ specterRunTraceVersion: '1.0',
856
+ recordedAt: this.runStartedAt.toISOString(),
857
+ status: result.status,
858
+ durationMs: Math.round(result.duration),
859
+ tests: tests.map(entry => {
860
+ const span = replayEntry ? replay?.tests.get(entry.testName) ?? replay?.tests.get(entry.testName.replace(/\\/g, '/')) : undefined;
861
+ return {
862
+ testName: entry.testName,
863
+ file: entry.file,
864
+ line: entry.line,
865
+ status: entry.status,
866
+ durationMs: entry.durationMs,
867
+ trace: `${entry.folder}/trace.json`,
868
+ replayStart: span?.start,
869
+ replayEnd: span?.end
870
+ };
871
+ }),
872
+ replay: replay && replayEntry ? { name: replay.name, file: replayEntry } : undefined
873
+ };
874
+ const traceDir = path.dirname(stageDir);
875
+ const finalPath = path.join(traceDir, `run-${fileStamp(this.runStartedAt)}.specter-trace.zip`);
876
+ partialPath = `${finalPath}.partial`;
877
+ zip = new specter_zip_1.SpecterZipWriter(partialPath);
878
+ zip.addFile('run.json', Buffer.from(JSON.stringify(manifest, null, 2), 'utf-8'));
879
+ for (const entry of tests) {
880
+ const testDir = path.join(stageDir, entry.folder);
881
+ zip.addFile(`${entry.folder}/trace.json`, fs.readFileSync(path.join(testDir, 'trace.json')));
882
+ const imageDir = path.join(testDir, 'screenshots');
883
+ if (fs.existsSync(imageDir)) {
884
+ for (const image of fs.readdirSync(imageDir).sort()) {
885
+ zip.addFile(`${entry.folder}/screenshots/${image}`, fs.readFileSync(path.join(imageDir, image)), { store: true });
886
+ }
887
+ }
888
+ }
889
+ if (replayFile && replayEntry) {
890
+ zip.addFile(replayEntry, fs.readFileSync(replayFile));
891
+ }
892
+ zip.close();
893
+ fs.rmSync(finalPath, { force: true });
894
+ fs.renameSync(partialPath, finalPath);
895
+ partialPath = '';
896
+ const failed = tests.filter(entry => entry.status !== 'passed' && entry.status !== 'skipped').length;
897
+ console.log(`[Specter Trace] Saved run trace (${tests.length} test${tests.length === 1 ? '' : 's'}, ${failed} failed, ${replayEntry ? 'with replay' : 'no replay'}) to: ${finalPath}`);
898
+ }
899
+ catch (e) {
900
+ console.error('[Specter Trace] Failed to write the run trace:', e);
901
+ zip?.abort();
902
+ }
903
+ finally {
904
+ if (partialPath) {
905
+ fs.rmSync(partialPath, { force: true });
906
+ }
907
+ fs.rmSync(stageDir, { recursive: true, force: true });
908
+ this.runStageDir = null;
909
+ this.runTests.clear();
910
+ }
911
+ }
912
+ async onEnd(result) {
626
913
  this.send({
627
914
  event: 'run_ended',
628
915
  payload: {
629
916
  status: result.status
630
917
  }
631
918
  });
919
+ await this.saveRunTrace(result);
632
920
  }
633
921
  }
634
922
  exports.default = SpecterReporter;
@@ -0,0 +1,21 @@
1
+ export declare class SpecterZipWriter {
2
+ private readonly filePath;
3
+ private fd;
4
+ private offset;
5
+ private entries;
6
+ private closed;
7
+ constructor(filePath: string);
8
+ /**
9
+ * Adds a file. `name` is its path inside the archive, with forward slashes.
10
+ * Pass `store: true` for data that is already compressed (PNG images).
11
+ */
12
+ addFile(name: string, data: Buffer, options?: {
13
+ store?: boolean;
14
+ date?: Date;
15
+ }): void;
16
+ /** Writes the directory and closes the file. The archive isn't readable until this has run. */
17
+ close(): void;
18
+ /** Closes the file without finishing the archive (after an error). */
19
+ abort(): void;
20
+ private write;
21
+ }
@@ -0,0 +1,195 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SpecterZipWriter = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const zlib = __importStar(require("zlib"));
39
+ /**
40
+ * A minimal .zip writer for run traces, so the package needs no archive dependency.
41
+ * Entries are written one at a time straight to disk (nothing but the entry in hand is held in memory).
42
+ * Plain zip only: no zip64, so the archive and each entry must stay under 4 GB and 65,535 entries.
43
+ */
44
+ const CRC_TABLE = (() => {
45
+ const table = new Uint32Array(256);
46
+ for (let n = 0; n < 256; n++) {
47
+ let c = n;
48
+ for (let k = 0; k < 8; k++) {
49
+ c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
50
+ }
51
+ table[n] = c >>> 0;
52
+ }
53
+ return table;
54
+ })();
55
+ function crc32(data) {
56
+ // Node 20.15+/22.2+ has a native one
57
+ const native = zlib.crc32;
58
+ if (typeof native === 'function') {
59
+ return native(data) >>> 0;
60
+ }
61
+ let crc = 0xffffffff;
62
+ for (let i = 0; i < data.length; i++) {
63
+ crc = CRC_TABLE[(crc ^ data[i]) & 0xff] ^ (crc >>> 8);
64
+ }
65
+ return (crc ^ 0xffffffff) >>> 0;
66
+ }
67
+ const MAX_UINT32 = 0xffffffff;
68
+ const MAX_ENTRIES = 0xffff;
69
+ /** Bit 11: entry names are UTF-8 */
70
+ const FLAG_UTF8 = 0x0800;
71
+ class SpecterZipWriter {
72
+ filePath;
73
+ fd;
74
+ offset = 0;
75
+ entries = [];
76
+ closed = false;
77
+ constructor(filePath) {
78
+ this.filePath = filePath;
79
+ this.fd = fs.openSync(filePath, 'w');
80
+ }
81
+ /**
82
+ * Adds a file. `name` is its path inside the archive, with forward slashes.
83
+ * Pass `store: true` for data that is already compressed (PNG images).
84
+ */
85
+ addFile(name, data, options = {}) {
86
+ if (this.closed) {
87
+ throw new Error('The archive is already closed');
88
+ }
89
+ const entryName = name.replace(/\\/g, '/').replace(/^\/+/, '');
90
+ if (!entryName || entryName.split('/').includes('..')) {
91
+ throw new Error(`Invalid archive entry name: ${name}`);
92
+ }
93
+ if (this.entries.length >= MAX_ENTRIES) {
94
+ throw new Error('Too many files for a zip archive (65,535 at most)');
95
+ }
96
+ let method = 0;
97
+ let body = data;
98
+ if (!options.store && data.length > 0) {
99
+ const deflated = zlib.deflateRawSync(data, { level: 6 });
100
+ if (deflated.length < data.length) {
101
+ method = 8;
102
+ body = deflated;
103
+ }
104
+ }
105
+ if (data.length > MAX_UINT32 || this.offset + body.length > MAX_UINT32) {
106
+ throw new Error('The archive would be larger than 4 GB');
107
+ }
108
+ const date = options.date ?? new Date();
109
+ const dosTime = (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1);
110
+ const dosDate = (Math.max(0, date.getFullYear() - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate();
111
+ const entry = {
112
+ name: Buffer.from(entryName, 'utf-8'),
113
+ method,
114
+ crc: crc32(data),
115
+ compressedSize: body.length,
116
+ size: data.length,
117
+ offset: this.offset,
118
+ dosTime,
119
+ dosDate
120
+ };
121
+ const header = Buffer.alloc(30);
122
+ header.writeUInt32LE(0x04034b50, 0);
123
+ header.writeUInt16LE(20, 4); // version needed
124
+ header.writeUInt16LE(FLAG_UTF8, 6);
125
+ header.writeUInt16LE(entry.method, 8);
126
+ header.writeUInt16LE(entry.dosTime, 10);
127
+ header.writeUInt16LE(entry.dosDate, 12);
128
+ header.writeUInt32LE(entry.crc, 14);
129
+ header.writeUInt32LE(entry.compressedSize, 18);
130
+ header.writeUInt32LE(entry.size, 22);
131
+ header.writeUInt16LE(entry.name.length, 26);
132
+ header.writeUInt16LE(0, 28); // extra field length
133
+ this.write(header);
134
+ this.write(entry.name);
135
+ this.write(body);
136
+ this.entries.push(entry);
137
+ }
138
+ /** Writes the directory and closes the file. The archive isn't readable until this has run. */
139
+ close() {
140
+ if (this.closed) {
141
+ return;
142
+ }
143
+ this.closed = true;
144
+ const directoryOffset = this.offset;
145
+ for (const entry of this.entries) {
146
+ const record = Buffer.alloc(46);
147
+ record.writeUInt32LE(0x02014b50, 0);
148
+ record.writeUInt16LE(20, 4); // version made by
149
+ record.writeUInt16LE(20, 6); // version needed
150
+ record.writeUInt16LE(FLAG_UTF8, 8);
151
+ record.writeUInt16LE(entry.method, 10);
152
+ record.writeUInt16LE(entry.dosTime, 12);
153
+ record.writeUInt16LE(entry.dosDate, 14);
154
+ record.writeUInt32LE(entry.crc, 16);
155
+ record.writeUInt32LE(entry.compressedSize, 20);
156
+ record.writeUInt32LE(entry.size, 24);
157
+ record.writeUInt16LE(entry.name.length, 28);
158
+ // extra length, comment length, disk number, internal attributes (2 bytes each), external attributes (4)
159
+ record.writeUInt32LE(entry.offset, 42);
160
+ this.write(record);
161
+ this.write(entry.name);
162
+ }
163
+ const directorySize = this.offset - directoryOffset;
164
+ if (this.offset > MAX_UINT32) {
165
+ fs.closeSync(this.fd);
166
+ throw new Error('The archive would be larger than 4 GB');
167
+ }
168
+ const end = Buffer.alloc(22);
169
+ end.writeUInt32LE(0x06054b50, 0);
170
+ end.writeUInt16LE(this.entries.length, 8);
171
+ end.writeUInt16LE(this.entries.length, 10);
172
+ end.writeUInt32LE(directorySize, 12);
173
+ end.writeUInt32LE(directoryOffset, 16);
174
+ this.write(end);
175
+ fs.closeSync(this.fd);
176
+ }
177
+ /** Closes the file without finishing the archive (after an error). */
178
+ abort() {
179
+ if (!this.closed) {
180
+ this.closed = true;
181
+ try {
182
+ fs.closeSync(this.fd);
183
+ }
184
+ catch { }
185
+ }
186
+ }
187
+ write(data) {
188
+ let written = 0;
189
+ while (written < data.length) {
190
+ written += fs.writeSync(this.fd, data, written, data.length - written);
191
+ }
192
+ this.offset += data.length;
193
+ }
194
+ }
195
+ exports.SpecterZipWriter = SpecterZipWriter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specter-automation/test",
3
- "version": "1.0.128",
3
+ "version": "1.0.129",
4
4
  "description": "Playwright integration for Unreal Engine automation via Specter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",