fix: map guest paths on document payloads and diagnostics - #281
Merged
Conversation
_rewrite_guest_paths mapped meta.filename and the include list, but a
document directive has a second, independent path - the file it points
at - and that one was never mapped. For entries produced by discovery
the rewriter was a complete no-op, because they are synthesized and
carry no source location at all (meta.filename is <unknown>), so the
only real path on them is the one being skipped.
Every auto-discovered document was therefore unreachable:
- statement_path resolves a transaction's document: value to an
absolute host path and looks for a Document whose filename equals
it. A /work/... filename can never match, so /statement/ always
raised StatementNotFoundError.
- /document/ is gated on the same values, and send_file was handed a
path with no host file behind it.
Hand-written document directives were unaffected, since rledger stores
directive filenames verbatim and they never transit the sandbox. That is
what isolated the failure to discovery and hid it.
Guest paths embedded in diagnostic messages are mapped too. They are
surfaced in the UI, and they are substrings rather than whole fields, so
the mount prefix is relocated rather than the path parsed out - a
document filename may contain spaces, so there is no reliable way to
find where one ends.
The wire key is path, not filename; filename is the attribute name on
the typed Document. Gated on the directive type even though path is
unique to document-dir among output directives today, so a future
directive that gains a path meaning something other than a host file is
not silently rewritten.
Two tests, one on the raw shapes and one end-to-end through a real
component, both sabotage-checked: dropping the payload rewrite fails
both, dropping the message rewrite fails the message assertion, and
removing the type gate fails the non-document case.
Closes #277.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018bGRsKA42peqSnz4VMreBG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #277.
The bug
_rewrite_guest_pathsmappedmeta.filenameand the include list. But adocumentdirective has a second, independent path — the file it points at — and that one was never mapped.For entries produced by discovery the rewriter was a complete no-op: they are synthesized, so they carry no source location at all (
meta.filenameis<unknown>), and the only real path on them is exactly the one being skipped.Every auto-discovered document was therefore unreachable:
statement_pathresolves a transaction'sdocument:value to an absolute host path, then looks for aDocumentwhose filename equals it. A/work/…filename can never match, so/statement/always raisedStatementNotFoundError./document/is gated on the same values, andsend_filewas handed a path with no host file behind it.Hand-written
documentdirectives were unaffected — rledger stores directive filenames verbatim and they never transit the sandbox. That's what isolated the failure to discovery, and what hid it.Reported on Windows; I reproduced it on Linux, so nothing about it is platform-specific.
Fix
Rewrite the document payload path, and guest paths embedded in diagnostic messages (surfaced in the UI):
Two details worth flagging:
path, notfilename.filenameis the attribute name on the typedDocument; the raw result dict usespath. The issue said "payloadfilename", which is right about the object and wrong about the key.Gated on the directive type even though
pathis unique todocument-diramong output directives today, so a future directive that gains apathmeaning something other than a host file isn't silently rewritten.Tests
Two tests — one on the raw shapes, one end-to-end through a real component asserting the mapped path actually exists on disk.
Sabotage-checked, each failure direction landing on a distinct assertion:
pathcase onlyFull suite against the pinned
v0.21.0asset: 669 passed, 1 skipped (667 before, +2 new).🤖 Generated with Claude Code
https://claude.ai/code/session_018bGRsKA42peqSnz4VMreBG