media-write-parity-integration.test.mjs
126 lines 4.1 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 10 days ago
1 /**
2 * Tier 2 — INTEGRATION: CLI = MCP = Hub parity + disabled gates.
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 { createProposal } from '../hub/proposals-store.mjs';
15 import {
16 buildMediaWriteFixture,
17 grantActiveConsent,
18 sampleLinkProposeBody,
19 sampleAttachProposeBody,
20 } from './fixtures/media/write-helpers.mjs';
21 import { registerAttachmentTools } from '../mcp/tools/attachment.mjs';
22
23 const __dirname = path.dirname(fileURLToPath(import.meta.url));
24 const tmpRoot = path.join(__dirname, 'fixtures', 'tmp-media-write-parity');
25
26 function stripVolatile(payload) {
27 const copy = structuredClone(payload);
28 delete copy.proposal_id;
29 return copy;
30 }
31
32 describe('media write — triple-surface parity', () => {
33 beforeEach(() => {
34 fs.rmSync(tmpRoot, { recursive: true, force: true });
35 delete process.env.MEDIA_EXTERNAL_LINK_ENABLED;
36 delete process.env.MEDIA_ATTACH_ENABLED;
37 });
38 afterEach(() => {
39 delete process.env.MEDIA_EXTERNAL_LINK_ENABLED;
40 delete process.env.MEDIA_ATTACH_ENABLED;
41 });
42
43 it('Hub, CLI, MCP produce deep-equal link propose envelope when gate on', async () => {
44 process.env.MEDIA_EXTERNAL_LINK_ENABLED = '1';
45 const fx = buildMediaWriteFixture(path.join(tmpRoot, 'link'));
46 const consentId = grantActiveConsent(fx.dataDir, fx.vaultId, 'gdrive');
47 const body = sampleLinkProposeBody({ consent_id: consentId });
48
49 const hub = await handleMediaLinkProposeRequest({
50 dataDir: fx.dataDir,
51 vaultId: fx.vaultId,
52 role: 'admin',
53 body,
54 intent: 'link it',
55 createProposal,
56 });
57 const cli = await handleMediaLinkProposeRequest({
58 dataDir: fx.dataDir,
59 vaultId: fx.vaultId,
60 cliScopes: ['personal', 'project', 'org'],
61 body,
62 intent: 'link it',
63 createProposal,
64 });
65 const mcp = await handleMediaLinkProposeRequest({
66 dataDir: fx.dataDir,
67 vaultId: fx.vaultId,
68 cliScopes: ['personal', 'project', 'org'],
69 body,
70 intent: 'link it',
71 createProposal,
72 });
73 assert.equal(hub.ok, true);
74 assert.equal(cli.ok, true);
75 assert.equal(mcp.ok, true);
76 assert.deepEqual(stripVolatile(hub.payload), stripVolatile(cli.payload));
77 assert.deepEqual(stripVolatile(cli.payload), stripVolatile(mcp.payload));
78 });
79
80 it('both gates off refuse link and attach on all surfaces', async () => {
81 const fx = buildMediaWriteFixture(path.join(tmpRoot, 'off'));
82 const linkBody = sampleLinkProposeBody();
83 const attachBody = sampleAttachProposeBody(fx);
84
85 for (const ctx of [{ role: 'admin' }, { cliScopes: ['personal'] }]) {
86 const link = await handleMediaLinkProposeRequest({
87 dataDir: fx.dataDir,
88 vaultId: fx.vaultId,
89 body: linkBody,
90 intent: 'link',
91 createProposal,
92 ...ctx,
93 });
94 assert.equal(link.ok, false);
95 assert.equal(link.code, 'MEDIA_EXTERNAL_LINK_DISABLED');
96
97 const attach = await handleMediaAttachProposeRequest({
98 dataDir: fx.dataDir,
99 vaultPath: fx.vaultPath,
100 vaultId: fx.vaultId,
101 body: attachBody,
102 intent: 'attach',
103 createProposal,
104 ...ctx,
105 });
106 assert.equal(attach.ok, false);
107 assert.equal(attach.code, 'MEDIA_ATTACH_DISABLED');
108 }
109 });
110
111 it('consent grant is not registered as an MCP write tool', () => {
112 /** @type {string[]} */
113 const registered = [];
114 const fakeServer = {
115 registerTool(name) {
116 registered.push(name);
117 },
118 };
119 registerAttachmentTools(fakeServer);
120 assert.ok(registered.includes('media_external_link_propose'));
121 assert.ok(registered.includes('media_attach_propose'));
122 assert.ok(registered.includes('media_import_consent_list'));
123 assert.ok(!registered.includes('media_import_consent_grant'));
124 assert.ok(!registered.includes('media_import_consent_revoke'));
125 });
126 });
File History 1 commit
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 10 days ago