@remnic/core 10.0.54 → 10.0.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "10.0.54",
3
+ "version": "10.0.55",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3346,7 +3346,7 @@
3346
3346
  "core"
3347
3347
  ],
3348
3348
  "peerDependencies": {
3349
- "@remnic/coding-graph": "^10.0.54"
3349
+ "@remnic/coding-graph": "^10.0.55"
3350
3350
  },
3351
3351
  "peerDependenciesMeta": {
3352
3352
  "@remnic/coding-graph": {
@@ -1,4 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
+ import { setImmediate as nextTurn } from "node:timers/promises";
2
3
  import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
3
4
  import { join } from "node:path";
4
5
  import { tmpdir } from "node:os";
@@ -75,7 +76,7 @@ describe("ProfilingCollector", () => {
75
76
  }
76
77
  });
77
78
 
78
- test("records parallel groups with correct wall time and member durations", async () => {
79
+ test("records parallel groups with correct wall time and member durations", async (t) => {
79
80
  const dir = tempDir();
80
81
  try {
81
82
  const collector = new ProfilingCollector({
@@ -84,16 +85,26 @@ describe("ProfilingCollector", () => {
84
85
  maxTraces: 10,
85
86
  });
86
87
 
88
+ // A fake clock: the collector reads Date.now(), so real timers and a real wall clock would
89
+ // make the measured wall time depend on the machine (issue #3294).
90
+ t.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 1_000 });
91
+
87
92
  collector.startTrace("extraction");
88
93
 
89
94
  // Start a parallel group with a 5ms and 30ms promise.
90
95
  const handle = collector.startParallelGroup("embed+classify");
91
96
  const p1 = new Promise<void>((resolve) => setTimeout(resolve, 5));
92
97
  const p2 = new Promise<void>((resolve) => setTimeout(resolve, 30));
93
- await collector.endParallelGroup(handle, [
98
+ const ended = collector.endParallelGroup(handle, [
94
99
  { name: "embed", promise: p1 },
95
100
  { name: "classify", promise: p2 },
96
101
  ]);
102
+ // Two steps with a real event-loop turn between them, so the 5ms member's continuation
103
+ // reads the clock at 5ms instead of after the whole 30ms has been ticked.
104
+ t.mock.timers.tick(5);
105
+ await nextTurn();
106
+ t.mock.timers.tick(25);
107
+ await ended;
97
108
 
98
109
  const trace = collector.endTrace();
99
110
 
@@ -103,12 +114,16 @@ describe("ProfilingCollector", () => {
103
114
 
104
115
  const group = trace!.parallelGroups![0];
105
116
  assert.equal(group.name, "embed+classify");
106
- // Wall time should be ~30ms (the longest promise).
107
- assert.ok(group.wallMs >= 25, `wallMs=${group.wallMs} expected >= 25`);
108
- assert.ok(group.wallMs <= 200, `wallMs=${group.wallMs} expected <= 200 (tolerance)`);
117
+ // Wall time is the longest member (30ms); each member's duration is its own timer.
118
+ assert.equal(group.wallMs, 30);
119
+ assert.equal(group.members[0].durationMs, 5);
120
+ assert.equal(group.members[1].durationMs, 30);
109
121
  assert.equal(group.members.length, 2);
110
122
  assert.equal(group.members[0].name, "embed");
111
123
  assert.equal(group.members[1].name, "classify");
124
+ // The shorter member resolved first.
125
+ assert.equal(group.members[0].resolvedIndex, 0);
126
+ assert.equal(group.members[1].resolvedIndex, 1);
112
127
  } finally {
113
128
  cleanup(dir);
114
129
  }