Skip to content

Pandoc filter shim: generated fast path, launch-failure handling, size-limit scale hint - #153

Merged
Malcolmnixon merged 4 commits into
mainfrom
fix/shim-fast-path
Nov 17, 2026
Merged

Malcolmnixon merged 4 commits into
mainfrom
fix/shim-fast-path

Conversation

@Malcolmnixon

Copy link
Copy Markdown
Member

Pull Request

Description

Fixes from the Pandoc filter rollout feedback (the handoff after 0.2.0-beta.11).

  • Generated fast path: the shim's quick "can CanvasNet draw this?" check no longer hand-copies the engine's rules. The embedded canvasnet.lua template has @CLASSES@ and @SUFFIXES@ placeholders that --write-shim fills from the engine's own tables:
    • classes mermaid (case-sensitive, as the engine matches them);
    • suffixes .svg .vl.json .vl .scad .vsdx .pptx .pdf .mmd .mermaid (case-insensitive).
      So a document with no CanvasNet pictures never starts the tool, and the shim cannot drift from the engine.
  • Launch-failure handling: when the tool cannot be started (not installed, not restored, crashes, or prints something that is not JSON), the shim stops with one canvasnet.lua: message that says what went wrong, instead of a Lua error from inside the shim. The e2e script tests seven failure shapes through a stubbed pandoc.pipe run by dotnet pandoc lua.
  • Size-limit hint: an over-size picture error now gives the size, the 8192-pixel limit, and a scale that fits (8192 divided by the larger side, rounded down to two significant digits, for example 0.56). The Viewer passes the scale to the tool through the exception's Data entry DemaConsulting.CanvasNet.Viewer.FitScale.
  • Mermaid crossings (handoff item 4): checked against Mermaid 11. It draws the same edge crossings through subgraph titles for the SonarMark diagram, so the layout is unchanged.

The filter protocol stays at 1, so shims already written keep working. The docs and canvasnet help pandoc say to regenerate the shim (dotnet canvasnet pandoc-filter --write-shim docs/filters/canvasnet.lua) after updating the tool, to pick up the generated fast path.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvement

Related Issues

Follow-up to #146.

Pre-Submission Checklist

Before submitting this pull request, ensure you have completed the following:

Build and Test

  • Code builds successfully and all tests pass: pwsh ./build.ps1 (passed, 0 failures)
  • Code produces zero warnings

Code Quality

  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

Please run the following checks before submitting:

  • All linters pass: pwsh ./lint.ps1 (passed)

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Updated docs/ documentation (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)

Additional Notes

docs/filters/test-canvasnet.ps1 (the end-to-end filter checks) passed all 124 checks. docs/filters/canvasnet.lua is regenerated from the new template, and the existing test keeps it byte-identical to the embedded copy.

Malcolm Nixon and others added 2 commits November 17, 2026 10:11
…ze-limit scale hint

- The shim's fast path starts the tool only for a code block of a class the
  engine draws (mermaid) or a local picture whose name ends in a suffix the
  engine may change (.svg .vl.json .vl .scad .vsdx .pptx .pdf .mmd .mermaid).
  --write-shim fills both lists into the embedded template from
  PictureAttributes.BlockClasses and PictureSuffixes, so the shim cannot drift
  from the tool; docs/filters/canvasnet.lua is regenerated.
- The shim treats a pandoc.pipe error as a process failure only when it is a
  table with a numeric error_code, reads its fields in protected mode, and
  reports every other error as "cannot run the canvasnet tool" with tostring.
- A size-limit error of a size that follows the natural size names the scale
  that fits; the Pandoc filter names the block's or picture's scale attribute.
- Tests: engine pass-through of pictures it does not draw, the registry, the
  generated shim, FitScale, the filter's size hint (stub and real drawer), and
  test-canvasnet.ps1 checks for the fast path and stubbed pandoc.pipe errors.
- Requirements, design, verification, user guide, help card, and SysML model
  updated; the shim should be written again after updating the tool.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings November 17, 2026 19:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active issues remain, including an incorrect two-significant-digit rounding implementation, a nondeterministic wall-clock regex timeout in a test, and an incomplete XML documentation sentence.

3 open issues
What changed in this PR

This PR improves the Pandoc filter shim and rendering diagnostics by generating fast-path registries from the engine, hardening launch-failure handling, and providing actionable scale hints for oversized images.

Changes:

  • Generate Lua class and suffix tables from shared engine registries.
  • Normalize tool-launch and malformed-output failures into clear shim errors.
  • Add fit-scale metadata, Pandoc hints, tests, and synchronized documentation.
File Description
test/​DemaConsulting.CanvasNet.Viewer.Tests/​Imaging/​SourceLoaderTests.cs Tests fit-scale hints, exception metadata, and rounding behavior.
test/​DemaConsulting.CanvasNet.Tool.Tests/​PandocFilter/​PictureAttributesTests.cs Verifies shared picture suffix and block-class registries.
test/​DemaConsulting.CanvasNet.Tool.Tests/​PandocFilter/​PandocFilterSubsystemTests.cs Tests oversized Mermaid scale guidance.
test/​DemaConsulting.CanvasNet.Tool.Tests/​PandocFilter/​PandocFilterShimTests.cs Tests shim template generation and generated fast-path contents.
test/​DemaConsulting.CanvasNet.Tool.Tests/​PandocFilter/​PandocFilterEngineTests.cs Tests pass-through behavior and scale-attribute hints.
src/​DemaConsulting.CanvasNet.Viewer/​Imaging/​SourceLoader.cs Adds fit-scale calculation and size-limit exception metadata.
src/​DemaConsulting.CanvasNet.Tool/​PandocFilter/​PictureAttributes.cs Defines shared picture suffix and block-class registries.
src/​DemaConsulting.CanvasNet.Tool/​PandocFilter/​PandocFilterShim.cs Generates the Lua shim from its template and engine registries.
src/​DemaConsulting.CanvasNet.Tool/​PandocFilter/​PandocFilterEngine.Drawing.cs Converts fit-scale metadata into Pandoc attribute hints.
src/​DemaConsulting.CanvasNet.Tool/​PandocFilter/​PandocFilterEngine.cs Uses shared block classification and tracks block jobs.
src/​DemaConsulting.CanvasNet.Tool/​PandocFilter/​canvasnet.lua Implements generated fast-path checks and protected launch-failure handling.
src/​DemaConsulting.CanvasNet.Tool/​DemaConsulting.CanvasNet.Tool.csproj Documents the embedded Lua file as a generated template.
src/​DemaConsulting.CanvasNet.Tool/​Commands/​PandocFilterCommand.cs Updates command guidance for regenerating the shim.
src/​DemaConsulting.CanvasNet.Tool/​Commands/​Help/​pandoc.md Documents fast-path behavior and size-limit hints.
docs/​verification/​canvas-net-viewer/​imaging/​source-loader.md Records fit-scale verification scenarios.
docs/​verification/​canvas-net-tool/​pandoc-filter/​picture-attributes.md Records registry verification coverage.
docs/​verification/​canvas-net-tool/​pandoc-filter/​pandoc-filter-shim.md Records generated-shim and launch-failure verification.
docs/​verification/​canvas-net-tool/​pandoc-filter/​pandoc-filter-engine.md Records pass-through and scale-hint verification.
docs/​verification/​canvas-net-tool/​pandoc-filter.md Records oversized Mermaid integration verification.
docs/​user_guide/​canvas-net-tool.md Updates user-facing shim and size-limit guidance.
docs/​sysml2/​model/​canvas-net-tool/​pandoc-filter/​picture-attributes.sysml Updates the model for shared registries.
docs/​sysml2/​model/​canvas-net-tool/​pandoc-filter/​pandoc-filter-shim.sysml Updates the model for generated shims and failure handling.
docs/​reqstream/​canvas-net-viewer/​imaging/​source-loader.yaml Adds fit-scale requirements and test traceability.
docs/​reqstream/​canvas-net-tool/​pandoc-filter/​picture-attributes.yaml Adds registry requirements.
docs/​reqstream/​canvas-net-tool/​pandoc-filter/​pandoc-filter-shim.yaml Adds generated fast-path requirements.
docs/​reqstream/​canvas-net-tool/​pandoc-filter/​pandoc-filter-engine.yaml Adds oversized-picture and pass-through requirements.
docs/​reqstream/​canvas-net-tool/​pandoc-filter.yaml Integrates the updated Pandoc filter requirements.
docs/​filters/​test-canvasnet.ps1 Expands end-to-end coverage for fast paths and launch failures.
docs/​filters/​canvasnet.lua Stores the regenerated repository Lua shim.
docs/​design/​canvas-net-viewer/​imaging/​source-loader.md Documents fit-scale calculation and exception metadata.
docs/​design/​canvas-net-tool/​pandoc-filter/​picture-attributes.md Documents shared suffix and block-class registries.
docs/​design/​canvas-net-tool/​pandoc-filter/​pandoc-filter-shim.md Documents template generation and failure handling.
docs/​design/​canvas-net-tool/​pandoc-filter/​pandoc-filter-engine.md Documents block classification and scale-specific hints.
docs/​design/​canvas-net-tool/​pandoc-filter.md Updates the filter fast-path design documentation.
docs/​design/​canvas-net-tool/​commands/​pandoc-filter-command.md Documents writing the generated shim.

Review effort: Lite

…o regex timeout in test, doc grammar

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings November 17, 2026 20:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Defer approval because the change spans generated Lua, Pandoc execution, in-process rendering, and Viewer exception propagation, requiring human and runtime validation of embedded-image failures and Pandoc integration.

No open issues 🎉

3 resolved since last review

Review effort: Lite

Copilot AI lite review requested due to automatic review settings November 17, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The change spans generated Lua, Pandoc’s pipe/error ABI, the tool engine, and Viewer exception metadata, requiring maintainer verification of real Pandoc behavior and the claimed end-to-end run after the mixed sizing-option hint correction.

No open issues 🎉

Review effort: Lite

@Malcolmnixon
Malcolmnixon merged commit 16a2a56 into main Nov 17, 2026
13 checks passed
@Malcolmnixon
Malcolmnixon deleted the fix/shim-fast-path branch November 17, 2026 23:53
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.

2 participants