PowerShell / Advanced: remote boundaries, security, desired state, and reliability / Lesson 21
Guard automation effects with ShouldProcess
Place a controlled mutation behind ShouldProcess and verify preview, execution, and ownership boundaries.
On this page
Lesson goals
- Identify the mutation and its target.
- Place the effect inside the ShouldProcess branch.
- Test preview and actual behavior with an isolated fixture.
- Place synthetic mutations behind explicit ShouldProcess decisions.
- Test preview, denial and normal state changes while keeping authorization and recovery separate.
Define the effect
Automation should make its intended target and effect visible before changing state. SupportsShouldProcess exposes standard preview and confirmation behavior to callers, but it does not by itself authorize an action or perform validation. The example changes only a script-scoped demonstration variable. A real administrative command needs a validated target, appropriate privileges, and a clear recovery policy before it modifies external resources.
Guard the actual mutation
The function declares SupportsShouldProcess and places its assignment inside the conditional result of $PSCmdlet.ShouldProcess. The target and action strings describe the intended change. Initializing DemoState outside the function creates the isolated fixture; it is not the effect being previewed. In a real command, any preparation that itself changes external state also requires an explicit policy and must not be hidden before the guard.
function Set-DemoState {
[CmdletBinding(SupportsShouldProcess)]
param([Parameter(Mandatory)][string]$Value)
if ($PSCmdlet.ShouldProcess("demo state", "Set value")) {
$script:DemoState = $Value
}
}
$script:DemoState = "original"
ShouldProcess encloses the only mutation performed by the function.
Compare preview and execution
Run the second block after the first in the same session. WhatIf requests a preview, so the guarded assignment should not run and the demonstration value should remain original. The following invocation disables confirmation for this isolated fixture and performs the assignment. The displayed value should then be changed. Exact preview text may vary by host; test the state and documented behavior rather than matching a full localized message.
Set-DemoState -Value "changed" -WhatIf
"State after preview: $script:DemoState"
Set-DemoState -Value "changed" -Confirm:$false
"State after action: $script:DemoState"
WhatIf skips the guarded assignment; the second call applies it to the isolated variable.
Keep validation and authorization separate
Check parameter values and the intended target before invoking a real effect, and enforce authorization at the system that owns the resource. WhatIf is an aid to understanding intended changes, not a transaction or a guarantee that the subsequent operation will succeed. For multi-step changes define partial-failure handling and rollback or recovery; a guarded first step does not automatically protect every later mutation.
Verify the whole contract
In an isolated test session initialize the fixture, invoke WhatIf, and assert that state remains unchanged. Invoke the action with confirmation handled by the test and assert the intended change. Test invalid input, a denied target, and an injected failure; verify the error reaches the caller and unrelated state remains untouched. For a real provider test, use an owned temporary resource and record edition and platform assumptions.
Name the exact mutation and owner
Before adding a preview switch, identify the exact state the operation may change and the component responsible for it. A function that updates an item may also create a file, write a log, call a helper or send a request; each of those actions has its own effect boundary. State the target, intended action, preconditions, expected outcome and recovery owner. Input validation can reject an invalid target before any change is proposed, but a valid target does not itself authorize the caller. Decide whether a declined operation returns a skipped status, no output or another documented result, and distinguish it from successful mutation. The examples use an in-memory variable as a synthetic state so the actual gate can be studied without touching files, services or accounts.
Guard the actual state change
An advanced function declares CmdletBinding with SupportsShouldProcess and calls $PSCmdlet.ShouldProcess with a target and action. The Boolean result controls whether the code inside the branch runs. The walkthrough resets a synthetic state to original, calls the function with WhatIf, then reads the state; the guarded assignment is skipped. Its second call disables the confirmation prompt for this harmless fixture and performs the assignment, demonstrating the normal path separately. A preview message alone is not the assertion: inspect the state itself and record both paths. Set meaningful target and action strings so a human can understand the proposed effect. Do not put the mutation before the gate or treat the switch as automatically protecting other statements. The bounded fixture has no external effects and is qualified only in the stated runtime.
$script:labState = 'original'
function Set-LabState {
[CmdletBinding(SupportsShouldProcess)]
param([string]$Target)
if ($PSCmdlet.ShouldProcess($Target, 'Set synthetic state')) { $script:labState = 'changed' }
}
Set-LabState -Target 'item-1' -WhatIf
$script:labState
Set-LabState -Target 'item-1' -Confirm:$false
$script:labState
What if: Performing the operation "Set synthetic state" on target "item-1".
original
changed
The exact in-memory block ran in isolated PowerShell 7.6.0: preview left original and the normal call changed the synthetic state.
Trace helpers and multiple targets
A function may call nested commands that have their own preview semantics. Review the entire call graph: a helper that writes before the parent gate or ignores a preview request can still perform an effect. Place each effect behind an appropriate decision and test a recording adapter in an isolated fixture. For a batch, associate each approval or denial with the exact target and preserve per-item outcomes; approving A must not silently authorize B. If a helper supports its own ShouldProcess contract, understand how the relevant preference and parameters are passed rather than assuming protection. Even diagnostic logging can be an effect if it writes a file or sends data. Test that the preview and declined paths cause zero unintended adapter calls, and separately test the ordinary path so a function that never performs its job cannot pass.
Separate preview, authorization and recovery
WhatIf is not a sandbox, an authorization system, or a transaction. It previews only effects implemented to honor the contract. A real operation may later fail because the target changed, permission was revoked, a network call timed out or a resource became unavailable. If a state-changing request was sent before a timeout, reconcile its documented operation identity before retrying; the absence of a response does not prove rollback. Capture the original failure and any cleanup failure separately, then verify the required postcondition and application health. Confirmation decisions are influenced by ConfirmImpact and caller preferences, so automation needs an explicit reviewed noninteractive policy. Never infer that suppressing a prompt grants authorization. A test fixture should avoid host or production mutations and report the exact path it exercised.
Test state, not only messages
A complete regression covers valid input with WhatIf, normal approved execution, a declined decision, invalid input, and any effectful helper. Check the state or adapter call count before and after each path; a displayed preview can be correct while an unguarded effect already happened. For multiple targets verify each identity and outcome, and preserve failure and cleanup evidence rather than collapsing the batch to one success flag. Keep synthetic tests independent and reset their state between cases. A local PowerShell test can establish the observed behavior of its exact function and runtime, but cannot prove that a real endpoint is authorized, available, or correctly rolled back. A later integration test needs a disposable approved target and separately reviewed effect and recovery plans.
20 worked examples
1. Preview a guarded assignment
Problem: A WhatIf call should leave the synthetic state unchanged.
- The ShouldProcess call describes the proposed Set action for A.
- WhatIf returns false to the branch, leaving state old.
$script:state='old'; function Set-Lab { [CmdletBinding(SupportsShouldProcess)] param() if ($PSCmdlet.ShouldProcess('A','Set')) { $script:state='new' } }; Set-Lab -WhatIf; $script:state
What if: Performing the operation "Set" on target "A".
old
The actual assignment is inside the guarded branch. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Expected result: WhatIf message then old.
Why this result follows: The actual assignment is inside the guarded branch.
2. Apply a guarded assignment
Problem: An approved synthetic call should update the in-memory state.
- The ordinary call permits the harmless synthetic action.
- The guarded assignment sets the state to new.
$script:state='old'; function Set-Lab { [CmdletBinding(SupportsShouldProcess)] param() if ($PSCmdlet.ShouldProcess('A','Set')) { $script:state='new' } }; Set-Lab -Confirm:$false; $script:state
new
The normal path demonstrates the function is not permanently disabled. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: The normal path demonstrates the function is not permanently disabled.
3. Identify target and action
Problem: A plan identifies an update to item B.
- The target field is B and the action field is Update.
- Both labels can be supplied to an operator before an effect.
$plan = @{ Target='B'; Action='Update' }; $plan.Target; $plan.Action
B
Update
Specific labels make the proposed operation understandable. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Expected result: B then Update
Why this result follows: Specific labels make the proposed operation understandable.
4. Skip a declined target
Problem: A synthetic decision denies an update to item C.
- The approval flag is false for this fixture.
- The guarded update is skipped, leaving unchanged.
$approved=$false; $state='unchanged'; if ($approved) { $state='changed' }; $state
unchanged
A declined decision must not trigger the protected mutation. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: A declined decision must not trigger the protected mutation.
5. Reject an empty target
Problem: An empty target fails validation before a preview gate.
- The empty string fails the nonblank target rule.
- The synthetic effect counter remains zero.
$target=''; $calls=0; if ([string]::IsNullOrWhiteSpace($target)) { 'invalid' } else { $calls++ }; $calls
invalid
0
Validation is distinct from approval and precedes the effect. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Expected result: invalid then 0
Why this result follows: Validation is distinct from approval and precedes the effect.
6. Track two target decisions
Problem: A is approved and B is denied under a batch policy.
- The approved flag is true only for A.
- The selected target list therefore contains A alone.
$decisions = @(@{Target='A'; Approved=$true}, @{Target='B'; Approved=$false}); @($decisions | Where-Object Approved).Target -join ','
A
Each target retains its own decision rather than inheriting another’s approval. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: Each target retains its own decision rather than inheriting another’s approval.
7. Detect an early helper effect
Problem: A helper increments a counter before approval is denied.
- The first increment is outside the later approval branch.
- Denying the branch leaves one already-performed synthetic effect.
$effects=0; $effects++; $approved=$false; if ($approved) { $effects++ }; $effects
1
A later gate cannot undo an earlier unguarded operation. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: A later gate cannot undo an earlier unguarded operation.
8. Guard a helper call
Problem: A synthetic helper is called only after approval.
- The false decision skips the helper branch.
- The recorded call count remains zero.
$calls=0; $approved=$false; if ($approved) { $calls++ }; $calls
0
The effectful helper must be included in the protected path. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: The effectful helper must be included in the protected path.
9. Preserve a no-op
Problem: The desired value is already present before a change.
- The current and desired values match.
- The fixture reports unchanged without invoking an effect.
$current='ready'; $desired='ready'; if ($current -eq $desired) { 'unchanged' }
unchanged
A successful no-op is distinct from both mutation and failure. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: A successful no-op is distinct from both mutation and failure.
10. Use explicit confirmation policy
Problem: A harmless synthetic call disables confirmation and modifies memory.
- Confirm false avoids an interactive prompt for this synthetic operation.
- The permitted branch increments the counter once.
$script:count=0; function Add-Lab { [CmdletBinding(SupportsShouldProcess)] param() if ($PSCmdlet.ShouldProcess('fixture','Increment')) { $script:count++ } }; Add-Lab -Confirm:$false; $script:count
1
A noninteractive confirmation choice is separate from authorization. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: A noninteractive confirmation choice is separate from authorization.
11. Count guarded effects
Problem: Two approved synthetic actions increment a counter.
- The first and third decisions are true while the second is false.
- Only approved branches increment the counter, yielding two.
$decisions = @($true,$false,$true); $count=0; foreach ($ok in $decisions) { if ($ok) { $count++ } }; $count
2
An effect count can verify per-item decisions in a controlled fixture. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: An effect count can verify per-item decisions in a controlled fixture.
12. Check existing state before mutation
Problem: A record already has version 4 and requires version 4.
- The current version equals the desired version.
- The operation can report no change under the declared contract.
$record = @{ Version=4 }; $desired=4; if ($record.Version -eq $desired) { 'no change' }
no change
A no-op avoids an unnecessary effect when state already matches. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: A no-op avoids an unnecessary effect when state already matches.
13. Reject before the effect
Problem: A synthetic validation error occurs before the mutation branch.
- The validation flag is false.
- The effect branch is not entered and the counter remains zero.
$valid=$false; $effect=0; if (-not $valid) { 'rejected' } else { $effect++ }; $effect
rejected
0
Invalid input should not reach the protected operation. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Expected result: rejected then 0
Why this result follows: Invalid input should not reach the protected operation.
14. Observe an approved state change
Problem: A synthetic update changes a value after the decision.
- The fixture approves the change.
- The guarded assignment changes the value from 2 to 5.
$approved=$true; $value=2; if ($approved) { $value=5 }; $value
5
Inspecting state verifies the effect rather than only the decision message. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: Inspecting state verifies the effect rather than only the decision message.
15. Report a partial batch
Problem: One target changed while another failed.
- A is marked changed while B is marked failed.
- The failed-target query returns B.
$results = @(@{Target='A'; State='changed'}, @{Target='B'; State='failed'}); @($results | Where-Object State -eq 'failed')[0].Target
B
A batch needs per-target outcomes rather than one assumed success. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: A batch needs per-target outcomes rather than one assumed success.
16. Treat logging as an effect
Problem: A log adapter call is skipped when a preview decision denies effects.
- The fixture is in preview mode.
- The simulated logging call is not made and the count remains zero.
$preview=$true; $logCalls=0; if (-not $preview) { $logCalls++ }; $logCalls
0
Writing diagnostics can be an effect that also needs an explicit policy. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: Writing diagnostics can be an effect that also needs an explicit policy.
17. Require target authorization
Problem: A syntactically valid target is not authorized.
- The target passes validation but fails authorization.
- The combined decision is false.
$request = @{ Valid=$true; Authorized=$false }; $request.Valid -and $request.Authorized
False
A valid target name is not permission to change it. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: A valid target name is not permission to change it.
18. Preview cannot ensure success
Problem: A preview succeeds but the later target is unavailable.
- The preview flag is true, while target availability is false.
- The combined readiness condition therefore fails.
$result = @{ PreviewSucceeded=$true; TargetAvailable=$false }; $result.PreviewSucceeded -and $result.TargetAvailable
False
A preview does not prove later connectivity or authorization. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: A preview does not prove later connectivity or authorization.
19. Reconcile cancelled work
Problem: A remote effect is cancelled locally after submission.
- The fixture records cancellation but no confirmed remote state.
- The decision requests reconciliation before assuming the effect was undone.
$operation = @{ Cancelled=$true; State='unknown' }; if ($operation.State -eq 'unknown') { 'reconcile' }
reconcile
Local cancellation is not proof of remote rollback. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: Local cancellation is not proof of remote rollback.
20. Verify final state
Problem: A change is reported but the observed value remains old.
- The observed value old differs from the expected value new.
- The postcondition check is false despite the reported change.
$result = @{ Reported='changed'; Observed='old'; Expected='new' }; $result.Observed -eq $result.Expected
False
State verification detects a result that a message alone would miss. Qualified in isolated PowerShell 7.6.0 using synthetic in-memory state only.
Why this result follows: State verification detects a result that a message alone would miss.
Common errors and fixes
WhatIf still changes a resource
- Why it happens
- The mutation occurs outside the ShouldProcess branch.
- How to fix it
- Move every relevant effect behind the appropriate guard.
- Prevent it next time
- Test preview against an owned fixture and assert unchanged state.
A preview is mistaken for authorization
- Why it happens
- ShouldProcess was treated as a permission check.
- How to fix it
- Validate the target and rely on the owning system’s authorization controls.
- Prevent it next time
- Test a denied operation separately from preview.
A multi-step action leaves partial state
- Why it happens
- Only one step was guarded or failure recovery was undefined.
- How to fix it
- Guard each effect and define recovery for partial failure.
- Prevent it next time
- Inject a failure between steps and verify the recovery contract.
20 practice exercises
1. What should DemoState contain after WhatIf?
Show hint
Inspect the variable itself after the preview call.
Show worked solution
It should remain original because ShouldProcess returns without approving the guarded assignment during the preview. Verify the variable itself rather than relying only on the preview text.
The original example should leave DemoState equal to original because WhatIf makes the guarded ShouldProcess branch skip the assignment. Assert the variable value and, when helpers exist, the absence of their effects; a preview message alone is insufficient.
Check your solution
- DemoState remains original after WhatIf.
- The guarded assignment is not performed.
2. Does a successful preview ensure a real operation succeeds?
Show hint
Compare preview conditions with the later real execution environment.
Show worked solution
No. Authorization, resource state, connectivity, and other conditions can differ during execution. Handle real errors and define recovery independently of preview.
A successful preview does not establish that a later operation will succeed: authorization, connectivity and resource state can change. Handle real errors and verify postconditions and recovery independently rather than treating preview as a transaction or guarantee.
Check your solution
- Real authorization and resource state are checked.
- Failure and recovery remain separate from preview.
3. A function has ConfirmImpact Medium and the caller’s confirmation preference is High. Explain the default prompting decision.
Show hint
Compare the impact and preference thresholds.
Show worked solution
Under the stated values, Medium is below High, so the default threshold does not request confirmation solely from impact. An explicit Confirm request can change prompting; neither choice grants target authorization.
Check your solution
- Medium is below the High threshold.
- Authorization remains a separate check.
4. A function previews a batch of two resources, but only one proposal is displayed. Design a coverage test.
Show hint
The preview must account for every intended target.
Show worked solution
Capture the proposed target and action for both synthetic resources and compare them with the expected batch before any effect. Fail if either proposal is missing, and separately assert that the preview performs no mutation.
Check your solution
- Both expected targets have proposals.
- Preview performs no mutation.
5. A function passes preview tests by never changing state. Add a normal-path regression.
Show hint
A correct gate must also permit an approved effect.
Show worked solution
Use a fresh synthetic state, invoke the function normally with an explicit noninteractive confirmation policy, and assert the expected state change occurs exactly once. Retain the separate WhatIf zero-effect test.
Check your solution
- The normal path changes the state once.
- The preview path remains effect-free.
6. A function’s helper can alter two separate resources. Design effect ownership and preview checks for both.
Show hint
Each resource needs its own guard and evidence.
Show worked solution
Identify the owner, target and approval policy for each helper effect, and use recording doubles to assert neither runs under preview. Test an approved normal call to ensure only the documented effects occur.
Check your solution
- Both helper effects have explicit owners.
- Preview records zero calls to either adapter.
7. A batch is atomic only when all targets are approved. Define a preflight policy for three targets.
Show hint
Collect all decisions before making any mutation.
Show worked solution
Gather decisions for A, B and C first; if any is denied, report the denial and perform zero mutations. If all are approved, execute under the documented batch contract and verify each result.
Check your solution
- Any denial blocks the whole atomic batch.
- A fully approved batch verifies each result.
8. A confirmation is requested for a high-impact synthetic change in a noninteractive job. Define a safe execution policy.
Show hint
Avoid unexpected prompting and obtain approval outside the runtime interaction.
Show worked solution
Require an explicit reviewed automation policy and authorized target, then test the selected noninteractive behavior with a harmless fixture. If approval is unavailable, report a blocked operation rather than waiting indefinitely or assuming consent.
Check your solution
- The automation policy is explicit and reviewed.
- Missing approval blocks the operation.
9. A target name is blank and another points outside the approved scope. Define validation and authorization checks.
Show hint
Syntax and authorization answer different questions.
Show worked solution
Reject the blank name as invalid before proposing a change, and deny the well-formed but out-of-scope target through the authorization policy. Assert no effect for either and report their distinct reasons.
Check your solution
- The blank target fails validation.
- The out-of-scope target fails authorization.
10. Two targets have the same display name but different IDs. Design a preview that cannot confuse them.
Show hint
A target label should identify the actual resource.
Show worked solution
Include each stable non-secret ID and the intended action in the preview, and assert the two proposals remain distinct. Confirm target authorization independently rather than assuming a clear label grants access.
Check your solution
- Each proposal includes a distinct stable ID.
- The action is visible and authorization remains separate.
11. A desired-state comparison finds the item already correct, but its health probe fails. Define the no-op acceptance decision.
Show hint
State equality and application health are distinct.
Show worked solution
Do not mutate solely because the desired value matches, but hold overall acceptance until the required health failure is investigated. Report unchanged state and failed health as separate outcomes; a no-op is not proof of health.
Check your solution
- The matching value does not cause an update.
- Failed health prevents overall acceptance.
12. A batch updates A and B successfully, then the final health check fails. Define the recovery evidence.
Show hint
A failed postcondition can follow multiple successful effects.
Show worked solution
Retain both target identities and update outcomes, record the failed health check, and apply the documented rollback or forward-recovery plan. Verify all required postconditions before reporting recovery complete.
Check your solution
- Both successful changes remain identifiable.
- Recovery is not complete until postconditions pass.
13. A protected command is declined but emits a separate diagnostic. Define success-stream and diagnostic assertions.
Show hint
The denial status and diagnostic channel have different contracts.
Show worked solution
Assert no mutation and a documented skipped success result if the function promises one, while capturing the denial diagnostic separately. Ensure the diagnostic does not masquerade as a changed record or leak secrets.
Check your solution
- The promised skipped result is correctly typed.
- The diagnostic is separate and sanitized.
14. A preview must produce a local explanation without sending telemetry. Design channel and effect tests.
Show hint
A message can be visible without an external logging call.
Show worked solution
Capture the in-memory preview message and assert it identifies the action, while a recording telemetry adapter receives zero calls. Separately test an approved normal operation under the documented telemetry policy.
Check your solution
- The local preview message identifies the action.
- The external telemetry adapter receives no preview call.
15. A protected command changes state successfully, but its success output contains an extra helper value. Define an output regression.
Show hint
Effect correctness and success-stream cleanliness are separate.
Show worked solution
Capture the entire success stream after the harmless approved fixture, assert the intended state change and exactly one documented result, and detect the extra helper value. Consume the helper output explicitly if it is not part of the contract.
Check your solution
- The state changes as intended.
- No extra helper value appears in success output.
16. A change is approved but the adapter throws before confirming completion. Define the result.
Show hint
Approval and successful completion are different events.
Show worked solution
Preserve the adapter error and operation identity, report failure or uncertainty according to the effect contract, and inspect state before recovery. Approval alone must not be returned as a successful change.
Check your solution
- The adapter error remains visible.
- Approval is not reported as completion.
17. A guarded command needs a stable audit record linking an approved change to its target and final verification. Define its fields.
Show hint
Decision, effect and postcondition are separate events.
Show worked solution
Record a non-secret operation ID, target identity, approval decision, effect outcome and postcondition status, with sanitized failure context when needed. Verify each field refers to the same operation without logging credentials or full private payloads.
Check your solution
- The audit links approval, effect and verification.
- Credentials and private payloads are excluded.
18. A caller is allowed to preview but lacks permission to modify the target. Define the real execution decision.
Show hint
Preview and authorization are independent.
Show worked solution
Allow only the preview if policy permits it, and deny the real mutation because target authorization is absent. Record the denial without secrets; suppressing a confirmation prompt cannot grant missing permissions.
Check your solution
- The preview does not imply write permission.
- The real mutation is denied.
19. A guarded operation fails and cleanup also fails. Define what the caller must receive.
Show hint
The original and cleanup failures have distinct causes.
Show worked solution
Preserve the operation error as primary and attach or report the cleanup failure separately, including the owned resource identity. Do not claim that the preview gate or catch block rolled back a committed effect.
Check your solution
- Both errors remain observable.
- Cleanup completion is not falsely claimed.
20. Define an acceptance plan for a guarded command before an authorized integration rollout.
Show hint
Test validation, preview, normal effect, denial, and recovery.
Show worked solution
Use a disposable approved target to verify invalid input and denial cause no effects, WhatIf preserves state, and an approved call makes only the intended change. Verify postconditions, failure and cleanup, and document versions and evidence before broader use.
Check your solution
- Preview and denial cause no mutation.
- Normal effect and recovery are independently verified.
Key takeaways
- Place mutations inside the ShouldProcess decision.
- Test preview and real behavior while keeping authorization and recovery explicit.
- The effect must be inside the guarded branch.
- WhatIf is not a sandbox or transaction.
- Verify state and helper effects, not only preview messages.