Add renderOperation helper and migrate mkdir/restore dry-run#350
Merged
Conversation
Add cross-command dry-run contract tests
Introduce renderOperation, a shared helper that renders a command's operation output (text closure plus the standard JSON operation envelope) so dry-run branches no longer duplicate the commandOutput/newJSONCommandOperationOutput glue. Migrate the two simplest dry-run commands, mkdir and restore, onto it. Output is unchanged; the existing byte-exact dry-run snapshots and the cross-command contract tests both continue to pass.
This was referenced Jul 10, 2026
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.
Summary
Second PR in the dry-run generalization series. Introduces
renderOperation, a shared helper that renders a command's operation output — the text closure plus the standard JSON operation envelope — so dry-run branches stop duplicating thecommandOutput(cmd).Render(..., newJSONCommandOperationOutput(cmd, ...))glue.Migrates the two simplest dry-run commands, mkdir and restore, onto it. These are single planned operations with no discovery or both-modes path, so they validate the helper before it touches more complex commands.
Changes
cmd/dry_run.go— addrenderOperation(cmd, input, results, warnings, textFn).cmd/mkdir.go— dry-run branch callsrenderOperation.cmd/restore.go— dry-run branch callsrenderOperation.Behavior
Unchanged. The text closure that was already passed to
.Renderis passed torenderOperationverbatim. The existing byte-exact dry-run snapshots (TestMkdirJSONDryRunOutputSnapshot,TestMkdirDryRunTextOutputSnapshot, restore's JSON dry-run test) and the cross-command contract tests all continue to pass.Testing
go build ./...cleango vet ./cmd/cleango test ./cmd/green (-count=1)Notes
Text stays a per-command closure by design — restore's
Would restore <path> to revision <rev>and later put/revoke output cannot be modeled by a shared struct.renderOperationowns only the envelope. Later PRs migrate share-link create/update, rm + share-link revoke, cp/mv, and put onto the same helper.