Complete Phase 15 spoken-word module
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
glossarymodule "gitea.maximumdirect.net/eric/audita/internal/modules/glossary"
|
||||
grammarmodule "gitea.maximumdirect.net/eric/audita/internal/modules/grammar"
|
||||
homophonesmodule "gitea.maximumdirect.net/eric/audita/internal/modules/homophones"
|
||||
spokenwordmodule "gitea.maximumdirect.net/eric/audita/internal/modules/spoken_word"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -74,6 +75,7 @@ func NewFactory(deps Dependencies) *Factory {
|
||||
}
|
||||
_ = factory.RegisterConstructor(ModuleKeyGlossary, constructGlossaryModule)
|
||||
_ = factory.RegisterConstructor(ModuleKeyHomophones, constructHomophonesModule)
|
||||
_ = factory.RegisterConstructor(ModuleKeySpokenWord, constructSpokenWordModule)
|
||||
_ = factory.RegisterConstructor(ModuleKeyGrammar, constructGrammarModule)
|
||||
return factory
|
||||
}
|
||||
@@ -112,6 +114,12 @@ func constructHomophonesModule(ctx context.Context, req ConstructRequest) (contr
|
||||
return homophonesmodule.New()
|
||||
}
|
||||
|
||||
func constructSpokenWordModule(ctx context.Context, req ConstructRequest) (contracts.TranscriptModule, error) {
|
||||
_ = ctx
|
||||
_ = req
|
||||
return spokenwordmodule.New()
|
||||
}
|
||||
|
||||
// ModuleForSpec resolves one configured run spec into a module instance.
|
||||
func (f *Factory) ModuleForSpec(spec contracts.ModuleRunSpec) (contracts.TranscriptModule, error) {
|
||||
if f == nil {
|
||||
|
||||
@@ -66,21 +66,20 @@ func TestUnsupportedUnknownModuleKeyFailsCleanly(t *testing.T) {
|
||||
|
||||
func TestRecognizedButUnimplementedModuleKeyFailsCleanly(t *testing.T) {
|
||||
factory := NewFactory(Dependencies{})
|
||||
for _, key := range []string{ModuleKeySpokenWord} {
|
||||
t.Run(key, func(t *testing.T) {
|
||||
_, err := factory.ModuleForSpec(contracts.ModuleRunSpec{ModuleKey: key, InstanceName: key})
|
||||
if err == nil {
|
||||
t.Fatal("expected unimplemented-module error")
|
||||
}
|
||||
// Force an unimplemented state for a known key to keep reason-code behavior tested.
|
||||
factory.constructors[ModuleKeySpokenWord] = nil
|
||||
|
||||
var unimplemented *UnimplementedModuleError
|
||||
if !errors.As(err, &unimplemented) {
|
||||
t.Fatalf("expected UnimplementedModuleError, got %T (%v)", err, err)
|
||||
}
|
||||
if unimplemented.ReasonCode() != ReasonUnimplementedModule {
|
||||
t.Fatalf("unexpected reason code: %q", unimplemented.ReasonCode())
|
||||
}
|
||||
})
|
||||
_, err := factory.ModuleForSpec(contracts.ModuleRunSpec{ModuleKey: ModuleKeySpokenWord, InstanceName: ModuleKeySpokenWord})
|
||||
if err == nil {
|
||||
t.Fatal("expected unimplemented-module error")
|
||||
}
|
||||
|
||||
var unimplemented *UnimplementedModuleError
|
||||
if !errors.As(err, &unimplemented) {
|
||||
t.Fatalf("expected UnimplementedModuleError, got %T (%v)", err, err)
|
||||
}
|
||||
if unimplemented.ReasonCode() != ReasonUnimplementedModule {
|
||||
t.Fatalf("unexpected reason code: %q", unimplemented.ReasonCode())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +116,17 @@ func TestHomophonesIsRegisteredAndConstructibleByDefault(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpokenWordIsRegisteredAndConstructibleByDefault(t *testing.T) {
|
||||
factory := NewFactory(Dependencies{})
|
||||
module, err := factory.ModuleForSpec(contracts.ModuleRunSpec{ModuleKey: ModuleKeySpokenWord, InstanceName: ModuleKeySpokenWord})
|
||||
if err != nil {
|
||||
t.Fatalf("ModuleForSpec error: %v", err)
|
||||
}
|
||||
if module.Key() != ModuleKeySpokenWord {
|
||||
t.Fatalf("expected spoken_word module key, got %q", module.Key())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterConstructorAndConstruct(t *testing.T) {
|
||||
factory := NewFactory(Dependencies{})
|
||||
if err := factory.RegisterConstructor(ModuleKeyGlossary, func(ctx context.Context, req ConstructRequest) (contracts.TranscriptModule, error) {
|
||||
|
||||
Reference in New Issue
Block a user