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
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:
11
app/scope.py
11
app/scope.py
@@ -82,6 +82,9 @@ class FieldSpec:
|
||||
keys: tuple[str, ...] = ()
|
||||
optional_keys: tuple[str, ...] = ()
|
||||
aliases: tuple[str, ...] = ()
|
||||
# A choice a design must honour. Stated by the customer, it has to be carried
|
||||
# by a requirement, and so by a Check on the Target architecture.
|
||||
binds: bool = False
|
||||
|
||||
def tier_for(self, kind: str | None) -> str:
|
||||
if isinstance(self.tier, Mapping):
|
||||
@@ -118,6 +121,7 @@ def load_catalogue(path: Path) -> Catalogue:
|
||||
keys=tuple(raw.get("keys") or ()),
|
||||
optional_keys=tuple(raw.get("optional_keys") or ()),
|
||||
aliases=tuple(raw.get("aliases") or ()),
|
||||
binds=bool(raw.get("binds")),
|
||||
)
|
||||
return Catalogue(
|
||||
schema_version=int(data.get("schema_version", 1)),
|
||||
@@ -248,6 +252,13 @@ class Scope:
|
||||
return {
|
||||
"kind": self.kind,
|
||||
"stated": stated,
|
||||
# The stated fields a design must honour: each has to be carried by a
|
||||
# requirement, which the requirements are checked for.
|
||||
"binding": [
|
||||
path
|
||||
for path in self.values
|
||||
if self.catalogue.fields[path].binds and self.source(path) != ASSUMED
|
||||
],
|
||||
# What the agent chose where the customer did not say. Not the
|
||||
# customer's decision: it may be revisited when they answer.
|
||||
"assumed": [
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -213,9 +213,87 @@ def check_requirements(
|
||||
problems += _lacking_conditions(
|
||||
[item for item in items if item["kind"] == "non_functional"], name
|
||||
)
|
||||
problems += _carries_the_scope(items, name, upstream)
|
||||
return problems
|
||||
|
||||
|
||||
def agreed_scope(upstream: Upstream | None) -> dict[str, Any]:
|
||||
"""The agreed scope, as every Specialist reads it; empty when there is none."""
|
||||
text = (
|
||||
((upstream or {}).get("scope") or {})
|
||||
.get("attachments", {})
|
||||
.get(SCOPE_DATA_FILE, "")
|
||||
)
|
||||
try:
|
||||
data = json.loads(text) if text else {}
|
||||
except ValueError:
|
||||
return {}
|
||||
return data if isinstance(data, dict) else {}
|
||||
|
||||
|
||||
def sources_of(item: Mapping[str, Any]) -> tuple[str, ...]:
|
||||
"""What a requirement comes from: the customer's own requirement ids and the
|
||||
scope spec's fields, as its `from` lists them."""
|
||||
listed = item.get("from")
|
||||
return tuple(str(s) for s in listed) if isinstance(listed, list) else ()
|
||||
|
||||
|
||||
def _carries_the_scope(
|
||||
items: Sequence[Mapping[str, Any]], name: str, upstream: Upstream | None
|
||||
) -> list[str]:
|
||||
"""What the customer stated has to reach the requirements, by name (ADR-0008).
|
||||
|
||||
Each requirement the customer wrote, and each choice they stated that a design
|
||||
must honour, is named in the `from` of a requirement. A choice is carried by a
|
||||
non-functional requirement with a condition, so the Target architecture owes it
|
||||
a Check. Before this a stated topology could be named in a design and not built:
|
||||
case 08 on 2026-10-11 passed all 101 Checks with no Check asking for it.
|
||||
"""
|
||||
scope = agreed_scope(upstream)
|
||||
if not scope:
|
||||
return []
|
||||
stated = scope.get("stated") or {}
|
||||
theirs = [
|
||||
str(entry.get("id"))
|
||||
for entry in ((stated.get("intent") or {}).get("requirements") or [])
|
||||
if isinstance(entry, Mapping) and entry.get("id")
|
||||
]
|
||||
binding = [str(path) for path in scope.get("binding") or []]
|
||||
cited = {source for item in items for source in sources_of(item)}
|
||||
problems = [
|
||||
f"{name}: the customer's requirement {reference} is covered by no "
|
||||
"requirement; name it in the `from` of the one that covers it"
|
||||
for reference in theirs
|
||||
if reference not in cited
|
||||
]
|
||||
problems += [
|
||||
f"{name}: the customer stated {path} and no requirement carries it; add a "
|
||||
f"non-functional requirement whose `from` names {path}, with the condition "
|
||||
"that shows it was honoured"
|
||||
for path in binding
|
||||
if path not in cited
|
||||
]
|
||||
for item in items:
|
||||
carried = [source for source in sources_of(item) if source in binding]
|
||||
if carried and (
|
||||
item.get("kind") != "non_functional" or not conditions_of_listed(item)
|
||||
):
|
||||
problems.append(
|
||||
f"{name}: {item.get('id')} carries {', '.join(carried)}, a choice "
|
||||
"the customer stated; it must be non_functional with at least one "
|
||||
"entry in `conditions`, so the design is checked against it"
|
||||
)
|
||||
return problems
|
||||
|
||||
|
||||
def conditions_of_listed(item: Mapping[str, Any]) -> tuple[str, ...]:
|
||||
"""The conditions a requirement lists outright, with no fallback to its text."""
|
||||
listed = item.get("conditions")
|
||||
if not isinstance(listed, list):
|
||||
return ()
|
||||
return tuple(c.strip() for c in listed if isinstance(c, str) and c.strip())
|
||||
|
||||
|
||||
def check_components(
|
||||
attachments: Mapping[str, str], upstream: Upstream | None
|
||||
) -> list[str]:
|
||||
|
||||
Reference in New Issue
Block a user