@indigoai-us/hq-cloud 6.16.5 → 6.16.6
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/dist/sync/event-sync.js +2 -2
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/sync/state-store.d.ts +8 -0
- package/dist/sync/state-store.d.ts.map +1 -1
- package/dist/sync/state-store.js +37 -0
- package/dist/sync/state-store.js.map +1 -1
- package/dist/watcher.d.ts +49 -9
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +418 -157
- package/dist/watcher.js.map +1 -1
- package/dist/watcher.test.js +295 -23
- package/dist/watcher.test.js.map +1 -1
- package/package.json +1 -1
package/dist/watcher.test.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as os from "os";
|
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { watch } from "chokidar";
|
|
7
|
-
import { FakeClock, WatchPushDriver, TreeWatcher, ChokidarWatchBudget, createWatchPathFilter, toChokidarIgnored, PushEventEmitter, PUBLISH_OUTCOME_JOURNALD_CEILING_BYTES, PUBLISH_OUTCOME_SUCCESS_SAMPLE_CAP, resolveEventDebounceConfig, summarizePublishBatchOutcome, DEFAULT_EVENT_DEBOUNCE_MS, DEFAULT_EVENT_MAX_WAIT_MS, DEFAULT_EVENT_SMALL_BATCH_DEBOUNCE_MS, DEFAULT_EVENT_SMALL_BATCH_MAX_PATHS, DEFAULT_EVENT_SMALL_BATCH_MAX_BYTES, DEFAULT_PUBLISH_MIN_INTERVAL_MS, EVENT_DEBOUNCE_MS_ENV, EVENT_MAX_WAIT_MS_ENV, EVENT_SMALL_BATCH_DEBOUNCE_MS_ENV, EVENT_SMALL_BATCH_MAX_PATHS_ENV, EVENT_SMALL_BATCH_MAX_BYTES_ENV, DEFAULT_TREE_WATCHER_MAX_WATCHED_PATHS, MAX_TREE_WATCHER_MAX_WATCHED_PATHS, TREE_WATCHER_MAX_WATCHED_PATHS_ENV, resolveMaxWatchedPaths, PUBLISH_MIN_INTERVAL_MS_ENV, resolvePublishMinIntervalMs,
|
|
7
|
+
import { FakeClock, WatchPushDriver, TreeWatcher, ChokidarWatchBudget, createWatchPathFilter, toChokidarIgnored, PushEventEmitter, PUBLISH_OUTCOME_JOURNALD_CEILING_BYTES, PUBLISH_OUTCOME_SUCCESS_SAMPLE_CAP, resolveEventDebounceConfig, summarizePublishBatchOutcome, DEFAULT_EVENT_DEBOUNCE_MS, DEFAULT_EVENT_MAX_WAIT_MS, DEFAULT_EVENT_SMALL_BATCH_DEBOUNCE_MS, DEFAULT_EVENT_SMALL_BATCH_MAX_PATHS, DEFAULT_EVENT_SMALL_BATCH_MAX_BYTES, DEFAULT_PUBLISH_MIN_INTERVAL_MS, EVENT_DEBOUNCE_MS_ENV, EVENT_MAX_WAIT_MS_ENV, EVENT_SMALL_BATCH_DEBOUNCE_MS_ENV, EVENT_SMALL_BATCH_MAX_PATHS_ENV, EVENT_SMALL_BATCH_MAX_BYTES_ENV, DEFAULT_TREE_WATCHER_MAX_WATCHED_PATHS, MAX_TREE_WATCHER_MAX_WATCHED_PATHS, TREE_WATCHER_MAX_WATCHED_PATHS_ENV, resolveMaxWatchedPaths, PUBLISH_MIN_INTERVAL_MS_ENV, resolvePublishMinIntervalMs, DurablePublishedContentHashes, DURABLE_PUBLISHED_HASH_BATCH_FLUSH_MS, replayDurablePublishedContentHashRecordsForTest } from "./watcher.js";
|
|
8
8
|
import { StaticFlagProvider } from "./sync/feature-flags.js";
|
|
9
9
|
import { StateStore, StateStoreLockError } from "./sync/state-store.js";
|
|
10
10
|
import { RealtimeUnavailableError, } from "./sync/push-transport.js";
|
|
@@ -1445,6 +1445,275 @@ describe("PushEventEmitter — directory and delete tombstone handling", () => {
|
|
|
1445
1445
|
expect(replayDurablePublishedContentHashRecordsForTest(records, true))
|
|
1446
1446
|
.toEqual(replayDurablePublishedContentHashRecordsForTest(records, false));
|
|
1447
1447
|
});
|
|
1448
|
+
it("replays legacy records followed by a batch with the exact single-record LRU state", () => {
|
|
1449
|
+
const batchEntries = [
|
|
1450
|
+
{ kind: "delete", relativePath: "alpha" },
|
|
1451
|
+
{ kind: "set", relativePath: "gamma", contentHash: "sha256:gamma", maxPaths: 2 },
|
|
1452
|
+
{ kind: "set", relativePath: "beta", contentHash: "sha256:beta-new", maxPaths: 2 },
|
|
1453
|
+
];
|
|
1454
|
+
const legacyThenBatch = [
|
|
1455
|
+
{ sequence: 1, type: 0x5031, flags: 0, payload: { relativePath: "alpha", contentHash: "sha256:alpha", maxPaths: 2 } },
|
|
1456
|
+
{ sequence: 2, type: 0x5031, flags: 0, payload: { relativePath: "beta", contentHash: "sha256:beta", maxPaths: 2 } },
|
|
1457
|
+
{ sequence: 3, type: 0x5033, flags: 0, payload: { entries: batchEntries } },
|
|
1458
|
+
];
|
|
1459
|
+
const equivalentSingles = [
|
|
1460
|
+
...legacyThenBatch.slice(0, 2),
|
|
1461
|
+
...batchEntries.map((entry, index) => ({
|
|
1462
|
+
sequence: index + 3,
|
|
1463
|
+
type: entry.kind === "set" ? 0x5031 : 0x5032,
|
|
1464
|
+
flags: 0,
|
|
1465
|
+
payload: entry.kind === "set"
|
|
1466
|
+
? { relativePath: entry.relativePath, contentHash: entry.contentHash, maxPaths: entry.maxPaths }
|
|
1467
|
+
: { relativePath: entry.relativePath },
|
|
1468
|
+
})),
|
|
1469
|
+
];
|
|
1470
|
+
const batched = replayDurablePublishedContentHashRecordsForTest(legacyThenBatch);
|
|
1471
|
+
expect(JSON.stringify(batched)).toBe(JSON.stringify(replayDurablePublishedContentHashRecordsForTest(equivalentSingles)));
|
|
1472
|
+
expect(batched).toEqual(replayDurablePublishedContentHashRecordsForTest(legacyThenBatch, false));
|
|
1473
|
+
});
|
|
1474
|
+
it("coalesces pull marks into one append and persists only the final mutation for a path", async () => {
|
|
1475
|
+
const clock = new FakeClock();
|
|
1476
|
+
const appendGenerated = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync");
|
|
1477
|
+
const stateDir = path.join(dir, "coalesced-state");
|
|
1478
|
+
const emitter = makeEmitter({ clock, lastPublishedContentHashStateDir: stateDir });
|
|
1479
|
+
const finalContent = "final revision\n";
|
|
1480
|
+
const finalHash = `sha256:${createHash("sha256").update(finalContent).digest("hex")}`;
|
|
1481
|
+
try {
|
|
1482
|
+
for (let index = 0; index < 128; index++) {
|
|
1483
|
+
emitter.markContentPublished(`path-${index}.md`, `sha256:${index}`);
|
|
1484
|
+
}
|
|
1485
|
+
emitter.markContentPublished("same.md", "sha256:obsolete");
|
|
1486
|
+
emitter.markContentPublished("same.md", finalHash);
|
|
1487
|
+
clock.advance(DURABLE_PUBLISHED_HASH_BATCH_FLUSH_MS);
|
|
1488
|
+
await flushImmediate();
|
|
1489
|
+
expect(appendGenerated).toHaveBeenCalledTimes(1);
|
|
1490
|
+
await emitter.dispose();
|
|
1491
|
+
const samePath = path.join(dir, "same.md");
|
|
1492
|
+
fs.writeFileSync(samePath, finalContent);
|
|
1493
|
+
const published = [];
|
|
1494
|
+
await makeEmitter({ published, lastPublishedContentHashStateDir: stateDir }).emitForBatch({
|
|
1495
|
+
paths: new Map([[samePath, "same.md"]]),
|
|
1496
|
+
});
|
|
1497
|
+
expect(published).toEqual([]);
|
|
1498
|
+
}
|
|
1499
|
+
finally {
|
|
1500
|
+
appendGenerated.mockRestore();
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
it("drops a stale guarded mutation at flush time without dropping the rest of its batch", async () => {
|
|
1504
|
+
const clock = new FakeClock();
|
|
1505
|
+
const hashes = new DurablePublishedContentHashes(path.join(dir, "predicate-state"), "test", 4, {}, clock);
|
|
1506
|
+
let shouldPersist = true;
|
|
1507
|
+
const stale = hashes.setIfCurrent("stale.md", "sha256:stale", 4, () => shouldPersist);
|
|
1508
|
+
const kept = hashes.set("kept.md", "sha256:kept", 4, false);
|
|
1509
|
+
shouldPersist = false;
|
|
1510
|
+
await hashes.dispose();
|
|
1511
|
+
await expect(stale).resolves.toBe(false);
|
|
1512
|
+
await expect(kept).resolves.toBeUndefined();
|
|
1513
|
+
expect(hashes.get("stale.md")).toBeUndefined();
|
|
1514
|
+
expect(hashes.get("kept.md")).toBe("sha256:kept");
|
|
1515
|
+
});
|
|
1516
|
+
it("flushes pending durable pull marks while disposing", async () => {
|
|
1517
|
+
const appendGenerated = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync");
|
|
1518
|
+
const emitter = makeEmitter({ lastPublishedContentHashStateDir: path.join(dir, "dispose-state") });
|
|
1519
|
+
try {
|
|
1520
|
+
emitter.markContentPublished("pending.md", "sha256:pending");
|
|
1521
|
+
await emitter.dispose();
|
|
1522
|
+
expect(appendGenerated).toHaveBeenCalledTimes(1);
|
|
1523
|
+
}
|
|
1524
|
+
finally {
|
|
1525
|
+
appendGenerated.mockRestore();
|
|
1526
|
+
}
|
|
1527
|
+
});
|
|
1528
|
+
it("reports and retries a failed durable hash append as one physical batch", async () => {
|
|
1529
|
+
const clock = new FakeClock();
|
|
1530
|
+
const onError = vi.fn();
|
|
1531
|
+
const appendGenerated = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync")
|
|
1532
|
+
.mockRejectedValueOnce(new StateStoreLockError("timed out acquiring append.lock"));
|
|
1533
|
+
const emitter = makeEmitter({
|
|
1534
|
+
clock,
|
|
1535
|
+
onError,
|
|
1536
|
+
lastPublishedContentHashStateDir: path.join(dir, "batch-lock-timeout-state"),
|
|
1537
|
+
});
|
|
1538
|
+
try {
|
|
1539
|
+
for (let index = 0; index < 128; index += 1) {
|
|
1540
|
+
emitter.markContentPublished(`batch-${index}.md`, `sha256:${index}`);
|
|
1541
|
+
}
|
|
1542
|
+
clock.advance(DURABLE_PUBLISHED_HASH_BATCH_FLUSH_MS);
|
|
1543
|
+
await flushImmediate();
|
|
1544
|
+
expect(onError).toHaveBeenCalledTimes(1);
|
|
1545
|
+
expect(onError.mock.calls[0]?.[0]).toMatchObject({ name: "StateStoreLockError" });
|
|
1546
|
+
expect((onError.mock.calls[0]?.[0]).message).toContain("128 mutations");
|
|
1547
|
+
expect(clock.pendingTimerCount()).toBe(1);
|
|
1548
|
+
}
|
|
1549
|
+
finally {
|
|
1550
|
+
await emitter.dispose();
|
|
1551
|
+
appendGenerated.mockRestore();
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1554
|
+
it("does not revive a superseded mutation while its failed batch is retrying", async () => {
|
|
1555
|
+
const clock = new FakeClock();
|
|
1556
|
+
let releaseRetry;
|
|
1557
|
+
const retryGate = new Promise((resolve) => { releaseRetry = resolve; });
|
|
1558
|
+
let retryEntered;
|
|
1559
|
+
const retryStarted = new Promise((resolve) => { retryEntered = resolve; });
|
|
1560
|
+
const originalAppendGeneratedIfAsync = StateStore.prototype.appendGeneratedIfAsync;
|
|
1561
|
+
const appendGenerated = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync")
|
|
1562
|
+
.mockRejectedValueOnce(new StateStoreLockError("timed out acquiring append.lock"))
|
|
1563
|
+
.mockImplementationOnce(async function (type, preparePayload, flags) {
|
|
1564
|
+
retryEntered();
|
|
1565
|
+
await retryGate;
|
|
1566
|
+
return originalAppendGeneratedIfAsync.call(this, type, preparePayload, flags);
|
|
1567
|
+
});
|
|
1568
|
+
const hashes = new DurablePublishedContentHashes(path.join(dir, "superseded-batch-retry-state"), "test", 4, {}, clock);
|
|
1569
|
+
try {
|
|
1570
|
+
const stale = hashes.setIfCurrent("same.md", "sha256:stale", 4, () => true);
|
|
1571
|
+
await expect(stale).resolves.toBe(false);
|
|
1572
|
+
expect(clock.pendingTimerCount()).toBe(1);
|
|
1573
|
+
clock.advance(250);
|
|
1574
|
+
await retryStarted;
|
|
1575
|
+
const newer = hashes.set("same.md", "sha256:newer", 4, false);
|
|
1576
|
+
releaseRetry();
|
|
1577
|
+
await flushImmediate();
|
|
1578
|
+
clock.advance(DURABLE_PUBLISHED_HASH_BATCH_FLUSH_MS);
|
|
1579
|
+
await expect(newer).resolves.toBeUndefined();
|
|
1580
|
+
expect(hashes.get("same.md")).toBe("sha256:newer");
|
|
1581
|
+
}
|
|
1582
|
+
finally {
|
|
1583
|
+
await hashes.dispose();
|
|
1584
|
+
appendGenerated.mockRestore();
|
|
1585
|
+
}
|
|
1586
|
+
});
|
|
1587
|
+
it("rechecks a guarded mutation when its failed batch retries", async () => {
|
|
1588
|
+
const clock = new FakeClock();
|
|
1589
|
+
let shouldPersist = true;
|
|
1590
|
+
const appendGenerated = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync")
|
|
1591
|
+
.mockRejectedValueOnce(new StateStoreLockError("timed out acquiring append.lock"));
|
|
1592
|
+
const hashes = new DurablePublishedContentHashes(path.join(dir, "guarded-batch-retry-state"), "test", 4, {}, clock);
|
|
1593
|
+
try {
|
|
1594
|
+
const stale = hashes.setIfCurrent("stale.md", "sha256:stale", 4, () => shouldPersist);
|
|
1595
|
+
await expect(stale).resolves.toBe(false);
|
|
1596
|
+
shouldPersist = false;
|
|
1597
|
+
clock.advance(250);
|
|
1598
|
+
await flushImmediate();
|
|
1599
|
+
expect(hashes.get("stale.md")).toBeUndefined();
|
|
1600
|
+
expect(appendGenerated).toHaveBeenCalledTimes(2);
|
|
1601
|
+
}
|
|
1602
|
+
finally {
|
|
1603
|
+
await hashes.dispose();
|
|
1604
|
+
appendGenerated.mockRestore();
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
it("drains an active publish into the durable memo before disposing", async () => {
|
|
1608
|
+
let releasePublish;
|
|
1609
|
+
const publishGate = new Promise((resolve) => { releasePublish = resolve; });
|
|
1610
|
+
let publishEntered;
|
|
1611
|
+
const publishStarted = new Promise((resolve) => { publishEntered = resolve; });
|
|
1612
|
+
const published = [];
|
|
1613
|
+
const stateDir = path.join(dir, "dispose-publish-drain-state");
|
|
1614
|
+
const changed = path.join(dir, "dispose-publish-drain.md");
|
|
1615
|
+
fs.writeFileSync(changed, "drain me\n");
|
|
1616
|
+
const emitter = makeEmitter({
|
|
1617
|
+
lastPublishedContentHashStateDir: stateDir,
|
|
1618
|
+
transport: {
|
|
1619
|
+
start: async () => { },
|
|
1620
|
+
dispose: async () => { },
|
|
1621
|
+
connected: true,
|
|
1622
|
+
publish: async (event) => {
|
|
1623
|
+
publishEntered();
|
|
1624
|
+
await publishGate;
|
|
1625
|
+
published.push(event);
|
|
1626
|
+
},
|
|
1627
|
+
},
|
|
1628
|
+
});
|
|
1629
|
+
const publishing = emitter.emitForBatch({ paths: new Map([[changed, "dispose-publish-drain.md"]]) });
|
|
1630
|
+
await publishStarted;
|
|
1631
|
+
let disposed = false;
|
|
1632
|
+
const disposing = emitter.dispose().then(() => { disposed = true; });
|
|
1633
|
+
await Promise.resolve();
|
|
1634
|
+
expect(disposed).toBe(false);
|
|
1635
|
+
releasePublish();
|
|
1636
|
+
await Promise.all([publishing, disposing]);
|
|
1637
|
+
const afterRestart = [];
|
|
1638
|
+
await makeEmitter({
|
|
1639
|
+
published: afterRestart,
|
|
1640
|
+
lastPublishedContentHashStateDir: stateDir,
|
|
1641
|
+
}).emitForBatch({ paths: new Map([[changed, "dispose-publish-drain.md"]]) });
|
|
1642
|
+
expect(published).toHaveLength(1);
|
|
1643
|
+
expect(afterRestart).toEqual([]);
|
|
1644
|
+
});
|
|
1645
|
+
it("leaves the durable memo open when a publish outlives the shutdown drain", async () => {
|
|
1646
|
+
const clock = new FakeClock();
|
|
1647
|
+
const onError = vi.fn();
|
|
1648
|
+
let releasePublish;
|
|
1649
|
+
const publishGate = new Promise((resolve) => { releasePublish = resolve; });
|
|
1650
|
+
let publishEntered;
|
|
1651
|
+
const publishStarted = new Promise((resolve) => { publishEntered = resolve; });
|
|
1652
|
+
const stateDir = path.join(dir, "dispose-timeout-state");
|
|
1653
|
+
const changed = path.join(dir, "dispose-timeout.md");
|
|
1654
|
+
fs.writeFileSync(changed, "late publish\n");
|
|
1655
|
+
const emitter = makeEmitter({
|
|
1656
|
+
clock,
|
|
1657
|
+
onError,
|
|
1658
|
+
lastPublishedContentHashStateDir: stateDir,
|
|
1659
|
+
transport: {
|
|
1660
|
+
start: async () => { },
|
|
1661
|
+
dispose: async () => { },
|
|
1662
|
+
connected: true,
|
|
1663
|
+
publish: async () => {
|
|
1664
|
+
publishEntered();
|
|
1665
|
+
await publishGate;
|
|
1666
|
+
},
|
|
1667
|
+
},
|
|
1668
|
+
});
|
|
1669
|
+
const publishing = emitter.emitForBatch({ paths: new Map([[changed, "dispose-timeout.md"]]) });
|
|
1670
|
+
await publishStarted;
|
|
1671
|
+
const disposing = emitter.dispose();
|
|
1672
|
+
clock.advance(60_000);
|
|
1673
|
+
await disposing;
|
|
1674
|
+
expect(onError).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining("timed out draining active publish") }), {});
|
|
1675
|
+
releasePublish();
|
|
1676
|
+
await publishing;
|
|
1677
|
+
await flushImmediate();
|
|
1678
|
+
const afterRestart = [];
|
|
1679
|
+
await makeEmitter({
|
|
1680
|
+
published: afterRestart,
|
|
1681
|
+
lastPublishedContentHashStateDir: stateDir,
|
|
1682
|
+
}).emitForBatch({ paths: new Map([[changed, "dispose-timeout.md"]]) });
|
|
1683
|
+
expect(afterRestart).toEqual([]);
|
|
1684
|
+
});
|
|
1685
|
+
it("returns one disposal barrier until the final durable batch is appended", async () => {
|
|
1686
|
+
let releaseAppend;
|
|
1687
|
+
const appendGate = new Promise((resolve) => { releaseAppend = resolve; });
|
|
1688
|
+
let appendEntered;
|
|
1689
|
+
const appendStarted = new Promise((resolve) => { appendEntered = resolve; });
|
|
1690
|
+
const originalAppendGeneratedIfAsync = StateStore.prototype.appendGeneratedIfAsync;
|
|
1691
|
+
const appendGenerated = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync")
|
|
1692
|
+
.mockImplementationOnce(async function (type, preparePayload, flags) {
|
|
1693
|
+
appendEntered();
|
|
1694
|
+
await appendGate;
|
|
1695
|
+
return originalAppendGeneratedIfAsync.call(this, type, preparePayload, flags);
|
|
1696
|
+
});
|
|
1697
|
+
const emitter = makeEmitter({ lastPublishedContentHashStateDir: path.join(dir, "concurrent-dispose-state") });
|
|
1698
|
+
try {
|
|
1699
|
+
emitter.markContentPublished("pending.md", "sha256:pending");
|
|
1700
|
+
const firstDispose = emitter.dispose();
|
|
1701
|
+
await appendStarted;
|
|
1702
|
+
let secondDisposed = false;
|
|
1703
|
+
const secondDispose = emitter.dispose();
|
|
1704
|
+
expect(secondDispose).toBe(firstDispose);
|
|
1705
|
+
void secondDispose.then(() => { secondDisposed = true; });
|
|
1706
|
+
await Promise.resolve();
|
|
1707
|
+
expect(secondDisposed).toBe(false);
|
|
1708
|
+
releaseAppend();
|
|
1709
|
+
await Promise.all([firstDispose, secondDispose]);
|
|
1710
|
+
expect(secondDisposed).toBe(true);
|
|
1711
|
+
expect(appendGenerated).toHaveBeenCalledTimes(1);
|
|
1712
|
+
}
|
|
1713
|
+
finally {
|
|
1714
|
+
appendGenerated.mockRestore();
|
|
1715
|
+
}
|
|
1716
|
+
});
|
|
1448
1717
|
it("replays __proto__ hash records with the same state as the legacy reducer", async () => {
|
|
1449
1718
|
const records = [
|
|
1450
1719
|
{ sequence: 1, type: 0x5031, flags: 0, payload: { relativePath: "__proto__", contentHash: "sha256:proto", maxPaths: 4 } },
|
|
@@ -2272,9 +2541,11 @@ describe("PushEventEmitter — directory and delete tombstone handling", () => {
|
|
|
2272
2541
|
it("retries a durable publish-state lock timeout without rejecting the watcher announce", async () => {
|
|
2273
2542
|
const clock = new FakeClock();
|
|
2274
2543
|
const onError = vi.fn();
|
|
2275
|
-
const
|
|
2276
|
-
|
|
2277
|
-
|
|
2544
|
+
const originalAppendGeneratedIfAsync = StateStore.prototype.appendGeneratedIfAsync;
|
|
2545
|
+
const appendGeneratedIfAsync = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync")
|
|
2546
|
+
.mockImplementationOnce(function (type, preparePayload, flags) {
|
|
2547
|
+
return originalAppendGeneratedIfAsync.call(this, type, preparePayload, flags);
|
|
2548
|
+
})
|
|
2278
2549
|
.mockRejectedValueOnce(new StateStoreLockError("timed out acquiring append.lock"));
|
|
2279
2550
|
const published = [];
|
|
2280
2551
|
const changed = path.join(dir, "lock-timeout.md");
|
|
@@ -2288,23 +2559,24 @@ describe("PushEventEmitter — directory and delete tombstone handling", () => {
|
|
|
2288
2559
|
}).emitForBatch({ paths: new Map([[changed, "lock-timeout.md"]]) })).resolves.toBeUndefined();
|
|
2289
2560
|
expect(published).toHaveLength(1);
|
|
2290
2561
|
expect(onError).toHaveBeenCalledWith(expect.objectContaining({ name: "StateStoreLockError" }), { relativePath: "lock-timeout.md" });
|
|
2291
|
-
expect(
|
|
2292
|
-
const
|
|
2562
|
+
expect(appendGeneratedIfAsync).toHaveBeenCalledTimes(2); // invalidate before the guarded durable set
|
|
2563
|
+
const appendsBeforeRetry = appendGeneratedIfAsync.mock.calls.length;
|
|
2293
2564
|
clock.advance(250);
|
|
2294
2565
|
await Promise.resolve();
|
|
2295
2566
|
await Promise.resolve();
|
|
2296
|
-
expect(
|
|
2567
|
+
expect(appendGeneratedIfAsync).toHaveBeenCalledTimes(appendsBeforeRetry + 1);
|
|
2297
2568
|
}
|
|
2298
2569
|
finally {
|
|
2299
|
-
|
|
2300
|
-
appendAsync.mockRestore();
|
|
2570
|
+
appendGeneratedIfAsync.mockRestore();
|
|
2301
2571
|
}
|
|
2302
2572
|
});
|
|
2303
2573
|
it("cancels a stale durable-state retry after persisting a newer hash", async () => {
|
|
2304
2574
|
const clock = new FakeClock();
|
|
2305
|
-
const
|
|
2306
|
-
|
|
2307
|
-
|
|
2575
|
+
const originalAppendGeneratedIfAsync = StateStore.prototype.appendGeneratedIfAsync;
|
|
2576
|
+
const appendGeneratedIfAsync = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync")
|
|
2577
|
+
.mockImplementationOnce(function (type, preparePayload, flags) {
|
|
2578
|
+
return originalAppendGeneratedIfAsync.call(this, type, preparePayload, flags);
|
|
2579
|
+
})
|
|
2308
2580
|
.mockRejectedValueOnce(new StateStoreLockError("timed out acquiring append.lock"));
|
|
2309
2581
|
const stateDir = path.join(dir, "superseded-retry-state");
|
|
2310
2582
|
const changed = path.join(dir, "superseded-retry.md");
|
|
@@ -2317,10 +2589,10 @@ describe("PushEventEmitter — directory and delete tombstone handling", () => {
|
|
|
2317
2589
|
fs.writeFileSync(changed, "B\n");
|
|
2318
2590
|
await emitter.emitForBatch({ paths: new Map([[changed, "superseded-retry.md"]]) });
|
|
2319
2591
|
expect(clock.pendingTimerCount()).toBe(0);
|
|
2320
|
-
const
|
|
2592
|
+
const appendsAfterNewerSuccess = appendGeneratedIfAsync.mock.calls.length;
|
|
2321
2593
|
clock.advance(10_000);
|
|
2322
2594
|
await Promise.resolve();
|
|
2323
|
-
expect(
|
|
2595
|
+
expect(appendGeneratedIfAsync).toHaveBeenCalledTimes(appendsAfterNewerSuccess);
|
|
2324
2596
|
const afterRestart = [];
|
|
2325
2597
|
await makeEmitter({
|
|
2326
2598
|
published: afterRestart,
|
|
@@ -2329,16 +2601,17 @@ describe("PushEventEmitter — directory and delete tombstone handling", () => {
|
|
|
2329
2601
|
expect(afterRestart).toEqual([]);
|
|
2330
2602
|
}
|
|
2331
2603
|
finally {
|
|
2332
|
-
|
|
2333
|
-
appendAsync.mockRestore();
|
|
2604
|
+
appendGeneratedIfAsync.mockRestore();
|
|
2334
2605
|
}
|
|
2335
2606
|
});
|
|
2336
2607
|
it("drops permanent durable-state persistence errors without scheduling retries", async () => {
|
|
2337
2608
|
const clock = new FakeClock();
|
|
2338
2609
|
const onError = vi.fn();
|
|
2339
|
-
const
|
|
2340
|
-
|
|
2341
|
-
|
|
2610
|
+
const originalAppendGeneratedIfAsync = StateStore.prototype.appendGeneratedIfAsync;
|
|
2611
|
+
const appendGeneratedIfAsync = vi.spyOn(StateStore.prototype, "appendGeneratedIfAsync")
|
|
2612
|
+
.mockImplementationOnce(function (type, preparePayload, flags) {
|
|
2613
|
+
return originalAppendGeneratedIfAsync.call(this, type, preparePayload, flags);
|
|
2614
|
+
})
|
|
2342
2615
|
.mockRejectedValue(new Error("EACCES: state directory is unwritable"));
|
|
2343
2616
|
const changed = path.join(dir, "permanent-state-error.md");
|
|
2344
2617
|
fs.writeFileSync(changed, "cannot persist\n");
|
|
@@ -2351,15 +2624,14 @@ describe("PushEventEmitter — directory and delete tombstone handling", () => {
|
|
|
2351
2624
|
expect(onError).toHaveBeenCalledTimes(1);
|
|
2352
2625
|
expect(onError).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining("EACCES") }), { relativePath: "permanent-state-error.md" });
|
|
2353
2626
|
expect(clock.pendingTimerCount()).toBe(0);
|
|
2354
|
-
const
|
|
2627
|
+
const appendsAfterFailure = appendGeneratedIfAsync.mock.calls.length;
|
|
2355
2628
|
clock.advance(60_000);
|
|
2356
2629
|
await Promise.resolve();
|
|
2357
|
-
expect(
|
|
2630
|
+
expect(appendGeneratedIfAsync).toHaveBeenCalledTimes(appendsAfterFailure);
|
|
2358
2631
|
expect(onError).toHaveBeenCalledTimes(1);
|
|
2359
2632
|
}
|
|
2360
2633
|
finally {
|
|
2361
|
-
|
|
2362
|
-
appendAsync.mockRestore();
|
|
2634
|
+
appendGeneratedIfAsync.mockRestore();
|
|
2363
2635
|
}
|
|
2364
2636
|
});
|
|
2365
2637
|
it("emits push telemetry only when publication fails", async () => {
|