Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
test(markdown-editor): add structure-count invariant + nested-composition coverage (M2, M3)
Sergey Kozyrenkob7012ee2af11
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.tsindex f95b9386..1da12c70 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts@@ -1,6 +1,6 @@import { beforeAll, describe, expect, it } from 'vitest';-import { roundTrip, setupEditorJsdom } from './markdown-editor-test-setup';+import { roundTrip, setupEditorJsdom, structuralCounts } from './markdown-editor-test-setup';beforeAll(setupEditorJsdom);@@ -42,8 +42,8 @@ const ATOMS = [const WORDS = ['firewall', 'payload', 'exploit', 'nmap', 'recon', 'shell', 'token', 'vector'];// Block contexts that keep inline content literal: paragraph, heading, bullet item, ordered item,-// blockquote, inline code. (ordered>bullet>code nesting is intentionally NOT generated — it hits the-// pinned @tiptap/markdown code-drop bug covered separately.)+// blockquote, inline code. (Nested compositions — ordered>bullet>code, fence-in-fence — are exercised+// separately below; the historical ordered>bullet>code drop is fixed by the indented-fence + fence-widen work.)const wrap = (context: number, text: string): string => {switch (context) {case 1:@@ -105,4 +105,33 @@ describe('generative content-integrity — atoms survive load↔serialize across])('round-trips %s byte-identical', (source) => {expect(roundTrip(source)).toBe(source);});++ // M3: the survives/converges oracles above only place atoms in SINGLE contexts. Nesting primitives inside+ // one another (ordered>bullet, blockquote>list, list>code, fence-in-fence) is exactly the class that+ // produced the historical ordered>bullet>code drop — assert structure (via structuralCounts, catching a+ // dropped block/item) AND convergence AND atom survival across depth-≥2 compositions.+ it('nested primitive compositions preserve structure, content, and converge', () => {+ const rng = mulberry32(0x5eeded);+ const nestAtoms = ['{{.TargetURL}}', '<container_environment>', '__init__', 'C++ then C++', 'os.execute()'];+ const nesters: ((a: string) => string)[] = [+ (a) => `1. first ${a}\n - nested ${a}\n2. second ${a}`,+ (a) => `> quote ${a}\n> - list item ${a}`,+ (a) => `- top ${a}\n - mid ${a}\n - deep ${a}`,+ (a) => `1. step ${a}\n\n \`\`\`\n payload ${a}\n \`\`\``,+ (a) => `\`\`\`\`\nouter ${a}\n\`\`\`\ninner ${a}\n\`\`\`\n\`\`\`\``,+ ];++ for (let i = 0; i < 120; i++) {+ const nester = nesters[Math.floor(rng() * nesters.length)] as (a: string) => string;+ const atom = nestAtoms[Math.floor(rng() * nestAtoms.length)] as string;+ const doc = nester(atom);+ const out = roundTrip(doc);++ expect(structuralCounts(out), `structure changed (i=${i}):\n${doc}\n-->\n${out}`).toEqual(+ structuralCounts(doc),+ );+ expect(roundTrip(out), `did not converge (i=${i}):\n${doc}`).toBe(out);+ expect(out.includes(atom), `atom "${atom}" lost (i=${i}):\n${doc}\n-->\n${out}`).toBe(true);+ }+ });});diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-corpus.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-corpus.test.tsindex 0db50916..a7f52d78 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-corpus.test.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-corpus.test.ts@@ -2,7 +2,7 @@ import { readdirSync, readFileSync } from 'node:fs';import { join } from 'node:path';import { beforeAll, describe, expect, it } from 'vitest';-import { roundTrip, setupEditorJsdom } from './markdown-editor-test-setup';+import { roundTrip, setupEditorJsdom, structuralCounts } from './markdown-editor-test-setup';beforeAll(setupEditorJsdom);@@ -14,7 +14,7 @@ describe('corpus — every real prompt .tmpl survives the round-trip with no conconst files = readdirSync(dir).filter((file) => file.endsWith('.tmpl'));for (const file of files) {- it(file + ': tags literal, {{ }} preserved, no word dropped, converges', () => {+ it(file + ': tags literal, {{ }} preserved, structure + words intact, converges', () => {const src = readFileSync(join(dir, file), 'utf8');const save1 = roundTrip(src);const save2 = roundTrip(save1);@@ -25,6 +25,9 @@ describe('corpus — every real prompt .tmpl survives the round-trip with no con// word MULTISET (not a Set) so a count drop / dup / reorder is caught, plus ≤2-save convergence// (some templates canonicalize over two saves — save1 ≠ save2 is within contract, save2 is stable)expect(words(save2).slice().sort()).toEqual(words(src).slice().sort());+ // structural node counts (code blocks, list items, headings, tables) — a word-preserving structural+ // downgrade (block split / dropped cell) passes the multiset check but fails this.+ expect(structuralCounts(save2)).toEqual(structuralCounts(src));expect(roundTrip(save2)).toBe(save2);});}diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-test-setup.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-test-setup.tsindex 9be179b9..34e8e837 100644--- a/frontend/src/components/shared/markdown-editor/markdown-editor-test-setup.ts+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-test-setup.ts@@ -20,3 +20,38 @@ export const roundTrip = (markdown: string): string => {return out;};++// Structural node types whose counts must survive a round-trip. paragraph/text/hardBreak are excluded: benign+// reflow (a paragraph splitting, whitespace) changes those without losing content, whereas a change in a+// structural count is a real downgrade — a dropped code block, list item, table cell, heading. Complements the+// word-multiset oracle (which a structure-only downgrade can pass while every word survives).+const STRUCTURAL_TYPES = new Set([+ 'blockquote',+ 'bulletList',+ 'codeBlock',+ 'heading',+ 'horizontalRule',+ 'image',+ 'listItem',+ 'orderedList',+ 'table',+ 'tableCell',+ 'tableHeader',+ 'tableRow',+ 'taskItem',+ 'taskList',+]);++export const structuralCounts = (markdown: string): Record<string, number> => {+ const editor = new Editor({ content: markdown, contentType: 'markdown', extensions: createMarkdownExtensions() });+ const counts: Record<string, number> = {};++ editor.state.doc.descendants((node) => {+ if (STRUCTURAL_TYPES.has(node.type.name)) {+ counts[node.type.name] = (counts[node.type.name] ?? 0) + 1;+ }+ });+ editor.destroy();++ return counts;+};