Skip to content

Enforce document related object references#244

Closed
HardlyDifficult wants to merge 5 commits into
codex/ocf-issuer-aggregate-share-ceilingfrom
codex/ocf-document-related-object-references
Closed

Enforce document related object references#244
HardlyDifficult wants to merge 5 commits into
codex/ocf-issuer-aggregate-share-ceilingfrom
codex/ocf-document-related-object-references

Conversation

@HardlyDifficult

@HardlyDifficult HardlyDifficult commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #243.

This adds final-state validation for Document.related_objects:

  • each related object reference must resolve to the current cap table issuer or to an existing object/transaction map entry;
  • references to objects created in the same batch are accepted because validation runs after deletes, edits, issuer edit, and creates;
  • OCF object-type enum values that this DAML package does not model, such as FINANCING and plan-security transaction aliases, are rejected instead of being accepted as dangling IDs.

OCF documentation

Tests

  • Updated the existing document optional-fields test to reference the actual cap-table issuer.
  • Added rejection for a missing issuer reference.
  • Added success for a document referencing a stock class created in the same batch.
  • Added edit-time rejection for a missing related stock class.
  • Added rejection for an unsupported related object type.

Validation

  • NODE_PATH=/Users/fairnick/Documents/code/fairmint/open-captable-protocol-daml/node_modules PATH="/Users/fairnick/Documents/code/fairmint/open-captable-protocol-daml/node_modules/.bin:$HOME/.dpm/bin:$PATH" npm run build
  • From Test/: JAVA_HOME=/opt/homebrew/opt/openjdk@17 PATH="/opt/homebrew/opt/openjdk@17/bin:$HOME/.dpm/bin:$PATH" dpm test --show-coverage --color --coverage-ignore-choice 'splice-amulet:.*'

Note

Medium Risk
Batch commits can now fail when documents carry invalid or unsupported related-object refs, which may break previously accepted updates; logic is localized to document validation at the end of UpdateCapTable.

Overview
UpdateCapTable now runs final-state validation on every document’s related_objects after deletes, edits, issuer updates, and creates complete, so references must point at the cap table’s issuer or an ID present in the corresponding object/transaction map (including objects created in the same batch).

Codegen adds validateObjectReference / validateDocumentRelatedObjects, maps each modeled OcfObjectType to the right cap-table map (with transaction and change-event constructor naming), and fails on unsupported enum values (e.g. FINANCING) instead of accepting dangling IDs. The packaged OpenCapTable-v34 DAR and dars.lock are refreshed.

Document tests gain a documentData helper plus scenarios for missing issuer refs, same-batch stock-class refs, edit-time missing refs, and unsupported related types; the optional-fields test now uses the real issuer id ISSUER_1.

Reviewed by Cursor Bugbot for commit 802c70f. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 554e6694-c0c6-492e-8ff5-e13732b4fac4

📥 Commits

Reviewing files that changed from the base of the PR and between 14f3e5b and 802c70f.

⛔ Files ignored due to path filters (1)
  • dars/dars.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • Test/daml/OpenCapTable/TestDocument.daml
  • dars/OpenCapTable-v34/0.0.2/OpenCapTable-v34.dar
  • scripts/codegen/generate-captable.ts
  • scripts/codegen/templates/CapTable.daml.template
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ocf-document-related-object-references

Comment @coderabbitai help to get the list of available commands.

@HardlyDifficult HardlyDifficult marked this pull request as ready for review July 8, 2026 23:48
@HardlyDifficult HardlyDifficult requested a review from Copilot July 8, 2026 23:48

Copilot AI 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.

Pull request overview

Adds final-state CapTable validation to ensure Document.related_objects references resolve to the current issuer or to an object/transaction present in the cap table maps, and expands DAML Script tests to cover valid/invalid document reference scenarios (including unsupported OCF object types).

Changes:

  • Add Document.related_objects reference validation in the generated CapTable update flow (runs after deletes/edits/issuer edit/creates).
  • Extend CapTable codegen to emit object-type constructor matches (including change-event overrides) and handle Document imports cleanly.
  • Update/add document tests for issuer/object existence checks, same-batch references, and unsupported object types.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Test/daml/OpenCapTable/TestDocument.daml Adds helper + new tests around Document.related_objects validation semantics.
scripts/codegen/templates/CapTable.daml.template Implements final-state validation for document related-object references and wires it into UpdateCapTable.
scripts/codegen/generate-captable.ts Extends type discovery metadata to generate correct OcfObjectType constructor matches (incl. overrides) and document handling.
dars/OpenCapTable-v34/0.0.2/OpenCapTable-v34.dar Updates compiled DAR artifact to include the new validation behavior.
dars/dars.lock Updates DAR lock metadata (sha/size/timestamp) for the new artifact.

Comment on lines +277 to +279
OcfObjIssuer -> do
issuerContract <- fetch issuerCid
assertMsg ("Issuer not found: " <> ref.object_id) (ref.object_id == issuerContract.issuer_data.id)
{{object_type_constructor}} ->
assertMsg ("{{name}} not found: " <> ref.object_id) (isSome (Map.lookup ref.object_id maps.{{map_field}}))
{{/each}}
_ -> assertMsg ("Unsupported related object type: " <> ref.object_id) False
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

Superseded by #251, which consolidates the reference-integrity work into one PR. Before closing this stack PR, I rechecked the live review comments and folded the actionable improvements into #251: StockPlan create-tier ordering, document related-object error messages, stock-class conversion source IDs, warrant conversion validation across all OcfAnyConversionRight variants, WarrantIssuance same-batch vesting-term edits, and immutable DAR backup versioning.

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.

2 participants