viberadar 0.3.209 → 0.3.210

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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,OAAO,EAAE,UAAU,EAA4H,MAAM,YAAY,CAAC;AAOlK,UAAU,aAAa;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;CACrB;AA0vED,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAgvG1G"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,OAAO,EAAE,UAAU,EAA4H,MAAM,YAAY,CAAC;AAOlK,UAAU,aAAa;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;CACrB;AA0vED,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAuzG1G"}
@@ -2223,18 +2223,66 @@ function startServer({ data: initialData, port, projectRoot }) {
2223
2223
  }
2224
2224
  return out;
2225
2225
  }
2226
- function buildLoadConfig(cfg) {
2226
+ function resolveLoadLocalPath(value) {
2227
+ if (typeof value !== 'string' || !value.trim())
2228
+ return undefined;
2229
+ const raw = value.trim();
2230
+ return path.resolve(path.isAbsolute(raw) ? raw : path.join(projectRoot, raw));
2231
+ }
2232
+ function copyLoadDataFiles(sourcePath, workDir) {
2233
+ if (!sourcePath || !fs.existsSync(sourcePath))
2234
+ return 0;
2235
+ const stat = fs.statSync(sourcePath);
2236
+ let copied = 0;
2237
+ const copyOne = (src, dst) => {
2238
+ const st = fs.statSync(src);
2239
+ if (st.isDirectory()) {
2240
+ fs.mkdirSync(dst, { recursive: true });
2241
+ for (const name of fs.readdirSync(src)) {
2242
+ if (name === '.git' || name === 'node_modules' || name === 'dist')
2243
+ continue;
2244
+ copyOne(path.join(src, name), path.join(dst, name));
2245
+ }
2246
+ return;
2247
+ }
2248
+ if (!st.isFile())
2249
+ return;
2250
+ fs.mkdirSync(path.dirname(dst), { recursive: true });
2251
+ fs.copyFileSync(src, dst);
2252
+ copied++;
2253
+ };
2254
+ if (stat.isDirectory()) {
2255
+ for (const name of fs.readdirSync(sourcePath)) {
2256
+ if (name === '.git' || name === 'node_modules' || name === 'dist')
2257
+ continue;
2258
+ copyOne(path.join(sourcePath, name), path.join(workDir, name));
2259
+ }
2260
+ }
2261
+ else if (stat.isFile()) {
2262
+ copyOne(sourcePath, path.join(workDir, path.basename(sourcePath)));
2263
+ }
2264
+ return copied;
2265
+ }
2266
+ function buildLoadConfig(cfg, paths) {
2227
2267
  const envVars = sanitizeLoadEnvVars(cfg.envVars);
2228
2268
  const baseUrl = typeof cfg.baseUrl === 'string' && cfg.baseUrl.trim() ? cfg.baseUrl.trim() : 'http://localhost:5000';
2269
+ const dataDir = resolveLoadLocalPath(cfg.dataDir);
2270
+ const resultDir = resolveLoadLocalPath(cfg.resultDir);
2229
2271
  envVars.BASE_URL = baseUrl;
2230
2272
  const config = {
2231
2273
  vus: normalizeLoadVus(cfg.vus),
2232
2274
  duration: normalizeLoadDuration(cfg.duration),
2233
2275
  baseUrl,
2234
2276
  scriptName: sanitizeLoadScriptName(cfg.scriptName),
2277
+ dataDir,
2278
+ resultDir,
2279
+ runDir: paths?.runDir,
2280
+ workDir: paths?.workDir,
2281
+ resultPath: paths?.resultPath,
2282
+ dataFilesCopied: paths?.dataFilesCopied,
2235
2283
  envVars: redactLoadEnvVars(envVars),
2236
2284
  };
2237
- return { config, envVars };
2285
+ return { config, envVars, dataDir, resultDir };
2238
2286
  }
2239
2287
  function flattenK6Checks(group) {
2240
2288
  let passes = 0;
@@ -2334,6 +2382,10 @@ function startServer({ data: initialData, port, projectRoot }) {
2334
2382
  fs.unlinkSync(path.join(loadRunsDir, `${old.runId}.json`));
2335
2383
  }
2336
2384
  catch { }
2385
+ try {
2386
+ fs.rmSync(path.join(loadRunsDir, old.runId), { recursive: true, force: true });
2387
+ }
2388
+ catch { }
2337
2389
  }
2338
2390
  }
2339
2391
  function loadLastRunIntoState() {
@@ -5045,7 +5097,7 @@ a{color:var(--blue)}
5045
5097
  req.on('data', (d) => { body += d; });
5046
5098
  req.on('end', () => {
5047
5099
  try {
5048
- const { name, script, vus, duration, baseUrl } = JSON.parse(body);
5100
+ const { name, script, vus, duration, baseUrl, dataDir, resultDir } = JSON.parse(body);
5049
5101
  if (!name || !script) {
5050
5102
  res.writeHead(400, jsonH);
5051
5103
  res.end(JSON.stringify({ error: 'name and script required' }));
@@ -5063,6 +5115,8 @@ a{color:var(--blue)}
5063
5115
  vus: normalizeLoadVus(vus),
5064
5116
  duration: normalizeLoadDuration(duration),
5065
5117
  baseUrl: typeof baseUrl === 'string' && baseUrl.trim() ? baseUrl.trim() : 'http://localhost:5000',
5118
+ dataDir: resolveLoadLocalPath(dataDir),
5119
+ resultDir: resolveLoadLocalPath(resultDir),
5066
5120
  };
5067
5121
  // overwrite if same name exists
5068
5122
  const existing = fs.readdirSync(scriptsDir).find(f => {
@@ -5220,12 +5274,20 @@ a{color:var(--blue)}
5220
5274
  res.end(JSON.stringify({ error: 'No script provided' }));
5221
5275
  return;
5222
5276
  }
5223
- const { config: loadConfig, envVars } = buildLoadConfig(cfg);
5224
5277
  const runId = `load-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
5225
- const scriptPath = path.join(os.tmpdir(), `viberadar-k6-${Date.now()}.js`);
5226
- const jsonOutPath = path.join(os.tmpdir(), `viberadar-k6-out-${Date.now()}.ndjson`);
5227
- const summaryPath = path.join(os.tmpdir(), `viberadar-k6-summary-${Date.now()}.json`);
5278
+ const runDir = path.join(loadRunsDir, runId);
5279
+ const workDir = path.join(runDir, 'work');
5280
+ const defaultResultDir = path.join(runDir, 'results');
5281
+ const initial = buildLoadConfig(cfg);
5282
+ const resultPath = initial.resultDir ? path.join(initial.resultDir, runId) : defaultResultDir;
5283
+ const scriptPath = path.join(workDir, 'script.js');
5284
+ const jsonOutPath = path.join(resultPath, 'metrics.ndjson');
5285
+ const summaryPath = path.join(resultPath, 'summary.json');
5286
+ let dataFilesCopied = 0;
5228
5287
  try {
5288
+ fs.mkdirSync(workDir, { recursive: true });
5289
+ fs.mkdirSync(resultPath, { recursive: true });
5290
+ dataFilesCopied = copyLoadDataFiles(initial.dataDir, workDir);
5229
5291
  fs.writeFileSync(scriptPath, script, 'utf-8');
5230
5292
  }
5231
5293
  catch (e) {
@@ -5233,6 +5295,12 @@ a{color:var(--blue)}
5233
5295
  res.end(JSON.stringify({ error: e.message }));
5234
5296
  return;
5235
5297
  }
5298
+ const { config: loadConfig, envVars } = buildLoadConfig(cfg, {
5299
+ runDir,
5300
+ workDir,
5301
+ resultPath,
5302
+ dataFilesCopied,
5303
+ });
5236
5304
  loadRunning = true;
5237
5305
  loadState = {
5238
5306
  runId, status: 'running', startTime: Date.now(), buckets: [], totalRequests: 0,
@@ -5256,7 +5324,7 @@ a{color:var(--blue)}
5256
5324
  scriptPath,
5257
5325
  ];
5258
5326
  loadProc = (0, child_process_1.spawn)('k6', args, {
5259
- cwd: projectRoot, env: { ...process.env }, shell: WIN, stdio: 'pipe',
5327
+ cwd: workDir, env: { ...process.env }, shell: WIN, stdio: 'pipe',
5260
5328
  });
5261
5329
  const addLog = (line) => {
5262
5330
  loadState.logs.push(line);
@@ -5353,15 +5421,11 @@ a{color:var(--blue)}
5353
5421
  saveLoadRun();
5354
5422
  broadcast('load-done', { runId: loadState.runId, status: loadState.status, summary: loadState.summary });
5355
5423
  try {
5356
- fs.unlinkSync(scriptPath);
5357
- }
5358
- catch { }
5359
- try {
5360
- fs.unlinkSync(jsonOutPath);
5424
+ fs.writeFileSync(path.join(resultPath, 'k6.log'), loadState.logs.join('\n'), 'utf-8');
5361
5425
  }
5362
5426
  catch { }
5363
5427
  try {
5364
- fs.unlinkSync(summaryPath);
5428
+ fs.writeFileSync(path.join(resultPath, 'config.json'), JSON.stringify(loadState.config, null, 2), 'utf-8');
5365
5429
  }
5366
5430
  catch { }
5367
5431
  });
@@ -5376,11 +5440,11 @@ a{color:var(--blue)}
5376
5440
  saveLoadRun();
5377
5441
  broadcast('load-done', { runId: loadState.runId, status: 'error', summary: loadState.summary });
5378
5442
  try {
5379
- fs.unlinkSync(scriptPath);
5443
+ fs.writeFileSync(path.join(resultPath, 'k6.log'), loadState.logs.join('\n'), 'utf-8');
5380
5444
  }
5381
5445
  catch { }
5382
5446
  try {
5383
- fs.unlinkSync(summaryPath);
5447
+ fs.writeFileSync(path.join(resultPath, 'config.json'), JSON.stringify(loadState.config, null, 2), 'utf-8');
5384
5448
  }
5385
5449
  catch { }
5386
5450
  });