Conversation
|
after looking into Jest snapshot capabilities to mask out variants. Short answer: yes, but not as a config-level pattern rule — the hook is a custom snapshot serializer. There is no regex/ What Jest actually offers
Keys were the thing worth checking, since the variance here is in keys. Verified with the repo's jest 30: a serializer whose // registry-serializer.cjs
module.exports = {
test: (val) => typeof val === "string" && val.includes("registry.opentofu.org"),
print: (val) =>
JSON.stringify(val.replaceAll("registry.opentofu.org", "registry.terraform.io")),
};// jest.config.js
module.exports = { snapshotSerializers: ["<rootDir>/registry-serializer.cjs"] };Snapshotting exports[`value and key handling 1`] = `
{
"registry.terraform.io/hashicorp/null": "3.1.0",
}
`;Nested FQPN keys included, from one shared module. Note the serializer must be a JS/CJS file the snapshot runtime can How I'd apply it to the registry-host varianceThe variance is a single fact — the host records which CLI fetched the schema, not anything about the generated code — and it reaches expectations through three snapshot sites plus one assertion:
So the pragmatic split is: keep the value-level normalisation for the non-snapshot assertion, and consider moving the snapshot-side handling into one serializer registered where both packages pick it up (shared preset, or Two notes on the existing attempt, neither blocking:
Separate finding on this PR: the tofu row appears twice
- terraform_version: "1.12.6"
terraform_binary: tofu1.12.6
- terraform_version: "1.12.6"
terraform_binary: tofu1.12.6That fans the job out to four rows and produces two identically named Docs: snapshotSerializers · snapshotFormat · snapshotResolver · expect.addSnapshotSerializer · property matchers |
7d67654 to
b996c63
Compare
|
The duplicate Follow-up PR: changing registry targets can leave generated documentation links stale
As a result, if a project runs Fix in this PR: OpenTofu URLs are still labeled “Terraform Registry”For an OpenTofu-only project, Please fix this in the current PR, either by making the display name part of the registry abstraction or by using registry-neutral wording such as “provider documentation.” |
|
for the first finding.. if changing the project targetVersions doesn't follow a change of the binary used to run get (which .. would trigger a new fetch and gen?) them not doing a churn on the generated docstrings is - by design? |
b996c63 to
b40c1be
Compare
Re-lands open-constructs#439 with the fixtures actually fixed. That PR passed vacuously - its diff touched only pr-unit.yml, so `nx affected` resolved to no terraform-tagged projects and the tofu job ran zero tests. It then failed on every PR that touched one, and was reverted in open-constructs#446. This branch touches provider-generator and provider-schema, so the tofu job runs for real on its own PR. Four things had to change, in two classes. Unsigned providers OpenTofu rejects: - versions-file.test.ts pinned kreuzwerker/docker 2.16.0 and provider.test.ts pinned 3.0.2. Both move to 3.9.0; signing starts at 3.7.0, not at the 3.x major (open-constructs#440). - provider.test.ts used andsafe-AG/bitbucket, which exists on the Terraform registry but not on OpenTofu's. It needs two same-named providers from different namespaces, so it moves to zahiar/bitbucket, which is on both. Fully qualified names leaking the fetching CLI into expectations. The schema JSON is keyed by FQPN, so the host records which binary fetched it rather than anything about the code under test: - provider-schema.test.ts snapshots the raw schema. Its sanitizer already stubs format_version, cli_name and cli_version for this exact reason; provider_schemas and provider_versions keys now get the same treatment. Keys only - a host inside provider documentation text is identical either way and stays as authored. - versions-file.test.ts asserted keys equal to `registry.terraform.io/${fqn}`; it now compares the provider part. - provider.test.ts snapshots a generated directory including versions.json; FQPN keys are normalized there too. Verified against both CLIs rather than assumed: @cdktn/provider-generator 23 suites / 117 tests / 101 snapshots and @cdktn/provider-schema 6 suites / 58 tests / 10 snapshots pass under terraform and under OpenTofu 1.12.6. The generated docs links that also differed by CLI are fixed by open-constructs#443, which this is stacked on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…nts at Review finding on open-constructs#447. open-constructs#443 made linkToDocs follow the project's declared targetVersions, but the prose around it stayed hardcoded: an OpenTofu-only project got "Refer to the Terraform Registry for docs" above a search.opentofu.org link, and "Docs at Terraform Registry" on every struct attribute. The registry now carries its own display name, and ResourceModel exposes it beside the link it already derives, so the two cannot disagree. Taking the abstraction option rather than neutral wording keeps the text specific - readers of an OpenTofu project see "OpenTofu Registry", not "provider documentation". No snapshots move: every fixture declares no targetVersions, which resolves to Terraform, so the emitted text is unchanged. provider-generator stays at 23 suites / 117 tests / 101 snapshots. A unit test covers the OpenTofu branch that no fixture exercises, asserting the name and the link host together. Not changed: module-generator's "Docs at Terraform Registry" for registry modules. That one hardcodes its own registry.terraform.io module URL, so it is self-consistent; module sources are a separate question from provider docs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
b40c1be to
b060ea5
Compare
Related issue
Re-lands #439, reverted in #446. Stacked on #443 — merge that first; this branch contains its commit.
If this is approved before #446, #446 can be dropped. Otherwise this is the follow-up to it.
Why #439 failed
Its diff touched only
.github/workflows/pr-unit.yml. The job it adds runsnx affected -t test --exclude='*,!tag:unit-test:terraform', so on a workflow-only changenx affectedresolved to no terraform-tagged projects and the OpenTofu job ran zero tests. The green check proved nothing, and it then failed on every PR that touched a tagged project.This branch touches
provider-generatorandprovider-schema, so the tofu job runs for real on its own PR. That is the point — a change topr-unit.ymlalone can never demonstrate this.What actually had to be fixed
Four fixtures, in two classes. The first was expected; the second was not, and is the more interesting one.
Providers OpenTofu will not install
versions-file.test.tspinnedkreuzwerker/docker2.16.0,provider.test.tspinned 3.0.2. Both rejected as unsigned. Moved to 3.9.0 — signing starts at 3.7.0, not at the 3.x major (test(tests): move the python providers fixture to Docker provider 3.9.0 #440).provider.test.tsusedandsafe-AG/bitbucket, which is on the Terraform registry but 404s on OpenTofu's. That test needs two same-named providers from different namespaces, so it moves tozahiar/bitbucket, which is on both.Fully qualified names leaking the fetching CLI into expectations
The schema JSON is keyed by FQPN, so the host records which binary fetched it, not anything about the code under test. Three places baked Terraform's in:
provider-schema.test.tsversions-file.test.tsregistry.terraform.io/${fqn}provider.test.tsversions.jsonFor
provider-schema.test.tsthis extends a pattern already there: itssanitizeJsonstubsformat_version,cli_nameandcli_versionfor exactly this reason —cli_nameis already stubbed because it stamps the fetching binary, and the FQPN host is the same signal through a different field.Keys only. A registry URL appearing inside provider documentation text is identical under either CLI and stays as authored.
Normalizing happens in the tests, not the product: the FQPN host is meaningful at runtime — #443 and #445 depend on it — so stripping it in the product would destroy information.
Verified against both CLIs
Not assumed, and not inferred from a green matrix job:
@cdktn/provider-generator@cdktn/provider-schemaThe generated documentation links that also differed by CLI are fixed by #443, which this is stacked on — without it,
provider.test.tsstill diverges.🤖 Generated with Claude Code