Skip to content

feat: expose identify/parse helpers on generated program plugins#143

Merged
lorisleiva merged 2 commits into
codama-idl:mainfrom
amilz:feat/increase-plugin-exposure
May 5, 2026
Merged

feat: expose identify/parse helpers on generated program plugins#143
lorisleiva merged 2 commits into
codama-idl:mainfrom
amilz:feat/increase-plugin-exposure

Conversation

@amilz

@amilz amilz commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Re-expose identifyAccount, identifyInstruction, and parseInstruction on the generated program plugin, so consumers can call client.myProgram.identifyInstruction(ix) without importing the per-function helpers.
  • Emission mirrors the existing rules for those helpers (account/instruction discriminators, respecting renderParentInstructions).
  • Adds fragment, page, and e2e (dummy) round-trip coverage; e2e fixtures regenerated.

Test Plan

  • pnpm test:unit
  • cd test/e2e/dummy && pnpm test

amilz added 2 commits April 30, 2026 16:28
Generated program plugins now re-expose the existing per-program identifier
and parser helpers as plugin fields. When a program has accounts with
discriminators, the plugin gains an `identifyAccount` field bound to the
generated `identify*Account` function. When any instruction (respecting
`renderParentInstructions`) carries a discriminator, the plugin gains
`identifyInstruction` and `parseInstruction` fields bound to the generated
`identify*Instruction` and `parse*Instruction` functions. Emission mirrors
the conditions under which those helper functions themselves get rendered,
so the plugin shape stays consistent with the rest of the program page.

Tests cover the discriminator-present, sub-instruction-only, no-discriminator,
and `renderParentInstructions: true` paths at both the fragment level and
the full program-page level. E2E fixtures regenerated to reflect the new
plugin shape.
Add three ava tests in the dummy e2e fixture that exercise the new
plugin shape against real generator-built instructions. The first two
assert that identifyDummyInstruction and parseDummyInstruction round-trip
the bytes encoded by getInstruction3Instruction and getInstruction10Instruction
back to their enum variants, giving us coverage that the encoder and
identifier agree on the wire format. The third applies dummyProgram()
to a stub client and verifies its identifyInstruction/parseInstruction
fields behave identically to the standalone helpers.

Also fix two prettier-flagged line-break issues in programPlugin.ts that
were masked in the previous lint run by eslint's short-circuit. The
e2e workspace now resolves @solana/kit at 6.8.0 (versus 6.1.0 before
the lockfile-driven reinstall), which surfaces extendClient typings
and lets the prettier check run cleanly.
@changeset-bot

changeset-bot Bot commented May 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f386fab

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/renderers-js Minor

Not sure what this means? Click here to learn what changesets are.

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

@amilz amilz requested a review from lorisleiva May 1, 2026 21:37
@amilz amilz self-assigned this May 1, 2026
@lorisleiva

Copy link
Copy Markdown
Member

@trevor-cortex

@trevor-cortex trevor-cortex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-exposes identifyAccount, identifyInstruction, and parseInstruction on generated program plugins so consumers can call them off the client (e.g. client.myProgram.parseInstruction(ix)) without importing the per-program helpers separately. Useful for indexers and anything that switches on instruction kind.

The plugin type and the plugin function are both updated symmetrically, and emission is gated by the same conditions that drive the underlying helper generation:

  • identifyAccount is emitted iff at least one account has a discriminator (mirrors getProgramAccountsIdentifierFunctionFragment).
  • identifyInstruction / parseInstruction are emitted iff at least one instruction (after the same getAllInstructionsWithSubs({ leavesOnly: !renderParentInstructions }) walk used by getProgramInstructionsFragment) has a discriminator.

Threading renderParentInstructions into getProgramPluginFragment/getProgramPluginTypeFragment/getProgramPluginFunctionFragment is required for that second condition to stay in sync — programPage.ts already had it in scope, so the plumbing is local.

Things to watch

  • Condition parity: hasAccountIdentifier and hasInstructionIdentifier duplicate the predicates from programAccounts.ts / programInstructions.ts. They match today; if those upstream conditions ever change (e.g. additional gating beyond discriminators.length > 0), these will need to change in lockstep. A short comment is already present on hasInstructionIdentifier; worth keeping in mind for future edits.
  • Field ordering: the new keys are appended after pdas in both the type and the function. Cosmetic only, but placing identifyAccount next to accounts and identifyInstruction/parseInstruction next to instructions would read more naturally. Not blocking — current placement is consistent across type + function and matches the regenerated e2e fixtures.

Notes for subsequent reviewers

  • E2E fixtures across dummy, system, token, associatedToken, and wenTransferGuard have been regenerated and look consistent with the new emission rules (e.g. associatedToken only gets identifyInstruction/parseInstruction because it has no accounts; token gets all three; dummy gets only the instruction pair).
  • The new dummy AVA test exercises the plugin via a stub {} as DummyPluginRequirements cast — fine here because identifyInstruction/parseInstruction are bare references that don't read from the client, but worth remembering if either helper ever becomes client-aware.
  • Tests cover the four interesting cases: discriminators present on both sides, sub-instruction-only discriminators, no discriminators (negative case), and renderParentInstructions: true flipping a parent-only discriminator into emission. Good coverage.
  • Changeset is minor and the description is accurate.

@lorisleiva lorisleiva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfection, Thank you!

@lorisleiva lorisleiva merged commit f513041 into codama-idl:main May 5, 2026
4 checks passed
@github-actions github-actions Bot mentioned this pull request May 5, 2026
@amilz amilz deleted the feat/increase-plugin-exposure branch May 5, 2026 15:46
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.

3 participants