@enspirit/opspicy 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +325 -2
- package/bin/entry.js +48 -0
- package/bin/help.js +115 -0
- package/bin/opspicy +27 -0
- package/dist/addresses.js +27 -0
- package/dist/behind.js +64 -0
- package/dist/citizens.js +71 -0
- package/dist/configuration.d.ts +56 -0
- package/dist/configuration.js +66 -0
- package/dist/explorer/afresh.js +43 -0
- package/dist/explorer/api.js +101 -0
- package/dist/explorer/asking.js +59 -0
- package/dist/explorer/build.js +11 -0
- package/dist/explorer/calls.js +42 -0
- package/dist/explorer/document.js +117 -0
- package/dist/explorer/elo-refs.js +153 -0
- package/dist/explorer/elo.js +95 -0
- package/dist/explorer/fonts/OFL.txt +93 -0
- package/dist/explorer/fonts/dm-sans-latin.woff2 +0 -0
- package/dist/explorer/html.js +104 -0
- package/dist/explorer/index.js +62 -0
- package/dist/explorer/json.js +33 -0
- package/dist/explorer/machine.js +34 -0
- package/dist/explorer/masking.js +57 -0
- package/dist/explorer/operation.js +97 -0
- package/dist/explorer/pages.js +159 -0
- package/dist/explorer/script/base.js +103 -0
- package/dist/explorer/script/call.js +161 -0
- package/dist/explorer/script/calling.js +103 -0
- package/dist/explorer/script/connection.js +83 -0
- package/dist/explorer/script/copying.js +75 -0
- package/dist/explorer/script/filter.js +56 -0
- package/dist/explorer/script/formaldef.js +37 -0
- package/dist/explorer/script/main.js +82 -0
- package/dist/explorer/script/markdown.js +143 -0
- package/dist/explorer/script/notes.js +184 -0
- package/dist/explorer/script/noting.js +38 -0
- package/dist/explorer/script/peek.js +62 -0
- package/dist/explorer/script/peeking.js +19 -0
- package/dist/explorer/script/ranking.js +91 -0
- package/dist/explorer/script/review.js +126 -0
- package/dist/explorer/script/rows.js +58 -0
- package/dist/explorer/script/run.js +168 -0
- package/dist/explorer/script/running.js +66 -0
- package/dist/explorer/script/search.js +122 -0
- package/dist/explorer/script/sending.js +64 -0
- package/dist/explorer/script/served.js +51 -0
- package/dist/explorer/serve.js +41 -0
- package/dist/explorer/server.js +143 -0
- package/dist/explorer/site.js +78 -0
- package/dist/explorer/style.css +247 -0
- package/dist/explorer/telling.js +30 -0
- package/dist/explorer/tests.js +78 -0
- package/dist/explorer/wiki.js +90 -0
- package/dist/files.js +178 -0
- package/dist/finding.js +17 -0
- package/dist/judging.js +99 -0
- package/dist/lines.js +30 -0
- package/dist/main.js +128 -0
- package/dist/meaning.js +100 -0
- package/dist/modelling.js +173 -0
- package/dist/naming.js +84 -0
- package/dist/notation.js +119 -0
- package/dist/planning.js +41 -0
- package/dist/reach.js +177 -0
- package/dist/reading.js +135 -0
- package/dist/report-file.js +42 -0
- package/dist/report.js +63 -0
- package/dist/running.js +105 -0
- package/dist/selecting.js +71 -0
- package/dist/starting.js +41 -0
- package/dist/suite.js +32 -0
- package/dist/upgrade.js +27 -0
- package/dist/upgrading.js +76 -0
- package/dist/words.js +103 -0
- package/dist/world.js +129 -0
- package/package.json +57 -4
package/dist/notation.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The small notations of a specification file, each read from a text: an entry, a Background,
|
|
2
|
+
// an answer, a way of violating a condition, the mark of a sentence, what a predicate or a
|
|
3
|
+
// function is given, the route of a state. Pure: a text that cannot be read throws what is wrong
|
|
4
|
+
// with it. The forms a citizen is written in are in citizens.ts.
|
|
5
|
+
import { Unrunnable } from './finding.js';
|
|
6
|
+
import { MARKS } from './suite.js';
|
|
7
|
+
const METHODS = ['GET', 'POST', 'PUT', 'DELETE'];
|
|
8
|
+
/** `POST /api/boards/:id` */
|
|
9
|
+
export function entryOf(text) {
|
|
10
|
+
const [, method, path] = String(text ?? '').match(/^\s*([A-Z]+)\s+(\/\S*)\s*$/) ?? [];
|
|
11
|
+
if (!method || !path || !METHODS.includes(method))
|
|
12
|
+
throw new Error(`entry: expected a method and a path, as in "POST /api/boards", got ${told(text)}`);
|
|
13
|
+
return { method: method, path };
|
|
14
|
+
}
|
|
15
|
+
/** `test/base, as member` */
|
|
16
|
+
export function givenOf(text) {
|
|
17
|
+
const [, seed, actor] = String(text ?? '').match(/^\s*([\w/-]+)\s*,\s*as\s+(\w+)\s*$/) ?? [];
|
|
18
|
+
if (!seed || !actor)
|
|
19
|
+
throw new Error(`given: expected a seed and who calls, as in "test/base, as member", got ${told(text)}`);
|
|
20
|
+
return { seed, actor };
|
|
21
|
+
}
|
|
22
|
+
/** `201`, or `400 boards.nameRequired` */
|
|
23
|
+
export function thenOf(text) {
|
|
24
|
+
const [, status, code] = String(text ?? '').match(/^\s*(\d{3})(?:\s+([\w.-]+))?\s*$/) ?? [];
|
|
25
|
+
if (!status)
|
|
26
|
+
throw new Error(`then: expected a status, and the code of a refusal, as in "400 boards.nameRequired", got ${told(text)}`);
|
|
27
|
+
return code ? { status: Number(status), code } : { status: Number(status) };
|
|
28
|
+
}
|
|
29
|
+
/** Whether an answer is a refusal, as a specification says one: a status of 400 or more, and the code it is refused with. */
|
|
30
|
+
export const refuses = (then) => then.status >= 400 && Boolean(then.code);
|
|
31
|
+
/** What a counterexample, or a condition that is violated, says instead of a refusal. */
|
|
32
|
+
export const NO_REFUSAL = 'what is answered is a refusal: a status of 400 or more, and its code, as in "400 boards.nameRequired"';
|
|
33
|
+
/** `as visitor -> 401 auth.signedOut` */
|
|
34
|
+
export function violatedOf(text) {
|
|
35
|
+
const [, actor, then] = String(text ?? '').match(/^\s*as\s+(\w+)\s*->\s*(.+)$/) ?? [];
|
|
36
|
+
if (!actor || !then)
|
|
37
|
+
throw new Error(`violated: expected who calls and what is answered, as in "as visitor -> 401 auth.signedOut", got ${told(text)}`);
|
|
38
|
+
return { actor, then: thenOf(then) };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A sentence may say whether it is checked: `(x) the requester is signed in` is one a formaldef
|
|
42
|
+
* decides, `( ) the origin is not locked out` one that is told and that nothing decides, and
|
|
43
|
+
* `(+) only the hash of the token is kept` one a formaldef decides in the complete run only.
|
|
44
|
+
*/
|
|
45
|
+
export function marked(sentence) {
|
|
46
|
+
const [, mark, said] = sentence.match(/^\s*\((x|\+| )\)\s+(.*)$/s) ?? [];
|
|
47
|
+
if (mark !== undefined && said)
|
|
48
|
+
return { description: said.trim(), mark: MARKS[mark] };
|
|
49
|
+
if (MARKLIKE.test(sentence))
|
|
50
|
+
throw new Error(`"${sentence.trim()}": a sentence is marked (x), (+) or ( ), then a space`);
|
|
51
|
+
return { description: sentence.trim() };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What looks like a mark and is none: `(X)`, `[x]`, `()`, or a mark with no space after it. Read
|
|
55
|
+
* as the start of the sentence, it would make another sentence of it, one no condition decides,
|
|
56
|
+
* and what was to be checked would be told.
|
|
57
|
+
*/
|
|
58
|
+
const MARKLIKE = /^\s*[([][^)\]]?[)\]]/;
|
|
59
|
+
/** What a predicate or a function is called, and what it is given: `board(id)`, or `signedIn` with nothing. */
|
|
60
|
+
export function signatureOf(text) {
|
|
61
|
+
const [, name, parameters] = String(text ?? '').match(/^\s*([a-z]\w*)\s*(?:\(([\w\s,]*)\))?\s*$/) ?? [];
|
|
62
|
+
if (!name)
|
|
63
|
+
throw new Error(`expected a name, and what it is given, as in "board(id)", got ${told(text)}`);
|
|
64
|
+
return { name, parameters: (parameters ?? '').split(',').map((parameter) => parameter.trim()).filter(Boolean) };
|
|
65
|
+
}
|
|
66
|
+
/** `GET /api/boards -> Boards`: state is observed by reading, and by nothing else; the type of what is told may follow. */
|
|
67
|
+
export function observedOf(text) {
|
|
68
|
+
const [, way, type] = String(text ?? '').match(/^\s*(GET\s+\/\S*?)(?:\s*->\s*([A-Z]\w*))?\s*$/) ?? [];
|
|
69
|
+
const path = way ? entryOf(way).path : '';
|
|
70
|
+
if (!path || placeholders(path).length)
|
|
71
|
+
throw new Error(`observed by a GET route with nothing to fill in, then "-> Type" for the type of what it tells if any, got ${told(text)}`);
|
|
72
|
+
return type ? { path, type } : { path };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The lines where a case starts right under the one before: a file is read by people, and an
|
|
76
|
+
* empty line sets each case apart. A comment above a case is its own, and the first case of a
|
|
77
|
+
* list stands right under `examples:`.
|
|
78
|
+
*/
|
|
79
|
+
export function crowded(text) {
|
|
80
|
+
const lines = text.split('\n');
|
|
81
|
+
const starts = lines.flatMap((line, at) => (/^\s*- when:/.test(line) ? [at] : []));
|
|
82
|
+
return starts.filter((at) => {
|
|
83
|
+
let above = at - 1;
|
|
84
|
+
while (above >= 0 && /^\s*#/.test(lines[above] ?? ''))
|
|
85
|
+
above--;
|
|
86
|
+
const before = lines[above] ?? '';
|
|
87
|
+
return before.trim() !== '' && !/^(examples|counterexamples):/.test(before);
|
|
88
|
+
}).map((at) => at + 1);
|
|
89
|
+
}
|
|
90
|
+
/** The parts of a path the input gives: `/api/boards/:id` names `id`. */
|
|
91
|
+
export const placeholders = (path) => [...path.matchAll(/:(\w+)/g)].map((match) => match[1] ?? '');
|
|
92
|
+
/** Data that has names: what a route takes its parts from, and what a query is made of. A list or a text has none. */
|
|
93
|
+
const isRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
94
|
+
/** A part that is no name: left as it is when the route is encoded, and followed when it is called, `/api/nothing/../boards` is `/api/boards`. */
|
|
95
|
+
const LEADS_ELSEWHERE = ['.', '..'];
|
|
96
|
+
/**
|
|
97
|
+
* The path with its parts filled from the input, and what is left of the input to send. An input
|
|
98
|
+
* that is no record (a list, a text, a number) fills no part and is left whole. A part is one the
|
|
99
|
+
* input itself gives: `:constructor` is not found in what every record is made from.
|
|
100
|
+
*/
|
|
101
|
+
export function addressed(path, input) {
|
|
102
|
+
const given = isRecord(input) ? { ...input } : {};
|
|
103
|
+
const filled = path.replace(/:(\w+)/g, (_all, name) => {
|
|
104
|
+
if (!Object.hasOwn(given, name) || given[name] === undefined || given[name] === null)
|
|
105
|
+
throw new Unrunnable(`the input gives no "${name}" for ${path}`);
|
|
106
|
+
const part = String(given[name]);
|
|
107
|
+
if (LEADS_ELSEWHERE.includes(part))
|
|
108
|
+
throw new Unrunnable(`the input gives "${part}" as "${name}" for ${path}: it would lead to another route`);
|
|
109
|
+
delete given[name];
|
|
110
|
+
return encodeURIComponent(part);
|
|
111
|
+
});
|
|
112
|
+
return { path: filled, rest: isRecord(input) ? given : input ?? null };
|
|
113
|
+
}
|
|
114
|
+
/** What is left of the input as a query, for a route that is only read: its names, and nothing of an input that has none. */
|
|
115
|
+
export function queryOf(rest) {
|
|
116
|
+
const pairs = Object.entries(isRecord(rest) ? rest : {}).filter(([, value]) => value !== undefined && value !== null);
|
|
117
|
+
return pairs.length ? `?${pairs.map(([name, value]) => `${encodeURIComponent(name)}=${encodeURIComponent(String(value))}`).join('&')}` : '';
|
|
118
|
+
}
|
|
119
|
+
const told = (value) => (value === undefined ? 'nothing' : JSON.stringify(value));
|
package/dist/planning.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// What is run for an operation, and what its specification leaves unsaid. Pure.
|
|
2
|
+
import { witnessesNamed } from './naming.js';
|
|
3
|
+
import { isPre, sameSentence } from './suite.js';
|
|
4
|
+
/** The counterexample a condition gives an operation that says it: its first example, called by who violates it. */
|
|
5
|
+
function generated(operation, clause, model) {
|
|
6
|
+
const condition = model.conditions.find((known) => sameSentence(known.description, clause.description));
|
|
7
|
+
const example = operation.cases.find((kase) => kase.kind === 'example');
|
|
8
|
+
if (clause.from !== 'shared' || !condition?.violated || !example || example.given.actor === condition.violated.actor)
|
|
9
|
+
return [];
|
|
10
|
+
const { actor, then } = condition.violated;
|
|
11
|
+
return [{ kind: 'counterexample', name: `${clause.name}/violated`, ...(condition.source ? { source: condition.source } : {}), description: `called as ${actor}`, for: clause.description, given: { seed: example.given.seed, actor }, input: example.input, then, and: [], generated: true }];
|
|
12
|
+
}
|
|
13
|
+
/** The cases of an operation: those it writes, then those its conditions give it. */
|
|
14
|
+
export const casesOf = (operation, model) => [...operation.cases, ...operation.clauses.filter(isPre).flatMap((clause) => generated(operation, clause, model))];
|
|
15
|
+
/** An operation as the fast run checks it: what is checked in the complete run only is told, as if it had no formaldef. */
|
|
16
|
+
export function mustOnly(operation) {
|
|
17
|
+
const told = (clause) => (clause.mark === 'complete' ? { ...clause, formaldef: undefined } : clause);
|
|
18
|
+
return { ...operation, clauses: operation.clauses.map(told), cases: operation.cases.map((kase) => ({ ...kase, and: kase.and.map(told) })) };
|
|
19
|
+
}
|
|
20
|
+
/** Who else must be signed in for a case: those through whose eyes a formaldef looks, `seenBy.admin.boards`. */
|
|
21
|
+
export function witnessesOf(operation, kase) {
|
|
22
|
+
const sources = [...operation.clauses, ...kase.and].map((clause) => clause.formaldef ?? '').concat(typeof kase.input === 'string' ? kase.input : '');
|
|
23
|
+
return [...new Set(sources.flatMap(witnessesNamed))];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What a reader should know is missing: what the operation is, a rule nothing violates, an
|
|
27
|
+
* operation nothing shows. An operation says the transition it makes, every rule aside: its DomPre
|
|
28
|
+
* and its DomPost. An observation makes none, and says none. A DomPre is the state the transition
|
|
29
|
+
* starts from, which a counterexample may show refused and need not: of an operation that makes
|
|
30
|
+
* something, nothing names what is not made yet.
|
|
31
|
+
*/
|
|
32
|
+
export function gapsOf(operation, cases) {
|
|
33
|
+
const violated = (clause) => cases.some((kase) => kase.kind === 'counterexample' && sameSentence(kase.for ?? '', clause.description));
|
|
34
|
+
const says = (kind) => operation.clauses.some((clause) => clause.kind === kind);
|
|
35
|
+
return [
|
|
36
|
+
...(operation.observes || says('DomPre') ? [] : ['no DomPre says the state it starts from']),
|
|
37
|
+
...(operation.observes || says('DomPost') ? [] : ['no DomPost says the state it makes']),
|
|
38
|
+
...(cases.some((kase) => kase.kind === 'example') ? [] : ['no example shows it succeed']),
|
|
39
|
+
...operation.clauses.filter((clause) => clause.kind === 'ReqPre' && !violated(clause)).map((clause) => `no counterexample violates "${clause.description}"`),
|
|
40
|
+
];
|
|
41
|
+
}
|
package/dist/reach.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// What an operation monitors and controls, in the terms of KAOS: the states it must read to meet
|
|
2
|
+
// its clauses, and those it may change. An operation says them, `monitors` and `controls`, or they
|
|
3
|
+
// are derived from its formaldefs (doc/derived.md). Pure: Elo's parser reads each expression, and
|
|
4
|
+
// nothing is run.
|
|
5
|
+
//
|
|
6
|
+
// A state is read at a moment: before the call, in a precondition, after `old.` in a postcondition,
|
|
7
|
+
// in the input of a case; after the call, bare in a postcondition. What a predicate or a function
|
|
8
|
+
// reads, it reads at the moment of the expression that names it. `seenBy.<actor>.` reads the same
|
|
9
|
+
// state through other eyes, and `_.before.` and `_.after.` at that moment; `db` is no state.
|
|
10
|
+
import { parse } from '@enspirit/elo';
|
|
11
|
+
import { RESERVED } from './naming.js';
|
|
12
|
+
import { isPre } from './suite.js';
|
|
13
|
+
const bind = (scope, names) => new Set([...scope, ...names]);
|
|
14
|
+
const FREE = new Set([...RESERVED, '_']);
|
|
15
|
+
function treeOf(text) {
|
|
16
|
+
try {
|
|
17
|
+
return parse(text);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// What Elo cannot read is told where the suite is read: here, it reads nothing.
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** The states an expression reads, said at a moment: before the call (a precondition, an input), or after it (a postcondition, which reads before through `old`). */
|
|
25
|
+
export function statesRead(text, at, readable) {
|
|
26
|
+
const read = { before: new Set(), after: new Set(), whole: false };
|
|
27
|
+
const states = new Set(readable.state.map((one) => one.name));
|
|
28
|
+
const words = new Map(readable.definitions.map((one) => [one.name, one.formaldef]));
|
|
29
|
+
const followed = new Set();
|
|
30
|
+
/** A name of the suite, read at a moment: a state is read; a word reads what its formaldef reads, at that moment, once. */
|
|
31
|
+
const named = (name, when) => {
|
|
32
|
+
if (states.has(name))
|
|
33
|
+
read[when].add(name);
|
|
34
|
+
const formaldef = words.get(name);
|
|
35
|
+
if (formaldef === undefined || followed.has(`${when} ${name}`))
|
|
36
|
+
return;
|
|
37
|
+
followed.add(`${when} ${name}`);
|
|
38
|
+
const tree = treeOf(formaldef);
|
|
39
|
+
if (tree)
|
|
40
|
+
walk(tree, new Set(), when);
|
|
41
|
+
};
|
|
42
|
+
/** What a chain of members leads to: a name of the suite after `old.`, `seenBy.<actor>.` or `old.seenBy.<actor>.`, and the moment it is read at. */
|
|
43
|
+
const reached = (node, scope, when) => {
|
|
44
|
+
if (node.type !== 'member_access')
|
|
45
|
+
return null;
|
|
46
|
+
const { object, property } = node;
|
|
47
|
+
if (object.type === 'variable' && object.name === 'old' && !scope.has('old'))
|
|
48
|
+
return { name: property, when: 'before' };
|
|
49
|
+
// What was observed, whole: `_.before.<state>` and `_.after.<state>`.
|
|
50
|
+
if (object.type === 'member_access' && object.object.type === 'variable' && object.object.name === '_' && !scope.has('_') && (object.property === 'before' || object.property === 'after'))
|
|
51
|
+
return { name: property, when: object.property };
|
|
52
|
+
const seen = object.type === 'member_access' ? object.object : null;
|
|
53
|
+
if (seen?.type === 'variable' && seen.name === 'seenBy' && !scope.has('seenBy'))
|
|
54
|
+
return { name: property, when };
|
|
55
|
+
const old = seen?.type === 'member_access' && seen.property === 'seenBy' ? seen.object : null;
|
|
56
|
+
if (old?.type === 'variable' && old.name === 'old' && !scope.has('old'))
|
|
57
|
+
return { name: property, when: 'before' };
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
const walk = (node, scope, when) => {
|
|
61
|
+
switch (node.type) {
|
|
62
|
+
case 'variable':
|
|
63
|
+
if (!scope.has(node.name) && (node.name === 'nothingChanged' || node.name === '_'))
|
|
64
|
+
read.whole = true;
|
|
65
|
+
if (!scope.has(node.name) && !FREE.has(node.name))
|
|
66
|
+
named(node.name, when);
|
|
67
|
+
return;
|
|
68
|
+
case 'function_call':
|
|
69
|
+
if (!scope.has(node.name))
|
|
70
|
+
named(node.name, when);
|
|
71
|
+
for (const one of node.args)
|
|
72
|
+
walk(one, scope, when);
|
|
73
|
+
return;
|
|
74
|
+
case 'member_access': {
|
|
75
|
+
const to = reached(node, scope, when);
|
|
76
|
+
if (to)
|
|
77
|
+
return named(to.name, to.when);
|
|
78
|
+
return walk(node.object, scope, when);
|
|
79
|
+
}
|
|
80
|
+
case 'apply': {
|
|
81
|
+
const to = reached(node.fn, scope, when);
|
|
82
|
+
if (to)
|
|
83
|
+
named(to.name, to.when);
|
|
84
|
+
else
|
|
85
|
+
walk(node.fn, scope, when);
|
|
86
|
+
for (const one of node.args)
|
|
87
|
+
walk(one, scope, when);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
case 'lambda':
|
|
91
|
+
return walk(node.body, bind(scope, node.params), when);
|
|
92
|
+
case 'let': {
|
|
93
|
+
let inner = scope;
|
|
94
|
+
for (const one of node.bindings) {
|
|
95
|
+
walk(one.value, inner, when);
|
|
96
|
+
inner = bind(inner, [one.name]);
|
|
97
|
+
}
|
|
98
|
+
return walk(node.body, inner, when);
|
|
99
|
+
}
|
|
100
|
+
case 'typedef':
|
|
101
|
+
return walk(node.body, bind(scope, node.definitions.map((one) => one.name)), when);
|
|
102
|
+
default:
|
|
103
|
+
for (const child of childrenOf(node))
|
|
104
|
+
walk(child, scope, when);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const tree = treeOf(text);
|
|
108
|
+
if (tree)
|
|
109
|
+
walk(tree, new Set(), at);
|
|
110
|
+
return read;
|
|
111
|
+
}
|
|
112
|
+
function childrenOf(node) {
|
|
113
|
+
switch (node.type) {
|
|
114
|
+
case 'binary': return [node.left, node.right];
|
|
115
|
+
case 'unary': return [node.operand];
|
|
116
|
+
case 'if': return [node.condition, node.then, node.else];
|
|
117
|
+
case 'object': return node.properties.map((one) => one.value);
|
|
118
|
+
case 'array': return node.elements;
|
|
119
|
+
case 'alternative': return node.alternatives;
|
|
120
|
+
case 'guard': return [...node.constraints.map((one) => one.condition), node.body];
|
|
121
|
+
default: return [];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The states a case of an operation observes in the fast run: those it monitors and controls,
|
|
126
|
+
* which hold every state its formaldefs read; every state when one reads what was observed whole.
|
|
127
|
+
* Nothing narrows what the complete run observes.
|
|
128
|
+
*/
|
|
129
|
+
export const observedIn = (reach, all) => (reach.whole ? all : all.filter((name) => reach.monitors.includes(name) || reach.controls.includes(name)));
|
|
130
|
+
const ordered = (all, readable) => readable.state.map((one) => one.name).filter((name) => all.has(name));
|
|
131
|
+
/**
|
|
132
|
+
* What an operation reads, from its formaldefs: what each precondition reads, before the call;
|
|
133
|
+
* what each postcondition, and what an example alone also shows, reads before and after it; what
|
|
134
|
+
* the input of a case reads, before it.
|
|
135
|
+
*/
|
|
136
|
+
export function readBy(operation, readable) {
|
|
137
|
+
const all = { before: new Set(), after: new Set(), whole: false };
|
|
138
|
+
const add = (read) => {
|
|
139
|
+
for (const name of read.before)
|
|
140
|
+
all.before.add(name);
|
|
141
|
+
for (const name of read.after)
|
|
142
|
+
all.after.add(name);
|
|
143
|
+
all.whole ||= Boolean(read.whole);
|
|
144
|
+
};
|
|
145
|
+
for (const clause of [...operation.clauses, ...operation.cases.flatMap((kase) => kase.and)])
|
|
146
|
+
if (clause.formaldef)
|
|
147
|
+
add(statesRead(clause.formaldef, isPre(clause) ? 'before' : 'after', readable));
|
|
148
|
+
for (const kase of operation.cases)
|
|
149
|
+
if (typeof kase.input === 'string')
|
|
150
|
+
add(statesRead(kase.input, 'before', readable));
|
|
151
|
+
return all;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Its reach, said or derived. Derived, it controls what a postcondition reads after the call (an
|
|
155
|
+
* observation, nothing): what it may change, since a postcondition that reads a state after the call
|
|
156
|
+
* may as well say it is unchanged. It monitors what it reads before the call, and what it reads
|
|
157
|
+
* after it and does not control.
|
|
158
|
+
*/
|
|
159
|
+
export function reachOf(operation, readable, said = {}) {
|
|
160
|
+
const read = readBy(operation, readable);
|
|
161
|
+
const controls = said.controls ?? (operation.observes ? [] : ordered(read.after, readable));
|
|
162
|
+
const monitors = said.monitors ?? ordered(new Set([...read.before, ...[...read.after].filter((name) => !controls.includes(name))]), readable);
|
|
163
|
+
return { monitors, controls, said: { monitors: said.monitors !== undefined, controls: said.controls !== undefined }, ...(read.whole ? { whole: true } : {}) };
|
|
164
|
+
}
|
|
165
|
+
/** What an operation says of its reach that cannot be: a state that is none, an observation that controls, a state it reads and says it neither monitors nor controls. */
|
|
166
|
+
export function reachProblems(operation, readable, reach) {
|
|
167
|
+
const states = readable.state.map((one) => one.name);
|
|
168
|
+
const named = [...(reach.said.monitors ? reach.monitors : []), ...(reach.said.controls ? reach.controls : [])];
|
|
169
|
+
const problems = [...new Set(named.filter((name) => !states.includes(name)))].map((name) => `"${name}" is not a state of state.yml: an operation monitors and controls states`);
|
|
170
|
+
if (operation.observes && reach.controls.length)
|
|
171
|
+
problems.push('an observation changes nothing: it controls no state');
|
|
172
|
+
if (!reach.said.monitors)
|
|
173
|
+
return problems;
|
|
174
|
+
const read = readBy(operation, readable);
|
|
175
|
+
const unreached = ordered(new Set([...read.before, ...read.after]), readable).filter((name) => !reach.monitors.includes(name) && !reach.controls.includes(name));
|
|
176
|
+
return [...problems, ...unreached.map((name) => `it reads "${name}", which it says it neither monitors nor controls`)];
|
|
177
|
+
}
|
package/dist/reading.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// A specification file as it was written (YAML, already parsed) becomes an operation, with its
|
|
2
|
+
// clauses and its cases. Pure: what cannot be read is told as a problem, and never guessed. What
|
|
3
|
+
// the suite says apart from its operations is read in modelling.ts.
|
|
4
|
+
import { a, listOf, record, sentenceOf, text } from './citizens.js';
|
|
5
|
+
import { placeOf } from './lines.js';
|
|
6
|
+
import { readsDatabase } from './behind.js';
|
|
7
|
+
import { reachOf, reachProblems } from './reach.js';
|
|
8
|
+
import { NO_REFUSAL, entryOf, givenOf, marked, placeholders, refuses, thenOf } from './notation.js';
|
|
9
|
+
import { SAID, TRIGGER, isA, isForType, isPre, named, sameSentence } from './suite.js';
|
|
10
|
+
const OPERATION_KEYS = ['name', 'description', 'agent', 'entry', 'input', 'output', 'monitors', 'controls', ...SAID, 'examples', 'counterexamples'];
|
|
11
|
+
const CASE_KEYS = ['name', 'when', 'for', 'given', 'input', 'then', 'and'];
|
|
12
|
+
const MARKED = { checked: 'x', complete: '+', told: ' ' };
|
|
13
|
+
/** What a reader gives, or the fallback with the reason told. */
|
|
14
|
+
function attempt(problems, read, fallback) {
|
|
15
|
+
try {
|
|
16
|
+
return read();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
problems.push(error instanceof Error ? error.message : String(error));
|
|
20
|
+
return fallback;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function unknownKeys(raw, known, where, problems) {
|
|
24
|
+
for (const key of Object.keys(raw))
|
|
25
|
+
if (!known.includes(key))
|
|
26
|
+
problems.push(`${where}: "${key}" is not something a specification says (${known.join(', ')})`);
|
|
27
|
+
}
|
|
28
|
+
/** What a mark says wrong of its sentence. A long form says none: what it is, is what the sentence is. */
|
|
29
|
+
function mismarked(kind, says, mark, long, has) {
|
|
30
|
+
const found = [];
|
|
31
|
+
if (has.behind && mark !== 'complete' && !long)
|
|
32
|
+
found.push(`${kind} "${says}" reads the database, behind the front door: it is checked in the complete run only, and says so with (+)`);
|
|
33
|
+
if (mark && mark !== 'told' && !has.own && !has.shared)
|
|
34
|
+
found.push(`${kind} "${says}" is marked (${MARKED[mark]}), and nothing gives it a formaldef: neither here nor a condition`);
|
|
35
|
+
if (mark === 'told' && (has.own || has.shared))
|
|
36
|
+
found.push(`${kind} "${says}" is marked ( ), and ${has.own ? 'has a formaldef here' : 'a condition gives it a formaldef'}: it is checked`);
|
|
37
|
+
return found;
|
|
38
|
+
}
|
|
39
|
+
/** A clause with its formaldef: its own, or the one a condition gives the same sentence. Named after where it stands, unless it names itself. */
|
|
40
|
+
function meant(kind, item, where, { conditions, definitions }, problems, source) {
|
|
41
|
+
const said = attempt(problems, () => sentenceOf(kind, item), null);
|
|
42
|
+
if (!said)
|
|
43
|
+
return null;
|
|
44
|
+
const { description, long } = said;
|
|
45
|
+
const shared = conditions.find((condition) => sameSentence(condition.description, description));
|
|
46
|
+
const formaldef = said.formaldef ?? shared?.formaldef;
|
|
47
|
+
const behind = attempt([], () => readsDatabase(formaldef ?? '', definitions), false);
|
|
48
|
+
if (kind === TRIGGER && formaldef)
|
|
49
|
+
problems.push(`${kind} "${description}" is told, and has no formaldef: one call shows nothing of what triggers an operation`);
|
|
50
|
+
if (shared && said.formaldef)
|
|
51
|
+
problems.push(`${kind} "${description}" has a formaldef here and another as a condition: keep one`);
|
|
52
|
+
problems.push(...mismarked(kind, description, said.mark, long, { own: Boolean(said.formaldef), shared: Boolean(shared), behind }));
|
|
53
|
+
const mark = long ? (!formaldef ? 'told' : behind ? 'complete' : 'checked') : said.mark;
|
|
54
|
+
return { kind, name: said.name ?? where, source, description, ...(formaldef ? { formaldef } : {}), from: said.formaldef ? 'here' : shared ? 'shared' : 'nowhere', mark };
|
|
55
|
+
}
|
|
56
|
+
const clausesOf = (raw, name, model, problems, place) => SAID.flatMap((kind) => listOf(`"${kind}"`, raw[kind], problems).map((item, at) => meant(kind, item, `${name}/${kind}/${at + 1}`, model, problems, place(kind, at)))).filter((clause) => clause !== null);
|
|
57
|
+
/** The precondition a counterexample is for, in the operation's words: with its mark or without. */
|
|
58
|
+
const forOf = (written, problems) => attempt(problems, () => marked(text(written)).description, text(written));
|
|
59
|
+
function caseOf(kind, item, where, model, problems, place) {
|
|
60
|
+
const raw = record(item);
|
|
61
|
+
const when = text(raw.when) || '(a case that does not say when)';
|
|
62
|
+
const mine = [];
|
|
63
|
+
unknownKeys(raw, CASE_KEYS, 'a case', mine);
|
|
64
|
+
if (!text(raw.when))
|
|
65
|
+
mine.push('a case says "when"');
|
|
66
|
+
const given = attempt(mine, () => givenOf(raw.given), { seed: '', actor: '' });
|
|
67
|
+
const then = attempt(mine, () => thenOf(raw.then), { status: 0 });
|
|
68
|
+
const and = listOf('"and"', raw.and, mine).map((more, at) => meant('and', more, `${where}/and/${at + 1}`, model, mine, place('and', at))).filter((clause) => clause !== null);
|
|
69
|
+
const violated = forOf(raw.for, mine);
|
|
70
|
+
problems.push(...mine.map((problem) => `${kind} "${when}": ${problem}`));
|
|
71
|
+
return { kind, name: text(raw.name) || where, source: place(), description: when, for: violated || undefined, given, input: raw.input ?? null, then, and, generated: false };
|
|
72
|
+
}
|
|
73
|
+
/** What a case says that its operation or the world does not bear out. */
|
|
74
|
+
function caseProblems(kase, operation, model) {
|
|
75
|
+
const found = [];
|
|
76
|
+
const actor = named(model.actors, kase.given.actor);
|
|
77
|
+
if (kase.given.actor && !actor)
|
|
78
|
+
found.push(`nobody is called "${kase.given.actor}" in the world`);
|
|
79
|
+
if (kase.given.seed && !named(model.backgrounds, kase.given.seed))
|
|
80
|
+
found.push(`"${kase.given.seed}" is not a Background of backgrounds.yml`);
|
|
81
|
+
if (kase.kind === 'example' && actor && named(model.agents, operation.agent) && !isA(model.agents, actor.is, operation.agent))
|
|
82
|
+
found.push(`it is called by "${actor.name}", who is ${a(actor.is)}: the operation is performed by ${a(operation.agent)}`);
|
|
83
|
+
if (kase.kind === 'example' && kase.for)
|
|
84
|
+
found.push('only a counterexample is "for" a precondition');
|
|
85
|
+
if (kase.kind === 'counterexample' && !kase.for)
|
|
86
|
+
found.push('a counterexample says which precondition it is "for"');
|
|
87
|
+
if (kase.kind === 'counterexample' && kase.for && !isForType(operation, kase) && !operation.clauses.some((clause) => isPre(clause) && sameSentence(clause.description, kase.for ?? '')))
|
|
88
|
+
found.push(`it is for "${kase.for}", which is not a precondition of the operation${operation.input ? `, nor the type of its input, ${operation.input}` : ''}`);
|
|
89
|
+
// A status of 0 is a `then` that could not be read, which is told already.
|
|
90
|
+
if (kase.kind === 'counterexample' && kase.then.status && !refuses(kase.then))
|
|
91
|
+
found.push(`"then": ${NO_REFUSAL}`);
|
|
92
|
+
if (kase.kind === 'counterexample' && kase.and.length)
|
|
93
|
+
found.push('a refusal changes nothing: there is no "and" to a counterexample');
|
|
94
|
+
return found.map((problem) => `${kase.kind} "${kase.description}": ${problem}`);
|
|
95
|
+
}
|
|
96
|
+
/** Two cases of a kind that say the same `when`: a case is known by what it says. */
|
|
97
|
+
const twice = (cases) => cases.filter((kase, at) => cases.findIndex((other) => other.kind === kase.kind && sameSentence(other.description, kase.description)) !== at).map((kase) => `${kase.kind} "${kase.description}": another ${kase.kind} says the same "when"`);
|
|
98
|
+
/** What an operation says of itself that the suite does not bear out. */
|
|
99
|
+
function headProblems(raw, { agents }) {
|
|
100
|
+
const found = ['name', 'description', 'agent', 'entry'].filter((key) => !text(raw[key])).map((key) => `the operation says its "${key}"`);
|
|
101
|
+
if (text(raw.agent) && !named(agents, text(raw.agent)))
|
|
102
|
+
found.push(`"${text(raw.agent)}" is not an agent of agents.yml`);
|
|
103
|
+
return found;
|
|
104
|
+
}
|
|
105
|
+
/** A list of states an operation says it monitors, or controls: what it says, when it says one. */
|
|
106
|
+
function statesSaid(raw, key, problems) {
|
|
107
|
+
if (raw[key] === undefined || raw[key] === null)
|
|
108
|
+
return {};
|
|
109
|
+
const said = raw[key];
|
|
110
|
+
if (!Array.isArray(said) || said.some((one) => typeof one !== 'string' || !one.trim())) {
|
|
111
|
+
problems.push(`"${key}" says a list of states, by their names, got ${JSON.stringify(said)}`);
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
return { [key]: said.map((one) => one.trim()) };
|
|
115
|
+
}
|
|
116
|
+
/** An operation, from its file; an observation when it is filed as one. */
|
|
117
|
+
export function operationOf(file, written, model, observes = false, lines) {
|
|
118
|
+
const raw = record(written);
|
|
119
|
+
const problems = [];
|
|
120
|
+
const name = text(raw.name) || file;
|
|
121
|
+
unknownKeys(raw, OPERATION_KEYS, 'the operation', problems);
|
|
122
|
+
problems.push(...headProblems(raw, model));
|
|
123
|
+
const entry = attempt(problems, () => entryOf(raw.entry), { method: 'GET', path: '/' });
|
|
124
|
+
const place = placeOf(file, lines);
|
|
125
|
+
const clauses = clausesOf(raw, name, model, problems, place);
|
|
126
|
+
const cases = ['example', 'counterexample'].flatMap((kind) => listOf(`"${kind}s"`, raw[`${kind}s`], problems).map((item, at) => caseOf(kind, item, `${name}/${kind}s/${at + 1}`, model, problems, (...path) => place(`${kind}s`, at, ...path))));
|
|
127
|
+
problems.push(...cases.flatMap((kase) => caseProblems(kase, { agent: text(raw.agent), clauses, input: text(raw.input) || undefined }, model)), ...twice(cases));
|
|
128
|
+
if (placeholders(entry.path).length && !text(raw.input))
|
|
129
|
+
problems.push(`the entry takes ${placeholders(entry.path).join(', ')} from the input: the operation says its "input"`);
|
|
130
|
+
const said = { ...statesSaid(raw, 'monitors', problems), ...statesSaid(raw, 'controls', problems) };
|
|
131
|
+
const reach = reachOf({ observes, clauses, cases }, model, said);
|
|
132
|
+
problems.push(...reachProblems({ observes, clauses, cases }, model, reach));
|
|
133
|
+
const operation = { file, source: place('name'), area: file.split(/[\\/]/)[0] ?? '', name, description: text(raw.description), agent: text(raw.agent), observes, entry, input: text(raw.input) || undefined, output: text(raw.output) || undefined, clauses, cases, reach };
|
|
134
|
+
return { operation, problems: problems.map((problem) => `${file}: ${problem}`) };
|
|
135
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const FORMAT = 'opspicy-report/1';
|
|
2
|
+
/** What the run did, as a report. */
|
|
3
|
+
export function reportOf(ran, facts) {
|
|
4
|
+
return {
|
|
5
|
+
format: FORMAT,
|
|
6
|
+
...facts,
|
|
7
|
+
operations: ran.map(({ operation, outcomes, gaps }) => ({
|
|
8
|
+
file: operation.file,
|
|
9
|
+
name: operation.name,
|
|
10
|
+
cases: outcomes.map(({ kase, kept: findings, ms }) => ({
|
|
11
|
+
kind: kase.kind,
|
|
12
|
+
when: kase.description,
|
|
13
|
+
...(kase.for ? { for: kase.for } : {}),
|
|
14
|
+
generated: kase.generated,
|
|
15
|
+
findings,
|
|
16
|
+
ms,
|
|
17
|
+
})),
|
|
18
|
+
gaps,
|
|
19
|
+
})),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const isRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
23
|
+
const isText = (value) => typeof value === 'string';
|
|
24
|
+
const areTexts = (value) => Array.isArray(value) && value.every(isText);
|
|
25
|
+
const isCase = (one) => isRecord(one) && (one.kind === 'example' || one.kind === 'counterexample') && isText(one.when) && (one.for === undefined || isText(one.for)) && typeof one.generated === 'boolean' && areTexts(one.findings) && typeof one.ms === 'number';
|
|
26
|
+
/** The gaps may be absent: a report written before they were kept says none. */
|
|
27
|
+
const isOperation = (one) => isRecord(one) && isText(one.file) && isText(one.name) && Array.isArray(one.cases) && one.cases.every(isCase) && (one.gaps === undefined || areTexts(one.gaps));
|
|
28
|
+
const isReport = (value) => isRecord(value) && value.format === FORMAT && isText(value.when) && areTexts(value.narrowed) && typeof value.fast === 'boolean' && typeof value.stopped === 'boolean' && Array.isArray(value.operations) && value.operations.every(isOperation);
|
|
29
|
+
/**
|
|
30
|
+
* A report as it was written, or nothing when the text is not one. Read, never trusted: it is a
|
|
31
|
+
* file somebody else may have written, and one that lacks a field or has one of another shape is
|
|
32
|
+
* not a report, rather than one that fails whoever reads it further on.
|
|
33
|
+
*/
|
|
34
|
+
export function parseReport(text) {
|
|
35
|
+
try {
|
|
36
|
+
const value = JSON.parse(text);
|
|
37
|
+
return isReport(value) ? { ...value, operations: value.operations.map((one) => ({ ...one, gaps: one.gaps ?? [] })) } : null;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isForType } from './suite.js';
|
|
2
|
+
const color = (code, text) => (process.stdout.isTTY ? `\u001b[${code}m${text}\u001b[0m` : text);
|
|
3
|
+
const green = (text) => color(32, text);
|
|
4
|
+
const red = (text) => color(31, text);
|
|
5
|
+
const dim = (text) => color(2, text);
|
|
6
|
+
const unchecked = (clause) => (clause.mark === 'complete' ? ' (checked in the complete run only)' : ' (told, not checked)');
|
|
7
|
+
const clauseLine = (clause) => ` ${clause.kind.padEnd(7)} ${clause.formaldef ? green('✓') : dim('·')} ${clause.description}${clause.formaldef ? '' : dim(unchecked(clause))}`;
|
|
8
|
+
/** A case that takes a second or more says so: it waited for something. */
|
|
9
|
+
const slow = (ms) => (ms >= 1000 ? dim(` ${(ms / 1000).toFixed(1)} s`) : '');
|
|
10
|
+
const took = (ms) => (ms >= 1000 ? `${(ms / 1000).toFixed(1)} s` : `${ms} ms`);
|
|
11
|
+
/** How a line of what a case did begins: how long that took, in a column of its own, empty for a line that goes on with the one above. */
|
|
12
|
+
const timed = (ms) => `${(ms === undefined ? '' : took(ms)).padStart(9)} `;
|
|
13
|
+
/** What was sent or answered, laid out to be read; nothing for nothing. */
|
|
14
|
+
const laid = (value) => (value === undefined || value === null ? [] : (typeof value === 'string' ? value : JSON.stringify(value, null, 2)).split('\n').map((line) => `${timed()} ${line}`));
|
|
15
|
+
/** The call of the case: how long it took, what it sent, and what it was answered. */
|
|
16
|
+
const called = (one) => [`${dim(timed(one.ms))}→ ${one.method} ${one.path}${dim(` as ${one.who}`)}`, ...laid(one.sent), `${timed()}← ${one.status}`, ...laid(one.body)];
|
|
17
|
+
/** A call around it, in a line: how long it took, and who observed what. What is sent and answered to sign in is not shown. */
|
|
18
|
+
const around = (one) => dim(`${timed(one.ms)}· ${one.who} ${one.doing}: ${one.method} ${one.path} ← ${one.status}${one.doing === 'signs in' ? '' : ` ${JSON.stringify(one.body)}`}`);
|
|
19
|
+
const isStep = (one) => !('method' in one);
|
|
20
|
+
/** A step that put the case where it starts, in a line: how long it took, and what it was, the Background set or the server waited for. */
|
|
21
|
+
const step = (one) => dim(`${timed(one.ms)}· ${one.doing === 'sets the Background' ? `the Background ${one.seed} is set` : 'the server is at rest'}`);
|
|
22
|
+
const line = (one) => (isStep(one) ? [step(one)] : one.doing === 'calls' ? called(one) : [around(one)]);
|
|
23
|
+
/**
|
|
24
|
+
* What a case did, as much as was asked: the Background it was set in and its own call, or
|
|
25
|
+
* everything around them too, the waits for the server and every other call.
|
|
26
|
+
*/
|
|
27
|
+
export function wireLines(wire, log) {
|
|
28
|
+
if (log !== 'debug' && log !== 'trace')
|
|
29
|
+
return [];
|
|
30
|
+
return wire.filter((one) => log === 'trace' || one.doing === 'calls' || one.doing === 'sets the Background').flatMap(line);
|
|
31
|
+
}
|
|
32
|
+
function caseLines({ kase, findings, ms, wire }, log, operation) {
|
|
33
|
+
const what = `${kase.description}${kase.for ? dim(isForType(operation, kase) ? ` — for its type, ${kase.for}` : ` — for "${kase.for}"`) : ''}${kase.generated ? dim(' [from a condition]') : ''}${slow(ms)}`;
|
|
34
|
+
const told = findings.length ? [` ${red('✗')} ${kase.kind}: ${what}`, ...findings.map((finding) => ` ${red(finding)}`)] : [` ${green('✓')} ${kase.kind}: ${what}`];
|
|
35
|
+
return [...told, ...wireLines(wire, log)];
|
|
36
|
+
}
|
|
37
|
+
const header = (operation) => `${operation.name} ${dim(`— ${operation.agent} · ${operation.entry.method} ${operation.entry.path} · ${operation.file}`)}`;
|
|
38
|
+
/** One operation, as it ran. Asked for what fails only, one that passes is not told, and of another only the cases that fail. */
|
|
39
|
+
export function operationLines({ operation, outcomes, gaps }, log = 'info') {
|
|
40
|
+
const lost = outcomes.filter((outcome) => outcome.findings.length > 0);
|
|
41
|
+
if (log === 'warn')
|
|
42
|
+
return lost.length ? ['', header(operation), ...lost.flatMap((outcome) => caseLines(outcome, log, operation))] : [];
|
|
43
|
+
return ['', header(operation), ...operation.clauses.map(clauseLine), ...outcomes.flatMap((outcome) => caseLines(outcome, log, operation)), ...gaps.map((gap) => dim(` · ${gap}`))];
|
|
44
|
+
}
|
|
45
|
+
export const failed = (ran) => ran.flatMap((one) => one.outcomes).filter((outcome) => outcome.findings.length > 0);
|
|
46
|
+
/** The run in three lines: the cases, the clauses, the gaps. */
|
|
47
|
+
export function summaryLines(ran) {
|
|
48
|
+
const outcomes = ran.flatMap((one) => one.outcomes);
|
|
49
|
+
const observing = ran.filter((one) => one.operation.observes).length;
|
|
50
|
+
const clauses = ran.flatMap((one) => one.operation.clauses);
|
|
51
|
+
const checked = clauses.filter((clause) => clause.formaldef).length;
|
|
52
|
+
const complete = clauses.filter((clause) => clause.mark === 'complete');
|
|
53
|
+
const left = complete.filter((clause) => !clause.formaldef).length;
|
|
54
|
+
const only = complete.length - left ? ` (${complete.length - left} of them in the complete run only)` : '';
|
|
55
|
+
const lost = failed(ran).length;
|
|
56
|
+
const seconds = Math.round(outcomes.reduce((sum, outcome) => sum + outcome.ms, 0) / 1000);
|
|
57
|
+
return [
|
|
58
|
+
'',
|
|
59
|
+
`${ran.length - observing} operations, ${observing} observations, ${outcomes.length} cases: ${outcomes.length - lost} pass${lost ? red(`, ${lost} fail`) : ''}, in ${seconds} s`,
|
|
60
|
+
`${clauses.length} clauses: ${checked} checked${only}, ${left ? `${left} checked in the complete run only, ` : ''}${clauses.length - checked - left} told and not checked`,
|
|
61
|
+
`${ran.reduce((sum, one) => sum + one.gaps.length, 0)} gaps: an operation that does not say its transition, a ReqPre no counterexample violates, an operation no example shows`,
|
|
62
|
+
];
|
|
63
|
+
}
|