@nice-code/commander 0.95.0 → 0.97.0

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.
@@ -364,9 +364,140 @@ function watchCommanderConfig(options) {
364
364
  };
365
365
  }
366
366
  //#endregion
367
+ //#region src/daemon/suiteRuns.ts
368
+ /** Tasks a tag-group run starts at once — a suite declares its own. */
369
+ const TAG_GROUP_PARALLEL = 4;
370
+ function createSuiteRunner(options) {
371
+ const { supervisor, publish, log } = options;
372
+ const runs = /* @__PURE__ */ new Map();
373
+ const live = /* @__PURE__ */ new Map();
374
+ const verdictOf = (report, id) => {
375
+ const outcome = report.results.find((result) => result.id === id)?.outcome;
376
+ if (outcome === "blocked") return "blocked";
377
+ return outcome === "failed" || outcome == null ? "fail" : "pass";
378
+ };
379
+ const evictTagGroupRuns = () => {
380
+ const ended = [...runs.entries()].filter(([, run]) => run.suite == null && run.endedAt != null).sort(([, a], [, b]) => (b.endedAt ?? 0) - (a.endedAt ?? 0));
381
+ for (const [key] of ended.slice(8)) {
382
+ runs.delete(key);
383
+ publish(key, null);
384
+ }
385
+ };
386
+ return {
387
+ idle: async () => {
388
+ await Promise.all(live.values());
389
+ },
390
+ run: (input) => {
391
+ const config = supervisor.config;
392
+ const suite = input.suite == null ? void 0 : config.suites[input.suite];
393
+ if (input.suite != null && suite == null) return {
394
+ accepted: false,
395
+ reason: `unknown suite "${input.suite}"`
396
+ };
397
+ const known = new Set(config.processes.map((proc) => proc.id));
398
+ const direct = (suite?.ids ?? input.ids ?? []).filter((id) => known.has(id));
399
+ if (direct.length === 0) return {
400
+ accepted: false,
401
+ reason: "nothing to run"
402
+ };
403
+ const filterId = input.filter == null ? void 0 : require_cli.savedFilterId(input.filter);
404
+ const runKey = suite?.name ?? `tg-${require_cli.hashCanonical(filterId ?? [...direct].sort(), 12)}`;
405
+ if (live.has(runKey)) return {
406
+ accepted: false,
407
+ runKey,
408
+ reason: "already running"
409
+ };
410
+ const ordered = require_cli.orderByDependency(config.processes, require_cli.withDependencies(config.processes, direct));
411
+ const byId = new Map(config.processes.map((proc) => [proc.id, proc]));
412
+ const definitions = ordered.flatMap((id) => byId.get(id) ?? []);
413
+ const services = definitions.filter((proc) => proc.kind === "service");
414
+ const tasks = definitions.filter((proc) => proc.kind === "task");
415
+ const previous = runs.get(runKey);
416
+ const run = {
417
+ ...suite != null ? { suite: suite.name } : {},
418
+ ...filterId != null ? { filterId } : {},
419
+ startedAt: Date.now(),
420
+ ...previous?.endedAt != null ? { previousDurationMs: previous.endedAt - previous.startedAt } : {},
421
+ members: Object.fromEntries(ordered.map((id) => [id, "pending"]))
422
+ };
423
+ const announce = () => publish(runKey, {
424
+ ...run,
425
+ members: { ...run.members }
426
+ });
427
+ const mark = (id, verdict) => {
428
+ run.members[id] = verdict;
429
+ announce();
430
+ };
431
+ runs.set(runKey, run);
432
+ announce();
433
+ const execute = async () => {
434
+ const satisfied = /* @__PURE__ */ new Set();
435
+ if (services.length > 0) {
436
+ for (const proc of services) mark(proc.id, "running");
437
+ const report = await supervisor.start(services.map((proc) => proc.id), {
438
+ wait: true,
439
+ staggerMs: suite?.staggerMs ?? 0
440
+ });
441
+ for (const proc of services) mark(proc.id, verdictOf(report, proc.id));
442
+ for (const result of report.results) {
443
+ if (byId.get(result.id)?.kind !== "task") continue;
444
+ mark(result.id, result.outcome === "succeeded" ? "pass" : "fail");
445
+ if (result.outcome === "succeeded") satisfied.add(result.id);
446
+ }
447
+ }
448
+ const pool = await require_cli.runTaskPool({
449
+ tasks: tasks.filter((task) => run.members[task.id] === "pending"),
450
+ parallel: input.parallel ?? suite?.parallel ?? TAG_GROUP_PARALLEL,
451
+ failFast: input.failFast ?? suite?.failFast ?? false,
452
+ run: async (task) => {
453
+ mark(task.id, "running");
454
+ const verdict = verdictOf(await supervisor.start([task.id], {
455
+ wait: true,
456
+ satisfied
457
+ }), task.id);
458
+ if (verdict === "pass") satisfied.add(task.id);
459
+ mark(task.id, verdict);
460
+ return verdict === "pass";
461
+ },
462
+ onBlocked: (task) => mark(task.id, "blocked"),
463
+ onFailFast: () => {
464
+ const running = tasks.filter((task) => run.members[task.id] === "running").map((task) => task.id);
465
+ if (running.length > 0) supervisor.stop(running);
466
+ }
467
+ });
468
+ for (const task of pool.leftover) mark(task.id, "skipped");
469
+ run.endedAt = Date.now();
470
+ run.outcome = Object.values(run.members).every((verdict) => verdict === "pass") ? "passed" : "failed";
471
+ announce();
472
+ log(`run ${runKey}: ${run.outcome} in ${run.endedAt - run.startedAt} ms`);
473
+ evictTagGroupRuns();
474
+ };
475
+ const settled = execute().catch((error) => {
476
+ run.endedAt = Date.now();
477
+ run.outcome = "failed";
478
+ announce();
479
+ log(`run ${runKey}: aborted — ${error.message}`);
480
+ }).finally(() => live.delete(runKey));
481
+ live.set(runKey, settled);
482
+ return {
483
+ accepted: true,
484
+ runKey
485
+ };
486
+ }
487
+ };
488
+ }
489
+ //#endregion
367
490
  //#region src/daemon/controlPlane.ts
368
491
  const DAEMON_COORD = require_cli.RuntimeCoordinate.env("commander_daemon");
369
492
  const SLOW_CONSUMER_DROP_BYTES = 256 * 1024;
493
+ const LIVE_STATES = new Set([
494
+ "starting",
495
+ "running",
496
+ "ready",
497
+ "unready",
498
+ "backoff",
499
+ "stopping"
500
+ ]);
370
501
  function projectExit(exit) {
371
502
  return {
372
503
  ...exit.code != null ? { code: exit.code } : {},
@@ -407,6 +538,7 @@ function projectProcess(status) {
407
538
  notes: status.capability.notes
408
539
  } } : {},
409
540
  tags: status.tags,
541
+ optIn: status.optIn,
410
542
  detail: {
411
543
  command: status.detail.command,
412
544
  cwd: status.detail.cwd,
@@ -437,8 +569,13 @@ function projectProcess(status) {
437
569
  * Members are projected in DAG order (the same `orderByDependency` `up` spawns with), so the
438
570
  * UI's "members in dependency order" and the CLI's execution order are one rule, not two.
439
571
  */
440
- function projectGroups(config) {
441
- return Object.fromEntries(Object.entries(config.groups).map(([name, group]) => [name, { members: require_cli.orderByDependency(config.processes, new Set(group.ids)) }]));
572
+ function projectSuites(config) {
573
+ return Object.fromEntries(Object.values(config.suites).map((suite) => [suite.name, {
574
+ ...suite.description != null ? { description: suite.description } : {},
575
+ members: require_cli.orderByDependency(config.processes, new Set(suite.ids)),
576
+ parallel: suite.parallel,
577
+ failFast: suite.failFast
578
+ }]));
442
579
  }
443
580
  function createControlPlane(options) {
444
581
  const { supervisor, log } = options;
@@ -460,7 +597,9 @@ function createControlPlane(options) {
460
597
  configRevisionHash: supervisor.config.configRevisionHash,
461
598
  configError: [],
462
599
  processes: Object.fromEntries(supervisor.status().map((status) => [status.id, projectProcess(status)])),
463
- groups: projectGroups(supervisor.config)
600
+ suites: projectSuites(supervisor.config),
601
+ runs: {},
602
+ savedFilters: [...options.savedFilters]
464
603
  });
465
604
  const engine = require_cli.createRealmServerEngine(require_cli.commanderStatusRealm, { initialState: initialState() });
466
605
  supervisor.subscribe((id) => {
@@ -470,6 +609,22 @@ function createControlPlane(options) {
470
609
  draft.processes[id] = projectProcess(status);
471
610
  });
472
611
  });
612
+ const suiteRunner = createSuiteRunner({
613
+ supervisor,
614
+ log,
615
+ publish: (runKey, run) => {
616
+ engine.update((draft) => {
617
+ if (run == null) delete draft.runs[runKey];
618
+ else draft.runs[runKey] = run;
619
+ });
620
+ }
621
+ });
622
+ const changeSavedFilters = async (change) => {
623
+ const next = await options.changeSavedFilters(change);
624
+ engine.update((draft) => {
625
+ draft.savedFilters = next;
626
+ });
627
+ };
473
628
  const liveSockets = /* @__PURE__ */ new Set();
474
629
  const acceptorAccess = {};
475
630
  const server = require_cli.serveChannel(runtime, require_cli.commanderChannel, {
@@ -494,15 +649,49 @@ function createControlPlane(options) {
494
649
  staggerMs: staggerMs ?? 0
495
650
  });
496
651
  },
497
- stop: async ({ ids }) => supervisor.stop(ids),
652
+ stop: async ({ ids, withDependencies: alsoDependencies }) => {
653
+ if (alsoDependencies !== true) return supervisor.stop(ids);
654
+ const live = new Set(supervisor.status().filter((status) => LIVE_STATES.has(status.state)).map((status) => status.id));
655
+ const { stop, kept } = require_cli.stopSetWithDependencies(supervisor.config.processes, ids, (id) => live.has(id));
656
+ const report = await supervisor.stop(stop);
657
+ return kept.length === 0 ? report : {
658
+ ...report,
659
+ warnings: [...report.warnings, `left running — still needed by other live processes: ${kept.join(", ")}`]
660
+ };
661
+ },
498
662
  restart: async ({ ids, wait, staggerMs }) => {
499
663
  const config = supervisor.config;
500
664
  const ordered = require_cli.orderByDependency(config.processes, require_cli.withDependencies(config.processes, ids));
501
665
  return supervisor.restart(ordered, {
502
666
  wait: wait ?? true,
503
- staggerMs: staggerMs ?? 0
667
+ staggerMs: staggerMs ?? 0,
668
+ stopIds: ids
504
669
  });
505
670
  },
671
+ runSuite: async (input) => {
672
+ const report = suiteRunner.run(input);
673
+ if (report.accepted && input.filter != null) await changeSavedFilters({
674
+ kind: "ran",
675
+ query: input.filter,
676
+ at: Date.now()
677
+ });
678
+ return report;
679
+ },
680
+ saveFilter: async ({ filter, name }) => {
681
+ await changeSavedFilters({
682
+ kind: "pin",
683
+ query: filter,
684
+ name
685
+ });
686
+ return { ok: true };
687
+ },
688
+ removeFilter: async ({ id }) => {
689
+ await changeSavedFilters({
690
+ kind: "remove",
691
+ id
692
+ });
693
+ return { ok: true };
694
+ },
506
695
  setEnv: async (input) => ({
507
696
  ok: true,
508
697
  warnings: await options.setEnvOverrides(input)
@@ -562,7 +751,7 @@ function createControlPlane(options) {
562
751
  draft.configName = next.name;
563
752
  draft.configRevisionHash = next.configRevisionHash;
564
753
  draft.configError = [];
565
- draft.groups = projectGroups(next);
754
+ draft.suites = projectSuites(next);
566
755
  for (const status of supervisor.status()) draft.processes[status.id] = projectProcess(status);
567
756
  });
568
757
  },
@@ -1363,6 +1552,7 @@ var CommanderSupervisor = class {
1363
1552
  break;
1364
1553
  }
1365
1554
  if (dep.definition.kind === "task") {
1555
+ if (options.satisfied?.has(depId) === true) continue;
1366
1556
  const taskResult = await (taskRuns.get(depId) ?? this._runTaskOnce(dep, taskRuns));
1367
1557
  if (!orderedIds.includes(depId)) results.push({
1368
1558
  ...taskResult,
@@ -1647,8 +1837,13 @@ var CommanderSupervisor = class {
1647
1837
  warnings
1648
1838
  };
1649
1839
  }
1840
+ /**
1841
+ * ⚠ Stops only `stopIds` — the ids the caller NAMED — then starts the whole ordered closure.
1842
+ * Stopping the closure bounced every shared dependency under its other live dependents: a
1843
+ * restart of three frontends took the backend down with it.
1844
+ */
1650
1845
  async restart(orderedIds, options = {}) {
1651
- const stopped = await this.stop(orderedIds);
1846
+ const stopped = await this.stop(options.stopIds ?? orderedIds);
1652
1847
  const started = await this.start(orderedIds, options);
1653
1848
  return {
1654
1849
  results: started.results.map((result) => {
@@ -1734,6 +1929,7 @@ var CommanderSupervisor = class {
1734
1929
  unreadyReason: proc?.unreadyReason ?? null,
1735
1930
  capability: proc?.capability ?? null,
1736
1931
  tags: holder.definition.tags,
1932
+ optIn: holder.definition.optIn,
1737
1933
  detail: describe(holder.definition, envVars)
1738
1934
  };
1739
1935
  });
@@ -1913,11 +2109,24 @@ async function startCommanderDaemon(argv) {
1913
2109
  envWrites = run.catch(() => {});
1914
2110
  return run;
1915
2111
  };
2112
+ let savedFilters = await require_cli.readSavedFilters(paths.savedFiltersPath);
2113
+ let filterWrites = Promise.resolve();
2114
+ const changeSavedFilters = (change) => {
2115
+ const run = filterWrites.then(async () => {
2116
+ savedFilters = require_cli.mutateSavedFilters(savedFilters, change);
2117
+ await require_cli.writeSavedFilters(paths.savedFiltersPath, savedFilters);
2118
+ return savedFilters;
2119
+ });
2120
+ filterWrites = run.catch(() => {});
2121
+ return run;
2122
+ };
1916
2123
  const plane = createControlPlane({
1917
2124
  supervisor,
1918
2125
  generation,
1919
2126
  reloadConfig: () => watcher?.reloadNow() ?? Promise.resolve(),
1920
2127
  setEnvOverrides,
2128
+ savedFilters,
2129
+ changeSavedFilters,
1921
2130
  requestShutdown: () => void shutdown(),
1922
2131
  log
1923
2132
  });
@@ -2068,7 +2277,7 @@ async function startCommanderDaemon(argv) {
2068
2277
  configKey: resolved.configKey,
2069
2278
  configRevisionHash: resolved.configRevisionHash,
2070
2279
  configPath: resolved.configPath,
2071
- protocolVersion: 5,
2280
+ protocolVersion: 6,
2072
2281
  packageVersion: await require_cli.commanderPackageVersion(),
2073
2282
  realmSchemaHash: require_cli.commanderStatusRealm.schemaHash
2074
2283
  });
@@ -2153,4 +2362,4 @@ async function runCommanderDaemon(argv) {
2153
2362
  //#endregion
2154
2363
  exports.runCommanderDaemon = runCommanderDaemon;
2155
2364
 
2156
- //# sourceMappingURL=main-B7EwREFQ.cjs.map
2365
+ //# sourceMappingURL=main-Xo-6rWk6.cjs.map