@remnic/core 1.1.29 → 1.1.31

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 (100) hide show
  1. package/dist/access-cli.js +13 -13
  2. package/dist/access-http.d.ts +2 -1
  3. package/dist/access-http.js +8 -8
  4. package/dist/access-mcp.d.ts +1 -1
  5. package/dist/access-mcp.js +7 -7
  6. package/dist/access-schema.d.ts +55 -5
  7. package/dist/access-schema.js +4 -2
  8. package/dist/{access-service-CEyV8XJ5.d.ts → access-service-CkZyb35d.d.ts} +10 -2
  9. package/dist/access-service.d.ts +1 -1
  10. package/dist/access-service.js +5 -5
  11. package/dist/briefing.js +2 -2
  12. package/dist/causal-consolidation.js +3 -3
  13. package/dist/{chunk-25YQM6XW.js → chunk-2IWUMAES.js} +3 -3
  14. package/dist/{chunk-6CB4E7ZV.js → chunk-3ZLVGM76.js} +4 -4
  15. package/dist/{chunk-QYHQ2JHL.js → chunk-43PJZYGL.js} +2 -2
  16. package/dist/{chunk-YITUHONZ.js → chunk-4KGVTPGD.js} +2 -2
  17. package/dist/{chunk-TR4DK5OH.js → chunk-76FLAAUC.js} +2 -2
  18. package/dist/{chunk-6BFAEWQS.js → chunk-77H5NU3M.js} +2 -2
  19. package/dist/{chunk-IANK6Y5W.js → chunk-A6KTB5R6.js} +2 -2
  20. package/dist/{chunk-7D6O46PF.js → chunk-BVF3AGJP.js} +2 -2
  21. package/dist/{chunk-4H6DURG6.js → chunk-JA3AK3PT.js} +2 -2
  22. package/dist/{chunk-RCZRL5BE.js → chunk-MRILGULB.js} +2 -2
  23. package/dist/{chunk-CWWDIQZB.js → chunk-QLLBRHAT.js} +8 -8
  24. package/dist/{chunk-2WIPXV3Y.js → chunk-RR2PKP3I.js} +2 -2
  25. package/dist/{chunk-3F24QTRI.js → chunk-SAZS2QZB.js} +2 -2
  26. package/dist/{chunk-VYU7PXUS.js → chunk-SIC6U3GZ.js} +2 -2
  27. package/dist/{chunk-WDSIV3AK.js → chunk-TPU5L5EY.js} +12 -12
  28. package/dist/{chunk-AMVN77EU.js → chunk-U7EJOMFC.js} +371 -91
  29. package/dist/chunk-U7EJOMFC.js.map +1 -0
  30. package/dist/{chunk-F33CJ5CH.js → chunk-VBJ7V5SK.js} +40 -8
  31. package/dist/chunk-VBJ7V5SK.js.map +1 -0
  32. package/dist/{chunk-6WV2HYTZ.js → chunk-W6AQJ2PY.js} +4 -4
  33. package/dist/{chunk-PUXCIHRL.js → chunk-XSZEP4SF.js} +2 -2
  34. package/dist/{chunk-NW7JW5GA.js → chunk-YROHKYBY.js} +41 -6
  35. package/dist/chunk-YROHKYBY.js.map +1 -0
  36. package/dist/{chunk-JUYT2J3K.js → chunk-YU5KIWYQ.js} +136 -8
  37. package/dist/chunk-YU5KIWYQ.js.map +1 -0
  38. package/dist/{chunk-LCTP7YRU.js → chunk-ZAVUCJ4H.js} +38 -7
  39. package/dist/chunk-ZAVUCJ4H.js.map +1 -0
  40. package/dist/{cli-BguVmIwO.d.ts → cli-kuh9PwZ5.d.ts} +1 -1
  41. package/dist/cli.d.ts +2 -2
  42. package/dist/cli.js +17 -17
  43. package/dist/compounding/engine.js +2 -2
  44. package/dist/connectors/codex-materialize-runner.js +2 -2
  45. package/dist/connectors/index.js +2 -2
  46. package/dist/entity-retrieval.js +2 -2
  47. package/dist/index.d.ts +4 -4
  48. package/dist/index.js +34 -22
  49. package/dist/index.js.map +1 -1
  50. package/dist/maintenance/memory-governance.js +2 -2
  51. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +2 -2
  52. package/dist/maintenance/rebuild-memory-projection.js +3 -3
  53. package/dist/mcp-memory-inspector-app.d.ts +1 -1
  54. package/dist/namespaces/migrate.js +3 -3
  55. package/dist/namespaces/storage.js +2 -2
  56. package/dist/offline-sync.d.ts +56 -1
  57. package/dist/offline-sync.js +15 -1
  58. package/dist/operator-toolkit.js +5 -5
  59. package/dist/orchestrator.js +9 -9
  60. package/dist/schemas.d.ts +22 -22
  61. package/dist/semantic-consolidation.js +3 -3
  62. package/dist/semantic-rule-promotion.js +2 -2
  63. package/dist/semantic-rule-verifier.js +2 -2
  64. package/dist/storage.d.ts +5 -0
  65. package/dist/storage.js +1 -1
  66. package/dist/transfer/types.d.ts +12 -12
  67. package/dist/verified-recall.js +2 -2
  68. package/package.json +1 -1
  69. package/src/access-http.test.ts +355 -0
  70. package/src/access-http.ts +149 -1
  71. package/src/access-schema.ts +58 -3
  72. package/src/access-service-namespace.test.ts +56 -1
  73. package/src/access-service-offline-file-content.test.ts +17 -0
  74. package/src/access-service.ts +47 -1
  75. package/src/index.ts +7 -0
  76. package/src/offline-sync.test.ts +1055 -1
  77. package/src/offline-sync.ts +465 -97
  78. package/src/storage.ts +36 -2
  79. package/dist/chunk-AMVN77EU.js.map +0 -1
  80. package/dist/chunk-F33CJ5CH.js.map +0 -1
  81. package/dist/chunk-JUYT2J3K.js.map +0 -1
  82. package/dist/chunk-LCTP7YRU.js.map +0 -1
  83. package/dist/chunk-NW7JW5GA.js.map +0 -1
  84. /package/dist/{chunk-25YQM6XW.js.map → chunk-2IWUMAES.js.map} +0 -0
  85. /package/dist/{chunk-6CB4E7ZV.js.map → chunk-3ZLVGM76.js.map} +0 -0
  86. /package/dist/{chunk-QYHQ2JHL.js.map → chunk-43PJZYGL.js.map} +0 -0
  87. /package/dist/{chunk-YITUHONZ.js.map → chunk-4KGVTPGD.js.map} +0 -0
  88. /package/dist/{chunk-TR4DK5OH.js.map → chunk-76FLAAUC.js.map} +0 -0
  89. /package/dist/{chunk-6BFAEWQS.js.map → chunk-77H5NU3M.js.map} +0 -0
  90. /package/dist/{chunk-IANK6Y5W.js.map → chunk-A6KTB5R6.js.map} +0 -0
  91. /package/dist/{chunk-7D6O46PF.js.map → chunk-BVF3AGJP.js.map} +0 -0
  92. /package/dist/{chunk-4H6DURG6.js.map → chunk-JA3AK3PT.js.map} +0 -0
  93. /package/dist/{chunk-RCZRL5BE.js.map → chunk-MRILGULB.js.map} +0 -0
  94. /package/dist/{chunk-CWWDIQZB.js.map → chunk-QLLBRHAT.js.map} +0 -0
  95. /package/dist/{chunk-2WIPXV3Y.js.map → chunk-RR2PKP3I.js.map} +0 -0
  96. /package/dist/{chunk-3F24QTRI.js.map → chunk-SAZS2QZB.js.map} +0 -0
  97. /package/dist/{chunk-VYU7PXUS.js.map → chunk-SIC6U3GZ.js.map} +0 -0
  98. /package/dist/{chunk-WDSIV3AK.js.map → chunk-TPU5L5EY.js.map} +0 -0
  99. /package/dist/{chunk-6WV2HYTZ.js.map → chunk-W6AQJ2PY.js.map} +0 -0
  100. /package/dist/{chunk-PUXCIHRL.js.map → chunk-XSZEP4SF.js.map} +0 -0
@@ -313,13 +313,13 @@ declare const CapsuleBlockSchema: z.ZodObject<{
313
313
  peerProfiles: boolean;
314
314
  }>;
315
315
  }, "strip", z.ZodTypeAny, {
316
- schemaVersion: string;
317
316
  includes: {
318
317
  procedural: boolean;
319
318
  taxonomy: boolean;
320
319
  identityAnchors: boolean;
321
320
  peerProfiles: boolean;
322
321
  };
322
+ schemaVersion: string;
323
323
  id: string;
324
324
  description: string;
325
325
  version: string;
@@ -334,13 +334,13 @@ declare const CapsuleBlockSchema: z.ZodObject<{
334
334
  directAnswerEnabled: boolean;
335
335
  };
336
336
  }, {
337
- schemaVersion: string;
338
337
  includes: {
339
338
  procedural: boolean;
340
339
  taxonomy: boolean;
341
340
  identityAnchors: boolean;
342
341
  peerProfiles: boolean;
343
342
  };
343
+ schemaVersion: string;
344
344
  id: string;
345
345
  description: string;
346
346
  version: string;
@@ -464,13 +464,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
464
464
  peerProfiles: boolean;
465
465
  }>;
466
466
  }, "strip", z.ZodTypeAny, {
467
- schemaVersion: string;
468
467
  includes: {
469
468
  procedural: boolean;
470
469
  taxonomy: boolean;
471
470
  identityAnchors: boolean;
472
471
  peerProfiles: boolean;
473
472
  };
473
+ schemaVersion: string;
474
474
  id: string;
475
475
  description: string;
476
476
  version: string;
@@ -485,13 +485,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
485
485
  directAnswerEnabled: boolean;
486
486
  };
487
487
  }, {
488
- schemaVersion: string;
489
488
  includes: {
490
489
  procedural: boolean;
491
490
  taxonomy: boolean;
492
491
  identityAnchors: boolean;
493
492
  peerProfiles: boolean;
494
493
  };
494
+ schemaVersion: string;
495
495
  id: string;
496
496
  description: string;
497
497
  version: string;
@@ -518,13 +518,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
518
518
  pluginVersion: string;
519
519
  includesTranscripts: boolean;
520
520
  capsule: {
521
- schemaVersion: string;
522
521
  includes: {
523
522
  procedural: boolean;
524
523
  taxonomy: boolean;
525
524
  identityAnchors: boolean;
526
525
  peerProfiles: boolean;
527
526
  };
527
+ schemaVersion: string;
528
528
  id: string;
529
529
  description: string;
530
530
  version: string;
@@ -551,13 +551,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
551
551
  pluginVersion: string;
552
552
  includesTranscripts: boolean;
553
553
  capsule: {
554
- schemaVersion: string;
555
554
  includes: {
556
555
  procedural: boolean;
557
556
  taxonomy: boolean;
558
557
  identityAnchors: boolean;
559
558
  peerProfiles: boolean;
560
559
  };
560
+ schemaVersion: string;
561
561
  id: string;
562
562
  description: string;
563
563
  version: string;
@@ -683,13 +683,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
683
683
  peerProfiles: boolean;
684
684
  }>;
685
685
  }, "strip", z.ZodTypeAny, {
686
- schemaVersion: string;
687
686
  includes: {
688
687
  procedural: boolean;
689
688
  taxonomy: boolean;
690
689
  identityAnchors: boolean;
691
690
  peerProfiles: boolean;
692
691
  };
692
+ schemaVersion: string;
693
693
  id: string;
694
694
  description: string;
695
695
  version: string;
@@ -704,13 +704,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
704
704
  directAnswerEnabled: boolean;
705
705
  };
706
706
  }, {
707
- schemaVersion: string;
708
707
  includes: {
709
708
  procedural: boolean;
710
709
  taxonomy: boolean;
711
710
  identityAnchors: boolean;
712
711
  peerProfiles: boolean;
713
712
  };
713
+ schemaVersion: string;
714
714
  id: string;
715
715
  description: string;
716
716
  version: string;
@@ -737,13 +737,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
737
737
  pluginVersion: string;
738
738
  includesTranscripts: boolean;
739
739
  capsule: {
740
- schemaVersion: string;
741
740
  includes: {
742
741
  procedural: boolean;
743
742
  taxonomy: boolean;
744
743
  identityAnchors: boolean;
745
744
  peerProfiles: boolean;
746
745
  };
746
+ schemaVersion: string;
747
747
  id: string;
748
748
  description: string;
749
749
  version: string;
@@ -770,13 +770,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
770
770
  pluginVersion: string;
771
771
  includesTranscripts: boolean;
772
772
  capsule: {
773
- schemaVersion: string;
774
773
  includes: {
775
774
  procedural: boolean;
776
775
  taxonomy: boolean;
777
776
  identityAnchors: boolean;
778
777
  peerProfiles: boolean;
779
778
  };
779
+ schemaVersion: string;
780
780
  id: string;
781
781
  description: string;
782
782
  version: string;
@@ -815,13 +815,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
815
815
  pluginVersion: string;
816
816
  includesTranscripts: boolean;
817
817
  capsule: {
818
- schemaVersion: string;
819
818
  includes: {
820
819
  procedural: boolean;
821
820
  taxonomy: boolean;
822
821
  identityAnchors: boolean;
823
822
  peerProfiles: boolean;
824
823
  };
824
+ schemaVersion: string;
825
825
  id: string;
826
826
  description: string;
827
827
  version: string;
@@ -854,13 +854,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
854
854
  pluginVersion: string;
855
855
  includesTranscripts: boolean;
856
856
  capsule: {
857
- schemaVersion: string;
858
857
  includes: {
859
858
  procedural: boolean;
860
859
  taxonomy: boolean;
861
860
  identityAnchors: boolean;
862
861
  peerProfiles: boolean;
863
862
  };
863
+ schemaVersion: string;
864
864
  id: string;
865
865
  description: string;
866
866
  version: string;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  searchVerifiedEpisodes
3
- } from "./chunk-4H6DURG6.js";
3
+ } from "./chunk-JA3AK3PT.js";
4
4
  import "./chunk-NZL6GGQE.js";
5
- import "./chunk-F33CJ5CH.js";
5
+ import "./chunk-VBJ7V5SK.js";
6
6
  import "./chunk-5UZXUTVO.js";
7
7
  import "./chunk-NN2DKE4T.js";
8
8
  import "./chunk-Q7P4WJDP.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/core",
3
- "version": "1.1.29",
3
+ "version": "1.1.31",
4
4
  "description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -3,11 +3,13 @@ import { mkdtemp, rm } from "node:fs/promises";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
5
  import test from "node:test";
6
+ import { gzipSync } from "node:zlib";
6
7
 
7
8
  import { EngramAccessHttpServer } from "./access-http.js";
8
9
  import { EngramAccessInputError, type EngramAccessService } from "./access-service.js";
9
10
  import { parseConfig } from "./config.js";
10
11
  import { readPair, writePair } from "./contradiction/contradiction-review.js";
12
+ import { OFFLINE_SYNC_MAX_MTIME_MS } from "./offline-sync.js";
11
13
  import type { StorageManager } from "./storage.js";
12
14
 
13
15
  test("HTTP server rejects invalid constructor ports", () => {
@@ -286,6 +288,176 @@ test("HTTP offline snapshot forwards namespace and transfer options", async () =
286
288
  }
287
289
  });
288
290
 
291
+ test("HTTP offline snapshot accepts gzipped fast-base bodies", async () => {
292
+ const calls: Array<{
293
+ namespace: string | undefined;
294
+ principal: string | undefined;
295
+ includeTranscripts: boolean | undefined;
296
+ includeContent: boolean | undefined;
297
+ baseFiles: unknown;
298
+ baseCapturedAt: Date | undefined;
299
+ }> = [];
300
+ const service = {
301
+ offlineSyncSnapshot: async (options: {
302
+ namespace?: string;
303
+ principal?: string;
304
+ includeTranscripts?: boolean;
305
+ includeContent?: boolean;
306
+ baseFiles?: unknown;
307
+ baseCapturedAt?: Date;
308
+ }) => {
309
+ calls.push({
310
+ namespace: options.namespace,
311
+ principal: options.principal,
312
+ includeTranscripts: options.includeTranscripts,
313
+ includeContent: options.includeContent,
314
+ baseFiles: options.baseFiles,
315
+ baseCapturedAt: options.baseCapturedAt,
316
+ });
317
+ return {
318
+ namespace: options.namespace ?? "default",
319
+ format: "remnic.offline-sync.snapshot.v1",
320
+ schemaVersion: 1,
321
+ createdAt: new Date("2026-05-21T00:00:00Z").toISOString(),
322
+ sourceId: "remote:test",
323
+ includeTranscripts: options.includeTranscripts !== false,
324
+ files: [],
325
+ };
326
+ },
327
+ } as unknown as EngramAccessService;
328
+ const server = new EngramAccessHttpServer({
329
+ service,
330
+ port: 0,
331
+ authToken: "test-token",
332
+ principal: "reader",
333
+ adminConsoleEnabled: false,
334
+ });
335
+
336
+ const status = await server.start();
337
+ try {
338
+ const body = gzipSync(JSON.stringify({
339
+ namespace: "team",
340
+ includeTranscripts: false,
341
+ includeContent: false,
342
+ baseCapturedAt: "2026-05-20T00:00:00.000Z",
343
+ baseFiles: [{
344
+ path: "facts/a.md",
345
+ sha256: "a".repeat(64),
346
+ bytes: 12,
347
+ mtimeMs: 1234,
348
+ }],
349
+ }));
350
+ const response = await fetch(
351
+ `http://127.0.0.1:${status.port}/remnic/v1/offline-sync/snapshot`,
352
+ {
353
+ method: "POST",
354
+ headers: {
355
+ authorization: "Bearer test-token",
356
+ "content-type": "application/json",
357
+ "content-encoding": "gzip",
358
+ },
359
+ body,
360
+ },
361
+ );
362
+ const responseBody = await response.json() as { namespace?: string };
363
+
364
+ assert.equal(response.status, 200);
365
+ assert.equal(responseBody.namespace, "team");
366
+ assert.equal(calls.length, 1);
367
+ const call = calls[0];
368
+ assert.ok(call);
369
+ assert.deepEqual(call, {
370
+ namespace: "team",
371
+ principal: "reader",
372
+ includeTranscripts: false,
373
+ includeContent: false,
374
+ baseFiles: [{
375
+ path: "facts/a.md",
376
+ sha256: "a".repeat(64),
377
+ bytes: 12,
378
+ mtimeMs: 1234,
379
+ }],
380
+ baseCapturedAt: new Date("2026-05-20T00:00:00.000Z"),
381
+ });
382
+ } finally {
383
+ await server.stop();
384
+ }
385
+ });
386
+
387
+ test("HTTP offline snapshot stream emits metadata records as NDJSON", async () => {
388
+ const calls: Array<{
389
+ namespace: string | undefined;
390
+ principal: string | undefined;
391
+ includeTranscripts: boolean | undefined;
392
+ includeContent: boolean | undefined;
393
+ }> = [];
394
+ const service = {
395
+ offlineSyncSnapshotStream: async (options: {
396
+ namespace?: string;
397
+ principal?: string;
398
+ includeTranscripts?: boolean;
399
+ includeContent?: boolean;
400
+ }) => {
401
+ calls.push({
402
+ namespace: options.namespace,
403
+ principal: options.principal,
404
+ includeTranscripts: options.includeTranscripts,
405
+ includeContent: options.includeContent,
406
+ });
407
+ return {
408
+ namespace: options.namespace ?? "default",
409
+ format: "remnic.offline-sync.snapshot.v1",
410
+ schemaVersion: 1,
411
+ createdAt: new Date("2026-05-21T00:00:00Z").toISOString(),
412
+ sourceId: "remote:test",
413
+ includeTranscripts: options.includeTranscripts !== false,
414
+ files: (async function* () {
415
+ yield {
416
+ path: "facts/a.md",
417
+ sha256: "a".repeat(64),
418
+ bytes: 12,
419
+ mtimeMs: 1234,
420
+ };
421
+ })(),
422
+ };
423
+ },
424
+ } as unknown as EngramAccessService;
425
+ const server = new EngramAccessHttpServer({
426
+ service,
427
+ port: 0,
428
+ authToken: "test-token",
429
+ principal: "reader",
430
+ adminConsoleEnabled: false,
431
+ });
432
+
433
+ const status = await server.start();
434
+ try {
435
+ const response = await fetch(
436
+ `http://127.0.0.1:${status.port}/remnic/v1/offline-sync/snapshot-stream?namespace=team&include_transcripts=false&content=false`,
437
+ { headers: { authorization: "Bearer test-token" } },
438
+ );
439
+ const lines = (await response.text())
440
+ .trim()
441
+ .split("\n")
442
+ .map((line) => JSON.parse(line) as Record<string, unknown>);
443
+
444
+ assert.equal(response.status, 200);
445
+ assert.equal(response.headers.get("content-type"), "application/x-ndjson; charset=utf-8");
446
+ assert.equal(lines[0]?.type, "snapshot");
447
+ assert.equal(lines[0]?.namespace, "team");
448
+ assert.equal(lines[1]?.type, "file");
449
+ assert.deepEqual((lines[1]?.file as { path?: string }).path, "facts/a.md");
450
+ assert.deepEqual(calls, [{
451
+ namespace: "team",
452
+ principal: "reader",
453
+ includeTranscripts: false,
454
+ includeContent: false,
455
+ }]);
456
+ } finally {
457
+ await server.stop();
458
+ }
459
+ });
460
+
289
461
  test("HTTP offline files forwards namespace and requested paths", async () => {
290
462
  const calls: Array<{
291
463
  namespace: string | undefined;
@@ -625,6 +797,189 @@ test("HTTP offline apply-file-content allows bulk sync chunks outside the generi
625
797
  }
626
798
  });
627
799
 
800
+ test("HTTP offline snapshot accepts baseline metadata for fast sync", async () => {
801
+ const calls: Array<{
802
+ namespace: string | undefined;
803
+ principal: string | undefined;
804
+ includeTranscripts: boolean | undefined;
805
+ includeContent: boolean | undefined;
806
+ baseCapturedAt: string | undefined;
807
+ baseFileCount: number;
808
+ }> = [];
809
+ const service = {
810
+ offlineSyncSnapshot: async (options: {
811
+ namespace?: string;
812
+ principal?: string;
813
+ includeTranscripts?: boolean;
814
+ includeContent?: boolean;
815
+ baseCapturedAt?: Date;
816
+ baseFiles?: Array<{ path: string; sha256: string; bytes: number; mtimeMs: number }>;
817
+ }) => {
818
+ calls.push({
819
+ namespace: options.namespace,
820
+ principal: options.principal,
821
+ includeTranscripts: options.includeTranscripts,
822
+ includeContent: options.includeContent,
823
+ baseCapturedAt: options.baseCapturedAt?.toISOString(),
824
+ baseFileCount: options.baseFiles?.length ?? 0,
825
+ });
826
+ return {
827
+ namespace: options.namespace ?? "default",
828
+ format: "remnic.offline-sync.snapshot.v1",
829
+ schemaVersion: 1,
830
+ createdAt: new Date("2026-05-21T00:00:00Z").toISOString(),
831
+ sourceId: "remote:test",
832
+ includeTranscripts: options.includeTranscripts !== false,
833
+ files: options.baseFiles ?? [],
834
+ };
835
+ },
836
+ } as unknown as EngramAccessService;
837
+ const server = new EngramAccessHttpServer({
838
+ service,
839
+ port: 0,
840
+ authToken: "test-token",
841
+ principal: "reader",
842
+ adminConsoleEnabled: false,
843
+ });
844
+
845
+ const status = await server.start();
846
+ try {
847
+ const response = await fetch(
848
+ `http://127.0.0.1:${status.port}/remnic/v1/offline-sync/snapshot`,
849
+ {
850
+ method: "POST",
851
+ headers: {
852
+ authorization: "Bearer test-token",
853
+ "content-type": "application/json",
854
+ },
855
+ body: JSON.stringify({
856
+ namespace: "team",
857
+ includeTranscripts: false,
858
+ includeContent: false,
859
+ baseCapturedAt: "2026-05-31T17:30:08.350Z",
860
+ baseFiles: [{
861
+ path: "facts/a.md",
862
+ sha256: "a".repeat(64),
863
+ bytes: 12,
864
+ mtimeMs: 1234,
865
+ }],
866
+ }),
867
+ },
868
+ );
869
+ const body = await response.json() as { namespace?: string; files?: unknown[] };
870
+
871
+ assert.equal(response.status, 200);
872
+ assert.equal(body.namespace, "team");
873
+ assert.equal(body.files?.length, 1);
874
+ assert.deepEqual(calls, [{
875
+ namespace: "team",
876
+ principal: "reader",
877
+ includeTranscripts: false,
878
+ includeContent: false,
879
+ baseCapturedAt: "2026-05-31T17:30:08.350Z",
880
+ baseFileCount: 1,
881
+ }]);
882
+ } finally {
883
+ await server.stop();
884
+ }
885
+ });
886
+
887
+ test("HTTP offline snapshot rejects unsafe baseline paths as validation errors", async () => {
888
+ let calls = 0;
889
+ const service = {
890
+ offlineSyncSnapshot: async () => {
891
+ calls += 1;
892
+ return {};
893
+ },
894
+ } as unknown as EngramAccessService;
895
+ const server = new EngramAccessHttpServer({
896
+ service,
897
+ port: 0,
898
+ authToken: "test-token",
899
+ principal: "reader",
900
+ adminConsoleEnabled: false,
901
+ });
902
+
903
+ const status = await server.start();
904
+ try {
905
+ const response = await fetch(
906
+ `http://127.0.0.1:${status.port}/remnic/v1/offline-sync/snapshot`,
907
+ {
908
+ method: "POST",
909
+ headers: {
910
+ authorization: "Bearer test-token",
911
+ "content-type": "application/json",
912
+ },
913
+ body: JSON.stringify({
914
+ baseFiles: [{
915
+ path: "../outside.md",
916
+ sha256: "a".repeat(64),
917
+ bytes: 12,
918
+ mtimeMs: 1234,
919
+ }],
920
+ }),
921
+ },
922
+ );
923
+ const body = await response.json() as { code?: string; details?: Array<{ field?: string; message?: string }> };
924
+
925
+ assert.equal(response.status, 400);
926
+ assert.equal(body.code, "validation_error");
927
+ assert.equal(body.details?.[0]?.field, "baseFiles.0.path");
928
+ assert.match(body.details?.[0]?.message ?? "", /POSIX relative path/);
929
+ assert.equal(calls, 0);
930
+ } finally {
931
+ await server.stop();
932
+ }
933
+ });
934
+
935
+ test("HTTP offline snapshot rejects out-of-range baseline mtimes as validation errors", async () => {
936
+ let calls = 0;
937
+ const service = {
938
+ offlineSyncSnapshot: async () => {
939
+ calls += 1;
940
+ return {};
941
+ },
942
+ } as unknown as EngramAccessService;
943
+ const server = new EngramAccessHttpServer({
944
+ service,
945
+ port: 0,
946
+ authToken: "test-token",
947
+ principal: "reader",
948
+ adminConsoleEnabled: false,
949
+ });
950
+
951
+ const status = await server.start();
952
+ try {
953
+ const response = await fetch(
954
+ `http://127.0.0.1:${status.port}/remnic/v1/offline-sync/snapshot`,
955
+ {
956
+ method: "POST",
957
+ headers: {
958
+ authorization: "Bearer test-token",
959
+ "content-type": "application/json",
960
+ },
961
+ body: JSON.stringify({
962
+ baseFiles: [{
963
+ path: "facts/a.md",
964
+ sha256: "a".repeat(64),
965
+ bytes: 12,
966
+ mtimeMs: OFFLINE_SYNC_MAX_MTIME_MS + 1,
967
+ }],
968
+ }),
969
+ },
970
+ );
971
+ const body = await response.json() as { code?: string; details?: Array<{ field?: string; message?: string }> };
972
+
973
+ assert.equal(response.status, 400);
974
+ assert.equal(body.code, "validation_error");
975
+ assert.equal(body.details?.[0]?.field, "baseFiles.0.mtimeMs");
976
+ assert.match(body.details?.[0]?.message ?? "", /less than or equal/);
977
+ assert.equal(calls, 0);
978
+ } finally {
979
+ await server.stop();
980
+ }
981
+ });
982
+
628
983
  test("HTTP offline snapshot rejects invalid boolean query values", async () => {
629
984
  let calls = 0;
630
985
  const service = {