operator-full-export.test.mjs
82 lines 2.3 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day ago
1 import { test, mock } from 'node:test';
2 import assert from 'node:assert/strict';
3 import {
4 collectAllOperatorUserIds,
5 fetchOperatorUserIndexPage,
6 buildOperatorFullExportPayload,
7 } from '../lib/operator-full-export.mjs';
8
9 test('fetchOperatorUserIndexPage builds URL with cursor and limit', async (t) => {
10 t.mock.method(globalThis, 'fetch', async (url, init) => {
11 assert.match(String(url), /\/api\/v1\/operator\/export/);
12 assert.ok(String(url).includes('cursor=10'));
13 assert.ok(String(url).includes('limit=50'));
14 assert.equal(init.headers['X-Operator-Export-Key'], 'k');
15 return {
16 ok: true,
17 async json() {
18 return { user_ids: ['a'], next_cursor: '11', done: false };
19 },
20 };
21 });
22 const j = await fetchOperatorUserIndexPage('https://c.example.test', 'k', '10', 50);
23 assert.deepEqual(j.user_ids, ['a']);
24 });
25
26 test('collectAllOperatorUserIds follows next_cursor until done', async () => {
27 let call = 0;
28 mock.method(globalThis, 'fetch', async (url) => {
29 call += 1;
30 if (call === 1) {
31 return {
32 ok: true,
33 json: async () => ({
34 user_ids: ['u1', 'u2'],
35 next_cursor: '2',
36 done: false,
37 }),
38 };
39 }
40 return {
41 ok: true,
42 json: async () => ({
43 user_ids: ['u3'],
44 next_cursor: '',
45 done: true,
46 }),
47 };
48 });
49 try {
50 const ids = await collectAllOperatorUserIds('https://c.test', 'key', 200);
51 assert.deepEqual(ids, ['u1', 'u2', 'u3']);
52 assert.equal(call, 2);
53 } finally {
54 mock.restoreAll();
55 }
56 });
57
58 test('collectAllOperatorUserIds stops if next_cursor empty when not done', async () => {
59 mock.method(globalThis, 'fetch', async () => ({
60 ok: true,
61 json: async () => ({
62 user_ids: ['x'],
63 next_cursor: '',
64 done: false,
65 }),
66 }));
67 try {
68 const ids = await collectAllOperatorUserIds('https://c.test', 'key');
69 assert.deepEqual(ids, ['x']);
70 } finally {
71 mock.restoreAll();
72 }
73 });
74
75 test('buildOperatorFullExportPayload shape', () => {
76 const p = buildOperatorFullExportPayload([
77 { user_id: 'a', vaults: [{ vault_id: 'default', notes: [] }], proposals: [] },
78 ]);
79 assert.equal(p.format_version, 4);
80 assert.equal(p.kind, 'knowtation-operator-full-export');
81 assert.equal(p.users.length, 1);
82 });
File History 2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6 docs: accept Calendar Events v0 spec with Phase 0 security … Human 1 day ago