@thymian/rules-testing 0.0.0-stage → 0.4.1
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 +227 -2
- package/dist/conforming-response.d.ts +12 -0
- package/dist/conforming-response.d.ts.map +1 -0
- package/dist/conforming-response.js +68 -0
- package/dist/conforming-response.js.map +1 -0
- package/dist/create-rule-tester.d.ts +101 -0
- package/dist/create-rule-tester.d.ts.map +1 -0
- package/dist/create-rule-tester.js +50 -0
- package/dist/create-rule-tester.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/recorded.d.ts +43 -0
- package/dist/recorded.d.ts.map +1 -0
- package/dist/recorded.js +75 -0
- package/dist/recorded.js.map +1 -0
- package/dist/rule-test-execution.d.ts +87 -0
- package/dist/rule-test-execution.d.ts.map +1 -0
- package/dist/rule-test-execution.js +118 -0
- package/dist/rule-test-execution.js.map +1 -0
- package/dist/rule-under-test.d.ts +21 -0
- package/dist/rule-under-test.d.ts.map +1 -0
- package/dist/rule-under-test.js +24 -0
- package/dist/rule-under-test.js.map +1 -0
- package/dist/run-analyze.d.ts +20 -0
- package/dist/run-analyze.d.ts.map +1 -0
- package/dist/run-analyze.js +179 -0
- package/dist/run-analyze.js.map +1 -0
- package/dist/run-lint.d.ts +10 -0
- package/dist/run-lint.d.ts.map +1 -0
- package/dist/run-lint.js +37 -0
- package/dist/run-lint.js.map +1 -0
- package/dist/run-test.d.ts +25 -0
- package/dist/run-test.d.ts.map +1 -0
- package/dist/run-test.js +195 -0
- package/dist/run-test.js.map +1 -0
- package/dist/stated-applicability.d.ts +46 -0
- package/dist/stated-applicability.d.ts.map +1 -0
- package/dist/stated-applicability.js +66 -0
- package/dist/stated-applicability.js.map +1 -0
- package/package.json +50 -4
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type ExecutionStatus, type FindingRecord, type Rule, type RuleSeverity, type RuleViolationLocation, type RunRulesResult, type ThymianFormat, type ThymianHttpTransaction } from '@thymian/core';
|
|
2
|
+
import type { RuleUnderTest } from './rule-under-test.js';
|
|
3
|
+
/**
|
|
4
|
+
* The status of an execution, spelled as the report spells it (ADR-0030).
|
|
5
|
+
*/
|
|
6
|
+
export type RuleTestExecutionStatus = ExecutionStatus['kind'];
|
|
7
|
+
/**
|
|
8
|
+
* What a rule said about one location, in one validation context.
|
|
9
|
+
*/
|
|
10
|
+
export type RuleTestExecution = {
|
|
11
|
+
/**
|
|
12
|
+
* Where the engine located the execution: a transaction (an `edge` whose
|
|
13
|
+
* `elementId` is the transaction id), a node, or a free string. Reported as
|
|
14
|
+
* the engine gave it, with one addition: a node or edge location without a
|
|
15
|
+
* `label` gets the label the engine prints for it in a report.
|
|
16
|
+
*/
|
|
17
|
+
location: RuleViolationLocation;
|
|
18
|
+
status: RuleTestExecutionStatus;
|
|
19
|
+
/** Present when `failed`. */
|
|
20
|
+
message?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Present when `failed`: the severity the rule declares, which is `off` for
|
|
23
|
+
* a rule that ships disabled.
|
|
24
|
+
*/
|
|
25
|
+
severity?: RuleSeverity;
|
|
26
|
+
/** Present when `skipped` or `notApplicable` and the engine gave a reason. */
|
|
27
|
+
reason?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Present when a grouped rule located the execution on a group as a whole
|
|
30
|
+
* and not on one of its members: the group key. Every member of the group
|
|
31
|
+
* then carries the execution, each on its own location.
|
|
32
|
+
*/
|
|
33
|
+
group?: string;
|
|
34
|
+
/**
|
|
35
|
+
* What the rule attached to the execution, as the engine reports it in a
|
|
36
|
+
* report: on a pass as much as on a violation. Empty when it attached
|
|
37
|
+
* nothing, and on a transaction the engine reported no execution on.
|
|
38
|
+
*/
|
|
39
|
+
findings: FindingRecord[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Arranges the executions of one run as the list a rule test compares against:
|
|
43
|
+
* every transaction of the format in the order it was added, once per
|
|
44
|
+
* execution the engine reported on it, then the executions the engine located
|
|
45
|
+
* anywhere else.
|
|
46
|
+
*
|
|
47
|
+
* A transaction the engine reported nothing on is `passed` when the rule
|
|
48
|
+
* applies to it and `notApplicable` when it does not. The engines report only
|
|
49
|
+
* what a rule returns, so this is the one place that knows the difference.
|
|
50
|
+
*/
|
|
51
|
+
export declare function listExecutions(format: ThymianFormat, reported: RuleTestExecution[], isApplicable: (transactionId: string) => boolean, transactionOf?: TransactionOf): RuleTestExecution[];
|
|
52
|
+
/**
|
|
53
|
+
* The executions the engine located on the transaction, in the order it
|
|
54
|
+
* reported them, or the one filled in for a transaction it reported nothing
|
|
55
|
+
* on, with the status given.
|
|
56
|
+
*/
|
|
57
|
+
export declare function executionsOn({ transactionId, thymianReq, thymianRes }: ThymianHttpTransaction, reported: RuleTestExecution[], unreported: 'passed' | 'notApplicable', transactionOf?: TransactionOf): RuleTestExecution[];
|
|
58
|
+
/** The executions the engine located on the transaction. */
|
|
59
|
+
export declare function reportedOn(transactionId: string, reported: RuleTestExecution[], transactionOf?: TransactionOf): RuleTestExecution[];
|
|
60
|
+
/**
|
|
61
|
+
* The executions the engine located on none of the transactions: on a node,
|
|
62
|
+
* on a free string, or on an edge that is not one of them.
|
|
63
|
+
*/
|
|
64
|
+
export declare function executionsElsewhere(transactions: ThymianHttpTransaction[], reported: RuleTestExecution[], transactionOf?: TransactionOf): RuleTestExecution[];
|
|
65
|
+
/**
|
|
66
|
+
* Which transaction an execution's location is about, if any; by default only
|
|
67
|
+
* a transaction location is. An execution keeps its location wherever it is
|
|
68
|
+
* listed.
|
|
69
|
+
*/
|
|
70
|
+
export type TransactionOf = (location: RuleViolationLocation) => string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* The transaction a location names: an `edge`'s `elementId`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function transactionOfEdge(location: RuleViolationLocation): string | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* The executions core's report builder makes of what the rule returned, as it
|
|
77
|
+
* does for `thymian lint` and `thymian analyze`, each on the location the rule
|
|
78
|
+
* returned it for. An execution on a group is listed once per member of the
|
|
79
|
+
* group, on the member, with the group key.
|
|
80
|
+
*/
|
|
81
|
+
export declare function reportedExecutions(result: RunRulesResult, { rule, declaredSeverity }: RuleUnderTest, format: ThymianFormat, runType: 'lint' | 'analyze'): RuleTestExecution[];
|
|
82
|
+
/**
|
|
83
|
+
* A location with the label the engine prints for it in a report, unless it
|
|
84
|
+
* is a free string or the rule labelled it itself.
|
|
85
|
+
*/
|
|
86
|
+
export declare function withEngineLabel(location: RuleViolationLocation, format: ThymianFormat, rule: Rule): RuleViolationLocation;
|
|
87
|
+
//# sourceMappingURL=rule-test-execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-test-execution.d.ts","sourceRoot":"","sources":["../src/rule-test-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,aAAa,EAGlB,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAE5B,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;;OAKG;IACH,QAAQ,EAAE,qBAAqB,CAAC;IAChC,MAAM,EAAE,uBAAuB,CAAC;IAChC,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC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AAe,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,IAAI,GACT,qBAAqB,CAYvB"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { executionsFromRunRulesResult, isRuleViolationGroupLocation, resolveViolationLocation, thymianHttpTransactionToString, } from '@thymian/core';
|
|
2
|
+
/**
|
|
3
|
+
* Arranges the executions of one run as the list a rule test compares against:
|
|
4
|
+
* every transaction of the format in the order it was added, once per
|
|
5
|
+
* execution the engine reported on it, then the executions the engine located
|
|
6
|
+
* anywhere else.
|
|
7
|
+
*
|
|
8
|
+
* A transaction the engine reported nothing on is `passed` when the rule
|
|
9
|
+
* applies to it and `notApplicable` when it does not. The engines report only
|
|
10
|
+
* what a rule returns, so this is the one place that knows the difference.
|
|
11
|
+
*/
|
|
12
|
+
export function listExecutions(format, reported, isApplicable, transactionOf = transactionOfEdge) {
|
|
13
|
+
const transactions = format.getThymianHttpTransactions();
|
|
14
|
+
return [
|
|
15
|
+
...transactions.flatMap((transaction) => executionsOn(transaction, reported, isApplicable(transaction.transactionId) ? 'passed' : 'notApplicable', transactionOf)),
|
|
16
|
+
...executionsElsewhere(transactions, reported, transactionOf),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The executions the engine located on the transaction, in the order it
|
|
21
|
+
* reported them, or the one filled in for a transaction it reported nothing
|
|
22
|
+
* on, with the status given.
|
|
23
|
+
*/
|
|
24
|
+
export function executionsOn({ transactionId, thymianReq, thymianRes }, reported, unreported, transactionOf = transactionOfEdge) {
|
|
25
|
+
const executions = reportedOn(transactionId, reported, transactionOf);
|
|
26
|
+
return executions.length > 0
|
|
27
|
+
? executions
|
|
28
|
+
: [
|
|
29
|
+
{
|
|
30
|
+
location: {
|
|
31
|
+
elementType: 'edge',
|
|
32
|
+
elementId: transactionId,
|
|
33
|
+
label: thymianHttpTransactionToString(thymianReq, thymianRes),
|
|
34
|
+
},
|
|
35
|
+
status: unreported,
|
|
36
|
+
findings: [],
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
/** The executions the engine located on the transaction. */
|
|
41
|
+
export function reportedOn(transactionId, reported, transactionOf = transactionOfEdge) {
|
|
42
|
+
return reported.filter(({ location }) => transactionOf(location) === transactionId);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The executions the engine located on none of the transactions: on a node,
|
|
46
|
+
* on a free string, or on an edge that is not one of them.
|
|
47
|
+
*/
|
|
48
|
+
export function executionsElsewhere(transactions, reported, transactionOf = transactionOfEdge) {
|
|
49
|
+
const ids = new Set(transactions.map(({ transactionId }) => transactionId));
|
|
50
|
+
return reported.filter(({ location }) => {
|
|
51
|
+
const transactionId = transactionOf(location);
|
|
52
|
+
return transactionId === undefined || !ids.has(transactionId);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The transaction a location names: an `edge`'s `elementId`.
|
|
57
|
+
*/
|
|
58
|
+
export function transactionOfEdge(location) {
|
|
59
|
+
return typeof location !== 'string' && location.elementType === 'edge'
|
|
60
|
+
? location.elementId
|
|
61
|
+
: undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The executions core's report builder makes of what the rule returned, as it
|
|
65
|
+
* does for `thymian lint` and `thymian analyze`, each on the location the rule
|
|
66
|
+
* returned it for. An execution on a group is listed once per member of the
|
|
67
|
+
* group, on the member, with the group key.
|
|
68
|
+
*/
|
|
69
|
+
export function reportedExecutions(result, { rule, declaredSeverity }, format, runType) {
|
|
70
|
+
const entries = result[rule.meta.name]?.ruleFnResult ?? [];
|
|
71
|
+
// One overload per run type, so the call is spelled out for each.
|
|
72
|
+
const executions = runType === 'lint'
|
|
73
|
+
? executionsFromRunRulesResult(result, [rule], format, 'lint')
|
|
74
|
+
: executionsFromRunRulesResult(result, [rule], format, 'analyze');
|
|
75
|
+
return executions.flatMap(({ status, findings }, index) => {
|
|
76
|
+
// The report builder emits one execution per entry, in entry order.
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
78
|
+
const { location } = entries[index];
|
|
79
|
+
const outcome = {
|
|
80
|
+
status: status.kind,
|
|
81
|
+
...(status.kind === 'failed'
|
|
82
|
+
? { message: status.reason, severity: declaredSeverity }
|
|
83
|
+
: {}),
|
|
84
|
+
...(status.kind === 'skipped' && status.reason !== undefined
|
|
85
|
+
? { reason: status.reason }
|
|
86
|
+
: {}),
|
|
87
|
+
findings,
|
|
88
|
+
};
|
|
89
|
+
// What a rule says about a group, it says about every member of it.
|
|
90
|
+
// A group without members has only its key to be listed on.
|
|
91
|
+
return isRuleViolationGroupLocation(location) && location.members.length > 0
|
|
92
|
+
? location.members.map((member) => ({
|
|
93
|
+
location: withEngineLabel(member, format, rule),
|
|
94
|
+
...outcome,
|
|
95
|
+
group: location.key,
|
|
96
|
+
}))
|
|
97
|
+
: [
|
|
98
|
+
{
|
|
99
|
+
location: isRuleViolationGroupLocation(location)
|
|
100
|
+
? location.key
|
|
101
|
+
: withEngineLabel(location, format, rule),
|
|
102
|
+
...outcome,
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A location with the label the engine prints for it in a report, unless it
|
|
109
|
+
* is a free string or the rule labelled it itself.
|
|
110
|
+
*/
|
|
111
|
+
export function withEngineLabel(location, format, rule) {
|
|
112
|
+
if (typeof location === 'string' || location.label !== undefined) {
|
|
113
|
+
return location;
|
|
114
|
+
}
|
|
115
|
+
const { heading } = resolveViolationLocation(location, format, rule.meta.name);
|
|
116
|
+
return heading === '' ? location : { ...location, label: heading };
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=rule-test-execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-test-execution.js","sourceRoot":"","sources":["../src/rule-test-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4B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AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,QAA+B,EAC/B,MAAqB,EACrB,IAAU;IAEV,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACjE,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,wBAAwB,CAC1C,QAAQ,EACR,MAAM,EACN,IAAI,CAAC,IAAI,CAAC,IAAI,CACf,CAAC;IAEF,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Rule, RulesConfiguration, RuleSeverity } from '@thymian/core';
|
|
2
|
+
/**
|
|
3
|
+
* A rule made ready for an engine, whatever it ships as.
|
|
4
|
+
*/
|
|
5
|
+
export type RuleUnderTest = {
|
|
6
|
+
/** The rule as the engine runs it: enabled, also when it ships `off`. */
|
|
7
|
+
rule: Rule;
|
|
8
|
+
/** What a config would say about the rule: its options. */
|
|
9
|
+
rulesConfig: RulesConfiguration;
|
|
10
|
+
/** The severity the rule declares, which is the one a rule test reports. */
|
|
11
|
+
declaredSeverity: RuleSeverity;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Prepares a rule for the engines. They leave a rule with severity `off`
|
|
15
|
+
* out, so such a rule is handed to them enabled, on a copy, as a config that
|
|
16
|
+
* turns it on would; and they read a rule's options from the rules
|
|
17
|
+
* configuration, so the options go there, checked against the rule's options
|
|
18
|
+
* schema first as the options of a config are when it is loaded.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ruleUnderTest(rule: Rule, options: Record<PropertyKey, unknown> | undefined): RuleUnderTest;
|
|
21
|
+
//# sourceMappingURL=rule-under-test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-under-test.d.ts","sourceRoot":"","sources":["../src/rule-under-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG5E;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,yEAAyE;IACzE,IAAI,EAAE,IAAI,CAAC;IACX,2DAA2D;IAC3D,WAAW,EAAE,kBAAkB,CAAC;IAChC,4EAA4E;IAC5E,gBAAgB,EAAE,YAAY,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,SAAS,GAChD,aAAa,CAqBf"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { validate } from '@thymian/core/ajv';
|
|
2
|
+
/**
|
|
3
|
+
* Prepares a rule for the engines. They leave a rule with severity `off`
|
|
4
|
+
* out, so such a rule is handed to them enabled, on a copy, as a config that
|
|
5
|
+
* turns it on would; and they read a rule's options from the rules
|
|
6
|
+
* configuration, so the options go there, checked against the rule's options
|
|
7
|
+
* schema first as the options of a config are when it is loaded.
|
|
8
|
+
*/
|
|
9
|
+
export function ruleUnderTest(rule, options) {
|
|
10
|
+
const declaredSeverity = rule.meta.severity;
|
|
11
|
+
if (options !== undefined &&
|
|
12
|
+
rule.meta.options &&
|
|
13
|
+
!validate(rule.meta.options, options)) {
|
|
14
|
+
throw new Error(`Options for rule "${rule.meta.name}" do not match the options schema of the rule.`);
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
rule: declaredSeverity === 'off'
|
|
18
|
+
? { ...rule, meta: { ...rule.meta, severity: 'error' } }
|
|
19
|
+
: rule,
|
|
20
|
+
rulesConfig: options === undefined ? {} : { [rule.meta.name]: { options } },
|
|
21
|
+
declaredSeverity,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=rule-under-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-under-test.js","sourceRoot":"","sources":["../src/rule-under-test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAc7C;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAU,EACV,OAAiD;IAEjD,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;IAE5C,IACE,OAAO,KAAK,SAAS;QACrB,IAAI,CAAC,IAAI,CAAC,OAAO;QACjB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,EACrC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,qBAAqB,IAAI,CAAC,IAAI,CAAC,IAAI,gDAAgD,CACpF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EACF,gBAAgB,KAAK,KAAK;YACxB,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;YACxD,CAAC,CAAC,IAAI;QACV,WAAW,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE;QAC3E,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ThymianFormat } from '@thymian/core';
|
|
2
|
+
import { type RecordedPair } from './recorded.js';
|
|
3
|
+
import { type RuleTestExecution } from './rule-test-execution.js';
|
|
4
|
+
import type { RuleUnderTest } from './rule-under-test.js';
|
|
5
|
+
/**
|
|
6
|
+
* Runs a rule in `analytics` against the traffic: every transaction of the
|
|
7
|
+
* format recorded once, conforming, unless traffic is handed in. A `default`
|
|
8
|
+
* transaction declares no status to answer with, so it is not recorded.
|
|
9
|
+
*
|
|
10
|
+
* The list is the recordings in traffic order, each on the transaction of the
|
|
11
|
+
* format it matches, then the transactions that were never recorded, then the
|
|
12
|
+
* executions the engine located anywhere else. An execution the engine
|
|
13
|
+
* located on a recording's label takes the place of the transaction that
|
|
14
|
+
* recording matched and keeps the label as its location. A recording that
|
|
15
|
+
* matches no transaction has no entry of its own: what the engine reports on
|
|
16
|
+
* it, it locates on the operation's request node when only the response is
|
|
17
|
+
* undocumented, otherwise on a free string.
|
|
18
|
+
*/
|
|
19
|
+
export declare function runAnalyze(underTest: RuleUnderTest, format: ThymianFormat, handedIn?: RecordedPair[]): Promise<RuleTestExecution[]>;
|
|
20
|
+
//# sourceMappingURL=run-analyze.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-analyze.d.ts","sourceRoot":"","sources":["../src/run-analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAML,KAAK,iBAAiB,EAGvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAiC1D;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,aAAa,EACrB,QAAQ,CAAC,EAAE,YAAY,EAAE,GACxB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAyG9B"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { httpTransactionToLabel, isDefaultResponse, NoopLogger, runRules, } from '@thymian/core';
|
|
2
|
+
import { AnalyticsApiContext, SqliteHttpTransactionRepository, } from '@thymian/plugin-http-analyzer';
|
|
3
|
+
import { recorded } from './recorded.js';
|
|
4
|
+
import { executionsElsewhere, executionsOn, listExecutions, reportedExecutions, reportedOn, transactionOfEdge, } from './rule-test-execution.js';
|
|
5
|
+
import { applicableTransactions, observeApplicability, } from './stated-applicability.js';
|
|
6
|
+
const logger = new NoopLogger();
|
|
7
|
+
/**
|
|
8
|
+
* The analyzer takes every Applicability as a filter expression, asked of the
|
|
9
|
+
* recorded pair. Only a rule that reads whole traces states none.
|
|
10
|
+
*/
|
|
11
|
+
const applicabilityCalls = {
|
|
12
|
+
stating: new Set([
|
|
13
|
+
'validateCommonHttpTransactions',
|
|
14
|
+
'validateGroupedCommonHttpTransactions',
|
|
15
|
+
'validateHttpTransactions',
|
|
16
|
+
'validateCapturedHttpTransactions',
|
|
17
|
+
]),
|
|
18
|
+
notStating: new Set(['validateCapturedHttpTraces']),
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Runs a rule in `analytics` against the traffic: every transaction of the
|
|
22
|
+
* format recorded once, conforming, unless traffic is handed in. A `default`
|
|
23
|
+
* transaction declares no status to answer with, so it is not recorded.
|
|
24
|
+
*
|
|
25
|
+
* The list is the recordings in traffic order, each on the transaction of the
|
|
26
|
+
* format it matches, then the transactions that were never recorded, then the
|
|
27
|
+
* executions the engine located anywhere else. An execution the engine
|
|
28
|
+
* located on a recording's label takes the place of the transaction that
|
|
29
|
+
* recording matched and keeps the label as its location. A recording that
|
|
30
|
+
* matches no transaction has no entry of its own: what the engine reports on
|
|
31
|
+
* it, it locates on the operation's request node when only the response is
|
|
32
|
+
* undocumented, otherwise on a free string.
|
|
33
|
+
*/
|
|
34
|
+
export async function runAnalyze(underTest, format, handedIn) {
|
|
35
|
+
const transactions = format.getThymianHttpTransactions();
|
|
36
|
+
const traffic = handedIn ??
|
|
37
|
+
transactions
|
|
38
|
+
.filter(({ thymianRes }) => !isDefaultResponse(thymianRes))
|
|
39
|
+
.map(({ transactionId }) => recorded(format, transactionId));
|
|
40
|
+
// Per recording, in traffic order: the id of the transaction it matches.
|
|
41
|
+
const matched = traffic.map((pair) => matchedTransaction(format, pair));
|
|
42
|
+
// The analyzer locates what a rule returns about a recorded pair on the
|
|
43
|
+
// pair's label: such an execution is about the transaction the pair matched.
|
|
44
|
+
const transactionOfLabel = transactionOfEachLabel(traffic.map(({ request, response }, index) => ({
|
|
45
|
+
label: httpTransactionToLabel(request, response),
|
|
46
|
+
transactionId: matched[index],
|
|
47
|
+
})));
|
|
48
|
+
const transactionOf = (location) => typeof location === 'string'
|
|
49
|
+
? transactionOfLabel.get(location)
|
|
50
|
+
: transactionOfEdge(location);
|
|
51
|
+
const whole = await analyze(underTest, format, traffic);
|
|
52
|
+
// The format recorded once is listed as the format is, as in `static`. A
|
|
53
|
+
// transaction whose recording the format cannot tell from another's has no
|
|
54
|
+
// recording of its own, and the rule was not asked about it there.
|
|
55
|
+
if (handedIn === undefined) {
|
|
56
|
+
return listExecutions(format, whole.reported, (transactionId) => matched.includes(transactionId) && whole.isApplicable(transactionId), transactionOf);
|
|
57
|
+
}
|
|
58
|
+
// The analyzer locates an execution on the transaction, not on the
|
|
59
|
+
// recording. Which recording of a transaction recorded several times an
|
|
60
|
+
// execution is about is therefore asked of each of them alone.
|
|
61
|
+
const alone = new Map();
|
|
62
|
+
for (const { transactionId } of transactions) {
|
|
63
|
+
const recordings = [...matched.keys()].filter((index) => matched[index] === transactionId);
|
|
64
|
+
if (recordings.length < 2) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const analyses = [];
|
|
68
|
+
for (const index of recordings) {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
|
+
analyses.push(await analyze(underTest, format, [traffic[index]]));
|
|
71
|
+
}
|
|
72
|
+
// A rule that compares recordings with each other says something else
|
|
73
|
+
// about one of them alone. What it reported on the transaction with all
|
|
74
|
+
// of them present then stands for every recording of it.
|
|
75
|
+
const reportedAlone = analyses.flatMap(({ reported }) => reportedOn(transactionId, reported, transactionOf));
|
|
76
|
+
if (reportedAlone.length ===
|
|
77
|
+
reportedOn(transactionId, whole.reported, transactionOf).length) {
|
|
78
|
+
recordings.forEach((index, position) => {
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
80
|
+
alone.set(index, analyses[position]);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const byId = new Map(transactions.map((transaction) => [transaction.transactionId, transaction]));
|
|
85
|
+
return [
|
|
86
|
+
...matched.flatMap((transactionId, index) => {
|
|
87
|
+
const transaction = transactionId === undefined ? undefined : byId.get(transactionId);
|
|
88
|
+
if (transaction === undefined) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const { reported, isApplicable } = alone.get(index) ?? whole;
|
|
92
|
+
return executionsOn(transaction, reported, isApplicable(transaction.transactionId) ? 'passed' : 'notApplicable', transactionOf);
|
|
93
|
+
}),
|
|
94
|
+
...transactions
|
|
95
|
+
.filter(({ transactionId }) => !matched.includes(transactionId))
|
|
96
|
+
.flatMap((transaction) => executionsOn(transaction, whole.reported, 'notApplicable', transactionOf)),
|
|
97
|
+
...executionsElsewhere(transactions, whole.reported, transactionOf),
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The analyzer's own context evaluates the rule against the traffic, held in
|
|
102
|
+
* memory, with the format present, and core's rule runner and report builder
|
|
103
|
+
* turn what it returns into executions, as they do for `thymian analyze`.
|
|
104
|
+
*
|
|
105
|
+
* Each pair is recorded as traffic read from a HAR file is by default, a user
|
|
106
|
+
* agent talking to an origin server.
|
|
107
|
+
*/
|
|
108
|
+
async function analyze(underTest, format, traffic) {
|
|
109
|
+
const { rule, rulesConfig } = underTest;
|
|
110
|
+
const repository = new SqliteHttpTransactionRepository(':memory:', logger);
|
|
111
|
+
try {
|
|
112
|
+
await repository.init();
|
|
113
|
+
for (const { request, response } of traffic) {
|
|
114
|
+
repository.insertHttpTransaction({
|
|
115
|
+
request: { data: request, meta: { role: 'user-agent' } },
|
|
116
|
+
response: { data: response, meta: { role: 'origin server' } },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const analyzerContext = () => new AnalyticsApiContext({
|
|
120
|
+
repository,
|
|
121
|
+
logger,
|
|
122
|
+
format,
|
|
123
|
+
roles: rule.meta.appliesTo,
|
|
124
|
+
});
|
|
125
|
+
let stated = () => undefined;
|
|
126
|
+
const adapter = {
|
|
127
|
+
errorName: 'AnalyzeLinterError',
|
|
128
|
+
mode: 'analytics',
|
|
129
|
+
getRuleFn: (rule) => rule.analyzeRule,
|
|
130
|
+
createContext: () => {
|
|
131
|
+
const observed = observeApplicability(analyzerContext(), applicabilityCalls);
|
|
132
|
+
stated = observed.stated;
|
|
133
|
+
return observed.context;
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
const result = await runRules(logger, [rule], format, rulesConfig, adapter);
|
|
137
|
+
const applicable = applicableTransactions(stated(), analyzerContext());
|
|
138
|
+
return {
|
|
139
|
+
reported: reportedExecutions(result, underTest, format, 'analyze'),
|
|
140
|
+
isApplicable: (transactionId) => applicable?.has(transactionId) ?? true,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
await repository.close();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The transaction each recording's label is about: what the analyzer locates
|
|
149
|
+
* on the label, from `validateCapturedHttpTransactions` and from
|
|
150
|
+
* `validateCapturedHttpTraces` for a trace of one pair, is about the
|
|
151
|
+
* transaction that recording matched. The label does not name the request's
|
|
152
|
+
* media type, so recordings of two transactions can share one; such a label is
|
|
153
|
+
* about neither.
|
|
154
|
+
*/
|
|
155
|
+
function transactionOfEachLabel(recordings) {
|
|
156
|
+
const byLabel = new Map();
|
|
157
|
+
// `undefined` stands for both a recording that matched no transaction and a
|
|
158
|
+
// label shared by recordings of two: either way it is about none.
|
|
159
|
+
for (const { label, transactionId } of recordings) {
|
|
160
|
+
byLabel.set(label, byLabel.has(label) && byLabel.get(label) !== transactionId
|
|
161
|
+
? undefined
|
|
162
|
+
: transactionId);
|
|
163
|
+
}
|
|
164
|
+
return byLabel;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The id of the transaction the analyzer recognises in the recording. None
|
|
168
|
+
* when the recording matches no transaction or more than one, or cannot be
|
|
169
|
+
* asked of the format at all, as for an origin that is no URL.
|
|
170
|
+
*/
|
|
171
|
+
function matchedTransaction(format, { request, response }) {
|
|
172
|
+
try {
|
|
173
|
+
return format.matchTransaction(request, response)?.[0];
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=run-analyze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-analyze.js","sourceRoot":"","sources":["../src/run-analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EAEV,QAAQ,GAET,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,mBAAmB,EACnB,+BAA+B,GAChC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAqB,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,UAAU,EAGV,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAEL,sBAAsB,EACtB,oBAAoB,GAErB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;AAEhC;;;GAGG;AACH,MAAM,kBAAkB,GAAuB;IAC7C,OAAO,EAAE,IAAI,GAAG,CAAC;QACf,gCAAgC;QAChC,uCAAuC;QACvC,0BAA0B;QAC1B,kCAAkC;KACnC,CAAC;IACF,UAAU,EAAE,IAAI,GAAG,CAAC,CAAC,4BAA4B,CAAC,CAAC;CACpD,CAAC;AAWF;;;;;;;;;;;;;GAaG;AACH,MAA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C;QAC5E,MAAM,UAAU,GAAG,sBAAsB,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;QAEvE,OAAO;YACL,QAAQ,EAAE,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC;YAClE,YAAY,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,IAAI;SACxE,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAC7B,UAAkE;IAElE,MAAM,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEtD,4EAA4E;IAC5E,kEAAkE;IAClE,KAAK,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,UAAU,EAAE,CAAC;QAClD,OAAO,CAAC,GAAG,CACT,KAAK,EACL,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,aAAa;YACxD,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,aAAa,CAClB,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,SAAS,kBAAkB,CACzB,MAAqB,EACrB,EAAE,OAAO,EAAE,QAAQ,EAAgB;IAEnC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ThymianFormat } from '@thymian/core';
|
|
2
|
+
import { type RuleTestExecution } from './rule-test-execution.js';
|
|
3
|
+
import type { RuleUnderTest } from './rule-under-test.js';
|
|
4
|
+
/**
|
|
5
|
+
* Runs a rule in `static`: the linter's own context evaluates it against the
|
|
6
|
+
* format, and core's rule runner and report builder turn what it returns into
|
|
7
|
+
* executions, as they do for `thymian lint`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function runLint(underTest: RuleUnderTest, format: ThymianFormat): Promise<RuleTestExecution[]>;
|
|
10
|
+
//# sourceMappingURL=run-lint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-lint.d.ts","sourceRoot":"","sources":["../src/run-lint.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAmB1D;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA+B9B"}
|
package/dist/run-lint.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NoopLogger, runRules, } from '@thymian/core';
|
|
2
|
+
import { StaticApiContext } from '@thymian/plugin-http-linter';
|
|
3
|
+
import { listExecutions, reportedExecutions, } from './rule-test-execution.js';
|
|
4
|
+
import { applicableTransactions, observeApplicability, } from './stated-applicability.js';
|
|
5
|
+
const logger = new NoopLogger();
|
|
6
|
+
/** The linter's `validateHttpTransactions` decides in a plain callback. */
|
|
7
|
+
const applicabilityCalls = {
|
|
8
|
+
stating: new Set([
|
|
9
|
+
'validateCommonHttpTransactions',
|
|
10
|
+
'validateGroupedCommonHttpTransactions',
|
|
11
|
+
]),
|
|
12
|
+
notStating: new Set(['validateHttpTransactions']),
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Runs a rule in `static`: the linter's own context evaluates it against the
|
|
16
|
+
* format, and core's rule runner and report builder turn what it returns into
|
|
17
|
+
* executions, as they do for `thymian lint`.
|
|
18
|
+
*/
|
|
19
|
+
export async function runLint(underTest, format) {
|
|
20
|
+
const { rule, rulesConfig } = underTest;
|
|
21
|
+
let stated = () => undefined;
|
|
22
|
+
const adapter = {
|
|
23
|
+
errorName: 'StaticLinterError',
|
|
24
|
+
mode: 'static',
|
|
25
|
+
getRuleFn: (rule) => rule.lintRule,
|
|
26
|
+
createContext: () => {
|
|
27
|
+
const observed = observeApplicability(new StaticApiContext(format, logger), applicabilityCalls);
|
|
28
|
+
stated = observed.stated;
|
|
29
|
+
return observed.context;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
const result = await runRules(logger, [rule], format, rulesConfig, adapter);
|
|
33
|
+
const reported = reportedExecutions(result, underTest, format, 'lint');
|
|
34
|
+
const applicable = applicableTransactions(stated(), new StaticApiContext(format, logger));
|
|
35
|
+
return listExecutions(format, reported, (transactionId) => applicable?.has(transactionId) ?? true);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=run-lint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-lint.js","sourceRoot":"","sources":["../src/run-lint.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAEV,QAAQ,GAET,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EACL,cAAc,EACd,kBAAkB,GAEnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAEL,sBAAsB,EACtB,oBAAoB,GAErB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;AAEhC,2EAA2E;AAC3E,MAAM,kBAAkB,GAAuB;IAC7C,OAAO,EAAE,IAAI,GAAG,CAAC;QACf,gCAAgC;QAChC,uCAAuC;KACxC,CAAC;IACF,UAAU,EAAE,IAAI,GAAG,CAAC,CAAC,0BAA0B,CAAC,CAAC;CAClD,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,SAAwB,EACxB,MAAqB;IAErB,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;IACxC,IAAI,MAAM,GAA8B,GAAG,EAAE,CAAC,SAAS,CAAC;IAExD,MAAM,OAAO,GAAwC;QACnD,SAAS,EAAE,mBAAmB;QAC9B,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ;QAClC,aAAa,EAAE,GAAG,EAAE;YAClB,MAAM,QAAQ,GAAG,oBAAoB,CACnC,IAAI,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,kBAAkB,CACnB,CAAC;YACF,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YACzB,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC;KACF,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAC5E,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAEvE,MAAM,UAAU,GAAG,sBAAsB,CACvC,MAAM,EAAE,EACR,IAAI,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CACrC,CAAC;IAEF,OAAO,cAAc,CACnB,MAAM,EACN,QAAQ,EACR,CAAC,aAAa,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,IAAI,CAC1D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type HttpRequest, type HttpResponse, type ThymianFormat } from '@thymian/core';
|
|
2
|
+
import { type RuleTestExecution } from './rule-test-execution.js';
|
|
3
|
+
import type { RuleUnderTest } from './rule-under-test.js';
|
|
4
|
+
/**
|
|
5
|
+
* What a responder is asked to answer.
|
|
6
|
+
*/
|
|
7
|
+
export type RespondInput = {
|
|
8
|
+
/** The id of the transaction the request is aimed at. */
|
|
9
|
+
transaction: string;
|
|
10
|
+
/** The response that answers the transaction exactly as the format declares it. */
|
|
11
|
+
conforming: HttpResponse;
|
|
12
|
+
/** The request that was sent. */
|
|
13
|
+
request: HttpRequest;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The server under test of a rule test: decides what comes back for a request.
|
|
17
|
+
*/
|
|
18
|
+
export type Respond = (input: RespondInput) => HttpResponse | Promise<HttpResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Runs a rule in `test`: the tester's own context evaluates it, sending the
|
|
21
|
+
* requests it builds to `respond` instead of a server, and the tester's own
|
|
22
|
+
* report builder turns what it returns into executions, as for `thymian test`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function runTest(underTest: RuleUnderTest, format: ThymianFormat, respond?: Respond): Promise<RuleTestExecution[]>;
|
|
25
|
+
//# sourceMappingURL=run-test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-test.d.ts","sourceRoot":"","sources":["../src/run-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,YAAY,EAgBjB,KAAK,aAAa,EAEnB,MAAM,eAAe,CAAC;AAYvB,OAAO,EAKL,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,mFAAmF;IACnF,UAAU,EAAE,YAAY,CAAC;IACzB,iCAAiC;IACjC,OAAO,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,CACpB,KAAK,EAAE,YAAY,KAChB,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAE1C;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,OAAwC,GAChD,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAmH9B"}
|