@cappa/cli 0.18.0 → 0.19.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.
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { getLogger, initLogger } from "@cappa/logger";
2
2
  import { Command, InvalidArgumentError } from "commander";
3
3
  import { configToEngineOptions, defaultConfig, getConfig } from "@cappa/config";
4
- import { LocalEngine, ScreenshotFileSystem, VERDICT_LABELS, clearJudgment, collectScreenshots, groupScreenshots, isVerdictLabel, normalizeChangeType, runAgentCheck, toSlimAgentReport, writeAgentVerdict } from "@cappa/core";
4
+ import { LocalEngine, ScreenshotFileSystem, VERDICT_LABELS, clearJudgment, collectScreenshots, groupScreenshots, isVerdictLabel, normalizeChangeType, removePlaywrightContainers, resolveContainerOptions, runAgentCheck, toSlimAgentReport, writeAgentVerdict } from "@cappa/core";
5
5
  import chalk from "chalk";
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
@@ -12,7 +12,7 @@ import { ProtocolMismatchError, createClient } from "@cappa/client";
12
12
  import { createServer, isLoopbackHost } from "@cappa/server";
13
13
  import { randomBytes } from "node:crypto";
14
14
  //#region package.json
15
- var version = "0.18.0";
15
+ var version = "0.19.0";
16
16
  //#endregion
17
17
  //#region ../../node_modules/.pnpm/tsdown@0.23.0_@arethetypeswrong+core@0.18.5_oxc-resolver@11.24.2_tsx@4.23.1_typescript@7.0.2/node_modules/tsdown/esm-shims.js
18
18
  const getFilename = () => fileURLToPath(import.meta.url);
@@ -635,6 +635,37 @@ const filterScreenshots = (screenshots, filters) => {
635
635
  });
636
636
  };
637
637
  //#endregion
638
+ //#region src/commands/browser.ts
639
+ /**
640
+ * The container CLI to use: `--cli`, else the config's
641
+ * `playwright({ container: { cli } })`, else `CAPPA_CONTAINER_CLI`, else
642
+ * docker. A config that fails to load must not block cleanup.
643
+ */
644
+ const resolveCli = async (cli) => {
645
+ if (cli) return cli;
646
+ let container;
647
+ try {
648
+ container = (await getConfig()).browser?.provider?.options?.container;
649
+ } catch (error) {
650
+ getLogger().debug("Could not load the config:", error);
651
+ }
652
+ return resolveContainerOptions(container && container !== true ? container : true)?.cli ?? "docker";
653
+ };
654
+ /** `cappa browser down` — remove every Playwright container cappa started. */
655
+ const browserDown = async (options = {}) => {
656
+ const logger = getLogger();
657
+ const cli = await resolveCli(options.cli);
658
+ const removed = await removePlaywrightContainers({ cli });
659
+ if (removed.length === 0) {
660
+ logger.info("No Playwright containers to remove.");
661
+ return;
662
+ }
663
+ for (const name of removed) logger.success(`Removed ${name}`);
664
+ };
665
+ const registerBrowserCommand = (program) => {
666
+ program.command("browser").description("Manage the Playwright container (browser.provider container)").command("down").description("Remove every Playwright container cappa started").option("--cli <cli>", "container CLI to use (docker, podman, nerdctl)").action(browserDown);
667
+ };
668
+ //#endregion
638
669
  //#region src/utils/captureReport.ts
639
670
  const errorMessage = (error) => {
640
671
  if (typeof error === "string") return error;
@@ -1586,6 +1617,7 @@ program.command("serve").description("Host a capture engine for a remote `cappa
1586
1617
  program.command("approve").description("Approve screenshots").option("-f, --filter <filter...>", "only approve screenshots whose name includes the provided filter value(s)").action(approve);
1587
1618
  program.command("status").description("Get status of screenshots").option("--max-regions <count>", "maximum number of interpreted diff regions listed per changed screenshot (0 to disable)", parseMaxRegions, 5).action(status);
1588
1619
  registerAgentCommand(program);
1620
+ registerBrowserCommand(program);
1589
1621
  program.command("init").description("Initialize Cappa in the current directory").action(init);
1590
1622
  async function run() {
1591
1623
  await program.parseAsync();