taist 0.2.13 → 0.2.15

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.
@@ -542,9 +542,22 @@ export function report(trace) {
542
542
  * Flush the global reporter
543
543
  */
544
544
  export async function flush() {
545
- if (globalReporter) {
546
- await globalReporter.flush();
545
+ const reporter = globalThis[TAIST_REPORTER_KEY];
546
+ if (reporter) {
547
+ await reporter.flush();
547
548
  }
548
549
  }
549
550
 
551
+ /**
552
+ * Reset the global reporter (for testing purposes).
553
+ * Closes the existing reporter and clears the singleton.
554
+ */
555
+ export function resetGlobalReporter() {
556
+ const reporter = globalThis[TAIST_REPORTER_KEY];
557
+ if (reporter) {
558
+ reporter.close();
559
+ }
560
+ globalThis[TAIST_REPORTER_KEY] = null;
561
+ }
562
+
550
563
  export default TraceReporter;
@@ -33,6 +33,7 @@ import fs from 'fs';
33
33
  * @property {boolean} [silent=false] - Suppress output
34
34
  * @property {string | null} [outputFile=null] - Write to file instead of stdout
35
35
  * @property {number} [maxTraceGroups=10] - Max request groups to show in trace output
36
+ * @property {number} [traceGracePeriod=500] - Grace period in ms to wait for late-arriving traces before stopping collector
36
37
  */
37
38
 
38
39
  export class TaistReporter {
@@ -48,6 +49,7 @@ export class TaistReporter {
48
49
  silent: options.silent || false,
49
50
  outputFile: options.outputFile || null,
50
51
  maxTraceGroups: options.maxTraceGroups || 10,
52
+ traceGracePeriod: options.traceGracePeriod ?? 500, // Grace period for late-arriving traces
51
53
  ...options
52
54
  };
53
55
 
@@ -148,6 +150,12 @@ export class TaistReporter {
148
150
  await this.collectorReady;
149
151
  }
150
152
 
153
+ // Wait for late-arriving traces (e.g., from child processes where the
154
+ // outermost resolver trace completes after the HTTP response is sent)
155
+ if (this.options.traceGracePeriod > 0) {
156
+ await new Promise(resolve => setTimeout(resolve, this.options.traceGracePeriod));
157
+ }
158
+
151
159
  // Stop the collector gracefully - this sends shutdown signal to workers
152
160
  // and waits for them to flush their traces before closing (up to 2s timeout)
153
161
  await this.collector.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taist",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "Token-Optimized Testing Framework for AI-Assisted Development",
5
5
  "main": "index.js",
6
6
  "type": "module",