Repository navigation
Write a detection rule's Markdown copy next to its HTML page - #5057
srednoff888-art wants to merge 2 commits into
Conversation
Rule pages come from .toml files outside the docs folder, so their default output path starts with ../rules. The HTML exporter remaps it with DetectionRuleFile.OutputPath, but the Markdown exporters got the path as it was, so each rule's .md copy went outside the output folder. A build whose output folder isn't inside the checkout then failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Document = document, | ||
| SourceFile = markdown, | ||
| DefaultOutputFile = outputFile, | ||
| DefaultOutputFile = markdownOutputFile, |
There was a problem hiding this comment.
Severity: P3 (Low)
A rule named rules/index.toml can now overwrite the rule overview’s rules.md export. The remapped path makes the LLM exporter treat the rule as a directory index and write <output>/rules.md, even though the HTML writer emits <output>/rules/index/index.html. If the docset also has a docs/rules.md overview, both exporters write the same Markdown file in parallel. Make the HTML and Markdown writers agree on what counts as a directory index.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
There was a problem hiding this comment.
True for a rule file named index.toml, since LlmMarkdownExporter treats any index page as a folder index. Before this change that copy went to <output>/../rules.md, so it was misplaced either way. elastic/detection-rules has no index.toml today (code search finds none), so I left it out of this PR. I can make the exporter skip the folder-index mapping for DetectionRuleFile here if you'd like it covered.
| fs.DirectoryInfo.New(Path.Join(root.FullName, "docs")), | ||
| new DocumentationScopeOptions { Inner = fs, Output = Path.Join(root.FullName, "out", "html") } | ||
| ); | ||
| var context = new BuildContext(collector, documentationFileSystem, TestHelpers.CreateConfigurationContext(fs)) |
There was a problem hiding this comment.
Severity: P3 (Low)
The test catches the misplaced Markdown copy, but not the scoped-filesystem failure. With .git at root, both root/out/html and the old destination root/out/rules are inside the writable checkout. Add a case where the output is outside the checkout and the write scope denies the old destination.
Generated by Libra. React with 👍 or 👎 to give feedback on this comment.
There was a problem hiding this comment.
In 8da92bd the checkout is now root/repo and the output root/out/html, outside it. On my machine (Windows) the old write to root/out/rules still isn't refused in that layout, so the test checks where the copy lands rather than the exception. Without the fix it still fails, because the .md is at ../rules/linux/kernel_ring_buffer.md relative to the output folder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A standalone build of a docset with detection rules now writes each rule's Markdown copy next to its HTML page, under the output folder, so the build no longer fails when the output folder is outside the checkout.
Affects: Content export, Isolated builds
Prompt summary: Fix #4923, where
docs-builder buildof the detection-rules docset fails withScopedFileSystemExceptionfor every rule page's Markdown copy. The copy should use the same output path as the rule's HTML page.Fixes #4923.
Why
Rule pages come from
.tomlfiles outside the docs folder, so their default output path starts with<output>/../rules/.RuleDocumentationFileExporterpasses that path throughDetectionRuleFile.OutputPath, which puts the HTML page back under the output folder. The Markdown exporters get the path unchanged inMarkdownExportFileContext.DefaultOutputFile, soLlmMarkdownExporterwrites each copy to<output>/../rules/…. That is outside the output folder, and since ScopedFileSystem 0.7.2 a build refuses the write when the folder's parent is not in scope.What
Markdown exporters get the remapped path
DocumentationGenerator.ProcessFilenow passes a detection rule's output path throughDetectionRuleFile.OutputPathbefore it gives it to the Markdown exporters. That is the same remap the HTML exporter andGlobalNavigationPathProvideralready use, and it leaves the path of every other page as it was. The fix is in the generator rather than inLlmMarkdownExporter, so every Markdown exporter gets the path where the HTML page is written.Test
GenerateAll_RuleOutsideDocsFolder_WritesMarkdownNextToHtmlbuilds a docset with one rule in a siblingrulesfolder and the output folder outside the docs folder, and checks that the rule'sindex.htmland.mdboth end up under the output folder.DetectionRule.Fromreads the.tomlfrom disk, so the test writes the docset to a temporary folder instead of aMockFileSystem. Without the fix, it fails because the.mdlands at../rules/linux/kernel_ring_buffer.md.Verify
All 2256 tests of
Elastic.Markdown.Testspass on Windows. I did not run a build of the realelastic/detection-rulesdocset.