@enspirit/opspicy 0.2.0 → 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/README.md +91 -47
- package/bin/entry.js +22 -1
- package/bin/help.js +115 -0
- package/bin/opspicy +12 -4
- package/dist/explorer/document.js +21 -13
- package/dist/explorer/html.js +48 -3
- package/dist/explorer/index.js +5 -4
- package/dist/explorer/operation.js +7 -4
- package/dist/explorer/pages.js +61 -34
- package/dist/explorer/script/ranking.js +1 -1
- package/dist/explorer/site.js +5 -4
- package/dist/explorer/style.css +6 -0
- package/dist/explorer/wiki.js +14 -0
- package/dist/files.js +6 -4
- package/dist/judging.js +29 -5
- package/dist/main.js +1 -1
- package/dist/modelling.js +70 -12
- package/dist/planning.js +11 -2
- package/dist/reach.js +177 -0
- package/dist/reading.js +21 -6
- package/dist/report.js +6 -5
- package/dist/running.js +5 -2
- package/dist/suite.js +9 -6
- package/dist/upgrade.js +27 -0
- package/dist/upgrading.js +76 -0
- package/dist/world.js +5 -4
- package/package.json +2 -2
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
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
import { a, listOf, record, sentenceOf, text } from './citizens.js';
|
|
5
5
|
import { placeOf } from './lines.js';
|
|
6
6
|
import { readsDatabase } from './behind.js';
|
|
7
|
+
import { reachOf, reachProblems } from './reach.js';
|
|
7
8
|
import { NO_REFUSAL, entryOf, givenOf, marked, placeholders, refuses, thenOf } from './notation.js';
|
|
8
|
-
import { SAID, TRIGGER, isA, isPre, named, sameSentence } from './suite.js';
|
|
9
|
-
const OPERATION_KEYS = ['name', 'description', 'agent', 'entry', 'input', 'output', ...SAID, 'examples', 'counterexamples'];
|
|
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'];
|
|
10
11
|
const CASE_KEYS = ['name', 'when', 'for', 'given', 'input', 'then', 'and'];
|
|
11
12
|
const MARKED = { checked: 'x', complete: '+', told: ' ' };
|
|
12
13
|
/** What a reader gives, or the fallback with the reason told. */
|
|
@@ -83,8 +84,8 @@ function caseProblems(kase, operation, model) {
|
|
|
83
84
|
found.push('only a counterexample is "for" a precondition');
|
|
84
85
|
if (kase.kind === 'counterexample' && !kase.for)
|
|
85
86
|
found.push('a counterexample says which precondition it is "for"');
|
|
86
|
-
if (kase.kind === 'counterexample' && kase.for && !operation.clauses.some((clause) => isPre(clause) && sameSentence(clause.description, kase.for ?? '')))
|
|
87
|
-
found.push(`it is for "${kase.for}", which is not a precondition of the operation`);
|
|
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}` : ''}`);
|
|
88
89
|
// A status of 0 is a `then` that could not be read, which is told already.
|
|
89
90
|
if (kase.kind === 'counterexample' && kase.then.status && !refuses(kase.then))
|
|
90
91
|
found.push(`"then": ${NO_REFUSAL}`);
|
|
@@ -101,6 +102,17 @@ function headProblems(raw, { agents }) {
|
|
|
101
102
|
found.push(`"${text(raw.agent)}" is not an agent of agents.yml`);
|
|
102
103
|
return found;
|
|
103
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
|
+
}
|
|
104
116
|
/** An operation, from its file; an observation when it is filed as one. */
|
|
105
117
|
export function operationOf(file, written, model, observes = false, lines) {
|
|
106
118
|
const raw = record(written);
|
|
@@ -112,9 +124,12 @@ export function operationOf(file, written, model, observes = false, lines) {
|
|
|
112
124
|
const place = placeOf(file, lines);
|
|
113
125
|
const clauses = clausesOf(raw, name, model, problems, place);
|
|
114
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))));
|
|
115
|
-
problems.push(...cases.flatMap((kase) => caseProblems(kase, { agent: text(raw.agent), clauses }, model)), ...twice(cases));
|
|
127
|
+
problems.push(...cases.flatMap((kase) => caseProblems(kase, { agent: text(raw.agent), clauses, input: text(raw.input) || undefined }, model)), ...twice(cases));
|
|
116
128
|
if (placeholders(entry.path).length && !text(raw.input))
|
|
117
129
|
problems.push(`the entry takes ${placeholders(entry.path).join(', ')} from the input: the operation says its "input"`);
|
|
118
|
-
const
|
|
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 };
|
|
119
134
|
return { operation, problems: problems.map((problem) => `${file}: ${problem}`) };
|
|
120
135
|
}
|
package/dist/report.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isForType } from './suite.js';
|
|
1
2
|
const color = (code, text) => (process.stdout.isTTY ? `\u001b[${code}m${text}\u001b[0m` : text);
|
|
2
3
|
const green = (text) => color(32, text);
|
|
3
4
|
const red = (text) => color(31, text);
|
|
@@ -28,8 +29,8 @@ export function wireLines(wire, log) {
|
|
|
28
29
|
return [];
|
|
29
30
|
return wire.filter((one) => log === 'trace' || one.doing === 'calls' || one.doing === 'sets the Background').flatMap(line);
|
|
30
31
|
}
|
|
31
|
-
function caseLines({ kase, findings, ms, wire }, log) {
|
|
32
|
-
const what = `${kase.description}${kase.for ? dim(` — for "${kase.for}"`) : ''}${kase.generated ? dim(' [from a condition]') : ''}${slow(ms)}`;
|
|
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)}`;
|
|
33
34
|
const told = findings.length ? [` ${red('✗')} ${kase.kind}: ${what}`, ...findings.map((finding) => ` ${red(finding)}`)] : [` ${green('✓')} ${kase.kind}: ${what}`];
|
|
34
35
|
return [...told, ...wireLines(wire, log)];
|
|
35
36
|
}
|
|
@@ -38,8 +39,8 @@ const header = (operation) => `${operation.name} ${dim(`— ${operation.agent}
|
|
|
38
39
|
export function operationLines({ operation, outcomes, gaps }, log = 'info') {
|
|
39
40
|
const lost = outcomes.filter((outcome) => outcome.findings.length > 0);
|
|
40
41
|
if (log === 'warn')
|
|
41
|
-
return lost.length ? ['', header(operation), ...lost.flatMap((outcome) => caseLines(outcome, log))] : [];
|
|
42
|
-
return ['', header(operation), ...operation.clauses.map(clauseLine), ...outcomes.flatMap((outcome) => caseLines(outcome, log)), ...gaps.map((gap) => dim(` · ${gap}`))];
|
|
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}`))];
|
|
43
44
|
}
|
|
44
45
|
export const failed = (ran) => ran.flatMap((one) => one.outcomes).filter((outcome) => outcome.findings.length > 0);
|
|
45
46
|
/** The run in three lines: the cases, the clauses, the gaps. */
|
|
@@ -57,6 +58,6 @@ export function summaryLines(ran) {
|
|
|
57
58
|
'',
|
|
58
59
|
`${ran.length - observing} operations, ${observing} observations, ${outcomes.length} cases: ${outcomes.length - lost} pass${lost ? red(`, ${lost} fail`) : ''}, in ${seconds} s`,
|
|
59
60
|
`${clauses.length} clauses: ${checked} checked${only}, ${left ? `${left} checked in the complete run only, ` : ''}${clauses.length - checked - left} told and not checked`,
|
|
60
|
-
`${ran.reduce((sum, one) => sum + one.gaps.length, 0)} gaps: a
|
|
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`,
|
|
61
62
|
];
|
|
62
63
|
}
|
package/dist/running.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// Then judging.ts says what does not hold
|
|
11
11
|
import { Unrunnable, unrun, whole } from './finding.js';
|
|
12
12
|
import { inputMisfit, judge } from './judging.js';
|
|
13
|
+
import { observedIn } from './reach.js';
|
|
13
14
|
import { addressed, queryOf } from './notation.js';
|
|
14
15
|
import { witnessesOf } from './planning.js';
|
|
15
16
|
import { credentialsOf } from './suite.js';
|
|
@@ -79,8 +80,10 @@ async function run(reach, model, meaning, operation, kase, origin, heard) {
|
|
|
79
80
|
await heard.step({ doing: 'sets the Background', seed: kase.given.seed }, () => reach.config.background(kase.given.seed));
|
|
80
81
|
const { requester, witnesses } = await browsers(reach, callers, origin, heard);
|
|
81
82
|
const world = worldOf(model, kase);
|
|
83
|
+
// The fast run observes what the operation monitors and controls; the complete run, every state.
|
|
84
|
+
const only = reach.relations ? undefined : observedIn(operation.reach, model.state.map((one) => one.name));
|
|
82
85
|
heard.doing('observes, before');
|
|
83
|
-
const before = await observe(reach, model, requester, witnesses);
|
|
86
|
+
const before = await observe(reach, model, requester, witnesses, only);
|
|
84
87
|
const input = typeof kase.input === 'string' ? meaning.value(kase.input, { before, world }, 'given') : kase.input;
|
|
85
88
|
heard.doing('calls');
|
|
86
89
|
const answer = await call(requester, operation, input);
|
|
@@ -88,7 +91,7 @@ async function run(reach, model, meaning, operation, kase, origin, heard) {
|
|
|
88
91
|
if (operation.entry.method !== 'GET' && answer.status < 400)
|
|
89
92
|
await rested(reach, heard);
|
|
90
93
|
heard.doing('observes, after');
|
|
91
|
-
const after = await observe(reach, model, requester, witnesses);
|
|
94
|
+
const after = await observe(reach, model, requester, witnesses, only);
|
|
92
95
|
return [...inputMisfit(operation, kase, input, meaning), ...judge(operation, kase, { input, world, before, after, status: answer.status, body: answer.body }, meaning, reach.config.refusal)];
|
|
93
96
|
}
|
|
94
97
|
/** What a case decided, from what was found: told whole to who runs it, and kept without what was seen. */
|
package/dist/suite.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
// What a specification is made of, once read: its citizens. Each has a name and a description,
|
|
2
|
-
// and some a formal definition, its formaldef: what the suite speaks of (areas, agents, Backgrounds,
|
|
3
|
-
// actors, the state), its words (predicates, functions, conditions, types), its operations.
|
|
4
1
|
export const PRE = ['DomPre', 'ReqPre'];
|
|
5
2
|
export const POST = ['DomPost', 'ReqPost'];
|
|
6
3
|
/** The four that can be checked, then when an operation is performed without being asked: told, since one call shows nothing of it. */
|
|
7
4
|
export const KINDS = [...PRE, ...POST];
|
|
8
5
|
export const TRIGGER = 'ReqTrig';
|
|
9
|
-
/** The clauses an operation says, each under its key. */
|
|
10
|
-
export const SAID = [
|
|
6
|
+
/** The clauses an operation says, each under its key, in the order they are shown: what it is, then what the rules demand of it. */
|
|
7
|
+
export const SAID = ['DomPre', 'DomPost', 'ReqPre', 'ReqPost', TRIGGER];
|
|
11
8
|
/** How a mark is written. */
|
|
12
9
|
export const MARKS = { x: 'checked', '+': 'complete', ' ': 'told' };
|
|
13
10
|
/** A suite that says nothing. */
|
|
14
|
-
export const NOTHING_SAID = { areas: [], agents: [], backgrounds: [], actors: [], world: {}, state: [], relations: [], definitions: [], conditions: [], types: [] };
|
|
11
|
+
export const NOTHING_SAID = { system: {}, descriptions: {}, areas: [], agents: [], backgrounds: [], actors: [], world: {}, state: [], relations: [], definitions: [], conditions: [], types: [] };
|
|
15
12
|
/** Two sentences are the same whatever their case and spacing. */
|
|
16
13
|
export const sameSentence = (a, b) => normal(a) === normal(b);
|
|
17
14
|
const normal = (sentence) => sentence.trim().replace(/\s+/g, ' ').toLowerCase();
|
|
18
15
|
export const isPre = (clause) => PRE.includes(clause.kind);
|
|
16
|
+
/**
|
|
17
|
+
* Whether a counterexample is for the type of the input: its input is not one, on purpose. Every
|
|
18
|
+
* operation refuses what is not of its type, a precondition no operation says; a counterexample
|
|
19
|
+
* that shows it refused names the type, `for: BoardGiven`, where another names a precondition.
|
|
20
|
+
*/
|
|
21
|
+
export const isForType = (operation, kase) => kase.kind === 'counterexample' && Boolean(operation.input) && kase.for === operation.input;
|
|
19
22
|
/** The citizen of that name, among those of one kind. */
|
|
20
23
|
export const named = (all, name) => all.find((one) => one.name === name);
|
|
21
24
|
/** What each actor signs in with, by name: `world.actors`. */
|
package/dist/upgrade.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// node src/upgrade.ts [<suite>]
|
|
2
|
+
//
|
|
3
|
+
// Rewrites a suite written for an earlier opspicy in the form this one reads, in place, and says
|
|
4
|
+
// what it changed, then what it found and cannot decide, and, the first time, what no file shows
|
|
5
|
+
// (upgrading.ts). Run again, it finds nothing to do: 0. A suite with no specification/ is told
|
|
6
|
+
// so: 2.
|
|
7
|
+
import { upgrade } from './upgrading.js';
|
|
8
|
+
/** What changed and that no file of a suite shows: told once, when the suite is rewritten from an earlier form. */
|
|
9
|
+
const UNSEEN = [
|
|
10
|
+
'`opspicy` alone now says how it is used: a script that ran it with no argument, for the suite of its directory, runs `opspicy .`.',
|
|
11
|
+
'After an example, every state that changed must be one the operation controls: a run tells `"<state>" changed, which <Operation> does not control`. The operation then says what it controls (`controls: [...]`), or a postcondition speaks of that state.',
|
|
12
|
+
'The explorer goes by the name `system.yml` gives the system, when it gives one: the notes of a reader are kept under the name of the specification, which `--name=` still sets.',
|
|
13
|
+
];
|
|
14
|
+
const suite = process.argv.slice(2).find((arg) => !arg.startsWith('-')) ?? '.';
|
|
15
|
+
try {
|
|
16
|
+
const { rewritten, found } = upgrade(suite);
|
|
17
|
+
const lines = rewritten.length ? [`${suite} is upgraded:`, ...rewritten.map((one) => ` ${one}`)] : [`${suite} is already in the form this opspicy reads: nothing to rewrite.`];
|
|
18
|
+
if (found.length)
|
|
19
|
+
lines.push('', 'To look at, which it cannot decide:', ...found.map((one) => ` ${one}`));
|
|
20
|
+
if (rewritten.length)
|
|
21
|
+
lines.push('', 'And what no file shows:', ...UNSEEN.map((one) => ` ${one}`), '', 'CHANGELOG.md says everything that changed.');
|
|
22
|
+
console.log(lines.join('\n'));
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
26
|
+
process.exit(2);
|
|
27
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// What `opspicy upgrade` does (upgrade.ts): rewrites a suite written for an earlier opspicy in
|
|
2
|
+
// the form this one reads, in place, and says what it changed. What it rewrites it keeps as it
|
|
3
|
+
// was written: its comments, its order, its quotes. Run again, it finds nothing to do.
|
|
4
|
+
//
|
|
5
|
+
// From 0.1 and 0.2, whose suites are written alike: areas.yml, agents.yml and backgrounds.yml were
|
|
6
|
+
// a list each. Each is now a map, of its description and its list (CHANGELOG.md): the list is moved
|
|
7
|
+
// under its key, as it was. What it cannot decide, it finds and says: a counterexample whose input
|
|
8
|
+
// is not of its operation's type, a description that was a value of the world. What no file shows
|
|
9
|
+
// (a script that runs `opspicy` alone, a state an operation changes and does not control) it says too.
|
|
10
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { YAMLMap, isSeq, parseDocument } from 'yaml';
|
|
13
|
+
import { readSuite } from './files.js';
|
|
14
|
+
import { meaningOf } from './meaning.js';
|
|
15
|
+
import { isForType } from './suite.js';
|
|
16
|
+
/** The files that were a list, and the key their list is now under. */
|
|
17
|
+
const LISTS = { 'areas.yml': 'areas', 'agents.yml': 'agents', 'backgrounds.yml': 'backgrounds' };
|
|
18
|
+
/** A file as this opspicy reads it, or nothing when it already is: its list, as it was written, under its key. */
|
|
19
|
+
export function upgraded(text, key) {
|
|
20
|
+
const document = parseDocument(text);
|
|
21
|
+
if (document.errors.length || !isSeq(document.contents))
|
|
22
|
+
return null;
|
|
23
|
+
const map = new YAMLMap();
|
|
24
|
+
map.add(document.createPair(key, document.contents));
|
|
25
|
+
// What was said above the list is said above the file, still: the parser gives it to the list,
|
|
26
|
+
// or to its first item.
|
|
27
|
+
const list = document.contents;
|
|
28
|
+
const first = list.items[0];
|
|
29
|
+
document.commentBefore = [document.commentBefore, list.commentBefore, first?.commentBefore].filter(Boolean).join('\n') || null;
|
|
30
|
+
list.commentBefore = undefined;
|
|
31
|
+
if (first)
|
|
32
|
+
first.commentBefore = undefined;
|
|
33
|
+
document.contents = map;
|
|
34
|
+
return document.toString();
|
|
35
|
+
}
|
|
36
|
+
/** What `world.yml` says as its `description`, when it says one: in 0.2, a value of the world; now, the text of its page. */
|
|
37
|
+
function worldDescribed(root) {
|
|
38
|
+
const path = join(root, 'world.yml');
|
|
39
|
+
if (!existsSync(path))
|
|
40
|
+
return [];
|
|
41
|
+
const world = parseDocument(readFileSync(path, 'utf8')).toJS();
|
|
42
|
+
return world && typeof world === 'object' && 'description' in world ? ['specification/world.yml: its "description" was a value of the world; it is now the text the World page leads with, in Markdown, and a formaldef no longer reads it as `world.description`: rename it, if a formaldef reads it'] : [];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The counterexamples whose input, written as data, is not of the type of their operation's input,
|
|
46
|
+
* and which are for a precondition: in 0.2 they passed, now they violate more than what they are
|
|
47
|
+
* for. Their input is corrected, or they say `for: <the type>`, where that is what they show.
|
|
48
|
+
*/
|
|
49
|
+
function inputsOutOfType(suite) {
|
|
50
|
+
const read = readSuite(suite);
|
|
51
|
+
if (read.problems.length)
|
|
52
|
+
return read.problems.map((problem) => `it cannot be read: ${problem}`);
|
|
53
|
+
const meaning = meaningOf(read.types);
|
|
54
|
+
return read.operations.flatMap((operation) => operation.cases.flatMap((kase) => {
|
|
55
|
+
if (kase.kind !== 'counterexample' || !operation.input || isForType(operation, kase) || typeof kase.input === 'string')
|
|
56
|
+
return [];
|
|
57
|
+
const misfit = meaning.misfit(operation.input, kase.input);
|
|
58
|
+
return misfit ? [`specification/${operation.file}: counterexample "${kase.description}": its input is not a ${operation.input} (${misfit}): correct it, or say \`for: ${operation.input}\` where that is what it shows`] : [];
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
/** Rewrites the files of a suite that are in an earlier form, and says which it rewrote, and what it found that it cannot decide. */
|
|
62
|
+
export function upgrade(suite) {
|
|
63
|
+
const root = join(suite, 'specification');
|
|
64
|
+
if (!existsSync(root))
|
|
65
|
+
throw new Error(`${suite} holds no specification/: nothing to upgrade`);
|
|
66
|
+
const rewritten = Object.entries(LISTS).flatMap(([file, key]) => {
|
|
67
|
+
const path = join(root, file);
|
|
68
|
+
const text = existsSync(path) ? upgraded(readFileSync(path, 'utf8'), key) : null;
|
|
69
|
+
if (text === null)
|
|
70
|
+
return [];
|
|
71
|
+
writeFileSync(path, text);
|
|
72
|
+
return [`specification/${file}: its list is now under "${key}", beside the description it may say`];
|
|
73
|
+
});
|
|
74
|
+
// What a suite of 0.2 said its own way is told when it is rewritten from that form, and once.
|
|
75
|
+
return { rewritten, found: [...(rewritten.length ? worldDescribed(root) : []), ...inputsOutOfType(suite)] };
|
|
76
|
+
}
|
package/dist/world.js
CHANGED
|
@@ -115,12 +115,13 @@ async function seenBy(model, theirs) {
|
|
|
115
115
|
seen[one.name] = toldBy(one, await theirs.call('GET', one.path));
|
|
116
116
|
return seen;
|
|
117
117
|
}
|
|
118
|
-
/** The state, now: as the requester sees it, as the witnesses do, and the relations of the database. */
|
|
119
|
-
export async function observe(reach, model, requester, witnesses) {
|
|
120
|
-
const
|
|
118
|
+
/** The state, now: as the requester sees it, as the witnesses do, and the relations of the database; only the states named, when some are. */
|
|
119
|
+
export async function observe(reach, model, requester, witnesses, only) {
|
|
120
|
+
const observed = only ? { ...model, state: model.state.filter((one) => only.includes(one.name)) } : model;
|
|
121
|
+
const state = await seenBy(observed, requester);
|
|
121
122
|
const others = {};
|
|
122
123
|
for (const [name, theirs] of Object.entries(witnesses))
|
|
123
|
-
others[name] = await seenBy(
|
|
124
|
+
others[name] = await seenBy(observed, theirs);
|
|
124
125
|
const db = {};
|
|
125
126
|
for (const relation of model.relations)
|
|
126
127
|
db[relation.name] = reach.database && reach.relations ? await tuples(reach.database, relation) : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enspirit/opspicy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Specifies the operations of a system by their clauses, as sentences that Elo gives a meaning, and runs them black-box",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test:package": "node --test --test-reporter=spec \"test/package/*.test.ts\"",
|
|
39
39
|
"build": "node build.ts",
|
|
40
40
|
"prepack": "npm run build",
|
|
41
|
-
"example": "node example/
|
|
41
|
+
"example": "node example/splitter.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@enspirit/elo": "1.2.4",
|