@enspirit/opspicy 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +281 -2
- package/bin/entry.js +27 -0
- package/bin/opspicy +19 -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 +109 -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 +59 -0
- package/dist/explorer/index.js +61 -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 +94 -0
- package/dist/explorer/pages.js +132 -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 +77 -0
- package/dist/explorer/style.css +241 -0
- package/dist/explorer/telling.js +30 -0
- package/dist/explorer/tests.js +78 -0
- package/dist/explorer/wiki.js +76 -0
- package/dist/files.js +176 -0
- package/dist/finding.js +17 -0
- package/dist/judging.js +75 -0
- package/dist/lines.js +30 -0
- package/dist/main.js +128 -0
- package/dist/meaning.js +100 -0
- package/dist/modelling.js +115 -0
- package/dist/naming.js +84 -0
- package/dist/notation.js +119 -0
- package/dist/planning.js +32 -0
- package/dist/reading.js +120 -0
- package/dist/report-file.js +42 -0
- package/dist/report.js +62 -0
- package/dist/running.js +102 -0
- package/dist/selecting.js +71 -0
- package/dist/starting.js +41 -0
- package/dist/suite.js +29 -0
- package/dist/words.js +103 -0
- package/dist/world.js +128 -0
- package/package.json +57 -4
package/dist/planning.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
/** What a reader should know is missing: a clause nothing checks, a precondition nothing violates, an operation nothing shows. */
|
|
26
|
+
export function gapsOf(operation, cases) {
|
|
27
|
+
const violated = (clause) => cases.some((kase) => kase.kind === 'counterexample' && sameSentence(kase.for ?? '', clause.description));
|
|
28
|
+
return [
|
|
29
|
+
...(cases.some((kase) => kase.kind === 'example') ? [] : ['no example shows it succeed']),
|
|
30
|
+
...operation.clauses.filter((clause) => isPre(clause) && !violated(clause)).map((clause) => `no counterexample violates "${clause.description}"`),
|
|
31
|
+
];
|
|
32
|
+
}
|
package/dist/reading.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
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 { 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'];
|
|
10
|
+
const CASE_KEYS = ['name', 'when', 'for', 'given', 'input', 'then', 'and'];
|
|
11
|
+
const MARKED = { checked: 'x', complete: '+', told: ' ' };
|
|
12
|
+
/** What a reader gives, or the fallback with the reason told. */
|
|
13
|
+
function attempt(problems, read, fallback) {
|
|
14
|
+
try {
|
|
15
|
+
return read();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
problems.push(error instanceof Error ? error.message : String(error));
|
|
19
|
+
return fallback;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function unknownKeys(raw, known, where, problems) {
|
|
23
|
+
for (const key of Object.keys(raw))
|
|
24
|
+
if (!known.includes(key))
|
|
25
|
+
problems.push(`${where}: "${key}" is not something a specification says (${known.join(', ')})`);
|
|
26
|
+
}
|
|
27
|
+
/** What a mark says wrong of its sentence. A long form says none: what it is, is what the sentence is. */
|
|
28
|
+
function mismarked(kind, says, mark, long, has) {
|
|
29
|
+
const found = [];
|
|
30
|
+
if (has.behind && mark !== 'complete' && !long)
|
|
31
|
+
found.push(`${kind} "${says}" reads the database, behind the front door: it is checked in the complete run only, and says so with (+)`);
|
|
32
|
+
if (mark && mark !== 'told' && !has.own && !has.shared)
|
|
33
|
+
found.push(`${kind} "${says}" is marked (${MARKED[mark]}), and nothing gives it a formaldef: neither here nor a condition`);
|
|
34
|
+
if (mark === 'told' && (has.own || has.shared))
|
|
35
|
+
found.push(`${kind} "${says}" is marked ( ), and ${has.own ? 'has a formaldef here' : 'a condition gives it a formaldef'}: it is checked`);
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
/** 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. */
|
|
39
|
+
function meant(kind, item, where, { conditions, definitions }, problems, source) {
|
|
40
|
+
const said = attempt(problems, () => sentenceOf(kind, item), null);
|
|
41
|
+
if (!said)
|
|
42
|
+
return null;
|
|
43
|
+
const { description, long } = said;
|
|
44
|
+
const shared = conditions.find((condition) => sameSentence(condition.description, description));
|
|
45
|
+
const formaldef = said.formaldef ?? shared?.formaldef;
|
|
46
|
+
const behind = attempt([], () => readsDatabase(formaldef ?? '', definitions), false);
|
|
47
|
+
if (kind === TRIGGER && formaldef)
|
|
48
|
+
problems.push(`${kind} "${description}" is told, and has no formaldef: one call shows nothing of what triggers an operation`);
|
|
49
|
+
if (shared && said.formaldef)
|
|
50
|
+
problems.push(`${kind} "${description}" has a formaldef here and another as a condition: keep one`);
|
|
51
|
+
problems.push(...mismarked(kind, description, said.mark, long, { own: Boolean(said.formaldef), shared: Boolean(shared), behind }));
|
|
52
|
+
const mark = long ? (!formaldef ? 'told' : behind ? 'complete' : 'checked') : said.mark;
|
|
53
|
+
return { kind, name: said.name ?? where, source, description, ...(formaldef ? { formaldef } : {}), from: said.formaldef ? 'here' : shared ? 'shared' : 'nowhere', mark };
|
|
54
|
+
}
|
|
55
|
+
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);
|
|
56
|
+
/** The precondition a counterexample is for, in the operation's words: with its mark or without. */
|
|
57
|
+
const forOf = (written, problems) => attempt(problems, () => marked(text(written)).description, text(written));
|
|
58
|
+
function caseOf(kind, item, where, model, problems, place) {
|
|
59
|
+
const raw = record(item);
|
|
60
|
+
const when = text(raw.when) || '(a case that does not say when)';
|
|
61
|
+
const mine = [];
|
|
62
|
+
unknownKeys(raw, CASE_KEYS, 'a case', mine);
|
|
63
|
+
if (!text(raw.when))
|
|
64
|
+
mine.push('a case says "when"');
|
|
65
|
+
const given = attempt(mine, () => givenOf(raw.given), { seed: '', actor: '' });
|
|
66
|
+
const then = attempt(mine, () => thenOf(raw.then), { status: 0 });
|
|
67
|
+
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);
|
|
68
|
+
const violated = forOf(raw.for, mine);
|
|
69
|
+
problems.push(...mine.map((problem) => `${kind} "${when}": ${problem}`));
|
|
70
|
+
return { kind, name: text(raw.name) || where, source: place(), description: when, for: violated || undefined, given, input: raw.input ?? null, then, and, generated: false };
|
|
71
|
+
}
|
|
72
|
+
/** What a case says that its operation or the world does not bear out. */
|
|
73
|
+
function caseProblems(kase, operation, model) {
|
|
74
|
+
const found = [];
|
|
75
|
+
const actor = named(model.actors, kase.given.actor);
|
|
76
|
+
if (kase.given.actor && !actor)
|
|
77
|
+
found.push(`nobody is called "${kase.given.actor}" in the world`);
|
|
78
|
+
if (kase.given.seed && !named(model.backgrounds, kase.given.seed))
|
|
79
|
+
found.push(`"${kase.given.seed}" is not a Background of backgrounds.yml`);
|
|
80
|
+
if (kase.kind === 'example' && actor && named(model.agents, operation.agent) && !isA(model.agents, actor.is, operation.agent))
|
|
81
|
+
found.push(`it is called by "${actor.name}", who is ${a(actor.is)}: the operation is performed by ${a(operation.agent)}`);
|
|
82
|
+
if (kase.kind === 'example' && kase.for)
|
|
83
|
+
found.push('only a counterexample is "for" a precondition');
|
|
84
|
+
if (kase.kind === 'counterexample' && !kase.for)
|
|
85
|
+
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`);
|
|
88
|
+
// A status of 0 is a `then` that could not be read, which is told already.
|
|
89
|
+
if (kase.kind === 'counterexample' && kase.then.status && !refuses(kase.then))
|
|
90
|
+
found.push(`"then": ${NO_REFUSAL}`);
|
|
91
|
+
if (kase.kind === 'counterexample' && kase.and.length)
|
|
92
|
+
found.push('a refusal changes nothing: there is no "and" to a counterexample');
|
|
93
|
+
return found.map((problem) => `${kase.kind} "${kase.description}": ${problem}`);
|
|
94
|
+
}
|
|
95
|
+
/** Two cases of a kind that say the same `when`: a case is known by what it says. */
|
|
96
|
+
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"`);
|
|
97
|
+
/** What an operation says of itself that the suite does not bear out. */
|
|
98
|
+
function headProblems(raw, { agents }) {
|
|
99
|
+
const found = ['name', 'description', 'agent', 'entry'].filter((key) => !text(raw[key])).map((key) => `the operation says its "${key}"`);
|
|
100
|
+
if (text(raw.agent) && !named(agents, text(raw.agent)))
|
|
101
|
+
found.push(`"${text(raw.agent)}" is not an agent of agents.yml`);
|
|
102
|
+
return found;
|
|
103
|
+
}
|
|
104
|
+
/** An operation, from its file; an observation when it is filed as one. */
|
|
105
|
+
export function operationOf(file, written, model, observes = false, lines) {
|
|
106
|
+
const raw = record(written);
|
|
107
|
+
const problems = [];
|
|
108
|
+
const name = text(raw.name) || file;
|
|
109
|
+
unknownKeys(raw, OPERATION_KEYS, 'the operation', problems);
|
|
110
|
+
problems.push(...headProblems(raw, model));
|
|
111
|
+
const entry = attempt(problems, () => entryOf(raw.entry), { method: 'GET', path: '/' });
|
|
112
|
+
const place = placeOf(file, lines);
|
|
113
|
+
const clauses = clausesOf(raw, name, model, problems, place);
|
|
114
|
+
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));
|
|
116
|
+
if (placeholders(entry.path).length && !text(raw.input))
|
|
117
|
+
problems.push(`the entry takes ${placeholders(entry.path).join(', ')} from the input: the operation says its "input"`);
|
|
118
|
+
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 };
|
|
119
|
+
return { operation, problems: problems.map((problem) => `${file}: ${problem}`) };
|
|
120
|
+
}
|
|
@@ -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,62 @@
|
|
|
1
|
+
const color = (code, text) => (process.stdout.isTTY ? `\u001b[${code}m${text}\u001b[0m` : text);
|
|
2
|
+
const green = (text) => color(32, text);
|
|
3
|
+
const red = (text) => color(31, text);
|
|
4
|
+
const dim = (text) => color(2, text);
|
|
5
|
+
const unchecked = (clause) => (clause.mark === 'complete' ? ' (checked in the complete run only)' : ' (told, not checked)');
|
|
6
|
+
const clauseLine = (clause) => ` ${clause.kind.padEnd(7)} ${clause.formaldef ? green('✓') : dim('·')} ${clause.description}${clause.formaldef ? '' : dim(unchecked(clause))}`;
|
|
7
|
+
/** A case that takes a second or more says so: it waited for something. */
|
|
8
|
+
const slow = (ms) => (ms >= 1000 ? dim(` ${(ms / 1000).toFixed(1)} s`) : '');
|
|
9
|
+
const took = (ms) => (ms >= 1000 ? `${(ms / 1000).toFixed(1)} s` : `${ms} ms`);
|
|
10
|
+
/** 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. */
|
|
11
|
+
const timed = (ms) => `${(ms === undefined ? '' : took(ms)).padStart(9)} `;
|
|
12
|
+
/** What was sent or answered, laid out to be read; nothing for nothing. */
|
|
13
|
+
const laid = (value) => (value === undefined || value === null ? [] : (typeof value === 'string' ? value : JSON.stringify(value, null, 2)).split('\n').map((line) => `${timed()} ${line}`));
|
|
14
|
+
/** The call of the case: how long it took, what it sent, and what it was answered. */
|
|
15
|
+
const called = (one) => [`${dim(timed(one.ms))}→ ${one.method} ${one.path}${dim(` as ${one.who}`)}`, ...laid(one.sent), `${timed()}← ${one.status}`, ...laid(one.body)];
|
|
16
|
+
/** 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. */
|
|
17
|
+
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)}`}`);
|
|
18
|
+
const isStep = (one) => !('method' in one);
|
|
19
|
+
/** 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. */
|
|
20
|
+
const step = (one) => dim(`${timed(one.ms)}· ${one.doing === 'sets the Background' ? `the Background ${one.seed} is set` : 'the server is at rest'}`);
|
|
21
|
+
const line = (one) => (isStep(one) ? [step(one)] : one.doing === 'calls' ? called(one) : [around(one)]);
|
|
22
|
+
/**
|
|
23
|
+
* What a case did, as much as was asked: the Background it was set in and its own call, or
|
|
24
|
+
* everything around them too, the waits for the server and every other call.
|
|
25
|
+
*/
|
|
26
|
+
export function wireLines(wire, log) {
|
|
27
|
+
if (log !== 'debug' && log !== 'trace')
|
|
28
|
+
return [];
|
|
29
|
+
return wire.filter((one) => log === 'trace' || one.doing === 'calls' || one.doing === 'sets the Background').flatMap(line);
|
|
30
|
+
}
|
|
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)}`;
|
|
33
|
+
const told = findings.length ? [` ${red('✗')} ${kase.kind}: ${what}`, ...findings.map((finding) => ` ${red(finding)}`)] : [` ${green('✓')} ${kase.kind}: ${what}`];
|
|
34
|
+
return [...told, ...wireLines(wire, log)];
|
|
35
|
+
}
|
|
36
|
+
const header = (operation) => `${operation.name} ${dim(`— ${operation.agent} · ${operation.entry.method} ${operation.entry.path} · ${operation.file}`)}`;
|
|
37
|
+
/** One operation, as it ran. Asked for what fails only, one that passes is not told, and of another only the cases that fail. */
|
|
38
|
+
export function operationLines({ operation, outcomes, gaps }, log = 'info') {
|
|
39
|
+
const lost = outcomes.filter((outcome) => outcome.findings.length > 0);
|
|
40
|
+
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}`))];
|
|
43
|
+
}
|
|
44
|
+
export const failed = (ran) => ran.flatMap((one) => one.outcomes).filter((outcome) => outcome.findings.length > 0);
|
|
45
|
+
/** The run in three lines: the cases, the clauses, the gaps. */
|
|
46
|
+
export function summaryLines(ran) {
|
|
47
|
+
const outcomes = ran.flatMap((one) => one.outcomes);
|
|
48
|
+
const observing = ran.filter((one) => one.operation.observes).length;
|
|
49
|
+
const clauses = ran.flatMap((one) => one.operation.clauses);
|
|
50
|
+
const checked = clauses.filter((clause) => clause.formaldef).length;
|
|
51
|
+
const complete = clauses.filter((clause) => clause.mark === 'complete');
|
|
52
|
+
const left = complete.filter((clause) => !clause.formaldef).length;
|
|
53
|
+
const only = complete.length - left ? ` (${complete.length - left} of them in the complete run only)` : '';
|
|
54
|
+
const lost = failed(ran).length;
|
|
55
|
+
const seconds = Math.round(outcomes.reduce((sum, outcome) => sum + outcome.ms, 0) / 1000);
|
|
56
|
+
return [
|
|
57
|
+
'',
|
|
58
|
+
`${ran.length - observing} operations, ${observing} observations, ${outcomes.length} cases: ${outcomes.length - lost} pass${lost ? red(`, ${lost} fail`) : ''}, in ${seconds} s`,
|
|
59
|
+
`${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 precondition no counterexample violates, an operation no example shows`,
|
|
61
|
+
];
|
|
62
|
+
}
|
package/dist/running.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// One case, run: the Background is set, the state observed, the operation called once, the
|
|
2
|
+
// state observed again, and the whole judged.
|
|
3
|
+
//
|
|
4
|
+
// Given the Background is set, once the server is at rest, and who calls is signed in (and
|
|
5
|
+
// whoever else looks on)
|
|
6
|
+
//
|
|
7
|
+
// What it did is kept in order, when the run asks to see it: its calls, and the steps that put
|
|
8
|
+
// it where it starts (the Background set, the server waited for), each with how long it took.
|
|
9
|
+
// When the entry is called with the input, and what it started is done
|
|
10
|
+
// Then judging.ts says what does not hold
|
|
11
|
+
import { Unrunnable, unrun, whole } from './finding.js';
|
|
12
|
+
import { inputMisfit, judge } from './judging.js';
|
|
13
|
+
import { addressed, queryOf } from './notation.js';
|
|
14
|
+
import { witnessesOf } from './planning.js';
|
|
15
|
+
import { credentialsOf } from './suite.js';
|
|
16
|
+
import { atRest, browserOf, observe } from './world.js';
|
|
17
|
+
function ears(listening) {
|
|
18
|
+
const wire = [];
|
|
19
|
+
let now = 'signs in';
|
|
20
|
+
const step = async (said, work) => {
|
|
21
|
+
const started = Date.now();
|
|
22
|
+
try {
|
|
23
|
+
await work();
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
if (listening)
|
|
27
|
+
wire.push({ ...said, ms: Date.now() - started });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return { wire, doing: (what) => void (now = what), of: (who) => (listening ? (called) => void wire.push({ who, doing: now, ...called }) : undefined), step };
|
|
31
|
+
}
|
|
32
|
+
/** Waits for the server to have nothing under way, where the suite can tell: said as a step only then. */
|
|
33
|
+
const rested = (reach, heard) => (reach.database && reach.config.atRest ? heard.step({ doing: 'waits for the server' }, () => atRest(reach)) : atRest(reach));
|
|
34
|
+
/** An origin nobody called from before: where a system counts by origin (wrong guesses, say), a case answers for its own only. */
|
|
35
|
+
const originOf = (run, n) => `10.${run % 256}.${Math.floor(n / 256) % 256}.${n % 256}`;
|
|
36
|
+
/** What a formaldef reads as `world`: what the suite says of it, what each actor signs in with, and who calls. */
|
|
37
|
+
export function worldOf(model, kase) {
|
|
38
|
+
const actors = credentialsOf(model);
|
|
39
|
+
// Their name last: somebody who signs in with a `name` is still called what the world calls them.
|
|
40
|
+
return { ...model.world, actors, requester: { ...actors[kase.given.actor], name: kase.given.actor } };
|
|
41
|
+
}
|
|
42
|
+
async function call(api, operation, input) {
|
|
43
|
+
const { path, rest } = addressed(operation.entry.path, input);
|
|
44
|
+
if (operation.entry.method === 'GET')
|
|
45
|
+
return api.call('GET', `${path}${queryOf(rest)}`);
|
|
46
|
+
// Nothing left to say is said as an empty object: what is sent is JSON, whatever the method.
|
|
47
|
+
return api.call(operation.entry.method, path, rest ?? {});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Who a case signs in: who calls, and whoever looks on. Each is somebody of the world. A name the
|
|
51
|
+
* world does not have is nobody, and so is one that every record has something under
|
|
52
|
+
* (`constructor`): asked before the Background is set, since such a case cannot run.
|
|
53
|
+
*/
|
|
54
|
+
export function callersOf(model, operation, kase) {
|
|
55
|
+
const held = credentialsOf(model);
|
|
56
|
+
const caller = (name) => {
|
|
57
|
+
if (!Object.hasOwn(held, name))
|
|
58
|
+
throw new Unrunnable(`nobody is called "${name}" in the world`);
|
|
59
|
+
return [name, held[name] ?? null];
|
|
60
|
+
};
|
|
61
|
+
return { requester: caller(kase.given.actor), witnesses: witnessesOf(operation, kase).map(caller) };
|
|
62
|
+
}
|
|
63
|
+
async function browsers(reach, callers, origin, heard) {
|
|
64
|
+
const witnesses = {};
|
|
65
|
+
for (const [name, held] of callers.witnesses)
|
|
66
|
+
witnesses[name] = await browserOf(reach.config, origin, name, held, heard.of(name));
|
|
67
|
+
const [actor, held] = callers.requester;
|
|
68
|
+
return { requester: await browserOf(reach.config, origin, actor, held, heard.of(actor)), witnesses };
|
|
69
|
+
}
|
|
70
|
+
/** Setting a Background empties the database. Whoever runs a case asks before; it is asked again here, where it is done, so that no caller sets one by forgetting to. */
|
|
71
|
+
function mayEmpty(config) {
|
|
72
|
+
if (config.mayEmptyTheDatabase !== true)
|
|
73
|
+
throw new Unrunnable('the configuration does not say that the database may be emptied, and setting a Background empties it');
|
|
74
|
+
}
|
|
75
|
+
async function run(reach, model, meaning, operation, kase, origin, heard) {
|
|
76
|
+
mayEmpty(reach.config);
|
|
77
|
+
const callers = callersOf(model, operation, kase);
|
|
78
|
+
await rested(reach, heard);
|
|
79
|
+
await heard.step({ doing: 'sets the Background', seed: kase.given.seed }, () => reach.config.background(kase.given.seed));
|
|
80
|
+
const { requester, witnesses } = await browsers(reach, callers, origin, heard);
|
|
81
|
+
const world = worldOf(model, kase);
|
|
82
|
+
heard.doing('observes, before');
|
|
83
|
+
const before = await observe(reach, model, requester, witnesses);
|
|
84
|
+
const input = typeof kase.input === 'string' ? meaning.value(kase.input, { before, world }, 'given') : kase.input;
|
|
85
|
+
heard.doing('calls');
|
|
86
|
+
const answer = await call(requester, operation, input);
|
|
87
|
+
// What an operation starts and does not wait for is part of what it brings about: the state is observed once it is done.
|
|
88
|
+
if (operation.entry.method !== 'GET' && answer.status < 400)
|
|
89
|
+
await rested(reach, heard);
|
|
90
|
+
heard.doing('observes, after');
|
|
91
|
+
const after = await observe(reach, model, requester, witnesses);
|
|
92
|
+
return [...inputMisfit(operation, kase, input, meaning), ...judge(operation, kase, { input, world, before, after, status: answer.status, body: answer.body }, meaning, reach.config.refusal)];
|
|
93
|
+
}
|
|
94
|
+
/** What a case decided, from what was found: told whole to who runs it, and kept without what was seen. */
|
|
95
|
+
export const outcomeOf = (kase, found, ms, wire = []) => ({ kase, findings: found.map(whole), kept: found.map((one) => one.says), ms, wire });
|
|
96
|
+
/** Runs a case. What keeps it from running at all is told as a finding, in other words than a failure of the product. */
|
|
97
|
+
export async function runCase(reach, model, meaning, operation, kase, at) {
|
|
98
|
+
const started = Date.now();
|
|
99
|
+
const heard = ears(at.listening ?? false);
|
|
100
|
+
const found = await run(reach, model, meaning, operation, kase, originOf(at.run, at.n), heard).catch((error) => [unrun(error)]);
|
|
101
|
+
return outcomeOf(kase, found, Date.now() - started, heard.wire);
|
|
102
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const ROBUST = ['all', 'no', 'only', 'generated'];
|
|
2
|
+
export const LEVELS = ['warn', 'info', 'debug', 'trace'];
|
|
3
|
+
const METHODS = ['GET', 'POST', 'PUT', 'DELETE'];
|
|
4
|
+
const YES = ['yes', 'true', '1', 'on'];
|
|
5
|
+
const NO = ['', 'no', 'false', '0', 'off'];
|
|
6
|
+
/** What was asked, and what of it cannot be understood: nothing is run on a guess. */
|
|
7
|
+
export function askedOf(env, flags = []) {
|
|
8
|
+
const problems = [];
|
|
9
|
+
const said = (name) => (env[name] ?? '').trim();
|
|
10
|
+
const yes = (name) => {
|
|
11
|
+
if (![...YES, ...NO].includes(said(name).toLowerCase()))
|
|
12
|
+
problems.push(`${name}=${said(name)}: yes or no`);
|
|
13
|
+
return YES.includes(said(name).toLowerCase());
|
|
14
|
+
};
|
|
15
|
+
const among = (name, known, otherwise) => {
|
|
16
|
+
const given = said(name).toLowerCase();
|
|
17
|
+
if (said(name) && !known.includes(given))
|
|
18
|
+
problems.push(`${name}=${said(name)}: one of ${known.filter((one) => one !== otherwise).join(', ')}`);
|
|
19
|
+
return said(name) && known.includes(given) ? given : otherwise;
|
|
20
|
+
};
|
|
21
|
+
const method = said('METHOD').toUpperCase();
|
|
22
|
+
if (method && !METHODS.includes(method))
|
|
23
|
+
problems.push(`METHOD=${said('METHOD')}: one of ${METHODS.join(', ')}`);
|
|
24
|
+
const asked = { operation: said('O'), method, kase: said('CASE'), robust: among('ROBUST', ROBUST, 'all'), failfast: yes('FAILFAST'), fast: yes('FAST') || flags.includes('--fast'), log: among('LOG_LEVEL', LEVELS, 'info') };
|
|
25
|
+
return { asked, problems };
|
|
26
|
+
}
|
|
27
|
+
const FLAGS = ['--check', '--fast'];
|
|
28
|
+
const REPORT = '--report=';
|
|
29
|
+
/**
|
|
30
|
+
* What the command is given, and what of it cannot be understood. A flag is held to what the
|
|
31
|
+
* environment is: one misspelt (`--chek`) would otherwise be a run where a reading was asked.
|
|
32
|
+
*/
|
|
33
|
+
export function commandOf(args) {
|
|
34
|
+
const flags = args.filter((one) => one.startsWith('-'));
|
|
35
|
+
const suites = args.filter((one) => !one.startsWith('-'));
|
|
36
|
+
const reports = flags.filter((flag) => flag.startsWith(REPORT)).map((flag) => flag.slice(REPORT.length));
|
|
37
|
+
const problems = [
|
|
38
|
+
...flags.filter((flag) => !FLAGS.includes(flag) && !flag.startsWith(REPORT)).map((flag) => `${flag}: one of ${FLAGS.join(', ')}, ${REPORT}<file>`),
|
|
39
|
+
...(reports.some((file) => !file) ? [`${REPORT}: the file the report is written to`] : []),
|
|
40
|
+
...(suites.length > 1 ? [`${suites.join(' ')}: one suite, a directory`] : []),
|
|
41
|
+
];
|
|
42
|
+
return { command: { suite: suites[0] ?? '.', check: flags.includes('--check'), ...(reports.at(-1) ? { report: reports.at(-1) } : {}) }, problems };
|
|
43
|
+
}
|
|
44
|
+
const holds = (text, part) => text.toLowerCase().includes(part.toLowerCase());
|
|
45
|
+
/** Whether an operation is one of those asked for: by its name, its file or its route, and by its method. */
|
|
46
|
+
export const operationAsked = (operation, asked) => holds(`${operation.file} ${operation.name} ${operation.entry.path}`, asked.operation) && (!asked.method || operation.entry.method === asked.method);
|
|
47
|
+
/**
|
|
48
|
+
* What cannot be read, of what is run: a run narrowed to some operations is not stopped by the
|
|
49
|
+
* file of another. A problem is that of the file it begins with, whole: what
|
|
50
|
+
* `boards/operations/Read.yml` cannot say is not what `keyboards/operations/Read.yml` cannot.
|
|
51
|
+
*/
|
|
52
|
+
export function problemsAsked(problems, operations, asked) {
|
|
53
|
+
const others = operations.filter((operation) => !operationAsked(operation, asked)).map((operation) => `${operation.file}: `);
|
|
54
|
+
return problems.filter((problem) => !others.some((file) => problem.startsWith(file)));
|
|
55
|
+
}
|
|
56
|
+
const KINDS = {
|
|
57
|
+
all: () => true,
|
|
58
|
+
no: (kase) => kase.kind === 'example',
|
|
59
|
+
only: (kase) => kase.kind === 'counterexample',
|
|
60
|
+
generated: (kase) => kase.generated,
|
|
61
|
+
};
|
|
62
|
+
/** The cases asked for, of those an operation has. */
|
|
63
|
+
export const casesAsked = (cases, asked) => cases.filter((kase) => KINDS[asked.robust](kase) && holds(kase.description, asked.kase));
|
|
64
|
+
/**
|
|
65
|
+
* Whether an operation that ran no case is told all the same: it has none at all, and that
|
|
66
|
+
* nothing shows it is a gap to tell. Not when the run was narrowed to some cases: it then says
|
|
67
|
+
* nothing of an operation, whether it has other cases or none.
|
|
68
|
+
*/
|
|
69
|
+
export const toldWithNoCase = (all, asked) => all.length === 0 && !asked.kase && asked.robust === 'all';
|
|
70
|
+
/** Whether a run is of the whole suite: one that is not says so, since it passes less. */
|
|
71
|
+
export const narrowed = (asked) => [asked.operation && `O=${asked.operation}`, asked.method && `METHOD=${asked.method}`, asked.kase && `CASE=${asked.kase}`, asked.robust !== 'all' && `ROBUST=${asked.robust}`].filter((one) => Boolean(one));
|
package/dist/starting.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// What a run needs before its first case: somewhere to write its report, the database it reads,
|
|
2
|
+
// a system that answers. Each that is missing is told in a sentence, as a `NotStarted`, and
|
|
3
|
+
// nothing is run: a run that dies on one of them after its cases has told nothing.
|
|
4
|
+
import { closeSync, openSync } from 'node:fs';
|
|
5
|
+
import { reader } from './world.js';
|
|
6
|
+
/** What keeps a run from starting: said in a line. */
|
|
7
|
+
export class NotStarted extends Error {
|
|
8
|
+
}
|
|
9
|
+
/** Why something failed, in a line: what is under a failure that only says it failed (`fetch failed`), and its code where it says nothing. */
|
|
10
|
+
export function why(error) {
|
|
11
|
+
const { message, code, cause } = (error ?? {});
|
|
12
|
+
if (cause)
|
|
13
|
+
return why(cause);
|
|
14
|
+
return (message || code || String(error)).split('\n')[0] ?? '';
|
|
15
|
+
}
|
|
16
|
+
/** A report can be written there: asked by opening the file as the run will, without touching what it holds. */
|
|
17
|
+
export function writable(file) {
|
|
18
|
+
try {
|
|
19
|
+
closeSync(openSync(file, 'a'));
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new NotStarted(`The report cannot be written to ${file}: ${why(error)}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** How the run reaches what it reads: the database, when the configuration names one. Its address is not told: it holds a password. */
|
|
26
|
+
export async function reachOf(suite, config, fast) {
|
|
27
|
+
if (suite.model.relations.length > 0 && !fast && !config.database)
|
|
28
|
+
throw new NotStarted('The state names relations, and the configuration no database to read them from.');
|
|
29
|
+
const unreached = (error) => {
|
|
30
|
+
throw new NotStarted(`The database cannot be reached: ${why(error)}`);
|
|
31
|
+
};
|
|
32
|
+
return { config, database: config.database ? await reader(config.database).catch(unreached) : null, relations: !fast };
|
|
33
|
+
}
|
|
34
|
+
/** The system answers at its front door, whatever it answers: asked once, so that a system that is not there is one sentence and not every case. */
|
|
35
|
+
export async function answering(config, withinMs = 15_000) {
|
|
36
|
+
const silent = (error) => {
|
|
37
|
+
throw new NotStarted(`The system does not answer at ${config.api}: ${why(error)}`);
|
|
38
|
+
};
|
|
39
|
+
const response = await fetch(config.api, { redirect: 'manual', signal: AbortSignal.timeout(withinMs) }).catch(silent);
|
|
40
|
+
await response.body?.cancel();
|
|
41
|
+
}
|
package/dist/suite.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
export const PRE = ['DomPre', 'ReqPre'];
|
|
5
|
+
export const POST = ['DomPost', 'ReqPost'];
|
|
6
|
+
/** The four that can be checked, then when an operation is performed without being asked: told, since one call shows nothing of it. */
|
|
7
|
+
export const KINDS = [...PRE, ...POST];
|
|
8
|
+
export const TRIGGER = 'ReqTrig';
|
|
9
|
+
/** The clauses an operation says, each under its key. */
|
|
10
|
+
export const SAID = [...KINDS, TRIGGER];
|
|
11
|
+
/** How a mark is written. */
|
|
12
|
+
export const MARKS = { x: 'checked', '+': 'complete', ' ': 'told' };
|
|
13
|
+
/** A suite that says nothing. */
|
|
14
|
+
export const NOTHING_SAID = { areas: [], agents: [], backgrounds: [], actors: [], world: {}, state: [], relations: [], definitions: [], conditions: [], types: [] };
|
|
15
|
+
/** Two sentences are the same whatever their case and spacing. */
|
|
16
|
+
export const sameSentence = (a, b) => normal(a) === normal(b);
|
|
17
|
+
const normal = (sentence) => sentence.trim().replace(/\s+/g, ' ').toLowerCase();
|
|
18
|
+
export const isPre = (clause) => PRE.includes(clause.kind);
|
|
19
|
+
/** The citizen of that name, among those of one kind. */
|
|
20
|
+
export const named = (all, name) => all.find((one) => one.name === name);
|
|
21
|
+
/** What each actor signs in with, by name: `world.actors`. */
|
|
22
|
+
export const credentialsOf = (model) => Object.fromEntries(model.actors.map((actor) => [actor.name, actor.with]));
|
|
23
|
+
/** Whether an agent is another, itself or through what it is: an Administrator is a Member, who is a Visitor. */
|
|
24
|
+
export function isA(agents, name, other, seen = []) {
|
|
25
|
+
if (name === other)
|
|
26
|
+
return true;
|
|
27
|
+
const next = named(agents, name)?.is;
|
|
28
|
+
return next !== undefined && !seen.includes(name) && isA(agents, next, other, [...seen, name]);
|
|
29
|
+
}
|
package/dist/words.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// The words an area says, as they are written, become citizens: its predicates and functions,
|
|
2
|
+
// its conditions, its types. Pure: what cannot be read is told as a problem, and never guessed.
|
|
3
|
+
import { citizenOf, listOf, sentenceOf } from './citizens.js';
|
|
4
|
+
import { placeOf } from './lines.js';
|
|
5
|
+
import { RESERVED, definitionsUsed } from './naming.js';
|
|
6
|
+
import { NO_REFUSAL, refuses, signatureOf, violatedOf } from './notation.js';
|
|
7
|
+
import { sameSentence } from './suite.js';
|
|
8
|
+
const FILES = { predicate: 'predicates', function: 'functions' };
|
|
9
|
+
const under = (where, problems) => problems.map((problem) => `${where}: ${problem}`);
|
|
10
|
+
/** A predicate or a function: its name says what it is given, `board(id)`, and its formaldef is in Elo. */
|
|
11
|
+
function definitionOf(kind, item, area, problems, source) {
|
|
12
|
+
const written = citizenOf(kind, item, problems, { formaldef: true });
|
|
13
|
+
if (!written.name || !written.formaldef)
|
|
14
|
+
return null;
|
|
15
|
+
try {
|
|
16
|
+
return { kind, ...signatureOf(written.name), description: written.description, formaldef: written.formaldef, area, source };
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
problems.push(`${kind} "${written.name}": ${error instanceof Error ? error.message : error}`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** The predicates and the functions of every area, each under a name of its own that nothing else has, and none said in terms of itself. */
|
|
24
|
+
export function definitionsOf(areas, states, problems) {
|
|
25
|
+
const read = (said, kind) => {
|
|
26
|
+
const mine = [];
|
|
27
|
+
const place = placeOf(`${said.area}/${FILES[kind]}.yml`, said.lines?.[FILES[kind]]);
|
|
28
|
+
const found = listOf('the file', said[FILES[kind]], mine).map((item, at) => definitionOf(kind, item, said.area, mine, place(at))).filter((one) => one !== null);
|
|
29
|
+
problems.push(...under(`${said.area}/${FILES[kind]}.yml`, mine));
|
|
30
|
+
return found;
|
|
31
|
+
};
|
|
32
|
+
const all = areas.flatMap((said) => [...read(said, 'predicate'), ...read(said, 'function')]);
|
|
33
|
+
const names = all.map((one) => one.name);
|
|
34
|
+
for (const name of new Set(names.filter((one, at) => names.indexOf(one) !== at)))
|
|
35
|
+
problems.push(`"${name}" is said twice, of the predicates and the functions`);
|
|
36
|
+
for (const one of all)
|
|
37
|
+
if (RESERVED.includes(one.name) || states.includes(one.name))
|
|
38
|
+
problems.push(`${one.kind} "${one.name}": the name is taken by ${states.includes(one.name) ? 'a state' : 'the suite'}`);
|
|
39
|
+
for (const one of all) {
|
|
40
|
+
try {
|
|
41
|
+
definitionsUsed(one.name, all);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
problems.push(error instanceof Error ? error.message : String(error));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return all;
|
|
48
|
+
}
|
|
49
|
+
/** A condition: a sentence with its formaldef, and for some how it is violated. Named after where it stands when it gives itself no name. */
|
|
50
|
+
function conditionOf(item, area, at, problems, source) {
|
|
51
|
+
try {
|
|
52
|
+
const { name, description, formaldef, mark, raw } = sentenceOf('a condition', item, ['violated']);
|
|
53
|
+
if (!formaldef)
|
|
54
|
+
throw new Error(`condition "${description}" says its "formaldef": what several operations say in the same words is decided once`);
|
|
55
|
+
if (mark)
|
|
56
|
+
problems.push(`condition "${description}" says no mark: the clause that says it does`);
|
|
57
|
+
const violated = raw.violated === undefined ? undefined : violatedOf(raw.violated);
|
|
58
|
+
if (violated && !refuses(violated.then))
|
|
59
|
+
problems.push(`condition "${description}": "violated": ${NO_REFUSAL}`);
|
|
60
|
+
return { name: name ?? `${area}/conditions/${at + 1}`, description, formaldef, area, source, ...(violated ? { violated } : {}) };
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
problems.push(error instanceof Error ? error.message : String(error));
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** The conditions of every area: a sentence is said once, wherever. */
|
|
68
|
+
export function conditionsOf(areas, problems) {
|
|
69
|
+
const all = areas.flatMap((said) => {
|
|
70
|
+
const mine = [];
|
|
71
|
+
const place = placeOf(`${said.area}/conditions.yml`, said.lines?.conditions);
|
|
72
|
+
const found = listOf('the file', said.conditions, mine).map((item, at) => conditionOf(item, said.area, at, mine, place(at))).filter((one) => one !== null);
|
|
73
|
+
problems.push(...under(`${said.area}/conditions.yml`, mine));
|
|
74
|
+
return found;
|
|
75
|
+
});
|
|
76
|
+
for (const [at, one] of all.entries())
|
|
77
|
+
if (all.findIndex((other) => sameSentence(other.description, one.description)) !== at)
|
|
78
|
+
problems.push(`condition "${one.description}" is said twice: its formaldef is given once`);
|
|
79
|
+
return all;
|
|
80
|
+
}
|
|
81
|
+
const DECLARED = /^([A-Z]\w*)\s*=\s*/;
|
|
82
|
+
const COMMENT = /^#\s?/;
|
|
83
|
+
/**
|
|
84
|
+
* The types an area declares, each a citizen: the comment right above it describes it, its name
|
|
85
|
+
* is what it declares, and what follows `=` is its formaldef, up to the next declaration or comment.
|
|
86
|
+
*/
|
|
87
|
+
export function typesOf(text, area, problems = []) {
|
|
88
|
+
const lines = text.split('\n');
|
|
89
|
+
const starts = lines.flatMap((line, at) => (DECLARED.test(line) ? [at] : []));
|
|
90
|
+
return starts.map((at) => {
|
|
91
|
+
let first = at;
|
|
92
|
+
while (first > 0 && COMMENT.test(lines[first - 1] ?? ''))
|
|
93
|
+
first--;
|
|
94
|
+
let last = at + 1;
|
|
95
|
+
while (last < lines.length && !DECLARED.test(lines[last] ?? '') && !COMMENT.test(lines[last] ?? ''))
|
|
96
|
+
last++;
|
|
97
|
+
const name = (lines[at] ?? '').match(DECLARED)?.[1] ?? '';
|
|
98
|
+
const description = lines.slice(first, at).map((line) => line.replace(COMMENT, '').trim()).join(' ').trim();
|
|
99
|
+
if (!description)
|
|
100
|
+
problems.push(`${area}/types.elo: type "${name}" says its description, in a comment right above it`);
|
|
101
|
+
return { name, description, formaldef: lines.slice(at, last).join('\n').replace(DECLARED, '').trimEnd(), area, source: `${area}/types.elo:${at + 1}` };
|
|
102
|
+
});
|
|
103
|
+
}
|