@enspirit/opspicy 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +325 -2
- package/bin/entry.js +48 -0
- package/bin/help.js +115 -0
- package/bin/opspicy +27 -0
- package/dist/addresses.js +27 -0
- package/dist/behind.js +64 -0
- package/dist/citizens.js +71 -0
- package/dist/configuration.d.ts +56 -0
- package/dist/configuration.js +66 -0
- package/dist/explorer/afresh.js +43 -0
- package/dist/explorer/api.js +101 -0
- package/dist/explorer/asking.js +59 -0
- package/dist/explorer/build.js +11 -0
- package/dist/explorer/calls.js +42 -0
- package/dist/explorer/document.js +117 -0
- package/dist/explorer/elo-refs.js +153 -0
- package/dist/explorer/elo.js +95 -0
- package/dist/explorer/fonts/OFL.txt +93 -0
- package/dist/explorer/fonts/dm-sans-latin.woff2 +0 -0
- package/dist/explorer/html.js +104 -0
- package/dist/explorer/index.js +62 -0
- package/dist/explorer/json.js +33 -0
- package/dist/explorer/machine.js +34 -0
- package/dist/explorer/masking.js +57 -0
- package/dist/explorer/operation.js +97 -0
- package/dist/explorer/pages.js +159 -0
- package/dist/explorer/script/base.js +103 -0
- package/dist/explorer/script/call.js +161 -0
- package/dist/explorer/script/calling.js +103 -0
- package/dist/explorer/script/connection.js +83 -0
- package/dist/explorer/script/copying.js +75 -0
- package/dist/explorer/script/filter.js +56 -0
- package/dist/explorer/script/formaldef.js +37 -0
- package/dist/explorer/script/main.js +82 -0
- package/dist/explorer/script/markdown.js +143 -0
- package/dist/explorer/script/notes.js +184 -0
- package/dist/explorer/script/noting.js +38 -0
- package/dist/explorer/script/peek.js +62 -0
- package/dist/explorer/script/peeking.js +19 -0
- package/dist/explorer/script/ranking.js +91 -0
- package/dist/explorer/script/review.js +126 -0
- package/dist/explorer/script/rows.js +58 -0
- package/dist/explorer/script/run.js +168 -0
- package/dist/explorer/script/running.js +66 -0
- package/dist/explorer/script/search.js +122 -0
- package/dist/explorer/script/sending.js +64 -0
- package/dist/explorer/script/served.js +51 -0
- package/dist/explorer/serve.js +41 -0
- package/dist/explorer/server.js +143 -0
- package/dist/explorer/site.js +78 -0
- package/dist/explorer/style.css +247 -0
- package/dist/explorer/telling.js +30 -0
- package/dist/explorer/tests.js +78 -0
- package/dist/explorer/wiki.js +90 -0
- package/dist/files.js +178 -0
- package/dist/finding.js +17 -0
- package/dist/judging.js +99 -0
- package/dist/lines.js +30 -0
- package/dist/main.js +128 -0
- package/dist/meaning.js +100 -0
- package/dist/modelling.js +173 -0
- package/dist/naming.js +84 -0
- package/dist/notation.js +119 -0
- package/dist/planning.js +41 -0
- package/dist/reach.js +177 -0
- package/dist/reading.js +135 -0
- package/dist/report-file.js +42 -0
- package/dist/report.js +63 -0
- package/dist/running.js +105 -0
- package/dist/selecting.js +71 -0
- package/dist/starting.js +41 -0
- package/dist/suite.js +32 -0
- package/dist/upgrade.js +27 -0
- package/dist/upgrading.js +76 -0
- package/dist/words.js +103 -0
- package/dist/world.js +129 -0
- package/package.json +57 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bernard Lambeau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,326 @@
|
|
|
1
|
-
#
|
|
1
|
+
# opspicy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Specifies the operations of a system by their clauses, and runs them.**
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
name: RemoveExpense
|
|
9
|
+
description: A member takes back an expense they paid, as if it had never been.
|
|
10
|
+
agent: Member
|
|
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
|
|
17
|
+
ReqPre:
|
|
18
|
+
- (x) the requester is signed in
|
|
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)
|
|
27
|
+
examples:
|
|
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
|
|
34
|
+
|
|
35
|
+
counterexamples:
|
|
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
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
It is one operation of [the example](#try-it), a splitter of a group's shared expenses.
|
|
50
|
+
|
|
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.*
|
|
52
|
+
|
|
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.
|
|
54
|
+
|
|
55
|
+
## Try it
|
|
56
|
+
|
|
57
|
+
To read a suite somebody wrote, and comment it, opspicy is installed from npm, with Node 22.18 or later:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
npm install -g @enspirit/opspicy # or nothing installed: npx @enspirit/opspicy serve path/to/suite
|
|
61
|
+
opspicy serve path/to/suite # http://127.0.0.1:8080: search it, read it, take notes, save them as review.md
|
|
62
|
+
```
|
|
63
|
+
|
|
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).
|
|
65
|
+
|
|
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:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
git clone https://github.com/enspirit/opspicy && cd opspicy && npm ci
|
|
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
|
|
72
|
+
bin/opspicy example/suite # runs the suite
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```
|
|
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
|
|
79
|
+
ReqPre ✓ the requester is signed in
|
|
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"
|
|
90
|
+
✓ counterexample: called as visitor — for "the requester is signed in" [from a condition]
|
|
91
|
+
```
|
|
92
|
+
|
|
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:
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
bin/opspicy example/suite --report=last.json # the same run, kept
|
|
106
|
+
bin/opspicy explorer example/suite --report=last.json # writes explorer.html: open it
|
|
107
|
+
bin/opspicy serve example/suite --report=last.json --api # http://127.0.0.1:8080, and it runs what its page asks
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## How a case runs
|
|
111
|
+
|
|
112
|
+
| | |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| **Given** | The Background: the database is put in a seed, and who calls is signed in. |
|
|
115
|
+
| | The state is observed: `_.before`. |
|
|
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. |
|
|
117
|
+
| **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 · 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. |
|
|
120
|
+
|
|
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.
|
|
122
|
+
|
|
123
|
+
### Two runs
|
|
124
|
+
|
|
125
|
+
| | Checks | Reads |
|
|
126
|
+
| --- | --- | --- |
|
|
127
|
+
| **complete** | Every clause that has a formaldef. | The routes of the state, and the relations of the database. |
|
|
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. |
|
|
129
|
+
|
|
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).
|
|
131
|
+
|
|
132
|
+
## Public interface
|
|
133
|
+
|
|
134
|
+
A command, a notation, and an image.
|
|
135
|
+
|
|
136
|
+
### The command
|
|
137
|
+
|
|
138
|
+
```sh
|
|
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
|
|
141
|
+
opspicy [<suite>] --check # reads it, and says what cannot be read: no system needed
|
|
142
|
+
opspicy [<suite>] --fast # the fast run
|
|
143
|
+
opspicy [<suite>] --report=<file> # also writes what the run decided, as JSON, for the explorer
|
|
144
|
+
opspicy explorer [<suite>] [--report=<file>] [--out=explorer.html] [--name=<name>] [--version=<version>] [--runner=<command>]
|
|
145
|
+
# the wiki of the suite, one standalone HTML file, offline
|
|
146
|
+
opspicy serve [<suite>] [--report=<file>] [--name=<name>] [--version=<version>] [--runner=<command>] [--host=127.0.0.1] [--port=8080]
|
|
147
|
+
# the same wiki, served read-only, re-read when the suite changes
|
|
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
|
|
151
|
+
```
|
|
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
|
+
|
|
155
|
+
There are three ways to have it, and it is the same command in each:
|
|
156
|
+
|
|
157
|
+
| | |
|
|
158
|
+
| --- | --- |
|
|
159
|
+
| The package | `npm install -g @enspirit/opspicy`, or beside a suite as a development dependency; `npx @enspirit/opspicy` installs nothing. It holds JavaScript: Node refuses to run TypeScript under a `node_modules`, so the sources are compiled when the package is made ([`build.ts`](build.ts)), and then only. |
|
|
160
|
+
| A checkout | [`bin/opspicy`](bin/opspicy), after `npm ci`. Node runs the TypeScript files of [`src/`](src/) as they are. |
|
|
161
|
+
| [The image](#the-image) | On its path, where Node runs the TypeScript files too. |
|
|
162
|
+
|
|
163
|
+
Which files it runs is decided in one place, [`bin/entry.js`](bin/entry.js): the sources where they are and Node runs them, the compiled files otherwise.
|
|
164
|
+
|
|
165
|
+
What of the suite is run, and how much of it is told, is asked through the environment:
|
|
166
|
+
|
|
167
|
+
| | |
|
|
168
|
+
| --- | --- |
|
|
169
|
+
| `O=expenses` | Only the operations whose name, file or route holds that text: `O=AddExpense`, `O=expenses/`, `O=/api/expenses`. |
|
|
170
|
+
| `METHOD=DELETE` | Only those entered by that method. |
|
|
171
|
+
| `CASE=blank` | Only the cases whose `when` holds that text. |
|
|
172
|
+
| `ROBUST=no\|only\|generated` | Only the examples; only the counterexamples; only those the conditions give. |
|
|
173
|
+
| `FAILFAST=yes` | Stops at the first case that fails. |
|
|
174
|
+
| `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. |
|
|
176
|
+
|
|
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.
|
|
178
|
+
|
|
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.
|
|
180
|
+
|
|
181
|
+
A system that stops answering during the run is not that: each case then could not be run, which is a case that does not pass.
|
|
182
|
+
|
|
183
|
+
### The image
|
|
184
|
+
|
|
185
|
+
`enspirit/opspicy`, on Docker Hub: Node, `opspicy`, and `tsc` with Node's types. Its directory is `/suite`.
|
|
186
|
+
|
|
187
|
+
| Tag | Is |
|
|
188
|
+
| --- | --- |
|
|
189
|
+
| `0.3.0` | The version tagged `v0.3.0`: the image of that commit, as it was tested. Name one of these. |
|
|
190
|
+
| `latest`, `sha-<commit>` | The main branch, and one commit of it. |
|
|
191
|
+
|
|
192
|
+
**As a tool**, on a suite that is mounted:
|
|
193
|
+
|
|
194
|
+
```sh
|
|
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
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The last one is read-only: `--api` is offered on the machine the server runs on, which a container is not.
|
|
202
|
+
|
|
203
|
+
**As the base of a suite's image**, where the system is reached: on the network of its stack, say.
|
|
204
|
+
|
|
205
|
+
```dockerfile
|
|
206
|
+
FROM enspirit/opspicy:0.3.0
|
|
207
|
+
COPY . /suite
|
|
208
|
+
CMD ["tail", "-f", "/dev/null"] # it sleeps, and `opspicy` is run in it
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
A suite's `config.ts` imports its type from where the image has it, `/opt/opspicy/src/configuration.ts`, and nothing else: [`example/suite/`](example/suite/) is written that way, with the `tsconfig.json` that checks it.
|
|
212
|
+
|
|
213
|
+
### A suite
|
|
214
|
+
|
|
215
|
+
A directory: a `config.ts`, which says how the suite meets the system, and a `specification/`, which says everything else, by area.
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
config.ts
|
|
219
|
+
specification/
|
|
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
|
|
223
|
+
_shared/ predicates.yml functions.yml conditions.yml types.elo
|
|
224
|
+
<area>/ predicates.yml functions.yml conditions.yml types.elo
|
|
225
|
+
operations/<Operation>.yml
|
|
226
|
+
observations/<Observation>.yml
|
|
227
|
+
```
|
|
228
|
+
|
|
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).
|
|
230
|
+
|
|
231
|
+
### The explorer
|
|
232
|
+
|
|
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.
|
|
234
|
+
|
|
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.
|
|
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
|
+
|
|
239
|
+
## Depends on
|
|
240
|
+
|
|
241
|
+
| | |
|
|
242
|
+
| --- | --- |
|
|
243
|
+
| Node.js 22.18 or later | It runs the TypeScript files directly: from a checkout and in the image, nothing is compiled. |
|
|
244
|
+
| `@enspirit/elo`, `luxon` | What a formaldef is written in, and the types; the dates Elo computes with. |
|
|
245
|
+
| `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
|
+
| `@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 relations. |
|
|
248
|
+
| `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
|
+
| `playwright-core` (development) | Drives the installed Chrome in the browser tests; downloads no browser. |
|
|
250
|
+
| [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. |
|
|
251
|
+
|
|
252
|
+
## Must not
|
|
253
|
+
|
|
254
|
+
1. **Know the system it runs against.** No route, no name of a variable, no shape of an answer but what the configuration tells it.
|
|
255
|
+
2. **Act on the system but through its front door**, and through what the configuration gives it to set a Background.
|
|
256
|
+
3. **Write the database.** It is opened to read and nothing else.
|
|
257
|
+
4. **Make a precondition hold.** A case that does not start where it says it does is a finding, not something to arrange.
|
|
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.
|
|
259
|
+
|
|
260
|
+
## Harness
|
|
261
|
+
|
|
262
|
+
```sh
|
|
263
|
+
npm ci
|
|
264
|
+
npm run typecheck # everything, example/splitter.ts included
|
|
265
|
+
npm test # needs neither a system nor a browser
|
|
266
|
+
npm run test:browser # needs Chrome: the one installed, or the executable CHROME names
|
|
267
|
+
npm run test:package # needs the registry: installs what would be published, and runs it
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
| What | Is held by |
|
|
271
|
+
| --- | --- |
|
|
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. |
|
|
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. |
|
|
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`. |
|
|
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. |
|
|
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). |
|
|
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. |
|
|
280
|
+
| The image | CI builds it, type-checks the example's suite in it and runs it there. |
|
|
281
|
+
| What these documents link to | [`test/links.test.ts`](test/links.test.ts): every link, and every heading one names, exists. |
|
|
282
|
+
|
|
283
|
+
CI ([`.github/workflows/test.yml`](.github/workflows/test.yml)) runs all of it on Node 22.18 and 24, then pushes the image from the main branch and from a version tag.
|
|
284
|
+
|
|
285
|
+
To release: the version in `package.json`, and in the examples of this document, pushed to the main branch; then, once CI has pushed the image of that commit, a tag `v` + that version. CI refuses a tag that names another version, and gives the image of the commit its version: it is not built again.
|
|
286
|
+
|
|
287
|
+
The package is published by hand, from a checkout of that tag: `npm ci`, `npm run test:package`, then `npm publish`, which builds `dist/` first and publishes for everybody, as the manifest says. CI does not: it holds no token of npm.
|
|
288
|
+
|
|
289
|
+
## Status
|
|
290
|
+
|
|
291
|
+
> **In flight:** nothing.
|
|
292
|
+
|
|
293
|
+
One suite uses it: [the operations of saras](https://github.com/enspirit/saras/tree/main/tests/operations).
|
|
294
|
+
|
|
295
|
+
What the notation cannot say yet:
|
|
296
|
+
|
|
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.
|
|
298
|
+
- **One precondition violated per counterexample**, so the order of two refusals is said nowhere.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
303
|
+
- **A trigger is told.** `ReqTrig` says when an operation is performed without being asked, and one call shows nothing of it.
|
|
304
|
+
- **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
|
+
- **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
|
+
- **`PATCH` is not a method an `entry` says.**
|
|
307
|
+
- **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
|
+
- **Elo has no pattern**: "is an address" is approximated.
|
|
309
|
+
- **A Background is a seed of the database.** What else the world holds (a mail server, say) is not put back between cases.
|
|
310
|
+
- **`atRest` looks at the database.** Work a system starts without leaving a trace there is not waited for.
|
|
311
|
+
|
|
312
|
+
What the runner does not do yet:
|
|
313
|
+
|
|
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 no relation is read (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.
|
|
315
|
+
- **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
|
+
- **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
|
+
- **A cookie is kept until it is taken back by name**: when it expires is not read.
|
|
318
|
+
- **`atRest` needs a `database`**, and is not waited for without one. It is waited for after any call that is not a `GET` and was not refused.
|
|
319
|
+
- **Gaps are not told at `LOG_LEVEL=WARN`**, and asking for one operation that has no case answers that nothing was run, without its gap.
|
|
320
|
+
- **Notes and the target of calls are kept by the name of the specification**, its directory's when `--name=` says none: two suites both in a `tests/operations`, opened as files in one browser, share them. Name each.
|
|
321
|
+
- **The API of a served explorer answers any program of the machine it is on**, not only the page it gave: it tells a page of another site from its own, and nothing more.
|
|
322
|
+
- **At `TRACE`, the path of the call that signs somebody in is shown**: a configuration that signs in by an address holding a token shows it there.
|
|
323
|
+
|
|
324
|
+
## Licence
|
|
325
|
+
|
|
326
|
+
[MIT](LICENSE). A document the explorer writes has inside it DM Sans, under the [SIL Open Font License](src/explorer/fonts/OFL.txt), and elo-form with Elo and Luxon, each MIT. The package holds the font too, with that licence beside it.
|
package/bin/entry.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Which file `opspicy` runs, and what it hands it: decided here, apart from the launcher that
|
|
2
|
+
// does it (opspicy), so that a table of cases holds it (test/launcher.test.ts). JavaScript, as
|
|
3
|
+
// the launcher is: installed, both are under a node_modules, where Node strips no types.
|
|
4
|
+
|
|
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', upgrade: 'upgrade' };
|
|
7
|
+
const RUNNER = 'main';
|
|
8
|
+
|
|
9
|
+
/** Where Node refuses to run TypeScript: its own rule, a directory of that name anywhere above. */
|
|
10
|
+
const UNDER_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The file to run, from the directory of opspicy, and its arguments: the sub-command is named
|
|
14
|
+
* first or not at all, and is not handed on, each file reading its arguments as if it were run
|
|
15
|
+
* alone. The sources are run where they are and Node runs them, so from a checkout and in the
|
|
16
|
+
* image, whether or not a dist/ was built there: what is edited is what runs. The compiled files
|
|
17
|
+
* are run otherwise, which is what the package on npm is.
|
|
18
|
+
*
|
|
19
|
+
* @param {string[]} args what the command was given
|
|
20
|
+
* @param {{ at: string, sources: boolean }} where the directory of opspicy, and whether it holds src/
|
|
21
|
+
* @returns {{ file: string, args: string[] }}
|
|
22
|
+
*/
|
|
23
|
+
export function entryOf(args, { at, sources }) {
|
|
24
|
+
const asked = Object.hasOwn(ENTRIES, args[0] ?? '') ? ENTRIES[args[0]] : null;
|
|
25
|
+
const [directory, extension] = sources && !UNDER_NODE_MODULES.test(at) ? ['src', 'ts'] : ['dist', 'js'];
|
|
26
|
+
return { file: `${directory}/${asked ?? RUNNER}.${extension}`, args: asked ? args.slice(1) : args };
|
|
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
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// opspicy <suite> [--check] [--fast] [--report=<file>] runs the suite, or reads it (main)
|
|
3
|
+
// opspicy explorer [<suite>] [--out=<file>] … writes its explorer, one file (explorer/build)
|
|
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)
|
|
6
|
+
//
|
|
7
|
+
// The suite is a directory: this one when only options are given. Each of the three is a file that reads
|
|
8
|
+
// the arguments of its process: this one says which (entry.js), takes the sub-command away, and
|
|
9
|
+
// runs it in this same process. From a checkout and in the image that file is TypeScript, of
|
|
10
|
+
// src/, which Node runs as it is; installed as a package it is the JavaScript of dist/.
|
|
11
|
+
//
|
|
12
|
+
// Node, not a shell: the one command is the same on macOS, Linux and Windows.
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { entryOf, helpOf } from './entry.js';
|
|
16
|
+
import { helpText } from './help.js';
|
|
17
|
+
|
|
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
|
+
}
|
|
25
|
+
const { file, args } = entryOf(process.argv.slice(2), { at: fileURLToPath(root), sources: existsSync(new URL('src/main.ts', root)) });
|
|
26
|
+
process.argv.splice(2, Infinity, ...args);
|
|
27
|
+
await import(new URL(file, root).href);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Where a case and a clause are found: at an address made of their name. A sentence is named
|
|
2
|
+
// after where it stands (`CreateBoard/ReqPre/2`) unless its long form names it, and a name that
|
|
3
|
+
// is chosen may be the one another has, or become it once it is an address. Pure.
|
|
4
|
+
import { casesOf } from './planning.js';
|
|
5
|
+
/**
|
|
6
|
+
* The address a name gives: every character that is not a letter, a digit, `_` or `-` is a `-`.
|
|
7
|
+
* The explorer makes its anchors so, and a case is run by its anchor: `A/b` and `A b` are one.
|
|
8
|
+
*/
|
|
9
|
+
export const addressOf = (name) => name.replace(/[^A-Za-z0-9_-]/g, '-');
|
|
10
|
+
const told = (one) => `"${one.name}"${one.source ? ` (${one.source})` : ''}`;
|
|
11
|
+
/** Those of one kind that are at the address of another: each address with all who are there. */
|
|
12
|
+
function together(kind, citizens) {
|
|
13
|
+
const at = new Map();
|
|
14
|
+
for (const one of citizens)
|
|
15
|
+
at.set(addressOf(one.name), [...(at.get(addressOf(one.name)) ?? []), one]);
|
|
16
|
+
return [...at.values()].filter((all) => all.length > 1).map((all) => `the ${kind}s ${all.map(told).join(' and ')} are at the same address: name one otherwise`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* What keeps each case, and each clause, of a suite from having an address of its own, across
|
|
20
|
+
* its operations: the cases it writes and those its conditions give it, its clauses and what an
|
|
21
|
+
* example alone also shows.
|
|
22
|
+
*/
|
|
23
|
+
export function sharedAddresses(operations, model) {
|
|
24
|
+
const cases = operations.flatMap((operation) => casesOf(operation, model));
|
|
25
|
+
const clauses = operations.flatMap((operation) => [...operation.clauses, ...operation.cases.flatMap((kase) => kase.and)]);
|
|
26
|
+
return [...together('case', cases), ...together('clause', clauses)];
|
|
27
|
+
}
|
package/dist/behind.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Whether a formaldef reads behind the front door: the relations of the database, `db`. What
|
|
2
|
+
// does is checked in the complete run only, and says so with `(+)`: the fast run reads no
|
|
3
|
+
// relation, and a clause that compared nothing with nothing would hold. Pure: Elo's parser is
|
|
4
|
+
// asked how the expression reads, and nothing is run.
|
|
5
|
+
import { parse } from '@enspirit/elo';
|
|
6
|
+
import { bare, definitionsUsed } from './naming.js';
|
|
7
|
+
const isTree = (value) => Boolean(value) && typeof value === 'object';
|
|
8
|
+
/** Where the relations are, beside the name `db`: in what there was, `old`, and in what was observed, `_.before` and `_.after`. */
|
|
9
|
+
const holdsRelations = (node) => isTree(node) && ((node.type === 'variable' && node.name === 'old') || (node.type === 'member_access' && ['before', 'after'].includes(String(node.property)) && isTree(node.object) && node.object.name === '_'));
|
|
10
|
+
/** `fetch(old, 'db')`: the member read by its key. */
|
|
11
|
+
const fetchesRelations = (args) => Array.isArray(args) && holdsRelations(args[0]) && isTree(args[1]) && args[1].type === 'string' && args[1].value === 'db';
|
|
12
|
+
/**
|
|
13
|
+
* Whether a tree of Elo reads the relations: it names `db` where nothing it binds itself is called
|
|
14
|
+
* so, or reads it of `old` or of what was observed. As Elo's parser reads it: a member `.db` of
|
|
15
|
+
* anything else, a text and a comment are not it. `_` handed whole to something is not followed.
|
|
16
|
+
*/
|
|
17
|
+
function reads(node, bound) {
|
|
18
|
+
if (Array.isArray(node))
|
|
19
|
+
return node.some((one) => reads(one, bound));
|
|
20
|
+
if (!isTree(node))
|
|
21
|
+
return false;
|
|
22
|
+
if (node.type === 'variable')
|
|
23
|
+
return node.name === 'db' && !bound.has('db');
|
|
24
|
+
if (node.type === 'member_access' && node.property === 'db' && holdsRelations(node.object))
|
|
25
|
+
return true;
|
|
26
|
+
if (node.type === 'function_call' && node.name === 'fetch' && fetchesRelations(node.args))
|
|
27
|
+
return true;
|
|
28
|
+
if (node.type === 'lambda')
|
|
29
|
+
return reads(node.body, new Set([...bound, ...node.params]));
|
|
30
|
+
if (node.type === 'let')
|
|
31
|
+
return readsLet(node.bindings, node.body, bound);
|
|
32
|
+
return Object.values(node).some((child) => reads(child, bound));
|
|
33
|
+
}
|
|
34
|
+
/** A `let`: each name is bound for those after it, and in its body. */
|
|
35
|
+
function readsLet(bindings, body, bound) {
|
|
36
|
+
let inner = bound;
|
|
37
|
+
for (const one of bindings) {
|
|
38
|
+
if (reads(one.value, inner))
|
|
39
|
+
return true;
|
|
40
|
+
inner = new Set([...inner, one.name]);
|
|
41
|
+
}
|
|
42
|
+
return reads(body, inner);
|
|
43
|
+
}
|
|
44
|
+
/** The same of a text. One Elo cannot read is told elsewhere: here it reads the database if it says the word at all. */
|
|
45
|
+
function readsRelations(text, given) {
|
|
46
|
+
try {
|
|
47
|
+
return reads(parse(text), new Set(given));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return /(?<![\w.])db\b/.test(bare(text));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Asked once of each text: a predicate is named by many clauses, and each asks again. */
|
|
54
|
+
const asked = new Map();
|
|
55
|
+
function relationsRead(text, given = []) {
|
|
56
|
+
const key = `${given.join(',')}\n${text}`;
|
|
57
|
+
if (!asked.has(key))
|
|
58
|
+
asked.set(key, readsRelations(text, given));
|
|
59
|
+
return asked.get(key);
|
|
60
|
+
}
|
|
61
|
+
/** Whether an expression reads what only the database shows: itself, or through a predicate or a function it names. */
|
|
62
|
+
export function readsDatabase(source, definitions) {
|
|
63
|
+
return relationsRead(source) || definitionsUsed(source, definitions).some((one) => relationsRead(one.formaldef, one.parameters));
|
|
64
|
+
}
|