Mermaid's static diagram overlaps badly as the graph grows. Replace the /__graph__ HTML with an interactive Cytoscape.js + dagre viewer (both loaded from a CDN, so no runtime dependency is added — the one-dep pitch holds). Clicking a route lights up its real transitive slice and dims the rest; clicking a provider/step shows its blast radius. Edges are colour-coded by kind (needs vs feeds-endpoint), provider/step/endpoint nodes are visually distinct, and nodes are draggable. toMermaid()/toDOT() and the text/plain path are unchanged. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+162
-24
No files matched your search
+2
-2
@@ -376,8 +376,8 @@ describe('devGraph endpoint', () => {
|
||||
const app = createApp({ modules: [M], devGraph: true });
|
||||
const s = await app.listen(0);
|
||||
const html = await fetch(`http://127.0.0.1:${portOf(s)}/__graph__`).then((r) => r.text());
|
||||
expect(html).toContain('class="mermaid"');
|
||||
expect(html).toContain('flowchart');
|
||||
expect(html).toContain('cytoscape');
|
||||
expect(html).toContain('/api/u/me');
|
||||
const mmd = await fetch(`http://127.0.0.1:${portOf(s)}/__graph__`, { headers: { accept: 'text/plain' } });
|
||||
expect(mmd.headers.get('content-type')).toContain('text/plain');
|
||||
expect(await mmd.text()).toContain('flowchart');
|
||||
|
||||
+19
-9
@@ -16,10 +16,10 @@ describe('toMermaid', () => {
|
||||
expect(m).toContain('flowchart');
|
||||
expect(m).toContain('"db"');
|
||||
expect(m).toContain('"user"');
|
||||
expect(m).toContain('n_config --> n_db'); // db needs config
|
||||
expect(m).toContain('n_db --> n_user'); // user needs db
|
||||
expect(m).not.toContain('n_req'); // 'req' is a seed (no node) -> no edge
|
||||
expect(m).toContain('GET /users/:id'); // route node label
|
||||
expect(m).toContain('n_config --> n_db'); // db needs config
|
||||
expect(m).toContain('n_db --> n_user'); // user needs db
|
||||
expect(m).not.toContain('n_req'); // 'req' is a seed (no node) -> no edge
|
||||
expect(m).toContain('GET /users/:id'); // route node label
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,10 +32,20 @@ describe('toDOT', () => {
|
||||
});
|
||||
|
||||
describe('graphHtml', () => {
|
||||
it('wraps mermaid source in an HTML page that loads mermaid', () => {
|
||||
const html = graphHtml('flowchart LR\n a-->b');
|
||||
expect(html).toContain('<pre class="mermaid">');
|
||||
expect(html).toContain('flowchart LR');
|
||||
expect(html).toContain('mermaid');
|
||||
it('emits an interactive Cytoscape page with the graph embedded as JSON', () => {
|
||||
const html = graphHtml(view);
|
||||
expect(html).toContain('cytoscape'); // loads the viz lib from CDN
|
||||
expect(html).toContain('cytoscape-dagre'); // and the DAG layout
|
||||
expect(html).toContain('"user"'); // node data is embedded client-side
|
||||
expect(html).toContain('/users/:id'); // route data too
|
||||
});
|
||||
|
||||
it('escapes embedded JSON so a node name cannot break out of the script tag', () => {
|
||||
const evil = graphHtml({
|
||||
nodes: [{ name: 'a</script><b', kind: 'provider', origin: 'x', needs: [], provides: ['a'] }],
|
||||
routes: [],
|
||||
});
|
||||
expect(evil).not.toContain('a</script><b'); // raw injection must not survive
|
||||
expect(evil).toContain('a\\u003c/script'); // '<' is escaped to <
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user