Skip to content

refactor: replace concrete type assertions with capability interfaces#120

Merged
intel352 merged 2 commits intomainfrom
refactor/issue-59-replace-type-assertions-with-interfaces
Feb 23, 2026
Merged

refactor: replace concrete type assertions with capability interfaces#120
intel352 merged 2 commits intomainfrom
refactor/issue-59-replace-type-assertions-with-interfaces

Conversation

@intel352
Copy link
Contributor

Summary

  • Defines two new interfaces in the interfaces/ package (SchemaRegistrar and WorkflowStoreProvider) that modules opt into, replacing direct concrete type assertions in cmd/server/main.go
  • Replaces svc.(*module.OpenAPIGenerator) with svc.(interfaces.SchemaRegistrar) — the server no longer needs to know the specific module type to enrich the OpenAPI spec
  • Replaces svc.(*module.WorkflowRegistry) with svc.(interfaces.WorkflowStoreProvider) — the server no longer needs to know the specific module type to discover the workflow data store
  • Adds RegisterAdminSchemas() method to *OpenAPIGenerator and WorkflowStore() any method to *WorkflowRegistry so they satisfy the new interfaces
  • Adds compile-time interface assertions (var _ interfaces.X = (*ConcreteType)(nil)) in both module files to catch regressions early

Test plan

  • go build ./... passes
  • go test ./... passes (all packages)
  • golangci-lint run reports 0 issues
  • Pre-push hooks pass (build + lint)
  • No behaviour changed — only the type-check mechanism is updated

closes #59

🤖 Generated with Claude Code

…closes #59)

Replace two concrete type assertions in cmd/server/main.go with interface checks:

1. svc.(*module.OpenAPIGenerator) → svc.(interfaces.SchemaRegistrar)
   - Define SchemaRegistrar in interfaces/ with Name(), RegisterAdminSchemas(),
     ApplySchemas() methods
   - Add RegisterAdminSchemas() method to *OpenAPIGenerator that delegates to
     the package-level RegisterAdminSchemas function
   - Add compile-time check: var _ interfaces.SchemaRegistrar = (*OpenAPIGenerator)(nil)

2. svc.(*module.WorkflowRegistry) → svc.(interfaces.WorkflowStoreProvider)
   - Define WorkflowStoreProvider in interfaces/ with Name() and WorkflowStore() any
   - Add WorkflowStore() any method to *WorkflowRegistry returning the store opaquely
     (avoids interfaces→module circular import)
   - Add compile-time check: var _ interfaces.WorkflowStoreProvider = (*WorkflowRegistry)(nil)

No behaviour is changed; only the mechanism for identifying capable services is updated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 23, 2026 08:55
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 introduces capability interfaces to decouple server startup code from concrete module types, replacing 2 of the 15+ type assertions mentioned in issue #59. The change establishes a pattern where modules opt into interfaces rather than having the server depend on specific concrete types, improving plugin isolation and modularity.

Changes:

  • Adds two new capability interfaces (SchemaRegistrar and WorkflowStoreProvider) in the interfaces/ package
  • Updates OpenAPIGenerator and WorkflowRegistry modules to satisfy these interfaces with compile-time assertions
  • Replaces concrete type assertions in cmd/server/main.go with interface-based checks

Reviewed changes

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

File Description
interfaces/registry.go Defines new SchemaRegistrar and WorkflowStoreProvider capability interfaces for decoupling server from concrete module types
module/openapi_generator.go Adds RegisterAdminSchemas() method and compile-time assertion to satisfy SchemaRegistrar interface
module/workflow_registry.go Adds WorkflowStore() method and compile-time assertion to satisfy WorkflowStoreProvider interface
cmd/server/main.go Replaces concrete type assertions with interface checks for OpenAPIGenerator and WorkflowRegistry
Comments suppressed due to low confidence (2)

cmd/server/main.go:503

  • The WorkflowStore() method can return nil if the WorkflowRegistry hasn't been started yet or if Start() failed. This code should check for nil before attempting the type assertion to *module.V1Store. Consider adding a nil check:
if provider, ok := svc.(interfaces.WorkflowStoreProvider); ok {
    workflowStore := provider.WorkflowStore()
    if workflowStore == nil {
        continue
    }
    if s, ok := workflowStore.(*module.V1Store); ok {
        store = s
        logger.Info("Using WorkflowRegistry store", "module", provider.Name())
        break
    }
}
		if provider, ok := svc.(interfaces.WorkflowStoreProvider); ok {
			if s, ok := provider.WorkflowStore().(*module.V1Store); ok {

interfaces/registry.go:34

  • The WorkflowStore() documentation should mention that it may return nil if the store hasn't been initialized yet. This would help callers understand they need to perform nil checks. Consider updating the comment to:

"WorkflowStore returns the underlying workflow data store as an opaque value, or nil if the store has not been initialized. The caller is responsible for checking for nil and asserting the concrete type (typically *module.V1Store) when further operations are required."

	// WorkflowStore returns the underlying workflow data store as an opaque
	// value. The caller is responsible for asserting the concrete type
	// (typically *module.V1Store) when further operations are required.
	WorkflowStore() any

@intel352 intel352 merged commit e502c24 into main Feb 23, 2026
14 checks passed
@intel352 intel352 deleted the refactor/issue-59-replace-type-assertions-with-interfaces branch February 23, 2026 09:21
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.

Replace 15+ concrete type assertions with capability interfaces in cmd/server/main.go

2 participants