@rljson/fs-agent 0.2.1 → 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.
@@ -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
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 # 67 files, 771 scenarios, 100 % coverage, then eslint
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 # 67 files, 771 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 771 scenarios actually prove, and what they cannot |
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
@@ -466,7 +466,9 @@ rewriting a whole catalogue.
466
466
  files and 30 % of the folder, or all but ten) gone without the watcher seeing
467
467
  it. That is the shape of a failed mount or a wiped drive, never of a person,
468
468
  so nothing is recorded and a `deletion/refused` signal asks somebody to
469
- decide. **Delete large amounts with the client running.**
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.**
470
472
 
471
473
  ---
472
474
 
@@ -562,7 +564,7 @@ moment after every edit; `diverged` for a long time, with `lastRepair.action`
562
564
  | --- | --- |
563
565
  | [README.architecture.md](README.architecture.md) | the design: why references rather than payloads, the edit chain, the conflict table, the stamp, the guards |
564
566
  | [README.api.md](README.api.md) | every export, grouped by module — the shape, where this document gives the advice |
565
- | [README.tests.md](README.tests.md) | the 771 scenarios this package ships, by what they prove |
567
+ | [README.tests.md](README.tests.md) | the 776 scenarios this package ships, by what they prove |
566
568
 
567
569
  Related packages: `@rljson/rljson` (trees), `@rljson/db` (database and
568
570
  `Connector`), `@rljson/io` (sockets and storage), `@rljson/bs` (blobs),
package/README.tests.md CHANGED
@@ -8,7 +8,7 @@ found in the LICENSE file in the root of this package.
8
8
 
9
9
  # The test suite, as a document
10
10
 
11
- **67 files, 771 scenarios, 100 % coverage on statements, branches, functions and
11
+ **67 files, 776 scenarios, 100 % coverage on statements, branches, functions and
12
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
 
@@ -23,7 +23,7 @@ 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 771 does
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
 
@@ -406,7 +406,7 @@ Open items are in
406
406
  ## 5. File index
407
407
 
408
408
  Counts are what `pnpm test` reports per file, so suites that generate cases in a
409
- loop are counted as they run. They sum to the 771 above.
409
+ loop are counted as they run. They sum to the 776 above.
410
410
 
411
411
  ### Mesh tier
412
412
 
@@ -416,7 +416,7 @@ loop are counted as they run. They sum to the 771 above.
416
416
  | `mesh/fs-mesh-field-defects.spec.ts` | 11 | F1–F11, field defects reduced in process |
417
417
  | `mesh/fs-mesh-matrix.spec.ts` | 9 | the scenario matrix at mesh tier (L7, L8, I7, I7b, I10, J4+J5, J6, J9 ×2) |
418
418
  | `mesh/fs-mesh-invariants.spec.ts` | 7 | invariants over the route, not the destination |
419
- | `mesh/fs-mesh-wiped-and-reverted.spec.ts` | 6 | a node comes back empty, or holding an older copy |
419
+ | `mesh/fs-mesh-wiped-and-reverted.spec.ts` | 7 | a node comes back empty, or holding an older copy |
420
420
  | `mesh/fs-mesh-catchup-cost.spec.ts` | 2 | coming back does not cost what you missed |
421
421
  | `fs-conflict-rules.spec.ts` | 8 | the conflict table C1–C6 on disks, and C3 before a stamp is known |
422
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 |
@@ -447,7 +447,7 @@ loop are counted as they run. They sum to the 771 above.
447
447
  | `fs-relate.spec.ts` | 11 | same / behind / ahead / fork / incomplete |
448
448
  | `fs-merge.spec.ts` | 22 | `merge3` — the conflict table by example — and copy naming |
449
449
  | `fs-stamps.spec.ts` | 11 | where each version reached the fleet, derived from payloads |
450
- | `fs-send.spec.ts` | 9 | the sender answers for its edits (`planAuthoring`) |
450
+ | `fs-send.spec.ts` | 13 | the sender answers for its edits, and a refusal holds its files (`planAuthoring`) |
451
451
  | `fs-collect-removals.spec.ts` | 26 | the removal walk, and `lastEditOf` |
452
452
  | `fs-edit-chain.spec.ts` | 16 | the chain |
453
453
  | `fs-plan-join.spec.ts` | 9 | joining, decided before anything is written |
@@ -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
package/dist/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 # 67 files, 771 scenarios, 100 % coverage, then eslint
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 # 67 files, 771 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 771 scenarios actually prove, and what they cannot |
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 |
@@ -466,7 +466,9 @@ rewriting a whole catalogue.
466
466
  files and 30 % of the folder, or all but ten) gone without the watcher seeing
467
467
  it. That is the shape of a failed mount or a wiped drive, never of a person,
468
468
  so nothing is recorded and a `deletion/refused` signal asks somebody to
469
- decide. **Delete large amounts with the client running.**
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.**
470
472
 
471
473
  ---
472
474
 
@@ -562,7 +564,7 @@ moment after every edit; `diverged` for a long time, with `lastRepair.action`
562
564
  | --- | --- |
563
565
  | [README.architecture.md](README.architecture.md) | the design: why references rather than payloads, the edit chain, the conflict table, the stamp, the guards |
564
566
  | [README.api.md](README.api.md) | every export, grouped by module — the shape, where this document gives the advice |
565
- | [README.tests.md](README.tests.md) | the 771 scenarios this package ships, by what they prove |
567
+ | [README.tests.md](README.tests.md) | the 776 scenarios this package ships, by what they prove |
566
568
 
567
569
  Related packages: `@rljson/rljson` (trees), `@rljson/db` (database and
568
570
  `Connector`), `@rljson/io` (sockets and storage), `@rljson/bs` (blobs),
@@ -8,7 +8,7 @@ found in the LICENSE file in the root of this package.
8
8
 
9
9
  # The test suite, as a document
10
10
 
11
- **67 files, 771 scenarios, 100 % coverage on statements, branches, functions and
11
+ **67 files, 776 scenarios, 100 % coverage on statements, branches, functions and
12
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
 
@@ -23,7 +23,7 @@ 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 771 does
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
 
@@ -406,7 +406,7 @@ Open items are in
406
406
  ## 5. File index
407
407
 
408
408
  Counts are what `pnpm test` reports per file, so suites that generate cases in a
409
- loop are counted as they run. They sum to the 771 above.
409
+ loop are counted as they run. They sum to the 776 above.
410
410
 
411
411
  ### Mesh tier
412
412
 
@@ -416,7 +416,7 @@ loop are counted as they run. They sum to the 771 above.
416
416
  | `mesh/fs-mesh-field-defects.spec.ts` | 11 | F1–F11, field defects reduced in process |
417
417
  | `mesh/fs-mesh-matrix.spec.ts` | 9 | the scenario matrix at mesh tier (L7, L8, I7, I7b, I10, J4+J5, J6, J9 ×2) |
418
418
  | `mesh/fs-mesh-invariants.spec.ts` | 7 | invariants over the route, not the destination |
419
- | `mesh/fs-mesh-wiped-and-reverted.spec.ts` | 6 | a node comes back empty, or holding an older copy |
419
+ | `mesh/fs-mesh-wiped-and-reverted.spec.ts` | 7 | a node comes back empty, or holding an older copy |
420
420
  | `mesh/fs-mesh-catchup-cost.spec.ts` | 2 | coming back does not cost what you missed |
421
421
  | `fs-conflict-rules.spec.ts` | 8 | the conflict table C1–C6 on disks, and C3 before a stamp is known |
422
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 |
@@ -447,7 +447,7 @@ loop are counted as they run. They sum to the 771 above.
447
447
  | `fs-relate.spec.ts` | 11 | same / behind / ahead / fork / incomplete |
448
448
  | `fs-merge.spec.ts` | 22 | `merge3` — the conflict table by example — and copy naming |
449
449
  | `fs-stamps.spec.ts` | 11 | where each version reached the fleet, derived from payloads |
450
- | `fs-send.spec.ts` | 9 | the sender answers for its edits (`planAuthoring`) |
450
+ | `fs-send.spec.ts` | 13 | the sender answers for its edits, and a refusal holds its files (`planAuthoring`) |
451
451
  | `fs-collect-removals.spec.ts` | 26 | the removal walk, and `lastEditOf` |
452
452
  | `fs-edit-chain.spec.ts` | 16 | the chain |
453
453
  | `fs-plan-join.spec.ts` | 9 | joining, decided before anything is written |
@@ -950,6 +950,12 @@ export declare class FsAgent {
950
950
  private _ownContent;
951
951
  /** Paths the watcher saw deleted since the own head was authored. */
952
952
  private readonly _watched;
953
+ /**
954
+ * What the last refusal held back and is still gone. A refusal holds its
955
+ * files until they are back — see `planAuthoring`. In memory only: after a
956
+ * restart the floors judge what is gone afresh, as before.
957
+ */
958
+ private _heldBack;
953
959
  /** Every chain entry's stamp, as this node learned it. */
954
960
  private _stamps?;
955
961
  /** The route this agent syncs, once a sync started. */
package/dist/fs-agent.js CHANGED
@@ -1601,6 +1601,8 @@ var receive = async (head, deps) => {
1601
1601
  //#endregion
1602
1602
  //#region src/fs-send.ts
1603
1603
  // @license
1604
+ /** Nothing held back. */
1605
+ var NOTHING_HELD = /* @__PURE__ */ new Set();
1604
1606
  /**
1605
1607
  * Whether this node may author an edit for what its folder looks like now.
1606
1608
  *
@@ -1615,10 +1617,18 @@ var receive = async (head, deps) => {
1615
1617
  * - the watcher did not see them go, so a person deleting files while the
1616
1618
  * agent runs is an ordinary edit;
1617
1619
  * - it is large: more than `minFiles` and more than `maxRatio` of the folder,
1618
- * or a folder of more than `allGoneMinFiles` left with that many or fewer.
1620
+ * or a folder of more than `allGoneMinFiles` left with that many or fewer —
1621
+ * or it is still part of a disappearance an earlier refusal held back.
1619
1622
  *
1620
1623
  * A few files deleted while the agent was down stay below the floors and are
1621
1624
  * authored like any other edit.
1625
+ *
1626
+ * **A refusal holds its files until they are back.** A refused folder that
1627
+ * fills up again one file at a time — a backup copied in, a drive coming back
1628
+ * — shrinks below the floors part-way, and without the hold the files still
1629
+ * to come would be authored as deleted, on every node, while they are being
1630
+ * copied. A held file is let go when it is back, when the head no longer has
1631
+ * it, or when the watcher sees it deleted after it came back.
1622
1632
  * @param q - The folder, the head, and the floors.
1623
1633
  * @returns `unchanged`, `author` with the delta against the head, or
1624
1634
  * `refused` with the files that disappeared.
@@ -1644,7 +1654,9 @@ var planAuthoring = (q) => {
1644
1654
  const disappeared = removed.filter((path) => isFile(q.head.get(path)) && !stillHere.has(q.head.get(path)) && !watched(path));
1645
1655
  const mass = disappeared.length > q.minFiles && disappeared.length / held > q.maxRatio;
1646
1656
  const allGone = disappeared.length > 0 && held > q.allGoneMinFiles && remaining <= q.allGoneMinFiles;
1647
- if (mass || allGone) return {
1657
+ const heldBack = q.heldBack ?? NOTHING_HELD;
1658
+ const stillHeld = disappeared.some((path) => heldBack.has(path));
1659
+ if (mass || allGone || stillHeld) return {
1648
1660
  kind: "refused",
1649
1661
  disappeared,
1650
1662
  held
@@ -3951,6 +3963,12 @@ var FsAgent = class FsAgent {
3951
3963
  _ownContent = /* @__PURE__ */ new Map();
3952
3964
  /** Paths the watcher saw deleted since the own head was authored. */
3953
3965
  _watched = /* @__PURE__ */ new Set();
3966
+ /**
3967
+ * What the last refusal held back and is still gone. A refusal holds its
3968
+ * files until they are back — see `planAuthoring`. In memory only: after a
3969
+ * restart the floors judge what is gone afresh, as before.
3970
+ */
3971
+ _heldBack = /* @__PURE__ */ new Set();
3954
3972
  /** Every chain entry's stamp, as this node learned it. */
3955
3973
  _stamps;
3956
3974
  /** The route this agent syncs, once a sync started. */
@@ -4271,13 +4289,16 @@ var FsAgent = class FsAgent {
4271
4289
  watched: this._watched,
4272
4290
  minFiles: 100,
4273
4291
  maxRatio: MASS_DELETE_MAX_RATIO,
4274
- allGoneMinFiles: 10
4292
+ allGoneMinFiles: 10,
4293
+ heldBack: this._heldBack
4275
4294
  });
4276
- if (plan.kind === "unchanged") return;
4277
4295
  if (plan.kind === "refused") {
4296
+ this._heldBack = new Set(plan.disappeared);
4278
4297
  this._refuseDeletion("author", plan.disappeared.length, plan.held, plan.disappeared, "The watcher did not see them go, so the folder keeps its last recorded state until a person decides.");
4279
4298
  return;
4280
4299
  }
4300
+ this._heldBack = /* @__PURE__ */ new Set();
4301
+ if (plan.kind === "unchanged") return;
4281
4302
  for (const path of plan.removed) if (await lstat(join(this._rootPath, ...path.split("/"))).catch(() => void 0)) {
4282
4303
  this._authorSoon?.();
4283
4304
  return;
package/dist/fs-send.d.ts CHANGED
@@ -15,6 +15,11 @@ export interface AuthoringQuestion {
15
15
  maxRatio: number;
16
16
  /** A folder holding more than this may not end up with this many or fewer. */
17
17
  allGoneMinFiles: number;
18
+ /**
19
+ * Paths an earlier refusal held back. While any of them is still gone, the
20
+ * disappearance is still refused, however few of its files are left.
21
+ */
22
+ heldBack?: ReadonlySet<string>;
18
23
  }
19
24
  /** What {@link planAuthoring} decided. */
20
25
  export type AuthoringPlan = {
@@ -42,10 +47,18 @@ export type AuthoringPlan = {
42
47
  * - the watcher did not see them go, so a person deleting files while the
43
48
  * agent runs is an ordinary edit;
44
49
  * - it is large: more than `minFiles` and more than `maxRatio` of the folder,
45
- * or a folder of more than `allGoneMinFiles` left with that many or fewer.
50
+ * or a folder of more than `allGoneMinFiles` left with that many or fewer —
51
+ * or it is still part of a disappearance an earlier refusal held back.
46
52
  *
47
53
  * A few files deleted while the agent was down stay below the floors and are
48
54
  * authored like any other edit.
55
+ *
56
+ * **A refusal holds its files until they are back.** A refused folder that
57
+ * fills up again one file at a time — a backup copied in, a drive coming back
58
+ * — shrinks below the floors part-way, and without the hold the files still
59
+ * to come would be authored as deleted, on every node, while they are being
60
+ * copied. A held file is let go when it is back, when the head no longer has
61
+ * it, or when the watcher sees it deleted after it came back.
49
62
  * @param q - The folder, the head, and the floors.
50
63
  * @returns `unchanged`, `author` with the delta against the head, or
51
64
  * `refused` with the files that disappeared.
@@ -1,2 +1,2 @@
1
1
  /** The version of the `@rljson/fs-agent` package. */
2
- export declare const fsAgentVersion = "0.2.1";
2
+ export declare const fsAgentVersion = "0.2.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rljson/fs-agent",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Rljson fs-agent description",
5
5
  "homepage": "https://github.com/rljson/fs-agent",
6
6
  "bugs": "https://github.com/rljson/fs-agent/issues",