Skip to content

refactor: adopt CBOR/JSON codegen method from libforge - #52

Merged
alanshaw merged 2 commits into
mainfrom
ash/refactor/code-gen
Aug 24, 2026
Merged

refactor: adopt CBOR/JSON codegen method from libforge#52
alanshaw merged 2 commits into
mainfrom
ash/refactor/code-gen

Conversation

@alanshaw

Copy link
Copy Markdown
Member

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.go generators to run via go generate with -tags codegen and 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.

Comment thread ucan/delegation/policy/codec.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@alanshaw
alanshaw merged commit 9bb30b7 into main Aug 24, 2026
6 checks passed
@alanshaw
alanshaw deleted the ash/refactor/code-gen branch August 24, 2026 12:03
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