Skip to content

feat(nodes): support nested-arg refs in argumentValueNode via path#992

Draft
amilz wants to merge 1 commit intocodama-idl:mainfrom
amilz:aaron/dev-443-codama-support-nested-arg-references-in-pda-seed-defaults
Draft

feat(nodes): support nested-arg refs in argumentValueNode via path#992
amilz wants to merge 1 commit intocodama-idl:mainfrom
amilz:aaron/dev-443-codama-support-nested-arg-references-in-pda-seed-defaults

Conversation

@amilz
Copy link
Copy Markdown
Contributor

@amilz amilz commented Apr 27, 2026

Summary

  • Adds optional path?: readonly CamelCaseString[] on ArgumentValueNode so PDA seeds and other contextual value refs can target nested struct fields of an instruction arg (e.g. argument("plan_data.plan_id")).
  • Wires nested resolution in @codama/dynamic-client (pda-seed-value, account-default-value, condition-node-value) via a shared resolveArgumentPath{Type,Value} helper that walks structTypeNode fields and definedTypeLinkNode (with cycle guard).
  • @codama/errors: ARGUMENT_MISSING gains optional argumentPath suffix; message formatter renders missing $vars as empty so callers without a path don't leak $argumentPath literals.
  • visitors-core: debug visitor renders dotted refs; getResolvedInstructionInputsVisitor preserves path when rebuilding deps.

Test Plan

  • pnpm vitest run test/unit in @codama/dynamic-client → 1038 passed (+15 new path-branch cases across pda-seed-value, account-default-value, condition-node-value).
  • pnpm -F @codama/visitors-core test → 1794 passed (+ debug/identity coverage for argumentValueNode with path).
  • pnpm test:types (dynamic-client) clean; lint clean across the 5 changed packages.
  • Anchor SVM round-trip not exercised here (requires Rust toolchain) — covered by unit tests until codama-rs lands a parser (DEV-445).

Out of scope (tracked)

  • DEV-444: renderers-js codegen — emit nested member-access in generated TS instruction builders.
  • DEV-445: codama-rs derive macro — parse argument("a.b.c") syntax.

Closes DEV-443

Adds optional path?: readonly CamelCaseString[] to ArgumentValueNode so
PDA seeds and other contextual value refs can target nested struct fields
of an instruction argument (e.g. argument("plan_data.plan_id")), unblocking
auto-derivation of PDAs whose seeds live inside a struct argument.

- IR: optional path on ArgumentValueNode; factory camelCases segments and
  drops empty arrays so {} round-trips
- @codama/dynamic-client: shared resolveArgumentPath{Type,Value} walk struct
  fields and definedTypeLinkNode (with cycle guard); pda-seed-value picks the
  leaf field's typeNode for codec selection; account-default-value and
  condition-node-value resolve nested values
- @codama/errors: ARGUMENT_MISSING gains optional argumentPath suffix and the
  message formatter renders missing $vars as empty string so other callers
  don't leak $argumentPath literals
- visitors-core: getDebugStringVisitor renders dotted refs;
  getResolvedInstructionInputsVisitor preserves path when rebuilding deps
- Tests: 5 new pda-seed-value cases (struct walk, definedTypeLinkNode,
  missing intermediate, non-struct path, missing leaf field), 3 new
  account-default-value cases, 2 new condition-node-value cases, debug+
  identity coverage in visitors-core

Renderers-js codegen (DEV-444) and codama-rs derive macro (DEV-445) tracked
as follow-ups.

Refs: DEV-443
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 27, 2026

⚠️ No Changeset found

Latest commit: 7827d3d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant