|
| 1 | +/** |
| 2 | + * The MCP `initialize` instructions must describe the VBA/Access surfaces the |
| 3 | + * fork actually indexes (issue #320). |
| 4 | + * |
| 5 | + * `src/mcp/server-instructions.ts` is the single source of truth for |
| 6 | + * agent-facing guidance (#529) — it is the first and only thing an agent is |
| 7 | + * told about what lives in this index. Prose there is cheap to write and easy |
| 8 | + * to let rot, so these tests do NOT assert on wording. They run the real |
| 9 | + * extractors, collect the node kinds and `synthesizedBy` tags those extractors |
| 10 | + * emit, and require the instructions to name each one. Rename a tag in an |
| 11 | + * extractor and this suite fails until the guidance follows. |
| 12 | + */ |
| 13 | +import { describe, it, expect } from 'vitest'; |
| 14 | +import * as fs from 'node:fs'; |
| 15 | +import * as path from 'node:path'; |
| 16 | +import { SERVER_INSTRUCTIONS } from '../src/mcp/server-instructions'; |
| 17 | +import { SqlQueryExtractor } from '../src/extraction/sql-query-extractor'; |
| 18 | +import { VbaTestSequenceExtractor } from '../src/extraction/vba-test-sequence-extractor'; |
| 19 | +import { VbaTestManifestExtractor } from '../src/extraction/vba-test-manifest-extractor'; |
| 20 | +import { |
| 21 | + AccessErdExtractor, |
| 22 | + ERD_TABLE_SYNTHESIZED_BY, |
| 23 | + ERD_LINKED_TABLE_SYNTHESIZED_BY, |
| 24 | +} from '../src/extraction/access-erd-extractor'; |
| 25 | +import { EXTERNAL_BACKEND_SYNTHESIZED_BY } from '../src/extraction/sql-table-scan'; |
| 26 | + |
| 27 | +/** Every `synthesizedBy` tag on the nodes, edges and refs of a result. */ |
| 28 | +function tagsOf(result: { |
| 29 | + nodes: Array<{ metadata?: Record<string, unknown> }>; |
| 30 | + edges: Array<{ metadata?: Record<string, unknown> }>; |
| 31 | + unresolvedReferences: Array<{ metadata?: Record<string, unknown> }>; |
| 32 | +}): string[] { |
| 33 | + const out = new Set<string>(); |
| 34 | + for (const item of [...result.nodes, ...result.edges, ...result.unresolvedReferences]) { |
| 35 | + const tag = item.metadata?.synthesizedBy; |
| 36 | + if (typeof tag === 'string') out.add(tag); |
| 37 | + } |
| 38 | + return [...out]; |
| 39 | +} |
| 40 | + |
| 41 | +describe('MCP server instructions — VBA/Access coverage (#320)', () => { |
| 42 | + it('names every tag and node kind a saved Access query emits', () => { |
| 43 | + const r = new SqlQueryExtractor( |
| 44 | + 'queries/Q_Ventas.sql', |
| 45 | + 'SELECT * FROM TbVentas INNER JOIN TbClientes ON 1 = 1;\n', |
| 46 | + ).extract(); |
| 47 | + |
| 48 | + // Sanity: the fixture really does produce a query node with table refs, so |
| 49 | + // an extractor that silently stopped emitting them cannot pass this test. |
| 50 | + expect(r.nodes.some((n) => n.kind === 'query')).toBe(true); |
| 51 | + const tags = tagsOf(r); |
| 52 | + expect(tags).toContain('sql-query-table'); |
| 53 | + |
| 54 | + for (const tag of tags) { |
| 55 | + expect(SERVER_INSTRUCTIONS, `undocumented tag: ${tag}`).toContain(tag); |
| 56 | + } |
| 57 | + expect(SERVER_INSTRUCTIONS).toContain('query'); |
| 58 | + expect(SERVER_INSTRUCTIONS).toContain('queries.json'); |
| 59 | + expect(SERVER_INSTRUCTIONS).toContain(EXTERNAL_BACKEND_SYNTHESIZED_BY); |
| 60 | + }); |
| 61 | + |
| 62 | + it('names the test-sequence surface, not just the manifests', () => { |
| 63 | + const r = new VbaTestSequenceExtractor( |
| 64 | + 'tests/sequences/cache.json', |
| 65 | + JSON.stringify({ |
| 66 | + runnerPolicy: { tool: 'dysflow', sequential: true }, |
| 67 | + procedures: ['Test_Cache_RunSlice'], |
| 68 | + }), |
| 69 | + ).extract(); |
| 70 | + |
| 71 | + const tags = tagsOf(r); |
| 72 | + expect(tags).toContain('vba-test-sequence'); |
| 73 | + for (const tag of tags) { |
| 74 | + expect(SERVER_INSTRUCTIONS, `undocumented tag: ${tag}`).toContain(tag); |
| 75 | + } |
| 76 | + |
| 77 | + // The metadata an agent has to know exists to act on a sequence. |
| 78 | + const ref = r.unresolvedReferences[0]; |
| 79 | + for (const key of Object.keys(ref?.metadata ?? {})) { |
| 80 | + if (key === 'synthesizedBy') continue; |
| 81 | + expect(SERVER_INSTRUCTIONS, `undocumented metadata key: ${key}`).toContain(key); |
| 82 | + } |
| 83 | + }); |
| 84 | + |
| 85 | + it('still names the manifest surface it already documented', () => { |
| 86 | + // Guard against a future edit trimming the paragraph the sequences one |
| 87 | + // now sits beside. |
| 88 | + const r = new VbaTestManifestExtractor( |
| 89 | + 'tests/tests.vba.smoke.json', |
| 90 | + JSON.stringify({ tests: [{ procedure: 'Test_X_RunAll' }] }), |
| 91 | + ).extract(); |
| 92 | + for (const tag of tagsOf(r)) { |
| 93 | + expect(SERVER_INSTRUCTIONS, `undocumented tag: ${tag}`).toContain(tag); |
| 94 | + } |
| 95 | + }); |
| 96 | + |
| 97 | + it('names every tag the Access ERD export emits', () => { |
| 98 | + const fixture = path.join( |
| 99 | + __dirname, |
| 100 | + 'fixtures', |
| 101 | + 'access-erd', |
| 102 | + 'ERD', |
| 103 | + 'Estructura_Datos.md', |
| 104 | + ); |
| 105 | + const r = new AccessErdExtractor( |
| 106 | + 'ERD/Estructura_Datos.md', |
| 107 | + fs.readFileSync(fixture, 'utf-8'), |
| 108 | + ).extract(); |
| 109 | + |
| 110 | + // The fixture carries both a plain and a LINKED table, so both tags are |
| 111 | + // exercised rather than assumed. |
| 112 | + const tags = tagsOf(r); |
| 113 | + expect(tags).toContain(ERD_TABLE_SYNTHESIZED_BY); |
| 114 | + expect(tags).toContain(ERD_LINKED_TABLE_SYNTHESIZED_BY); |
| 115 | + |
| 116 | + for (const tag of tags) { |
| 117 | + expect(SERVER_INSTRUCTIONS, `undocumented tag: ${tag}`).toContain(tag); |
| 118 | + } |
| 119 | + // The node kinds an agent would have to ask for by name. |
| 120 | + expect(SERVER_INSTRUCTIONS).toContain('type_member'); |
| 121 | + expect(SERVER_INSTRUCTIONS).toContain('ERD/'); |
| 122 | + }); |
| 123 | +}); |
0 commit comments