Skip to content

Add opt-in EmitShapeTag support - #49

Merged
sator-imaging merged 12 commits into
mainfrom
codex/add-emitshapetag-to-zeroserializerattribute
Aug 12, 2026
Merged

Add opt-in EmitShapeTag support#49
sator-imaging merged 12 commits into
mainfrom
codex/add-emitshapetag-to-zeroserializerattribute

Conversation

@sator-imaging

Copy link
Copy Markdown
Owner

Motivation

  • Prevent accidental emission of the human-readable string ShapeTag by default because it can expose internal type details, while still providing ShapeHash for consumers and an opt-in escape hatch.

Description

  • Injected the attribute to include an obsolete public bool EmitShapeTag; and an explicit parameterless constructor on the generated ZeroSerializerAttribute so consumers can opt in; changes in src/ZeroSerializerGenerator.cs.
  • Added syntax-based detection ShouldEmitShapeTag that inspects attribute arguments and pipes the result into the TypeGenerationModel via a new EmitShapeTag property in src/TypeGenerationModel.cs.
  • Made generated view output conditional: XML <remarks> and the active public const string ShapeTag are emitted only when EmitShapeTag is true, otherwise a commented-out ShapeTag line with guidance is emitted, while ShapeHash is always generated; changes in src/ZeroSerializerGenerator.cs.
  • Opted existing test models into explicit emission where the tests rely on ShapeTag, and added a new unit test file tests/ShapeTagEmissionTests.cs that covers default suppression, explicit emission, and the injected attribute contents.

Testing

  • Ran repository checks git diff --check and git diff --cached --check, which succeeded.
  • Attempted to run the test suite with dotnet test tests/ZeroSerializer.Tests.csproj -f net8.0 --no-restore but the environment does not have dotnet installed so the command could not be executed.
  • New unit tests were added (tests/ShapeTagEmissionTests.cs) and model fixtures were updated (tests/SerializationModels.cs), but the C# test run was not executed in this environment due to the missing dotnet tool.

Codex Task

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 201a5451-c8d4-4adc-955c-12773532eac0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Summary by CodeRabbit

  • New Features

    • Added an opt-in setting to include shape tags and related metadata in generated serialization views.
    • Generated output now provides guidance comments when shape-tag emission is disabled.
    • Existing serialization models can enable shape-tag generation through their serializer configuration.
  • Tests

    • Added coverage for default behavior, opt-in shape-tag output, remarks, and generated attribute metadata.

Walkthrough

The serializer generator now supports opt-in shape-tag emission through the obsolete EmitShapeTag attribute field. Generated views emit shape-tag documentation and constants only when the field is set to true. Tests cover both modes and injected metadata.

Changes

Shape tag emission

Layer / File(s) Summary
Attribute capture and generation model
src/ZeroSerializerGenerator.cs, src/TypeGenerationModel.cs
The injected attribute exposes the obsolete EmitShapeTag field and a parameterless constructor. The generator detects a literal EmitShapeTag = true argument and stores the setting in TypeGenerationModel.
Conditional generated output
src/ZeroSerializerGenerator.cs
Generated views include shape-tag remarks and an active ShapeTag constant when enabled. Disabled output contains explanatory comments instead.
Fixture and generator validation
tests/SerializationModels.cs, tests/ShapeTagEmissionTests.cs
Four serialization models enable shape-tag emission. Generator tests verify default output, enabled output, and injected attribute metadata.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SerializerAttribute
  participant ZeroSerializerGenerator
  participant TypeGenerationModel
  participant GeneratedView

  SerializerAttribute->>ZeroSerializerGenerator: Read EmitShapeTag = true
  ZeroSerializerGenerator->>TypeGenerationModel: Store emitShapeTag
  ZeroSerializerGenerator->>GeneratedView: Emit ShapeTag remarks and constant
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the opt-in EmitShapeTag change.
Description check ✅ Passed The description explains the motivation, implementation, tests, and known test limitation for EmitShapeTag support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/add-emitshapetag-to-zeroserializerattribute
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/add-emitshapetag-to-zeroserializerattribute

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/ShapeTagEmissionTests.cs`:
- Around line 22-36: Strengthen the ShapeTag emission tests: in the default-mode
test, assert that an uncommented public ShapeTag declaration is absent, and in
ShapeTagAndRemarksAreEmittedWhenRequested, assert that the public ShapeHash
declaration is still present. Keep the existing assertions for commented
ShapeTag output and enabled remarks.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 29f7f5a9-e159-4a56-8d24-5e78fdd11630

📥 Commits

Reviewing files that changed from the base of the PR and between 6b7c124 and ed755e8.

📒 Files selected for processing (4)
  • src/TypeGenerationModel.cs
  • src/ZeroSerializerGenerator.cs
  • tests/SerializationModels.cs
  • tests/ShapeTagEmissionTests.cs
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: test (Debug)
  • GitHub Check: test (Release)
🔇 Additional comments (4)
src/ZeroSerializerGenerator.cs (1)

114-117: LGTM!

Also applies to: 292-292, 373-407, 957-980

src/TypeGenerationModel.cs (1)

18-26: LGTM!

Also applies to: 39-40

tests/ShapeTagEmissionTests.cs (1)

39-71: LGTM!

tests/SerializationModels.cs (1)

25-25: 📐 Maintainability & Code Quality

No warning-policy issue found. The test project and repository configuration do not promote CS0618 warnings to errors. No narrow suppression is required.

			> Likely an incorrect or invalid review comment.

Comment thread tests/ShapeTagEmissionTests.cs Outdated
Comment thread src/ZeroSerializerGenerator.cs Outdated
Comment thread src/ZeroSerializerGenerator.cs Outdated
Comment thread src/ZeroSerializerGenerator.cs
Comment thread src/ZeroSerializerGenerator.cs Outdated
Comment thread src/ZeroSerializerGenerator.cs Outdated
Comment thread tests/ShapeTagEmissionTests.cs Outdated
Comment thread tests/ShapeTagEmissionTests.cs Outdated
Co-authored-by: sator-imaging <16752340+sator-imaging@users.noreply.github.com>
Comment thread tests/ShapeTagEmissionTests.cs
Comment thread tests/ShapeTagEmissionTests.cs Outdated
Comment thread tests/ShapeTagEmissionTests.cs Outdated
Comment thread tests/ShapeTagEmissionTests.cs Outdated
Comment thread tests/ShapeTagEmissionTests.cs
@sator-imaging
sator-imaging merged commit 56e1789 into main Aug 12, 2026
4 checks passed
@sator-imaging
sator-imaging deleted the codex/add-emitshapetag-to-zeroserializerattribute branch August 12, 2026 04:53
@github-actions github-actions Bot added the enhancement New feature or request label Aug 12, 2026
@sator-imaging sator-imaging changed the title Add opt-in EmitShapeTag support Add opt-in EmitShapeTag support Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant