Skip to content

feat: typed enum for OSCAL implementation status state#383

Merged
gusfcarvalho merged 3 commits into
mainfrom
devin/1776677736-implementation-status-enum
Apr 20, 2026
Merged

feat: typed enum for OSCAL implementation status state#383
gusfcarvalho merged 3 commits into
mainfrom
devin/1776677736-implementation-status-enum

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Replaces the free-form string type on ImplementationStatus.State with a well-defined ImplementationStatusState enum constrained to the five OSCAL SSP states:

  • implemented — the control is fully implemented
  • partial — the control is partially implemented
  • planned — there is a plan for implementing the control
  • alternative — there is an alternative implementation
  • not-applicable — the control does not apply to this system

Changes:

  • New type & constants: ImplementationStatusState with five valid constants and a Validate() method on ImplementationStatus
  • Endpoint validation: All three ByComponent create/update handlers (UpdateImplementedRequirementByComponent, UpdateImplementedRequirementStatementByComponent, CreateImplementedRequirementStatementByComponent) now validate the implementation status state, returning 400 for invalid values
  • OSCAL compatibility: Serialization/deserialization round-trips remain fully compatible with OSCAL JSON (state stored as lowercase string)
  • Existing code: Updated system_component_suggestions.go to use the typed constant, fixed existing test using non-lowercase "Implemented" state
  • Comprehensive tests: 13 new unit tests covering valid states, invalid states, empty/omitted status, marshal/unmarshal round-trips, and JSON compatibility

Review & Testing Checklist for Human

  • Verify that existing OSCAL SSP import (make oscal import) still loads documents with implementation-status fields correctly — the deserialization accepts any string from existing data, but new writes are validated
  • Test creating/updating a ByComponent via the API with each valid state (implemented, partial, planned, alternative, not-applicable) and confirm 200/201 responses
  • Test creating/updating a ByComponent with an invalid state (e.g. "Implemented", "invalid") and confirm a 400 response with a clear error message
  • Verify omitting implementation-status entirely in a ByComponent request still works (no validation error)

Notes

  • The ImplementationStatus struct is now a standalone type (no longer type ImplementationStatus oscalTypes_1_1_3.ImplementationStatus) to allow using the typed ImplementationStatusState for the State field while keeping JSON tags identical for OSCAL compatibility
  • Existing records loaded from the database will deserialize safely regardless of stored state value; validation only runs on API create/update paths

Link to Devin session: https://app.devin.ai/sessions/e6bb63391665462eb8f427a9cbd8bcf5
Requested by: @gusfcarvalho

Replace free-form string State on ImplementationStatus with a
well-defined ImplementationStatusState type constrained to the five
OSCAL SSP states: implemented, partial, planned, alternative,
not-applicable.

- Add ImplementationStatusState type, constants, and validation
- Add Validate() method on ImplementationStatus
- Add validation in Create/Update ByComponent handler endpoints
- Ensure serialization/deserialization remains OSCAL JSON compatible
- Add comprehensive tests for valid/invalid states, omitted status,
  marshal/unmarshal round-trips, and JSON compatibility
- Fix existing test using non-lowercase 'Implemented' state

Co-Authored-By: Gustavo Fernandes <gusfcarvalho@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

devin-ai-integration Bot commented Apr 20, 2026

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 tightens OSCAL SSP implementation-status.state handling by replacing a free-form string with a typed enum, and enforcing valid values on the ByComponent create/update API paths while preserving OSCAL JSON round-trip compatibility.

Changes:

  • Introduces ImplementationStatusState + constants and refactors ImplementationStatus to use the typed state with a Validate() method.
  • Adds request-time validation in the three ByComponent create/update handlers to reject invalid states with HTTP 400.
  • Updates/extends unit and integration tests to cover enum validity and JSON marshal/unmarshal round-trips.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/service/relational/system_security_plan.go Adds the typed enum + validation and updates OSCAL marshal/unmarshal conversions for ImplementationStatus.
internal/service/relational/system_security_plan_test.go Adds unit tests for valid/invalid states and JSON compatibility/round-trips.
internal/service/relational/system_component_suggestions.go Switches hard-coded "implemented" to the typed constant.
internal/api/handler/oscal/system_security_plans.go Adds validation hook for ByComponent create/update flows.
internal/api/handler/oscal/system_security_plans_test.go Fixes integration test input to use lowercase "implemented".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/api/handler/oscal/system_security_plans.go
Address Copilot review feedback: when the implementation-status field
is present in the request but has an empty state, return 400 instead
of silently allowing it. Only skip validation when the entire field
is absent (zero JSONType).

Add integration test covering invalid state, empty state with remarks,
and omitted implementation-status scenarios.

Co-Authored-By: Gustavo Fernandes <gusfcarvalho@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/api/handler/oscal/system_security_plans_test.go
Fix compilation error in TestCreateByComponentInvalidImplementationStatus
by using the correct test helper and adding missing handler registration.

Co-Authored-By: Gustavo Fernandes <gusfcarvalho@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gusfcarvalho gusfcarvalho merged commit 25b7879 into main Apr 20, 2026
8 checks passed
@gusfcarvalho gusfcarvalho deleted the devin/1776677736-implementation-status-enum branch April 20, 2026 14:59
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