Skip to content

feat: risktemplate/subjectemplate batch endpoints for agent#350

Merged
gusfcarvalho merged 11 commits intomainfrom
gc/feat/batch-enpdoints-for-agent
Mar 17, 2026
Merged

feat: risktemplate/subjectemplate batch endpoints for agent#350
gusfcarvalho merged 11 commits intomainfrom
gc/feat/batch-enpdoints-for-agent

Conversation

@gusfcarvalho
Copy link
Contributor

No description provided.

Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Copilot AI review requested due to automatic review settings March 16, 2026 17:41
Copy link
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

Adds agent-facing batch reconciliation endpoints for Risk Templates and Subject Templates, backed by new BatchUpsert service methods and documented in Swagger.

Changes:

  • Implement BatchUpsert in RiskTemplateService and SubjectTemplateService (create/update/delete + unchanged detection) with unit tests.
  • Add new /api/agent/risk-templates/batch and /api/agent/subject-templates/batch handlers + integration tests.
  • Update Swagger docs and add JSON testdata payload examples for agent batch requests.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
testdata/empty_subject_batch.json Example empty batch payload for subject templates.
testdata/empty_batch.json Example empty batch payload for risk templates.
testdata/batch_upsert_subject_templates.json Example subject-template batch upsert payload.
testdata/batch_upsert_risk_templates.json Example risk-template batch upsert payload.
internal/service/relational/templates/subject_template_service_test.go Adds unit tests for subject template batch upsert behaviors.
internal/service/relational/templates/subject_template_service.go Implements subject template batch reconciliation + fingerprinting.
internal/service/relational/templates/risk_template_service_test.go Adds unit tests for risk template batch upsert behaviors.
internal/service/relational/templates/risk_template_service.go Implements risk template batch reconciliation + fingerprinting.
internal/api/middleware/agent_auth.go Introduces agent auth middleware (currently stubbed).
internal/api/handler/templates/subject_template_integration_test.go Adds agent batch endpoint integration coverage for subject templates.
internal/api/handler/templates/subject_template.go Adds agent batch endpoint + request/response types + swagger annotations.
internal/api/handler/templates/risk_template_integration_test.go Adds agent batch endpoint integration coverage for risk templates.
internal/api/handler/templates/risk_template.go Adds agent batch endpoint + request/response types + swagger annotations.
internal/api/handler/api.go Registers new /agent/* template routes and middleware.
docs/swagger.yaml Documents new agent batch endpoints + schemas.
docs/swagger.json Generated swagger JSON updates for new endpoints.
docs/docs.go Generated embedded swagger updates for new endpoints.

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

Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Copy link
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

Adds agent-facing batch upsert endpoints for risk templates and subject templates, including service-layer reconciliation logic (create/update/delete/unchanged), API handlers, integration/unit tests, and updated Swagger docs so agents can register and reconcile templates in bulk.

Changes:

  • Implement BatchUpsert reconciliation in RiskTemplateService and SubjectTemplateService (create/update/delete + unchanged detection).
  • Add /api/agent/{risk-templates,subject-templates}/batch endpoints with integration tests and Swagger updates.
  • Improve make test-integration output by summarizing failing tests across multiple runs.

Reviewed changes

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

Show a summary per file
File Description
testdata/empty_subject_batch.json Example empty subject-template batch payload.
testdata/empty_batch.json Example empty risk-template batch payload.
testdata/batch_upsert_subject_templates.json Example subject-template batch payload for agents.
testdata/batch_upsert_risk_templates.json Example risk-template batch payload for agents.
internal/service/relational/templates/subject_template_service.go Adds BatchUpsert for subject templates + unchanged detection helpers.
internal/service/relational/templates/subject_template_service_test.go Adds unit tests covering create/update/delete/unchanged + validation for subject batch upsert.
internal/service/relational/templates/risk_template_service.go Adds BatchUpsert for risk templates + unchanged detection helpers.
internal/service/relational/templates/risk_template_service_test.go Adds unit tests covering create/update/delete/unchanged + validation for risk batch upsert.
internal/api/middleware/agent_auth.go Introduces placeholder agent JWT middleware (currently no-op).
internal/api/handler/templates/subject_template.go Adds agent batch endpoint handler + request/response types + swagger annotations.
internal/api/handler/templates/subject_template_integration_test.go Adds integration tests for agent subject-template batch endpoint.
internal/api/handler/templates/risk_template.go Adds agent batch endpoint handler + request/response types + swagger annotations.
internal/api/handler/templates/risk_template_integration_test.go Adds integration tests for agent risk-template batch endpoint.
internal/api/handler/api.go Registers new /api/agent/* template routes.
docs/swagger.yaml Documents new agent batch endpoints + request/response schemas.
docs/swagger.json Generated Swagger JSON updates for new endpoints/schemas.
docs/docs.go Generated Go swagger-doc template updates for new endpoints/schemas.
Makefile Enhances integration test target to aggregate and summarize failing tests.

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

Copy link
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 adds agent-facing batch upsert endpoints for risk templates and subject templates, enabling an agent to reconcile the full template set per scope (plugin or plugin+policy) via a single request, with create/update/delete handled transactionally.

Changes:

  • Added BatchUpsert implementations for RiskTemplateService and SubjectTemplateService, including “skip unchanged” behavior and dependent-row cleanup on delete.
  • Added new agent API routes (/api/agent/risk-templates/batch, /api/agent/subject-templates/batch) with request/response shapes, integration tests, and regenerated Swagger docs.
  • Added testdata JSON payload examples and improved make test-integration output summarization.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/service/relational/templates/subject_template_service.go Implements subject-template batch upsert + payload fingerprinting + scoped listing and transactional delete cleanup.
internal/service/relational/templates/subject_template_service_test.go Adds unit tests covering create/update/delete, empty payload deletion, unchanged detection, validation, and plugin scoping.
internal/service/relational/templates/risk_template_service.go Implements risk-template batch upsert + payload fingerprinting, transactional deletes with threat/evidence/remediation cleanup.
internal/service/relational/templates/risk_template_service_test.go Adds unit tests for batch upsert lifecycle, scoping, validation, and dependent-row cleanup.
internal/api/handler/templates/subject_template.go Adds agent batch endpoint handler + request/response types + Swagger annotations.
internal/api/handler/templates/risk_template.go Adds agent batch endpoint handler + request/response types + Swagger annotations.
internal/api/handler/templates/subject_template_integration_test.go Adds integration coverage for agent subject-template batch behavior (create/update/delete/validation/public).
internal/api/handler/templates/risk_template_integration_test.go Adds integration coverage for agent risk-template batch behavior (create/update/delete/validation/public).
internal/api/middleware/agent_auth.go Introduces placeholder agent JWT middleware (currently no-op).
internal/api/handler/api.go Registers new /agent/* route groups and wires the agent middleware.
docs/swagger.yaml / docs/swagger.json / docs/docs.go Regenerated Swagger artifacts including the new agent batch endpoints and schemas.
testdata/*.json Adds example batch payloads for empty and populated requests.
Makefile Enhances integration test target to collect and print a failure summary across multiple runs.

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

Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Copy link
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

Adds agent-facing batch upsert endpoints to reconcile risk templates and subject templates, enabling agents to create/update/delete templates in bulk with deterministic IDs and atomic behavior.

Changes:

  • Implement BatchUpsert reconciliation logic for RiskTemplateService and SubjectTemplateService (create/update/delete + unchanged detection).
  • Expose new /api/agent/*/batch endpoints with integration tests and regenerated Swagger docs.
  • Add sample batch payload JSON files and enhance make test-integration output to summarize failing tests across runs.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
testdata/empty_subject_batch.json Example empty batch payload for subject template reconciliation.
testdata/empty_batch.json Example empty batch payload for risk template reconciliation.
testdata/batch_upsert_subject_templates.json Example subject template batch payload (used for manual testing/examples).
testdata/batch_upsert_risk_templates.json Example risk template batch payload (used for manual testing/examples).
internal/service/relational/templates/subject_template_service.go Adds subject template batch upsert implementation + payload fingerprinting for unchanged detection.
internal/service/relational/templates/subject_template_service_test.go Adds unit tests covering batch create/update/delete/unchanged/validation and dependent-row cleanup.
internal/service/relational/templates/risk_template_service.go Adds risk template batch upsert implementation + fingerprinting for unchanged detection and dependent-row cleanup.
internal/service/relational/templates/risk_template_service_test.go Adds unit tests for risk template batch upsert scenarios and cleanup behavior.
internal/api/middleware/agent_auth.go Introduces placeholder agent middleware (currently no-op).
internal/api/handler/templates/subject_template.go Adds agent /batch handler + request/response types and swagger annotations.
internal/api/handler/templates/subject_template_integration_test.go Adds integration coverage for agent subject template batch upsert behavior.
internal/api/handler/templates/risk_template.go Adds agent /batch handler + request/response types and swagger annotations.
internal/api/handler/templates/risk_template_integration_test.go Adds integration coverage for agent risk template batch upsert behavior.
internal/api/handler/api.go Registers new agent route groups for risk/subject template batch endpoints.
docs/swagger.yaml Documents new agent batch endpoints and request/response shapes.
docs/swagger.json Regenerated Swagger JSON with the new endpoints and schemas.
docs/docs.go Regenerated embedded Swagger docs with the new endpoints and schemas.
Makefile Updates integration test target to collect and summarize failing tests across runs.

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

Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Copy link
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

Adds agent-facing batch upsert endpoints for risk and subject templates, enabling agents to reconcile templates per plugin scope (and per policy package for risk templates) with create/update/delete semantics in a single transaction.

Changes:

  • Implement BatchUpsert in RiskTemplateService and SubjectTemplateService, including “unchanged” detection and transactional reconciliation + cleanup of dependent rows on delete.
  • Expose new /api/agent/*/batch endpoints in handlers, register routes, and generate Swagger artifacts.
  • Add unit + integration test coverage for batch upsert behaviors and update integration test tooling output.

Reviewed changes

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

Show a summary per file
File Description
testdata/empty_subject_batch.json Example payload for empty subject-template batch request.
testdata/empty_batch.json Example payload for empty risk-template batch request.
testdata/batch_upsert_subject_templates.json Example subject-template batch payload for agent use.
testdata/batch_upsert_risk_templates.json Example risk-template batch payload for agent use.
internal/service/relational/templates/subject_template_service_test.go Unit tests covering subject-template batch create/update/delete/validation behaviors.
internal/service/relational/templates/subject_template_service.go Adds subject-template batch reconciliation logic scoped by selector label _plugin.
internal/service/relational/templates/risk_template_service_test.go Unit tests covering risk-template batch reconciliation/validation behaviors.
internal/service/relational/templates/risk_template_service.go Adds risk-template batch reconciliation scoped by (pluginID, policyPackage) plus unchanged detection.
internal/api/middleware/agent_auth.go Introduces placeholder middleware for agent routes (currently no-op).
internal/api/handler/templates/subject_template_integration_test.go Integration tests for new subject-template agent batch endpoint.
internal/api/handler/templates/subject_template.go Adds agent route registration + batch request/response mapping and endpoint handler.
internal/api/handler/templates/risk_template_integration_test.go Integration tests for new risk-template agent batch endpoint.
internal/api/handler/templates/risk_template.go Adds agent route registration + batch request/response mapping and endpoint handler.
internal/api/handler/api.go Registers new /agent/risk-templates and /agent/subject-templates route groups.
docs/swagger.yaml Swagger definitions + paths for the new agent batch endpoints.
docs/swagger.json Generated Swagger JSON updates for the new endpoints and schemas.
docs/docs.go Generated embedded Swagger docs updates for the new endpoints and schemas.
Makefile Enhances integration test target to summarize failed tests and supports TEST_PATH.

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

Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Copy link
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 adds agent-facing batch upsert endpoints for RiskTemplates and SubjectTemplates, enabling agents to reconcile (create/update/delete) template sets in one atomic operation and exposing corresponding OpenAPI documentation and test fixtures.

Changes:

  • Implement BatchUpsert reconciliation logic for risk templates (scoped by (plugin-id, policy-package)) and subject templates (scoped by selector-label key "_plugin").
  • Add new /api/agent/*/batch handlers + integration/service-level tests covering create/update/delete/validation cases.
  • Update Swagger artifacts and add example JSON payloads; enhance make test-integration output to summarize failing tests across repeated runs.

Reviewed changes

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

Show a summary per file
File Description
internal/service/relational/templates/risk_template_service.go Adds risk-template batch upsert implementation, including “unchanged” detection via fingerprinting
internal/service/relational/templates/subject_template_service.go Adds subject-template batch upsert implementation scoped by selector-label "_plugin"
internal/api/handler/templates/risk_template.go Adds /agent/risk-templates/batch handler + request/response shapes
internal/api/handler/templates/subject_template.go Adds /agent/subject-templates/batch handler + request/response shapes
internal/api/handler/api.go Registers new agent route groups
internal/api/middleware/agent_auth.go Introduces placeholder agent JWT middleware
internal/service/relational/templates/risk_template_service_test.go Adds unit tests for risk batch upsert behavior
internal/service/relational/templates/subject_template_service_test.go Adds unit tests for subject batch upsert behavior (including evidence-link cleanup)
internal/api/handler/templates/*_integration_test.go Adds integration tests for the new agent batch endpoints
docs/swagger.yaml, docs/swagger.json, docs/docs.go Adds OpenAPI schema + paths for the new batch endpoints
testdata/*.json Adds example batch request payloads (including empty batches)
Makefile Improves integration test target to aggregate/report failing tests across runs

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

Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Copilot AI review requested due to automatic review settings March 17, 2026 13:02
Copy link
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 adds new agent-facing batch upsert endpoints for RiskTemplates and SubjectTemplates, enabling agents to reconcile templates in bulk (create/update/delete) within an atomic transaction and updating integration/unit tests + Swagger docs accordingly.

Changes:

  • Add BatchUpsert implementations to RiskTemplateService and SubjectTemplateService, including unchanged detection and scoped deletions.
  • Expose new public (currently no-op “auth”) agent endpoints: POST /api/agent/risk-templates/batch and POST /api/agent/subject-templates/batch, plus integration tests and Swagger updates.
  • Improve make test-integration output by summarizing failed tests across multiple runs.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
testdata/empty_subject_batch.json Adds example empty subject-template batch payload.
testdata/empty_batch.json Adds example empty risk-template batch payload.
testdata/batch_upsert_subject_templates.json Adds example subject-template batch upsert payload.
testdata/batch_upsert_risk_templates.json Adds example risk-template batch upsert payload.
internal/service/relational/templates/subject_template_service.go Implements SubjectTemplate BatchUpsert with plugin scoping and cleanup.
internal/service/relational/templates/subject_template_service_test.go Adds unit tests covering create/update/delete/unchanged/validation + cleanup behavior for subject batch upsert.
internal/service/relational/templates/risk_template_service.go Implements RiskTemplate BatchUpsert plus payload fingerprinting for unchanged detection.
internal/service/relational/templates/risk_template_service_test.go Adds unit tests covering create/update/delete/unchanged/validation + cleanup behavior for risk batch upsert.
internal/service/relational/templates/models.go Changes RiskTemplate IsActive default tag.
internal/api/middleware/agent_auth.go Introduces placeholder agent “JWT” middleware (currently a no-op).
internal/api/handler/templates/subject_template.go Adds agent batch endpoint handler + request/response types + Swagger annotations.
internal/api/handler/templates/subject_template_integration_test.go Adds integration coverage for agent subject batch upsert behavior (including public access).
internal/api/handler/templates/risk_template.go Adds agent batch endpoint handler + request/response types + Swagger annotations.
internal/api/handler/templates/risk_template_integration_test.go Adds integration coverage for agent risk batch upsert behavior (including public access).
internal/api/handler/api.go Registers /api/agent/* batch routes.
docs/swagger.yaml Documents new batch endpoints and request/response schemas.
docs/swagger.json Documents new batch endpoints and request/response schemas.
docs/docs.go Updates embedded Swagger spec with new endpoints/schemas.
Makefile Enhances integration test target with failed-test summary across runs.

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

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 17, 2026 13:14
Copy link
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 adds agent-facing batch upsert endpoints for RiskTemplates and SubjectTemplates, enabling an agent to reconcile the full template set for a given scope (plugin / plugin+policy package) via a single atomic request.

Changes:

  • Added BatchUpsert implementations to RiskTemplateService and SubjectTemplateService, including create/update/delete reconciliation and “unchanged” detection.
  • Exposed new /api/agent/*/batch endpoints with request/response types, swagger docs, and integration/unit tests.
  • Improved make test-integration output to summarize failed tests across repeated runs.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
testdata/empty_subject_batch.json Example payload for empty subject-template batch request
testdata/empty_batch.json Example payload for empty risk-template batch request
testdata/batch_upsert_subject_templates.json Example payload for subject-template batch upsert
testdata/batch_upsert_risk_templates.json Example payload for risk-template batch upsert
internal/service/relational/templates/subject_template_service_test.go Unit tests for subject-template batch upsert behavior
internal/service/relational/templates/subject_template_service.go SubjectTemplate BatchUpsert implementation + fingerprinting
internal/service/relational/templates/risk_template_service_test.go Unit tests for risk-template batch upsert behavior
internal/service/relational/templates/risk_template_service.go RiskTemplate BatchUpsert implementation + fingerprinting
internal/service/relational/templates/models.go Changes RiskTemplate IsActive DB default
internal/api/middleware/agent_auth.go Adds agent middleware stub (currently no-op)
internal/api/handler/templates/subject_template_integration_test.go Integration tests for agent subject-template batch endpoint
internal/api/handler/templates/subject_template.go Adds agent batch endpoint handler and request/response types
internal/api/handler/templates/risk_template_integration_test.go Integration tests for agent risk-template batch endpoint
internal/api/handler/templates/risk_template.go Adds agent batch endpoint handler and request/response types
internal/api/handler/api.go Registers new /api/agent/* routes
docs/swagger.yaml Documents new agent batch endpoints and schemas
docs/swagger.json Generated swagger JSON update
docs/docs.go Generated swagger docs update
Makefile Enhances integration-test loop reporting

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

Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
@gusfcarvalho gusfcarvalho enabled auto-merge (squash) March 17, 2026 13:31
@gusfcarvalho gusfcarvalho merged commit 6206f52 into main Mar 17, 2026
4 checks passed
@gusfcarvalho gusfcarvalho deleted the gc/feat/batch-enpdoints-for-agent branch March 17, 2026 13:35
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