refactor: adopt CBOR/JSON codegen method from libforge - #52
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns the repository鈥檚 CBOR/DAG-JSON code generation approach with libforge by running generators under a dedicated codegen build tag, ensuring generated outputs are excluded during generator compilation, and adding CI enforcement to detect stale generated files.
Changes:
- Updated multiple
*/gen/main.gogenerators to run viago generatewith-tags codegenand to prefix generated outputs with//go:build !codegen. - Refactored several codec/encoding implementations into separate
!codegen-guarded files to keep generator builds independent from generated methods. - Added Makefile targets and a GitHub Actions workflow to compile generators and fail PRs when generated files are out of date.
Reviewed changes
Copilot reviewed 39 out of 52 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| validator/internal/fixtures/datamodel/gen/main.go | Run DAG-JSON generator under codegen tag and tag output with !codegen. |
| validator/internal/fixtures/datamodel/dag_json_gen.go | Add !codegen build tag to generated DAG-JSON code. |
| ucan/receipt/datamodel/gen/main.go | Run CBOR + DAG-JSON generators under codegen tag and tag outputs with !codegen. |
| ucan/receipt/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| ucan/receipt/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| ucan/promise/promise.go | Remove codec methods from core type file to decouple from generator builds. |
| ucan/promise/datamodel/gen/main.go | Run CBOR + DAG-JSON generators under codegen tag and tag outputs with !codegen. |
| ucan/promise/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| ucan/promise/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| ucan/promise/codec.go | Reintroduce promise codec methods in a !codegen-guarded file. |
| ucan/invocation/datamodel/gen/main.go | Run CBOR + DAG-JSON (maps) generators under codegen tag and tag outputs with !codegen. |
| ucan/invocation/datamodel/dag_json_gen.maps.go | Add !codegen build tag; updated generated error context strings. |
| ucan/invocation/datamodel/cbor_gen.maps.go | Add !codegen build tag to generated CBOR code. |
| ucan/envelope/datamodel/gen/main.go | Run tuple CBOR + DAG-JSON generators under codegen tag and tag outputs with !codegen. |
| ucan/envelope/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| ucan/envelope/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| ucan/delegation/policy/selector/internal/fixtures/datamodel/gen/main.go | Run DAG-JSON generator under codegen tag and tag output with !codegen. |
| ucan/delegation/policy/selector/internal/fixtures/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| ucan/delegation/policy/selector/datamodel/gen/main.go | Run CBOR + DAG-JSON generators under codegen tag and tag outputs with !codegen. |
| ucan/delegation/policy/selector/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| ucan/delegation/policy/selector/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| ucan/delegation/policy/policy.go | Move codec-related methods out to reduce dependencies during generator builds. |
| ucan/delegation/policy/internal/fixtures/datamodel/gen/main.go | Run DAG-JSON generator under codegen tag and tag output with !codegen. |
| ucan/delegation/policy/internal/fixtures/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| ucan/delegation/policy/datamodel/statement.go | New custom marshal/unmarshal routing for StatementModel, guarded by !codegen. |
| ucan/delegation/policy/datamodel/policy.go | Remove StatementModel codec implementations (moved to statement.go). |
| ucan/delegation/policy/datamodel/gen/main.go | Run tuple CBOR + DAG-JSON generators under codegen tag and tag outputs with !codegen. |
| ucan/delegation/policy/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| ucan/delegation/policy/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| ucan/delegation/policy/codec.go | New !codegen-guarded codec/JSON helpers for Policy and Statement. |
| ucan/delegation/datamodel/gen/main.go | Run CBOR + DAG-JSON (maps) generators under codegen tag and tag outputs with !codegen. |
| ucan/delegation/datamodel/dag_json_gen.maps.go | Add !codegen build tag; updated generated error context strings. |
| ucan/delegation/datamodel/cbor_gen.maps.go | Add !codegen build tag to generated CBOR code. |
| ucan/container/datamodel/gen/main.go | Run CBOR + DAG-JSON generators under codegen tag and tag outputs with !codegen. |
| ucan/container/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| ucan/container/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| testutil/datamodel/gen/main.go | Run CBOR generator under codegen tag and tag output with !codegen. |
| testutil/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| result/datamodel/gen/main.go | Run CBOR + DAG-JSON generators under codegen tag and tag outputs with !codegen. |
| result/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| result/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| Makefile | Switch to go generate ./...; add codegen-build, gen-check, and ci targets. |
| examples/types/gen/main.go | Run CBOR generator under codegen tag and tag output with !codegen. |
| examples/types/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| errors/datamodel/gen/main.go | Run CBOR + DAG-JSON generators under codegen tag and tag outputs with !codegen. |
| errors/datamodel/errors.go | Move ErrorModelWithCause out; reduce imports in core model file. |
| errors/datamodel/dag_json_gen.go | Add !codegen build tag; updated generated error context strings. |
| errors/datamodel/cbor_gen.go | Add !codegen build tag to generated CBOR code. |
| errors/datamodel/cause.go | New !codegen-guarded ErrorModelWithCause implementation. |
| did/plc/types.go | Move operation chaining helpers out to a separate file for !codegen gating. |
| did/plc/operation.go | New !codegen-guarded PLC operation helpers (incl. hashing previous operation). |
| .github/workflows/codegen.yml | New workflow to compile generators and detect stale generated outputs. |
Files not reviewed (13)
- errors/datamodel/cbor_gen.go: Generated file
- errors/datamodel/dag_json_gen.go: Generated file
- examples/types/cbor_gen.go: Generated file
- result/datamodel/cbor_gen.go: Generated file
- result/datamodel/dag_json_gen.go: Generated file
- testutil/datamodel/cbor_gen.go: Generated file
- ucan/container/datamodel/cbor_gen.go: Generated file
- ucan/container/datamodel/dag_json_gen.go: Generated file
- ucan/delegation/datamodel/cbor_gen.maps.go: Generated file
- ucan/delegation/datamodel/dag_json_gen.maps.go: Generated file
- ucan/delegation/policy/datamodel/cbor_gen.go: Generated file
- ucan/delegation/policy/datamodel/dag_json_gen.go: Generated file
- ucan/delegation/policy/internal/fixtures/datamodel/dag_json_gen.go: Generated file
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adopts the code gen method used in libforge for generating CBOR/JSON marshal/unmarshal methods for types.
Additionally it adds a workflow for checking stale generated files.