Registry Mirror
Skip to content

Conversation

@coryodaniel

Copy link
Copy Markdown
Member

mass bundle build now warns when a dependency's cardinality in massdriver.yaml differs from the latest published version of the same bundle. Authors see the change while they develop, not after they publish.

For each changed dependency, build prints one orange warning line with the field name, both values, the published version, and what changes for users:

  • one to many: the variable becomes a map; the existing line becomes a set of one.
  • many to one: the variable becomes an object; on upgrade the field's connections are removed and the user connects one source.

No warning when the bundle has no published version, or when the field is new in this version. An empty cardinality counts as one.

How the published cardinality is read

internal/api sends a V2 bundle(organizationId, id) query that selects version and dependencies { name cardinality }. The id is the bare bundle name, so the API resolves it to the newest stable version, or the newest dev version when no stable version exists. The SDK's Bundles.Get does not select cardinality yet, so the query sits in internal/api with the other operations the SDK does not expose. It can move to the SDK when the SDK adds the field.

API failures

The check never fails the build. If the query fails for any reason (no published version, offline, no auth, a server without the cardinality field), build skips the check with no output. The CLI has no debug log level to write a line to. In practice build already needs the API: schema validation fetches bundle.json from the server and fails the build when it cannot, so an offline build stops before this check runs.

Closes #269
Refs massdriver-cloud/massdriver#3692

🤖 Generated with Claude Code

Authors learn that a field moves between one and many while they develop,
before they publish a version that changes the IaC variable and the canvas
for every instance that upgrades.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coryodaniel

Copy link
Copy Markdown
Member Author

@claude please review.

@claude

claude Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 1m 11s —— View job


Review of #271: cardinality change warning at build

Verdict: looks good. I found no blocking issues.

  • Read the diff against origin/main
  • Checked the change against CLAUDE.md
  • Ran go build ./... and the tests for internal/api and internal/commands/bundle. Both packages pass. I did not run make check (lint) or make docs.

What I checked

  • Layering: cmd/bundle.go only passes context, the client and os.Stdout through. The logic is in internal/commands/bundle behind a narrow PublishedBundleAPI interface with an injected io.Writer. No test files were added to cmd/. This follows CLAUDE.md.
  • Advisory behavior: WarnCardinalityChanges returns silently on any API error, when there are no dependencies, and when a field is new. An empty cardinality counts as one through IsMany(). Output is sorted by field name, so it is deterministic.
  • Case handling: the API returns ONE/MANY, and the adapter lowercases both before comparing with bundle.CardinalityOne and bundle.CardinalityMany.
  • Tests: they are table-driven, use hand-rolled fakes, and add cases to the existing files. They cover both change directions, no change, a new field, not found, and an API failure.
  • Docs: no command or flag changed, so make docs should produce no diff. Please confirm that in CI.

Minor suggestions (non-blocking)

  1. Context and cancellation (cmd/bundle.go:373): the cobra command already carries a context, so cmd.Context() would be better than context.Background(). A slow API would then respect Ctrl-C. Because the check is advisory, consider adding a short timeout (for example 5s) so a hung API can't stall mass bundle build.
  2. Extra round trip: the check adds one extra API call to every build of a bundle that has dependencies. That seems acceptable, since build already needs the API.
  3. Dev-version fallback (internal/api/bundle.go): when no stable version exists, the API falls back to the newest dev version, as the PR description says. The warning then compares against name@<dev version>. That is fine, but the warning wording says only "since name@version", so it may be worth stating that the comparison is against the latest published version.
  4. Query hand-written: it is an untyped struct and a raw query string, which is consistent with the rest of internal/api. The TODO to move it to the SDK is noted in the package doc, so no action is needed.
  5. Test gap: the adapter publishedBundleAPI.PublishedCardinalities (the lowercasing) has no direct test. It is trivial, but a one-case test in internal/api or build_test.go would lock in the ONE→one mapping, which the warning logic depends on.
    · branch cardinality-build-warning

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coryodaniel

Copy link
Copy Markdown
Member Author

Review items:

  1. cmd.Context() and a timeout: not changed. Every command in cmd/ uses context.Background(), and the root command runs with Execute, not ExecuteContext, so cmd.Context() is the same background context. A separate timeout for this call would not help: schema validation and resource type resolution in the same build call the same API with no timeout, so a hung API stalls the build before or after this check anyway.
  2. Extra round trip: no change needed, as the review says.
  3. Warning wording: fixed in d1e60a0. The warning now says "since the latest published version, name@version".
  4. Hand-written query: no change needed, as the review says.
  5. Adapter test: fixed in d1e60a0. TestPublishedBundleAPILowercasesCardinality checks that ONE and MANY from the API become one and many.

@claude please review.

@claude

claude Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Claude finished @coryodaniel's task in 1m 4s —— View job


Review of #271 (follow-up after d1e60a0)

Verdict: looks good. I found no blocking issues.

  • Read the diff against origin/main
  • Checked your replies to the earlier review items
  • Ran go test ./internal/api/ ./internal/commands/bundle/. Both packages pass. I did not run make check (lint) or make docs.

Your replies

  1. cmd.Context() and timeout: I agree with leaving it. Execute is used rather than ExecuteContext, so cmd.Context() would be the same background context. A timeout on this call alone would not help, because schema validation and resource type resolution make the same API calls without one.
  2. Warning wording: fixed. The message now reads "since the latest published version, name@version", and the test cases assert on that text.
  3. Adapter test: fixed. TestPublishedBundleAPILowercasesCardinality checks that ONE and MANY from the API become one and many, through the real adapter and a mocked transport.

Remaining notes (non-blocking)

  • Compared values: IsMany() maps an empty cardinality to one. The published side is lowercased in the adapter. A server value other than ONE or MANY would lowercase to something that matches neither, and the dependency would warn as a change. That's unlikely, and an extra warning is harmless for an advisory check.
  • Layering: cmd/bundle.go only passes the context, client and os.Stdout through. The logic is in internal/commands/bundle behind an injected interface and writer, and no test files were added to cmd/.
  • Docs: no command or flag changed, so make docs should produce no diff. CI will confirm.
    · branch cardinality-build-warning

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.

Warn at bundle build when a dependency's cardinality changes

1 participant