Fix formal review findings: external relationship validation, snippet deserialization, package enhance, and doc corrections#139
Conversation
…ckage, SpdxExternalDocumentReference, spdx-element.md Agent-Logs-Url: https://github.com/demaconsulting/SpdxModel/sessions/73bdb3a5-002d-45d6-bae2-efae32971c6b Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
|
@copilot You've checked these changes against the SPDX 2.2 and 2.3 specifications right? |
…g [TestMethod] and method signature, fix doubled summary tag Agent-Logs-Url: https://github.com/demaconsulting/SpdxModel/sessions/6b938c12-262d-4881-a9a7-85ac63280ebf Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Yes — each change was verified against the SPDX 2.2 and 2.3 specifications:
The build error in |
There was a problem hiding this comment.
Pull request overview
This PR addresses formal review findings across the SPDX model library by fixing a few correctness bugs in relationship validation, JSON snippet deserialization, and package enhancement behavior, and by correcting several documentation/XML comment inaccuracies.
Changes:
- Loosen
SpdxRelationships.Add()validation to allowDocumentRef-…related elements andNOASSERTION, aligning withSpdxRelationship.Validate(). - Make
Spdx2JsonDeserializer.DeserializeSnippet()resilient to missing snippet range fields by usingint.TryParseinstead ofConvert.ToInt32. - Prevent
SpdxPackage.Enhance()from overwriting an existingVerificationCodewithnull; plus targeted doc/comment corrections.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/DemaConsulting.SpdxModel.Tests/SpdxExternalDocumentReferenceTests.cs | Fixes incorrect XML doc text for validation tests. |
| src/DemaConsulting.SpdxModel/Transform/SpdxRelationships.cs | Updates related-element validation to permit external DocumentRef-… and NOASSERTION. |
| src/DemaConsulting.SpdxModel/SpdxPackage.cs | Fixes enhancement logic to avoid nulling an existing VerificationCode. |
| src/DemaConsulting.SpdxModel/SpdxExternalDocumentReference.cs | Corrects comparer remarks to accurately describe external document references. |
| src/DemaConsulting.SpdxModel/IO/Spdx2JsonDeserializer.cs | Makes snippet range parsing tolerant of missing fields via TryParse. |
| docs/design/spdx-model/spdx-element.md | Corrects inheritance documentation for element types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…-number ranges Agent-Logs-Url: https://github.com/demaconsulting/SpdxModel/sessions/443b19c8-949c-494a-9aef-267008dccea7 Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/DemaConsulting.SpdxModel/Transform/SpdxRelationships.cs:55
- The new allowance for external
DocumentRef-...references andNOASSERTIONinRelatedSpdxElementchangesSpdxRelationships.Addbehavior, but there isn’t a regression test covering these now-valid cases (similar to the existing MissingRelatedElement test). Adding tests that assertAddacceptsRelatedSpdxElement = "NOASSERTION"and aDocumentRef-...value would prevent accidental reintroduction of the previous rejection behavior.
// Ensure the relationship related-element ID matches an element, or is valid external/NOASSERTION
if (!relationship.RelatedSpdxElement.StartsWith("DocumentRef-") &&
relationship.RelatedSpdxElement != SpdxElement.NoAssertion &&
document.GetElement(relationship.RelatedSpdxElement) == null)
{
throw new ArgumentException($"Element {relationship.RelatedSpdxElement} not found in SPDX document",
nameof(relationship));
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…e DocumentRef- prefix check Agent-Logs-Url: https://github.com/demaconsulting/SpdxModel/sessions/ec3e463a-47b5-4b57-bdaf-dd40f6605413 Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Yes — all changes were verified against SPDX 2.2 and 2.3:
|
Pull Request
Description
Fixes several bugs and documentation inaccuracies identified during a formal review of all
.reviewmark.yamlreview-sets. All changes have been verified against the SPDX 2.2 and 2.3 specifications.Bug fixes:
SpdxRelationships.Add()– Incorrectly rejected validDocumentRef-…external references andNOASSERTIONas the related element. Now mirrors the logic inSpdxRelationship.Validate(). Per SPDX 2.3 §11, therelatedSpdxElementfield may be an external document reference (DocumentRef-[idstring]:[SPDX element ID]) orNOASSERTION:Spdx2JsonDeserializer.DeserializeSnippet()– UsedConvert.ToInt32(… ?? "")for optional snippet range fields, throwingFormatExceptionwhen the field was absent. Replaced withint.TryParse, defaulting to0. Per SPDX 2.3 §9,snippetLineRangeis optional; byte ranges are required but should deserialize gracefully.SpdxPackage.Enhance()– Theelsebranch of the verification-code enhance block ran whenVerificationCode != nullbutother.VerificationCode == null, silently nulling out an existing value. Added an explicit== nullguard. Per SPDX 2.3 §7,packageVerificationCodeis optional and an existing value must not be lost during enhancement.Documentation / comment fixes:
SpdxExternalDocumentReference.cs– XML<remarks>incorrectly described theSamecomparer as comparing "packages"; corrected to "external document references".docs/design/spdx-model/spdx-element.md– Incorrectly stated all concrete types inherit directly fromSpdxElement. Corrected to reflect thatSpdxPackage,SpdxFile, andSpdxSnippetinherit via the intermediateSpdxLicenseElementabstract class.SpdxExternalDocumentReferenceTests.cs– Corrected copy-paste XML doc comments on two validation test methods (MissingIdandMissingDocument) that incorrectly referenced "annotators". Also fixed a build error introduced during the comment correction (missing[TestMethod]attribute and method signature).SpdxRelationships.cs– Inline comment on theDocumentRef-prefix check inAdd()was corrected from "is valid external/NOASSERTION" to accurately state that only theDocumentRef-prefix is checked (consistent withSpdxRelationship.Validate()), per SPDX 2.3 §11.Test additions:
Spdx2JsonDeserializeSnippet.cs– Added regression testSpdx2JsonDeserializer_DeserializeSnippet_WithoutLineRanges_DefaultsToZerothat verifies noFormatExceptionis thrown when the optionallineNumberrange entries are absent, and that absent line ranges correctly default to0.Type of Change
Related Issues
Pre-Submission Checklist
Before submitting this pull request, ensure you have completed the following:
Build and Test
dotnet build --configuration Releasedotnet test --configuration ReleaseCode Quality
dotnet format --verify-no-changesQuality Checks
Please run the following checks before submitting:
./lint.sh(Unix/macOS) orcmd /c lint.bat/./lint.bat(Windows)Testing
Documentation
Additional Notes
All 158 tests pass across net8.0, net9.0, and net10.0 with zero warnings.