feat: a stated choice must reach a requirement, and only pinned providers (iteration 9 step 3)
Some checks failed
validation / verify (push) Failing after 11s

Case 08 named the customer's stated topology in its design and did not build
it; every Check passed because none asked for it.

- The catalogue marks the 26 fields that bind a design. The agreed scope lists
  the ones the customer stated; what was assumed for them does not bind.
- A requirement says what it comes from. A submission of requirements is
  refused when one of the customer's own requirements, or a stated binding
  field, is named by none, or when the requirement carrying a choice is not a
  constraint with a condition. The existing chain then owes it a Check.
- Generated code may use only the providers the bundle pins: a resource or a
  required_providers entry of any other is refused before Terraform runs.
- The guide opens with how much of the design the customer stated, how much
  was assumed and how much is unknown.

Not run with real models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 19:36:12 +01:00
parent c26b744b26
commit 0f80cb642f
16 changed files with 469 additions and 12 deletions

View File

@@ -143,8 +143,10 @@ class TerraformRunner:
)
async def validate(self, files: Mapping[str, str]) -> ToolResult:
refusal = _check_files(files) or check_module_sources(
files, allowed_namespaces(self.module_namespaces)
refusal = (
_check_files(files)
or check_providers(files, self.providers)
or check_module_sources(files, allowed_namespaces(self.module_namespaces))
)
if refusal:
return refusal
@@ -160,8 +162,10 @@ class TerraformRunner:
async def plan(
self, files: Mapping[str, str], variables: Mapping[str, str] | None = None
) -> ToolResult:
refusal = _check_files(files) or check_module_sources(
files, allowed_namespaces(self.module_namespaces)
refusal = (
_check_files(files)
or check_providers(files, self.providers)
or check_module_sources(files, allowed_namespaces(self.module_namespaces))
)
if refusal:
return refusal
@@ -363,6 +367,45 @@ class TerraformRunner:
return process.returncode or 0, stdout.decode(errors="replace")
_BLOCK_TYPE = re.compile(
r'^\s*(?:resource|data)\s+"([a-z0-9]+)_[a-z0-9_]*"', re.MULTILINE
)
_PROVIDER_SOURCE = re.compile(r'^\s*source\s*=\s*"([\w.-]+/[\w.-]+)"\s*$', re.MULTILINE)
# Built into Terraform itself: terraform_data and the terraform_remote_state source.
_BUILT_IN = frozenset({"terraform"})
def check_providers(
files: Mapping[str, str], pinned: Mapping[str, Mapping[str, str]]
) -> ToolResult | None:
"""Refuse code that uses a provider the bundle does not pin.
`terraform init` downloads whatever provider the code names, at whatever
version is current. A design with a source repository in it brought the GitHub
provider into generated code that way on 2026-10-11. With nothing pinned there
is nothing to hold code to, and it passes.
"""
if not pinned:
return None
names = set(pinned) | _BUILT_IN
sources = {pin["source"] for pin in pinned.values()}
code = "\n".join(text for name, text in files.items() if name.endswith(".tf"))
foreign = sorted({m.group(1) for m in _BLOCK_TYPE.finditer(code)} - names)
undeclared = sorted({m.group(1) for m in _PROVIDER_SOURCE.finditer(code)} - sources)
if not foreign and not undeclared:
return None
found = [f"resources of the {name} provider" for name in foreign]
found += [f"the provider {source}" for source in undeclared]
return ToolResult(
"Refused: the code uses "
+ ", ".join(found)
+ ". Only these providers may be used: "
+ ", ".join(sorted(sources))
+ ". Write resources of those alone, and describe anything outside them in "
"the deployment guidance as a step the user takes."
)
def _check_files(files: Mapping[str, str]) -> ToolResult | None:
if not files:
return ToolResult("Refused: provide at least one Terraform file.")