@indigoai-us/hq-cloud 6.15.101 → 6.15.102

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.
Files changed (32) hide show
  1. package/dist/bin/sync-runner-events.test.js +60 -0
  2. package/dist/bin/sync-runner-events.test.js.map +1 -1
  3. package/dist/bin/sync-runner-heap-telemetry.d.ts +344 -0
  4. package/dist/bin/sync-runner-heap-telemetry.d.ts.map +1 -0
  5. package/dist/bin/sync-runner-heap-telemetry.js +550 -0
  6. package/dist/bin/sync-runner-heap-telemetry.js.map +1 -0
  7. package/dist/bin/sync-runner-heap-telemetry.test.d.ts +2 -0
  8. package/dist/bin/sync-runner-heap-telemetry.test.d.ts.map +1 -0
  9. package/dist/bin/sync-runner-heap-telemetry.test.js +697 -0
  10. package/dist/bin/sync-runner-heap-telemetry.test.js.map +1 -0
  11. package/dist/bin/sync-runner-watch-loop.d.ts +29 -0
  12. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  13. package/dist/bin/sync-runner-watch-loop.js +160 -0
  14. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  15. package/dist/bin/sync-runner-watch-loop.test.d.ts +2 -0
  16. package/dist/bin/sync-runner-watch-loop.test.d.ts.map +1 -0
  17. package/dist/bin/sync-runner-watch-loop.test.js +62 -0
  18. package/dist/bin/sync-runner-watch-loop.test.js.map +1 -0
  19. package/dist/bin/sync-runner.d.ts +74 -0
  20. package/dist/bin/sync-runner.d.ts.map +1 -1
  21. package/dist/bin/sync-runner.js.map +1 -1
  22. package/dist/sync/event-sync.d.ts +6 -0
  23. package/dist/sync/event-sync.d.ts.map +1 -1
  24. package/dist/sync/event-sync.js +2 -0
  25. package/dist/sync/event-sync.js.map +1 -1
  26. package/dist/watcher.d.ts +28 -2
  27. package/dist/watcher.d.ts.map +1 -1
  28. package/dist/watcher.js +137 -13
  29. package/dist/watcher.js.map +1 -1
  30. package/dist/watcher.test.js +153 -0
  31. package/dist/watcher.test.js.map +1 -1
  32. package/package.json +1 -1
@@ -1689,6 +1689,159 @@ describe("PushEventEmitter — directory and delete tombstone handling", () => {
1689
1689
  contentHash: `sha256:${createHash("sha256").update(oldContent).digest("hex")}`,
1690
1690
  });
1691
1691
  });
1692
+ it("bounds publishedContentHashGenerations to the published-hash cap (was an unbounded Map)", () => {
1693
+ const maxPaths = 8;
1694
+ const K = 12;
1695
+ const emitter = makeEmitter({ lastPublishedContentHashMaxPaths: maxPaths });
1696
+ for (let i = 0; i < maxPaths + K; i++) {
1697
+ emitter.markContentPublished(`companies/indigo/gen-${i}.md`, `sha256:h${i}`);
1698
+ }
1699
+ const sizes = emitter.censusSizes();
1700
+ // The generations map used to be a plain Map with no eviction, so it grew to
1701
+ // maxPaths + K and stayed there for the whole watch session — the unbounded
1702
+ // retention this fix removes. It must now hold no more than its bounded
1703
+ // sibling's cap.
1704
+ expect(sizes.publishedContentHashGenerations).toBeLessThanOrEqual(maxPaths);
1705
+ expect(sizes.lastPublishedContentHashes).toBeLessThanOrEqual(maxPaths);
1706
+ // Sanity: we really did drive more distinct paths than the cap.
1707
+ expect(maxPaths + K).toBeGreaterThan(maxPaths);
1708
+ });
1709
+ it("bounds the generations map without breaking pull-apply echo suppression for a hot path", async () => {
1710
+ const published = [];
1711
+ const maxPaths = 4;
1712
+ const emitter = makeEmitter({ published, lastPublishedContentHashMaxPaths: maxPaths });
1713
+ // Churn several cold paths first: each takes a fresh monotonic generation and
1714
+ // evicts older ones from the now-bounded map.
1715
+ for (let i = 0; i < maxPaths * 4; i++) {
1716
+ emitter.markContentPublished(`companies/indigo/cold-${i}.md`, `sha256:c${i}`);
1717
+ }
1718
+ // The pulled path is marked LAST, so it is the hot, retained entry.
1719
+ const applied = path.join(dir, "companies", "indigo", "hot-note.md");
1720
+ const relativePath = "companies/indigo/hot-note.md";
1721
+ const remoteContent = "from remote\n";
1722
+ fs.mkdirSync(path.dirname(applied), { recursive: true });
1723
+ fs.writeFileSync(applied, remoteContent);
1724
+ emitter.markContentPublished(relativePath, `sha256:${createHash("sha256").update(remoteContent).digest("hex")}`);
1725
+ // The identical local write is still suppressed as an echo (contract #456).
1726
+ await emitter.emitForBatch({ paths: new Map([[applied, relativePath]]) });
1727
+ expect(published).toEqual([]);
1728
+ // A genuinely new local edit still publishes.
1729
+ fs.writeFileSync(applied, "local follow-up\n");
1730
+ await emitter.emitForBatch({ paths: new Map([[applied, relativePath]]) });
1731
+ expect(published).toHaveLength(1);
1732
+ });
1733
+ it("keeps generation currency fail-closed under the bounded map: a newer pull mark still wins the publish race", async () => {
1734
+ const published = [];
1735
+ const maxPaths = 4;
1736
+ const applied = path.join(dir, "companies", "indigo", "fail-closed-race.md");
1737
+ const relativePath = "companies/indigo/fail-closed-race.md";
1738
+ const oldContent = "local old bytes\n";
1739
+ const remoteContent = "remote newer bytes\n";
1740
+ fs.mkdirSync(path.dirname(applied), { recursive: true });
1741
+ fs.writeFileSync(applied, oldContent);
1742
+ let releasePublish;
1743
+ let publishStartedResolve;
1744
+ const publishStarted = new Promise((resolve) => {
1745
+ publishStartedResolve = resolve;
1746
+ });
1747
+ const publishGate = new Promise((resolve) => {
1748
+ releasePublish = resolve;
1749
+ });
1750
+ const emitter = makeEmitter({
1751
+ published,
1752
+ lastPublishedContentHashMaxPaths: maxPaths,
1753
+ transport: {
1754
+ start: async () => { },
1755
+ dispose: async () => { },
1756
+ connected: true,
1757
+ publish: async (event) => {
1758
+ published.push(event);
1759
+ publishStartedResolve?.();
1760
+ await publishGate;
1761
+ },
1762
+ },
1763
+ });
1764
+ // Mark the path with an UNRELATED hash before the publish starts, so the
1765
+ // in-flight publish captures a NON-ZERO generation yet is NOT echo-suppressed
1766
+ // (the file's bytes differ from the marked hash).
1767
+ emitter.markContentPublished(relativePath, "sha256:00decoy00");
1768
+ const oldPublish = emitter.emitForBatch({ paths: new Map([[applied, relativePath]]) });
1769
+ await publishStarted;
1770
+ // A pull applies newer bytes while the old publish is in flight, taking a
1771
+ // fresh monotonic generation the captured value can never match.
1772
+ emitter.markContentPublished(relativePath, `sha256:${createHash("sha256").update(remoteContent).digest("hex")}`);
1773
+ releasePublish?.();
1774
+ await oldPublish;
1775
+ fs.writeFileSync(applied, remoteContent);
1776
+ await emitter.emitForBatch({ paths: new Map([[applied, relativePath]]) });
1777
+ // The stale in-flight publish could not resurrect its captured generation to
1778
+ // overwrite the newer pull mark, so the remote bytes stay suppressed.
1779
+ expect(published.filter((event) => event.relativePath === relativePath)).toHaveLength(1);
1780
+ expect(published[published.length - 1]).toMatchObject({
1781
+ kind: "upsert",
1782
+ relativePath,
1783
+ contentHash: `sha256:${createHash("sha256").update(oldContent).digest("hex")}`,
1784
+ });
1785
+ });
1786
+ it("does not resurrect an evicted generation to record a stale publish (ABA at the eviction boundary)", async () => {
1787
+ const published = [];
1788
+ const maxPaths = 2;
1789
+ const applied = path.join(dir, "companies", "indigo", "aba-race.md");
1790
+ const relativePath = "companies/indigo/aba-race.md";
1791
+ const oldContent = "local old bytes\n";
1792
+ const remoteContent = "remote newer bytes\n";
1793
+ const oldHash = `sha256:${createHash("sha256").update(oldContent).digest("hex")}`;
1794
+ fs.mkdirSync(path.dirname(applied), { recursive: true });
1795
+ fs.writeFileSync(applied, oldContent);
1796
+ let releasePublish;
1797
+ let firstStartedResolve;
1798
+ const firstStarted = new Promise((resolve) => {
1799
+ firstStartedResolve = resolve;
1800
+ });
1801
+ const publishGate = new Promise((resolve) => {
1802
+ releasePublish = resolve;
1803
+ });
1804
+ let publishCount = 0;
1805
+ const emitter = makeEmitter({
1806
+ published,
1807
+ lastPublishedContentHashMaxPaths: maxPaths,
1808
+ transport: {
1809
+ start: async () => { },
1810
+ dispose: async () => { },
1811
+ connected: true,
1812
+ publish: async (event) => {
1813
+ published.push(event);
1814
+ publishCount += 1;
1815
+ // Gate only the FIRST publish so it is still in flight while the pull
1816
+ // mark and eviction happen underneath it.
1817
+ if (publishCount === 1) {
1818
+ firstStartedResolve?.();
1819
+ await publishGate;
1820
+ }
1821
+ },
1822
+ },
1823
+ });
1824
+ // The path has NEVER been marked, so the in-flight publish captures the
1825
+ // never-marked sentinel — the exact ABA precondition.
1826
+ const firstPublish = emitter.emitForBatch({ paths: new Map([[applied, relativePath]]) });
1827
+ await firstStarted;
1828
+ // A pull applies newer bytes for this path while the publish is in flight...
1829
+ emitter.markContentPublished(relativePath, `sha256:${createHash("sha256").update(remoteContent).digest("hex")}`);
1830
+ // ...then enough other paths are marked to evict this path's generation entry,
1831
+ // collapsing it back to the absent sentinel.
1832
+ for (let i = 0; i < maxPaths * 4; i += 1) {
1833
+ emitter.markContentPublished(`companies/indigo/aba-churn-${i}.md`, `sha256:z${i}`);
1834
+ }
1835
+ releasePublish?.();
1836
+ await firstPublish;
1837
+ // The stale completion must NOT have recorded oldHash for this path. If it
1838
+ // had (the ABA bug), the genuine local revert to oldContent below would be
1839
+ // wrongly suppressed as an echo and never published — silent data loss.
1840
+ await emitter.emitForBatch({ paths: new Map([[applied, relativePath]]) });
1841
+ const forPath = published.filter((event) => event.relativePath === relativePath);
1842
+ expect(forPath).toHaveLength(2);
1843
+ expect(forPath[1]).toMatchObject({ kind: "upsert", relativePath, contentHash: oldHash });
1844
+ });
1692
1845
  it("stamps an upsert with the byte length of the content it hashes", async () => {
1693
1846
  const published = [];
1694
1847
  const file = path.join(dir, "sized-content.bin");