Skip to content

Write parser output only after successful generation - #807

Open
ydah wants to merge 1 commit into
masterfrom
fix/avoid-invalid-parser-output
Open

Write parser output only after successful generation#807
ydah wants to merge 1 commit into
masterfrom
fix/avoid-invalid-parser-output

Conversation

@ydah

@ydah ydah commented Sep 6, 2026

Copy link
Copy Markdown
Member

Command rendered the parser output before validating the computed states. When %expect did not match the actual conflict count, Lrama exited with status 1 only after writing a complete output file, allowing build tools to treat an unvalidated parser as up to date.

Validate the states before rendering the parser output. Render into an in-memory buffer and write the target file only after rendering completes, preserving an existing output file when rendering raises an exception.

Add command-level regression coverage for %expect mismatches producing no parser output and rendering failures preserving existing output.

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.

🟢 Approval recommended

The change directly addresses the reported failure mode and includes targeted regression tests that cover both %expect mismatches and render exceptions without introducing obvious behavioral regressions.

Pull request overview

This pull request ensures Lrama only writes the generated parser output file after the computed states have been successfully validated, preventing build tools from treating an invalidated parser as up to date. It also adds regression coverage to confirm that %expect mismatches and rendering failures do not clobber parser outputs.

Changes:

  • Reorders the command workflow to validate computed states before rendering/writing the parser output.
  • Buffers rendered parser output in-memory and writes the output file only after rendering completes successfully.
  • Adds command-level specs covering %expect mismatch behavior (no output file created) and render exceptions preserving existing output.
File summaries
File Description
spec/lrama/command_spec.rb Adds regression tests ensuring no output is written on %expect mismatch and existing output is preserved on render failure.
lib/lrama/command.rb Validates states before rendering and buffers output in StringIO before writing to the target file.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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