Skip to content

feat(iac): --allow-replace flag + batch protected-blocker discovery (W-6 of 12)#532

Merged
intel352 merged 57 commits into
mainfrom
feat/iac-allow-replace
May 4, 2026
Merged

feat(iac): --allow-replace flag + batch protected-blocker discovery (W-6 of 12)#532
intel352 merged 57 commits into
mainfrom
feat/iac-allow-replace

Conversation

@intel352
Copy link
Copy Markdown
Contributor

@intel352 intel352 commented May 4, 2026

Summary

W-6 of the 12-PR IaC plan series. Adds --allow-replace=<comma-list> flag to wfctl infra apply for per-resource opt-in to bypass protected: true. Without the flag, Replace + Delete actions on protected resources error pre-dispatch. With matching name in the list, protection is bypassed for that resource only. T6.2 single-pass discovery: error reports ALL blockers in one error with copy-paste --allow-replace=name1,name2,... value.

Plan reference: docs/plans/2026-05-03-iac-conformance-and-replace.md rev10.

Base: main (W-3b PR #528 merged at a434d195).

What ships

5 commits:

  • a37176a T6.1: --allow-replace flag + per-resource gate (live-diff + --plan paths)
  • e4f7e53 T6.2: batch-aggregator multi-blocker discovery + copy-paste flag value
  • 894955d Merge from main (W-3b cascade)
  • c9bb29a Fix: restore T6.1 + T6.2 helpers lost during cascade-merge with -X theirs (foot-gun noted for future cascades)
  • 4f90dd3 T6.4: docs/WFCTL.md infra apply flag section

Plan-spec defects (W-6 incidentals)

  1. T6.3 doesn't exist — rev2 stub-conformance pattern removed. T6.4 is documentation; W-7 owns the conformance scenarios.
  2. T6.1 file location precedent: plan said infra_apply.go but flag registration follows codebase convention in cmd/wfctl/infra.go (where runInfraApply and other apply flags live). Gate logic IS in infra_apply.go per spec.
  3. T6.2 header phrasing: broader "destructive action on N protected resource(s)" rather than design's "replacing N" — accurately covers both replace AND delete (gate scope from T6.1). Plan T6.2 doesn't mandate a literal.
  4. `-X theirs` cascade-merge foot-gun: W-3b → W-6 cascade-merge silently dropped T6.1+T6.2 helpers from cmd/wfctl/infra_apply.go while keeping their call sites. Caught by code-reviewer at quality review; restored via `c9bb29a`. Future cascade strategy: prefer plain merge with manual conflict resolution OR `-X ours` for branch-additive helpers.

Test plan

  • `GOWORK=off go test -race -count=1 ./interfaces/... ./iac/... ./platform/... ./cmd/wfctl/...` PASS
  • 14 W-6-specific tests (8 T6.1 + 5 T6.2 + 1 v2 dispatch carry-forward)
  • `markdown-link-check docs/WFCTL.md` clean (mdformat waived per ADR/team-lead Option-3)
  • CI

🤖 Generated with Claude Code

intel352 and others added 30 commits May 3, 2026 19:05
T2.1 — bounded-concurrency Refresh(ctx, provider, states, opts) that calls
ResourceDriver.Read per resource and returns a copy of the state slice with
Outputs reconciled to the live values. Default concurrency 8 when
Options.Concurrency < 1; otherwise honor the caller's value. On any Read or
driver-resolution failure, returns (nil, err) so callers don't half-persist
a refresh. Foundation for wfctl infra refresh-outputs (T2.2) and the opt-in
apply pre-step (T2.3).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
T2.2 — `wfctl infra refresh-outputs [-c CONFIG] [--env ENV] [--concurrency N]`
reads live Outputs for each resource already in state and persists any
field-level changes back to the state backend. Read-only at the cloud
level — never invokes Update or Replace.

Discovers iac.provider modules in the config (with per-env resolution),
groups state entries by their owning iac.provider module (ProviderRef-first,
falling back to provider type when exactly one module of that type exists),
loads each provider once, calls iac/refreshoutputs.Refresh per group, and
SaveResource()s any state whose Outputs map changed.

When the resolved config has no usable iac.provider module for the
requested env, emits the literal error
  refresh-outputs: provider not configured for env "<env>"
verbatim per `fmt.Errorf("refresh-outputs: provider not configured for
env %q", env)`. T2.7's runtime-launch-validation asserts against this
exact line.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ESH_OUTPUTS)

T2.3 — wires iac/refreshoutputs.Refresh into runInfraApply as a pre-plan
read-only state reconciliation. Default OFF: operators get pre-W-2
behavior unless they explicitly opt in.

Activation rules:
- WFCTL_REFRESH_OUTPUTS unset, empty, or unrecognised → no-op (default).
- WFCTL_REFRESH_OUTPUTS="1"/"true"/"t" (strconv.ParseBool truthy) →
  run pre-step.
- WFCTL_REFRESH_OUTPUTS="0"/"false"/"f" (strconv.ParseBool falsey) →
  no-op. Operators who use the "0"/"false" convention to disable a
  feature get the expected behaviour rather than a presence-only
  foot-gun.
- --skip-refresh → suppress pre-step regardless of env var (for CI
  environments that force the env var on globally).

Behavior: after the existing --refresh drift/prune phase and before the
plan/apply dispatch, discovers iac.provider modules with per-env
resolution, loads current state, and calls
refreshOutputsAcrossProviders to read live Outputs and persist any
field-level changes. On any Read or driver-resolution failure, apply
aborts with the wrapped error from T2.1's helper (no half-persisted
refresh, no plan computed against stale state). Only fires for
infra.* configs (legacy platform.* path is silently skipped).

Rollback: unset WFCTL_REFRESH_OUTPUTS, pass --skip-refresh, or revert
this commit. Reverting removes the pre-step entirely (helper file plus
the gated block in infra.go).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
T2.5 — pure-package stress test in iac/refreshoutputs/. Drives Refresh
with 100 fake resources at Concurrency=8 and asserts:

  1. No deadlock (10s watchdog around the call).
  2. Read called exactly once per ProviderID (atomic per-ID counter).
  3. Every refreshed state carries the live Outputs map — no
     write-into-wrong-slot bug under concurrency.
  4. Concurrent in-flight peak between 2 and the requested cap, proving
     both that parallelism happened AND that the semaphore enforced
     its limit.

The countingDriver introduces a 5ms sleep per Read so the bounded pool
actually queues at the cap (5ms × 100 / 8 ≈ 63ms total at peak; well
under the 10s watchdog). Test runs ~1.5s wall.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
T2.6 — adds the infra refresh-outputs section to docs/WFCTL.md:

- New row in the Command Tree mermaid graph.
- New row in the infra Action table.
- Dedicated #### subsection with usage, flag table, behavior summary,
  literal-error contract (load-bearing per T2.7), apply-time pre-step
  semantics (WFCTL_REFRESH_OUTPUTS, --skip-refresh), and three
  representative examples.

See also: docs/adr/006-wfctl-refresh-outputs-env-var-parsebool.md
records the T2.3 plan-deviation (ParseBool vs plan-literal presence
check) that the docs in this commit accurately reflect.

Verification — plan §T2.6 line 1090 invocation `mdformat --check
docs/WFCTL.md && find docs -name "*.md" -exec markdown-link-check {} +`
ran with locally-installed mdformat 1.0.0 (pip) and markdown-link-check
3.14.2 (npm):

  $ mdformat --check docs/WFCTL.md
  Error: File "docs/WFCTL.md" is not formatted.
  exit=1

  This failure is PRE-EXISTING. Verified by checking out the file at
  the W-2 T2.2 tip (181e579) before any T2.6 edits and rerunning
  mdformat against it: identical error. docs/WFCTL.md has never been
  mdformat-formatted in this repo. Reformatting the entire file is
  out of scope for T2.6 (would introduce a multi-thousand-line
  unrelated diff). T2.6's own additions follow the existing in-file
  conventions exactly.

  $ markdown-link-check docs/WFCTL.md
  FILE: docs/WFCTL.md
    [✓] https://github.com/GoCodeAlone/workflow
    [✓] #build-ui
    [✓] mcp.md
    3 links checked.
  exit=0

  docs/WFCTL.md has zero broken links — including the new
  refresh-outputs section. The directory-wide scan reports 7 broken
  links in unrelated files (self-improvement-tutorial.md,
  getting-started.md, etc.); all are pre-existing and out of scope.

T2.7 runtime-launch-validation transcript (folded into this commit
body per the "Files: none new" plan note for T2.7):

  $ GOWORK=off go build -o /tmp/wfctl ./cmd/wfctl
  exit=0

  $ /tmp/wfctl infra refresh-outputs --help
  Usage of infra refresh-outputs:
    -c string
      	Config file (short for --config)
    -concurrency int
      	Maximum concurrent Read calls (default 8)
    -config string
      	Config file
    -e string
      	Environment name (short for --env)
    -env string
      	Environment name (resolves per-module overrides)
  exit=0

  $ cat /tmp/t27-fake.yaml
  modules:
    - name: state-store
      type: iac.state
      config:
        backend: filesystem
        directory: /tmp/t27-fake-state

  $ /tmp/wfctl infra refresh-outputs -c /tmp/t27-fake.yaml --env staging
  error: refresh-outputs: provider not configured for env "staging"
  exit=1

  No panic, no stack trace. Stderr line is the verbatim literal pinned
  by T2.7 (plan line 1098), produced by T2.2's
  fmt.Errorf("refresh-outputs: provider not configured for env %q",
  env) at cmd/wfctl/infra_refresh_outputs.go:49.

  PR W-2 mandate (plan line 1101):
  $ GOWORK=off go test ./iac/refreshoutputs/... ./cmd/wfctl/... -count=1 -race
  ok  	github.com/GoCodeAlone/workflow/iac/refreshoutputs	1.405s
  ok  	github.com/GoCodeAlone/workflow/cmd/wfctl	10.485s

  Manual smoke against staging-PG: not run — no staging-PG available
  in this worktree environment. Plan line 1102 marks this "if
  available", so deferring to the operator landing the PR.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… from plan §T2.3

ADR 006 — formalises the spec-vs-quality-review trade-off recorded
during W-2 T2.3 review:

- Plan §T2.3 line 1061 specified `os.Getenv("WFCTL_REFRESH_OUTPUTS") != ""`.
- Code-reviewer flagged this as a foot-gun (=0 mis-enables).
- Implementation at cmd/wfctl/infra_apply_refresh_pre.go (bfd1bbe) uses
  strconv.ParseBool so falsey values explicitly disable.
- Spec-reviewer accepted post-hoc and requested this ADR per
  superpowers:recording-decisions.
- Team-lead approved option-1 (approve-as-is + follow-up ADR) over a
  plan revert; provenance recorded in the ADR itself.

Captures the rejected alternative, the rationale, references back to
the plan spec, the implementation site, the pinning test, and the
operator-facing docs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…rovider schema

Addresses code-reviewer findings on commit 695a070:

- Important: race on lazy compiledSchema cache. Wrap with sync.Once;
  capture both *jsonschema.Schema and the compile error so concurrent
  callers observe a single deterministic outcome. Adds a 32-goroutine
  ParseManifest stress test that fires under -race to lock in the
  invariant going forward.
- Minor: ManifestSchemaJSON() now returns bytes.Clone(...) so callers
  cannot mutate the //go:embed slice (defense-in-depth; embed slices
  are technically writable). New test verifies the copy semantics.
- Minor: iacProvider sub-object gains additionalProperties:false so a
  typo like "computeplanversion" or an unknown key is rejected at
  parse time instead of silently defaulting to v1 dispatch. The root
  object stays permissive — existing plugin.json files carry
  version/author/dependencies/etc. and the SDK manifest is a strict
  subset by design. New test covers both the typo-rejection and the
  root-permissivity contracts.
T2.1 — bounded-concurrency Refresh(ctx, provider, states, opts) that calls
ResourceDriver.Read per resource and returns a copy of the state slice with
Outputs reconciled to the live values. Default concurrency 8 when
Options.Concurrency < 1; otherwise honor the caller's value. On any Read or
driver-resolution failure, returns (nil, err) so callers don't half-persist
a refresh. Foundation for wfctl infra refresh-outputs (T2.2) and the opt-in
apply pre-step (T2.3).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
T2.2 — `wfctl infra refresh-outputs [-c CONFIG] [--env ENV] [--concurrency N]`
reads live Outputs for each resource already in state and persists any
field-level changes back to the state backend. Read-only at the cloud
level — never invokes Update or Replace.

Discovers iac.provider modules in the config (with per-env resolution),
groups state entries by their owning iac.provider module (ProviderRef-first,
falling back to provider type when exactly one module of that type exists),
loads each provider once, calls iac/refreshoutputs.Refresh per group, and
SaveResource()s any state whose Outputs map changed.

When the resolved config has no usable iac.provider module for the
requested env, emits the literal error
  refresh-outputs: provider not configured for env "<env>"
verbatim per `fmt.Errorf("refresh-outputs: provider not configured for
env %q", env)`. T2.7's runtime-launch-validation asserts against this
exact line.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ESH_OUTPUTS)

T2.3 — wires iac/refreshoutputs.Refresh into runInfraApply as a pre-plan
read-only state reconciliation. Default OFF: operators get pre-W-2
behavior unless they explicitly opt in.

Activation rules:
- WFCTL_REFRESH_OUTPUTS unset, empty, or unrecognised → no-op (default).
- WFCTL_REFRESH_OUTPUTS="1"/"true"/"t" (strconv.ParseBool truthy) →
  run pre-step.
- WFCTL_REFRESH_OUTPUTS="0"/"false"/"f" (strconv.ParseBool falsey) →
  no-op. Operators who use the "0"/"false" convention to disable a
  feature get the expected behaviour rather than a presence-only
  foot-gun.
- --skip-refresh → suppress pre-step regardless of env var (for CI
  environments that force the env var on globally).

Behavior: after the existing --refresh drift/prune phase and before the
plan/apply dispatch, discovers iac.provider modules with per-env
resolution, loads current state, and calls
refreshOutputsAcrossProviders to read live Outputs and persist any
field-level changes. On any Read or driver-resolution failure, apply
aborts with the wrapped error from T2.1's helper (no half-persisted
refresh, no plan computed against stale state). Only fires for
infra.* configs (legacy platform.* path is silently skipped).

Rollback: unset WFCTL_REFRESH_OUTPUTS, pass --skip-refresh, or revert
this commit. Reverting removes the pre-step entirely (helper file plus
the gated block in infra.go).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
T2.5 — pure-package stress test in iac/refreshoutputs/. Drives Refresh
with 100 fake resources at Concurrency=8 and asserts:

  1. No deadlock (10s watchdog around the call).
  2. Read called exactly once per ProviderID (atomic per-ID counter).
  3. Every refreshed state carries the live Outputs map — no
     write-into-wrong-slot bug under concurrency.
  4. Concurrent in-flight peak between 2 and the requested cap, proving
     both that parallelism happened AND that the semaphore enforced
     its limit.

The countingDriver introduces a 5ms sleep per Read so the bounded pool
actually queues at the cap (5ms × 100 / 8 ≈ 63ms total at peak; well
under the 10s watchdog). Test runs ~1.5s wall.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
T2.6 — adds the infra refresh-outputs section to docs/WFCTL.md:

- New row in the Command Tree mermaid graph.
- New row in the infra Action table.
- Dedicated #### subsection with usage, flag table, behavior summary,
  literal-error contract (load-bearing per T2.7), apply-time pre-step
  semantics (WFCTL_REFRESH_OUTPUTS, --skip-refresh), and three
  representative examples.

See also: docs/adr/006-wfctl-refresh-outputs-env-var-parsebool.md
records the T2.3 plan-deviation (ParseBool vs plan-literal presence
check) that the docs in this commit accurately reflect.

Verification — plan §T2.6 line 1090 invocation `mdformat --check
docs/WFCTL.md && find docs -name "*.md" -exec markdown-link-check {} +`
ran with locally-installed mdformat 1.0.0 (pip) and markdown-link-check
3.14.2 (npm):

  $ mdformat --check docs/WFCTL.md
  Error: File "docs/WFCTL.md" is not formatted.
  exit=1

  This failure is PRE-EXISTING. Verified by checking out the file at
  the W-2 T2.2 tip (181e579) before any T2.6 edits and rerunning
  mdformat against it: identical error. docs/WFCTL.md has never been
  mdformat-formatted in this repo. Reformatting the entire file is
  out of scope for T2.6 (would introduce a multi-thousand-line
  unrelated diff). T2.6's own additions follow the existing in-file
  conventions exactly.

  $ markdown-link-check docs/WFCTL.md
  FILE: docs/WFCTL.md
    [✓] https://github.com/GoCodeAlone/workflow
    [✓] #build-ui
    [✓] mcp.md
    3 links checked.
  exit=0

  docs/WFCTL.md has zero broken links — including the new
  refresh-outputs section. The directory-wide scan reports 7 broken
  links in unrelated files (self-improvement-tutorial.md,
  getting-started.md, etc.); all are pre-existing and out of scope.

T2.7 runtime-launch-validation transcript (folded into this commit
body per the "Files: none new" plan note for T2.7):

  $ GOWORK=off go build -o /tmp/wfctl ./cmd/wfctl
  exit=0

  $ /tmp/wfctl infra refresh-outputs --help
  Usage of infra refresh-outputs:
    -c string
      	Config file (short for --config)
    -concurrency int
      	Maximum concurrent Read calls (default 8)
    -config string
      	Config file
    -e string
      	Environment name (short for --env)
    -env string
      	Environment name (resolves per-module overrides)
  exit=0

  $ cat /tmp/t27-fake.yaml
  modules:
    - name: state-store
      type: iac.state
      config:
        backend: filesystem
        directory: /tmp/t27-fake-state

  $ /tmp/wfctl infra refresh-outputs -c /tmp/t27-fake.yaml --env staging
  error: refresh-outputs: provider not configured for env "staging"
  exit=1

  No panic, no stack trace. Stderr line is the verbatim literal pinned
  by T2.7 (plan line 1098), produced by T2.2's
  fmt.Errorf("refresh-outputs: provider not configured for env %q",
  env) at cmd/wfctl/infra_refresh_outputs.go:49.

  PR W-2 mandate (plan line 1101):
  $ GOWORK=off go test ./iac/refreshoutputs/... ./cmd/wfctl/... -count=1 -race
  ok  	github.com/GoCodeAlone/workflow/iac/refreshoutputs	1.405s
  ok  	github.com/GoCodeAlone/workflow/cmd/wfctl	10.485s

  Manual smoke against staging-PG: not run — no staging-PG available
  in this worktree environment. Plan line 1102 marks this "if
  available", so deferring to the operator landing the PR.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… from plan §T2.3

ADR 006 — formalises the spec-vs-quality-review trade-off recorded
during W-2 T2.3 review:

- Plan §T2.3 line 1061 specified `os.Getenv("WFCTL_REFRESH_OUTPUTS") != ""`.
- Code-reviewer flagged this as a foot-gun (=0 mis-enables).
- Implementation at cmd/wfctl/infra_apply_refresh_pre.go (bfd1bbe) uses
  strconv.ParseBool so falsey values explicitly disable.
- Spec-reviewer accepted post-hoc and requested this ADR per
  superpowers:recording-decisions.
- Team-lead approved option-1 (approve-as-is + follow-up ADR) over a
  plan revert; provenance recorded in the ADR itself.

Captures the rejected alternative, the rationale, references back to
the plan spec, the implementation site, the pinning test, and the
operator-facing docs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…mitempty contract

Addresses code-reviewer findings on commit 13a6fad:

- Important: ReplaceIDMap godoc said "Keyed by the dependent resource
  Name" but the populating site (T3.4 plan §1625) sets
  result.ReplaceIDMap[action.Resource.Name] where action.Resource is the
  REPLACED resource. The roundtrip fixture {"vpc":"new-uuid"} confirms
  this. Re-worded to "Keyed by the *replaced* resource's Name" with an
  explicit reference to action.Resource.Name + a sentence on how W-5 JIT
  substitution will use the map (lookup by replaced-resource name to
  obtain the new ProviderID for dependent configs). Locks the contract
  before the field has any consumers.
- Minor: cross-referenced the InputDriftReport sort-stability guarantee
  to its enforcing test (TestComputeDrift_ResultIsSortedByName in
  iac/inputsnapshot/compute_drift_test.go) so the contract is no longer
  free-floating on the field godoc.
- Minor: added TestApplyResult_OmitEmptyContract — table-driven across
  nil and empty-but-non-nil values for all three new fields, asserting
  the JSON keys are absent from the encoded form. Locks the omitempty
  tag behavior so a future refactor cannot silently regress to emitting
  "initial_input_snapshot": {} / "input_drift_report": [] / "replace_id_map": {}.
…iver-resolve test

Addresses code-reviewer findings on commit 8416498:

- Important 1 (weak Replace assertion): converted fakeDriver from
  boolean call recorders to integer counters. The 4-action plan
  [create, update, replace, delete] now asserts Create==2, Update==1,
  Delete==2. If "case replace" were silently dropped from
  dispatchAction the counts would shift to 1/1/1 and the test would
  fail. Added TestApplyPlan_ReplaceDispatchesViaDeleteThenCreate that
  isolates Replace via a single-action plan: 1 Delete + 1 Create + 0
  Update. Removes the calledReplace() proxy entirely.
- Important 2 (resolve-driver-error path uncovered): added
  TestApplyPlan_ResolveDriverErrorRecordsActionError which exercises
  fakeProvider.driverErr, asserts the canonical "resolve driver:"
  prefix, and verifies the loop continues past action[0] to action[1]
  (best-effort contract). Folded the loop-continues-after-failure
  coverage into a separate TestApplyPlan_LoopContinuesAfterPerActionFailure
  using a selectiveFakeProvider that errors on one type only — proves
  one action's failure does not block another's success.
- Minor 1 (wasted %w): switched fmt.Errorf(...).Error() to
  fmt.Sprintf("resolve driver: %v", err) since the destination is a
  string field and the wrapping chain dies at the field boundary.
- Minor 3 (ctx.Done not checked): added ctx.Err() check at the loop
  iteration boundary; on cancel, returns the result accumulated so far
  + the ctx error as top-level. Added
  TestApplyPlan_CtxCancellationStopsLoop covering pre-call cancel:
  driver receives zero invocations, top-level error is context.Canceled.
- Minor 5 (refFromAction defensive note): added a godoc paragraph
  documenting the same-name-same-type invariant for Replace plans.
  Documenting rather than enforcing — ComputePlan upstream is the
  contract owner.

Minor 2 (uniform error prefixing across sub-functions) intentionally
deferred to T3.2/T3.3/T3.4 per reviewer guidance — those tasks own the
final sub-function bodies and can pick the convention once.
…_plan_test

Imports were left orphaned by W-1 PR #523 (commit 48f7a0c) when
fingerprintForTest was switched to delegate to inputsnapshot.Compute
instead of computing sha256 inline. cmd/wfctl test build was broken on
HEAD because of the unused imports — surfaced while landing T3.1.5,
which adds a new test file in the same package.

Pure-mechanical cleanup. No behavior change.
intel352 and others added 23 commits May 3, 2026 22:32
…rkflows

T3.5 lifecycle constraint #4 (rev3) follow-up — addresses spec-reviewer
finding on commit 8774205. Two plan-mandated deliverables that the
T3.5 commit's `git add` line omitted:

1. **docs/WFCTL.md gains a "Diff Cache" section.** Documents the cache
   as an amortization-only optimization (not correctness mechanism),
   the WFCTL_DIFFCACHE backend selection (disabled / :memory: /
   filesystem default), the LRU eviction caps (1024 entries / 64 MiB),
   the corruption recovery contract (silent eviction + once-per-process
   info log), the plugin-downgrade safety property, and the rev3
   "all CI workflows set :memory: explicitly" statement plus a list
   of the affected workflow files.

2. **WFCTL_DIFFCACHE=:memory: at workflow-level env in CI.** Set in
   every workflow that runs `go test` or `wfctl`:
   - .github/workflows/ci.yml          (test + lint jobs)
   - .github/workflows/benchmark.yml   (performance benchmarks)
   - .github/workflows/pre-release.yml (pre-release tests)
   - .github/workflows/release.yml     (release tests)
   - .github/workflows/dependency-update.yml (post-update test gate)

   Workflow files that don't invoke go test / wfctl are not modified
   (codeql.yml, copilot-setup-steps.yml, create-release.yml, helm-lint.yml,
   osv-scanner.yml, test-dispatch.yml).

Each workflow gets a brief inline comment citing ci.yml as the
canonical rationale + the T3.5 rev3 lifecycle constraint reference.

Per spec-reviewer guidance: kept the original T3.5 package-code commit
(8774205) untouched and stacked this docs+CI commit on top. YAML
syntax verified on all 5 modified workflows.
…leanup

Addresses 5 of 7 code-reviewer minors on commits 8774205 + f80a060:

- Minor 1 (atomic Put, worth-doing production improvement): Put now
  uses write-temp-then-rename. POSIX rename(2) is atomic on the same
  filesystem, so a process crash mid-write leaves either the prior
  contents or the new contents — never a partial write. The
  corruption-recovery path in Get is still the safety net for cross-
  filesystem renames or NFS edge cases that don't honor atomicity.
  In production this means corruption recovery essentially never
  fires from native crashes. The .json extension filter in
  maybeEvict already excludes .tmp orphans, so no additional
  filtering needed. On rename failure, best-effort cleanup of the
  temp file.
- Minor 3 (userCacheDir godoc): tightened the platform-conventions
  language. Linux honors XDG_CACHE_HOME; macOS uses
  ~/Library/Caches; Windows uses %LocalAppData%. The previous
  comment overstated XDG honoring on all platforms.
- Minor 4 (Key JSON tags vs keyFingerprint): added a godoc note
  explaining the tags are for log/transcript serialization, not
  cache keying — keyFingerprint uses NUL-separated string concat,
  not JSON marshaling. Future readers checking the fingerprint
  shape now have the right pointer.
- Minor 5 (vestigial sanity check): dropped the
  `os.Stat(filepath.Join(dir, "*.json"))` literal-glob check at the
  end of TestCache_EvictionTouchesNothingWhenUnderCap. The check was
  meaningless — no code path creates a file with `*` in its name.
  Likely leftover from earlier debugging. Removing it lets us drop
  the now-unused `os` import.
- Minor 6 (mtime resolution test comment): added a paragraph to
  TestCache_LRUEvictionByCount's godoc explaining the ≤1ms mtime
  resolution assumption and listing the supported filesystems
  (ext4/btrfs/xfs/APFS/NTFS — the CI matrix). Coarse-mtime
  filesystems (FAT32, SMB) are explicitly out of scope.

Skipped per reviewer guidance:
- Minor 2 (maybeEvict O(N) scan on every Put): "skeleton-class
  concern; acceptable for W-3a scope."
- Minor 7 (Put error log-silent): "the cache-as-amortization framing
  in the package godoc already sets the expectation."
…EAKING: fails on plugin-load error)

W-3b T3.6b. Adds computePlanForInfraSpecs which discovers iac.provider
modules in the config, groups desired specs by `provider:` field, loads
each via the same loader the apply path uses, and dispatches
platform.ComputePlan per group so the v2 Diff contract (T3.6e) operates
against a real plugin process at plan time, not just at apply time.

BREAKING: configs declaring at least one iac.provider module now require
the plugin process to load successfully. Plugin-load failure exits
non-zero with the literal error documented in the v0.21.0 CHANGELOG.
There is no --no-provider escape hatch (rev3 YAGNI fix per cycle-2);
operators who need pure offline validation should use `wfctl validate`.

Configs without any iac.provider module fall back to the legacy
ConfigHash compare path so minimal/legacy fixtures and out-of-band
scripts continue to work.

cmd/wfctl/infra_apply.go:350 receives a temporary nil provider so the
package compiles; T3.6c replaces nil with the live provider handle.
W-3b T3.6d. Updates the 4 cross-package ComputePlan call sites in
module/infra_module_integration_test.go to the new (ctx, provider, …)
signature. Lifts the no-op fake into a small public test helper at
iac/iactest/fakeprovider.go so the same shape no longer needs to be
re-declared every time a new package wants to satisfy the interface.

Folds in the T3.6c review's IMPORTANT follow-up: cmd/wfctl's
computePlanForInfraSpecs now dispatches via the same computeInfraPlan
seam the apply path uses (no parallel seam variable; one override point
serves both call sites). Plan-loop body is wrapped in an IIFE so each
provider's closer fires after its group is computed instead of
deferring to function exit (multi-provider plan no longer holds N gRPC
connections open at once).

Drops the duplicated planNoopProvider and applyV2RecordingProvider
no-op implementations in cmd/wfctl tests in favor of the shared
iactest.NoopProvider. Three structurally-identical 14-method shells
become one. Atomic counters carried forward where used.

Doc updates:
- godoc on computePlanForInfraSpecs corrected: groups are concatenated
  in first-reference-in-`desired` order, not iac.provider declaration
  order (matches actual code).
- CHANGELOG entry calls out the empty-desired alignment with apply
  (loop over groupOrder is empty when no specs reference any provider;
  use `wfctl infra destroy --dry-run` to preview teardown).
…tion when ForceNew or NeedsReplace

W-3b T3.6e — the binding TDD red→green commit for the v2 IaC contract
(rev3 fix for the cycle-2 self-contradiction: test + impl ship in the
same SHA, no t.Skip placeholder).

ComputePlan now classifies each existing resource via
p.ResourceDriver(spec.Type).Diff(ctx, spec, currentOut), running the
per-resource Diff calls in parallel under errgroup with a bounded
worker pool (default 8; WFCTL_PLAN_DIFF_CONCURRENCY env var override
clamped 1..32). Action emission:

  - replace, when DiffResult.NeedsReplace OR any FieldChange.ForceNew
    is true (the latter closes design issue C — pre-W-3b ForceNew was
    silently downgraded to update);
  - update,  when DiffResult.NeedsUpdate is true and replace did not
    fire;
  - skip,    when neither flag is set.

Net-new resources still emit create without dispatching Diff;
resources removed from desired still emit delete in reverse-dep order.

Nil-tolerance contract preserved: if p is nil, or if
p.ResourceDriver(typ) returns (nil, nil) for a resource type,
ComputePlan falls back to the legacy ConfigHash compare for the
affected resources. Replace cannot be expressed via the legacy path —
callers needing Replace must supply a provider whose drivers implement
Diff. Per-resource driver.Diff errors propagate via errgroup so
operators see the underlying cause (rate limit, network, etc.).

Test surface (platform/differ_replace_test.go, NEW; ships in this
commit per the rev3 atomicity rule):

  - TestComputePlan_NeedsReplaceEmitsReplaceAction
  - TestComputePlan_ForceNewWithoutNeedsReplace_StillEmitsReplace
  - TestComputePlan_NeedsUpdateWithoutForceNew_EmitsUpdate
  - TestComputePlan_DiffReturnsNoChanges_EmitsNothing
  - TestComputePlan_NilProvider_FallsBackToConfigHash
  - TestComputePlan_NilDriver_FallsBackToConfigHash
  - TestComputePlan_DriverDiffError_PropagatesAsError

platform/fake_provider_test.go extended with newFakeProviderWithDiff
helper; in-package no-op fakeProvider/fakeDriver kept (cannot collapse
to iac/iactest until cache_test in T3.6f also depends on the helper —
deferred to keep T3.6e's diff bounded).

Carry-forward notes addressed:
- T3.6a note 1: dropped unused *testing.T param from newFakeProvider().
- T3.6a note 2: added compile-time interface conformance asserts on
  fakeProvider and fakeDriver.
- T3.6a note 3: nil-provider AND nil-driver guards baked in; covered
  by two explicit tests.
- T3.6a note 4: rewrote fake_provider_test.go godoc to behavior-based
  phrasing.

cmd/wfctl test fakes updated to match the new dispatch model:
- readDriver.Diff now returns NeedsUpdate=true (the adoption tests
  rely on the post-adopt ComputePlan emitting update; pre-W-3b that
  was the ConfigHash compare's job).
- refreshOutputsCmdFakeDriver.Diff now returns (nil, nil) instead of
  panicking — the refresh-outputs test fixture only exercises Read.
W-3b T3.6f. Wires the iac/diffcache package (W-3a/T3.5) into
classifyModification: cache.Get is consulted before each
ResourceDriver.Diff dispatch under the (PluginVersion, Type,
ProviderID, SHAConfig, SHAOutputs) tuple; on hit, the cached
DiffResult is used directly; on miss, the freshly-computed result is
Put into the cache. Apply-time correctness does not depend on cache
hits — fresh CI runners always miss and re-Diff (the cache is purely
an amortization optimization for repeated `wfctl infra plan` against
the same checkout).

Cache backend selection follows iac/diffcache's WFCTL_DIFFCACHE env
var contract: unset → filesystem (~/.cache/wfctl/diff/); ":memory:" →
in-memory; "disabled" → noop. The package-level cache instance is
lazy-initialised on first ComputePlan call and shared across
subsequent calls; tests in the same package may swap it via the
internal-package setDiffCacheForTest helper.

platform/main_test.go (NEW) sets WFCTL_DIFFCACHE=disabled at TestMain
so the platform test suite never reads/writes the developer's
filesystem cache and so cache state cannot leak across tests with
incidentally-aligned cache keys (caught during integration: T3.6e's
Replace-emission test was Putting a result that polluted later
update/no-op tests).

Folds in the T3.6e code-review IMPORTANT carry-forwards (since both
fixes touch platform/):

- Note 1 (env-clamping testability): extract parseConcurrencyEnv as a
  pure function; new TestParseConcurrencyEnv table-driven test covers
  empty, non-numeric, "0", "1", "8", "32", "33", "100", "-5".
- Note 2 (parallel-dispatch correctness): new
  TestComputePlan_ParallelDispatch_AllCandidatesObserveDiff exercises
  N=5 modification candidates, asserts driver.diffCount.Load() == 5
  and the resulting plan has 5 actions.
- Note 3 (driver returns nil DiffResult): explicit test
  TestComputePlan_DriverReturnsNilDiff_EmitsNothing.

And T3.6e adversarial-review minor cleanups:

- Note 4 (i := i shadowing redundant in Go 1.22+): dropped.
- Note 5 (errSentinel uses custom errFromTest): replaced with
  errors.New.
- Note 7 (concurrency contract on ComputePlan godoc): added — p and
  the ResourceDriver instances it returns MUST be safe for concurrent
  use.

New tests (3 cache-behaviour scenarios in differ_cache_test.go):
- TestComputePlan_CacheHitSkipsDiff (second call against unchanged
  inputs hits cache; diffCount stays at 1)
- TestComputePlan_CacheMissesOnDifferentInputs (varying SHAConfig
  forces re-dispatch)
- TestComputePlan_NoopCacheNeverHits (disabled backend always
  re-dispatches)
…est (Copilot review)

Strengthens the count-only TestComputePlan_ParallelDispatch_AllCandidatesObserveDiff
(landed in T3.6f) per team-lead's explicit request: a regression that
accidentally serialized Diff dispatch (e.g., g.SetLimit(1)) would
still pass the count-only assertion as long as every candidate
eventually got dispatched. The new
TestComputePlan_ParallelDiffDispatch_InFlightGoroutinesObserved uses
a channel-gated driver to prove ≥2 Diff goroutines are simultaneously
in-flight before any returns: regression to serial dispatch would
hang on the second `<-entered` and time out at 5s.

Pure addition (no production-code change). cacheTestProvider.driver
loosened from *cacheTestDriver to interfaces.ResourceDriver so the
new channelGatedDriver shares the provider shell.
…parator (Copilot review)

Code-reviewer flagged the T3.6f cache PluginVersion key as fragile:
composing via `p.Name() + "@" + p.Version()` would let two
genuinely-different providers — `("foo", "bar@1.0")` vs
`("foo@bar", "1.0")` — collide on the literal string `"foo@bar@1.0"`
and serve each other's cached DiffResults. Today's registered
providers (digitalocean, dockercompose, mock) don't carry `@` in
either field so no observed bug, but there's no compile-time guard
against a future provider declaring `do@enterprise` or similar.

Replace with sha256(name + "\x00" + version) — fixed-length, NUL is
invalid in both fields by Unicode convention, ambiguity-free.
Matches how configHash already keys per-config inputs.

Three regression tests pin the fix:
- TestPluginVersionKey_NoCollisionOnAtSeparator (the actual bug)
- TestPluginVersionKey_NilProvider (defensive — empty key, no panic)
- TestPluginVersionKey_Stable (deterministic across calls)

Pure additive — no change to any existing test outcome. The cache
re-keys against the new digest, which means any DiffResults persisted
under the old `name@version` keys will miss on the next plan and
re-Diff naturally (cache misses are correct by design).
…tePlanVersion

W-3b T3.7. Routes apply through wfctlhelpers.ApplyPlan when the
loaded plugin's plugin.json declares iacProvider.computePlanVersion:
v2 (read at provider load time and surfaced via the optional
ComputePlanVersionDeclarer interface). Providers that don't declare
the field, or declare anything other than "v2", take the legacy
provider.Apply path.

rev2/rev3-locked: NO env-var, NO operator-flippable gate. The
v1/v2 routing is plugin-author-controlled via plugin.json from day 1
— there is no transitional WFCTL_USE_V2_APPLY flag to misuse.

Wires the printDriftReportIfAny helper (added unwired in W-3a/T3.1.5
as foundation only). The v2 dispatch path is the production caller
that surfaces the InputDriftReport to stderr after a successful
ApplyPlan return; v1 path remains untouched per the W-3a "zero
runtime change for v1 plugins" invariant.

New plumbing:
- iac/wfctlhelpers/dispatch.go (NEW): ComputePlanVersionDeclarer
  interface + DispatchVersionV2 const + DispatchVersionFor helper.
  Single override point for the dispatch decision.
- iac/iactest/fakeprovider.go: NoopProvider gains DispatchVersion +
  ProviderVersion fields and ComputePlanVersion() method so tests
  drive both v1 (default empty) and v2 paths through the shared fake.
- cmd/wfctl/deploy_providers.go: iacPluginManifest reads top-level
  iacProvider.computePlanVersion alongside existing
  capabilities.iacProvider.name; findIaCPluginDir returns the
  version; readIaCPluginComputePlanVersion is the load-time helper;
  remoteIaCProvider stores the value and exposes it via
  ComputePlanVersion() to satisfy the optional interface. (Re-reads
  plugin.json once per provider load rather than threading through
  loadIaCPlugin's 4-tuple var-seam — keeps the seam signature stable
  for the existing test override; cost is one tiny os.ReadFile vs
  the gRPC start.)
- cmd/wfctl/infra_apply.go: applyV2ApplyPlanFn = wfctlhelpers.ApplyPlan
  test seam + dispatch branch in applyWithProviderAndStore. Drift
  report printed to writer on success (no-op when empty).
- cmd/wfctl/infra_apply_v2_test.go: 3 new tests cover
  TestApplyWithProviderAndStore_V2RoutesThroughWfctlhelpers (v2
  routes), TestApplyWithProviderAndStore_V1FallsThroughToProviderApply
  (v1/un-declared routes legacy), TestApplyWithProviderAndStore_V2
  PrintsDriftReport (drift wiring asserted via writer-buffer
  substring). v1 fixture v1RecordingProvider intentionally does NOT
  implement ComputePlanVersionDeclarer to prove the dispatcher's
  "default to v1 when un-declared" branch.
…rage (Copilot review)

Code-reviewer flagged 3 IMPORTANT items in T3.7:

1. Comment/code mismatch on drift-report timing. The comment promised
   "Run on success or partial failure" but the code gated on
   `err == nil` (success only). The contract the comment described
   is the more useful behavior — operators most need the
   stale-input diagnostic when an apply fails ("which input went
   stale during the failed apply?"). Without it, the failure error
   and the "what changed" context are disconnected.

   Fix: gate on `result != nil` instead of `err == nil`.
   printDriftReportIfAny already no-ops on empty/nil reports so
   unconditional-on-result-non-nil is safe.

2. No test for the drift-on-partial-failure path. Added
   TestApplyWithProviderAndStore_V2PrintsDriftReportOnPartialFailure
   which has applyV2ApplyPlanFn return (resultWithDrift, applyErr)
   and asserts both: (a) the err propagates, AND (b) the drift
   report still reaches the writer.

3. Optional-interface coverage gap. Two semantically-different "v1"
   paths exist:
   - Path A: provider doesn't implement ComputePlanVersionDeclarer
     at all → type-assert fails → legacy. Covered by
     v1RecordingProvider.
   - Path B: provider implements interface but ComputePlanVersion()
     returns "" (the realistic mid-transition state for v1 plugins
     after the SDK update lands but before they migrate) → type-
     assert succeeds, DispatchVersionFor returns "v1" → legacy.
     Was untested.

   Added TestApplyWithProviderAndStore_V1Path_DeclarerReturnsEmpty
   using iactest.NoopProvider{DispatchVersion: ""}, which always
   implements the interface (the method exists on the type). Pins
   Path B specifically.

Pure correctness fixes — no signature change, no behavior change for
the success-only or v1-RecordingProvider paths.
…onversion

cmd/wfctl/deploy_providers.go remoteResourceDriver.Diff was passing
current.Sensitive (map[string]bool) directly into the args map.
structpb.NewStruct rejects map[string]bool — it accepts map[string]any
only — and the upstream plugin/external/convert.go::mapToStruct
returns &structpb.Struct{} on err rather than surfacing the typing
failure. Result: every Diff dispatch over gRPC for any provider whose
ResourceOutput.Sensitive map was non-nil (or even an empty
map[string]bool{}) silently observed args=map[] on the plugin side.

v1 plugins never tripped this because v1 dispatches IaCProvider.Plan
server-side (no ResourceDriver.Diff over gRPC). v2 (W-3b T3.7's
manifest-driven dispatch) surfaces it immediately on the first
existing-resource Diff call.

Fix: convert via sensitiveToAny() to the map[string]any shape
NewStruct accepts. Returns nil for empty/nil input so the wire stays
trim-friendly. Bug discovered during W-3b T3.9 runtime-launch
validation against an out-of-band gRPC stub plugin; the canonical
T3.9 in-tree test ships separately as a loader-seam Go integration
test (per team-lead direction + plan precedent at plugin/sdk/iaclint/).

Will surface in T3.10's PR description as a third
incidentally-fixed-by-W-3b bug.
W-3b T3.9. Exercises the full v2 dispatch chain — config parse →
state load → provider load (via the resolveIaCProvider seam from
T3.6c) → ComputePlan Diff dispatch (T3.6e/f) →
wfctlhelpers.ApplyPlan (T3.7's manifest-driven branch) → Replace
decomposition into Delete + Create → printDriftReportIfAny — by
injecting a Go in-process v2-declaring provider through the package-
level seam. No out-of-process gRPC binary or plugin.json under
internal/testdata/.

# ADR 007 — non-trivial deviation from plan-literal

Plan §T3.9 specified "Build a real gRPC-loaded stub provider plugin
in internal/testdata/stub-provider/." Team-lead authorized switching
to in-tree loader-seam validation per:

  1. Plan precedent cite (plugin/sdk/iaclint/) is itself a Go
     test-helper package, not a runnable binary.
  2. Real-gRPC runtime validation lands in P-DO when DO sets
     computePlanVersion: v2 in its plugin.json.
  3. Hours-of-stub-plumbing cost doesn't earn proportional coverage
     vs. T3.6e/f + T3.7 unit tests + this loader-seam end-to-end.
  4. W-7 conformance suite is the recurring cross-PR gRPC harness.

Full reasoning + considered alternatives in
docs/adr/007-t3-9-runtime-validation-via-loader-seam.md.

# Tests

- TestApply_V2_LoaderSeamDispatch_EndToEnd:
  - Writes a real config + filesystem state seeded with vpc
    region=nyc3 (under iacStateRecord shape).
  - Sets desired region=nyc1.
  - Substitutes the resolveIaCProvider seam to return a Go provider
    that declares v2 + has a driver returning NeedsReplace=true.
  - Calls applyInfraModules (the production runInfraApply
    entrypoint) and asserts driver.diffCount == 1, deleteCount ==
    1, createCount == 1, plus exact identity of the deleted
    ProviderID and the created Config["region"].

- TestApply_V2_LoaderSeam_DriftReportPrinted:
  - Same loader-seam setup + applyV2ApplyPlanFn substitution
    returning InputDriftReport with one entry.
  - Captures os.Stderr and asserts the FormatStaleError block
    reaches the operator (drift-report wiring T3.7 added is
    end-to-end alive in the v2 loader path).

# Test infrastructure

- cmd/wfctl/main_test.go: NEW TestMain forces
  WFCTL_DIFFCACHE=disabled so the platform diffcache (process-
  scoped via getDiffCache lazy init) doesn't observe stale entries
  from a developer's local ~/.cache/wfctl/diff/ as false-positive
  cache hits skipping driver Diff dispatch. Same pattern as
  platform/main_test.go from T3.6f. Caught during dev when the
  end-to-end test failed in the full cmd/wfctl test run but passed
  in isolation.

# Bug-class context

The Option-A draft (real gRPC binary; not retained on this branch
per the ADR) surfaced a real wfctl bug fixed in commit 40e07a1
(remoteResourceDriver.Diff sensitiveToAny conversion). The bug
exists independent of which T3.9 option ships; the fix is in tree
and surfaces in T3.10's PR description as the third W-3b
incidentally-fixed bug.
W-3b T3.10. Stages the W-3b PR body text in docs/prs/w3b-pr-body.md
as a stable artifact the team-lead can copy-paste at PR-open time.
Pure-additive doc; no code changes.

Captures all three incidentally-fixed bugs surfaced during W-3b's
binding dispatch wiring:

1. Delete-via-Apply state leakage (T3.3 doDelete + T3.7 dispatch)
2. ForceNew silently downgraded to Update (T3.6e replace emission)
3. map[string]bool drops gRPC args silently — sensitiveToAny
   converter (commit 40e07a1; surfaced during T3.9 runtime
   validation; v1 plugins never tripped it)

Includes summary, BREAKING-change call-out, ADR reference, rollout
notes, and test plan.
Per spec-reviewer's adversarial review of the prior keeps-grpc-stub
variant: the durability invariant for recording-decisions requires
preserving ALL transitions of a deliberation, not just the final
landing. The original ADR (loader-seam variant) recorded only one
team-lead direction; the keeps-grpc-stub variant (since superseded)
recorded only one reversal. Neither captured the full B → A → B → A →
B oscillation that played out during T3.9 execution.

This commit:

- Status header updated to "Accepted (with extensive deliberation
  history — see Decision history section)".
- Context section adjusted to preface the deliberation history
  rather than imply a single-direction trajectory.
- New Decision history section lists all 5 transitions with
  verbatim team-lead quotes + per-transition implementer action.
- Final paragraph captures the meta-lesson: when team-lead path-
  flips mid-execution, reviewer + implementer should refuse to
  proceed and force explicit disambiguation. Both reviewers
  endorsed this hold during transition 4; the strict-interpretation
  invariant from using-superpowers was the operative rule.

Pure ADR amendment; no code changes. Branch state (c9101ba T3.9
loader-seam + d2e50d4 T3.10 PR body) unaffected.

Closes spec-reviewer's Issue 1 from c9101ba pre-review:
"ADR-history erasure: cherry-picking 92f060e onto 40e07a1 erased
the durable record of team-lead's 'Path #1 — keep A' reversal.
Future branch-readers will see no record of why Option A was
considered + rejected."
…t-in

W-6/T6.1: gate replace and delete actions targeting `protected: true`
resources behind a per-resource opt-in flag at apply time. Without
--allow-replace=<csv>, the apply errors before any provider Apply or
wfctlhelpers.ApplyPlan dispatch with the design-spec literal
("resource %q is protected: true and would be %sd; pass
--allow-replace=%s to override"). With the resource name listed in
--allow-replace, the protection is bypassed for that resource only.

Gate fires on both dispatch paths — live-diff (applyWithProviderAndStore)
and --plan (applyPrecomputedPlanWithStore) — so the safety guarantee
holds regardless of plan provenance. The protected flag is sourced from
Resource.Config for replace actions and Current.AppliedConfig for delete
actions (where platform.differ leaves Resource.Config empty).

The allow-set is published via package-level applyAllowReplaceSet
(matching the computeInfraPlan / applyV2ApplyPlanFn seam pattern) and
reset to nil at the top of every runInfraApply via deferred cleanup —
override authorization must not leak across runs.

T6.2 will swap this fail-fast for an aggregated multi-blocker report
with a copy-paste --allow-replace=name1,name2,... value.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…aste flag

W-6/T6.2: validateAllowReplaceProtected now walks the entire plan and
aggregates ALL replace/delete blockers (resources annotated
`protected: true` and not in --allow-replace) into a single error,
instead of failing fast on the first one. The operator sees the
complete blocker set in one apply attempt and gets a pre-formatted
copy-paste flag value to authorize them all at once:

  plan would require destructive action on N protected resource(s):
    <name1> (replace)
    <name2> (delete)
    ...
  to authorize, re-run with:
    --allow-replace=<name1>,<name2>,...

Names and the csv preserve plan-action declaration order so output is
deterministic. The single-blocker case still emits the batch format —
operator-facing UX is consistent regardless of blocker count, which
matters for automation pinning the copy-paste flag pattern.

Per plan T6.2 "(or apply-time check; pick one — apply is cleaner since
plan output already shows all actions)" — the gate stays in
cmd/wfctl/infra_apply.go rather than platform/differ.go::ComputePlan.
ComputePlan remains plugin-agnostic; the protected-resource policy is
a wfctl-side operator-experience concern.

T6.1's single-line error literal is superseded; T6.1 tests are
updated to assert on the operator-facing essentials (resource name +
copy-paste flag value) rather than the legacy literal.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
W-6/T6.4: add a dedicated `infra apply` subsection to docs/WFCTL.md
covering the protected-resource gate, the new --allow-replace=<csv>
override, and its relation to the older --allow-protected-prune flag.
Includes the canonical aggregated-blocker error format from T6.2 so
operators know what to expect (and what to copy-paste) when the gate
fires, plus three runnable examples (standard apply, --plan apply,
authorized Replace cascade).

Per W-4 team-lead Option-3, mdformat is waived; markdown-link-check
is the meaningful baseline. WFCTL.md links all resolve clean against
the local repo (3 internal/external refs). Pre-existing dead links
elsewhere in docs/ are unchanged by this commit and out of W-6 scope.

Verification:
  markdown-link-check docs/WFCTL.md → 0 errors
  GOWORK=off go test -race -count=1 ./interfaces/... ./iac/... \
    ./platform/... ./cmd/wfctl/... ./module/... → all pass

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 4, 2026 07:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit per-resource opt-in (--allow-replace) to permit replace/delete actions on protected: true IaC resources during wfctl infra apply, and improves operator UX by aggregating all protected blockers into a single copy/paste-ready error.

Changes:

  • Introduces --allow-replace=<csv> parsing + a pre-dispatch protected-resource gate for both live-diff and --plan apply paths.
  • Aggregates all protected replace/delete blockers into one deterministic error message (including a ready-to-use --allow-replace=... value).
  • Documents the new flag and gate behavior in docs/WFCTL.md, and adds targeted unit/integration tests for the new behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/WFCTL.md Adds infra apply flag documentation and explains the protected-resource gate + examples.
cmd/wfctl/infra.go Registers --allow-replace flag and wires parsed allow-list into the apply invocation lifecycle.
cmd/wfctl/infra_apply.go Implements allow-list parsing + protected gate (batch blocker reporting) and enforces it in both apply paths.
cmd/wfctl/infra_apply_allow_replace_test.go Tests allow-list parsing and verifies gate behavior in both live-diff and --plan paths.
cmd/wfctl/infra_apply_batch_blockers_test.go Pins the aggregated multi-blocker error format and deterministic ordering behavior.

Comment thread cmd/wfctl/infra_apply.go Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

⏱ Benchmark Results

No significant performance regressions detected.

benchstat comparison (baseline → PR)
## benchstat: baseline → PR
baseline-bench.txt:254: parsing iteration count: invalid syntax
baseline-bench.txt:337638: parsing iteration count: invalid syntax
baseline-bench.txt:673717: parsing iteration count: invalid syntax
baseline-bench.txt:995666: parsing iteration count: invalid syntax
baseline-bench.txt:1315032: parsing iteration count: invalid syntax
baseline-bench.txt:1610287: parsing iteration count: invalid syntax
benchmark-results.txt:254: parsing iteration count: invalid syntax
benchmark-results.txt:412803: parsing iteration count: invalid syntax
benchmark-results.txt:821476: parsing iteration count: invalid syntax
benchmark-results.txt:1230386: parsing iteration count: invalid syntax
benchmark-results.txt:1639125: parsing iteration count: invalid syntax
benchmark-results.txt:2041210: parsing iteration count: invalid syntax
goos: linux
goarch: amd64
pkg: github.com/GoCodeAlone/workflow/dynamic
cpu: AMD EPYC 9V74 80-Core Processor                
                            │ baseline-bench.txt │        benchmark-results.txt        │
                            │       sec/op       │    sec/op     vs base               │
InterpreterCreation-4              3.300m ± 196%   3.539m ± 67%        ~ (p=0.937 n=6)
ComponentLoad-4                    3.529m ±   6%   2.754m ± 13%  -21.95% (p=0.002 n=6)
ComponentExecute-4                 1.833µ ±   2%   1.411µ ±  0%  -23.03% (p=0.002 n=6)
PoolContention/workers-1-4        1025.0n ±   3%   809.5n ±  3%  -21.02% (p=0.002 n=6)
PoolContention/workers-2-4        1035.0n ±   4%   810.0n ±  1%  -21.73% (p=0.002 n=6)
PoolContention/workers-4-4        1030.5n ±   1%   803.4n ±  2%  -22.04% (p=0.002 n=6)
PoolContention/workers-8-4        1027.0n ±   1%   791.5n ±  2%  -22.94% (p=0.002 n=6)
PoolContention/workers-16-4       1034.0n ±   2%   793.1n ±  1%  -23.30% (p=0.002 n=6)
ComponentLifecycle-4               3.545m ±   0%   2.767m ±  1%  -21.93% (p=0.002 n=6)
SourceValidation-4                 2.066µ ±   2%   1.637µ ±  1%  -20.76% (p=0.002 n=6)
RegistryConcurrent-4               763.0n ±   2%   582.1n ±  2%  -23.71% (p=0.002 n=6)
LoaderLoadFromString-4             3.600m ±   1%   2.809m ±  1%  -21.98% (p=0.002 n=6)
geomean                            16.78µ          13.41µ        -20.11%

                            │ baseline-bench.txt │        benchmark-results.txt         │
                            │        B/op        │     B/op      vs base                │
InterpreterCreation-4               2.027Mi ± 0%   2.027Mi ± 0%       ~ (p=0.734 n=6)
ComponentLoad-4                     2.180Mi ± 0%   2.180Mi ± 0%       ~ (p=0.615 n=6)
ComponentExecute-4                  1.203Ki ± 0%   1.203Ki ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-1-4          1.203Ki ± 0%   1.203Ki ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-2-4          1.203Ki ± 0%   1.203Ki ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-4-4          1.203Ki ± 0%   1.203Ki ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-8-4          1.203Ki ± 0%   1.203Ki ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-16-4         1.203Ki ± 0%   1.203Ki ± 0%       ~ (p=1.000 n=6) ¹
ComponentLifecycle-4                2.183Mi ± 0%   2.183Mi ± 0%       ~ (p=1.000 n=6)
SourceValidation-4                  1.984Ki ± 0%   1.984Ki ± 0%       ~ (p=1.000 n=6) ¹
RegistryConcurrent-4                1.133Ki ± 0%   1.133Ki ± 0%       ~ (p=1.000 n=6) ¹
LoaderLoadFromString-4              2.182Mi ± 0%   2.182Mi ± 0%       ~ (p=0.102 n=6)
geomean                             15.25Ki        15.25Ki       +0.00%
¹ all samples are equal

                            │ baseline-bench.txt │        benchmark-results.txt        │
                            │     allocs/op      │  allocs/op   vs base                │
InterpreterCreation-4                15.68k ± 0%   15.68k ± 0%       ~ (p=1.000 n=6)
ComponentLoad-4                      18.02k ± 0%   18.02k ± 0%       ~ (p=1.000 n=6)
ComponentExecute-4                    25.00 ± 0%    25.00 ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-1-4            25.00 ± 0%    25.00 ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-2-4            25.00 ± 0%    25.00 ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-4-4            25.00 ± 0%    25.00 ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-8-4            25.00 ± 0%    25.00 ± 0%       ~ (p=1.000 n=6) ¹
PoolContention/workers-16-4           25.00 ± 0%    25.00 ± 0%       ~ (p=1.000 n=6) ¹
ComponentLifecycle-4                 18.07k ± 0%   18.07k ± 0%       ~ (p=1.000 n=6) ¹
SourceValidation-4                    32.00 ± 0%    32.00 ± 0%       ~ (p=1.000 n=6) ¹
RegistryConcurrent-4                  2.000 ± 0%    2.000 ± 0%       ~ (p=1.000 n=6) ¹
LoaderLoadFromString-4               18.06k ± 0%   18.06k ± 0%       ~ (p=1.000 n=6) ¹
geomean                               183.3         183.3       +0.00%
¹ all samples are equal

pkg: github.com/GoCodeAlone/workflow/middleware
                                  │ baseline-bench.txt │       benchmark-results.txt        │
                                  │       sec/op       │   sec/op     vs base               │
CircuitBreakerDetection-4                  300.0n ± 6%   230.3n ± 4%  -23.23% (p=0.002 n=6)
CircuitBreakerExecution_Success-4          22.68n ± 0%   17.58n ± 0%  -22.50% (p=0.002 n=6)
CircuitBreakerExecution_Failure-4          70.94n ± 0%   55.18n ± 0%  -22.21% (p=0.002 n=6)
geomean                                    78.45n        60.68n       -22.65%

                                  │ baseline-bench.txt │       benchmark-results.txt        │
                                  │        B/op        │    B/op     vs base                │
CircuitBreakerDetection-4                 144.0 ± 0%     144.0 ± 0%       ~ (p=1.000 n=6) ¹
CircuitBreakerExecution_Success-4         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
CircuitBreakerExecution_Failure-4         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                              ²               +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                  │ baseline-bench.txt │       benchmark-results.txt        │
                                  │     allocs/op      │ allocs/op   vs base                │
CircuitBreakerDetection-4                 1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=6) ¹
CircuitBreakerExecution_Success-4         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
CircuitBreakerExecution_Failure-4         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                              ²               +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

pkg: github.com/GoCodeAlone/workflow/module
                                 │ baseline-bench.txt │        benchmark-results.txt        │
                                 │       sec/op       │    sec/op     vs base               │
JQTransform_Simple-4                     811.4n ± 31%   654.4n ± 22%  -19.35% (p=0.002 n=6)
JQTransform_ObjectConstruction-4         1.395µ ±  1%   1.086µ ±  1%  -22.19% (p=0.002 n=6)
JQTransform_ArraySelect-4                3.355µ ±  1%   2.730µ ±  2%  -18.63% (p=0.002 n=6)
JQTransform_Complex-4                    41.65µ ±  2%   33.18µ ±  0%  -20.35% (p=0.002 n=6)
JQTransform_Throughput-4                 1.712µ ±  1%   1.322µ ±  0%  -22.81% (p=0.002 n=6)
SSEPublishDelivery-4                     64.84n ±  2%   50.14n ±  4%  -22.68% (p=0.002 n=6)
geomean                                  1.612µ         1.273µ        -21.02%

                                 │ baseline-bench.txt │        benchmark-results.txt         │
                                 │        B/op        │     B/op      vs base                │
JQTransform_Simple-4                   1.273Ki ± 0%     1.273Ki ± 0%       ~ (p=1.000 n=6) ¹
JQTransform_ObjectConstruction-4       1.773Ki ± 0%     1.773Ki ± 0%       ~ (p=1.000 n=6) ¹
JQTransform_ArraySelect-4              2.625Ki ± 0%     2.625Ki ± 0%       ~ (p=1.000 n=6) ¹
JQTransform_Complex-4                  16.22Ki ± 0%     16.22Ki ± 0%       ~ (p=1.000 n=6) ¹
JQTransform_Throughput-4               1.984Ki ± 0%     1.984Ki ± 0%       ~ (p=1.000 n=6) ¹
SSEPublishDelivery-4                     0.000 ± 0%       0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                             ²                 +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                 │ baseline-bench.txt │       benchmark-results.txt        │
                                 │     allocs/op      │ allocs/op   vs base                │
JQTransform_Simple-4                     10.00 ± 0%     10.00 ± 0%       ~ (p=1.000 n=6) ¹
JQTransform_ObjectConstruction-4         15.00 ± 0%     15.00 ± 0%       ~ (p=1.000 n=6) ¹
JQTransform_ArraySelect-4                30.00 ± 0%     30.00 ± 0%       ~ (p=1.000 n=6) ¹
JQTransform_Complex-4                    324.0 ± 0%     324.0 ± 0%       ~ (p=1.000 n=6) ¹
JQTransform_Throughput-4                 17.00 ± 0%     17.00 ± 0%       ~ (p=1.000 n=6) ¹
SSEPublishDelivery-4                     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                             ²               +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

pkg: github.com/GoCodeAlone/workflow/schema
                                    │ baseline-bench.txt │       benchmark-results.txt        │
                                    │       sec/op       │   sec/op     vs base               │
SchemaValidation_Simple-4                  1125.5n ± 17%   852.2n ± 5%  -24.28% (p=0.002 n=6)
SchemaValidation_AllFields-4                1.650µ ±  2%   1.271µ ± 1%  -22.98% (p=0.002 n=6)
SchemaValidation_FormatValidation-4         1.589µ ±  1%   1.234µ ± 2%  -22.34% (p=0.002 n=6)
SchemaValidation_ManySchemas-4              1.616µ ±  2%   1.268µ ± 1%  -21.57% (p=0.002 n=6)
geomean                                     1.478µ         1.141µ       -22.80%

                                    │ baseline-bench.txt │       benchmark-results.txt        │
                                    │        B/op        │    B/op     vs base                │
SchemaValidation_Simple-4                   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
SchemaValidation_AllFields-4                0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
SchemaValidation_FormatValidation-4         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
SchemaValidation_ManySchemas-4              0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                ²               +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                    │ baseline-bench.txt │       benchmark-results.txt        │
                                    │     allocs/op      │ allocs/op   vs base                │
SchemaValidation_Simple-4                   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
SchemaValidation_AllFields-4                0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
SchemaValidation_FormatValidation-4         0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
SchemaValidation_ManySchemas-4              0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                ²               +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

pkg: github.com/GoCodeAlone/workflow/store
                                   │ baseline-bench.txt │        benchmark-results.txt        │
                                   │       sec/op       │    sec/op     vs base               │
EventStoreAppend_InMemory-4               1061.5n ± 10%   758.8n ±  6%  -28.52% (p=0.002 n=6)
EventStoreAppend_SQLite-4                  1.053m ±  4%   2.006m ± 89%  +90.46% (p=0.002 n=6)
GetTimeline_InMemory/events-10-4          12.886µ ±  4%   7.617µ ± 34%  -40.89% (p=0.002 n=6)
GetTimeline_InMemory/events-50-4           65.18µ ± 18%   41.91µ ±  1%  -35.70% (p=0.002 n=6)
GetTimeline_InMemory/events-100-4         106.90µ ±  1%   84.30µ ±  0%  -21.13% (p=0.002 n=6)
GetTimeline_InMemory/events-500-4          544.8µ ±  2%   431.2µ ±  1%  -20.85% (p=0.002 n=6)
GetTimeline_InMemory/events-1000-4        1106.7µ ±  3%   871.2µ ±  1%  -21.28% (p=0.002 n=6)
GetTimeline_SQLite/events-10-4             82.55µ ±  1%   68.39µ ±  2%  -17.15% (p=0.002 n=6)
GetTimeline_SQLite/events-50-4             218.2µ ±  1%   176.0µ ±  1%  -19.37% (p=0.002 n=6)
GetTimeline_SQLite/events-100-4            384.3µ ±  0%   301.8µ ±  0%  -21.47% (p=0.002 n=6)
GetTimeline_SQLite/events-500-4            1.668m ±  0%   1.313m ±  1%  -21.26% (p=0.002 n=6)
GetTimeline_SQLite/events-1000-4           3.251m ±  1%   2.564m ±  2%  -21.13% (p=0.002 n=6)
geomean                                    190.4µ         154.7µ        -18.74%

                                   │ baseline-bench.txt │         benchmark-results.txt         │
                                   │        B/op        │     B/op      vs base                 │
EventStoreAppend_InMemory-4                  781.5 ± 5%     860.0 ± 1%  +10.04% (p=0.002 n=6)
EventStoreAppend_SQLite-4                  1.983Ki ± 1%   1.986Ki ± 1%        ~ (p=0.370 n=6)
GetTimeline_InMemory/events-10-4           7.953Ki ± 0%   7.953Ki ± 0%        ~ (p=1.000 n=6) ¹
GetTimeline_InMemory/events-50-4           46.62Ki ± 0%   46.62Ki ± 0%        ~ (p=1.000 n=6) ¹
GetTimeline_InMemory/events-100-4          94.48Ki ± 0%   94.48Ki ± 0%        ~ (p=1.000 n=6) ¹
GetTimeline_InMemory/events-500-4          472.8Ki ± 0%   472.8Ki ± 0%        ~ (p=1.000 n=6)
GetTimeline_InMemory/events-1000-4         944.3Ki ± 0%   944.3Ki ± 0%        ~ (p=0.545 n=6)
GetTimeline_SQLite/events-10-4             16.74Ki ± 0%   16.74Ki ± 0%        ~ (p=1.000 n=6) ¹
GetTimeline_SQLite/events-50-4             87.14Ki ± 0%   87.14Ki ± 0%        ~ (p=1.000 n=6) ¹
GetTimeline_SQLite/events-100-4            175.4Ki ± 0%   175.4Ki ± 0%        ~ (p=1.000 n=6) ¹
GetTimeline_SQLite/events-500-4            846.1Ki ± 0%   846.1Ki ± 0%        ~ (p=1.000 n=6)
GetTimeline_SQLite/events-1000-4           1.639Mi ± 0%   1.639Mi ± 0%        ~ (p=0.232 n=6)
geomean                                    67.28Ki        67.83Ki        +0.81%
¹ all samples are equal

                                   │ baseline-bench.txt │        benchmark-results.txt        │
                                   │     allocs/op      │  allocs/op   vs base                │
EventStoreAppend_InMemory-4                  7.000 ± 0%    7.000 ± 0%       ~ (p=1.000 n=6) ¹
EventStoreAppend_SQLite-4                    53.00 ± 0%    53.00 ± 2%       ~ (p=1.000 n=6)
GetTimeline_InMemory/events-10-4             125.0 ± 0%    125.0 ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_InMemory/events-50-4             653.0 ± 0%    653.0 ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_InMemory/events-100-4           1.306k ± 0%   1.306k ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_InMemory/events-500-4           6.514k ± 0%   6.514k ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_InMemory/events-1000-4          13.02k ± 0%   13.02k ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_SQLite/events-10-4               382.0 ± 0%    382.0 ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_SQLite/events-50-4              1.852k ± 0%   1.852k ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_SQLite/events-100-4             3.681k ± 0%   3.681k ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_SQLite/events-500-4             18.54k ± 0%   18.54k ± 0%       ~ (p=1.000 n=6) ¹
GetTimeline_SQLite/events-1000-4            37.29k ± 0%   37.29k ± 0%       ~ (p=1.000 n=6) ¹
geomean                                     1.162k        1.162k       +0.00%
¹ all samples are equal

Benchmarks run with go test -bench=. -benchmem -count=6.
Regressions ≥ 20% are flagged. Results compared via benchstat.

…tion at apply call site (Copilot review)

DispatchVersionFor is documented to centralise the type-assertion plus
the default-to-v1 fallback so call sites pass the raw provider value
rather than re-asserting the optional interface. The v2 dispatch
condition reverts to the canonical form:

    if wfctlhelpers.DispatchVersionFor(provider) == wfctlhelpers.DispatchVersionV2 { ... }

No behavior change: a provider that doesn't implement the interface,
or returns anything other than "v2", still routes to the legacy v1
provider.Apply path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@intel352 intel352 merged commit 4ef2d2a into main May 4, 2026
17 of 18 checks passed
@intel352 intel352 deleted the feat/iac-allow-replace branch May 4, 2026 07:56
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