@rljson/fs-agent 0.2.0 → 0.2.2
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.api.md +128 -5
- package/README.architecture.md +52 -3
- package/README.md +2 -2
- package/README.public.md +42 -5
- package/README.tests.md +44 -13
- package/dist/README.api.md +128 -5
- package/dist/README.architecture.md +52 -3
- package/dist/README.md +2 -2
- package/dist/README.public.md +42 -5
- package/dist/README.tests.md +44 -13
- package/dist/fs-agent.d.ts +101 -9
- package/dist/fs-agent.js +4977 -4436
- package/dist/fs-atomic-write.d.ts +11 -0
- package/dist/fs-history.d.ts +83 -0
- package/dist/fs-scanner.d.ts +19 -0
- package/dist/fs-send.d.ts +14 -1
- package/dist/fs-signals.d.ts +45 -2
- package/dist/fs-stamps.d.ts +8 -0
- package/dist/fs_agent_version.d.ts +2 -0
- package/dist/index.d.ts +5 -3
- package/package.json +28 -42
package/README.api.md
CHANGED
|
@@ -8,7 +8,7 @@ found in the LICENSE file in the root of this package.
|
|
|
8
8
|
|
|
9
9
|
# @rljson/fs-agent — API reference
|
|
10
10
|
|
|
11
|
-
Every symbol the package exports, grouped by what it is for. **
|
|
11
|
+
Every symbol the package exports, grouped by what it is for. **63 exports.**
|
|
12
12
|
|
|
13
13
|
Most consumers need only the first section. The rest is exported because a host
|
|
14
14
|
builds on it — a scanner to watch a folder, the chain to show a history, an
|
|
@@ -19,7 +19,8 @@ to reach for every part.
|
|
|
19
19
|
| --- | --- |
|
|
20
20
|
| to sync a folder | [The agent](#the-agent) |
|
|
21
21
|
| to know what the agent did | [Signals](#signals) · [Observability](#observability) |
|
|
22
|
-
|
|
|
22
|
+
| to show a folder's history, or go back to a revision | [The history](#the-history) |
|
|
23
|
+
| the chain underneath | [The edit chain](#the-edit-chain) |
|
|
23
24
|
| to scan, store or restore a folder yourself | [Scanner and adapters](#scanner-and-adapters) |
|
|
24
25
|
| to write into a synced folder | [Utilities](#utilities) |
|
|
25
26
|
| the design behind any of it | [README.architecture.md](README.architecture.md) |
|
|
@@ -46,9 +47,13 @@ pass `client.bs`, or use `FsAgent.fromClient`, which wires this correctly.
|
|
|
46
47
|
| `syncToDb(db, connector, treeKey)` | `Promise<() => void>` | **sending.** Watches the folder, authors an entry per change, announces its head. Returns `stop()` |
|
|
47
48
|
| `syncFromDb(db, connector, treeKey)` | `Promise<() => void>` | **receiving.** Hears the heads the network says and applies, adopts, announces or merges. Returns `stop()` |
|
|
48
49
|
| `ownHead` | `string \| undefined` | the chain entry this folder stands on; persisted in `.fsagent-state.json` |
|
|
50
|
+
| `headInfo()` | `Promise<FsHistoryEntry \| undefined>` | that entry as the history lists it — what it changed, when, and its stamp. See [The history](#the-history) |
|
|
51
|
+
| `history(options?)` | `Promise<FsHistoryPage>` | one page of the folder's history, newest first |
|
|
52
|
+
| `relationTo(head)` | `Promise<Relation \| undefined>` | how this folder's head stands to another: `same`, `behind`, `ahead`, `fork` or `incomplete` |
|
|
53
|
+
| `restoreRevision(head)` | `Promise<'restored' \| 'unknown' \| 'busy'>` | makes the folder exactly that revision, as a new edit every node follows |
|
|
49
54
|
| `dispose()` | `void` | releases the watcher and abandons a pending join |
|
|
50
55
|
| `extract()` | `Promise<FsTree>` | scans the folder into a tree, without storing or announcing it |
|
|
51
|
-
| `restore(tree, targetPath?, options?)` | `Promise<void>` | writes a tree to disk. See [`RestoreOptions`](#interface-restoreoptions) |
|
|
56
|
+
| `restore(tree, targetPath?, options?)` | `Promise<void>` | writes a tree to disk. See [`RestoreOptions`](#interface-restoreoptions) and [the restore errors](#restore-errors) |
|
|
52
57
|
| `storeInDb(db, treeKey, options?)` | `Promise<string>` | scans and stores, returning the tree ref |
|
|
53
58
|
| `loadFromDb(db, treeKey, rootRef, targetPath?, options?)` | `Promise<void>` | fetches a tree by ref and writes it out |
|
|
54
59
|
| `getTree()` | `FsTree \| null` | the last scanned tree |
|
|
@@ -125,6 +130,7 @@ a host aggregating several agents can own one and feed it from each `onSignal`.
|
|
|
125
130
|
|
|
126
131
|
| field | type | |
|
|
127
132
|
| --- | --- | --- |
|
|
133
|
+
| `id` | `string` | the signal's identity: a hash of what it says, unique within the log, the same on every read. Key a row by it, or remember by it what a person has seen |
|
|
128
134
|
| `kind` | `FsSignalKind` | what happened |
|
|
129
135
|
| `at` | `number` | epoch ms |
|
|
130
136
|
| `paths` | `readonly string[]` | affected paths, sorted, at most `SIGNAL_PATHS_MAX` |
|
|
@@ -132,13 +138,15 @@ a host aggregating several agents can own one and feed it from each `onSignal`.
|
|
|
132
138
|
| `action` | `FsSignalAction` | whether a person has to do something |
|
|
133
139
|
| `decidedBy` | `FsSignalDecidedBy` | who chose the outcome |
|
|
134
140
|
| `copyPath` | `string` | where the version that lost the path was kept |
|
|
141
|
+
| `copies` | `Record<string, string>` | for a join: where each named path's own version went, original → copy. A path the join could not move has none |
|
|
142
|
+
| `head` | `string` | the chain entry the signal belongs to — for a merge conflict, the merge, which `history()` lists |
|
|
135
143
|
| `detail` | `string` | one sentence for a person; never a stack trace |
|
|
136
144
|
|
|
137
145
|
### `type FsSignalKind`
|
|
138
146
|
|
|
139
147
|
| `kind` | `action` | what it means |
|
|
140
148
|
| --- | --- | --- |
|
|
141
|
-
| `conflict/arbitrary` | `review` | two machines changed one file at once, or one deleted what the other edited. Both versions were kept (`copyPath`)
|
|
149
|
+
| `conflict/arbitrary` | `review` | two machines changed one file at once, or one deleted what the other edited. Both versions were kept (`copyPath`, `decidedBy: 'stamp'`): which keeps the name follows the order the fleet heard them in. Or the edit was (no `copyPath`, `decidedBy: 'chain'`): an edit beats a deletion by rule |
|
|
142
150
|
| `collision/type` | **`required`** | a directory and a file at one path: the directory keeps it, the file is at `copyPath` |
|
|
143
151
|
| `deletion/refused` | **`required`** | a deletion beyond the guard's floors was not made — not authored at the sender, not applied at a receiver |
|
|
144
152
|
| `join/recovered` | `review` | a joining machine moved files the history had removed into `.fsagent-recovered/` |
|
|
@@ -159,7 +167,8 @@ refused, so nothing was chosen. None of them compares two machines' clocks.
|
|
|
159
167
|
|
|
160
168
|
### `type FsSignalInput`
|
|
161
169
|
|
|
162
|
-
What a producer passes before the sink stamps `at` and counts
|
|
170
|
+
What a producer passes before the sink stamps `at`, derives `id` and counts
|
|
171
|
+
`paths`.
|
|
163
172
|
|
|
164
173
|
### `type FsSignalLog`
|
|
165
174
|
|
|
@@ -183,6 +192,115 @@ The persisted shape: `{ signals, totals }`.
|
|
|
183
192
|
|
|
184
193
|
---
|
|
185
194
|
|
|
195
|
+
## The history
|
|
196
|
+
|
|
197
|
+
**What a host shows about a folder's past, and how it goes back.** Read from
|
|
198
|
+
the edit chain, the one order every node agrees on — not from a node's own
|
|
199
|
+
insert rows, which miss every state it took from a peer.
|
|
200
|
+
|
|
201
|
+
| member | |
|
|
202
|
+
| --- | --- |
|
|
203
|
+
| `agent.headInfo()` | where the folder stands, as one `FsHistoryEntry` |
|
|
204
|
+
| `agent.history(options?)` | one page, newest first, from the own head or `options.from` |
|
|
205
|
+
| `agent.relationTo(head)` | how the own head stands to another |
|
|
206
|
+
| `agent.restoreRevision(head)` | goes back to a revision, exactly |
|
|
207
|
+
| `readFsHistory(db, treeKey, options)` | the same pages from a store this process does not own |
|
|
208
|
+
|
|
209
|
+
**The order.** Newest first by stamp — the announcement that first carried an
|
|
210
|
+
entry to the fleet; an entry not stamped yet first of all — then, within one
|
|
211
|
+
announcement, by the authoring node's time. Never an entry above one made on
|
|
212
|
+
top of it. A page continues exactly where the last stopped:
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
let page = await agent.history({ limit: 50 });
|
|
216
|
+
show(page.entries);
|
|
217
|
+
while (page.cursor) {
|
|
218
|
+
page = await agent.history({ cursor: page.cursor });
|
|
219
|
+
show(page.entries);
|
|
220
|
+
}
|
|
221
|
+
if (page.missing.length > 0) say('older history is not on this machine');
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Going back.** `restoreRevision(head)` makes the folder exactly that
|
|
225
|
+
revision: what it holds is written, what it lacks is deleted, and the result is
|
|
226
|
+
authored as a new edit, so every node follows and the revision being left stays
|
|
227
|
+
in the history. Work not yet recorded is recorded first, and a file still being
|
|
228
|
+
written is waited out. It returns `unknown` for an entry this node cannot read,
|
|
229
|
+
and `busy` when a file is still being written after the wait. It rejects with a
|
|
230
|
+
`MassDeleteRefusedError` when the revision would delete a large part of the
|
|
231
|
+
folder. In all three cases the folder is unchanged.
|
|
232
|
+
|
|
233
|
+
### `interface FsHistoryEntry`
|
|
234
|
+
|
|
235
|
+
An `FsChainEntry` (`head`, `timeId`, `treeRef`, `previous`, `changed`,
|
|
236
|
+
`removed`) and:
|
|
237
|
+
|
|
238
|
+
| field | type | |
|
|
239
|
+
| --- | --- | --- |
|
|
240
|
+
| `kind` | `'edit' \| 'merge' \| 'root'` | a change one node made; two lineages joined (`previous` names both); where a lineage began |
|
|
241
|
+
| `at` | `number` | when the authoring node made the edit, epoch ms by **its** clock. Absent for a merge and a root, which carry no time |
|
|
242
|
+
| `stamp` | `RefStamp` | the announcement that first carried it to the fleet, as this node learned it — the order no clock decides. Absent until this node learned it |
|
|
243
|
+
|
|
244
|
+
Two entries with one `treeRef` hold the same files — a restore, or two merges
|
|
245
|
+
of one fork.
|
|
246
|
+
|
|
247
|
+
### `interface FsHistoryOptions`
|
|
248
|
+
|
|
249
|
+
`from` — the entry to start from (the agent defaults it to its own head);
|
|
250
|
+
`cursor` — the previous page's, which wins over `from`; `limit` — entries per
|
|
251
|
+
page, default `FS_HISTORY_PAGE` (50), at most 500.
|
|
252
|
+
|
|
253
|
+
### `interface FsHistoryPage`
|
|
254
|
+
|
|
255
|
+
`entries`, newest first; `cursor`, absent when nothing is left (opaque — pass it
|
|
256
|
+
back as it came); `missing`, entries named as a `previous` that this node cannot
|
|
257
|
+
read, below which nothing can be listed.
|
|
258
|
+
|
|
259
|
+
### `readFsHistory(db, treeKey, options)`
|
|
260
|
+
|
|
261
|
+
The history from a database this process does not own — the store of an agent
|
|
262
|
+
running in another process, opened read-only. Writes nothing: no table is
|
|
263
|
+
created, and stamps are absent when their table is.
|
|
264
|
+
|
|
265
|
+
### `walkFsHistory(source, options)` · `interface FsHistorySource`
|
|
266
|
+
|
|
267
|
+
The walk underneath both, over any source that can read an entry
|
|
268
|
+
(`entry(head)`) and its stamp (`stamp(head)`).
|
|
269
|
+
|
|
270
|
+
### `readFsStamps(db, treeKey)`
|
|
271
|
+
|
|
272
|
+
Every stamp a route's entries carry, read without writing: `Map<entry, RefStamp>`.
|
|
273
|
+
|
|
274
|
+
### `FS_HISTORY_PAGE`
|
|
275
|
+
|
|
276
|
+
`50` — a page's size when the caller does not say.
|
|
277
|
+
|
|
278
|
+
### `type Relation`
|
|
279
|
+
|
|
280
|
+
`{ verdict: 'same' | 'behind' | 'ahead' | 'incomplete' }` or
|
|
281
|
+
`{ verdict: 'fork'; base }`. `incomplete`: an entry could not be read, so a
|
|
282
|
+
fork cannot be told from a lag. Two different heads can hold the same files;
|
|
283
|
+
compare their tree refs for that.
|
|
284
|
+
|
|
285
|
+
### `type ReceiveOutcome`
|
|
286
|
+
|
|
287
|
+
What receiving one head made a node do: `no-head`, `in-sync`, `applied`,
|
|
288
|
+
`refused`, `announced`, `adopted`, `merged`, `deferred` or `blocked`.
|
|
289
|
+
|
|
290
|
+
### Restore errors
|
|
291
|
+
|
|
292
|
+
A restore that could not finish rejects with a `RestoreIncompleteError`:
|
|
293
|
+
|
|
294
|
+
| class | |
|
|
295
|
+
| --- | --- |
|
|
296
|
+
| `MassDeleteRefusedError` | the prune would delete a large part of the folder (`wouldPrune`, `totalFiles`, `incomingFiles`). Judged before anything is written: the folder is unchanged |
|
|
297
|
+
| `PartialRestoreError` | files another process holds open; everything else was written |
|
|
298
|
+
| `BlobUnavailableError` | content no reachable store serves yet |
|
|
299
|
+
| `UnwritablePathError` | a path this filesystem rejects |
|
|
300
|
+
| `DiskFullError` | no space left |
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
186
304
|
## Observability
|
|
187
305
|
|
|
188
306
|
| member | type | |
|
|
@@ -325,6 +443,11 @@ produce bytes nobody wrote — measured at 1 520 blended pairs in 2 000.
|
|
|
325
443
|
|
|
326
444
|
Writes to a temporary file beside the target and renames it into place.
|
|
327
445
|
|
|
446
|
+
### `atomicWriteFileSync(path, content)`
|
|
447
|
+
|
|
448
|
+
The same, synchronously — for a small file that must be on disk before the
|
|
449
|
+
caller returns. The agent writes its signal log and state file through it.
|
|
450
|
+
|
|
328
451
|
### `atomicWriteStream(path, stream)`
|
|
329
452
|
|
|
330
453
|
The same, from a stream.
|
package/README.architecture.md
CHANGED
|
@@ -521,6 +521,14 @@ never of a person: nothing is authored, the folder keeps its head, and
|
|
|
521
521
|
renamed while the agent was down, and a few files deleted while it was down are
|
|
522
522
|
all ordinary edits.
|
|
523
523
|
|
|
524
|
+
A refusal holds its files until they are back. A refused folder that fills up
|
|
525
|
+
again one file at a time — a backup copied in, a drive reconnecting — shrinks
|
|
526
|
+
below the floors part-way, and the files still to come would otherwise be
|
|
527
|
+
authored as deleted while they are being copied. So what a refusal held back
|
|
528
|
+
stays refused while any of it is gone; a held file is let go when it is back,
|
|
529
|
+
when the head no longer has it, or when the watcher sees it deleted after it
|
|
530
|
+
came back.
|
|
531
|
+
|
|
524
532
|
### At the receiver
|
|
525
533
|
|
|
526
534
|
An apply that would **lose** more than the same floors — content the target tree
|
|
@@ -635,9 +643,50 @@ so a folder that produced two thousand refusals still says so. One signal names
|
|
|
635
643
|
at most `SIGNAL_PATHS_MAX` (20) paths and counts the rest. `addOnce` keys are
|
|
636
644
|
bounded too (`SIGNAL_ONCE_MAX`); `repair/blocked` is keyed on the **pair** of
|
|
637
645
|
heads it is between. The log is persisted to `SIGNAL_LOG_FILE`
|
|
638
|
-
(`.fsagent-signals.json`) inside the synced folder
|
|
639
|
-
firing subscribers. `.sync-errors.log`
|
|
640
|
-
exceptions, which are not signals.
|
|
646
|
+
(`.fsagent-signals.json`) inside the synced folder, through a staging file and a
|
|
647
|
+
rename, and read back lazily, without firing subscribers. `.sync-errors.log`
|
|
648
|
+
stays the record of internal failures — exceptions, which are not signals.
|
|
649
|
+
|
|
650
|
+
**A signal's `id` is derived, not counted**: a hash of what it says, with a
|
|
651
|
+
counter only for two signals that say the same thing in one millisecond. A log
|
|
652
|
+
written before ids existed gets the same ids on every read, so a host can key a
|
|
653
|
+
row by one, or remember what a person has seen. A merge conflict names the merge
|
|
654
|
+
(`head`), and a join names where each file it moved went (`copies`).
|
|
655
|
+
|
|
656
|
+
## The history a host shows, and going back (`src/fs-history.ts`)
|
|
657
|
+
|
|
658
|
+
A host lists a folder's past from the chain, never from a node's own insert
|
|
659
|
+
rows: those record only the trees that node stored itself, so after a pull the
|
|
660
|
+
newest row is not the state the folder is in.
|
|
661
|
+
|
|
662
|
+
**The order is a walk, not a sort.** The chain is a graph — two lineages run
|
|
663
|
+
side by side until a merge — and a person reads it a page at a time, so the
|
|
664
|
+
walk keeps a queue and takes the newest waiting entry: by stamp (an
|
|
665
|
+
announcement carries everything below the head it names, so an entry is never
|
|
666
|
+
stamped later than one made on top of it; an unstamped entry has not reached
|
|
667
|
+
the fleet and is newest of all), then within one announcement by the authoring
|
|
668
|
+
node's time, a merge taking the time of the entry it was reached from. And an
|
|
669
|
+
entry is never taken while one made on top of it waits, whatever the keys say.
|
|
670
|
+
The queue is the page's cursor.
|
|
671
|
+
|
|
672
|
+
**Going back is an edit.** `restoreRevision` records what the folder holds,
|
|
673
|
+
writes the revision with `cleanTarget`, and authors the result on top of the own
|
|
674
|
+
head, so every node follows and nothing leaves the history. Three things make
|
|
675
|
+
that safe:
|
|
676
|
+
|
|
677
|
+
- a file the scanner deferred — new, or written to while the scan ran — is in
|
|
678
|
+
no entry yet, and a prune or an overwrite would lose it with no copy
|
|
679
|
+
anywhere; the restore rescans until nothing is deferred, and gives up as
|
|
680
|
+
`busy` after `RESTORE_SETTLE_PASSES`;
|
|
681
|
+
- the prune's deletions are recorded as deletions seen, so the authoring guard
|
|
682
|
+
does not hold back what a person asked for;
|
|
683
|
+
- the mass-delete guard judges before anything is written. Judged after, a
|
|
684
|
+
refused restore had already overwritten what the tree holds, and the watcher
|
|
685
|
+
recorded that half as an edit.
|
|
686
|
+
|
|
687
|
+
A prune with `cleanTarget` touches content only: what the scanner ignores — the
|
|
688
|
+
agent's own state and signal log, `.fsagent-recovered/`, the host's ignore
|
|
689
|
+
list — is in no tree, so no tree's absence can delete it.
|
|
641
690
|
|
|
642
691
|
## What grows, and what bounds it
|
|
643
692
|
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ decision everything else follows from.
|
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
22
|
npm install @rljson/fs-agent
|
|
23
|
-
pnpm test #
|
|
23
|
+
pnpm test # 67 files, 776 scenarios, 100 % coverage, then eslint
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
## Where to start
|
|
@@ -28,7 +28,7 @@ pnpm test # 63 files, 723 scenarios, 100 % coverage, then eslint
|
|
|
28
28
|
| if you are | read |
|
|
29
29
|
| --- | --- |
|
|
30
30
|
| **using the package** | [README.public.md](README.public.md) — install, the production configuration, every option and what it costs, troubleshooting |
|
|
31
|
-
| **deciding whether to trust it** | [README.tests.md](README.tests.md) — what the
|
|
31
|
+
| **deciding whether to trust it** | [README.tests.md](README.tests.md) — what the 776 scenarios actually prove, and what they cannot |
|
|
32
32
|
| **changing the sync** | [README.architecture.md](README.architecture.md) — the mechanism, and why each rule exists |
|
|
33
33
|
| **calling the API** | [README.api.md](README.api.md) — every export, grouped by module, with what it costs |
|
|
34
34
|
| **setting the repo up** | [README.contributors.md](README.contributors.md) — run, debug, build, publish |
|
package/README.public.md
CHANGED
|
@@ -253,13 +253,16 @@ waiting on a blob nobody serves would keep this machine from recording its own
|
|
|
253
253
|
work. A timed-out apply is tried again the next time the hub says its head. A
|
|
254
254
|
large catalogue wants a larger `extract` and `restore` than the defaults.
|
|
255
255
|
|
|
256
|
-
### `
|
|
256
|
+
### `cleanTarget` — read this before setting it
|
|
257
257
|
|
|
258
258
|
`cleanTarget: true` makes `restore()` prune anything not in the tree. **The sync
|
|
259
259
|
never uses it**: an apply deletes exactly what an edit descending from this
|
|
260
260
|
machine's state removed, and nothing else. It is honoured only by a direct
|
|
261
261
|
`restore()` or `loadFromDb()` call, where *you* are asserting the tree is the
|
|
262
|
-
whole truth.
|
|
262
|
+
whole truth — and by `restoreRevision`, which is that assertion made safely.
|
|
263
|
+
It prunes content only: what the scanner ignores is never deleted, and a prune
|
|
264
|
+
that would take a large part of the folder is refused before anything is
|
|
265
|
+
written.
|
|
263
266
|
|
|
264
267
|
---
|
|
265
268
|
|
|
@@ -353,9 +356,40 @@ once: both versions were kept, and the one that reached the fleet later keeps
|
|
|
353
356
|
the name. That is the order the hub heard them in, not who edited last — which
|
|
354
357
|
nobody can know without trusting two machines' clocks.
|
|
355
358
|
|
|
359
|
+
Every signal has an `id`, derived from what it says and the same on every
|
|
360
|
+
read, so a UI can key a row by it. A merge conflict names the merge (`head`);
|
|
361
|
+
a join names where each file it moved went (`copies`).
|
|
362
|
+
|
|
356
363
|
The full table of kinds and the field reference are in
|
|
357
364
|
[README.api.md § Signals](README.api.md#signals).
|
|
358
365
|
|
|
366
|
+
## Showing the history, and going back
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
const head = await agent.headInfo(); // where the folder stands, with its stamp
|
|
370
|
+
const page = await agent.history({ limit: 50 }); // newest first
|
|
371
|
+
const next = await agent.history({ cursor: page.cursor });
|
|
372
|
+
const relation = await agent.relationTo(hubHead); // same, behind, ahead, fork
|
|
373
|
+
|
|
374
|
+
await agent.restoreRevision(page.entries[3].head); // 'restored' | 'unknown' | 'busy'
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
**The history is the edit chain**, the same order on every node: every edit,
|
|
378
|
+
every merge with both of its parents, whichever machine made it. An entry says
|
|
379
|
+
what it changed and removed, when its author made it, and — once the hub said
|
|
380
|
+
it back — its stamp. A host whose agent runs in another process reads the same
|
|
381
|
+
pages from the store with `readFsHistory(db, treeKey, { from })`, which writes
|
|
382
|
+
nothing.
|
|
383
|
+
|
|
384
|
+
**Going back makes the folder exactly that revision**, deleting what it lacks,
|
|
385
|
+
and records the result as a new edit that every machine follows. Nothing is
|
|
386
|
+
lost: work not yet recorded is recorded first, the revision being left stays
|
|
387
|
+
in the history, and a file still being written is waited out (`busy` when it
|
|
388
|
+
does not finish). A revision that would delete a large part of the folder is
|
|
389
|
+
refused with a `MassDeleteRefusedError`, before anything is written.
|
|
390
|
+
|
|
391
|
+
Details in [README.api.md § The history](README.api.md#the-history).
|
|
392
|
+
|
|
359
393
|
## Reading what the agent is doing
|
|
360
394
|
|
|
361
395
|
| | |
|
|
@@ -388,7 +422,8 @@ const tree = await agent.extract();
|
|
|
388
422
|
// Tree -> folder, additively
|
|
389
423
|
await agent.restore(tree, './elsewhere');
|
|
390
424
|
|
|
391
|
-
// Tree -> folder, exactly: prune anything not in the tree
|
|
425
|
+
// Tree -> folder, exactly: prune anything not in the tree that the scanner
|
|
426
|
+
// would see
|
|
392
427
|
await agent.restore(tree, './elsewhere', { cleanTarget: true });
|
|
393
428
|
```
|
|
394
429
|
|
|
@@ -431,7 +466,9 @@ rewriting a whole catalogue.
|
|
|
431
466
|
files and 30 % of the folder, or all but ten) gone without the watcher seeing
|
|
432
467
|
it. That is the shape of a failed mount or a wiped drive, never of a person,
|
|
433
468
|
so nothing is recorded and a `deletion/refused` signal asks somebody to
|
|
434
|
-
decide.
|
|
469
|
+
decide. The refusal holds those files until they are back, so a backup
|
|
470
|
+
copied in file by file is never half-recorded as deleted. **Delete large
|
|
471
|
+
amounts with the client running.**
|
|
435
472
|
|
|
436
473
|
---
|
|
437
474
|
|
|
@@ -527,7 +564,7 @@ moment after every edit; `diverged` for a long time, with `lastRepair.action`
|
|
|
527
564
|
| --- | --- |
|
|
528
565
|
| [README.architecture.md](README.architecture.md) | the design: why references rather than payloads, the edit chain, the conflict table, the stamp, the guards |
|
|
529
566
|
| [README.api.md](README.api.md) | every export, grouped by module — the shape, where this document gives the advice |
|
|
530
|
-
| [README.tests.md](README.tests.md) | the
|
|
567
|
+
| [README.tests.md](README.tests.md) | the 776 scenarios this package ships, by what they prove |
|
|
531
568
|
|
|
532
569
|
Related packages: `@rljson/rljson` (trees), `@rljson/db` (database and
|
|
533
570
|
`Connector`), `@rljson/io` (sockets and storage), `@rljson/bs` (blobs),
|
package/README.tests.md
CHANGED
|
@@ -8,22 +8,22 @@ found in the LICENSE file in the root of this package.
|
|
|
8
8
|
|
|
9
9
|
# The test suite, as a document
|
|
10
10
|
|
|
11
|
-
**
|
|
12
|
-
lines.**
|
|
11
|
+
**67 files, 776 scenarios, 100 % coverage on statements, branches, functions and
|
|
12
|
+
lines.** 770 must pass; one is committed inverted, and §2.11 says which and why.
|
|
13
13
|
One command runs all of it:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
pnpm test # vitest --coverage --no-file-parallelism, then eslint
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
`--no-file-parallelism` is not a preference. **Thirty-
|
|
19
|
+
`--no-file-parallelism` is not a preference. **Thirty-four of these files**
|
|
20
20
|
drive a real `Server`, a real socket pair or the mesh harness — with real
|
|
21
21
|
watchers and real timers; run in parallel they fight over the cores and invent
|
|
22
22
|
failures. Four different tests once failed
|
|
23
23
|
across four CI runs of the same commit, each passing on re-run — not four bugs,
|
|
24
24
|
one scheduler.
|
|
25
25
|
|
|
26
|
-
This document says what the suite actually proves, because the number
|
|
26
|
+
This document says what the suite actually proves, because the number 776 does
|
|
27
27
|
not. It is organised by the question answered rather than by file; the file
|
|
28
28
|
index is at the end.
|
|
29
29
|
|
|
@@ -33,9 +33,9 @@ index is at the end.
|
|
|
33
33
|
|
|
34
34
|
| tier | what it is | files |
|
|
35
35
|
| --- | --- | --- |
|
|
36
|
-
| **mesh** | a real `Server`, real sockets (`createSocketPair`), real watchers, real files on disk, two to four nodes, with cuts, heals, mutes, deafenings and stopped processes |
|
|
36
|
+
| **mesh** | a real `Server`, real sockets (`createSocketPair`), real watchers, real files on disk, two to four nodes, with cuts, heals, mutes, deafenings and stopped processes | 12 |
|
|
37
37
|
| **client–server** | two or three clients and a real hub, each suite run **twice** — once over `SocketMock`, once over a real socket.io server configured at production's 50 MB limit | 6 |
|
|
38
|
-
| **unit / decision** | one agent, or a pure function with no filesystem and no clock |
|
|
38
|
+
| **unit / decision** | one agent, or a pure function with no filesystem and no clock | 55 |
|
|
39
39
|
|
|
40
40
|
A decision-tier test proves a RULE. It does not prove the rule is ever
|
|
41
41
|
reached, and the difference has cost this package real defects: every decision
|
|
@@ -190,7 +190,7 @@ receive side stops reporting.
|
|
|
190
190
|
|
|
191
191
|
### 2.6b That a host application is told what happened
|
|
192
192
|
|
|
193
|
-
`fs-signals.spec.ts` (
|
|
193
|
+
`fs-signals.spec.ts` (41) tests the sink with no filesystem at all, which is
|
|
194
194
|
what lets it assert the awkward parts directly: the cap dropping the oldest, the
|
|
195
195
|
per-kind counters surviving that drop, a listener that throws not costing the
|
|
196
196
|
next one its notification, and a persisted log coming back from a shape nobody
|
|
@@ -212,9 +212,36 @@ agent that does something to a user's folder, asserting the **fields** rather
|
|
|
212
212
|
than that something was emitted. A signal with the right kind and the wrong
|
|
213
213
|
`action` is worse than no signal, because it gets filtered into silence.
|
|
214
214
|
|
|
215
|
+
The sink also derives each signal's `id`, and the same ids again from a log
|
|
216
|
+
written before ids existed; two signals saying the same thing in one
|
|
217
|
+
millisecond stay two. A join's `copies` keep only the paths the signal names.
|
|
218
|
+
|
|
215
219
|
The mass-delete guard tests and the mesh harness's `mesh.conflicts` collector
|
|
216
220
|
read the signal channel too: there is no other surface left to assert.
|
|
217
221
|
|
|
222
|
+
### 2.6c That a host can show the history, and go back
|
|
223
|
+
|
|
224
|
+
`fs-history.spec.ts` (22) walks chains written by hand, because the orders that
|
|
225
|
+
matter are the ones a running fleet produces rarely: both sides of a fork that
|
|
226
|
+
reached the fleet in one announcement, a stamp that disagrees with the graph, a
|
|
227
|
+
merge below a merge. Each states the whole order it expects, and one rule
|
|
228
|
+
outranks every key: an entry is never listed above one made on top of it.
|
|
229
|
+
Pages are asserted to continue exactly where the last stopped, across a fork
|
|
230
|
+
too, and the read-only reader is asserted to leave the store byte for byte as
|
|
231
|
+
it found it.
|
|
232
|
+
|
|
233
|
+
`fs-agent-history.spec.ts` (12) is the same on a running mesh. A pull and a
|
|
234
|
+
merge are in the history, in one order on both nodes. And `restoreRevision`
|
|
235
|
+
makes a folder exactly a revision, as an edit the other node follows. Its
|
|
236
|
+
guards each have a case:
|
|
237
|
+
|
|
238
|
+
- a file saved a moment before is recorded first rather than pruned. This is
|
|
239
|
+
the case that found the settle rule hiding a brand-new file from the restore;
|
|
240
|
+
- a file still being written makes the restore `busy`, not lossy;
|
|
241
|
+
- the agent's own log and the set-aside copies survive the prune;
|
|
242
|
+
- a revision that would empty the folder is refused before anything is
|
|
243
|
+
written.
|
|
244
|
+
|
|
218
245
|
### 2.7 That a node claims only what it changed
|
|
219
246
|
|
|
220
247
|
The standing design rule: one identical chain on every client, an edit exists
|
|
@@ -379,7 +406,7 @@ Open items are in
|
|
|
379
406
|
## 5. File index
|
|
380
407
|
|
|
381
408
|
Counts are what `pnpm test` reports per file, so suites that generate cases in a
|
|
382
|
-
loop are counted as they run. They sum to the
|
|
409
|
+
loop are counted as they run. They sum to the 776 above.
|
|
383
410
|
|
|
384
411
|
### Mesh tier
|
|
385
412
|
|
|
@@ -389,9 +416,10 @@ loop are counted as they run. They sum to the 723 above.
|
|
|
389
416
|
| `mesh/fs-mesh-field-defects.spec.ts` | 11 | F1–F11, field defects reduced in process |
|
|
390
417
|
| `mesh/fs-mesh-matrix.spec.ts` | 9 | the scenario matrix at mesh tier (L7, L8, I7, I7b, I10, J4+J5, J6, J9 ×2) |
|
|
391
418
|
| `mesh/fs-mesh-invariants.spec.ts` | 7 | invariants over the route, not the destination |
|
|
392
|
-
| `mesh/fs-mesh-wiped-and-reverted.spec.ts` |
|
|
419
|
+
| `mesh/fs-mesh-wiped-and-reverted.spec.ts` | 7 | a node comes back empty, or holding an older copy |
|
|
393
420
|
| `mesh/fs-mesh-catchup-cost.spec.ts` | 2 | coming back does not cost what you missed |
|
|
394
421
|
| `fs-conflict-rules.spec.ts` | 8 | the conflict table C1–C6 on disks, and C3 before a stamp is known |
|
|
422
|
+
| `fs-agent-history.spec.ts` | 12 | the history a host shows — a pull, a merge, one order — and going back to a revision exactly |
|
|
395
423
|
| `fs-editor-patterns.spec.ts` | 6 | how real programs save |
|
|
396
424
|
| `fs-chain-crosses-the-wire.spec.ts` | 3 | the chain crosses the wire |
|
|
397
425
|
| `field-repro.spec.ts` | 3 | reported failures, reproduced verbatim |
|
|
@@ -419,23 +447,24 @@ loop are counted as they run. They sum to the 723 above.
|
|
|
419
447
|
| `fs-relate.spec.ts` | 11 | same / behind / ahead / fork / incomplete |
|
|
420
448
|
| `fs-merge.spec.ts` | 22 | `merge3` — the conflict table by example — and copy naming |
|
|
421
449
|
| `fs-stamps.spec.ts` | 11 | where each version reached the fleet, derived from payloads |
|
|
422
|
-
| `fs-send.spec.ts` |
|
|
450
|
+
| `fs-send.spec.ts` | 13 | the sender answers for its edits, and a refusal holds its files (`planAuthoring`) |
|
|
423
451
|
| `fs-collect-removals.spec.ts` | 26 | the removal walk, and `lastEditOf` |
|
|
424
452
|
| `fs-edit-chain.spec.ts` | 16 | the chain |
|
|
425
453
|
| `fs-plan-join.spec.ts` | 9 | joining, decided before anything is written |
|
|
426
|
-
| `fs-agent-mass-delete-guard.spec.ts` |
|
|
454
|
+
| `fs-agent-mass-delete-guard.spec.ts` | 14 | refusing a deletion that looks like a loss — before anything is written — and reporting it; a prune never touches what the scanner ignores |
|
|
427
455
|
| `fs-agent-anti-entropy.spec.ts` | 7 | receiving what the hub says |
|
|
428
456
|
| `fs-agent-stale-reconnect.spec.ts` | 14 | a peer reconnecting with a stale tree |
|
|
429
457
|
| `fs-agent-no-laundering.spec.ts` | 8 | a node does not re-advertise what it adopted |
|
|
430
458
|
| `fs-agent-authorship.spec.ts` | 4 | a node claims only what it changed |
|
|
431
459
|
| `fs-divergence-is-content.spec.ts` | 2 | a divergence is a difference in CONTENT |
|
|
432
460
|
| `fs-ref-vs-content.spec.ts` | 6 | ref identity vs content identity |
|
|
433
|
-
| `fs-agent-concurrent-write.spec.ts` |
|
|
461
|
+
| `fs-agent-concurrent-write.spec.ts` | 12 | two writes of one path must not blend — 200 rounds per assertion — and the synchronous writer the bookkeeping uses |
|
|
434
462
|
| `fs-agent-incremental-restore.spec.ts` | 8 | a restore writes only what changed |
|
|
435
463
|
| `fs-agent-locked-file.spec.ts` | 8 | a file held open by another process |
|
|
436
464
|
| `fs-agent-blob-stream.spec.ts` | 3 | a restore streams the blob |
|
|
437
465
|
| `fs-agent-signals.spec.ts` | 19 | one case per thing the agent signals, asserting the fields |
|
|
438
|
-
| `fs-signals.spec.ts` |
|
|
466
|
+
| `fs-signals.spec.ts` | 41 | the signal sink: the cap, the counters, ids, and a log read from a hostile folder |
|
|
467
|
+
| `fs-history.spec.ts` | 22 | the history walk: its order on hand-written chains, pages, cursors, and the read-only reader |
|
|
439
468
|
| `fs-ignore.spec.ts` | 28 | glob ignore patterns, and every legacy prefix |
|
|
440
469
|
| `fs-blob-adapter.spec.ts` | 26 | file ↔ blob |
|
|
441
470
|
| `fs-db-adapter.spec.ts` | 6 | storing a tree with its predecessors |
|
|
@@ -458,3 +487,5 @@ loop are counted as they run. They sum to the 723 above.
|
|
|
458
487
|
| `fs-agent-own-echo.spec.ts` | 1 | its own advertisement echoed back |
|
|
459
488
|
| `example.spec.ts` | 1 | the README example, against a golden |
|
|
460
489
|
| `setup/goldens.spec.ts` | 1 | the golden mechanism itself |
|
|
490
|
+
| `dna/dna.spec.ts` | 1 | the files the rljson DNA generates are as it ships them |
|
|
491
|
+
| `fs_agent_version.test.ts` | 1 | the version file gg writes agrees with `package.json` |
|