@indigoai-us/hq-cloud 6.16.8 → 6.16.10

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.
@@ -7753,11 +7753,51 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
7753
7753
  restore: () => spy.mockRestore(),
7754
7754
  };
7755
7755
  }
7756
+ function captureWatchLoopJournal() {
7757
+ const decisions = [];
7758
+ const chunks = [];
7759
+ const spy = vi
7760
+ .spyOn(process.stderr, "write")
7761
+ .mockImplementation((chunk) => {
7762
+ if (typeof chunk === "string" && chunk.startsWith("{")) {
7763
+ const parsed = JSON.parse(String(chunk));
7764
+ if (typeof parsed === "object" &&
7765
+ parsed !== null &&
7766
+ parsed.type === "full-reconcile-decision") {
7767
+ decisions.push(parsed);
7768
+ }
7769
+ if (typeof parsed === "object" &&
7770
+ parsed !== null &&
7771
+ parsed.type === "watcher-batch-chunked") {
7772
+ chunks.push(parsed);
7773
+ }
7774
+ }
7775
+ return true;
7776
+ });
7777
+ return {
7778
+ decisions,
7779
+ chunks,
7780
+ clear: () => {
7781
+ decisions.splice(0);
7782
+ chunks.splice(0);
7783
+ },
7784
+ restore: () => spy.mockRestore(),
7785
+ };
7786
+ }
7787
+ function scopePathsFromArgv(argv) {
7788
+ const paths = [];
7789
+ for (let i = 0; i < argv.length; i++) {
7790
+ if (argv[i] === "--scope-path" && argv[i + 1] !== undefined) {
7791
+ paths.push(argv[i + 1]);
7792
+ i += 1;
7793
+ }
7794
+ }
7795
+ return paths;
7796
+ }
7756
7797
  const allTriggerFlags = (matched = []) => ({
7757
7798
  "event-push-surfaces-inactive": matched.includes("event-push-surfaces-inactive"),
7758
7799
  "first-tick": matched.includes("first-tick"),
7759
7800
  "bare-wake": matched.includes("bare-wake"),
7760
- "batch-over-limit": matched.includes("batch-over-limit"),
7761
7801
  "overflow-routes-unknown": matched.includes("overflow-routes-unknown"),
7762
7802
  "watcher-warmup-catch-up": matched.includes("watcher-warmup-catch-up"),
7763
7803
  "watcher-warmup-catch-up-failed": matched.includes("watcher-warmup-catch-up-failed"),
@@ -7861,15 +7901,38 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
7861
7901
  await loop;
7862
7902
  capture.restore();
7863
7903
  });
7864
- it("logs batch-over-limit as the sole full-reconcile trigger", async () => {
7865
- const saved = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
7866
- process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
7904
+ it("logs overflow-routes-unknown as the sole full-reconcile trigger", async () => {
7867
7905
  const capture = captureFullReconcileDecisions();
7906
+ const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
7907
+ const { loop, watcher, tick, shutdown } = startBatchDrainLoop(runPass);
7908
+ await flushLoopMicrotasks();
7909
+ capture.clear();
7910
+ runPass.mockClear();
7911
+ watcher.emit("companies/indigo/a.md", {
7912
+ paths: new Map([["/tmp/hq/companies/indigo/a.md", "companies/indigo/a.md"]]),
7913
+ overflowed: true,
7914
+ });
7915
+ tick();
7916
+ await flushLoopMicrotasks();
7917
+ expectFullReconcileDecision(capture.records[0], "full", [
7918
+ "overflow-routes-unknown",
7919
+ ]);
7920
+ expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
7921
+ shutdown();
7922
+ await loop;
7923
+ capture.restore();
7924
+ });
7925
+ it("does not escalate a fully-enumerated over-limit batch to a full reconcile", async () => {
7926
+ const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
7927
+ const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
7928
+ process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
7929
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
7930
+ const journal = captureWatchLoopJournal();
7868
7931
  try {
7869
7932
  const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
7870
7933
  const { loop, watcher, tick, shutdown } = startBatchDrainLoop(runPass);
7871
7934
  await flushLoopMicrotasks();
7872
- capture.clear();
7935
+ journal.clear();
7873
7936
  runPass.mockClear();
7874
7937
  watcher.emit("companies/indigo/a.md", {
7875
7938
  paths: new Map([
@@ -7879,42 +7942,78 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
7879
7942
  ]),
7880
7943
  });
7881
7944
  tick();
7945
+ await flushLoopMicrotasks(40);
7946
+ const calls = runPass.mock.calls.map((call) => call[0]);
7947
+ expect(calls).not.toContainEqual(fullArgv);
7948
+ expect(journal.decisions.map((record) => record.mode)).not.toContain("full");
7949
+ expect(journal.chunks[0]).toMatchObject({
7950
+ type: "watcher-batch-chunked",
7951
+ batchPathCount: 3,
7952
+ chunkPathCount: 2,
7953
+ remainingPathCount: 1,
7954
+ });
7955
+ const pushScopePaths = calls
7956
+ .filter((argv) => argv.includes("--direction") && argv.includes("push"))
7957
+ .flatMap(scopePathsFromArgv);
7958
+ expect(new Set(pushScopePaths)).toEqual(new Set(["a.md", "b.md", "c.md"]));
7959
+ expect(Math.max(0, ...calls.map((argv) => scopePathsFromArgv(argv).length))).toBeLessThanOrEqual(2);
7960
+ shutdown();
7961
+ await loop;
7962
+ }
7963
+ finally {
7964
+ journal.restore();
7965
+ if (savedLimit === undefined)
7966
+ delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
7967
+ else
7968
+ process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
7969
+ if (savedInterval === undefined)
7970
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
7971
+ else
7972
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
7973
+ }
7974
+ });
7975
+ it("still escalates an overflowed batch with unknown routes to a full reconcile", async () => {
7976
+ const savedLimit = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
7977
+ const savedInterval = process.env.HQ_SYNC_FULL_RECONCILE_MS;
7978
+ process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
7979
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
7980
+ const journal = captureWatchLoopJournal();
7981
+ try {
7982
+ const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
7983
+ const { loop, watcher, tick, shutdown } = startBatchDrainLoop(runPass);
7882
7984
  await flushLoopMicrotasks();
7883
- expectFullReconcileDecision(capture.records[0], "full", ["batch-over-limit"]);
7884
- expect(capture.records[0]?.batchPathCount).toBe(3);
7985
+ journal.clear();
7986
+ runPass.mockClear();
7987
+ watcher.emit("companies/indigo/a.md", {
7988
+ paths: new Map([
7989
+ ["/tmp/hq/companies/indigo/a.md", "companies/indigo/a.md"],
7990
+ ["/tmp/hq/companies/indigo/b.md", "companies/indigo/b.md"],
7991
+ ["/tmp/hq/companies/indigo/c.md", "companies/indigo/c.md"],
7992
+ ]),
7993
+ overflowed: true,
7994
+ });
7995
+ tick();
7996
+ await flushLoopMicrotasks(40);
7997
+ expectFullReconcileDecision(journal.decisions[0], "full", [
7998
+ "overflow-routes-unknown",
7999
+ ]);
7885
8000
  expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
8001
+ expect(journal.chunks).toEqual([]);
7886
8002
  shutdown();
7887
8003
  await loop;
7888
8004
  }
7889
8005
  finally {
7890
- capture.restore();
7891
- if (saved === undefined)
8006
+ journal.restore();
8007
+ if (savedLimit === undefined)
7892
8008
  delete process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
7893
8009
  else
7894
- process.env.HQ_SYNC_EVENT_BATCH_LIMIT = saved;
8010
+ process.env.HQ_SYNC_EVENT_BATCH_LIMIT = savedLimit;
8011
+ if (savedInterval === undefined)
8012
+ delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
8013
+ else
8014
+ process.env.HQ_SYNC_FULL_RECONCILE_MS = savedInterval;
7895
8015
  }
7896
8016
  });
7897
- it("logs overflow-routes-unknown as the sole full-reconcile trigger", async () => {
7898
- const capture = captureFullReconcileDecisions();
7899
- const runPass = vi.fn().mockResolvedValue(completedPassOutcome());
7900
- const { loop, watcher, tick, shutdown } = startBatchDrainLoop(runPass);
7901
- await flushLoopMicrotasks();
7902
- capture.clear();
7903
- runPass.mockClear();
7904
- watcher.emit("companies/indigo/a.md", {
7905
- paths: new Map([["/tmp/hq/companies/indigo/a.md", "companies/indigo/a.md"]]),
7906
- overflowed: true,
7907
- });
7908
- tick();
7909
- await flushLoopMicrotasks();
7910
- expectFullReconcileDecision(capture.records[0], "full", [
7911
- "overflow-routes-unknown",
7912
- ]);
7913
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
7914
- shutdown();
7915
- await loop;
7916
- capture.restore();
7917
- });
7918
8017
  it("logs scheduled-interval as the sole full-reconcile trigger on the legacy cadence", async () => {
7919
8018
  const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
7920
8019
  delete process.env.HQ_SYNC_FULL_RECONCILE_MS;
@@ -8693,7 +8792,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8693
8792
  await loop;
8694
8793
  capture.restore();
8695
8794
  });
8696
- it("falls back to a full reconcile when an event batch exceeds HQ_SYNC_EVENT_BATCH_LIMIT", async () => {
8795
+ it("chunks an event batch that exceeds HQ_SYNC_EVENT_BATCH_LIMIT instead of a full reconcile", async () => {
8697
8796
  const saved = process.env.HQ_SYNC_EVENT_BATCH_LIMIT;
8698
8797
  process.env.HQ_SYNC_EVENT_BATCH_LIMIT = "2";
8699
8798
  try {
@@ -8721,9 +8820,13 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8721
8820
  ]),
8722
8821
  });
8723
8822
  sleep.tick();
8724
- await flushLoopMicrotasks();
8725
- // Mass change: one full reconcile, no per-path scoped passes.
8726
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
8823
+ await flushLoopMicrotasks(40);
8824
+ const calls = runPass.mock.calls.map((call) => call[0]);
8825
+ expect(calls).not.toContainEqual(fullArgv);
8826
+ const pushScopePaths = calls
8827
+ .filter((argv) => argv.includes("push"))
8828
+ .flatMap(scopePathsFromArgv);
8829
+ expect(new Set(pushScopePaths)).toEqual(new Set(["a.md", "b.md", "c.md"]));
8727
8830
  triggerShutdown();
8728
8831
  await loop;
8729
8832
  }
@@ -8773,7 +8876,7 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8773
8876
  triggerShutdown();
8774
8877
  await loop;
8775
8878
  });
8776
- it("a batch above the shipped 10,000-path default forces a full reconcile before the interval", async () => {
8879
+ it("a batch above the shipped 10,000-path default stays on chunked targeted passes before the interval", async () => {
8777
8880
  const saved = process.env.HQ_SYNC_FULL_RECONCILE_MS;
8778
8881
  process.env.HQ_SYNC_FULL_RECONCILE_MS = "10800000";
8779
8882
  try {
@@ -8801,8 +8904,14 @@ describe("runRunnerWithLoop — accumulate-and-drain scoped push", () => {
8801
8904
  ])),
8802
8905
  });
8803
8906
  sleep.tick();
8804
- await flushLoopMicrotasks();
8805
- expect(runPass.mock.calls.map((call) => call[0])).toEqual([fullArgv]);
8907
+ await flushLoopMicrotasks(40);
8908
+ const calls = runPass.mock.calls.map((call) => call[0]);
8909
+ expect(calls).not.toContainEqual(fullArgv);
8910
+ const pushScopeCounts = calls
8911
+ .filter((argv) => argv.includes("push"))
8912
+ .map((argv) => scopePathsFromArgv(argv).length);
8913
+ expect(Math.max(0, ...pushScopeCounts)).toBeLessThanOrEqual(10_000);
8914
+ expect(pushScopeCounts.reduce((sum, count) => sum + count, 0)).toBe(10_001);
8806
8915
  triggerShutdown();
8807
8916
  await loop;
8808
8917
  }