Skip to content

feat(search): verify exact speculative import plans (6/6) - #591

Open
sowju-hashicorp wants to merge 1 commit into
sowju/search-05-prepare-importfrom
sowju/search-06-verify-plan
Open

sowju-hashicorp wants to merge 1 commit into
sowju/search-05-prepare-importfrom
sowju/search-06-verify-plan

Conversation

@sowju-hashicorp

Copy link
Copy Markdown

Summary

PR 6 of 6 in the Terraform Search stack.

Branch: sowju/search-06-verify-plan
Base: sowju/search-05-prepare-import

Adds read-only verify_import_plan on both MCP SDKs, completing the Search-to-import assistance workflow with verification of one exact speculative Run and its associated Plan.

Changes

  • Accepts the exact Run ID for the confirmed target rather than discovering or substituting the latest Run.
  • Verifies backend workspace association and explicit plan-only=true / auto-apply=false evidence.
  • Resolves Plan and configuration-version relationships from the backend Run.
  • Handles pending and terminal states with bounded polling and caller cancellation.
  • Requires unchanged preparation context and one unique marker-to-address binding per selection before finished-Plan JSON classification.
  • Classifies selected Plan actions independently from object identity.
  • Reports relevant extra imports, unrelated managed actions, drift, and deferred effects.
  • Preserves complete structured and JSON-text results across both SDKs.
  • Adds verifier, guard, adapter, full-workflow tests, and final workflow documentation.

Security and evidence boundaries

  • Does not trust caller-supplied Plan or configuration-version IDs.
  • Prevents Plan JSON classification before target, Run, lifecycle, context, and binding checks succeed.
  • Allows context-free polling, but requires preparation context and bindings for finished-Plan classification.
  • Keeps carried selection evidence stateless: no hidden session-held identity data or replacement with newer QueryRun evidence.
  • Treats markers and the context digest as continuity checks—not authentication or tamper-proof attestation.
  • Preserves unknown or mismatched identity findings independently of action classification. A no-op action or import ID does not prove cloud-object identity.
  • Returns selective findings without reproducing raw sensitive Plan values.
  • Successful classification does not prove uploaded configuration bytes, effective provider scope, or apply safety.

Read-only boundary

verify_import_plan does not create Runs, upload configuration, modify workspaces, execute imports, write state, or apply changes.

The workflow ends at reviewed configuration and Plan findings. Full Plan review and any subsequent action remain separate user decisions.

Validation

  • Focused tests passed for Search logic, client middleware, both SDK integrations, registration, toolsets, instructions, and CLI.
  • Coverage includes Run/target association, plan-only guards, missing or altered context, invalid bindings, pending behavior, cancellation, and failed Plan states.
  • Guard tests verify that ineligible requests do not trigger premature Plan JSON reads.
  • Fixture-backed workflow and cross-SDK compatibility tests passed.
  • Final package/command test suite, server build, and diff checks passed.
  • Cumulative source comparison confirmed preservation of Search runtime declarations after helper relocation, including the 256 MiB decoded-log ceiling.
  • No live HCP Terraform operations were performed.

Reviewer focus

  • Exact Run, target, Plan, and configuration-version associations.
  • Ordering of preflight guards before Plan JSON access.
  • Stateless context validation and unique selection/address bindings.
  • Independent action and identity classifications.
  • Sensitive-data handling, adapter compatibility, and the no-apply boundary.

Stack scope

Depends on PR 5 for explicitly selected evidence and stateless import context. Set this PR's base to sowju/search-05-prepare-import so the diff shows only verification and final workflow coverage.

This completes the six-layer stack:

  1. Provider discovery and shared foundation.
  2. Schema-backed query guidance.
  3. Query execution and bounded status polling.
  4. Validated streaming summaries and generated-HCL projections.
  5. Explicit import preparation.
  6. Exact speculative Plan verification.

Configuration upload, Run creation for import planning, import execution, and apply remain out of scope.

Rollback

Revert this PR to remove Plan verification while retaining the preceding Search and preparation capabilities.

The verifier performs no remote mutations, so no data migration or infrastructure rollback is required. Existing Runs and Plans remain unchanged; any separately performed user actions must be assessed independently.

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 02:02
@sowju-hashicorp
sowju-hashicorp requested a review from a team as a code owner October 22, 2026 02:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved verifier issues affect numeric identity preservation, valid address handling, and the completeness and consistency of Plan findings.

5 open issues
What changed in this PR

Completes the Search-to-import workflow with read-only verification of an exact speculative Run and its backend-associated Plan across both MCP SDKs.

Changes:

  • Adds Run association, lifecycle, preparation-context, and binding checks before Plan classification.
  • Reports selected actions, object identity, and other Plan effects with structured and JSON-text results.
  • Extends registration, guard, transport-parity, logging, and workflow tests and documentation.
File Description
README.md Revises scope defaults and workflow documentation.
pkg/​toolsets/​toolsets.go Updates the Search toolset description.
pkg/​toolsets/​toolsets_test.go Expands Search filtering and known-tool coverage.
pkg/​toolsets/​search.go Adds verifier tool metadata.
pkg/​toolsets/​search_test.go Checks verifier credential gating.
pkg/​tools/​search/​verify_import_plan.go Implements exact-Run verification and Plan classification.
pkg/​tools/​search/​provider_validation_test.go Renames foundation tests to avoid collisions.
pkg/​tools/​search/​import_tools.go Adds the legacy verifier adapter and description.
pkg/​tools/​search/​import_tools_test.go Tests classification, output safety, and legacy responses.
pkg/​tools/​search/​import_preflight_test.go Tests context integrity, guards, polling, and cancellation.
pkg/​tools/​search/​diagnostic_codes.go Adds verification diagnostics and reorganizes shared codes.
pkg/​tools/​search/​diagnostic_codes_test.go Renames a foundation diagnostic test.
pkg/​tools/​search/​descriptions_test.go Checks tool descriptions and workflow boundaries.
pkg/​tools/​factories.go Registers the legacy verifier factory.
pkg/​tools/​factories_test.go Extends credential-based registration tests.
pkg/​mcp-official/​tools/​verify_flow_test.go Tests full-workflow transport parity and guards.
pkg/​mcp-official/​tools/​tools.go Registers the official SDK verifier.
pkg/​mcp-official/​tools/​tools_test.go Extends registration and credential tests.
pkg/​mcp-official/​tools/​source_registration_test.go Adds registration and workflow regression coverage.
pkg/​mcp-official/​tools/​search/​verify_test.go Tests verifier schemas and target confirmation.
pkg/​mcp-official/​tools/​search/​search.go Adds the official SDK verifier adapter.
pkg/​mcp-official/​tools/​search/​search_test.go Extends schema, description, and annotation tests.
pkg/​mcp-official/​tools/​middleware/​tool_logging_test.go Checks verifier argument and error logging protection.
pkg/​instructions/​instructions.md Documents separately approved planning and verification.
pkg/​instructions/​instructions_test.go Checks updated Search/import workflow boundaries.
pkg/​client/​tool_logging_middleware_test.go Checks legacy verifier argument logging protection.
CHANGELOG.md Records verification capabilities and read-only boundaries.

Review effort: Balanced

ImportContext *ImportContext `json:"import_context,omitempty" jsonschema:"Unchanged context returned by prepare_import; required for finished Plan classification"`
Bindings []ImportBinding `json:"bindings,omitempty" jsonschema:"One query result marker to exact target address binding per selection"`
DetailAddresses []string `json:"detail_addresses,omitempty" jsonschema:"Optional selected target addresses to inspect without values"`
}
return verifyImportPollConfig{wait: verifyImportWait, interval: verifyImportInterval}
}

var importAddressPattern = regexp.MustCompile(`^[a-zA-Z0-9_\[\]".:-]+$`)
if err := collectImportPlanVersions(plan.PlannedValues.RootModule, versions, 0); err != nil {
return nil, nil, err
}
return byAddress, versions, nil
Comment on lines +647 to +649
if !jsonPresent(resource.Change.Importing) {
item.Change, item.IdentityReason = "import_missing", "no_import_marker"
return item, detail, nil

func compareImportPlanIdentity(selection ImportContextSelection, versions map[string]uint64, address string, raw json.RawMessage, terraformVersion, support string) (string, string) {
if !jsonPresent(raw) {
if old, known := terraformImportSyntaxVersion(terraformVersion); known && old {
@mjyocca
mjyocca added this pull request to stack #593 October 22, 2026 16:45
@mjyocca
mjyocca force-pushed the sowju/search-06-verify-plan branch from e22fe21 to 004bfdf Compare October 22, 2026 18:54

This branch has not been deployed

No deployments
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