@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/README.md
CHANGED
|
@@ -2,36 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
**Specifies the operations of a system by their clauses, and runs them.**
|
|
4
4
|
|
|
5
|
-
A system does things when it is asked to: it
|
|
5
|
+
A system does things when it is asked to: it takes an expense back, invites a member, sends a reply. Each is an *operation*, and opspicy specifies one per file, in the terms of [KAOS](https://en.wikipedia.org/wiki/KAOS_(software_development)): the transition the operation makes, from what was not there to what is (`DomPre`, `DomPost`), and what the rules demand of it, every constraint on what it is given and what it makes (`ReqPre`, `ReqPost`), as sentences. [Which is which](doc/suite.md#dom-and-req-the-transition-and-the-rules) is the one thing to get right. A sentence is checked when it has a formal definition, its *formaldef*: an expression in [Elo](https://elo-lang.org), true or false of what can be observed before and after one call.
|
|
6
6
|
|
|
7
7
|
```yaml
|
|
8
|
-
name:
|
|
9
|
-
description: A member
|
|
8
|
+
name: RemoveExpense
|
|
9
|
+
description: A member takes back an expense they paid, as if it had never been.
|
|
10
10
|
agent: Member
|
|
11
|
-
entry:
|
|
12
|
-
input:
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
entry: DELETE /api/expenses/:id
|
|
12
|
+
input: ExpenseId
|
|
13
|
+
DomPre:
|
|
14
|
+
- (x) the expense is kept: expense(input.id) != null
|
|
15
|
+
DomPost:
|
|
16
|
+
- (x) the expense is kept no more: expense(input.id) == null
|
|
15
17
|
ReqPre:
|
|
16
18
|
- (x) the requester is signed in
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
# Of an expense that is kept: of one that is not, the DomPre says it.
|
|
20
|
+
- (x) the requester paid it: expense(input.id) == null || expense(input.id).paidBy == me
|
|
21
|
+
ReqPost:
|
|
22
|
+
- (x) it is one expense fewer: count(expenses) == count(old.expenses) - 1
|
|
23
|
+
- (x) the balances still sum to zero: balanced
|
|
24
|
+
- (x) each who shared it, the payer aside, owes their share less, to the cent: >-
|
|
25
|
+
let e = old.expense(input.id), n = count(e.sharedBy) in
|
|
26
|
+
all(e.sharedBy, w ~> w == me || abs((owed(w) - old.owed(w)) * n - e.amount) < n)
|
|
21
27
|
examples:
|
|
22
|
-
- when:
|
|
23
|
-
given: test/base, as
|
|
24
|
-
input: {
|
|
25
|
-
then:
|
|
28
|
+
- when: Ann takes back the groceries
|
|
29
|
+
given: test/base, as ann
|
|
30
|
+
input: { id: 1 }
|
|
31
|
+
then: 204
|
|
32
|
+
and:
|
|
33
|
+
- nobody owes Ann any more, and Ann owes Bob for the taxi: owed('ann') == -600 && owed('bob') == 600 && owed('cy') == 0
|
|
26
34
|
|
|
27
35
|
counterexamples:
|
|
28
|
-
- when:
|
|
29
|
-
for:
|
|
30
|
-
given: test/base, as
|
|
31
|
-
input: {
|
|
32
|
-
then:
|
|
36
|
+
- when: Ann takes back an expense nobody paid
|
|
37
|
+
for: the expense is kept
|
|
38
|
+
given: test/base, as ann
|
|
39
|
+
input: { id: 99 }
|
|
40
|
+
then: 404 expenses.unknown
|
|
41
|
+
|
|
42
|
+
- when: Bob takes back what Ann paid
|
|
43
|
+
for: the requester paid it
|
|
44
|
+
given: test/base, as bob
|
|
45
|
+
input: { id: 1 }
|
|
46
|
+
then: 403 expenses.notTheirs
|
|
33
47
|
```
|
|
34
48
|
|
|
49
|
+
It is one operation of [the example](#try-it), a splitter of a group's shared expenses.
|
|
50
|
+
|
|
35
51
|
One responsibility: *read a suite of such files, run each case against a running system through its front door, and say what does not hold.*
|
|
36
52
|
|
|
37
53
|
It knows nothing of the system: a suite tells it where the front door is, how somebody signs in and how a Background is set, in its [`config.ts`](doc/suite.md#the-configuration-configts). It comes after [webspicy](https://github.com/enspirit/webspicy), which specifies a web service route by route and looks at the answer: opspicy specifies it operation by operation, and looks at the state.
|
|
@@ -47,25 +63,43 @@ opspicy serve path/to/suite # http://127.0.0.1:8080: search it, read
|
|
|
47
63
|
|
|
48
64
|
`opspicy explorer path/to/suite` writes the same pages as one file, `explorer.html`, to open or to send. Neither needs the system the suite specifies, nor its `config.ts`: [the explorer](#the-explorer).
|
|
49
65
|
|
|
50
|
-
To run one, [`example/`](example/) holds a system, a
|
|
66
|
+
To run one, [`example/`](example/) holds a system, a splitter of a group's shared expenses, and the suite that specifies it. From a checkout, Node runs both as they are:
|
|
51
67
|
|
|
52
68
|
```sh
|
|
53
69
|
git clone https://github.com/enspirit/opspicy && cd opspicy && npm ci
|
|
54
|
-
node example/
|
|
55
|
-
export
|
|
70
|
+
node example/splitter.ts & # the system, on http://127.0.0.1:4000
|
|
71
|
+
export SPLITTER_API=http://127.0.0.1:4000 SPLITTER_MAY_BE_EMPTIED=yes
|
|
56
72
|
bin/opspicy example/suite # runs the suite
|
|
57
73
|
```
|
|
58
74
|
|
|
59
75
|
```
|
|
60
|
-
|
|
76
|
+
AddExpense — Member · POST /api/expenses · expenses/operations/AddExpense.yml
|
|
77
|
+
DomPre · the expense is not kept yet (told, not checked)
|
|
78
|
+
DomPost ✓ the expense is kept
|
|
61
79
|
ReqPre ✓ the requester is signed in
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
ReqPre ✓ it is shared among the group
|
|
81
|
+
ReqPost ✓ it is one expense more, as given, paid by the requester
|
|
82
|
+
ReqPost ✓ the balances still sum to zero
|
|
83
|
+
ReqPost ✓ each who shares it, the payer aside, owes their share more, to the cent
|
|
84
|
+
ReqPost ✓ nobody else's balance moves
|
|
85
|
+
✓ example: Bob pays a lunch for the three, which splits evenly
|
|
86
|
+
✗ example: Ann pays a dinner for the three, which leaves a cent over
|
|
87
|
+
ReqPost "the balances still sum to zero" does not hold after the call
|
|
88
|
+
✓ counterexample: the amount is nothing — for its type, ExpenseGiven
|
|
89
|
+
✓ counterexample: it is shared with somebody out of the group — for "it is shared among the group"
|
|
65
90
|
✓ counterexample: called as visitor — for "the requester is signed in" [from a condition]
|
|
66
91
|
```
|
|
67
92
|
|
|
68
|
-
|
|
93
|
+
Its four specifications are small. Each operation says first the transition it makes, one `DomPre` and one `DomPost` (an expense is not kept, then it is), then what the rules demand of it, which is more than what one call changes: the balances of the group always sum to zero, a member pays back no more than they owe nor to somebody who is owed less, and only who paid an expense takes it back.
|
|
94
|
+
|
|
95
|
+
| | Its transition | What the rules demand of it |
|
|
96
|
+
| --- | --- | --- |
|
|
97
|
+
| [`AddExpense`](example/suite/specification/expenses/operations/AddExpense.yml) | The expense is not kept yet; then it is. | Shared among the group; an amount above zero, which its type says, `Int(c \| c > 0)`, and a counterexample `for` the type shows refused. It is one expense more, as given; each who shares it owes their share more, to the cent; nobody else's balance moves; another member sees it too. |
|
|
98
|
+
| [`SettleUp`](example/suite/specification/expenses/operations/SettleUp.yml) | The requester has a debt; then a smaller one. | The requester owes at least the amount, and whom it is paid to is owed at least that much: constraints on the state, not on the input. Both balances move by exactly that much, and no expense is made. |
|
|
99
|
+
| [`RemoveExpense`](example/suite/specification/expenses/operations/RemoveExpense.yml) | The expense is kept; then it is not. | Only who paid it, and who shared it owes their share less. |
|
|
100
|
+
| [`ListBalances`](example/suite/specification/expenses/observations/ListBalances.yml) | None: an observation makes no transition. | What it tells is the state, and sums to zero. |
|
|
101
|
+
|
|
102
|
+
The splitter has one fault, on purpose: an amount that does not split evenly leaves a cent over, which nobody is made to owe. Its answer is right, and so is every share, to the cent: only the sum of the balances shows it, and only on an uneven split, which is what a run finds. Then, to read the suite rather than its files:
|
|
69
103
|
|
|
70
104
|
```sh
|
|
71
105
|
bin/opspicy example/suite --report=last.json # the same run, kept
|
|
@@ -81,8 +115,8 @@ bin/opspicy serve example/suite --report=last.json --api # http://127.0.0
|
|
|
81
115
|
| | The state is observed: `_.before`. |
|
|
82
116
|
| **When** | The operation is called once, through the front door, with the input. What it started and did not wait for is waited for. |
|
|
83
117
|
| **Then** | The state is observed again: `_.after`. |
|
|
84
|
-
| an example | Every precondition held before the call · the answer has the status said, and is of the type said, when the operation names one: a text is not a number there, nor true or false · every postcondition holds · an observation, and any route entered by `GET`, changed nothing. |
|
|
85
|
-
| a counterexample |
|
|
118
|
+
| an example | Every precondition held before the call · the answer has the status said, and is of the type said, when the operation names one: a text is not a number there, nor true or false · every postcondition holds · every state that changed is one the operation [controls](doc/derived.md#what-an-operation-may-change) · an observation, and any route entered by `GET`, changed nothing. |
|
|
119
|
+
| a counterexample | Its input is of the operation's type, unless it is `for` that type, on purpose · the precondition it is `for` did not hold, and every other did (one that a condition gives is not asked the second: who violates a condition, somebody not signed in say, violates more) · it is refused with the status and the code said, as the type refusals have · **nothing changed**: every route of the state and every relation is as it was. |
|
|
86
120
|
|
|
87
121
|
Nothing is instrumented: a precondition is never *made* to hold. A case chooses its Background, and what is checked is that the preconditions are what the case says they are.
|
|
88
122
|
|
|
@@ -91,7 +125,7 @@ Nothing is instrumented: a precondition is never *made* to hold. A case chooses
|
|
|
91
125
|
| | Checks | Reads |
|
|
92
126
|
| --- | --- | --- |
|
|
93
127
|
| **complete** | Every clause that has a formaldef. | The routes of the state, and the relations of the database. |
|
|
94
|
-
| **fast** (`--fast`) | What must hold: every clause but those marked `(+)`, which it tells. |
|
|
128
|
+
| **fast** (`--fast`) | What must hold: every clause but those marked `(+)`, which it tells. | Of the routes of the state, those [each operation monitors and controls](doc/derived.md#the-fast-run), and no relation: a run is as long as what the operations touch. "Nothing changed" is then said of those routes alone. What the configuration's `atRest` asks of the database is still asked. |
|
|
95
129
|
|
|
96
130
|
The fast run is the system as a black box: it passes whatever the schema is, so it is the one that must stay as it is when the system is rebuilt inside. A clause that reads the database is checked in the complete run only, and [says so](doc/suite.md#an-operation-specificationareaoperationsoperationyml-and-an-observation-beside-it).
|
|
97
131
|
|
|
@@ -102,7 +136,8 @@ A command, a notation, and an image.
|
|
|
102
136
|
### The command
|
|
103
137
|
|
|
104
138
|
```sh
|
|
105
|
-
opspicy
|
|
139
|
+
opspicy # says how it is used; so do --help, -h, and `help [explorer|serve]`
|
|
140
|
+
opspicy <suite> # runs the suite of that directory: `opspicy .` runs this one
|
|
106
141
|
opspicy [<suite>] --check # reads it, and says what cannot be read: no system needed
|
|
107
142
|
opspicy [<suite>] --fast # the fast run
|
|
108
143
|
opspicy [<suite>] --report=<file> # also writes what the run decided, as JSON, for the explorer
|
|
@@ -111,8 +146,12 @@ opspicy explorer [<suite>] [--report=<file>] [--out=explorer.html] [--name=<name
|
|
|
111
146
|
opspicy serve [<suite>] [--report=<file>] [--name=<name>] [--version=<version>] [--runner=<command>] [--host=127.0.0.1] [--port=8080]
|
|
112
147
|
# the same wiki, served read-only, re-read when the suite changes
|
|
113
148
|
opspicy serve [<suite>] --api … # the same, and it runs what its page asks: on this machine only
|
|
149
|
+
opspicy upgrade [<suite>] # rewrites a suite of an earlier opspicy, in place: CHANGELOG.md says what changed
|
|
150
|
+
opspicy --version # the version, and so does -v
|
|
114
151
|
```
|
|
115
152
|
|
|
153
|
+
Given options only, the suite is the directory it is run in: `opspicy --check` reads that one. Each sub-command says how it is used, `opspicy serve --help`.
|
|
154
|
+
|
|
116
155
|
There are three ways to have it, and it is the same command in each:
|
|
117
156
|
|
|
118
157
|
| | |
|
|
@@ -127,7 +166,7 @@ What of the suite is run, and how much of it is told, is asked through the envir
|
|
|
127
166
|
|
|
128
167
|
| | |
|
|
129
168
|
| --- | --- |
|
|
130
|
-
| `O=
|
|
169
|
+
| `O=expenses` | Only the operations whose name, file or route holds that text: `O=AddExpense`, `O=expenses/`, `O=/api/expenses`. |
|
|
131
170
|
| `METHOD=DELETE` | Only those entered by that method. |
|
|
132
171
|
| `CASE=blank` | Only the cases whose `when` holds that text. |
|
|
133
172
|
| `ROBUST=no\|only\|generated` | Only the examples; only the counterexamples; only those the conditions give. |
|
|
@@ -135,7 +174,7 @@ What of the suite is run, and how much of it is told, is asked through the envir
|
|
|
135
174
|
| `FAST=yes` | [The fast run](#two-runs); `--fast` says the same. |
|
|
136
175
|
| `LOG_LEVEL=DEBUG` | Also shows, under each case, the Background it was set in, then what it sent and what it was answered. `TRACE` adds everything around, in a line each and in the order it happened: each wait for the server to be at rest, who signed in, and what each route of the state told whom, before and after. Each of these lines begins with how long that step took: putting the database in the seed, a wait, a call. What the runner sends and is answered to sign an actor in is never shown; a case that is itself a sign-in is shown as any case is. `WARN` tells only the cases that fail. |
|
|
137
176
|
|
|
138
|
-
They combine: `O=
|
|
177
|
+
They combine: `O=expenses ROBUST=no FAILFAST=yes LOG_LEVEL=DEBUG`. What is not understood stops the run before anything is called: `ROBUST=maybe`, a `LOG_LEVEL` that is none of `WARN`, `INFO`, `DEBUG` and `TRACE`, a flag the command does not have, a second directory. So does asking for what no case is. A run that was narrowed says so in its last lines.
|
|
139
178
|
|
|
140
179
|
It answers 0 when every case that was run passes, 1 when one does not, and 2 when nothing could be run, with a sentence saying why and before any case is: the suite cannot be read; it has no `config.ts`, or one that fails; the configuration does not say the database may be emptied; the report cannot be written where it is asked; the database or the system does not answer. The system is asked once for that, `GET` on its front door, whatever it answers.
|
|
141
180
|
|
|
@@ -147,16 +186,16 @@ A system that stops answering during the run is not that: each case then could n
|
|
|
147
186
|
|
|
148
187
|
| Tag | Is |
|
|
149
188
|
| --- | --- |
|
|
150
|
-
| `0.
|
|
189
|
+
| `0.3.0` | The version tagged `v0.3.0`: the image of that commit, as it was tested. Name one of these. |
|
|
151
190
|
| `latest`, `sha-<commit>` | The main branch, and one commit of it. |
|
|
152
191
|
|
|
153
192
|
**As a tool**, on a suite that is mounted:
|
|
154
193
|
|
|
155
194
|
```sh
|
|
156
|
-
docker run --rm -v "$PWD":/suite:ro enspirit/opspicy:0.
|
|
157
|
-
docker run --rm -v "$PWD":/suite:ro enspirit/opspicy:0.
|
|
158
|
-
docker run --rm -v "$PWD":/suite enspirit/opspicy:0.
|
|
159
|
-
docker run --rm -v "$PWD":/suite:ro -p 127.0.0.1:8080:8080 enspirit/opspicy:0.
|
|
195
|
+
docker run --rm -v "$PWD":/suite:ro enspirit/opspicy:0.3.0 opspicy --check
|
|
196
|
+
docker run --rm -v "$PWD":/suite:ro enspirit/opspicy:0.3.0 tsc -p . # type-checks its config.ts
|
|
197
|
+
docker run --rm -v "$PWD":/suite enspirit/opspicy:0.3.0 opspicy explorer --out=explorer.html
|
|
198
|
+
docker run --rm -v "$PWD":/suite:ro -p 127.0.0.1:8080:8080 enspirit/opspicy:0.3.0 opspicy serve --host=0.0.0.0
|
|
160
199
|
```
|
|
161
200
|
|
|
162
201
|
The last one is read-only: `--api` is offered on the machine the server runs on, which a container is not.
|
|
@@ -164,7 +203,7 @@ The last one is read-only: `--api` is offered on the machine the server runs on,
|
|
|
164
203
|
**As the base of a suite's image**, where the system is reached: on the network of its stack, say.
|
|
165
204
|
|
|
166
205
|
```dockerfile
|
|
167
|
-
FROM enspirit/opspicy:0.
|
|
206
|
+
FROM enspirit/opspicy:0.3.0
|
|
168
207
|
COPY . /suite
|
|
169
208
|
CMD ["tail", "-f", "/dev/null"] # it sleeps, and `opspicy` is run in it
|
|
170
209
|
```
|
|
@@ -178,14 +217,16 @@ A directory: a `config.ts`, which says how the suite meets the system, and a `sp
|
|
|
178
217
|
```
|
|
179
218
|
config.ts
|
|
180
219
|
specification/
|
|
181
|
-
|
|
220
|
+
system.yml agents.yml state.yml the system
|
|
221
|
+
areas.yml and a directory per area, below the specification
|
|
222
|
+
world.yml backgrounds.yml testing
|
|
182
223
|
_shared/ predicates.yml functions.yml conditions.yml types.elo
|
|
183
224
|
<area>/ predicates.yml functions.yml conditions.yml types.elo
|
|
184
225
|
operations/<Operation>.yml
|
|
185
226
|
observations/<Observation>.yml
|
|
186
227
|
```
|
|
187
228
|
|
|
188
|
-
Everything it says is a **citizen**: a name, a description, and for some a formaldef. **[`doc/suite.md`](doc/suite.md) is the reference**: [the metamodel](doc/suite.md#the-metamodel-citizens), [an operation's file](doc/suite.md#an-operation-specificationareaoperationsoperationyml-and-an-observation-beside-it), [what a formaldef reads](doc/suite.md#a-formaldef), [the
|
|
229
|
+
Everything it says is a **citizen**: a name, a description, and for some a formaldef. **[`doc/suite.md`](doc/suite.md) is the reference**: [the metamodel](doc/suite.md#the-metamodel-citizens), [an operation's file](doc/suite.md#an-operation-specificationareaoperationsoperationyml-and-an-observation-beside-it), [what a formaldef reads](doc/suite.md#a-formaldef), [the files at the root, one section each](doc/suite.md#the-files-at-the-root-one-file-one-section), [what an area says](doc/suite.md#what-an-area-says-predicatesyml-functionsyml-conditionsyml-typeselo), and [the configuration](doc/suite.md#the-configuration-configts).
|
|
189
230
|
|
|
190
231
|
### The explorer
|
|
191
232
|
|
|
@@ -193,6 +234,8 @@ A wiki of a suite, as one HTML document that fetches nothing: the specification,
|
|
|
193
234
|
|
|
194
235
|
**[`doc/explorer.md`](doc/explorer.md) is its reference**: its pages, [the notes and the review file](doc/explorer.md#notes-and-the-review-file), [calling an operation](doc/explorer.md#calling-an-operation), [running a case](doc/explorer.md#running-a-case), [the API](doc/explorer.md#served-with---api), and what the document says to its own script.
|
|
195
236
|
|
|
237
|
+
**[`doc/derived.md`](doc/derived.md) is where every rule opspicy derives a category by is written**, apart from what a suite says: which counterexamples a condition gives, what a gap is, what the fast run leaves out, the kind of a type, the result of an operation, what is masked. A rule that is not there is not one opspicy follows.
|
|
238
|
+
|
|
196
239
|
## Depends on
|
|
197
240
|
|
|
198
241
|
| | |
|
|
@@ -212,13 +255,13 @@ A wiki of a suite, as one HTML document that fetches nothing: the specification,
|
|
|
212
255
|
2. **Act on the system but through its front door**, and through what the configuration gives it to set a Background.
|
|
213
256
|
3. **Write the database.** It is opened to read and nothing else.
|
|
214
257
|
4. **Make a precondition hold.** A case that does not start where it says it does is a finding, not something to arrange.
|
|
215
|
-
5. **Pass what it did not check.** A sentence with no formaldef is reported as told; a
|
|
258
|
+
5. **Pass what it did not check.** A sentence with no formaldef is reported as told; an operation that does not say its transition (no `DomPre` or no `DomPost`), a `ReqPre` nothing violates and an operation nothing shows are reported as gaps.
|
|
216
259
|
|
|
217
260
|
## Harness
|
|
218
261
|
|
|
219
262
|
```sh
|
|
220
263
|
npm ci
|
|
221
|
-
npm run typecheck # everything, example/
|
|
264
|
+
npm run typecheck # everything, example/splitter.ts included
|
|
222
265
|
npm test # needs neither a system nor a browser
|
|
223
266
|
npm run test:browser # needs Chrome: the one installed, or the executable CHROME names
|
|
224
267
|
npm run test:package # needs the registry: installs what would be published, and runs it
|
|
@@ -227,12 +270,13 @@ npm run test:package # needs the registry: installs what would be published, a
|
|
|
227
270
|
| What | Is held by |
|
|
228
271
|
| --- | --- |
|
|
229
272
|
| What reads a suite ([`notation`](src/notation.ts), [`citizens`](src/citizens.ts), [`modelling`](src/modelling.ts), [`words`](src/words.ts), [`lines`](src/lines.ts), [`reading`](src/reading.ts), and [`files`](src/files.ts) on a directory made for the test), names ([`naming`](src/naming.ts)), plans ([`planning`](src/planning.ts)), chooses what is run ([`selecting`](src/selecting.ts)), judges ([`judging`](src/judging.ts)) and tells ([`report`](src/report.ts), [`report-file`](src/report-file.ts)) | Pure, and tables of cases with no server and no mock: [`test/`](test/). |
|
|
230
|
-
| What sets a Background, calls and observes ([`world`](src/world.ts), [`running`](src/running.ts)), and the command | Cases run over the wire against
|
|
273
|
+
| What sets a Background, calls and observes ([`world`](src/world.ts), [`running`](src/running.ts)), and the command | Cases run over the wire against a keeper of boards, [`test/boards/`](test/boards/), started in the test's own process: a small real server, and the suite that specifies it. |
|
|
274
|
+
| The example | [`test/example.test.ts`](test/example.test.ts): the suite of [`example/`](example/) reads, and a run of it against the splitter finds its one fault, and nothing else. |
|
|
231
275
|
| What writes the explorer ([`src/explorer/`](src/explorer/)) and what its API answers | The same: pure for the document, over the wire for the API. |
|
|
232
276
|
| What the page's script decides: what a search finds and in what order, the review file, what a call sends and the command that says it ([`src/explorer/script/`](src/explorer/script/)) | `test/script*.test.ts`, which read the script as the page does; the copied command is run through a shell, with a stand-in for `curl`. |
|
|
233
277
|
| What the script does to the page | [`test/browser/`](test/browser/): a headless Chrome, driven with `playwright-core`, on the document opened by `file://` as it is used, and served with its API. They **fail** with a sentence saying so when there is no Chrome, never pass unchecked. |
|
|
234
278
|
| Which files the command runs, and what it hands them ([`bin/entry.js`](bin/entry.js)) | A table of cases: [`test/launcher.test.ts`](test/launcher.test.ts). |
|
|
235
|
-
| The package | [`test/package/`](test/package/): `npm pack`, `npm install` of that file in a directory outside the checkout, then the `opspicy` npm put there, on the
|
|
279
|
+
| The package | [`test/package/`](test/package/): `npm pack`, `npm install` of that file in a directory outside the checkout, then the `opspicy` npm put there, on the suite of the keeper of boards: `--check`, `explorer`, `serve`, a run against the keeper, and a `config.ts` type-checked against what the package declares. |
|
|
236
280
|
| The image | CI builds it, type-checks the example's suite in it and runs it there. |
|
|
237
281
|
| What these documents link to | [`test/links.test.ts`](test/links.test.ts): every link, and every heading one names, exists. |
|
|
238
282
|
|
|
@@ -253,7 +297,7 @@ What the notation cannot say yet:
|
|
|
253
297
|
- **One call per case.** That a new password opens the account, that a link is good once: each is shown by what the one call left in the state, or told.
|
|
254
298
|
- **One precondition violated per counterexample**, so the order of two refusals is said nowhere.
|
|
255
299
|
- **What is answered is its status and its body.** A cookie cleared, a header set, a file that is neither JSON nor text: told only.
|
|
256
|
-
- **A member is checked where a type says what there is.** Elo's checker reads a formaldef under the types of the suite, and only a member that no type has is told: what may be `null` and is read as if it were not is left to the run. What a function is given has no type, so `withId(
|
|
300
|
+
- **A member is checked where a type says what there is.** Elo's checker reads a formaldef under the types of the suite, and only a member that no type has is told: what may be `null` and is read as if it were not is left to the run. What a function is given has no type, so `withId(expenses, 1).amout` is read, and gives nothing.
|
|
257
301
|
- **A predicate or a function is said in Elo, which decides and does not ask.** What a formaldef reads was observed before it is decided: neither can call the system.
|
|
258
302
|
- **What an area says is known to every area**: a condition by its sentence, a predicate, a function and a type by their name. The directory says where a word is at home, not who may say it. The same words written elsewhere with a formaldef of their own make that file unreadable, and the same words written with none take the formaldef silently.
|
|
259
303
|
- **A trigger is told.** `ReqTrig` says when an operation is performed without being asked, and one call shows nothing of it.
|
package/bin/entry.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// the launcher is: installed, both are under a node_modules, where Node strips no types.
|
|
4
4
|
|
|
5
5
|
/** The file of each sub-command, from src/ or dist/, without its extension; the runner is asked by none. */
|
|
6
|
-
const ENTRIES = { explorer: 'explorer/build', serve: 'explorer/serve' };
|
|
6
|
+
const ENTRIES = { explorer: 'explorer/build', serve: 'explorer/serve', upgrade: 'upgrade' };
|
|
7
7
|
const RUNNER = 'main';
|
|
8
8
|
|
|
9
9
|
/** Where Node refuses to run TypeScript: its own rule, a directory of that name anywhere above. */
|
|
@@ -25,3 +25,24 @@ export function entryOf(args, { at, sources }) {
|
|
|
25
25
|
const [directory, extension] = sources && !UNDER_NODE_MODULES.test(at) ? ['src', 'ts'] : ['dist', 'js'];
|
|
26
26
|
return { file: `${directory}/${asked ?? RUNNER}.${extension}`, args: asked ? args.slice(1) : args };
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
const HELP = ['--help', '-h'];
|
|
30
|
+
const VERSION = ['--version', '-v'];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* What the command is asked to say of itself, when it is: its help, with nothing to do or when
|
|
34
|
+
* asked (`--help` or `-h` anywhere, `help` first), of the sub-command it names; or its version,
|
|
35
|
+
* asked alone. Nothing otherwise, and the command runs. A suite whose directory is named `help` is
|
|
36
|
+
* named otherwise: ./help.
|
|
37
|
+
*
|
|
38
|
+
* @param {string[]} args what the command was given
|
|
39
|
+
* @returns {'opspicy' | 'explorer' | 'serve' | 'upgrade' | 'version' | null}
|
|
40
|
+
*/
|
|
41
|
+
export function helpOf(args) {
|
|
42
|
+
if (args.length === 0) return 'opspicy';
|
|
43
|
+
if (args.length === 1 && VERSION.includes(args[0])) return 'version';
|
|
44
|
+
const [first, ...rest] = args;
|
|
45
|
+
const sub = (name) => (Object.hasOwn(ENTRIES, name ?? '') ? name : 'opspicy');
|
|
46
|
+
if (first === 'help') return sub(rest[0]);
|
|
47
|
+
return args.some((one) => HELP.includes(one)) ? sub(first) : null;
|
|
48
|
+
}
|
package/bin/help.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// What `opspicy` says of itself: with nothing to do, or when asked (--help, -h, help), of the
|
|
2
|
+
// command or of one sub-command; and its version. JavaScript, as the launcher that prints it is,
|
|
3
|
+
// and pure: test/launcher.test.ts reads it.
|
|
4
|
+
|
|
5
|
+
const DOCUMENTATION = 'https://github.com/enspirit/opspicy';
|
|
6
|
+
|
|
7
|
+
const OPSPICY = `opspicy {version}: specifies the operations of a system by their clauses, and runs them.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
opspicy <suite> [options] run a suite against the system it specifies
|
|
11
|
+
opspicy explorer [<suite>] [options] write the suite's explorer, one HTML file
|
|
12
|
+
opspicy serve [<suite>] [options] serve the suite's explorer over HTTP
|
|
13
|
+
opspicy upgrade [<suite>] rewrite a suite written for an earlier opspicy
|
|
14
|
+
opspicy help [explorer | serve | upgrade] show this help, or that of a sub-command
|
|
15
|
+
|
|
16
|
+
A suite is a directory holding a config.ts and a specification/. Given options only,
|
|
17
|
+
the suite is the current directory: \`opspicy --check\` reads the one you are in.
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
--check read the suite and say what cannot be read; call nothing
|
|
21
|
+
--fast the fast run: every clause but those marked (+), and no relation
|
|
22
|
+
--report=<file> also write what the run decided, as JSON, for the explorer
|
|
23
|
+
-h, --help show this help
|
|
24
|
+
-v, --version show the version
|
|
25
|
+
|
|
26
|
+
Environment, to narrow a run or tell more of it:
|
|
27
|
+
O=<text> only the operations whose name, file or route holds it
|
|
28
|
+
METHOD=<method> only those entered by that method: GET, POST, PUT or DELETE
|
|
29
|
+
CASE=<text> only the cases whose \`when\` holds it
|
|
30
|
+
ROBUST=<which> no: the examples only · only: the counterexamples only ·
|
|
31
|
+
generated: only the counterexamples the conditions give
|
|
32
|
+
FAILFAST=yes stop at the first case that fails
|
|
33
|
+
FAST=yes the fast run, as --fast
|
|
34
|
+
LOG_LEVEL=<level> WARN: only what fails · INFO (default) · DEBUG: what each case
|
|
35
|
+
sent and was answered · TRACE: every step, timed
|
|
36
|
+
|
|
37
|
+
Exit status:
|
|
38
|
+
0 every case that was run passes
|
|
39
|
+
1 a case does not pass
|
|
40
|
+
2 nothing could be run: the suite cannot be read, its config.ts fails or does
|
|
41
|
+
not say the database may be emptied, or its system does not answer
|
|
42
|
+
|
|
43
|
+
Examples:
|
|
44
|
+
opspicy example/suite --check
|
|
45
|
+
O=AddExpense LOG_LEVEL=DEBUG opspicy example/suite
|
|
46
|
+
opspicy example/suite --report=last.json
|
|
47
|
+
opspicy explorer example/suite --report=last.json
|
|
48
|
+
|
|
49
|
+
Documentation: ${DOCUMENTATION}`;
|
|
50
|
+
|
|
51
|
+
/** What the explorer and the served explorer both read. */
|
|
52
|
+
const ABOUT_THE_SUITE = ` --report=<file> the report of a run (opspicy --report), shown beside each case
|
|
53
|
+
--name=<name> the name of the specification (by default, its directory's)
|
|
54
|
+
--version=<version> its version, which the review file says
|
|
55
|
+
--runner=<command> the command the page gives to run a case (opspicy <suite>)`;
|
|
56
|
+
|
|
57
|
+
const EXPLORER = `opspicy explorer [<suite>] [options]
|
|
58
|
+
|
|
59
|
+
Writes the wiki of a suite as one standalone HTML file: search it, read it, take notes
|
|
60
|
+
and save them as review.md, offline. It needs neither the system nor the suite's
|
|
61
|
+
config.ts. The suite is the current directory when none is named.
|
|
62
|
+
|
|
63
|
+
Options:
|
|
64
|
+
--out=<file> where it is written (explorer.html)
|
|
65
|
+
${ABOUT_THE_SUITE}
|
|
66
|
+
-h, --help show this help
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
opspicy explorer example/suite --report=last.json --out=explorer.html
|
|
70
|
+
|
|
71
|
+
Documentation: ${DOCUMENTATION}/blob/main/doc/explorer.md`;
|
|
72
|
+
|
|
73
|
+
const SERVE = `opspicy serve [<suite>] [options]
|
|
74
|
+
|
|
75
|
+
Serves the same wiki over HTTP, read-only, written again when the suite changes. Notes
|
|
76
|
+
are saved as review.md, beside the specification. The suite is the current directory
|
|
77
|
+
when none is named. Stop it with Ctrl-C.
|
|
78
|
+
|
|
79
|
+
Options:
|
|
80
|
+
--host=<host> where it listens (127.0.0.1; 0.0.0.0 in a container)
|
|
81
|
+
--port=<port> the port (8080; 0 for any free one)
|
|
82
|
+
--api also run what the page asks: one case, or a call as an actor.
|
|
83
|
+
It meets the system through the suite's config.ts, and running
|
|
84
|
+
a case empties its database: offered on this machine only.
|
|
85
|
+
${ABOUT_THE_SUITE}
|
|
86
|
+
-h, --help show this help
|
|
87
|
+
|
|
88
|
+
Example:
|
|
89
|
+
opspicy serve example/suite --report=last.json --api
|
|
90
|
+
|
|
91
|
+
Documentation: ${DOCUMENTATION}/blob/main/doc/explorer.md`;
|
|
92
|
+
|
|
93
|
+
const UPGRADE = `opspicy upgrade [<suite>]
|
|
94
|
+
|
|
95
|
+
Rewrites, in place, the files of a suite written for an earlier opspicy in the form this one
|
|
96
|
+
reads, and says what it changed: comments, order and quotes are kept. Then it says what it found
|
|
97
|
+
and cannot decide (a counterexample whose input is not of its operation's type), and, the first
|
|
98
|
+
time, what changed that no file shows. Run again, it finds nothing to rewrite. The suite is the
|
|
99
|
+
current directory when none is named. Commit before, and read the difference after.
|
|
100
|
+
|
|
101
|
+
From 0.1 and 0.2: areas.yml, agents.yml and backgrounds.yml, a list each, become a map of their
|
|
102
|
+
description and their list.
|
|
103
|
+
|
|
104
|
+
Documentation: ${DOCUMENTATION}/blob/main/CHANGELOG.md`;
|
|
105
|
+
|
|
106
|
+
const TEXTS = { opspicy: OPSPICY, explorer: EXPLORER, serve: SERVE, upgrade: UPGRADE };
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* What is printed for what helpOf (entry.js) found asked.
|
|
110
|
+
*
|
|
111
|
+
* @param {'opspicy' | 'explorer' | 'serve' | 'upgrade' | 'version'} asked
|
|
112
|
+
* @param {string} version the version of the package
|
|
113
|
+
* @returns {string}
|
|
114
|
+
*/
|
|
115
|
+
export const helpText = (asked, version) => (asked === 'version' ? `opspicy ${version}` : TEXTS[asked].replace('{version}', version));
|
package/bin/opspicy
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// opspicy
|
|
2
|
+
// opspicy <suite> [--check] [--fast] [--report=<file>] runs the suite, or reads it (main)
|
|
3
3
|
// opspicy explorer [<suite>] [--out=<file>] … writes its explorer, one file (explorer/build)
|
|
4
4
|
// opspicy serve [<suite>] [--port=<port>] [--api] … serves its explorer (explorer/serve)
|
|
5
|
+
// opspicy, opspicy --help, opspicy help [explorer|serve] says how it is used (help.js)
|
|
5
6
|
//
|
|
6
|
-
// The suite is a directory: this one when
|
|
7
|
+
// The suite is a directory: this one when only options are given. Each of the three is a file that reads
|
|
7
8
|
// the arguments of its process: this one says which (entry.js), takes the sub-command away, and
|
|
8
9
|
// runs it in this same process. From a checkout and in the image that file is TypeScript, of
|
|
9
10
|
// src/, which Node runs as it is; installed as a package it is the JavaScript of dist/.
|
|
10
11
|
//
|
|
11
12
|
// Node, not a shell: the one command is the same on macOS, Linux and Windows.
|
|
12
|
-
import { existsSync } from 'node:fs';
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
13
14
|
import { fileURLToPath } from 'node:url';
|
|
14
|
-
import { entryOf } from './entry.js';
|
|
15
|
+
import { entryOf, helpOf } from './entry.js';
|
|
16
|
+
import { helpText } from './help.js';
|
|
15
17
|
|
|
16
18
|
const root = new URL('../', import.meta.url);
|
|
19
|
+
const help = helpOf(process.argv.slice(2));
|
|
20
|
+
if (help) {
|
|
21
|
+
const { version } = JSON.parse(readFileSync(new URL('package.json', root), 'utf8'));
|
|
22
|
+
console.log(helpText(help, version));
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
17
25
|
const { file, args } = entryOf(process.argv.slice(2), { at: fileURLToPath(root), sources: existsSync(new URL('src/main.ts', root)) });
|
|
18
26
|
process.argv.splice(2, Infinity, ...args);
|
|
19
27
|
await import(new URL(file, root).href);
|
|
@@ -14,36 +14,44 @@ function metaOf(wiki, about) {
|
|
|
14
14
|
return { name: about.name, ...(about.version ? { version: about.version } : {}), generated: about.generated, runner: about.runner, run };
|
|
15
15
|
}
|
|
16
16
|
const THEMES = '<select id="thm" aria-label="Theme"><option value="">System theme</option><option value="light">Light</option><option value="dark">Dark</option></select>';
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/** The name the explorer goes by: that of the specified system, as its specification says it, or the name it was given. */
|
|
18
|
+
const nameOf = (wiki, about) => wiki.system.name ?? about.name;
|
|
19
|
+
const navOf = (wiki, about) => `<nav class="side" aria-label="Explorer">
|
|
20
|
+
<a class="brand" href="#home"><i aria-hidden="true"></i>${esc(nameOf(wiki, about))}</a>
|
|
19
21
|
<div class="searchbox"><input class="find" id="q" type="search" placeholder="Search everything" aria-label="Search every page, citizen and formaldef" aria-keyshortcuts="/" autocomplete="off"><kbd>/</kbd></div>
|
|
20
|
-
<p class="chap">
|
|
22
|
+
<p class="chap">The system</p>
|
|
21
23
|
<div class="nav">
|
|
22
24
|
${link('#home', 'Overview')}
|
|
23
|
-
${link('#agents', 'Agents
|
|
24
|
-
${link('#
|
|
25
|
-
${link('#types', 'Types')}
|
|
26
|
-
${link('#state', 'State and world')}
|
|
25
|
+
${link('#agents', 'Agents')}
|
|
26
|
+
${link('#state', 'State')}
|
|
27
27
|
</div>
|
|
28
|
-
<p class="chap">
|
|
28
|
+
<p class="chap">The specification</p>
|
|
29
29
|
<div class="nav">${wiki.areas
|
|
30
30
|
.map((area) => `<a href="#${esc(idOf('area', area.name))}">${esc(areaTitle(area.name))}<span>${area.operations.length}</span></a>`)
|
|
31
31
|
.join('')}</div>
|
|
32
|
-
<p class="chap">
|
|
32
|
+
<p class="chap">Index</p>
|
|
33
|
+
<div class="nav">
|
|
34
|
+
${link('#definitions', 'Formal definitions')}
|
|
35
|
+
${link('#types', 'Types')}
|
|
36
|
+
</div>
|
|
37
|
+
<p class="chap">Testing</p>
|
|
33
38
|
<div class="nav">
|
|
39
|
+
${link('#world', 'World')}
|
|
40
|
+
${link('#backgrounds', 'Backgrounds')}
|
|
34
41
|
<a href="#tests">Last run${wiki.run ? `<span>${wiki.run.failed ? '✗' : '✓'} ${esc(plural(wiki.run.ran, 'case'))}</span>` : ''}</a>
|
|
35
42
|
</div>
|
|
36
43
|
<p class="chap work">Your work</p>
|
|
37
44
|
<div class="nav work"><a href="#review">Review <span class="count" id="note-count"></span></a><button type="button" data-conf>Connection <span id="conf-state"></span></button></div>
|
|
38
45
|
<footer class="foot">${LEGEND}
|
|
39
|
-
${THEMES}
|
|
46
|
+
${THEMES}
|
|
47
|
+
<p class="by">A specification read by <a href="https://github.com/enspirit/opspicy">opspicy</a></p></footer>
|
|
40
48
|
</nav>`;
|
|
41
49
|
/** The bar that stays on top of every page, and under it where the search shows what it finds, in place of the page. */
|
|
42
50
|
const TOOLS = `<div class="tools" id="tools">
|
|
43
51
|
<input type="search" class="filter" id="filter" placeholder="Filter this page" aria-label="Filter this page" aria-keyshortcuts="f" autocomplete="off" hidden>
|
|
44
52
|
<span class="m s" id="fcount" aria-live="polite"></span>
|
|
45
53
|
<span class="sp"></span>
|
|
46
|
-
<button type="button" class="tb" id="formal" aria-pressed="false" aria-keyshortcuts="d" title="Show or hide every formaldef, on every page"><b>ƒ</b>
|
|
54
|
+
<button type="button" class="tb" id="formal" aria-pressed="false" aria-keyshortcuts="d" title="Show or hide every formaldef, on every page"><b>ƒ</b> Formaldefs <kbd>d</kbd></button>
|
|
47
55
|
<button type="button" class="tb" id="pnote" aria-keyshortcuts="n" title="Write a note on this page">✎ Note <kbd>n</kbd></button>
|
|
48
56
|
</div>
|
|
49
57
|
<section id="results" aria-live="polite"></section>`;
|
|
@@ -83,7 +91,7 @@ export function documentOf(wiki, { css, script, form }, about) {
|
|
|
83
91
|
<meta charset="utf-8">
|
|
84
92
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
85
93
|
<meta name="generator" content="opspicy explorer">
|
|
86
|
-
<title
|
|
94
|
+
<title>${esc(nameOf(wiki, about))} · specification</title>
|
|
87
95
|
<style>
|
|
88
96
|
${css}
|
|
89
97
|
</style>${form ? `\n<style id="elo-form-css">\n${form.css}\n</style>` : ''}
|
|
@@ -91,7 +99,7 @@ ${css}
|
|
|
91
99
|
</head>
|
|
92
100
|
<body>
|
|
93
101
|
<div class="layout">
|
|
94
|
-
${navOf(wiki)}
|
|
102
|
+
${navOf(wiki, about)}
|
|
95
103
|
<main id="main">
|
|
96
104
|
${TOOLS}
|
|
97
105
|
${sections}
|
package/dist/explorer/html.js
CHANGED
|
@@ -12,6 +12,51 @@ export const mono = (text) => `<span class="mono">${esc(text)}</span>`;
|
|
|
12
12
|
export const elo = (text, refs, about) => `<pre class="elo">${eloHtml(text, refs, about)}</pre>`;
|
|
13
13
|
/** A description, as its file says it: what it sets between backticks is code. */
|
|
14
14
|
export const said = (description) => esc(description).replace(/`([^`]+)`/g, '<code>$1</code>');
|
|
15
|
+
/**
|
|
16
|
+
* What a file of the specification says of its section, as the page leads with it: its first
|
|
17
|
+
* paragraph as the lead, and the rest under it.
|
|
18
|
+
*/
|
|
19
|
+
export function described(text) {
|
|
20
|
+
const [first = '', ...rest] = text.trim().split(/\n\s*\n/);
|
|
21
|
+
const lead = /^([-*] |#)/.test(first) ? markdown(first) : `<p class="lead">${inline(first.split('\n').map((line) => line.trim()).join(' '))}</p>`;
|
|
22
|
+
return `${lead}${rest.length ? `<div class="prose">${markdown(rest.join('\n\n'))}</div>` : ''}`;
|
|
23
|
+
}
|
|
24
|
+
/** A link of a text in Markdown leads to a page of the explorer, `#op-AddExpense`, or to the web: nothing else is a link. */
|
|
25
|
+
const LINKED = /^(#[\w-]+|https?:\/\/\S+)$/;
|
|
26
|
+
/** A line of Markdown: code between backticks, then, outside code, **strong**, *emphasis* and [links](#an-anchor). */
|
|
27
|
+
export function inline(text) {
|
|
28
|
+
// Code is set aside first, so that nothing in it is read as Markdown, then put back where it was.
|
|
29
|
+
const code = [];
|
|
30
|
+
const aside = text.replace(/\u0000/g, '').replace(/`([^`]+)`/g, (_, held) => `\u0000${code.push(held) - 1}\u0000`);
|
|
31
|
+
return esc(aside)
|
|
32
|
+
.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (whole, label, href) => (LINKED.test(href) ? `<a href="${href}">${label}</a>` : whole))
|
|
33
|
+
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
34
|
+
.replace(/\*([^*]+)\*/g, '<em>$1</em>')
|
|
35
|
+
.replace(/\u0000(\d+)\u0000/g, (_, at) => `<code>${esc(code[Number(at)])}</code>`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A text of the suite in Markdown, as HTML: what a specification says of its system. Paragraphs,
|
|
39
|
+
* lists, headings (shown under the page's own), and what a line holds. Anything else is text:
|
|
40
|
+
* no HTML of the file reaches the page.
|
|
41
|
+
*/
|
|
42
|
+
export function markdown(text) {
|
|
43
|
+
return text
|
|
44
|
+
.trim()
|
|
45
|
+
.split(/\n\s*\n/)
|
|
46
|
+
.map((block) => {
|
|
47
|
+
const lines = block.split('\n').map((line) => line.trim());
|
|
48
|
+
if (/^[-*] /.test(lines[0] ?? '')) {
|
|
49
|
+
// An item goes on until the next one begins: a long one is wrapped over several lines.
|
|
50
|
+
const items = lines.reduce((all, line) => (/^[-*] /.test(line) ? [...all, line.slice(2)] : [...all.slice(0, -1), `${all.at(-1)} ${line}`]), []);
|
|
51
|
+
return `<ul>${items.map((item) => `<li>${inline(item)}</li>`).join('')}</ul>`;
|
|
52
|
+
}
|
|
53
|
+
const heading = /^#{1,6} (.*)$/.exec(lines[0] ?? '');
|
|
54
|
+
if (heading && lines.length === 1)
|
|
55
|
+
return `<h3>${inline(heading[1] ?? '')}</h3>`;
|
|
56
|
+
return `<p>${inline(lines.join(' '))}</p>`;
|
|
57
|
+
})
|
|
58
|
+
.join('');
|
|
59
|
+
}
|
|
15
60
|
export const RESULT = {
|
|
16
61
|
passed: '<span class="res ok">✓ passed</span>',
|
|
17
62
|
failed: '<span class="res ko">✗ failed</span>',
|
|
@@ -49,11 +94,11 @@ function citizenRows(one, span) {
|
|
|
49
94
|
* and its description, and its formaldef under it, folded until the heading's toggle, the
|
|
50
95
|
* sidebar's switch or its own address opens it.
|
|
51
96
|
*/
|
|
52
|
-
export function citizens(title, all, { level = 'h2', columns = [], widths, note } = {}) {
|
|
97
|
+
export function citizens(title, all, { level = 'h2', columns = [], widths, note, intro = '' } = {}) {
|
|
53
98
|
if (!all.length)
|
|
54
|
-
return `<${level}>${esc(title)}</${level}
|
|
99
|
+
return `<${level}>${esc(title)}</${level}>${intro}<p class="sub">None.</p>`;
|
|
55
100
|
const span = 2 + Math.max(0, ...all.map((one) => one.more?.length ?? 0));
|
|
56
101
|
const toggle = all.some((one) => one.formaldef) ? ` ${TOGGLE}` : '';
|
|
57
102
|
const heading = `<${level} class="group"><span>${esc(title)}${toggle}</span><span class="m s">${esc(note ?? plural(all.length, 'entry'))}</span></${level}>`;
|
|
58
|
-
return `<section class="citizens">${heading}<div class="scroll"><table class="t">${colgroup(widths)}${thead(columns)}<tbody>${all.map((one) => citizenRows(one, span)).join('')}</tbody></table></div></section>`;
|
|
103
|
+
return `<section class="citizens">${heading}${intro}<div class="scroll"><table class="t">${colgroup(widths)}${thead(columns)}<tbody>${all.map((one) => citizenRows(one, span)).join('')}</tbody></table></div></section>`;
|
|
59
104
|
}
|