@rljson/fs-agent 0.0.85 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.api.md +383 -0
- package/README.architecture.md +483 -288
- package/README.contributors.md +101 -15
- package/README.md +41 -11
- package/README.public.md +409 -796
- package/README.tests.md +460 -0
- package/README.trouble.md +70 -8
- package/dist/README.api.md +383 -0
- package/dist/README.architecture.md +483 -288
- package/dist/README.contributors.md +101 -15
- package/dist/README.md +41 -11
- package/dist/README.public.md +409 -796
- package/dist/README.tests.md +460 -0
- package/dist/README.trouble.md +70 -8
- package/dist/fs-agent.d.ts +703 -426
- package/dist/fs-agent.js +2801 -1584
- package/dist/fs-atomic-write.d.ts +46 -0
- package/dist/fs-edit-chain.d.ts +368 -0
- package/dist/fs-ignore.d.ts +32 -0
- package/dist/fs-merge.d.ts +109 -0
- package/dist/fs-receive.d.ts +83 -0
- package/dist/fs-scanner.d.ts +169 -6
- package/dist/fs-send.d.ts +53 -0
- package/dist/fs-signals.d.ts +169 -0
- package/dist/fs-stamps.d.ts +94 -0
- package/dist/index.d.ts +5 -2
- package/package.json +11 -11
- package/dist/fs-anti-entropy.d.ts +0 -146
- package/dist/fs-conflict-resolver.d.ts +0 -181
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@license
|
|
3
|
+
Copyright (c) 2025 Rljson
|
|
4
|
+
|
|
5
|
+
Use of this source code is governed by terms that can be
|
|
6
|
+
found in the LICENSE file in the root of this package.
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# The test suite, as a document
|
|
10
|
+
|
|
11
|
+
**63 files, 723 scenarios, 100 % coverage on statements, branches, functions and
|
|
12
|
+
lines.** 722 must pass; one is committed inverted, and §2.11 says which and why.
|
|
13
|
+
One command runs all of it:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm test # vitest --coverage --no-file-parallelism, then eslint
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`--no-file-parallelism` is not a preference. **Thirty-three of these files**
|
|
20
|
+
drive a real `Server`, a real socket pair or the mesh harness — with real
|
|
21
|
+
watchers and real timers; run in parallel they fight over the cores and invent
|
|
22
|
+
failures. Four different tests once failed
|
|
23
|
+
across four CI runs of the same commit, each passing on re-run — not four bugs,
|
|
24
|
+
one scheduler.
|
|
25
|
+
|
|
26
|
+
This document says what the suite actually proves, because the number 723 does
|
|
27
|
+
not. It is organised by the question answered rather than by file; the file
|
|
28
|
+
index is at the end.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 1. Three tiers, and why the distinction is the point
|
|
33
|
+
|
|
34
|
+
| tier | what it is | files |
|
|
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 | 11 |
|
|
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 | 52 |
|
|
39
|
+
|
|
40
|
+
A decision-tier test proves a RULE. It does not prove the rule is ever
|
|
41
|
+
reached, and the difference has cost this package real defects: every decision
|
|
42
|
+
in the join protocol was proven by a pure function while the input was never
|
|
43
|
+
assembled, and the defect was in the assembly. So a scenario answered only at
|
|
44
|
+
the unit tier is answered only **partly**, and the tiers above exist to close
|
|
45
|
+
exactly that gap.
|
|
46
|
+
|
|
47
|
+
The mesh harness (`test/mesh/fs-mesh.ts`) is the instrument most of the hard
|
|
48
|
+
results come from. It can `cut()` a node (both directions), `mute()` it (its
|
|
49
|
+
work reaches nobody while it still hears), `deafen()` it (it announces into a
|
|
50
|
+
void), `down()` and `up()` it (a stopped PROCESS, which is what a crash is,
|
|
51
|
+
rather than a broken network), and `join()` a node whose folder was written
|
|
52
|
+
*before* its agent started — which is what restoring a backup actually looks
|
|
53
|
+
like. `converged()` compares **file contents**, not refs, and names the paths
|
|
54
|
+
that differ when it fails.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 2. What the suite proves
|
|
59
|
+
|
|
60
|
+
### 2.1 That something arrives at all
|
|
61
|
+
|
|
62
|
+
The floor. `shared-sync-tests.ts` holds 35 scenarios and is run twice, once per
|
|
63
|
+
transport: a file A→B and B→A, content changes, empty files, binaries, files
|
|
64
|
+
with spaces and special characters, a file that grows and then shrinks, a
|
|
65
|
+
100 KB file, multiple files created at once, a new directory with files,
|
|
66
|
+
directory deletion, deeply nested creation, empty directories, nested empty
|
|
67
|
+
directories, a rename, convergence that then stops producing traffic, and —
|
|
68
|
+
asserted explicitly — that teardown really stops it.
|
|
69
|
+
|
|
70
|
+
At mesh tier the same floor is `fs-mesh.spec.ts` T1–T7 and
|
|
71
|
+
`fs-mesh-field-defects.spec.ts` F1–F10, each of which is a defect that was
|
|
72
|
+
measured in the field rather than an invented case.
|
|
73
|
+
|
|
74
|
+
### 2.2 That a deletion travels — the hardest thing here
|
|
75
|
+
|
|
76
|
+
Deletion is where this package has lost data, and it carries the most tests per
|
|
77
|
+
line of code anywhere in it.
|
|
78
|
+
|
|
79
|
+
The architecture is the claim: **an absence is not a deletion.** A tree lacks a
|
|
80
|
+
path because its author removed it or because its author never had it, and a
|
|
81
|
+
content hash cannot tell the two apart. Every attempt to infer it failed. So a
|
|
82
|
+
deletion is applied for one reason only — the head that lacks the file
|
|
83
|
+
**descends from this node's own** — and an absence anywhere else reaches the
|
|
84
|
+
folder only through a three-way merge against the common ancestor.
|
|
85
|
+
|
|
86
|
+
What holds it up:
|
|
87
|
+
|
|
88
|
+
- `fs-relate.spec.ts` — how two heads stand, including that a descent found is
|
|
89
|
+
proof even where another part of the history cannot be read, and that a walk
|
|
90
|
+
out of budget answers `fork`, never `behind`.
|
|
91
|
+
- `fs-send.spec.ts` and `fs-agent-mass-delete-guard.spec.ts` — the guards: a
|
|
92
|
+
sender does not author a mass disappearance its watcher did not see, and a
|
|
93
|
+
receiver keeps what an apply would lose.
|
|
94
|
+
- `fs-collect-removals.spec.ts` — the net delta a join uses to tell a stale
|
|
95
|
+
copy from new work, netting re-adds against removals in order.
|
|
96
|
+
- At mesh tier: T2 (a delete survives a merge with a peer that still holds the
|
|
97
|
+
file), T4 (a delete made while cut off is not resurrected on rejoin), F1
|
|
98
|
+
(removing a **directory** propagates), F7 (100 deletions out of 400 complete
|
|
99
|
+
everywhere), **F11** (deletions from alternating nodes, one with a clock 20 s
|
|
100
|
+
fast, all arrive and none returns), I7 (a peer's deletion does not remove a
|
|
101
|
+
file re-created since), J9 (a deletion made while the agent was **down**
|
|
102
|
+
propagates), and the wiped-and-reverted file (a machine that lost its folder
|
|
103
|
+
does not empty the fleet, and is refilled).
|
|
104
|
+
|
|
105
|
+
### 2.3 That two people editing one file lose nothing
|
|
106
|
+
|
|
107
|
+
`fs-merge.spec.ts` carries the conflict table on maps; `fs-conflict-rules.spec.ts`
|
|
108
|
+
carries it on disks — one test per row, C1–C6, on two real nodes and a stamping
|
|
109
|
+
hub, each forcing its order instead of racing for it, plus *C3 with no stamp*:
|
|
110
|
+
nothing is decided, nothing is lost, the wait is told, and two nodes do not
|
|
111
|
+
answer each other's announcements in a loop.
|
|
112
|
+
|
|
113
|
+
The guarantee: both versions survive, the one that reached the fleet later keeps
|
|
114
|
+
the name — by the hub's stamp, never a clock — every node reaches the same
|
|
115
|
+
verdict, and the conflict is reported. `fs-stamps.spec.ts` holds how a version's
|
|
116
|
+
stamp is derived, including a walk that stops at a row it cannot read yet.
|
|
117
|
+
|
|
118
|
+
At mesh tier: F5 (four nodes editing one file end on one version), F10 (two
|
|
119
|
+
nodes keep both versions **and say so**), T3 (both changes kept from a shared
|
|
120
|
+
ancestor), and `simultaneous-edit.spec.ts` (three nodes contesting one file).
|
|
121
|
+
|
|
122
|
+
### 2.4 That a document never goes backwards
|
|
123
|
+
|
|
124
|
+
`fs-mesh-invariants.spec.ts` asserts properties over the ROUTE rather than the
|
|
125
|
+
destination: *a document never goes backwards while one person edits it*, *a
|
|
126
|
+
converged deletion does not come back*, *every node ends on the last save*,
|
|
127
|
+
*every announcement carries a chain head*, and — under random churn and
|
|
128
|
+
partitions across three seeds — *a disagreement is never silent*.
|
|
129
|
+
|
|
130
|
+
These are the expensive ones, and they are the tests that caught defects no
|
|
131
|
+
example-based test could. One was the scanner's: Node rounds an mtime to the
|
|
132
|
+
nearest millisecond, so a file the agent applied in the second half of the
|
|
133
|
+
millisecond the next scan started in read as one still being written, and the
|
|
134
|
+
receiver announced the version before it. `fs-scanner.spec.ts` now pins it — a
|
|
135
|
+
rewrite the agent noted reads as written, an un-noted one as the version before.
|
|
136
|
+
Another: a receiver catching up recorded itself as the author of
|
|
137
|
+
a file it had never edited, 28 seconds after the real edit, and the whole fleet
|
|
138
|
+
settled one version behind the last save about one run in three.
|
|
139
|
+
|
|
140
|
+
**The churn scenarios found three things, and only one of them was what it
|
|
141
|
+
looked like.** One was a real defect and is fixed — a same-path conflict settled
|
|
142
|
+
by content hash rather than by when the edit happened, which made the fleet
|
|
143
|
+
converge on a superseded write. One did not exist: the test's own count of a
|
|
144
|
+
node's tree entries used a field those nodes do not have, so it counted
|
|
145
|
+
directories and the folder root as files and reported a consistent fleet as a
|
|
146
|
+
loss. The third had never been gated at all, because the test read the fleet's
|
|
147
|
+
convergence verdict and used only its snapshot.
|
|
148
|
+
|
|
149
|
+
All three are now asserted: the same files, the same bytes, and — if that ever
|
|
150
|
+
fails — that some node's `diverged` said so. The silence
|
|
151
|
+
check is kept beside the equality check rather than instead of it, because a
|
|
152
|
+
disagreement nobody noticed is a different defect from one every node is
|
|
153
|
+
announcing, and a failure should say which. The seed fixes the write sequence
|
|
154
|
+
and nothing else, so each run is a different race; that is why these are run
|
|
155
|
+
repeatedly rather than once, and why a count of passes is the only evidence
|
|
156
|
+
worth quoting.
|
|
157
|
+
|
|
158
|
+
### 2.5 That joining a network cannot destroy what is already there
|
|
159
|
+
|
|
160
|
+
A folder's contents cannot say where a joining node belongs in the history. A
|
|
161
|
+
node that authored a lineage root from whatever it happened to hold, and pushed
|
|
162
|
+
it as the network's newest claim, would carry one defect with two faces: every
|
|
163
|
+
node gets its own root, so every announcement classifies as a fork; and a
|
|
164
|
+
machine restored from a backup pushes a month of deleted files back to the
|
|
165
|
+
fleet.
|
|
166
|
+
|
|
167
|
+
`fs-plan-join.spec.ts` (9) decides it against the chain, with every path in at
|
|
168
|
+
most one of four buckets — write, announce, recover, conflict — and
|
|
169
|
+
`fs-mesh-matrix.spec.ts` proves it reached: **J4+J5** (a joiner keeps its own
|
|
170
|
+
new work and does not resurrect a deletion) and **J9** twice (work done while
|
|
171
|
+
the agent was down is not lost; a deletion made then still propagates).
|
|
172
|
+
|
|
173
|
+
A file the history deliberately deleted is neither announced nor destroyed: it
|
|
174
|
+
is renamed aside into `.fsagent-recovered/`, which the scanner ignores.
|
|
175
|
+
|
|
176
|
+
### 2.6 That a lost message heals itself
|
|
177
|
+
|
|
178
|
+
`heals-after-forced-divergence.spec.ts` (scenarios × 2 hub signals) drops
|
|
179
|
+
messages on purpose: a new file whose push the hub never received, a deletion
|
|
180
|
+
whose push it never received, a deletion a peer never received, a peer deletion
|
|
181
|
+
that must **not** be undone, every node healing when the hub received nothing
|
|
182
|
+
at all, and a node that misses every forward while another keeps writing.
|
|
183
|
+
|
|
184
|
+
There is no separate repair mechanism to test: the hub says its head again on
|
|
185
|
+
the beacon or the bootstrap, and `receive` is the repair. `fs-receive.spec.ts`
|
|
186
|
+
holds that decision — one case per relation — and
|
|
187
|
+
`fs-agent-anti-entropy.spec.ts` the wiring: what the agent hears, what it
|
|
188
|
+
reports, that a head nobody can read is said once per pair, and that a stopped
|
|
189
|
+
receive side stops reporting.
|
|
190
|
+
|
|
191
|
+
### 2.6b That a host application is told what happened
|
|
192
|
+
|
|
193
|
+
`fs-signals.spec.ts` (34) tests the sink with no filesystem at all, which is
|
|
194
|
+
what lets it assert the awkward parts directly: the cap dropping the oldest, the
|
|
195
|
+
per-kind counters surviving that drop, a listener that throws not costing the
|
|
196
|
+
next one its notification, and a persisted log coming back from a shape nobody
|
|
197
|
+
validated on the way out.
|
|
198
|
+
|
|
199
|
+
That last part is most of the file, deliberately. A signal log is read from a
|
|
200
|
+
folder that users, backup tools and other builds of this agent all write into,
|
|
201
|
+
so it will be truncated, half-written and occasionally produced by a newer
|
|
202
|
+
version. Every branch of that tolerance has a case: not an object, `null`, a
|
|
203
|
+
`signals` that is not an array, an entry missing each required field in turn, a
|
|
204
|
+
total that is not a finite number, and a good entry either side of a bad one.
|
|
205
|
+
Two of those encode decisions rather than defences — an unknown `kind` is
|
|
206
|
+
**kept**, because it is still a true record of something that happened, and
|
|
207
|
+
restoring does **not** fire subscribers, because replaying history through the
|
|
208
|
+
callback would make every restart look like a fresh folder-wide conflict.
|
|
209
|
+
|
|
210
|
+
`fs-agent-signals.spec.ts` (19) is the other half: one case per place in the
|
|
211
|
+
agent that does something to a user's folder, asserting the **fields** rather
|
|
212
|
+
than that something was emitted. A signal with the right kind and the wrong
|
|
213
|
+
`action` is worse than no signal, because it gets filtered into silence.
|
|
214
|
+
|
|
215
|
+
The mass-delete guard tests and the mesh harness's `mesh.conflicts` collector
|
|
216
|
+
read the signal channel too: there is no other surface left to assert.
|
|
217
|
+
|
|
218
|
+
### 2.7 That a node claims only what it changed
|
|
219
|
+
|
|
220
|
+
The standing design rule: one identical chain on every client, an edit exists
|
|
221
|
+
only where the change was made, a receiver adopts and never authors.
|
|
222
|
+
|
|
223
|
+
`fs-agent-authorship.spec.ts` (a received file, a stated deletion, a real edit
|
|
224
|
+
after both, and an absence only a lagging scan reports), `fs-agent-no-laundering.spec.ts` (a node does not re-advertise
|
|
225
|
+
what it adopted; a partial apply stays quiet; authoring never reads a pass that
|
|
226
|
+
began before its own write — the F9 revert, pinned deterministically — and
|
|
227
|
+
reads the watcher's last pass otherwise, so a stalled copy is not looked at
|
|
228
|
+
again), `fs-agent-own-echo.spec.ts`,
|
|
229
|
+
`fs-agent-self-parent.spec.ts` and `fs-agent-stale-reconnect.spec.ts` hold the
|
|
230
|
+
edges, with `fs-edit-chain.spec.ts` and `fs-chain-crosses-the-wire.spec.ts`
|
|
231
|
+
under them.
|
|
232
|
+
|
|
233
|
+
The receiving half: an apply writes over nothing it has not read.
|
|
234
|
+
`fs-agent-receive-degradation.spec.ts` lands a save between a receive's scan and
|
|
235
|
+
its apply — once under an apply, once under a merge. The apply stops, the save
|
|
236
|
+
becomes this node's work, and the head is merged; a scan that cannot catch up
|
|
237
|
+
stops receiving again after `RECEIVE_AGAIN_MAX` tries, and the next time the
|
|
238
|
+
head is said tries again.
|
|
239
|
+
|
|
240
|
+
Also here: `fs-ref-vs-content.spec.ts` — identical content written at different
|
|
241
|
+
times gives **one** ref and one content map. mtime is deliberately not part of
|
|
242
|
+
content identity: while it was, the same bytes gave a different ref per machine.
|
|
243
|
+
|
|
244
|
+
### 2.8 That a hostile or broken filesystem breaks only itself
|
|
245
|
+
|
|
246
|
+
| suite | what it survives |
|
|
247
|
+
| --- | --- |
|
|
248
|
+
| `fs-agent-locked-file.spec.ts` (8) | a file another process holds open — the rest of the restore lands, every locked file is named, a non-lock write failure still aborts, and the half-applied state is **not** advertised to peers |
|
|
249
|
+
| `fs-impossible-filename.spec.ts` (4) | a path the filesystem refuses — a 300-character path, `CON.txt`. Each blocks only itself |
|
|
250
|
+
| `fs-filenames.spec.ts` (5) | a German filename round-tripping byte for byte, two Unicode spellings of one name not destroying each other, a case-only rename |
|
|
251
|
+
| `fs-hostile-tree.spec.ts` (7) | a tree from a peer is not trusted with paths — no escaping the sync root |
|
|
252
|
+
| `fs-filetype-changes.spec.ts` (6) | a path that changes what it IS: file → directory, directory → file, symlinks |
|
|
253
|
+
| `fs-scanner-vanish.spec.ts` (12) | an entry deleted between `readdir` and `stat` |
|
|
254
|
+
| `fs-disk-full.spec.ts` (3) | ENOSPC — a clean abort with a message, not a silent standstill |
|
|
255
|
+
| `fs-slow-copy.spec.ts` (3) | a file still being written: never hashed half-done, and one unsettled file does not stop the folder |
|
|
256
|
+
| `fs-clock-skew.spec.ts` (6) | a machine whose clock is wrong — a file is visible whatever its timestamp says |
|
|
257
|
+
| `fs-agent-blob-stream.spec.ts` (3) | a file larger than one socket message, and a transfer that breaks off mid-file |
|
|
258
|
+
|
|
259
|
+
### 2.9 That coming back does not cost what you missed
|
|
260
|
+
|
|
261
|
+
`fs-mesh-catchup-cost.spec.ts` measures, not asserts-and-hopes: a node away for
|
|
262
|
+
twenty saves of one document fetches **one** blob, named by content rather than
|
|
263
|
+
counted, so the measurement cannot be satisfied by a blob the node already
|
|
264
|
+
held. A number that tracked the number of missed saves would mean the cost of
|
|
265
|
+
being away is proportional to how long you were away.
|
|
266
|
+
|
|
267
|
+
`fs-agent-incremental-restore.spec.ts` (8) and `fs-scale.spec.ts` D8 are the
|
|
268
|
+
same property on disk: a new file arriving must not rewrite the folder, and a
|
|
269
|
+
second scan of 4 000 files re-reads nothing.
|
|
270
|
+
|
|
271
|
+
`fs-scale.spec.ts` T1 is endurance — memory, handles and the agent's own
|
|
272
|
+
bounded structures sampled while the folder churns. Short by default;
|
|
273
|
+
`FS_SOAK_MS=14400000` runs the four hours the register asks for and nothing
|
|
274
|
+
about the test changes.
|
|
275
|
+
|
|
276
|
+
### 2.10 That the wire format is what it claims to be
|
|
277
|
+
|
|
278
|
+
There is no mixed-version test, because there is only one format — every node
|
|
279
|
+
announces a chain head, and the fleet is upgraded together.
|
|
280
|
+
|
|
281
|
+
What holds that is a census rather than a sample: `every announcement carries a
|
|
282
|
+
chain head`, in `mesh/fs-mesh-invariants.spec.ts`, records every ref each node
|
|
283
|
+
puts on the wire across the whole mesh tier and fails if any is bare. **Zero
|
|
284
|
+
bare refs.**
|
|
285
|
+
|
|
286
|
+
### 2.11 Reproductions, kept verbatim
|
|
287
|
+
|
|
288
|
+
`field-repro.spec.ts` reproduces reported failures as written,
|
|
289
|
+
and `fs-mesh-wiped-and-reverted.spec.ts` the two shapes a machine comes back
|
|
290
|
+
in: a folder **wiped** (must not empty the fleet, must be refilled) and a
|
|
291
|
+
folder **reverted** to an older copy. Several suites carry a backlog ID in
|
|
292
|
+
their `describe` — `F1/D2`, `F1/D5`, `V2/D3`, `L2/D4`, `F5`, `F7`, `S5` — so
|
|
293
|
+
the item that paid for the test is readable from the test.
|
|
294
|
+
|
|
295
|
+
The reverted shape holds the package's **one inverted test**, *a node reverted
|
|
296
|
+
to an older copy does not drag the fleet back*. A revert performed underneath a
|
|
297
|
+
**running** agent is not decidable from the history: that node had adopted the
|
|
298
|
+
edit whose file is now missing, which is the precise condition for a legitimate
|
|
299
|
+
deletion, so its own watcher states the removal and every peer is right to obey
|
|
300
|
+
it. Three detectors were built for it and each one suppressed ordinary work — a
|
|
301
|
+
rename's target, an atomic save, a create/delete/recreate. The test carries that
|
|
302
|
+
measurement and runs on every gate, so it turns red the day a protection exists.
|
|
303
|
+
The field shape — a backup restored while the agent is **stopped** — is covered,
|
|
304
|
+
because that node joins and `planJoin` renames what the history removed into
|
|
305
|
+
`.fsagent-recovered/`.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## 3. The conventions, and why each exists
|
|
310
|
+
|
|
311
|
+
**`it.fails` for a known-red test, never `it.skip`.** An inverted test passes
|
|
312
|
+
while the body fails and turns red the day it starts working, with "this works
|
|
313
|
+
now — remove the inversion and let it gate". A skipped test is silent in both
|
|
314
|
+
directions and relies on somebody remembering to come back. Ten were committed
|
|
315
|
+
inverted during the edit-chain work; **nine are now ordinary assertions and
|
|
316
|
+
there are no skips anywhere in the package.**
|
|
317
|
+
|
|
318
|
+
**One inversion remains, and it is a proof rather than a backlog item.** *A node
|
|
319
|
+
reverted to an older copy does not drag the fleet back*
|
|
320
|
+
(`fs-mesh-wiped-and-reverted.spec.ts`) carries its own argument: the reverted
|
|
321
|
+
node had ADOPTED the edit whose file is now missing, which is the exact
|
|
322
|
+
condition for a legitimate deletion, so under a live agent the two are not
|
|
323
|
+
separable from the chain. Three detectors were built and every one of them
|
|
324
|
+
suppressed ordinary work — a rename's target, an atomic save, a
|
|
325
|
+
create/delete/recreate — because authorship claims are recorded *after* the
|
|
326
|
+
push being judged. Closing it needs the **L1 approval path**: a human deciding
|
|
327
|
+
whether a bulk disappearance is a restore or a deletion, which is a product
|
|
328
|
+
decision and not a defect in this package. The field shape that matters today
|
|
329
|
+
(a backup restored while the agent is stopped, then a join) is covered by
|
|
330
|
+
`planJoin`'s recover bucket and is green.
|
|
331
|
+
|
|
332
|
+
**A pass count is a sample, not a measurement.** These suites carry several
|
|
333
|
+
units of run-to-run variance — more than most fixes move. A change is confirmed
|
|
334
|
+
by a run that *isolates* it, repeated: three for a signal, eight before calling
|
|
335
|
+
a mesh scenario fixed. This rule exists because a "6/8 → 4/8 regression" was
|
|
336
|
+
once reported from three runs whose only difference was a guard that logged
|
|
337
|
+
zero hits.
|
|
338
|
+
|
|
339
|
+
**Assert WHAT, not HOW MANY.** The catch-up cost test asserted "at most two
|
|
340
|
+
blobs" and measured three; the third was the writer's own in-flight push and
|
|
341
|
+
the second a blob the node already held. Rewritten to name the contents
|
|
342
|
+
touched, it reports one blob on every run. A bound raised to swallow a known
|
|
343
|
+
failure stops measuring anything.
|
|
344
|
+
|
|
345
|
+
**`ORIGIN_FIXTURE` says what is true of a fixture.** A folder with files and no
|
|
346
|
+
history defers its first announcement and asks the network for its state first,
|
|
347
|
+
because announcing over an established fleet is how a restored backup drags it
|
|
348
|
+
back. Nearly every fixture here has exactly that shape and almost none has a
|
|
349
|
+
peer with a history to wait for, so `{ joinWaitMs: 0 }` states "this folder is
|
|
350
|
+
the first state of its own history". It is not a way around the behaviour — a
|
|
351
|
+
test that means to exercise joining sets a real wait.
|
|
352
|
+
|
|
353
|
+
**Goldens** are snapshots reviewed by a human: `pnpm updateGoldens`, then read
|
|
354
|
+
the diff. `test/goldens/example.log` snapshots the agent's own field layout, so
|
|
355
|
+
adding a field is expected to change it.
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## 4. What this suite cannot answer
|
|
360
|
+
|
|
361
|
+
Named rather than implied.
|
|
362
|
+
|
|
363
|
+
Of the 23 end-to-end file-sync scenarios an integration environment runs, 14 are answered here at a tier that fails
|
|
364
|
+
the build. The rest are of two honest kinds:
|
|
365
|
+
|
|
366
|
+
- **A budget or a size.** Sync latency, the cold-start budget, and the 44 MB
|
|
367
|
+
file that is a realistic production number. A budget asserted on a developer
|
|
368
|
+
laptop measures the laptop.
|
|
369
|
+
- **An environment this suite does not have.** A Windows file lock (the one
|
|
370
|
+
thing on the list a mesh on macOS cannot settle — it wants a Windows
|
|
371
|
+
runner), the OS watcher at a scale that overwhelms it, a transport limit, and
|
|
372
|
+
the real production folder across four workstations.
|
|
373
|
+
|
|
374
|
+
Open items are in
|
|
375
|
+
[README.public.md § Known constraints](README.public.md#known-constraints).
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## 5. File index
|
|
380
|
+
|
|
381
|
+
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 723 above.
|
|
383
|
+
|
|
384
|
+
### Mesh tier
|
|
385
|
+
|
|
386
|
+
| file | n | what it covers |
|
|
387
|
+
| --- | --- | --- |
|
|
388
|
+
| `mesh/fs-mesh.spec.ts` | 6 | T1–T7, the scenarios the sync has to survive |
|
|
389
|
+
| `mesh/fs-mesh-field-defects.spec.ts` | 11 | F1–F11, field defects reduced in process |
|
|
390
|
+
| `mesh/fs-mesh-matrix.spec.ts` | 9 | the scenario matrix at mesh tier (L7, L8, I7, I7b, I10, J4+J5, J6, J9 ×2) |
|
|
391
|
+
| `mesh/fs-mesh-invariants.spec.ts` | 7 | invariants over the route, not the destination |
|
|
392
|
+
| `mesh/fs-mesh-wiped-and-reverted.spec.ts` | 6 | a node comes back empty, or holding an older copy |
|
|
393
|
+
| `mesh/fs-mesh-catchup-cost.spec.ts` | 2 | coming back does not cost what you missed |
|
|
394
|
+
| `fs-conflict-rules.spec.ts` | 8 | the conflict table C1–C6 on disks, and C3 before a stamp is known |
|
|
395
|
+
| `fs-editor-patterns.spec.ts` | 6 | how real programs save |
|
|
396
|
+
| `fs-chain-crosses-the-wire.spec.ts` | 3 | the chain crosses the wire |
|
|
397
|
+
| `field-repro.spec.ts` | 3 | reported failures, reproduced verbatim |
|
|
398
|
+
|
|
399
|
+
### Client–server tier
|
|
400
|
+
|
|
401
|
+
| file | n | what it covers |
|
|
402
|
+
| --- | --- | --- |
|
|
403
|
+
| `client-server/socket-mock.spec.ts` | 35 | the shared suite (`shared-sync-tests.ts`) over `SocketMock` |
|
|
404
|
+
| `client-server/socket-io.spec.ts` | 35 | the same shared suite over a real socket.io server at production's 50 MB limit |
|
|
405
|
+
| `client-server/advanced-sync.spec.ts` | 15 | three clients, catch-up, teardown and restart, 10 MB, 100 files, rapid overwrites |
|
|
406
|
+
| `client-server/heals-after-forced-divergence.spec.ts` | 14 | deliberately dropped messages |
|
|
407
|
+
| `client-server/conflict-sync.spec.ts` | 2 | a real offline divergent edit, both versions preserved |
|
|
408
|
+
| `client-server/simultaneous-edit.spec.ts` | 4 | five rounds of three nodes contesting one file |
|
|
409
|
+
|
|
410
|
+
### Unit and decision tier
|
|
411
|
+
|
|
412
|
+
| file | n | what it covers |
|
|
413
|
+
| --- | --- | --- |
|
|
414
|
+
| `fs-agent.spec.ts` | 81 | the agent's surface |
|
|
415
|
+
| `fs-scanner.spec.ts` | 62 | scanning, watching, the scan cache, the agent's own writes |
|
|
416
|
+
| `fs-agent-degradation.spec.ts` | 15 | what the agent does when a dependency fails, and the shapes no scenario reaches |
|
|
417
|
+
| `fs-agent-receive-degradation.spec.ts` | 16 | receiving when a part of it fails — a tree it cannot read, a stamp or state it cannot file, a folder that moves under the apply, a join |
|
|
418
|
+
| `fs-receive.spec.ts` | 11 | what a node does with a head that arrived |
|
|
419
|
+
| `fs-relate.spec.ts` | 11 | same / behind / ahead / fork / incomplete |
|
|
420
|
+
| `fs-merge.spec.ts` | 22 | `merge3` — the conflict table by example — and copy naming |
|
|
421
|
+
| `fs-stamps.spec.ts` | 11 | where each version reached the fleet, derived from payloads |
|
|
422
|
+
| `fs-send.spec.ts` | 9 | the sender answers for its edits (`planAuthoring`) |
|
|
423
|
+
| `fs-collect-removals.spec.ts` | 26 | the removal walk, and `lastEditOf` |
|
|
424
|
+
| `fs-edit-chain.spec.ts` | 16 | the chain |
|
|
425
|
+
| `fs-plan-join.spec.ts` | 9 | joining, decided before anything is written |
|
|
426
|
+
| `fs-agent-mass-delete-guard.spec.ts` | 12 | refusing a deletion that looks like a loss, and reporting it |
|
|
427
|
+
| `fs-agent-anti-entropy.spec.ts` | 7 | receiving what the hub says |
|
|
428
|
+
| `fs-agent-stale-reconnect.spec.ts` | 14 | a peer reconnecting with a stale tree |
|
|
429
|
+
| `fs-agent-no-laundering.spec.ts` | 8 | a node does not re-advertise what it adopted |
|
|
430
|
+
| `fs-agent-authorship.spec.ts` | 4 | a node claims only what it changed |
|
|
431
|
+
| `fs-divergence-is-content.spec.ts` | 2 | a divergence is a difference in CONTENT |
|
|
432
|
+
| `fs-ref-vs-content.spec.ts` | 6 | ref identity vs content identity |
|
|
433
|
+
| `fs-agent-concurrent-write.spec.ts` | 9 | two writes of one path must not blend — 200 rounds per assertion |
|
|
434
|
+
| `fs-agent-incremental-restore.spec.ts` | 8 | a restore writes only what changed |
|
|
435
|
+
| `fs-agent-locked-file.spec.ts` | 8 | a file held open by another process |
|
|
436
|
+
| `fs-agent-blob-stream.spec.ts` | 3 | a restore streams the blob |
|
|
437
|
+
| `fs-agent-signals.spec.ts` | 19 | one case per thing the agent signals, asserting the fields |
|
|
438
|
+
| `fs-signals.spec.ts` | 34 | the signal sink: the cap, the counters, and a log read from a hostile folder |
|
|
439
|
+
| `fs-ignore.spec.ts` | 28 | glob ignore patterns, and every legacy prefix |
|
|
440
|
+
| `fs-blob-adapter.spec.ts` | 26 | file ↔ blob |
|
|
441
|
+
| `fs-db-adapter.spec.ts` | 6 | storing a tree with its predecessors |
|
|
442
|
+
| `blob-io.spec.ts` | 5 | storing a file as a blob |
|
|
443
|
+
| `fs-scanner-vanish.spec.ts` | 12 | an entry that vanishes mid-scan |
|
|
444
|
+
| `fs-scanner-scan-coalescing.spec.ts` | 4 | a burst collapses into at most two passes |
|
|
445
|
+
| `fs-hostile-tree.spec.ts` | 7 | a peer's tree is not trusted with paths |
|
|
446
|
+
| `fs-impossible-filename.spec.ts` | 4 | a path the filesystem refuses |
|
|
447
|
+
| `fs-filetype-changes.spec.ts` | 6 | a path changes what it is |
|
|
448
|
+
| `fs-filenames.spec.ts` | 5 | unicode and case |
|
|
449
|
+
| `fs-clock-skew.spec.ts` | 6 | a file is visible whatever its timestamp says |
|
|
450
|
+
| `fs-slow-copy.spec.ts` | 3 | a file being written is not distributed half-done |
|
|
451
|
+
| `fs-disk-full.spec.ts` | 3 | a full disk |
|
|
452
|
+
| `fs-scale.spec.ts` | 3 | scale and endurance |
|
|
453
|
+
| `fs-agent-silent-joiner.spec.ts` | 4 | an agent with nothing to say does not speak |
|
|
454
|
+
| `fs-stage-timings.spec.ts` | 4 | per-stage timings |
|
|
455
|
+
| `fs-agent-rescan-commits.spec.ts` | 1 | a change found only by the safety rescan |
|
|
456
|
+
| `fs-agent-self-parent.spec.ts` | 2 | a push that parents itself |
|
|
457
|
+
| `fs-rename-folder.spec.ts` | 2 | renaming a folder |
|
|
458
|
+
| `fs-agent-own-echo.spec.ts` | 1 | its own advertisement echoed back |
|
|
459
|
+
| `example.spec.ts` | 1 | the README example, against a golden |
|
|
460
|
+
| `setup/goldens.spec.ts` | 1 | the golden mechanism itself |
|
package/dist/README.trouble.md
CHANGED
|
@@ -8,16 +8,78 @@ found in the LICENSE file in the root of this package.
|
|
|
8
8
|
|
|
9
9
|
# Trouble shooting
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Development and test-environment problems. For problems **running** the agent,
|
|
12
|
+
see [README.public.md](README.public.md#troubleshooting).
|
|
12
13
|
|
|
13
|
-
- [
|
|
14
|
+
- [Tests fail in ways that do not reproduce](#tests-fail-in-ways-that-do-not-reproduce)
|
|
15
|
+
- [A test leaves folders behind](#a-test-leaves-folders-behind)
|
|
16
|
+
- [The coverage gate fails but every test passes](#the-coverage-gate-fails-but-every-test-passes)
|
|
17
|
+
- [A golden fails after an unrelated change](#a-golden-fails-after-an-unrelated-change)
|
|
18
|
+
- [A mesh test hangs instead of failing](#a-mesh-test-hangs-instead-of-failing)
|
|
19
|
+
- [VS Code on Windows: debugging is not working](#vs-code-on-windows-debugging-is-not-working)
|
|
14
20
|
|
|
15
|
-
##
|
|
21
|
+
## Tests fail in ways that do not reproduce
|
|
22
|
+
|
|
23
|
+
Run the suite the way `package.json` defines it. `vitest run` **without**
|
|
24
|
+
`--no-file-parallelism` puts twenty-six integration files — real servers, real
|
|
25
|
+
sockets, real watchers, real timers — in contention over the cores, and invents
|
|
26
|
+
failures that look exactly like product defects. Four different tests once
|
|
27
|
+
failed across four CI runs of the same commit, each passing on re-run.
|
|
28
|
+
|
|
29
|
+
If a single mesh scenario is flaky, that is information, not noise: run it
|
|
30
|
+
eight times before concluding anything either way.
|
|
31
|
+
|
|
32
|
+
## A test leaves folders behind
|
|
33
|
+
|
|
34
|
+
The mesh and client–server suites create `test-temp-*` directories in the
|
|
35
|
+
repository root and remove them in `afterEach`. A run killed mid-test leaves
|
|
36
|
+
them, and a stale one can make the next run read someone else's state:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
rm -rf test-temp-*
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## The coverage gate fails but every test passes
|
|
43
|
+
|
|
44
|
+
Expected: the gate is 100 % on all four metrics. The text reporter **omits
|
|
45
|
+
fully covered files**, so an empty table means everything is covered, and any
|
|
46
|
+
file that appears is the one to look at — with its uncovered line numbers in
|
|
47
|
+
the last column.
|
|
48
|
+
|
|
49
|
+
Before reaching for `/* v8 ignore */`, check whether the branch is genuinely
|
|
50
|
+
unreachable. If it is, say why after `@preserve`. If it is reachable, it wants
|
|
51
|
+
a test.
|
|
52
|
+
|
|
53
|
+
## A golden fails after an unrelated change
|
|
54
|
+
|
|
55
|
+
`test/goldens/example.log` is a snapshot of the agent's own field layout, so
|
|
56
|
+
adding or removing a private field changes it legitimately:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pnpm updateGoldens
|
|
60
|
+
git diff test/goldens/ # READ this — that is the point of the step
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Accepting a golden without reading the diff is how a real behaviour change gets
|
|
64
|
+
recorded as a formatting one.
|
|
65
|
+
|
|
66
|
+
## A mesh test hangs instead of failing
|
|
67
|
+
|
|
68
|
+
`converged()` and `settlesOn()` poll until a timeout. A hang to the end of the
|
|
69
|
+
timeout means the fleet never agreed, and `whyNot(result)` names the paths that
|
|
70
|
+
differ — assert on it rather than on `converged` alone, or the failure message
|
|
71
|
+
tells you nothing.
|
|
72
|
+
|
|
73
|
+
A node that was `cut()` and never `heal()`ed will never converge. In the
|
|
74
|
+
harness, `cut` is both directions, `mute` is outbound only, `deafen` is inbound
|
|
75
|
+
only, and `down`/`up` stop and restart the agent while leaving the folder
|
|
76
|
+
reachable.
|
|
77
|
+
|
|
78
|
+
## VS Code on Windows: debugging is not working
|
|
16
79
|
|
|
17
80
|
Date: 2025-03-08
|
|
18
81
|
|
|
19
|
-
⚠️
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
resolved.
|
|
82
|
+
⚠️ On Windows, check the repository out on drive C. There is a bug in the VS
|
|
83
|
+
Code Vitest extension (v1.14.4) that prevents test debugging from working:
|
|
84
|
+
<https://github.com/vitest-dev/vscode/issues/548>. Check from time to time
|
|
85
|
+
whether it has been fixed, and remove this note when it has.
|