@pagopa/dx-cli 0.22.0 → 0.22.2

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,43 +1,45 @@
1
+ import fc from "fast-check";
1
2
  /**
2
3
  * Tests for the CLI environment schema.
3
4
  * Validates that `cliEnvSchema` correctly parses `process.env`.
4
5
  */
5
6
  import { afterEach, describe, expect, it, vi } from "vitest";
7
+ import { z } from "zod";
6
8
  import { cliEnvSchema } from "../env.js";
9
+ // The accepted stringbool values mirror those recognised by z.stringbool().
10
+ const CI_TRUTHY = ["true", "1", "yes", "y", "on"];
11
+ const CI_FALSEY = ["false", "0", "no", "n", "off"];
12
+ const CI_ACCEPTED = [...CI_TRUTHY, ...CI_FALSEY];
7
13
  describe("cliEnvSchema", () => {
8
14
  afterEach(() => {
9
15
  vi.unstubAllEnvs();
10
16
  });
11
17
  describe("CI field", () => {
12
- it("is undefined when CI is not set", () => {
13
- vi.stubEnv("CI", undefined);
14
- const result = cliEnvSchema.safeParse(process.env);
15
- expect(result.success).toBe(true);
16
- expect(result.success && result.data.CI).toBeUndefined();
18
+ it("should be true for truthy string-bool values", () => {
19
+ fc.assert(fc.property(fc.constantFrom(...CI_TRUTHY), (value) => {
20
+ vi.stubEnv("CI", value);
21
+ const result = cliEnvSchema.safeParse(process.env);
22
+ expect(result.success).toBe(true);
23
+ expect(result.success && result.data.CI).toBe(true);
24
+ }));
17
25
  });
18
- it("captures any non-empty CI value", () => {
19
- vi.stubEnv("CI", "true");
20
- const result = cliEnvSchema.safeParse(process.env);
21
- expect(result.success).toBe(true);
22
- expect(result.success && result.data.CI).toBe("true");
26
+ it("should be false for falsey string-bool values or when unset", () => {
27
+ fc.assert(fc.property(fc.constantFrom(...CI_FALSEY, undefined), (value) => {
28
+ vi.stubEnv("CI", value);
29
+ const result = cliEnvSchema.safeParse(process.env);
30
+ expect(result.success).toBe(true);
31
+ expect(result.success && result.data.CI).toBe(false);
32
+ }));
23
33
  });
24
- it("captures CI=false as a string (presence is the signal, not the value)", () => {
25
- vi.stubEnv("CI", "false");
26
- const result = cliEnvSchema.safeParse(process.env);
27
- expect(result.success).toBe(true);
28
- expect(result.success && result.data.CI).toBe("false");
34
+ it("should not parse unrecognised values", () => {
35
+ fc.assert(fc.property(
36
+ // Every string not in the accepted list
37
+ fc.string().filter((s) => !CI_ACCEPTED.includes(s.toLowerCase())), (value) => {
38
+ vi.stubEnv("CI", value);
39
+ const result = cliEnvSchema.safeParse(process.env);
40
+ expect(result.success).toBe(false);
41
+ expect(result.error).toBeInstanceOf(z.ZodError);
42
+ }));
29
43
  });
30
- it("captures CI=1 for numeric-style env vars", () => {
31
- vi.stubEnv("CI", "1");
32
- const result = cliEnvSchema.safeParse(process.env);
33
- expect(result.success).toBe(true);
34
- expect(result.success && result.data.CI).toBe("1");
35
- });
36
- });
37
- it("passes through an object with unrelated env keys without failing", () => {
38
- vi.stubEnv("CI", "true");
39
- const result = cliEnvSchema.safeParse(process.env);
40
- expect(result.success).toBe(true);
41
- expect(result.success && result.data.CI).toBe("true");
42
44
  });
43
45
  });
@@ -8,6 +8,6 @@
8
8
  */
9
9
  import { z } from "zod";
10
10
  export declare const cliEnvSchema: z.ZodObject<{
11
- CI: z.ZodOptional<z.ZodString>;
11
+ CI: z.ZodDefault<z.ZodCodec<z.ZodString, z.ZodBoolean>>;
12
12
  }, z.core.$loose>;
13
13
  export type CliEnv = z.infer<typeof cliEnvSchema>;
@@ -9,9 +9,7 @@
9
9
  import { z } from "zod";
10
10
  export const cliEnvSchema = z
11
11
  .object({
12
- // Standard CI marker. Presence (any string value) signals an automated
13
- // pipeline where interactive prompts must not block. Follows the same
14
- // convention used by `is-interactive` and `ora`.
15
- CI: z.string().optional(),
12
+ // Use a truthy value to enable CI mode.
13
+ CI: z.stringbool().default(false),
16
14
  })
17
15
  .loose();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/dx-cli",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "type": "module",
5
5
  "description": "A CLI useful to manage DX tools.",
6
6
  "repository": {
@@ -48,7 +48,7 @@
48
48
  "semver": "^7.7.4",
49
49
  "yaml": "^2.8.4",
50
50
  "zod": "^4.4.2",
51
- "@pagopa/dx-savemoney": "^0.2.5"
51
+ "@pagopa/dx-savemoney": "^0.2.6"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@tsconfig/node24": "24.0.4",
@@ -58,6 +58,7 @@
58
58
  "@types/semver": "^7.7.1",
59
59
  "@vitest/coverage-v8": "^3.2.4",
60
60
  "eslint": "^10.3.0",
61
+ "fast-check": "^4.8.0",
61
62
  "memfs": "^4.57.2",
62
63
  "plop": "^4.0.5",
63
64
  "prettier": "3.8.3",