dryrun

package
v0.37.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dryrun is the shared mechanism behind `--dry-run` on every `specscore <kind> change-status` verb (see spec/features/cli/lifecycle-transitions/README.md#req-dry-run-mode).

The per-kind ChangeStatus orchestrators (pkg/feature, pkg/idea, pkg/plan, pkg/lesson, pkg/issue, pkg/sidekick) are NOT unified behind one function — each kind has its own artifact layout and Options shape. What IS shared is how a preview is produced: Sandbox copies the project's spec/ subtree into a throwaway temporary directory, lets the caller run the EXACT SAME mutation code it would run for real — just pointed at the copy — and diffs the result. Because dry-run and the real path share the identical mutation function, the reported file list cannot drift from what a subsequent real run actually touches; it is not a separate, hand-maintained prediction of what "should" happen.

The real project root is never opened for writing by this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintReport

func PrintReport(w io.Writer, id, from, to string, changes []Change)

PrintReport writes the standard dry-run report to w: a first line shaped like the real success line ("<id>: <from> → <to>"), annotated with a dry-run marker and the changed-file count, followed by one indented git-status-style line per Change (" M spec/ideas/foo.md"), in Changes' existing (path-sorted) order.

Types

type Change

type Change struct {
	Kind ChangeKind
	Path string
}

Change names one file a mutation would create, modify, or delete. Path is relative to the project root (it carries the leading "spec/" segment), so it can be handed directly to `git diff <path>` or `git add <path>`.

func Sandbox

func Sandbox[T any](root string, mutate func(sandboxRoot string) (T, error)) (T, []Change, error)

Sandbox copies the "spec" subdirectory of root into a temporary directory, invokes mutate with that temporary directory's path standing in for root, computes the file-level Changes mutate made (diffing the temporary spec/ tree against root's spec/ tree AFTER mutate returns), and removes the temporary directory before returning. root — and everything under it — is NEVER written to; mutate MUST perform all of its I/O by deriving paths from the sandboxRoot argument it receives, exactly as the real (non-dry- run) call site derives them from root.

If mutate returns an error, Sandbox returns that error with any occurrence of the sandbox's temporary path rewritten back to root, so the message reads identically to what a real, non-sandboxed invocation would have printed — a caller comparing dry-run output to real output (or a script testing transition legality via --dry-run) sees no sandbox artifact leak through. The error's exit code (via an ExitCode() int method, e.g. *pkg/exitcode.Error) is preserved.

func (Change) String

func (c Change) String() string

String renders a Change the way PrintReport does: "<kind> <path>".

type ChangeKind

type ChangeKind string

ChangeKind classifies how a file differs between the pre-mutation and post-mutation snapshot of the spec tree, mirroring `git status --short`'s single-letter vocabulary.

const (
	// Modified means the file exists on both sides with different content.
	Modified ChangeKind = "M"
	// Added means the file exists only in the post-mutation snapshot.
	Added ChangeKind = "A"
	// Removed means the file exists only in the pre-mutation snapshot.
	Removed ChangeKind = "D"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL