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:
@@ -383,3 +383,72 @@ def test_the_cache_setting_resolves_under_the_repository_and_can_be_disabled():
|
||||
).terraform_plugin_cache()
|
||||
== "/var/cache/tf"
|
||||
)
|
||||
|
||||
|
||||
# --- only the providers the bundle pins ---------------------------------------------------
|
||||
|
||||
PINNED = {"cloud": {"source": "example/cloud", "version": "1.2.3"}}
|
||||
|
||||
|
||||
def provider_refusal(code: str, pinned=PINNED) -> str:
|
||||
from app.tools.local import check_providers
|
||||
|
||||
result = check_providers({"terraform/main.tf": code}, pinned)
|
||||
return result.message if result else ""
|
||||
|
||||
|
||||
def test_code_of_the_pinned_provider_alone_is_accepted():
|
||||
code = """
|
||||
terraform {
|
||||
required_providers {
|
||||
cloud = {
|
||||
source = "example/cloud"
|
||||
version = "1.2.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
resource "cloud_service" "web" {}
|
||||
data "cloud_project" "this" {}
|
||||
resource "terraform_data" "marker" {}
|
||||
module "network" {
|
||||
source = "example-modules/network/cloud"
|
||||
version = "1.0.0"
|
||||
}
|
||||
"""
|
||||
|
||||
assert provider_refusal(code) == ""
|
||||
|
||||
|
||||
def test_a_resource_of_a_provider_that_is_not_pinned_is_refused():
|
||||
message = provider_refusal('resource "sourcehost_repository" "infra" {}')
|
||||
|
||||
assert message.startswith("Refused: the code uses resources of the sourcehost")
|
||||
assert "Only these providers may be used: example/cloud" in message
|
||||
|
||||
|
||||
def test_declaring_another_provider_is_refused():
|
||||
declared = """
|
||||
terraform {
|
||||
required_providers {
|
||||
sourcehost = {
|
||||
source = "integrations/sourcehost"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
assert "the provider integrations/sourcehost" in provider_refusal(declared)
|
||||
|
||||
|
||||
def test_with_nothing_pinned_there_is_nothing_to_hold_code_to():
|
||||
assert provider_refusal('resource "anything_at_all" "x" {}', pinned={}) == ""
|
||||
|
||||
|
||||
async def test_validation_refuses_a_foreign_provider_before_terraform_runs():
|
||||
runner = TerraformRunner(binary="no-such-binary", providers=PINNED)
|
||||
|
||||
result = await runner.validate(
|
||||
{"terraform/main.tf": 'resource "sourcehost_repository" "infra" {}'}
|
||||
)
|
||||
|
||||
assert result.message.startswith("Refused: the code uses")
|
||||
|
||||
Reference in New Issue
Block a user