MCPcopy Create free account
hub / github.com/garrytan/gstack / runScript

Function runScript

test/analytics.test.ts:24–47  ·  view source on GitHub ↗

* Run the analytics script with a custom JSONL file by overriding the path. * We test the exported functions directly for unit tests, and use this * helper for integration-style checks.

(jsonlPath: string | null, extraArgs: string = '')

Source from the content-addressed store, hash-verified

22 * helper for integration-style checks.
23 */
24function runScript(jsonlPath: string | null, extraArgs: string = ''): string {
25 // We test via the exported functions; for CLI integration we read the file
26 // and run the pipeline manually to avoid needing to override the hardcoded path.
27 if (jsonlPath === null) {
28 return 'No analytics data found.';
29 }
30 if (!fs.existsSync(jsonlPath)) {
31 return 'No analytics data found.';
32 }
33 const content = fs.readFileSync(jsonlPath, 'utf-8').trim();
34 if (!content) {
35 return 'No analytics data found.';
36 }
37 const events = parseJSONL(content);
38 if (events.length === 0) {
39 return 'No analytics data found.';
40 }
41 // Parse period from extraArgs
42 let period = 'all';
43 const match = extraArgs.match(/--period\s+(\S+)/);
44 if (match) period = match[1];
45 const filtered = filterByPeriod(events, period);
46 return formatReport(filtered, period);
47}
48
49beforeEach(() => {
50 fs.mkdirSync(TMP_DIR, { recursive: true });

Callers 1

analytics.test.tsFile · 0.70

Calls 3

parseJSONLFunction · 0.90
filterByPeriodFunction · 0.90
formatReportFunction · 0.90

Tested by

no test coverage detected