Skip to content

Add staged submodel composition and validation (fragments) with tests#19

Merged
Freezor merged 2 commits into12-enable-incremental-submodel-composition-via-addsubmodel-at-any-stage-of-the-build-processfrom
codex/design-addsubmodel-method-for-aas-builder
Mar 27, 2026
Merged

Add staged submodel composition and validation (fragments) with tests#19
Freezor merged 2 commits into12-enable-incremental-submodel-composition-via-addsubmodel-at-any-stage-of-the-build-processfrom
codex/design-addsubmodel-method-for-aas-builder

Conversation

@Freezor
Copy link
Copy Markdown
Owner

@Freezor Freezor commented Mar 27, 2026

Motivation

  • Enable modular registration and late enrichment of Submodel instances so different modules/plugins can contribute elements before Build().
  • Improve robustness by validating submodel identity and shell-submodel references during build-time to surface configuration errors early.

Description

  • Add SubmodelFragmentBuilder to stage contributions against an existing Submodel and apply them during Build() via AddSubmodelFragment(string, Action<SubmodelFragmentBuilder>) on IAasBuilder/AasBuilder.
  • Introduce AddSubmodel(Submodel) (delegated from AddExistingSubmodel) and centralize submodel validation in ValidateSubmodel to check Id and IdShort when adding.
  • Implement build-time checks to detect duplicate submodel ids, ensure fragments target an existing submodel, and verify shell submodel references resolve to known submodels, and apply staged fragments in registration order.
  • Update README.md with usage examples and notes about staged submodel composition and backward compatibility.

Testing

  • Added unit tests in FluentAAS.Builder.Tests/AasBuilderTests.cs: AddSubmodel_WithValidSubmodel_ShouldAddToEnvironmentAndReturnBuilder, AddSubmodel_WithInvalidIdShort_ShouldThrowArgumentException, Build_WithDuplicateSubmodelIds_ShouldThrowInvalidOperationException, AddSubmodelFragment_ShouldApplyContributionAtBuildTime, and AddSubmodelFragment_WithoutBaseSubmodel_ShouldThrowInvalidOperationException, and verified existing Build_WhenCalledMultipleTimes_ShouldReturnNewEnvironmentInstancesWithSameContent still behaves correctly.
  • Ran the FluentAAS.Builder.Tests suite including the new tests and the full builder tests, and all automated tests passed successfully.

Codex Task

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 27, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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: CHILL

Plan: Pro

Run ID: 05c02ec0-55f7-4545-aff1-32c7ccb3d237

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/design-addsubmodel-method-for-aas-builder

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 and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a5f3b54fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

throw new InvalidOperationException($"No base submodel with id '{submodelId}' was found for a staged fragment. Add the submodel before adding fragments.");
}

applyFragment(submodel);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid mutating staged submodels during each Build

Build() executes applyFragment(submodel) against the builder’s stored Submodel instances on every invocation, and _submodelFragments is never consumed or reset. This makes repeated Build() calls non-idempotent (fragment elements are appended again each time) and also mutates previously returned environments because they share the same submodel objects. Apply fragments to a fresh copy (or apply each fragment only once) before returning the environment.

Useful? React with 👍 / 👎.

public void AddSubmodelInternal(Submodel submodel)
{
ArgumentNullException.ThrowIfNull(submodel);
ValidateSubmodel(submodel);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve id-only submodel references in internal registration

AddSubmodelInternal now always calls ValidateSubmodel, which throws when IdShort is missing. That change also affects ShellBuilder.AddSubmodelReference, which routes through AddSubmodelInternal and previously accepted reference-only submodels created as new Submodel(id: ...). This introduces a runtime break for existing reference flows unless callers are all updated to provide IdShort.

Useful? React with 👍 / 👎.

@Freezor Freezor merged commit 9cb0629 into 12-enable-incremental-submodel-composition-via-addsubmodel-at-any-stage-of-the-build-process Mar 27, 2026
3 checks passed
@Freezor Freezor deleted the codex/design-addsubmodel-method-for-aas-builder branch March 27, 2026 11:02
Freezor added a commit that referenced this pull request Mar 27, 2026
#20)

* Add staged submodel composition and validation (fragments) with tests (#19)

* Update README for staged submodel composition and remove extra spec doc

* Fix staged fragment idempotency and preserve internal submodel compatibility

* 📝 Add docstrings to `12-enable-incremental-submodel-composition-via-addsubmodel-at-any-stage-of-the-build-process` (#21)

Docstrings generation was requested by @Freezor.

* #20 (comment)

The following files were modified:

* `FluentAAS/FluentAAS.Builder/AasBuilder.cs`
* `FluentAAS/FluentAAS.Builder/IAasBuilder.cs`
* `FluentAAS/FluentAAS.Builder/SubModel/SubmodelFragmentBuilder.cs`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* 📝 CodeRabbit Chat: Add unit tests

* Fix malformed XML docs in builder interfaces (#22)

* FEAT Fix docs issue

* Make submodel fragment application transactional in Build (#23)

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant