@trentapps/manager-protocol 1.1.2 → 1.2.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/README.md +29 -1
- package/dist/analyzers/CSSAnalyzer.d.ts +188 -8
- package/dist/analyzers/CSSAnalyzer.d.ts.map +1 -1
- package/dist/analyzers/CSSAnalyzer.js +794 -192
- package/dist/analyzers/CSSAnalyzer.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/config/dashboard.d.ts +55 -0
- package/dist/config/dashboard.d.ts.map +1 -0
- package/dist/config/dashboard.js +103 -0
- package/dist/config/dashboard.js.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +7 -0
- package/dist/config/index.js.map +1 -0
- package/dist/dashboard/httpDashboard.d.ts +100 -0
- package/dist/dashboard/httpDashboard.d.ts.map +1 -0
- package/dist/dashboard/httpDashboard.js +1276 -0
- package/dist/dashboard/httpDashboard.js.map +1 -0
- package/dist/dashboard/index.d.ts +6 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +7 -0
- package/dist/dashboard/index.js.map +1 -0
- package/dist/engine/AuditLogger.d.ts +370 -2
- package/dist/engine/AuditLogger.d.ts.map +1 -1
- package/dist/engine/AuditLogger.js +1067 -24
- package/dist/engine/AuditLogger.js.map +1 -1
- package/dist/engine/GitHubApprovalManager.d.ts +13 -0
- package/dist/engine/GitHubApprovalManager.d.ts.map +1 -1
- package/dist/engine/GitHubApprovalManager.js +72 -46
- package/dist/engine/GitHubApprovalManager.js.map +1 -1
- package/dist/engine/GitHubClient.d.ts +183 -0
- package/dist/engine/GitHubClient.d.ts.map +1 -0
- package/dist/engine/GitHubClient.js +411 -0
- package/dist/engine/GitHubClient.js.map +1 -0
- package/dist/engine/RateLimiter.d.ts +5 -3
- package/dist/engine/RateLimiter.d.ts.map +1 -1
- package/dist/engine/RateLimiter.js +53 -70
- package/dist/engine/RateLimiter.js.map +1 -1
- package/dist/engine/RuleDependencyAnalyzer.d.ts +73 -0
- package/dist/engine/RuleDependencyAnalyzer.d.ts.map +1 -0
- package/dist/engine/RuleDependencyAnalyzer.js +475 -0
- package/dist/engine/RuleDependencyAnalyzer.js.map +1 -0
- package/dist/engine/RulesEngine.d.ts +102 -3
- package/dist/engine/RulesEngine.d.ts.map +1 -1
- package/dist/engine/RulesEngine.js +326 -21
- package/dist/engine/RulesEngine.js.map +1 -1
- package/dist/engine/TaskManager.d.ts +11 -10
- package/dist/engine/TaskManager.d.ts.map +1 -1
- package/dist/engine/TaskManager.js +180 -195
- package/dist/engine/TaskManager.js.map +1 -1
- package/dist/engine/index.d.ts +3 -0
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +5 -0
- package/dist/engine/index.js.map +1 -1
- package/dist/rules/azure.d.ts.map +1 -1
- package/dist/rules/azure.js +12 -14
- package/dist/rules/azure.js.map +1 -1
- package/dist/rules/compliance.d.ts.map +1 -1
- package/dist/rules/compliance.js +23 -41
- package/dist/rules/compliance.js.map +1 -1
- package/dist/rules/condition-optimizer.d.ts +151 -0
- package/dist/rules/condition-optimizer.d.ts.map +1 -0
- package/dist/rules/condition-optimizer.js +479 -0
- package/dist/rules/condition-optimizer.js.map +1 -0
- package/dist/rules/css.d.ts.map +1 -1
- package/dist/rules/css.js +538 -0
- package/dist/rules/css.js.map +1 -1
- package/dist/rules/field-standards.d.ts +1172 -0
- package/dist/rules/field-standards.d.ts.map +1 -0
- package/dist/rules/field-standards.js +908 -0
- package/dist/rules/field-standards.js.map +1 -0
- package/dist/rules/flask.d.ts.map +1 -1
- package/dist/rules/flask.js +18 -31
- package/dist/rules/flask.js.map +1 -1
- package/dist/rules/index.d.ts +220 -0
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +155 -0
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/ml-ai.d.ts.map +1 -1
- package/dist/rules/ml-ai.js +11 -13
- package/dist/rules/ml-ai.js.map +1 -1
- package/dist/rules/patterns.d.ts +568 -0
- package/dist/rules/patterns.d.ts.map +1 -0
- package/dist/rules/patterns.js +1359 -0
- package/dist/rules/patterns.js.map +1 -0
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +580 -19
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/shared-patterns.d.ts +268 -0
- package/dist/rules/shared-patterns.d.ts.map +1 -0
- package/dist/rules/shared-patterns.js +556 -0
- package/dist/rules/shared-patterns.js.map +1 -0
- package/dist/rules/storage.d.ts +8 -2
- package/dist/rules/storage.d.ts.map +1 -1
- package/dist/rules/storage.js +541 -3
- package/dist/rules/storage.js.map +1 -1
- package/dist/rules/stripe.d.ts.map +1 -1
- package/dist/rules/stripe.js +19 -26
- package/dist/rules/stripe.js.map +1 -1
- package/dist/rules/websocket.d.ts.map +1 -1
- package/dist/rules/websocket.js +32 -40
- package/dist/rules/websocket.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +96 -17
- package/dist/server.js.map +1 -1
- package/dist/supervisor/AgentSupervisor.d.ts +52 -0
- package/dist/supervisor/AgentSupervisor.d.ts.map +1 -1
- package/dist/supervisor/AgentSupervisor.js +120 -1
- package/dist/supervisor/AgentSupervisor.js.map +1 -1
- package/dist/supervisor/ManagedServerRegistry.d.ts +139 -2
- package/dist/supervisor/ManagedServerRegistry.d.ts.map +1 -1
- package/dist/supervisor/ManagedServerRegistry.js +590 -6
- package/dist/supervisor/ManagedServerRegistry.js.map +1 -1
- package/dist/supervisor/ProjectTracker.d.ts +24 -2
- package/dist/supervisor/ProjectTracker.d.ts.map +1 -1
- package/dist/supervisor/ProjectTracker.js +151 -59
- package/dist/supervisor/ProjectTracker.js.map +1 -1
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +12 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/rule-tester.d.ts +217 -0
- package/dist/testing/rule-tester.d.ts.map +1 -0
- package/dist/testing/rule-tester.examples.d.ts +57 -0
- package/dist/testing/rule-tester.examples.d.ts.map +1 -0
- package/dist/testing/rule-tester.examples.js +375 -0
- package/dist/testing/rule-tester.examples.js.map +1 -0
- package/dist/testing/rule-tester.js +381 -0
- package/dist/testing/rule-tester.js.map +1 -0
- package/dist/testing/rule-validator.d.ts +141 -0
- package/dist/testing/rule-validator.d.ts.map +1 -0
- package/dist/testing/rule-validator.js +640 -0
- package/dist/testing/rule-validator.js.map +1 -0
- package/dist/types/index.d.ts +265 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +57 -2
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/rate-limiting.d.ts +268 -0
- package/dist/utils/rate-limiting.d.ts.map +1 -0
- package/dist/utils/rate-limiting.js +403 -0
- package/dist/utils/rate-limiting.js.map +1 -0
- package/dist/utils/shared.d.ts +306 -0
- package/dist/utils/shared.d.ts.map +1 -0
- package/dist/utils/shared.js +464 -0
- package/dist/utils/shared.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enterprise Agent Supervisor - Rule Testing Framework
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for testing individual business rules and verifying their behavior.
|
|
5
|
+
*/
|
|
6
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
7
|
+
import { RulesEngine } from '../engine/RulesEngine.js';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// RULE TESTER CLASS
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* RuleTester class for testing individual business rules
|
|
13
|
+
*/
|
|
14
|
+
export class RuleTester {
|
|
15
|
+
engine;
|
|
16
|
+
verbose;
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.engine = new RulesEngine();
|
|
19
|
+
this.verbose = options.verbose ?? false;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Test a single rule against multiple test cases
|
|
23
|
+
*/
|
|
24
|
+
testRule(rule, testCases) {
|
|
25
|
+
const startTime = Date.now();
|
|
26
|
+
const testCaseResults = [];
|
|
27
|
+
let passedTests = 0;
|
|
28
|
+
let failedTests = 0;
|
|
29
|
+
let skippedTests = 0;
|
|
30
|
+
// Register only this rule
|
|
31
|
+
this.engine = new RulesEngine();
|
|
32
|
+
this.engine.registerRule(rule);
|
|
33
|
+
// Check if any test has 'only' flag
|
|
34
|
+
const hasOnlyTests = testCases.some(tc => tc.only);
|
|
35
|
+
for (const testCase of testCases) {
|
|
36
|
+
// Skip tests not in the run list (when 'only' is used)
|
|
37
|
+
if (hasOnlyTests && !testCase.only) {
|
|
38
|
+
skippedTests++;
|
|
39
|
+
testCaseResults.push({
|
|
40
|
+
testCaseId: testCase.id || uuidv4(),
|
|
41
|
+
description: testCase.description,
|
|
42
|
+
passed: false,
|
|
43
|
+
skipped: true,
|
|
44
|
+
failures: [],
|
|
45
|
+
durationMs: 0
|
|
46
|
+
});
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (testCase.skip) {
|
|
50
|
+
skippedTests++;
|
|
51
|
+
testCaseResults.push({
|
|
52
|
+
testCaseId: testCase.id || uuidv4(),
|
|
53
|
+
description: testCase.description,
|
|
54
|
+
passed: false,
|
|
55
|
+
skipped: true,
|
|
56
|
+
failures: [],
|
|
57
|
+
durationMs: 0
|
|
58
|
+
});
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const result = this.runTestCase(rule, testCase);
|
|
62
|
+
testCaseResults.push(result);
|
|
63
|
+
if (result.passed) {
|
|
64
|
+
passedTests++;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
failedTests++;
|
|
68
|
+
if (this.verbose) {
|
|
69
|
+
this.logFailure(rule, testCase, result);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
ruleId: rule.id,
|
|
75
|
+
ruleName: rule.name,
|
|
76
|
+
totalTests: testCases.length,
|
|
77
|
+
passedTests,
|
|
78
|
+
failedTests,
|
|
79
|
+
skippedTests,
|
|
80
|
+
testCaseResults,
|
|
81
|
+
totalDurationMs: Date.now() - startTime
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Run a single test case
|
|
86
|
+
*/
|
|
87
|
+
runTestCase(rule, testCase) {
|
|
88
|
+
const startTime = Date.now();
|
|
89
|
+
const testCaseId = testCase.id || uuidv4();
|
|
90
|
+
const failures = [];
|
|
91
|
+
// Build full action
|
|
92
|
+
const action = {
|
|
93
|
+
id: uuidv4(),
|
|
94
|
+
...testCase.input.action
|
|
95
|
+
};
|
|
96
|
+
// Build context
|
|
97
|
+
const context = testCase.input.context
|
|
98
|
+
? { ...testCase.input.context }
|
|
99
|
+
: undefined;
|
|
100
|
+
// Evaluate
|
|
101
|
+
const result = this.engine.evaluateAction(action, context);
|
|
102
|
+
// Check if rule matched
|
|
103
|
+
const ruleMatched = result.appliedRules.includes(rule.id);
|
|
104
|
+
// Assertion: shouldMatch
|
|
105
|
+
if (testCase.expectedResult.shouldMatch !== ruleMatched) {
|
|
106
|
+
failures.push({
|
|
107
|
+
assertion: 'shouldMatch',
|
|
108
|
+
expected: testCase.expectedResult.shouldMatch,
|
|
109
|
+
actual: ruleMatched,
|
|
110
|
+
message: testCase.expectedResult.shouldMatch
|
|
111
|
+
? `Expected rule '${rule.name}' to match, but it did not`
|
|
112
|
+
: `Expected rule '${rule.name}' NOT to match, but it did`
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// Only check other assertions if shouldMatch is correct
|
|
116
|
+
if (testCase.expectedResult.shouldMatch && ruleMatched) {
|
|
117
|
+
// Check status
|
|
118
|
+
if (testCase.expectedResult.status !== undefined) {
|
|
119
|
+
if (result.status !== testCase.expectedResult.status) {
|
|
120
|
+
failures.push({
|
|
121
|
+
assertion: 'status',
|
|
122
|
+
expected: testCase.expectedResult.status,
|
|
123
|
+
actual: result.status,
|
|
124
|
+
message: `Expected status '${testCase.expectedResult.status}', got '${result.status}'`
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Check allowed
|
|
129
|
+
if (testCase.expectedResult.allowed !== undefined) {
|
|
130
|
+
if (result.allowed !== testCase.expectedResult.allowed) {
|
|
131
|
+
failures.push({
|
|
132
|
+
assertion: 'allowed',
|
|
133
|
+
expected: testCase.expectedResult.allowed,
|
|
134
|
+
actual: result.allowed,
|
|
135
|
+
message: `Expected allowed=${testCase.expectedResult.allowed}, got ${result.allowed}`
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Check risk level
|
|
140
|
+
if (testCase.expectedResult.riskLevel !== undefined) {
|
|
141
|
+
if (result.riskLevel !== testCase.expectedResult.riskLevel) {
|
|
142
|
+
failures.push({
|
|
143
|
+
assertion: 'riskLevel',
|
|
144
|
+
expected: testCase.expectedResult.riskLevel,
|
|
145
|
+
actual: result.riskLevel,
|
|
146
|
+
message: `Expected risk level '${testCase.expectedResult.riskLevel}', got '${result.riskLevel}'`
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Check risk score range
|
|
151
|
+
if (testCase.expectedResult.minRiskScore !== undefined) {
|
|
152
|
+
if (result.riskScore < testCase.expectedResult.minRiskScore) {
|
|
153
|
+
failures.push({
|
|
154
|
+
assertion: 'minRiskScore',
|
|
155
|
+
expected: `>= ${testCase.expectedResult.minRiskScore}`,
|
|
156
|
+
actual: result.riskScore,
|
|
157
|
+
message: `Expected risk score >= ${testCase.expectedResult.minRiskScore}, got ${result.riskScore}`
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (testCase.expectedResult.maxRiskScore !== undefined) {
|
|
162
|
+
if (result.riskScore > testCase.expectedResult.maxRiskScore) {
|
|
163
|
+
failures.push({
|
|
164
|
+
assertion: 'maxRiskScore',
|
|
165
|
+
expected: `<= ${testCase.expectedResult.maxRiskScore}`,
|
|
166
|
+
actual: result.riskScore,
|
|
167
|
+
message: `Expected risk score <= ${testCase.expectedResult.maxRiskScore}, got ${result.riskScore}`
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Check human approval
|
|
172
|
+
if (testCase.expectedResult.requiresHumanApproval !== undefined) {
|
|
173
|
+
if (result.requiresHumanApproval !== testCase.expectedResult.requiresHumanApproval) {
|
|
174
|
+
failures.push({
|
|
175
|
+
assertion: 'requiresHumanApproval',
|
|
176
|
+
expected: testCase.expectedResult.requiresHumanApproval,
|
|
177
|
+
actual: result.requiresHumanApproval,
|
|
178
|
+
message: `Expected requiresHumanApproval=${testCase.expectedResult.requiresHumanApproval}, got ${result.requiresHumanApproval}`
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Check violation count
|
|
183
|
+
if (testCase.expectedResult.violationCount !== undefined) {
|
|
184
|
+
if (result.violations.length !== testCase.expectedResult.violationCount) {
|
|
185
|
+
failures.push({
|
|
186
|
+
assertion: 'violationCount',
|
|
187
|
+
expected: testCase.expectedResult.violationCount,
|
|
188
|
+
actual: result.violations.length,
|
|
189
|
+
message: `Expected ${testCase.expectedResult.violationCount} violations, got ${result.violations.length}`
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// Check warning count
|
|
194
|
+
if (testCase.expectedResult.warningCount !== undefined) {
|
|
195
|
+
if (result.warnings.length !== testCase.expectedResult.warningCount) {
|
|
196
|
+
failures.push({
|
|
197
|
+
assertion: 'warningCount',
|
|
198
|
+
expected: testCase.expectedResult.warningCount,
|
|
199
|
+
actual: result.warnings.length,
|
|
200
|
+
message: `Expected ${testCase.expectedResult.warningCount} warnings, got ${result.warnings.length}`
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Check violation messages
|
|
205
|
+
if (testCase.expectedResult.violationMessages) {
|
|
206
|
+
for (const expectedMsg of testCase.expectedResult.violationMessages) {
|
|
207
|
+
const found = result.violations.some(v => v.message.includes(expectedMsg));
|
|
208
|
+
if (!found) {
|
|
209
|
+
failures.push({
|
|
210
|
+
assertion: 'violationMessage',
|
|
211
|
+
expected: expectedMsg,
|
|
212
|
+
actual: result.violations.map(v => v.message),
|
|
213
|
+
message: `Expected violation message containing '${expectedMsg}' not found`
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Check warning messages
|
|
219
|
+
if (testCase.expectedResult.warningMessages) {
|
|
220
|
+
for (const expectedMsg of testCase.expectedResult.warningMessages) {
|
|
221
|
+
const found = result.warnings.some(w => w.includes(expectedMsg));
|
|
222
|
+
if (!found) {
|
|
223
|
+
failures.push({
|
|
224
|
+
assertion: 'warningMessage',
|
|
225
|
+
expected: expectedMsg,
|
|
226
|
+
actual: result.warnings,
|
|
227
|
+
message: `Expected warning message containing '${expectedMsg}' not found`
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
testCaseId,
|
|
235
|
+
description: testCase.description,
|
|
236
|
+
passed: failures.length === 0,
|
|
237
|
+
skipped: false,
|
|
238
|
+
actualResult: result,
|
|
239
|
+
failures,
|
|
240
|
+
durationMs: Date.now() - startTime
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Log a test failure in verbose mode
|
|
245
|
+
*/
|
|
246
|
+
logFailure(rule, testCase, result) {
|
|
247
|
+
console.log(`\n[FAIL] Rule: ${rule.name}`);
|
|
248
|
+
console.log(` Test: ${testCase.description}`);
|
|
249
|
+
for (const failure of result.failures) {
|
|
250
|
+
console.log(` - ${failure.message}`);
|
|
251
|
+
console.log(` Expected: ${JSON.stringify(failure.expected)}`);
|
|
252
|
+
console.log(` Actual: ${JSON.stringify(failure.actual)}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// ============================================================================
|
|
257
|
+
// HELPER FUNCTIONS
|
|
258
|
+
// ============================================================================
|
|
259
|
+
/**
|
|
260
|
+
* Test a single rule against multiple test cases (convenience function)
|
|
261
|
+
*/
|
|
262
|
+
export function testRule(rule, testCases) {
|
|
263
|
+
const tester = new RuleTester();
|
|
264
|
+
return tester.testRule(rule, testCases);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Create a test case with defaults
|
|
268
|
+
*/
|
|
269
|
+
export function createTestCase(description, action, expectedResult, context) {
|
|
270
|
+
return {
|
|
271
|
+
description,
|
|
272
|
+
input: { action, context },
|
|
273
|
+
expectedResult
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Create a test case that expects the rule to match and deny
|
|
278
|
+
*/
|
|
279
|
+
export function expectDeny(description, action, options) {
|
|
280
|
+
return createTestCase(description, action, {
|
|
281
|
+
shouldMatch: true,
|
|
282
|
+
status: 'denied',
|
|
283
|
+
allowed: false,
|
|
284
|
+
violationCount: 1,
|
|
285
|
+
...options
|
|
286
|
+
}, options?.context);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Create a test case that expects the rule to match and require approval
|
|
290
|
+
*/
|
|
291
|
+
export function expectApproval(description, action, options) {
|
|
292
|
+
return createTestCase(description, action, {
|
|
293
|
+
shouldMatch: true,
|
|
294
|
+
status: 'pending_approval',
|
|
295
|
+
allowed: true,
|
|
296
|
+
requiresHumanApproval: true,
|
|
297
|
+
...options
|
|
298
|
+
}, options?.context);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Create a test case that expects the rule to match and warn
|
|
302
|
+
*/
|
|
303
|
+
export function expectWarn(description, action, options) {
|
|
304
|
+
return createTestCase(description, action, {
|
|
305
|
+
shouldMatch: true,
|
|
306
|
+
status: 'requires_review',
|
|
307
|
+
allowed: true,
|
|
308
|
+
warningCount: 1,
|
|
309
|
+
...options
|
|
310
|
+
}, options?.context);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Create a test case that expects the rule NOT to match
|
|
314
|
+
*/
|
|
315
|
+
export function expectNoMatch(description, action, context) {
|
|
316
|
+
return createTestCase(description, action, { shouldMatch: false }, context);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Create a test case that expects the rule to match and allow
|
|
320
|
+
*/
|
|
321
|
+
export function expectAllow(description, action, context) {
|
|
322
|
+
return createTestCase(description, action, {
|
|
323
|
+
shouldMatch: true,
|
|
324
|
+
status: 'approved',
|
|
325
|
+
allowed: true
|
|
326
|
+
}, context);
|
|
327
|
+
}
|
|
328
|
+
// ============================================================================
|
|
329
|
+
// ASSERTION HELPERS
|
|
330
|
+
// ============================================================================
|
|
331
|
+
/**
|
|
332
|
+
* Assertion helpers for use with testing frameworks like vitest
|
|
333
|
+
*/
|
|
334
|
+
export const assertions = {
|
|
335
|
+
/**
|
|
336
|
+
* Assert that a rule matches the given action
|
|
337
|
+
*/
|
|
338
|
+
ruleMatches(rule, action, context) {
|
|
339
|
+
const engine = new RulesEngine();
|
|
340
|
+
engine.registerRule(rule);
|
|
341
|
+
const result = engine.evaluateAction(action, context);
|
|
342
|
+
return result.appliedRules.includes(rule.id);
|
|
343
|
+
},
|
|
344
|
+
/**
|
|
345
|
+
* Assert that a rule denies the given action
|
|
346
|
+
*/
|
|
347
|
+
ruleDenies(rule, action, context) {
|
|
348
|
+
const engine = new RulesEngine();
|
|
349
|
+
engine.registerRule(rule);
|
|
350
|
+
const result = engine.evaluateAction(action, context);
|
|
351
|
+
return result.appliedRules.includes(rule.id) && result.status === 'denied';
|
|
352
|
+
},
|
|
353
|
+
/**
|
|
354
|
+
* Assert that a rule requires approval for the given action
|
|
355
|
+
*/
|
|
356
|
+
ruleRequiresApproval(rule, action, context) {
|
|
357
|
+
const engine = new RulesEngine();
|
|
358
|
+
engine.registerRule(rule);
|
|
359
|
+
const result = engine.evaluateAction(action, context);
|
|
360
|
+
return result.appliedRules.includes(rule.id) && result.requiresHumanApproval;
|
|
361
|
+
},
|
|
362
|
+
/**
|
|
363
|
+
* Assert that a rule produces a warning for the given action
|
|
364
|
+
*/
|
|
365
|
+
ruleWarns(rule, action, context) {
|
|
366
|
+
const engine = new RulesEngine();
|
|
367
|
+
engine.registerRule(rule);
|
|
368
|
+
const result = engine.evaluateAction(action, context);
|
|
369
|
+
return result.appliedRules.includes(rule.id) && result.warnings.length > 0;
|
|
370
|
+
},
|
|
371
|
+
/**
|
|
372
|
+
* Assert that a rule allows the given action
|
|
373
|
+
*/
|
|
374
|
+
ruleAllows(rule, action, context) {
|
|
375
|
+
const engine = new RulesEngine();
|
|
376
|
+
engine.registerRule(rule);
|
|
377
|
+
const result = engine.evaluateAction(action, context);
|
|
378
|
+
return result.appliedRules.includes(rule.id) && result.allowed;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
//# sourceMappingURL=rule-tester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-tester.js","sourceRoot":"","sources":["../../src/testing/rule-tester.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAQpC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAsHvD,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,MAAM,CAAc;IACpB,OAAO,CAAU;IAEzB,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,IAAkB,E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
|
|
1
|
+
/**
|
|
2
|
+
* Enterprise Agent Supervisor - Rule Validation Framework
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for validating rule structure, syntax, and detecting conflicts.
|
|
5
|
+
*/
|
|
6
|
+
import type { BusinessRule } from '../types/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Result of validating a single rule
|
|
9
|
+
*/
|
|
10
|
+
export interface RuleValidationResult {
|
|
11
|
+
/** Rule being validated */
|
|
12
|
+
ruleId: string;
|
|
13
|
+
/** Whether the rule is valid */
|
|
14
|
+
isValid: boolean;
|
|
15
|
+
/** List of validation errors */
|
|
16
|
+
errors: ValidationError[];
|
|
17
|
+
/** List of validation warnings */
|
|
18
|
+
warnings: ValidationWarning[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validation error
|
|
22
|
+
*/
|
|
23
|
+
export interface ValidationError {
|
|
24
|
+
/** Error code */
|
|
25
|
+
code: string;
|
|
26
|
+
/** Error message */
|
|
27
|
+
message: string;
|
|
28
|
+
/** Path to the problematic field */
|
|
29
|
+
path?: string;
|
|
30
|
+
/** Severity */
|
|
31
|
+
severity: 'error';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validation warning
|
|
35
|
+
*/
|
|
36
|
+
export interface ValidationWarning {
|
|
37
|
+
/** Warning code */
|
|
38
|
+
code: string;
|
|
39
|
+
/** Warning message */
|
|
40
|
+
message: string;
|
|
41
|
+
/** Path to the problematic field */
|
|
42
|
+
path?: string;
|
|
43
|
+
/** Severity */
|
|
44
|
+
severity: 'warning';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Result of checking for rule conflicts
|
|
48
|
+
*/
|
|
49
|
+
export interface ConflictCheckResult {
|
|
50
|
+
/** Whether conflicts were found */
|
|
51
|
+
hasConflicts: boolean;
|
|
52
|
+
/** List of detected conflicts */
|
|
53
|
+
conflicts: RuleConflict[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A conflict between two rules
|
|
57
|
+
*/
|
|
58
|
+
export interface RuleConflict {
|
|
59
|
+
/** First rule in the conflict */
|
|
60
|
+
rule1: {
|
|
61
|
+
id: string;
|
|
62
|
+
name: string;
|
|
63
|
+
};
|
|
64
|
+
/** Second rule in the conflict */
|
|
65
|
+
rule2: {
|
|
66
|
+
id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
};
|
|
69
|
+
/** Type of conflict */
|
|
70
|
+
conflictType: ConflictType;
|
|
71
|
+
/** Description of the conflict */
|
|
72
|
+
description: string;
|
|
73
|
+
/** Suggested resolution */
|
|
74
|
+
suggestion?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Types of rule conflicts
|
|
78
|
+
*/
|
|
79
|
+
export type ConflictType = 'contradicting_actions' | 'duplicate_conditions' | 'shadowed_rule' | 'redundant_rule' | 'circular_dependency';
|
|
80
|
+
/**
|
|
81
|
+
* Result of linting rules
|
|
82
|
+
*/
|
|
83
|
+
export interface LintResult {
|
|
84
|
+
/** Total issues found */
|
|
85
|
+
totalIssues: number;
|
|
86
|
+
/** Critical issues that should be fixed */
|
|
87
|
+
errors: LintIssue[];
|
|
88
|
+
/** Non-critical issues that should be reviewed */
|
|
89
|
+
warnings: LintIssue[];
|
|
90
|
+
/** Suggestions for improvement */
|
|
91
|
+
suggestions: LintIssue[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A lint issue
|
|
95
|
+
*/
|
|
96
|
+
export interface LintIssue {
|
|
97
|
+
/** Issue code */
|
|
98
|
+
code: string;
|
|
99
|
+
/** Rule ID with the issue */
|
|
100
|
+
ruleId: string;
|
|
101
|
+
/** Issue message */
|
|
102
|
+
message: string;
|
|
103
|
+
/** Severity */
|
|
104
|
+
severity: 'error' | 'warning' | 'suggestion';
|
|
105
|
+
/** How to fix the issue */
|
|
106
|
+
fix?: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Validate a single business rule
|
|
110
|
+
*/
|
|
111
|
+
export declare function validateRule(rule: unknown): RuleValidationResult;
|
|
112
|
+
/**
|
|
113
|
+
* Validate an array of conditions
|
|
114
|
+
*/
|
|
115
|
+
export declare function validateConditions(conditions: unknown[]): {
|
|
116
|
+
errors: ValidationError[];
|
|
117
|
+
warnings: ValidationWarning[];
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Check for conflicts between rules
|
|
121
|
+
*/
|
|
122
|
+
export declare function checkForConflicts(rules: BusinessRule[]): ConflictCheckResult;
|
|
123
|
+
/**
|
|
124
|
+
* Lint rules for potential issues and best practices
|
|
125
|
+
*/
|
|
126
|
+
export declare function lintRules(rules: BusinessRule[]): LintResult;
|
|
127
|
+
/**
|
|
128
|
+
* Validate multiple rules at once
|
|
129
|
+
*/
|
|
130
|
+
export declare function validateRules(rules: unknown[]): {
|
|
131
|
+
valid: RuleValidationResult[];
|
|
132
|
+
invalid: RuleValidationResult[];
|
|
133
|
+
summary: {
|
|
134
|
+
total: number;
|
|
135
|
+
valid: number;
|
|
136
|
+
invalid: number;
|
|
137
|
+
errorCount: number;
|
|
138
|
+
warningCount: number;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=rule-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-validator.d.ts","sourceRoot":"","sources":["../../src/testing/rule-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,YAAY,EAMb,MAAM,mBAAmB,CAAC;AAM3B;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,gCAAgC;IAChC,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,kCAAkC;IAClC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iBA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