@lightdash-tools/common 0.5.0 → 0.7.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.
Files changed (94) hide show
  1. package/dist/agentops/extract-yaml-project.d.ts +7 -0
  2. package/dist/agentops/extract-yaml-project.js +42 -0
  3. package/dist/agentops/formatters.d.ts +5 -0
  4. package/dist/agentops/formatters.js +47 -0
  5. package/dist/agentops/snapshots.d.ts +32 -0
  6. package/dist/agentops/snapshots.js +34 -0
  7. package/dist/agentops/types.d.ts +224 -0
  8. package/dist/agentops/types.js +430 -0
  9. package/dist/argument-validation.d.ts +25 -0
  10. package/dist/argument-validation.js +199 -0
  11. package/dist/argument-validation.test.d.ts +1 -0
  12. package/dist/argument-validation.test.js +183 -0
  13. package/dist/audit.d.ts +9 -2
  14. package/dist/audit.js +17 -2
  15. package/dist/audit.test.d.ts +1 -0
  16. package/dist/audit.test.js +73 -0
  17. package/dist/env.d.ts +8 -0
  18. package/dist/env.js +9 -1
  19. package/dist/index.d.ts +7 -1
  20. package/dist/index.js +14 -0
  21. package/dist/input-validation.d.ts +35 -0
  22. package/dist/input-validation.js +87 -0
  23. package/dist/input-validation.test.js +93 -0
  24. package/dist/operations/agent-safe.d.ts +7 -0
  25. package/dist/operations/agent-safe.js +16 -0
  26. package/dist/operations/ai-agents.d.ts +6 -0
  27. package/dist/operations/ai-agents.js +411 -0
  28. package/dist/operations/index.d.ts +5 -0
  29. package/dist/operations/index.js +16 -0
  30. package/dist/operations/parity.test.d.ts +1 -0
  31. package/dist/operations/parity.test.js +28 -0
  32. package/dist/operations/registry.d.ts +10 -0
  33. package/dist/operations/registry.js +35 -0
  34. package/dist/operations/registry.test.d.ts +1 -0
  35. package/dist/operations/registry.test.js +196 -0
  36. package/dist/operations/types.d.ts +69 -0
  37. package/dist/operations/types.js +70 -0
  38. package/dist/operations/types.test.d.ts +1 -0
  39. package/dist/operations/types.test.js +104 -0
  40. package/dist/operations/users.d.ts +6 -0
  41. package/dist/operations/users.js +60 -0
  42. package/dist/safety.d.ts +27 -2
  43. package/dist/safety.js +52 -5
  44. package/dist/safety.test.js +217 -4
  45. package/dist/types/generated/openapi-types.d.ts +35895 -10622
  46. package/dist/types/generated/openapi-types.js +0 -1
  47. package/dist/types/lightdash-api.d.ts +1 -1
  48. package/dist/types/v1/ai-agents.d.ts +112 -3
  49. package/dist/types/v1/charts.d.ts +5 -3
  50. package/dist/types/v1/dashboards.d.ts +13 -0
  51. package/dist/types/v1/index.d.ts +45 -8
  52. package/dist/types/v1/index.js +1 -1
  53. package/dist/types/v1/lightdash-api.d.ts +107 -16
  54. package/dist/types/v1/users.d.ts +4 -0
  55. package/dist/types/v2/content.d.ts +2 -0
  56. package/dist/types/v2/content.js +8 -0
  57. package/dist/types/v2/index.d.ts +11 -9
  58. package/dist/types/v2/index.js +1 -1
  59. package/package.json +16 -3
  60. package/src/agentops/extract-yaml-project.ts +42 -0
  61. package/src/agentops/formatters.ts +52 -0
  62. package/src/agentops/snapshots.ts +56 -0
  63. package/src/agentops/types.ts +599 -0
  64. package/src/argument-validation.test.ts +270 -0
  65. package/src/argument-validation.ts +240 -0
  66. package/src/audit.test.ts +87 -0
  67. package/src/audit.ts +21 -3
  68. package/src/env.ts +9 -0
  69. package/src/index.test.ts +1 -0
  70. package/src/index.ts +16 -1
  71. package/src/input-validation.test.ts +157 -1
  72. package/src/input-validation.ts +95 -0
  73. package/src/operations/agent-safe.ts +18 -0
  74. package/src/operations/ai-agents.ts +451 -0
  75. package/src/operations/index.ts +19 -0
  76. package/src/operations/parity.test.ts +35 -0
  77. package/src/operations/registry.test.ts +219 -0
  78. package/src/operations/registry.ts +44 -0
  79. package/src/operations/types.test.ts +148 -0
  80. package/src/operations/types.ts +168 -0
  81. package/src/operations/users.ts +67 -0
  82. package/src/safety.test.ts +276 -4
  83. package/src/safety.ts +72 -4
  84. package/src/types/generated/openapi-types.ts +37017 -11241
  85. package/src/types/lightdash-api.ts +39 -0
  86. package/src/types/v1/ai-agents.ts +133 -3
  87. package/src/types/v1/charts.ts +5 -3
  88. package/src/types/v1/dashboards.ts +19 -0
  89. package/src/types/v1/index.ts +51 -8
  90. package/src/types/v1/lightdash-api.ts +129 -20
  91. package/src/types/v1/users.ts +4 -0
  92. package/src/types/v2/content.ts +8 -0
  93. package/src/types/v2/index.ts +11 -9
  94. package/tsconfig.json +1 -0
package/dist/safety.js CHANGED
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WRITE_DESTRUCTIVE = exports.WRITE_IDEMPOTENT = exports.READ_ONLY_DEFAULT = exports.SafetyMode = void 0;
3
+ exports.WRITE_DESTRUCTIVE = exports.WRITE_OPEN_WORLD = exports.WRITE_NONDESTRUCTIVE = exports.WRITE_IDEMPOTENT = exports.READ_ONLY_DEFAULT = exports.SafetyMode = void 0;
4
4
  exports.isAllowed = isAllowed;
5
+ exports.isOperationAllowed = isOperationAllowed;
5
6
  exports.getSafetyModeFromEnv = getSafetyModeFromEnv;
6
7
  exports.getAllowedProjectUuidsFromEnv = getAllowedProjectUuidsFromEnv;
7
8
  exports.isProjectAllowed = isProjectAllowed;
8
9
  exports.areAllProjectsAllowed = areAllProjectsAllowed;
9
10
  exports.extractProjectUuids = extractProjectUuids;
11
+ const extract_yaml_project_1 = require("./agentops/extract-yaml-project");
10
12
  const env_1 = require("./env");
11
13
  /**
12
14
  * Hierarchical safety modes for Lightdash AI tools and CLI.
@@ -14,7 +16,9 @@ const env_1 = require("./env");
14
16
  var SafetyMode;
15
17
  (function (SafetyMode) {
16
18
  SafetyMode["READ_ONLY"] = "read-only";
19
+ /** Deprecated alias — prefer {@link SafetyMode.WRITE_NONDESTRUCTIVE}. */
17
20
  SafetyMode["WRITE_IDEMPOTENT"] = "write-idempotent";
21
+ SafetyMode["WRITE_NONDESTRUCTIVE"] = "write-nondestructive";
18
22
  SafetyMode["WRITE_DESTRUCTIVE"] = "write-destructive";
19
23
  })(SafetyMode || (exports.SafetyMode = SafetyMode = {}));
20
24
  /** Preset: read-only, non-destructive, idempotent, closed-world. Use for list/get/compile tools. */
@@ -24,13 +28,30 @@ exports.READ_ONLY_DEFAULT = {
24
28
  destructiveHint: false,
25
29
  idempotentHint: true,
26
30
  };
27
- /** Preset: write, non-destructive, idempotent (e.g. upsert by slug). Use for create/update tools. */
31
+ /**
32
+ * Legacy preset: write, non-destructive, idempotent (e.g. upsert by slug).
33
+ * Prefer {@link WRITE_NONDESTRUCTIVE} for new tools; idempotent behavior is not implied by safety mode.
34
+ */
28
35
  exports.WRITE_IDEMPOTENT = {
29
36
  readOnlyHint: false,
30
37
  openWorldHint: false,
31
38
  destructiveHint: false,
32
39
  idempotentHint: true,
33
40
  };
41
+ /** Preset: write, non-destructive, closed-world. Use for create/update tools without idempotency guarantee. */
42
+ exports.WRITE_NONDESTRUCTIVE = {
43
+ readOnlyHint: false,
44
+ openWorldHint: false,
45
+ destructiveHint: false,
46
+ idempotentHint: false,
47
+ };
48
+ /** Preset: write, non-destructive, open-world. Use for LLM generation and similar external interactions. */
49
+ exports.WRITE_OPEN_WORLD = {
50
+ readOnlyHint: false,
51
+ openWorldHint: true,
52
+ destructiveHint: false,
53
+ idempotentHint: false,
54
+ };
34
55
  /** Preset: write, destructive, non-idempotent. Use for delete/remove tools. */
35
56
  exports.WRITE_DESTRUCTIVE = {
36
57
  readOnlyHint: false,
@@ -39,25 +60,50 @@ exports.WRITE_DESTRUCTIVE = {
39
60
  idempotentHint: false,
40
61
  };
41
62
  /**
42
- * Validates if an operation is allowed in the current safety mode.
63
+ * Validates if an operation is allowed in the current safety mode using MCP tool annotations.
64
+ * Unknown modes default to permissive for backward compatibility.
43
65
  */
44
66
  function isAllowed(mode, annotations) {
45
67
  switch (mode) {
46
68
  case SafetyMode.READ_ONLY:
47
69
  return !!annotations.readOnlyHint;
70
+ case SafetyMode.WRITE_NONDESTRUCTIVE:
48
71
  case SafetyMode.WRITE_IDEMPOTENT:
49
72
  return !!annotations.readOnlyHint || !annotations.destructiveHint;
50
73
  case SafetyMode.WRITE_DESTRUCTIVE:
51
74
  return true;
52
75
  default:
53
- return true; // Default to most permissive if mode is unknown
76
+ return true;
77
+ }
78
+ }
79
+ /**
80
+ * Validates if an operation is allowed in the current safety mode using semantic impact policy.
81
+ * Unknown modes fail closed.
82
+ */
83
+ function isOperationAllowed(mode, policy) {
84
+ switch (mode) {
85
+ case SafetyMode.READ_ONLY:
86
+ return policy.impact === 'read';
87
+ case SafetyMode.WRITE_NONDESTRUCTIVE:
88
+ case SafetyMode.WRITE_IDEMPOTENT:
89
+ return (policy.impact === 'read' ||
90
+ policy.impact === 'write-nondestructive' ||
91
+ policy.impact === 'external-side-effect');
92
+ case SafetyMode.WRITE_DESTRUCTIVE:
93
+ return true;
94
+ default:
95
+ return false;
54
96
  }
55
97
  }
56
98
  /**
57
99
  * Resolves safety mode from environment variable.
100
+ * Accepts `write-idempotent` as a deprecated alias for `write-nondestructive`.
58
101
  */
59
102
  function getSafetyModeFromEnv() {
60
103
  const mode = process.env[env_1.ENV_LIGHTDASH_TOOLS_SAFETY_MODE];
104
+ if (mode === SafetyMode.WRITE_IDEMPOTENT) {
105
+ return SafetyMode.WRITE_NONDESTRUCTIVE;
106
+ }
61
107
  if (Object.values(SafetyMode).includes(mode)) {
62
108
  return mode;
63
109
  }
@@ -135,7 +181,7 @@ function extractProjectUuids(args) {
135
181
  else if (typeof args === 'object') {
136
182
  // MCP or single options object
137
183
  const a = args;
138
- const keys = ['project', 'projectUuid', 'projectUuids'];
184
+ const keys = ['projects', 'project', 'projectUuid', 'projectUuids'];
139
185
  for (const key of keys) {
140
186
  const val = a[key];
141
187
  if (typeof val === 'string') {
@@ -149,5 +195,6 @@ function extractProjectUuids(args) {
149
195
  }
150
196
  }
151
197
  }
198
+ uuids.push(...(0, extract_yaml_project_1.extractProjectUuidsFromToolArgs)(args));
152
199
  return [...new Set(uuids)].filter((u) => u.length > 0);
153
200
  }
@@ -2,27 +2,135 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const vitest_1 = require("vitest");
4
4
  const safety_1 = require("./safety");
5
+ const UUID_A = '11111111-1111-1111-1111-111111111111';
6
+ const UUID_B = '22222222-2222-2222-2222-222222222222';
7
+ const UUID_C = '33333333-3333-3333-3333-333333333333';
8
+ const ALL_IMPACTS = [
9
+ 'read',
10
+ 'write-nondestructive',
11
+ 'write-destructive',
12
+ 'credential-sensitive',
13
+ 'external-side-effect',
14
+ ];
15
+ function policy(impact) {
16
+ return { impact };
17
+ }
5
18
  (0, vitest_1.describe)('Safety Logic', () => {
19
+ (0, vitest_1.describe)('annotation presets', () => {
20
+ (0, vitest_1.it)('should define READ_ONLY_DEFAULT as read-only closed-world', () => {
21
+ (0, vitest_1.expect)(safety_1.READ_ONLY_DEFAULT).toEqual({
22
+ readOnlyHint: true,
23
+ openWorldHint: false,
24
+ destructiveHint: false,
25
+ idempotentHint: true,
26
+ });
27
+ });
28
+ (0, vitest_1.it)('should define WRITE_IDEMPOTENT as deprecated non-destructive idempotent write', () => {
29
+ (0, vitest_1.expect)(safety_1.WRITE_IDEMPOTENT).toEqual({
30
+ readOnlyHint: false,
31
+ openWorldHint: false,
32
+ destructiveHint: false,
33
+ idempotentHint: true,
34
+ });
35
+ });
36
+ (0, vitest_1.it)('should define WRITE_NONDESTRUCTIVE as non-destructive closed-world write', () => {
37
+ (0, vitest_1.expect)(safety_1.WRITE_NONDESTRUCTIVE).toEqual({
38
+ readOnlyHint: false,
39
+ openWorldHint: false,
40
+ destructiveHint: false,
41
+ idempotentHint: false,
42
+ });
43
+ });
44
+ (0, vitest_1.it)('should define WRITE_OPEN_WORLD for LLM generation style tools', () => {
45
+ (0, vitest_1.expect)(safety_1.WRITE_OPEN_WORLD).toEqual({
46
+ readOnlyHint: false,
47
+ openWorldHint: true,
48
+ destructiveHint: false,
49
+ idempotentHint: false,
50
+ });
51
+ });
52
+ (0, vitest_1.it)('should define WRITE_DESTRUCTIVE as destructive write', () => {
53
+ (0, vitest_1.expect)(safety_1.WRITE_DESTRUCTIVE).toEqual({
54
+ readOnlyHint: false,
55
+ openWorldHint: false,
56
+ destructiveHint: true,
57
+ idempotentHint: false,
58
+ });
59
+ });
60
+ });
61
+ (0, vitest_1.describe)('SafetyMode enum', () => {
62
+ (0, vitest_1.it)('should keep WRITE_IDEMPOTENT as deprecated alias with distinct string value', () => {
63
+ (0, vitest_1.expect)(safety_1.SafetyMode.WRITE_IDEMPOTENT).toBe('write-idempotent');
64
+ (0, vitest_1.expect)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE).toBe('write-nondestructive');
65
+ (0, vitest_1.expect)(safety_1.SafetyMode.WRITE_IDEMPOTENT).not.toBe(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE);
66
+ });
67
+ });
6
68
  (0, vitest_1.describe)('isAllowed', () => {
7
69
  (0, vitest_1.it)('should allow read-only operations in read-only mode', () => {
8
70
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.READ_ONLY, safety_1.READ_ONLY_DEFAULT)).toBe(true);
9
71
  });
10
72
  (0, vitest_1.it)('should forbid non-read-only operations in read-only mode', () => {
11
73
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.READ_ONLY, safety_1.WRITE_IDEMPOTENT)).toBe(false);
74
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.READ_ONLY, safety_1.WRITE_NONDESTRUCTIVE)).toBe(false);
75
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.READ_ONLY, safety_1.WRITE_OPEN_WORLD)).toBe(false);
12
76
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.READ_ONLY, safety_1.WRITE_DESTRUCTIVE)).toBe(false);
13
77
  });
14
- (0, vitest_1.it)('should allow read-only and idempotent-write in write-idempotent mode', () => {
78
+ (0, vitest_1.it)('should allow read-only and non-destructive writes in write-idempotent mode', () => {
15
79
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_IDEMPOTENT, safety_1.READ_ONLY_DEFAULT)).toBe(true);
16
80
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_IDEMPOTENT, safety_1.WRITE_IDEMPOTENT)).toBe(true);
81
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_IDEMPOTENT, safety_1.WRITE_NONDESTRUCTIVE)).toBe(true);
82
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_IDEMPOTENT, safety_1.WRITE_OPEN_WORLD)).toBe(true);
17
83
  });
18
- (0, vitest_1.it)('should forbid destructive operations in write-idempotent mode', () => {
84
+ (0, vitest_1.it)('should allow read-only and non-destructive writes in write-nondestructive mode', () => {
85
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, safety_1.READ_ONLY_DEFAULT)).toBe(true);
86
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, safety_1.WRITE_NONDESTRUCTIVE)).toBe(true);
87
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, safety_1.WRITE_OPEN_WORLD)).toBe(true);
88
+ });
89
+ (0, vitest_1.it)('should forbid destructive operations in write-idempotent and write-nondestructive modes', () => {
19
90
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_IDEMPOTENT, safety_1.WRITE_DESTRUCTIVE)).toBe(false);
91
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, safety_1.WRITE_DESTRUCTIVE)).toBe(false);
20
92
  });
21
93
  (0, vitest_1.it)('should allow all operations in write-destructive mode', () => {
22
94
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_DESTRUCTIVE, safety_1.READ_ONLY_DEFAULT)).toBe(true);
23
95
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_DESTRUCTIVE, safety_1.WRITE_IDEMPOTENT)).toBe(true);
96
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_DESTRUCTIVE, safety_1.WRITE_NONDESTRUCTIVE)).toBe(true);
97
+ (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_DESTRUCTIVE, safety_1.WRITE_OPEN_WORLD)).toBe(true);
24
98
  (0, vitest_1.expect)((0, safety_1.isAllowed)(safety_1.SafetyMode.WRITE_DESTRUCTIVE, safety_1.WRITE_DESTRUCTIVE)).toBe(true);
25
99
  });
100
+ (0, vitest_1.it)('should default to permissive for an unknown mode string (backward compat)', () => {
101
+ (0, vitest_1.expect)((0, safety_1.isAllowed)('custom-mode', safety_1.WRITE_DESTRUCTIVE)).toBe(true);
102
+ });
103
+ });
104
+ (0, vitest_1.describe)('isOperationAllowed', () => {
105
+ (0, vitest_1.it)('should allow only read impact in read-only mode', () => {
106
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.READ_ONLY, policy('read'))).toBe(true);
107
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.READ_ONLY, policy('write-nondestructive'))).toBe(false);
108
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.READ_ONLY, policy('write-destructive'))).toBe(false);
109
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.READ_ONLY, policy('credential-sensitive'))).toBe(false);
110
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.READ_ONLY, policy('external-side-effect'))).toBe(false);
111
+ });
112
+ (0, vitest_1.it)('should allow read, write-nondestructive, and external-side-effect in write-nondestructive mode', () => {
113
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, policy('read'))).toBe(true);
114
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, policy('write-nondestructive'))).toBe(true);
115
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, policy('external-side-effect'))).toBe(true);
116
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, policy('write-destructive'))).toBe(false);
117
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, policy('credential-sensitive'))).toBe(false);
118
+ });
119
+ (0, vitest_1.it)('should treat write-idempotent mode the same as write-nondestructive for policy checks', () => {
120
+ for (const impact of ALL_IMPACTS) {
121
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.WRITE_IDEMPOTENT, policy(impact))).toBe((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE, policy(impact)));
122
+ }
123
+ });
124
+ (0, vitest_1.it)('should allow all impacts in write-destructive mode', () => {
125
+ for (const impact of ALL_IMPACTS) {
126
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)(safety_1.SafetyMode.WRITE_DESTRUCTIVE, policy(impact))).toBe(true);
127
+ }
128
+ });
129
+ (0, vitest_1.it)('should fail closed for unknown mode strings', () => {
130
+ for (const impact of ALL_IMPACTS) {
131
+ (0, vitest_1.expect)((0, safety_1.isOperationAllowed)('custom-mode', policy(impact))).toBe(false);
132
+ }
133
+ });
26
134
  });
27
135
  (0, vitest_1.describe)('getSafetyModeFromEnv', () => {
28
136
  const originalEnv = process.env.LIGHTDASH_TOOLS_SAFETY_MODE;
@@ -33,9 +141,17 @@ const safety_1 = require("./safety");
33
141
  delete process.env.LIGHTDASH_TOOLS_SAFETY_MODE;
34
142
  (0, vitest_1.expect)((0, safety_1.getSafetyModeFromEnv)()).toBe(safety_1.SafetyMode.READ_ONLY);
35
143
  });
36
- (0, vitest_1.it)('should return value from env when set to valid mode', () => {
144
+ (0, vitest_1.it)('should return WRITE_NONDESTRUCTIVE when env is set to write-nondestructive', () => {
145
+ process.env.LIGHTDASH_TOOLS_SAFETY_MODE = safety_1.SafetyMode.WRITE_NONDESTRUCTIVE;
146
+ (0, vitest_1.expect)((0, safety_1.getSafetyModeFromEnv)()).toBe(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE);
147
+ });
148
+ (0, vitest_1.it)('should map deprecated write-idempotent env value to WRITE_NONDESTRUCTIVE', () => {
37
149
  process.env.LIGHTDASH_TOOLS_SAFETY_MODE = safety_1.SafetyMode.WRITE_IDEMPOTENT;
38
- (0, vitest_1.expect)((0, safety_1.getSafetyModeFromEnv)()).toBe(safety_1.SafetyMode.WRITE_IDEMPOTENT);
150
+ (0, vitest_1.expect)((0, safety_1.getSafetyModeFromEnv)()).toBe(safety_1.SafetyMode.WRITE_NONDESTRUCTIVE);
151
+ });
152
+ (0, vitest_1.it)('should return WRITE_DESTRUCTIVE when env is set to write-destructive', () => {
153
+ process.env.LIGHTDASH_TOOLS_SAFETY_MODE = safety_1.SafetyMode.WRITE_DESTRUCTIVE;
154
+ (0, vitest_1.expect)((0, safety_1.getSafetyModeFromEnv)()).toBe(safety_1.SafetyMode.WRITE_DESTRUCTIVE);
39
155
  });
40
156
  (0, vitest_1.it)('should return READ_ONLY when env is set to invalid value', () => {
41
157
  process.env.LIGHTDASH_TOOLS_SAFETY_MODE = 'invalid-mode';
@@ -96,4 +212,101 @@ const safety_1 = require("./safety");
96
212
  (0, vitest_1.expect)((0, safety_1.areAllProjectsAllowed)(['uuid-a'], ['uuid-b', 'uuid-c'])).toBe(false);
97
213
  });
98
214
  });
215
+ (0, vitest_1.describe)('extractProjectUuids', () => {
216
+ (0, vitest_1.it)('should return empty array for null', () => {
217
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)(null)).toEqual([]);
218
+ });
219
+ (0, vitest_1.it)('should return empty array for undefined', () => {
220
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)(undefined)).toEqual([]);
221
+ });
222
+ (0, vitest_1.it)('should extract projectUuid from MCP-style object', () => {
223
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)({ projectUuid: UUID_A })).toEqual([UUID_A]);
224
+ });
225
+ (0, vitest_1.it)('should extract projectUuids array from MCP-style object', () => {
226
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)({ projectUuids: [UUID_A, UUID_B] })).toEqual([UUID_A, UUID_B]);
227
+ });
228
+ (0, vitest_1.it)('should extract projects array from MCP-style object', () => {
229
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)({ projects: [UUID_A, UUID_B] })).toEqual([UUID_A, UUID_B]);
230
+ });
231
+ (0, vitest_1.it)('should extract project from MCP-style object', () => {
232
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)({ project: UUID_A })).toEqual([UUID_A]);
233
+ });
234
+ (0, vitest_1.it)('should extract UUID from CLI positional argument', () => {
235
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([UUID_A])).toEqual([UUID_A]);
236
+ });
237
+ (0, vitest_1.it)('should ignore non-UUID CLI positional strings', () => {
238
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)(['not-a-uuid', 'also-invalid'])).toEqual([]);
239
+ });
240
+ (0, vitest_1.it)('should extract from nested CLI options with projects key', () => {
241
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([{ projects: [UUID_A, UUID_B] }])).toEqual([UUID_A, UUID_B]);
242
+ });
243
+ (0, vitest_1.it)('should extract from nested CLI options with project key', () => {
244
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([{ project: UUID_A }])).toEqual([UUID_A]);
245
+ });
246
+ (0, vitest_1.it)('should extract from nested CLI options with projectUuid key', () => {
247
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([{ projectUuid: UUID_A }])).toEqual([UUID_A]);
248
+ });
249
+ (0, vitest_1.it)('should extract from nested CLI options with projectUuids key', () => {
250
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([{ projectUuids: [UUID_A, UUID_B] }])).toEqual([UUID_A, UUID_B]);
251
+ });
252
+ (0, vitest_1.it)('should combine positional UUIDs and nested option values', () => {
253
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([UUID_A, { project: UUID_B }])).toEqual([UUID_A, UUID_B]);
254
+ });
255
+ (0, vitest_1.it)('should deduplicate UUIDs across sources', () => {
256
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([
257
+ UUID_A,
258
+ { projectUuid: UUID_A, projectUuids: [UUID_B, UUID_C] },
259
+ { projects: [UUID_B, UUID_C] },
260
+ ])).toEqual([UUID_A, UUID_B, UUID_C]);
261
+ });
262
+ (0, vitest_1.it)('should filter out empty strings from extracted values', () => {
263
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)({
264
+ projectUuid: '',
265
+ projectUuids: [UUID_A, '', UUID_B],
266
+ })).toEqual([UUID_A, UUID_B]);
267
+ });
268
+ (0, vitest_1.it)('should filter empty strings from nested CLI options', () => {
269
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([{ projects: ['', UUID_A, ''] }])).toEqual([UUID_A]);
270
+ });
271
+ (0, vitest_1.it)('should return empty array for MCP object with no project keys', () => {
272
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)({ query: 'test', limit: 10 })).toEqual([]);
273
+ });
274
+ (0, vitest_1.it)('should extract projectUuid from bundleYaml in MCP tool args', () => {
275
+ const projectUuid = '550e8400-e29b-41d4-a716-446655440000';
276
+ const bundleYaml = [
277
+ 'apiVersion: lightdash.ai/v1alpha1',
278
+ 'kind: LightdashAiAgentBundle',
279
+ 'metadata:',
280
+ ' name: test-bundle',
281
+ 'spec:',
282
+ ` projectUuid: ${projectUuid}`,
283
+ ' agents:',
284
+ ' - key: a1',
285
+ ' name: Agent One',
286
+ ' evaluations: []',
287
+ ].join('\n');
288
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)({ bundleYaml })).toEqual([projectUuid]);
289
+ });
290
+ (0, vitest_1.it)('should extract projectUuid from gateYaml in MCP tool args', () => {
291
+ const projectUuid = '550e8400-e29b-41d4-a716-446655440000';
292
+ const agentUuid = '660e8400-e29b-41d4-a716-446655440001';
293
+ const evaluationUuid = '770e8400-e29b-41d4-a716-446655440002';
294
+ const gateYaml = [
295
+ 'apiVersion: lightdash.ai/v1alpha1',
296
+ 'kind: LightdashAiEvaluationGate',
297
+ 'metadata:',
298
+ ' name: release-gate',
299
+ 'spec:',
300
+ ` projectUuid: ${projectUuid}`,
301
+ ` agentUuid: ${agentUuid}`,
302
+ ` evaluationUuid: ${evaluationUuid}`,
303
+ ' policy:',
304
+ ' minPassRate: 0.9',
305
+ ].join('\n');
306
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)({ gateYaml })).toEqual([projectUuid]);
307
+ });
308
+ (0, vitest_1.it)('should return empty array for empty CLI argument array', () => {
309
+ (0, vitest_1.expect)((0, safety_1.extractProjectUuids)([])).toEqual([]);
310
+ });
311
+ });
99
312
  });