@enspirit/opspicy 0.3.2 → 0.6.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 +56 -34
- package/bin/help.js +8 -2
- package/dist/configuration.d.ts +8 -2
- package/dist/explorer/api.js +162 -12
- package/dist/explorer/asking.js +51 -0
- package/dist/explorer/dependencies.js +117 -0
- package/dist/explorer/depending.js +139 -0
- package/dist/explorer/diagrams.js +176 -0
- package/dist/explorer/document.js +1 -0
- package/dist/explorer/elo-refs.js +6 -3
- package/dist/explorer/elo.js +18 -0
- package/dist/explorer/index.js +1 -2
- package/dist/explorer/operation.js +2 -4
- package/dist/explorer/pages.js +14 -16
- package/dist/explorer/script/depending.js +41 -0
- package/dist/explorer/script/main.js +1 -0
- package/dist/explorer/script/ranking.js +2 -2
- package/dist/explorer/script/review.js +1 -1
- package/dist/explorer/script/run.js +4 -1
- package/dist/explorer/script/runner.js +420 -0
- package/dist/explorer/script/running.js +111 -0
- package/dist/explorer/script/sending.js +1 -1
- package/dist/explorer/script/served.js +4 -2
- package/dist/explorer/serve.js +1 -1
- package/dist/explorer/server.js +28 -6
- package/dist/explorer/site.js +1 -1
- package/dist/explorer/style.css +91 -1
- package/dist/explorer/telling.js +2 -0
- package/dist/explorer/tests.js +51 -18
- package/dist/explorer/wiki.js +5 -3
- package/dist/files.js +27 -16
- package/dist/judging.js +2 -34
- package/dist/main.js +1 -1
- package/dist/meaning.js +2 -2
- package/dist/modelling.js +99 -25
- package/dist/naming.js +44 -15
- package/dist/notation.js +18 -3
- package/dist/observing.js +112 -0
- package/dist/planning.js +3 -3
- package/dist/reach.js +244 -140
- package/dist/reading.js +14 -18
- package/dist/running.js +18 -8
- package/dist/starting.js +4 -3
- package/dist/suite.js +8 -1
- package/dist/upgrade.js +3 -9
- package/dist/upgrading-state.js +197 -0
- package/dist/upgrading.js +13 -2
- package/dist/variables.js +62 -0
- package/dist/world.js +8 -39
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -11,15 +11,14 @@ agent: Member
|
|
|
11
11
|
entry: DELETE /api/expenses/:id
|
|
12
12
|
input: ExpenseId
|
|
13
13
|
DomPre:
|
|
14
|
-
- (x) the expense is kept:
|
|
14
|
+
- (x) the expense is kept: kept(input.id)
|
|
15
15
|
DomPost:
|
|
16
|
-
- (x) the expense is kept no more:
|
|
16
|
+
- (x) the expense is kept no more: "!kept(input.id)"
|
|
17
17
|
ReqPre:
|
|
18
18
|
- (x) the requester is signed in
|
|
19
19
|
# Of an expense that is kept: of one that is not, the DomPre says it.
|
|
20
|
-
- (x) the requester paid it:
|
|
20
|
+
- (x) the requester paid it: "!kept(input.id) || expense(input.id).paidBy == me"
|
|
21
21
|
ReqPost:
|
|
22
|
-
- (x) it is one expense fewer: count(expenses) == count(old.expenses) - 1
|
|
23
22
|
- (x) the balances still sum to zero: balanced
|
|
24
23
|
- (x) each who shared it, the payer aside, owes their share less, to the cent: >-
|
|
25
24
|
let e = old.expense(input.id), n = count(e.sharedBy) in
|
|
@@ -46,7 +45,7 @@ counterexamples:
|
|
|
46
45
|
then: 403 expenses.notTheirs
|
|
47
46
|
```
|
|
48
47
|
|
|
49
|
-
It is one operation of [the example](#try-it), a splitter of a group's shared expenses.
|
|
48
|
+
It is one operation of [the example](#try-it), a splitter of a group's shared expenses. What it reads is derived from its clauses, as [state variables](doc/suite.md#state-variables) say: one expense, by what it is given, and the balance of whoever has one. Nothing says what it changes, and nothing checks that the rest stayed as it was: only its clauses and its answer are checked.
|
|
50
49
|
|
|
51
50
|
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.*
|
|
52
51
|
|
|
@@ -67,7 +66,7 @@ To run one, [`example/`](example/) holds a system, a splitter of a group's share
|
|
|
67
66
|
|
|
68
67
|
```sh
|
|
69
68
|
git clone https://github.com/enspirit/opspicy && cd opspicy && npm ci
|
|
70
|
-
node example/splitter.ts &
|
|
69
|
+
SPLITTER_FAULT=yes node example/splitter.ts & # the system, on http://127.0.0.1:4000, with its one fault
|
|
71
70
|
export SPLITTER_API=http://127.0.0.1:4000 SPLITTER_MAY_BE_EMPTIED=yes
|
|
72
71
|
bin/opspicy example/suite # runs the suite
|
|
73
72
|
```
|
|
@@ -78,28 +77,30 @@ AddExpense — Member · POST /api/expenses · expenses/operations/AddExpense.ym
|
|
|
78
77
|
DomPost ✓ the expense is kept
|
|
79
78
|
ReqPre ✓ the requester is signed in
|
|
80
79
|
ReqPre ✓ it is shared among the group
|
|
81
|
-
ReqPost ✓ it is
|
|
80
|
+
ReqPost ✓ it is as given, paid by the requester
|
|
82
81
|
ReqPost ✓ the balances still sum to zero
|
|
83
82
|
ReqPost ✓ each who shares it, the payer aside, owes their share more, to the cent
|
|
84
|
-
ReqPost ✓ nobody else's balance moves
|
|
85
83
|
✓ example: Bob pays a lunch for the three, which splits evenly
|
|
86
84
|
✗ example: Ann pays a dinner for the three, which leaves a cent over
|
|
87
85
|
ReqPost "the balances still sum to zero" does not hold after the call
|
|
86
|
+
✓ example: Cy pays the first expense of the group
|
|
88
87
|
✓ counterexample: the amount is nothing — for its type, ExpenseGiven
|
|
89
88
|
✓ counterexample: it is shared with somebody out of the group — for "it is shared among the group"
|
|
90
89
|
✓ counterexample: called as visitor — for "the requester is signed in" [from a condition]
|
|
91
90
|
```
|
|
92
91
|
|
|
93
|
-
Its
|
|
92
|
+
Its six 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
93
|
|
|
95
94
|
| | Its transition | What the rules demand of it |
|
|
96
95
|
| --- | --- | --- |
|
|
97
|
-
| [`
|
|
98
|
-
| [`
|
|
96
|
+
| [`SignIn`](example/suite/specification/members/operations/SignIn.yml) | The requester is not signed in; then they are. | The password is theirs, as the world knows it; no password at all is no `Credentials`, which a counterexample `for` the type shows refused. They are who they said they are, and are told the balances, which a visitor is not. |
|
|
97
|
+
| [`SignOut`](example/suite/specification/members/operations/SignOut.yml) | The requester is signed in; then they are not. | Nothing more: a visitor who asks is refused, as a condition says of every operation a member performs. |
|
|
98
|
+
| [`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 as given; each who shares it owes their share more, to the cent; another member sees it too. |
|
|
99
|
+
| [`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. |
|
|
99
100
|
| [`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
101
|
| [`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
|
|
|
102
|
-
|
|
103
|
+
Started so, 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. Started without `SPLITTER_FAULT=yes`, it does what its suite says, the cents left over owed by the first of those who share the expense, and a run finds nothing. Then, to read the suite rather than its files:
|
|
103
104
|
|
|
104
105
|
```sh
|
|
105
106
|
bin/opspicy example/suite --report=last.json # the same run, kept
|
|
@@ -107,27 +108,43 @@ bin/opspicy explorer example/suite --report=last.json # writes explore
|
|
|
107
108
|
bin/opspicy serve example/suite --report=last.json --api # http://127.0.0.1:8080, and it runs what its page asks
|
|
108
109
|
```
|
|
109
110
|
|
|
111
|
+
The splitter also gives a page at its front door, `http://127.0.0.1:4000`, to show what such a system is made of before any of this is read. It opens as a *User* has it: an app as any other, to sign in (Ann, Bob or Cy), add an expense, take one back, settle up and read the balances, of a group that spent nothing yet; *Start over* puts the splitter back there, whatever was done, and signs out. Turned to the *Analyst*, or opened at `http://127.0.0.1:4000/#analyst`, the page shows beside the app what it is made of. In the middle, its specification: its operations, each with what it demands before and promises after, decided as the page is used. What a member does in the app is a verb, add an expense, and what the specification says of it, and the splitter runs, is an operation, `AddExpense`: a button is held back while a precondition of its operation fails, and the clause that fails turns red, a moment after it does: a form that was just used is empty again, and would otherwise seem to have failed. A clause is read by its sentence, and *Formaldefs* shows the formaldef of every one, as in the explorer. On the right, the state, the rule it must always satisfy, and every call as a transition from one state to the next, or as a refusal that left it where it was. *The concepts*, which a user has as an analyst does, opens the page that explains it, `http://127.0.0.1:4000/about`: a schema of the splitter as a black box, with its state, the observation of that state through its front door, and an operation with its conditions to be called and what it guarantees of the result, said by its definition and by an example; from there, two ways lead back to the app, as a user and as an analyst, which kept what was asked. The same calls are read another way under *The data exchanges*: where each was sent, the JSON it was sent and the JSON it answered. What a user did is judged and written down all the same, and is there to read. *Ask anyway* lets the page ask what the rules are against, and it is the splitter that refuses. The splitter has no fault there unless it is started with one: with `SPLITTER_FAULT=yes`, a dinner of 100.00 for the three is answered 201, the app has nothing to say, and the page shows the state the rules do not allow. The operations are those of the suite, in its words, [`example/ui/operations.js`](example/ui/operations.js): a test holds the two together.
|
|
112
|
+
|
|
113
|
+
Both are at one address, with what runs the cases, when the example is started whole:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
node example/training.ts # http://127.0.0.1:4000
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
| | |
|
|
120
|
+
| --- | --- |
|
|
121
|
+
| `/` | Leads to the page that explains, `/app/about`, which leads to the three below. |
|
|
122
|
+
| `/app/` | The splitter and its page: the app as a user has it, and `/app/#analyst` with what an analyst reads beside it. Each operation there leads to its page of the specification. |
|
|
123
|
+
| `/spec/` | The explorer of the suite, served with its API. Its Tests page runs every case, of the suite or of one area, and tells each as it is run. |
|
|
124
|
+
|
|
125
|
+
The cases are run against a splitter of their own, which nothing else reaches: a run begins by putting the system back in a seed, and whoever is learning in the app would lose what they did at the first case. That splitter has its fault, since a run is there to find something; `SPLITTER_FAULT=no` starts it without. What is at the address only passes each request on to the server its path names ([`example/training.ts`](example/training.ts)): the splitter and the explorer are what they are alone.
|
|
126
|
+
|
|
110
127
|
## How a case runs
|
|
111
128
|
|
|
112
129
|
| | |
|
|
113
130
|
| --- | --- |
|
|
114
131
|
| **Given** | The Background: the database is put in a seed, and who calls is signed in. |
|
|
115
|
-
| | The state is observed: `_.before`. |
|
|
132
|
+
| | The state is observed: `_.before`. [What of it](doc/derived.md#what-a-case-observes), and by which mechanism, is the run's to say: [two runs](#two-runs). |
|
|
116
133
|
| **When** | The operation is called once, through the front door, with the input. What it started and did not wait for is waited for. |
|
|
117
134
|
| **Then** | The state is observed again: `_.after`. |
|
|
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
|
|
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
|
|
135
|
+
| 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 |
|
|
136
|
+
| 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 |
|
|
120
137
|
|
|
121
138
|
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.
|
|
122
139
|
|
|
123
140
|
### Two runs
|
|
124
141
|
|
|
125
|
-
| | Checks |
|
|
142
|
+
| | Checks | Observes |
|
|
126
143
|
| --- | --- | --- |
|
|
127
|
-
| **complete** | Every clause that has a formaldef. |
|
|
128
|
-
| **fast** (`--fast`) | What must hold: every clause but those marked `(+)`, which it tells. |
|
|
144
|
+
| **complete** | Every clause that has a formaldef, `(+)` included. | [What each case reads](doc/derived.md#what-a-case-observes), by every mechanism it reads it through: the front door, as who calls and as whoever looks on, and the database. |
|
|
145
|
+
| **fast** (`--fast`) | What must hold: every clause but those marked `(+)`, which it tells. | Through the front door alone, [what each case reads](doc/derived.md#what-a-case-observes), as narrowly as it is named: an item by the route that tells it alone, where the state says one. What the configuration's `atRest` asks of the database is still asked. |
|
|
129
146
|
|
|
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).
|
|
147
|
+
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. It is as long as what its cases touch, and not as the system is large: an operation that reads one item, `board(input.id).name`, has its cases ask for that board, not for every board. 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).
|
|
131
148
|
|
|
132
149
|
## Public interface
|
|
133
150
|
|
|
@@ -172,7 +189,7 @@ What of the suite is run, and how much of it is told, is asked through the envir
|
|
|
172
189
|
| `ROBUST=no\|only\|generated` | Only the examples; only the counterexamples; only those the conditions give. |
|
|
173
190
|
| `FAILFAST=yes` | Stops at the first case that fails. |
|
|
174
191
|
| `FAST=yes` | [The fast run](#two-runs); `--fast` says the same. |
|
|
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. |
|
|
192
|
+
| `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: what a case asked of the system to be judged. 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. |
|
|
176
193
|
|
|
177
194
|
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.
|
|
178
195
|
|
|
@@ -186,16 +203,16 @@ A system that stops answering during the run is not that: each case then could n
|
|
|
186
203
|
|
|
187
204
|
| Tag | Is |
|
|
188
205
|
| --- | --- |
|
|
189
|
-
| `0.
|
|
206
|
+
| `0.6.0` | The version tagged `v0.6.0`: the image of that commit, as it was tested. Name one of these. |
|
|
190
207
|
| `latest`, `sha-<commit>` | The main branch, and one commit of it. |
|
|
191
208
|
|
|
192
209
|
**As a tool**, on a suite that is mounted:
|
|
193
210
|
|
|
194
211
|
```sh
|
|
195
|
-
docker run --rm -v "$PWD":/suite:ro enspirit/opspicy:0.
|
|
196
|
-
docker run --rm -v "$PWD":/suite:ro enspirit/opspicy:0.
|
|
197
|
-
docker run --rm -v "$PWD":/suite enspirit/opspicy:0.
|
|
198
|
-
docker run --rm -v "$PWD":/suite:ro -p 127.0.0.1:8080:8080 enspirit/opspicy:0.
|
|
212
|
+
docker run --rm -v "$PWD":/suite:ro enspirit/opspicy:0.6.0 opspicy --check
|
|
213
|
+
docker run --rm -v "$PWD":/suite:ro enspirit/opspicy:0.6.0 tsc -p . # type-checks its config.ts
|
|
214
|
+
docker run --rm -v "$PWD":/suite enspirit/opspicy:0.6.0 opspicy explorer --out=explorer.html
|
|
215
|
+
docker run --rm -v "$PWD":/suite:ro -p 127.0.0.1:8080:8080 enspirit/opspicy:0.6.0 opspicy serve --host=0.0.0.0
|
|
199
216
|
```
|
|
200
217
|
|
|
201
218
|
The last one is read-only: `--api` is offered on the machine the server runs on, which a container is not.
|
|
@@ -203,7 +220,7 @@ The last one is read-only: `--api` is offered on the machine the server runs on,
|
|
|
203
220
|
**As the base of a suite's image**, where the system is reached: on the network of its stack, say.
|
|
204
221
|
|
|
205
222
|
```dockerfile
|
|
206
|
-
FROM enspirit/opspicy:0.
|
|
223
|
+
FROM enspirit/opspicy:0.6.0
|
|
207
224
|
COPY . /suite
|
|
208
225
|
CMD ["tail", "-f", "/dev/null"] # it sleeps, and `opspicy` is run in it
|
|
209
226
|
```
|
|
@@ -230,7 +247,7 @@ Everything it says is a **citizen**: a name, a description, and for some a forma
|
|
|
230
247
|
|
|
231
248
|
### The explorer
|
|
232
249
|
|
|
233
|
-
A wiki of a suite, as one HTML document that fetches nothing: the specification, and the last run of each operation when there is a report of one. A reader searches it, opens a formaldef at a click, follows a name in Elo to the citizen it names, takes notes that become one review file, and, where the document is served with `--api`, runs one case or calls an operation by hand.
|
|
250
|
+
A wiki of a suite, as one HTML document that fetches nothing: the specification, and the last run of each operation when there is a report of one. A reader searches it, opens a formaldef at a click, follows a name in Elo to the citizen it names, takes notes that become one review file, and, where the document is served with `--api`, runs one case, every case of the suite or of an area with each told as it is run, or calls an operation by hand.
|
|
234
251
|
|
|
235
252
|
**[`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.
|
|
236
253
|
|
|
@@ -244,7 +261,7 @@ A wiki of a suite, as one HTML document that fetches nothing: the specification,
|
|
|
244
261
|
| `@enspirit/elo`, `luxon` | What a formaldef is written in, and the types; the dates Elo computes with. |
|
|
245
262
|
| `highlight.js`, `@enspirit/highlightjs-elo` | Elo as the explorer shows it: the grammar is Elo's own, applied when the document is written, so the page carries neither. |
|
|
246
263
|
| `@enspirit/elo-form` | The form an operation is called with, in the explorer: Elo's own contrib, whose standalone script and style a document is written with. |
|
|
247
|
-
| `yaml`, `pg` | Reading the files; reading the
|
|
264
|
+
| `yaml`, `pg` | Reading the files; reading what the database shows of the state. |
|
|
248
265
|
| `typescript`, `@types/node` (development, and in the image) | Type-checking opspicy itself, and compiling the package; in the image, type-checking a suite's `config.ts`. Who installs the package downloads neither. |
|
|
249
266
|
| `playwright-core` (development) | Drives the installed Chrome in the browser tests; downloads no browser. |
|
|
250
267
|
| [dbagent](https://github.com/enspirit/dbagent), PostgreSQL (of a suite that wants them) | `dbagent(url)` sets a Background by installing a seed, and `noKeyHeld` reads PostgreSQL's advisory locks: both are handed to a `config.ts`, which may do without. |
|
|
@@ -269,9 +286,9 @@ npm run test:package # needs the registry: installs what would be published, a
|
|
|
269
286
|
|
|
270
287
|
| What | Is held by |
|
|
271
288
|
| --- | --- |
|
|
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/). |
|
|
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. |
|
|
289
|
+
| 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)), says what a state variable is and which covers which ([`variables`](src/variables.ts)), what a formaldef reads of them ([`reach`](src/reach.ts)), plans ([`planning`](src/planning.ts), and what a case observes: [`observing`](src/observing.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/). |
|
|
290
|
+
| What sets a Background, calls and observes ([`world`](src/world.ts), [`observing`](src/observing.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. What is asked of a database is held as the statements it is asked: no test has one. |
|
|
291
|
+
| 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 when it is started with it, and nothing else; nothing at all when it is not. [`test/example-page.test.ts`](test/example-page.test.ts): the page of the splitter says each clause of the suite in its words, and judges every case of it as a run does. [`test/browser/splitter.test.ts`](test/browser/splitter.test.ts): the page as a member has it, in a Chrome. [`test/example-training.test.ts`](test/example-training.test.ts) and [`test/browser/training.test.ts`](test/browser/training.test.ts): the example at one address, the app under `/app/` and its explorer under `/spec/`, where every case is run and the app loses nothing to it. |
|
|
275
292
|
| 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. |
|
|
276
293
|
| 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`. |
|
|
277
294
|
| 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. |
|
|
@@ -298,20 +315,25 @@ What the notation cannot say yet:
|
|
|
298
315
|
- **One precondition violated per counterexample**, so the order of two refusals is said nowhere.
|
|
299
316
|
- **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.
|
|
300
317
|
- **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.
|
|
318
|
+
- **A key is said of what the operation is given**: one item, or each of a list, `board(input.ids)`. An item that only the state names (the first board, the boards of the requester, who shared the expense that is taken back) is read as any of them, which is every item: `boards(*)`.
|
|
319
|
+
- **A view is compared whole where nothing else is read through it.** `seenBy.admin == old.seenBy.admin` and `db == old.db` compare what was told and shown. In a formaldef that also names an item, a predicate or a function (`board(1)`, `seesBoard(1)`), a view holds what reads it too, and two are never the same: such a formaldef compares the states it means, `seenBy.admin.boards == old.seenBy.admin.boards`.
|
|
301
320
|
- **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.
|
|
302
321
|
- **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.
|
|
303
|
-
- **A trigger is told.** `ReqTrig` says when an operation is performed without being asked, and one call shows nothing of it.
|
|
322
|
+
- **A trigger is told.** `ReqTrig` says when an operation is performed without being asked, and one call shows nothing of it. It may say its formaldef, which is read and not checked: that the postcondition of the operation that leaves the state so implies it is for a reader to see, in the same state variables.
|
|
304
323
|
- **An agent is who calls.** What performs an operation without being asked (the server on its clock, say) has no entry to call, and is not an agent of `agents.yml`.
|
|
305
324
|
- **An operation with no example gets no counterexample from a condition**, which gives its first example to who violates it. And one written by hand does not stand in for it: who is not signed in violates more than the one precondition a counterexample is `for`. So that such an operation refuses a visitor is shown by no case.
|
|
306
325
|
- **`PATCH` is not a method an `entry` says.**
|
|
307
326
|
- **A type that is one of several is tried in their order.** Under `Int|String`, `"12"` is refused as a text given for a number; under `String|Int` it is a text.
|
|
308
327
|
- **Elo has no pattern**: "is an address" is approximated.
|
|
309
|
-
- **A Background is
|
|
328
|
+
- **A Background is what the configuration's `background` sets**, by its name. `dbagent(url)` puts the database in a seed; what else a case starts from (a mail server, a queue) is the configuration's to put back there too, before or after it, or it stays as the case before left it. opspicy hands it nothing for that.
|
|
310
329
|
- **`atRest` looks at the database.** Work a system starts without leaving a trace there is not waited for.
|
|
311
330
|
|
|
312
331
|
What the runner does not do yet:
|
|
313
332
|
|
|
314
|
-
- **"Nothing changed" is said of what was observed.** A requester whom every route of the state refuses is told nothing, before and after: where
|
|
333
|
+
- **"Nothing changed" is said of what was observed.** A requester whom every route of the state refuses is told nothing, before and after: where nothing is read in the database (the fast run) and nobody looks on, a counterexample called by them shows that it is refused as said, and nothing of what the call left. A clause that names `seenBy.<actor>` has somebody look on. Nothing else is checked: a call that changes what no clause names is not a finding, in either run.
|
|
334
|
+
- **The database is read where a clause reads it.** The complete run looks in the database at what the clauses read, and the fast run at nothing behind the front door.
|
|
335
|
+
- **A mechanism is the front door or the database.** What else shows the state of a system (a mailbox, a queue, a file) is not observed.
|
|
336
|
+
- **A column is an attribute of the same name, or the one the state says it is** (`filter_json: filter`), as a formaldef reads it. A formaldef still reads a row by its columns, `db.board(1).filter_json`, and a column holds what the table holds, which need not be what the front door tells of that attribute.
|
|
315
337
|
- **A call has no time limit of its own**, nor a question asked of the database: a system that hangs holds a case for as long as Node waits.
|
|
316
338
|
- **An origin is a case's own within one run.** Given an `originHeader`, two runs may call from the same origins, and whoever looks on calls from the requester's.
|
|
317
339
|
- **A cookie is kept until it is taken back by name**: when it expires is not read.
|
package/bin/help.js
CHANGED
|
@@ -18,7 +18,8 @@ the suite is the current directory: \`opspicy --check\` reads the one you are in
|
|
|
18
18
|
|
|
19
19
|
Options:
|
|
20
20
|
--check read the suite and say what cannot be read; call nothing
|
|
21
|
-
--fast the fast run: every clause but those marked (+),
|
|
21
|
+
--fast the fast run: every clause but those marked (+), through the front
|
|
22
|
+
door alone, of what each case reads
|
|
22
23
|
--report=<file> also write what the run decided, as JSON, for the explorer
|
|
23
24
|
-h, --help show this help
|
|
24
25
|
-v, --version show the version
|
|
@@ -79,7 +80,8 @@ when none is named. Stop it with Ctrl-C.
|
|
|
79
80
|
Options:
|
|
80
81
|
--host=<host> where it listens (127.0.0.1; 0.0.0.0 in a container)
|
|
81
82
|
--port=<port> the port (8080; 0 for any free one)
|
|
82
|
-
--api also run what the page asks: one case,
|
|
83
|
+
--api also run what the page asks: one case, every case of an
|
|
84
|
+
operation, of an area or of the suite, or a call as an actor.
|
|
83
85
|
It meets the system through the suite's config.ts, and running
|
|
84
86
|
a case empties its database: offered on this machine only.
|
|
85
87
|
${ABOUT_THE_SUITE}
|
|
@@ -101,6 +103,10 @@ current directory when none is named. Commit before, and read the difference aft
|
|
|
101
103
|
From 0.1 and 0.2: areas.yml, agents.yml and backgrounds.yml, a list each, become a map of their
|
|
102
104
|
description and their list.
|
|
103
105
|
|
|
106
|
+
From 0.3: state.yml said the routes of the state and, apart, the relations of the database. It
|
|
107
|
+
becomes one list of state variables, each with what observes it (web, db); a function that reads
|
|
108
|
+
one item of a collection by its key becomes the item of that state.
|
|
109
|
+
|
|
104
110
|
Documentation: ${DOCUMENTATION}/blob/main/CHANGELOG.md`;
|
|
105
111
|
|
|
106
112
|
const TEXTS = { opspicy: OPSPICY, explorer: EXPLORER, serve: SERVE, upgrade: UPGRADE };
|
package/dist/configuration.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export interface Answer {
|
|
|
4
4
|
body: unknown;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Somebody's browser: it keeps the cookies it is given,
|
|
8
|
-
* of sign-in is a header it sends with every call.
|
|
7
|
+
* Somebody's browser: it keeps the cookies it is given, by a call or by the configuration, and
|
|
8
|
+
* comes from one origin. Any other scheme of sign-in is a header it sends with every call.
|
|
9
9
|
*/
|
|
10
10
|
export interface Browser {
|
|
11
11
|
call(method: string, path: string, body?: unknown): Promise<Answer>;
|
|
@@ -15,6 +15,12 @@ export interface Browser {
|
|
|
15
15
|
* never told of: a run says what was sent and what was answered, not what the call was signed with.
|
|
16
16
|
*/
|
|
17
17
|
header(name: string, value: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Gives it a cookie, as if a call had been answered with it: `sid` with the session a seed
|
|
20
|
+
* holds for somebody, say, who is then signed in without a call. A cookie a later call is
|
|
21
|
+
* given under the same name replaces it, and one it is taken takes it away.
|
|
22
|
+
*/
|
|
23
|
+
cookie(name: string, value: string): void;
|
|
18
24
|
}
|
|
19
25
|
/** Asks the database, to read: one statement, its rows. */
|
|
20
26
|
export type Ask = (sql: string) => Promise<Record<string, unknown>[]>;
|
package/dist/explorer/api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// What the served explorer does when its page asks: says what it serves, runs one case,
|
|
2
|
-
//
|
|
1
|
+
// What the served explorer does when its page asks: says what it serves, runs one case, or every
|
|
2
|
+
// case of the suite or of an area, telling each as it is run, calls an operation as an actor of
|
|
3
|
+
// the world, and writes the review beside the specification. It is the
|
|
3
4
|
// runner, asked from a page: a case is run as main.ts runs it, through the front door, against
|
|
4
5
|
// the system the suite's configuration names.
|
|
5
6
|
//
|
|
@@ -7,23 +8,28 @@
|
|
|
7
8
|
// it is read again whenever its files are no longer what they were (afresh.ts). Nothing told
|
|
8
9
|
// here holds what an actor signs in with: a sign-in is neither logged nor answered, and what a
|
|
9
10
|
// run tells is told without what the world holds (telling.ts, masking.ts).
|
|
10
|
-
import { lstatSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { lstatSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
11
12
|
import { join } from 'node:path';
|
|
12
13
|
import { namesOf } from '../files.js';
|
|
14
|
+
import { gapsOf } from '../planning.js';
|
|
15
|
+
import { parseReport, reportOf } from '../report-file.js';
|
|
13
16
|
import { meaningOf } from '../meaning.js';
|
|
14
17
|
import { addressed, queryOf } from '../notation.js';
|
|
15
18
|
import { runCase } from '../running.js';
|
|
19
|
+
import { observedBy } from '../suite.js';
|
|
16
20
|
import { NotStarted, reachOf } from '../starting.js';
|
|
17
21
|
import { browserOf } from '../world.js';
|
|
18
22
|
import { suiteAt } from './afresh.js';
|
|
19
|
-
import {
|
|
23
|
+
import { idOf } from './wiki.js';
|
|
24
|
+
import { callAsked, isTold, refused, runAsked, runsAsked } from './asking.js';
|
|
20
25
|
import { secretsOf } from './masking.js';
|
|
21
|
-
import { ranOf } from './telling.js';
|
|
26
|
+
import { amongOf, ranOf } from './telling.js';
|
|
27
|
+
export const isStreamed = (answer) => 'stream' in answer;
|
|
22
28
|
const PROTECTED = 'This stack does not say that its database may be emptied';
|
|
23
29
|
/** Whether the database is somebody's: it is, unless the configuration says in so many words that it may be emptied. What only looks like yes (`'yes'`, `1`) is not. */
|
|
24
30
|
export const isProtected = (config) => config.mayEmptyTheDatabase !== true;
|
|
25
|
-
/** Whether the complete run can be made: it reads the
|
|
26
|
-
const completes = (suite, config) => suite.model.
|
|
31
|
+
/** Whether the complete run can be made: it reads what the database shows of the state, which takes a database. */
|
|
32
|
+
const completes = (suite, config) => observedBy(suite.model, 'db').length === 0 || Boolean(config.database);
|
|
27
33
|
/** What is served: the specification, the system it is run against, whether its database is somebody's, and the runs that can be made. */
|
|
28
34
|
export function health(bench) {
|
|
29
35
|
const suite = suiteAt(bench.root);
|
|
@@ -31,7 +37,7 @@ export function health(bench) {
|
|
|
31
37
|
const mode = bench.lastMode() ?? 'fast';
|
|
32
38
|
return { status: 200, body: { name: bench.name, ...(bench.version ? { version: bench.version } : {}), target: bench.config.api, protected: isProtected(bench.config), modes, mode: modes.includes(mode) ? mode : 'fast' } };
|
|
33
39
|
}
|
|
34
|
-
let
|
|
40
|
+
let made = 0;
|
|
35
41
|
/** Runs one case, by its anchor: its Background is set, which replaces what the database held, and the case is judged. */
|
|
36
42
|
export async function run(bench, asked) {
|
|
37
43
|
const suite = suiteAt(bench.root);
|
|
@@ -41,19 +47,163 @@ export async function run(bench, asked) {
|
|
|
41
47
|
if (isProtected(bench.config))
|
|
42
48
|
return refused(403, `${PROTECTED}, and running a case sets its Background, which empties it.`);
|
|
43
49
|
if (found.mode === 'complete' && !completes(suite, bench.config))
|
|
44
|
-
return refused(400, 'The complete run reads the
|
|
50
|
+
return refused(400, 'The complete run reads what the database shows of the state, and the configuration names no database to read it from.');
|
|
45
51
|
// What a run reads is reached as the runner reaches it, and a database that is not there is its sentence, not a failure of this server.
|
|
46
52
|
const reach = await reachOf(suite, bench.config, found.mode === 'fast').catch((error) => (error instanceof NotStarted ? refused(503, error.message) : Promise.reject(error)));
|
|
47
53
|
if (isTold(reach))
|
|
48
54
|
return reach;
|
|
49
55
|
try {
|
|
50
|
-
const outcome = await runCase(reach, suite.model, meaningOf(suite.types, namesOf(suite.model)), found.operation, found.kase, { run: process.pid, n:
|
|
51
|
-
|
|
56
|
+
const outcome = await runCase(reach, suite.model, meaningOf(suite.types, namesOf(suite.model)), found.operation, found.kase, { run: process.pid, n: made++, listening: true });
|
|
57
|
+
const told = ranOf(found.operation, outcome, found.mode, secretsOf(suite.model));
|
|
58
|
+
keptOf(bench).set(idOf('case', found.kase.name), told);
|
|
59
|
+
return { status: 200, body: told };
|
|
52
60
|
}
|
|
53
61
|
finally {
|
|
54
62
|
await reach.database?.end();
|
|
55
63
|
}
|
|
56
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* What the last run of each case told, whole: its call, its answer, what did not hold and its
|
|
67
|
+
* log. A run of many cases tells each in a line, and keeps the rest here, for the page to ask for
|
|
68
|
+
* the case it opens. Kept for as long as the server runs, by the suite it is of, and nowhere else:
|
|
69
|
+
* a log holds what the system answered.
|
|
70
|
+
*/
|
|
71
|
+
const KEPT = new Map();
|
|
72
|
+
function keptOf(bench) {
|
|
73
|
+
const kept = KEPT.get(bench.root) ?? new Map();
|
|
74
|
+
KEPT.set(bench.root, kept);
|
|
75
|
+
return kept;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* What the last run of a case told, by its anchor: of one that was run alone or among others,
|
|
79
|
+
* since this server started. Of one it did not run it keeps nothing, and says so as `null`: that
|
|
80
|
+
* is an answer and no failure, and a page that asks of each case it opens is told so quietly.
|
|
81
|
+
*/
|
|
82
|
+
export function ran(bench, ref) {
|
|
83
|
+
if (!ref)
|
|
84
|
+
return refused(400, 'What a run told is asked by the anchor of its case: ?case=case-CreateBoard-examples-1.');
|
|
85
|
+
return { status: 200, body: keptOf(bench).get(ref) ?? null };
|
|
86
|
+
}
|
|
87
|
+
/** The report a run is added to, when there is one that reads. */
|
|
88
|
+
function reportBefore(file) {
|
|
89
|
+
try {
|
|
90
|
+
return parseReport(readFileSync(file, 'utf8'));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** A run in words, as a report says what was asked of it. */
|
|
97
|
+
const asked = (scope) => (scope.of === 'suite' ? [] : scope.of === 'area' ? [`area ${scope.area}`] : scope.of === 'operation' ? [`operation ${scope.operation}`] : [`operation ${scope.operation}, case "${scope.kase}"`]);
|
|
98
|
+
/**
|
|
99
|
+
* The report after a run. A run of the whole suite is the report, as the runner writes it. A run
|
|
100
|
+
* of less is added to the report there was: each operation it ran takes the place of what the
|
|
101
|
+
* report said of it, and a case run alone the place of that case, so that what was run before is
|
|
102
|
+
* still told. Such a report is of several runs: it says so, unless it was one of the whole suite,
|
|
103
|
+
* which it still is.
|
|
104
|
+
*/
|
|
105
|
+
export function reportAfter(before, ran, facts, scope) {
|
|
106
|
+
const now = reportOf(ran, { ...facts, narrowed: asked(scope) });
|
|
107
|
+
if (scope.of === 'suite' || !before)
|
|
108
|
+
return now;
|
|
109
|
+
const operations = before.operations.map((one) => ({ ...one, cases: [...one.cases] }));
|
|
110
|
+
for (const run of now.operations) {
|
|
111
|
+
const at = operations.findIndex((one) => one.file === run.file);
|
|
112
|
+
if (at < 0)
|
|
113
|
+
operations.push(run);
|
|
114
|
+
else if (scope.of !== 'case')
|
|
115
|
+
operations[at] = run;
|
|
116
|
+
else {
|
|
117
|
+
const was = operations[at];
|
|
118
|
+
for (const kase of run.cases) {
|
|
119
|
+
const same = was.cases.findIndex((one) => one.kind === kase.kind && one.when === kase.when && one.generated === kase.generated);
|
|
120
|
+
if (same < 0)
|
|
121
|
+
was.cases.push(kase);
|
|
122
|
+
else
|
|
123
|
+
was.cases[same] = kase;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { ...now, narrowed: before.narrowed.length ? ['several runs from the explorer'] : [], operations };
|
|
128
|
+
}
|
|
129
|
+
/** The report of a run, in its file: written beside and put in its place, so that who reads it meanwhile reads a whole one. What kept it from being written is said. */
|
|
130
|
+
function reported(file, ran, facts, scope) {
|
|
131
|
+
const beside = `${file}.${process.pid}.part`;
|
|
132
|
+
try {
|
|
133
|
+
writeFileSync(beside, JSON.stringify(reportAfter(reportBefore(file), ran, facts, scope), null, 2) + '\n');
|
|
134
|
+
renameSync(beside, file);
|
|
135
|
+
return { report: file };
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
return { report: null, unwritten: `The report could not be written to ${file}: ${error instanceof Error ? error.message : String(error)}` };
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
rmSync(beside, { force: true });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Runs every case of the suite, of one area or of one operation, or one case, and tells each as
|
|
146
|
+
* it is run. What is told, a message at a time: `started`, with what is to be run; `running`, a
|
|
147
|
+
* case, before it is; `ran`, the same case, with its result and what did not hold; `ended`, with
|
|
148
|
+
* the counts. The whole telling of each case, its log among it, is kept for the page to ask for
|
|
149
|
+
* (`ran`). A run that ended is written to the report of the explorer, when it has one: the whole
|
|
150
|
+
* suite as the runner writes it, less than that added to what the report told. Its pages then
|
|
151
|
+
* tell that run. One that whoever asked did not wait for stops, and writes nothing.
|
|
152
|
+
*/
|
|
153
|
+
export async function runs(bench, asked) {
|
|
154
|
+
const suite = suiteAt(bench.root);
|
|
155
|
+
const found = runsAsked(suite, asked, bench.lastMode());
|
|
156
|
+
if (isTold(found))
|
|
157
|
+
return found;
|
|
158
|
+
if (isProtected(bench.config))
|
|
159
|
+
return refused(403, `${PROTECTED}, and running a case sets its Background, which empties it.`);
|
|
160
|
+
if (found.mode === 'complete' && !completes(suite, bench.config))
|
|
161
|
+
return refused(400, 'The complete run reads what the database shows of the state, and the configuration names no database to read it from.');
|
|
162
|
+
const reach = await reachOf(suite, bench.config, found.mode === 'fast').catch((error) => (error instanceof NotStarted ? refused(503, error.message) : Promise.reject(error)));
|
|
163
|
+
if (isTold(reach))
|
|
164
|
+
return reach;
|
|
165
|
+
const { mode, scope, plan } = found;
|
|
166
|
+
const kept = keptOf(bench);
|
|
167
|
+
const [meaning, secrets] = [meaningOf(suite.types, namesOf(suite.model)), secretsOf(suite.model)];
|
|
168
|
+
const stream = async (say, gone) => {
|
|
169
|
+
const started = Date.now();
|
|
170
|
+
const counts = { passed: 0, failed: 0, error: 0 };
|
|
171
|
+
const ran = [];
|
|
172
|
+
let stopped = false;
|
|
173
|
+
try {
|
|
174
|
+
say({
|
|
175
|
+
is: 'started',
|
|
176
|
+
mode,
|
|
177
|
+
...(scope.of === 'area' ? { area: idOf('area', scope.area) } : {}),
|
|
178
|
+
cases: plan.reduce((sum, one) => sum + one.cases.length, 0),
|
|
179
|
+
operations: plan.map(({ operation, cases }) => ({ ref: idOf('op', operation.name), name: operation.name, cases: cases.map((kase) => idOf('case', kase.name)) })),
|
|
180
|
+
});
|
|
181
|
+
for (const { operation, cases, all } of plan) {
|
|
182
|
+
const outcomes = [];
|
|
183
|
+
for (const kase of cases) {
|
|
184
|
+
if ((stopped = gone()))
|
|
185
|
+
break;
|
|
186
|
+
say({ is: 'running', ref: idOf('case', kase.name) });
|
|
187
|
+
const outcome = await runCase(reach, suite.model, meaning, operation, kase, { run: process.pid, n: made++, listening: true });
|
|
188
|
+
const told = ranOf(operation, outcome, mode, secrets);
|
|
189
|
+
kept.set(idOf('case', kase.name), told);
|
|
190
|
+
counts[told.result] += 1;
|
|
191
|
+
outcomes.push(outcome);
|
|
192
|
+
say({ is: 'ran', ...amongOf(operation, kase, told) });
|
|
193
|
+
}
|
|
194
|
+
if (stopped)
|
|
195
|
+
break;
|
|
196
|
+
ran.push({ operation, outcomes, gaps: gapsOf(operation, all) });
|
|
197
|
+
}
|
|
198
|
+
const written = !stopped && bench.report ? reported(bench.report, ran, { when: new Date(started).toISOString(), narrowed: [], fast: mode === 'fast', stopped: false }, scope) : { report: null };
|
|
199
|
+
say({ is: 'ended', passed: counts.passed, failed: counts.failed, errors: counts.error, seconds: (Date.now() - started) / 1000, stopped, ...written });
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
await reach.database?.end();
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
return { status: 200, stream };
|
|
206
|
+
}
|
|
57
207
|
/** Calls an operation once, as an actor of the world, with an input: the route is filled from it, and the rest is sent. */
|
|
58
208
|
export async function call(bench, asked) {
|
|
59
209
|
const found = callAsked(suiteAt(bench.root), asked);
|
|
@@ -70,7 +220,7 @@ export async function call(bench, asked) {
|
|
|
70
220
|
return refused(400, error instanceof Error ? error.message : String(error));
|
|
71
221
|
}
|
|
72
222
|
const started = Date.now();
|
|
73
|
-
const theirs = await browserOf(bench.config, `10.254.${(
|
|
223
|
+
const theirs = await browserOf(bench.config, `10.254.${(made >> 8) % 256}.${made++ % 256}`, actor, held).catch(() => null);
|
|
74
224
|
if (!theirs)
|
|
75
225
|
return refused(400, `"${actor}" could not be signed in.`);
|
|
76
226
|
const answer = operation.entry.method === 'GET' ? await theirs.call('GET', `${sent.path}${queryOf(sent.rest)}`) : await theirs.call(operation.entry.method, sent.path, sent.rest ?? {});
|
package/dist/explorer/asking.js
CHANGED
|
@@ -57,3 +57,54 @@ export function callAsked(suite, asked) {
|
|
|
57
57
|
return refused(400, `Nobody is called "${actor}" in the world.`);
|
|
58
58
|
return { operation, actor, held: held[actor] ?? null, input };
|
|
59
59
|
}
|
|
60
|
+
const HOW_RUNS = 'Runs are asked as { area, mode }, { operation, mode } or { case, mode }: the anchor of an area, of an operation or of a case, or none of them for the whole suite, and "fast" or "complete".';
|
|
61
|
+
/**
|
|
62
|
+
* The runs a page asks for, or why none is made: every case of the area an anchor names,
|
|
63
|
+
* `area-expenses`, of the operation one names, `op-AddExpense`, the case one names alone, or every
|
|
64
|
+
* case of the suite when nothing is named. Nothing of a suite that cannot be read is run, as the
|
|
65
|
+
* runner runs nothing of it.
|
|
66
|
+
*/
|
|
67
|
+
export function runsAsked(suite, asked, lastMode) {
|
|
68
|
+
const { area, operation, case: kase, mode: wanted } = record(asked);
|
|
69
|
+
const mode = wanted ?? lastMode ?? 'fast';
|
|
70
|
+
const named = [area, operation, kase].filter((one) => one !== undefined);
|
|
71
|
+
if (named.length > 1 || named.some((one) => typeof one !== 'string') || (mode !== 'fast' && mode !== 'complete'))
|
|
72
|
+
return refused(400, HOW_RUNS);
|
|
73
|
+
const unread = suite.problems;
|
|
74
|
+
const cannot = () => refused(400, `The specification cannot be read, and nothing of it is run until it is: ${unread[0]}${unread.length > 1 ? ` (and ${unread.length - 1} more)` : ''}`);
|
|
75
|
+
const checked = suite.operations.map((written) => (mode === 'fast' ? mustOnly(written) : written));
|
|
76
|
+
const planned = (operations, only) => operations.map((one) => {
|
|
77
|
+
const all = casesOf(one, suite.model);
|
|
78
|
+
return { operation: one, cases: only ? [only] : all, all };
|
|
79
|
+
});
|
|
80
|
+
if (typeof kase === 'string') {
|
|
81
|
+
const found = caseAt(suite, kase, mode);
|
|
82
|
+
if (!found)
|
|
83
|
+
return refused(404, `The specification has no case at "${kase}".`);
|
|
84
|
+
if (unread.length)
|
|
85
|
+
return cannot();
|
|
86
|
+
return { mode, scope: { of: 'case', operation: found.operation.name, kase: found.kase.description }, plan: planned([found.operation], found.kase) };
|
|
87
|
+
}
|
|
88
|
+
if (typeof operation === 'string') {
|
|
89
|
+
const [found, ...others] = checked.filter((one) => idOf('op', one.name) === operation);
|
|
90
|
+
if (!found)
|
|
91
|
+
return refused(404, `The specification has no operation at "${operation}".`);
|
|
92
|
+
if (others.length)
|
|
93
|
+
return refused(409, `The specification has ${others.length + 1} operations at "${operation}": name one otherwise.`);
|
|
94
|
+
if (unread.length)
|
|
95
|
+
return cannot();
|
|
96
|
+
const plan = planned([found]);
|
|
97
|
+
if (!plan[0].cases.length)
|
|
98
|
+
return refused(404, `The operation "${found.name}" has no case to run.`);
|
|
99
|
+
return { mode, scope: { of: 'operation', operation: found.name }, plan };
|
|
100
|
+
}
|
|
101
|
+
const within = typeof area === 'string' ? suite.model.areas.find((one) => idOf('area', one.name) === area)?.name : undefined;
|
|
102
|
+
if (typeof area === 'string' && within === undefined)
|
|
103
|
+
return refused(404, `The specification has no area at "${area}".`);
|
|
104
|
+
if (unread.length)
|
|
105
|
+
return cannot();
|
|
106
|
+
const plan = planned(checked.filter((one) => within === undefined || one.area === within));
|
|
107
|
+
if (!plan.some((one) => one.cases.length))
|
|
108
|
+
return refused(404, within === undefined ? 'The specification has no case to run.' : `The area "${within}" has no case to run.`);
|
|
109
|
+
return { mode, scope: within === undefined ? { of: 'suite' } : { of: 'area', area: within }, plan };
|
|
110
|
+
}
|