docs-oauth-connector-data-integrity.test.mjs
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
11 days ago
| 1 | import assert from 'node:assert/strict'; |
| 2 | import fs from 'node:fs'; |
| 3 | import os from 'node:os'; |
| 4 | import path from 'node:path'; |
| 5 | import test from 'node:test'; |
| 6 | |
| 7 | import { |
| 8 | connectorForClient, |
| 9 | getConnector, |
| 10 | saveConnector, |
| 11 | } from '../lib/docs/docs-connector-store.mjs'; |
| 12 | import { proposeDocsImports } from '../lib/docs/docs-import-propose.mjs'; |
| 13 | import { noteStateIdFromParts } from '../lib/note-state-id.mjs'; |
| 14 | |
| 15 | test('data-integrity: cursor and custody fields never enter client projection', () => { |
| 16 | const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kn-docs-data-')); |
| 17 | const connector = { |
| 18 | connector_id: 'conn_0123456789abcdef', |
| 19 | provider: 'google-drive', |
| 20 | display_name: 'Drive', |
| 21 | status: 'connected', |
| 22 | account_sub: 'private-sub', |
| 23 | oauth_ref: 'secret-ref', |
| 24 | sync_cursor: 'opaque-cursor', |
| 25 | last_sync_at: null, |
| 26 | last_sync_error: 'none', |
| 27 | file_count: 3, |
| 28 | revoked_at: null, |
| 29 | oauth_pending: { state: 'secret-state' }, |
| 30 | }; |
| 31 | saveConnector(dataDir, 'vault-d', connector); |
| 32 | assert.equal(getConnector(dataDir, 'vault-d', connector.connector_id).sync_cursor, 'opaque-cursor'); |
| 33 | const client = connectorForClient(connector); |
| 34 | for (const hidden of ['account_sub', 'oauth_ref', 'sync_cursor', 'oauth_pending']) { |
| 35 | assert.equal(Object.hasOwn(client, hidden), false); |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | test('data-integrity: existing source identity produces an edit proposal state id', () => { |
| 40 | const note = { |
| 41 | path: 'archive/existing.md', |
| 42 | frontmatter: { source: 'google-drive', source_id: 'drive_1', title: 'Old' }, |
| 43 | body: 'Old body', |
| 44 | }; |
| 45 | const calls = []; |
| 46 | const output = proposeDocsImports({ |
| 47 | dataDir: '/unused', |
| 48 | vaultPath: '/vault', |
| 49 | vaultId: 'vault-d', |
| 50 | connectorId: 'conn_0123456789abcdef', |
| 51 | provider: 'google-drive', |
| 52 | items: [{ source_id: 'drive_1', name: 'New', markdown: 'New body', size: 8 }], |
| 53 | createProposalFn: (_dataDir, input) => { |
| 54 | calls.push(input); |
| 55 | return { ...input, proposal_id: 'edit-proposal', status: 'proposed' }; |
| 56 | }, |
| 57 | loadProposalsFn: () => [], |
| 58 | listMarkdownFilesFn: () => [note.path], |
| 59 | readNoteFn: () => note, |
| 60 | }); |
| 61 | assert.equal(output.proposed, 1); |
| 62 | assert.equal(calls[0].path, note.path); |
| 63 | assert.equal(calls[0].base_state_id, noteStateIdFromParts(note.frontmatter, note.body)); |
| 64 | }); |
File History
1 commit
sha256:700fafdd1afa490919f9515d660ca6e75456bcd5bb67513abcd8757a634c01f6
docs: record AIP-b SD-21 land (KN #308)
Human
11 days ago