87 lines
3.4 KiB
Go
87 lines
3.4 KiB
Go
package artifacts
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
)
|
|
|
|
func TestResolveEffectiveArtifactSetUsesDefaultsOrExplicitSelection(t *testing.T) {
|
|
configured := map[string]ConfiguredArtifactDefinition{
|
|
"session_recap": {Enabled: true, OutputPath: "artifacts/session_recap.md"},
|
|
"player_handout": {Enabled: false, OutputPath: "artifacts/player_handout.md"},
|
|
}
|
|
|
|
defaults, err := ResolveEffectiveArtifactSet(configured, nil)
|
|
if err != nil {
|
|
t.Fatalf("ResolveEffectiveArtifactSet(defaults) error = %v", err)
|
|
}
|
|
if got, want := defaults.Keys(), []string{"session_recap"}; !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("default keys = %v, want %v", got, want)
|
|
}
|
|
|
|
explicit, err := ResolveEffectiveArtifactSet(configured, []string{"player_handout"})
|
|
if err != nil {
|
|
t.Fatalf("ResolveEffectiveArtifactSet(explicit) error = %v", err)
|
|
}
|
|
if got, want := explicit.Keys(), []string{"player_handout"}; !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("explicit keys = %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestBootstrapRuntimeCatalogUsesEffectiveSetAndDeterministicDefinitions(t *testing.T) {
|
|
configured := map[string]ConfiguredArtifactDefinition{
|
|
"zeta": {Enabled: true, OutputPath: "artifacts/zeta.md"},
|
|
"alpha": {Enabled: false, OutputPath: "artifacts/alpha.md"},
|
|
}
|
|
effective, err := ResolveEffectiveArtifactSet(configured, []string{"alpha"})
|
|
if err != nil {
|
|
t.Fatalf("ResolveEffectiveArtifactSet() error = %v", err)
|
|
}
|
|
catalog, err := BootstrapRuntimeCatalog(configured, effective, map[string]ExtractionArtifactDefinition{
|
|
"zeta_lane": {LaneID: "zeta"},
|
|
"alpha_lane": {LaneID: "alpha"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("BootstrapRuntimeCatalog() error = %v", err)
|
|
}
|
|
|
|
configuredEntries := catalog.ListConfigured()
|
|
if got, want := []string{configuredEntries[0].ConfiguredKey, configuredEntries[1].ConfiguredKey}, []string{"alpha", "zeta"}; !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("configured order = %v, want %v", got, want)
|
|
}
|
|
if !configuredEntries[0].Executable || configuredEntries[1].Executable {
|
|
t.Fatalf("configured executability = %+v, want only alpha executable", configuredEntries)
|
|
}
|
|
extractionEntries := catalog.ListExtraction()
|
|
if got, want := []string{extractionEntries[0].ExtractionKey, extractionEntries[1].ExtractionKey}, []string{"alpha_lane", "zeta_lane"}; !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("extraction order = %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestCollectPreviousArtifactRequirementsUsesExactEffectiveSet(t *testing.T) {
|
|
configured := map[string]config.ScriptoriumArtifactConfig{
|
|
"default_artifact": {
|
|
Enabled: true,
|
|
Inputs: map[string]config.ScriptoriumInputConfig{
|
|
"previous": {Source: "narratio.previous_session.artifact.default_artifact", Required: true},
|
|
},
|
|
},
|
|
"explicit_artifact": {
|
|
Enabled: false,
|
|
Inputs: map[string]config.ScriptoriumInputConfig{
|
|
"previous": {Source: "narratio.previous_session.artifact.explicit_artifact", Required: true},
|
|
},
|
|
},
|
|
}
|
|
effective, err := ResolveEffectiveArtifactSet(ConfiguredArtifactDefinitions(configured), []string{"explicit_artifact"})
|
|
if err != nil {
|
|
t.Fatalf("ResolveEffectiveArtifactSet() error = %v", err)
|
|
}
|
|
requirements := CollectPreviousArtifactRequirements(configured, effective)
|
|
if len(requirements) != 1 || requirements[0].Name != "explicit_artifact" || !requirements[0].Required {
|
|
t.Fatalf("requirements = %#v, want only the explicit artifact prerequisite", requirements)
|
|
}
|
|
}
|