media-write-e2e.test.mjs
92 lines 3.3 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * Tier 3 — E2E: consent → link → approve → read → attach → approve → linked_note_refs.
3 */
4 import { describe, it, beforeEach, afterEach } from 'node:test';
5 import assert from 'node:assert/strict';
6 import fs from 'node:fs';
7 import path from 'node:path';
8 import { fileURLToPath } from 'node:url';
9
10 import {
11 handleMediaLinkProposeRequest,
12 handleMediaAttachProposeRequest,
13 } from '../lib/attachments/attachment-write.mjs';
14 import {
15 handleAttachmentListRequest,
16 handleAttachmentGetRequest,
17 } from '../lib/attachments/attachment-handlers.mjs';
18 import { createProposal } from '../hub/proposals-store.mjs';
19 import {
20 approveMediaProposal,
21 buildMediaWriteFixture,
22 grantActiveConsent,
23 sampleLinkProposeBody,
24 sampleAttachProposeBody,
25 } from './fixtures/media/write-helpers.mjs';
26
27 const __dirname = path.dirname(fileURLToPath(import.meta.url));
28 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-media-write-e2e');
29
30 describe('media write — e2e lifecycle', () => {
31 beforeEach(() => {
32 fs.rmSync(tmpRoot, { recursive: true, force: true });
33 delete process.env.MEDIA_EXTERNAL_LINK_ENABLED;
34 delete process.env.MEDIA_ATTACH_ENABLED;
35 });
36 afterEach(() => {
37 delete process.env.MEDIA_EXTERNAL_LINK_ENABLED;
38 delete process.env.MEDIA_ATTACH_ENABLED;
39 });
40
41 it('grant consent → link propose → approve → connector_ref list → attach → approve → linked note', async () => {
42 process.env.MEDIA_EXTERNAL_LINK_ENABLED = '1';
43 process.env.MEDIA_ATTACH_ENABLED = '1';
44 const fx = buildMediaWriteFixture(path.join(tmpRoot, 'full'));
45 const consentId = grantActiveConsent(fx.dataDir, fx.vaultId, 'gdrive');
46
47 const link = await handleMediaLinkProposeRequest({
48 dataDir: fx.dataDir,
49 vaultId: fx.vaultId,
50 cliScopes: ['personal', 'project', 'org'],
51 body: sampleLinkProposeBody({ consent_id: consentId }),
52 intent: 'link shared board',
53 createProposal,
54 });
55 assert.equal(link.ok, true);
56 assert.equal(approveMediaProposal(fx.dataDir, link.payload.proposal_id, fx.vaultPath).ok, true);
57
58 const connectorList = handleAttachmentListRequest({
59 dataDir: fx.dataDir,
60 vaultPath: fx.vaultPath,
61 vaultId: fx.vaultId,
62 role: 'admin',
63 source: 'connector_ref',
64 });
65 assert.equal(connectorList.ok, true);
66 assert.ok(connectorList.payload.attachments.some((a) => a.source === 'connector_ref'));
67 const linkId = link.payload.attachment_id;
68 assert.ok(connectorList.payload.attachments.some((a) => a.attachment_id === linkId));
69
70 const attach = await handleMediaAttachProposeRequest({
71 dataDir: fx.dataDir,
72 vaultPath: fx.vaultPath,
73 vaultId: fx.vaultId,
74 cliScopes: ['personal', 'project', 'org'],
75 body: sampleAttachProposeBody(fx, { attachment_id: linkId }),
76 intent: 'attach to lesson',
77 createProposal,
78 });
79 assert.equal(attach.ok, true);
80 assert.equal(approveMediaProposal(fx.dataDir, attach.payload.proposal_id, fx.vaultPath).ok, true);
81
82 const got = handleAttachmentGetRequest({
83 dataDir: fx.dataDir,
84 vaultPath: fx.vaultPath,
85 vaultId: fx.vaultId,
86 attachmentId: linkId,
87 role: 'admin',
88 });
89 assert.equal(got.ok, true);
90 assert.ok(got.payload.attachment.linked_note_refs.includes(fx.targetNoteRef));
91 });
92 });
File History 1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago