Skip to content

Write a detection rule's Markdown copy next to its HTML page - #5057

Open
srednoff888-art wants to merge 2 commits into
elastic:mainfrom
srednoff888-art:fix/rule-markdown-output-path
Open

srednoff888-art wants to merge 2 commits into
elastic:mainfrom
srednoff888-art:fix/rule-markdown-output-path

Conversation

@srednoff888-art

Copy link
Copy Markdown

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 build of the detection-rules docset fails with ScopedFileSystemException for 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 .toml files outside the docs folder, so their default output path starts with <output>/../rules/. RuleDocumentationFileExporter passes that path through DetectionRuleFile.OutputPath, which puts the HTML page back under the output folder. The Markdown exporters get the path unchanged in MarkdownExportFileContext.DefaultOutputFile, so LlmMarkdownExporter writes 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.ProcessFile now passes a detection rule's output path through DetectionRuleFile.OutputPath before it gives it to the Markdown exporters. That is the same remap the HTML exporter and GlobalNavigationPathProvider already use, and it leaves the path of every other page as it was. The fix is in the generator rather than in LlmMarkdownExporter, so every Markdown exporter gets the path where the HTML page is written.

Test

GenerateAll_RuleOutsideDocsFolder_WritesMarkdownNextToHtml builds a docset with one rule in a sibling rules folder and the output folder outside the docs folder, and checks that the rule's index.html and .md both end up under the output folder. DetectionRule.From reads the .toml from disk, so the test writes the docset to a temporary folder instead of a MockFileSystem. Without the fix, it fails because the .md lands at ../rules/linux/kernel_ring_buffer.md.

Verify

dotnet test --project tests/Elastic.Markdown.Tests --treenode-filter "/*/*/DetectionRuleExportTests/*"

All 2256 tests of Elastic.Markdown.Tests pass on Windows. I did not run a build of the real elastic/detection-rules docset.

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>
@srednoff888-art
srednoff888-art requested a review from a team as a code owner November 26, 2026 00:09
Document = document,
SourceFile = markdown,
DefaultOutputFile = outputFile,
DefaultOutputFile = markdownOutputFile,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standalone builds of the detection-rules docset fail: the Markdown exporter writes rule pages outside the output folder

1 participant