Prepare shared glossary envelopes and combined input
This commit is contained in:
@@ -168,6 +168,7 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
{"campaign", artifactpolicy.SourceInputGlossaryCampaign},
|
||||
{"setting", artifactpolicy.SourceInputGlossarySetting},
|
||||
{"spells", artifactpolicy.SourceInputGlossarySpells},
|
||||
{"combined", artifactpolicy.SourceInputGlossaryCombined},
|
||||
} {
|
||||
descriptor, ok := artifactpolicy.DescribePreparedInputSource(item.source)
|
||||
if !ok {
|
||||
@@ -182,7 +183,13 @@ func (prepareStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: materialize %s: %w", descriptor.ManifestKind, err)
|
||||
}
|
||||
inputs = append(inputs, manifest.InputRecord{Kind: descriptor.ManifestKind, Path: dst, Checksum: checksum, Size: int64(len(data)), Source: "derived_from_configuration"})
|
||||
record := manifest.InputRecord{Kind: descriptor.ManifestKind, Path: dst, Checksum: checksum, Size: int64(len(data)), Source: "derived_from_configuration"}
|
||||
if item.source == artifactpolicy.SourceInputGlossaryCombined {
|
||||
for _, dependency := range artifactpolicy.GlossaryInputSources() {
|
||||
record.Dependencies = append(record.Dependencies, dependency.SourceID)
|
||||
}
|
||||
}
|
||||
inputs = append(inputs, record)
|
||||
}
|
||||
partyInputs, err := materializePreparedPartyInputs(env.ArtifactStore, env.Config, paths.InputsDir)
|
||||
if err != nil {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||
@@ -24,6 +25,7 @@ type prepareExpectedInput struct {
|
||||
destinationName string
|
||||
checksum string
|
||||
source string
|
||||
dependencies []string
|
||||
configSnapshot bool
|
||||
s3Bucket string
|
||||
s3Key string
|
||||
@@ -53,7 +55,7 @@ func (prepareStage) ValidateResume(ctx context.Context, env *Env, m *manifest.Ma
|
||||
return NonResumable(prepareResumeChangedReason), nil
|
||||
}
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
for _, source := range []string{artifactpolicy.SourceInputGlossaryParty, artifactpolicy.SourceInputGlossaryCampaign, artifactpolicy.SourceInputGlossarySetting, artifactpolicy.SourceInputGlossarySpells} {
|
||||
for _, source := range []string{artifactpolicy.SourceInputGlossaryParty, artifactpolicy.SourceInputGlossaryCampaign, artifactpolicy.SourceInputGlossarySetting, artifactpolicy.SourceInputGlossarySpells, artifactpolicy.SourceInputGlossaryCombined} {
|
||||
if _, err := artifacts.ResolvePreparedInput(paths, m, source); err != nil {
|
||||
return NonResumable(prepareResumeChangedReason), nil
|
||||
}
|
||||
@@ -128,12 +130,19 @@ func currentPrepareSourceInputs(ctx context.Context, env *Env, m *manifest.Manif
|
||||
for _, item := range []struct{ name, source string }{
|
||||
{"party", artifactpolicy.SourceInputGlossaryParty}, {"campaign", artifactpolicy.SourceInputGlossaryCampaign},
|
||||
{"setting", artifactpolicy.SourceInputGlossarySetting}, {"spells", artifactpolicy.SourceInputGlossarySpells},
|
||||
{"combined", artifactpolicy.SourceInputGlossaryCombined},
|
||||
} {
|
||||
descriptor, ok := artifactpolicy.DescribePreparedInputSource(item.source)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("glossary descriptor %q unavailable", item.source)
|
||||
}
|
||||
expected = append(expected, prepareExpectedInput{kind: descriptor.ManifestKind, checksum: checksumPrepareBytes(documents[item.name])})
|
||||
entry := prepareExpectedInput{kind: descriptor.ManifestKind, checksum: checksumPrepareBytes(documents[item.name])}
|
||||
if item.source == artifactpolicy.SourceInputGlossaryCombined {
|
||||
for _, dependency := range artifactpolicy.GlossaryInputSources() {
|
||||
entry.dependencies = append(entry.dependencies, dependency.SourceID)
|
||||
}
|
||||
}
|
||||
expected = append(expected, entry)
|
||||
}
|
||||
partyInputs, err := currentPreparePartySourceInputs(env)
|
||||
if err != nil {
|
||||
@@ -225,7 +234,7 @@ func prepareSourceInputsMatch(paths artifacts.SessionPaths, expected []prepareEx
|
||||
managedKinds := map[string]struct{}{
|
||||
"campaign_config": {}, "session_config": {},
|
||||
"audio": {}, "speakers": {}, "autocorrect": {}, "glossary": {},
|
||||
"glossary_party": {}, "glossary_campaign": {}, "glossary_setting": {}, "glossary_spells": {},
|
||||
"glossary_party": {}, "glossary_campaign": {}, "glossary_setting": {}, "glossary_spells": {}, "glossary_combined": {},
|
||||
"players": {}, "party": {},
|
||||
}
|
||||
expectedCounts := make(map[string]int, len(managedKinds))
|
||||
@@ -277,6 +286,9 @@ func prepareInputRecordMatches(paths artifacts.SessionPaths, expected prepareExp
|
||||
if expected.source != "" && record.Source != expected.source {
|
||||
return false
|
||||
}
|
||||
if !slices.Equal(expected.dependencies, record.Dependencies) {
|
||||
return false
|
||||
}
|
||||
if expected.destinationName != "" && filepath.Base(record.Path) != expected.destinationName {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
@@ -174,6 +176,79 @@ func TestPrepareAutocorrectionEvidenceAndReuse(t *testing.T) {
|
||||
assertPrepareResume(t, env, m, true)
|
||||
}
|
||||
|
||||
func TestCombinedGlossarySharesVerifiedReferenceAcrossRoles(t *testing.T) {
|
||||
env, m, _ := prepareResumeLocalFixture(t)
|
||||
record := findManifestInput(t, m.Inputs, "glossary_combined")
|
||||
var want []string
|
||||
for _, descriptor := range artifactpolicy.GlossaryInputSources() {
|
||||
want = append(want, descriptor.SourceID)
|
||||
}
|
||||
if !reflect.DeepEqual(record.Dependencies, want) {
|
||||
t.Fatalf("dependencies = %v, want %v", record.Dependencies, want)
|
||||
}
|
||||
for i := range m.Inputs {
|
||||
if m.Inputs[i].Kind == "glossary_combined" {
|
||||
m.Inputs[i].Dependencies = nil
|
||||
assertPrepareResume(t, env, m, false)
|
||||
m.Inputs[i].Dependencies = append([]string(nil), want...)
|
||||
}
|
||||
}
|
||||
manifestPath := filepath.Join(t.TempDir(), "manifest.json")
|
||||
store := &manifest.LocalStore{}
|
||||
if err := store.Save(context.Background(), manifestPath, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := store.Load(context.Background(), manifestPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := findManifestInput(t, loaded.Inputs, "glossary_combined").Dependencies; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("persisted dependencies = %v", got)
|
||||
}
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
configured := &config.NotariusConfig{References: map[string]string{"glossary": artifactpolicy.SourceInputGlossaryCombined, "spell_catalog": artifactpolicy.SourceInputGlossaryCombined}}
|
||||
references, err := resolveExtractReferences(paths, m, configured, m.SessionID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bindings, err := materializeExtractReferenceSnapshots(paths, references)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(bindings) != 2 || bindings[0].Path != bindings[1].Path {
|
||||
t.Fatalf("bindings = %+v", bindings)
|
||||
}
|
||||
if err := verifyExtractReferenceSnapshots(paths, references); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(bindings[0].Path, []byte("corrupt"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := verifyExtractReferenceSnapshots(paths, references); err == nil {
|
||||
t.Fatal("corrupt snapshot accepted")
|
||||
}
|
||||
if err := os.Remove(bindings[0].Path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := verifyExtractReferenceSnapshots(paths, references); err == nil {
|
||||
t.Fatal("missing snapshot accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCombinedGlossaryChangesWhenAnyCollectionChanges(t *testing.T) {
|
||||
env, m, _ := prepareResumeLocalFixture(t)
|
||||
before := findManifestInput(t, m.Inputs, "glossary_combined").Checksum
|
||||
env.Config.Session.Inputs.Glossary = map[string]any{"entries": []any{map[string]any{"id": "harbor", "name": "Harbor", "category": "place"}}}
|
||||
assertPrepareResume(t, env, m, false)
|
||||
if _, err := (prepareStage{}).Run(context.Background(), env, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
after := findManifestInput(t, m.Inputs, "glossary_combined").Checksum
|
||||
if before == after {
|
||||
t.Fatal("combined glossary did not change")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareSnapshotComparisonIgnoresRelocatedSourcePaths(t *testing.T) {
|
||||
first := []byte("schema_version: maximumdirect.rpg.campaign.v1\nid: campaign\nreferences: {party: /old/party.yml}\nnarratio:\n inputs: {speakers_file: /old/speakers.yml, glossary_file: /old/glossary.yml}\n")
|
||||
second := []byte("schema_version: maximumdirect.rpg.campaign.v1\nid: campaign\nreferences: {party: /new/party.yml}\nnarratio:\n inputs: {speakers_file: /new/speakers.yml, glossary_file: /new/glossary.yml}\n")
|
||||
@@ -309,19 +384,19 @@ func TestPrepareResumeTracksEffectiveGlossaryVocabulary(t *testing.T) {
|
||||
writeFile(t, filepath.Join(root, "audio", "one.flac"), "audio")
|
||||
source := filepath.Join(root, "vocabulary.yml")
|
||||
fragment := filepath.Join(root, "fragment.yml")
|
||||
writeFile(t, source, "config:\n imports:\n - path: fragment.yml\ncampaign: {instruction: Names}\n")
|
||||
writeFile(t, fragment, "campaign: {entries: [{id: watch, name: Watch, category: organization}]}\n")
|
||||
writeFile(t, source, "config:\n imports:\n - path: fragment.yml\nschema_version: maximumdirect.glossary.v1\ncollections:\n campaign: {instruction: Names}\n")
|
||||
writeFile(t, fragment, "collections:\n campaign: {entries: [{id: watch, name: Watch, category: organization}]}\n")
|
||||
env.Config.Session.Inputs.GlossaryFile = &source
|
||||
if _, err := (prepareStage{}).Run(context.Background(), env, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertPrepareResume(t, env, m, true)
|
||||
relocated := filepath.Join(root, "relocated.yml")
|
||||
writeFile(t, relocated, "campaign:\n instruction: Names\n entries:\n - {name: Watch, id: watch, category: organization}\n")
|
||||
writeFile(t, relocated, "schema_version: maximumdirect.glossary.v1\ncollections:\n campaign:\n instruction: Names\n entries:\n - {name: Watch, id: watch, category: organization}\n")
|
||||
env.Config.Session.Inputs.GlossaryFile = &relocated
|
||||
assertPrepareResume(t, env, m, true)
|
||||
env.Config.Session.Inputs.GlossaryFile = &source
|
||||
writeFile(t, fragment, "campaign: {entries: [{id: watch, name: Changed, category: organization}]}\n")
|
||||
writeFile(t, fragment, "collections:\n campaign: {entries: [{id: watch, name: Changed, category: organization}]}\n")
|
||||
assertPrepareResume(t, env, m, false)
|
||||
}
|
||||
|
||||
@@ -342,8 +417,8 @@ func TestPrepareResumeChecksSelectedCatalogContent(t *testing.T) {
|
||||
root := filepath.Dir(env.Config.SessionPath)
|
||||
writeFile(t, filepath.Join(root, "audio", "one.flac"), "audio")
|
||||
one, two := filepath.Join(root, "one.yml"), filepath.Join(root, "two.yml")
|
||||
writeFile(t, one, "setting: {entries: [{id: place, name: One, category: place}]}\n")
|
||||
writeFile(t, two, "setting: {entries: [{id: place, name: Two, category: place}]}\n")
|
||||
writeFile(t, one, "schema_version: maximumdirect.glossary.v1\ncollections:\n setting: {entries: [{id: place, name: One, category: place}]}\n")
|
||||
writeFile(t, two, "schema_version: maximumdirect.glossary.v1\ncollections:\n setting: {entries: [{id: place, name: Two, category: place}]}\n")
|
||||
env.Config.Pipeline.ReferenceCatalog.Settings = map[string]string{"one": one, "two": two}
|
||||
env.Config.Session.Inputs.Setting = new("one")
|
||||
if _, err := (prepareStage{}).Run(context.Background(), env, m); err != nil {
|
||||
|
||||
@@ -45,6 +45,7 @@ func TestPrepareStageExplicitAudioFiles(t *testing.T) {
|
||||
filepath.Join(paths.InputsDir, "glossaries", "campaign.yml"),
|
||||
filepath.Join(paths.InputsDir, "glossaries", "setting.yml"),
|
||||
filepath.Join(paths.InputsDir, "glossaries", "spells.yml"),
|
||||
filepath.Join(paths.InputsDir, "glossaries", "combined.yml"),
|
||||
filepath.Join(paths.InputsDir, "players.yml"),
|
||||
filepath.Join(paths.InputsDir, "party.yml"),
|
||||
filepath.Join(paths.AudioDir, "alice.flac"),
|
||||
@@ -55,8 +56,8 @@ func TestPrepareStageExplicitAudioFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(m.Inputs) != 13 {
|
||||
t.Fatalf("manifest inputs len = %d, want 13", len(m.Inputs))
|
||||
if len(m.Inputs) != 14 {
|
||||
t.Fatalf("manifest inputs len = %d, want 14", len(m.Inputs))
|
||||
}
|
||||
for _, in := range m.Inputs {
|
||||
if in.Checksum == "" {
|
||||
|
||||
@@ -14,9 +14,12 @@ func TestPublishPreparedInputsRetainVerifiedBytesAndRejectTampering(t *testing.T
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(files) != 7 {
|
||||
if len(files) != 8 {
|
||||
t.Fatalf("prepared archive files = %d", len(files))
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(runRoot, "prepare", "inputs", "glossaries", "combined.yml")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, file := range files {
|
||||
path := filepath.Join(runRoot, filepath.FromSlash(file.RelativePath))
|
||||
checksum, err := env.ArtifactStore.Checksum(path)
|
||||
|
||||
@@ -35,6 +35,9 @@ func collectPublishPreparedInputs(store artifacts.Store, paths artifacts.Session
|
||||
filenames[descriptor.ManifestKind] = descriptor.Filename
|
||||
glossaries[descriptor.ManifestKind] = descriptor
|
||||
}
|
||||
combined, _ := artifactpolicy.DescribePreparedInputSource(artifactpolicy.SourceInputGlossaryCombined)
|
||||
filenames[combined.ManifestKind] = combined.Filename
|
||||
glossaries[combined.ManifestKind] = combined
|
||||
var result []publishUploadFile
|
||||
for _, record := range records {
|
||||
name, ok := filenames[record.Kind]
|
||||
|
||||
@@ -154,6 +154,7 @@ func prepareStableInputSemantics(cfg *config.Config) []prepareStableInputSelecti
|
||||
{Kind: "autocorrect", Present: true},
|
||||
{Kind: "glossary_party", Present: true}, {Kind: "glossary_campaign", Present: true},
|
||||
{Kind: "glossary_setting", Present: true}, {Kind: "glossary_spells", Present: true},
|
||||
{Kind: "glossary_combined", Present: true},
|
||||
prepareStableInput("party", stable.PartyFile, ""),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ func setupTranscribeEnv(t *testing.T, audioFiles []string) (*Env, *manifest.Mani
|
||||
writeFile(t, campaignPath, "campaign_id: sample-campaign\ninputs:\n speakers_file: ./speakers.yml\n autocorrect_file: ./autocorrect.yml\n glossary_file: ./glossary.yml\n party_file: ./party.yml\n")
|
||||
writeFile(t, filepath.Join(cfgDir, "speakers.yml"), "alice: alice.flac\n")
|
||||
writeFile(t, filepath.Join(cfgDir, "autocorrect.yml"), "[]\n")
|
||||
writeFile(t, filepath.Join(cfgDir, "glossary.yml"), "campaign: {entries: []}\n")
|
||||
writeFile(t, filepath.Join(cfgDir, "glossary.yml"), "schema_version: maximumdirect.glossary.v1\ncollections:\n campaign: {entries: []}\n")
|
||||
partyBytes := []byte("schema_version: maximumdirect.rpg.party.v1\ncharacters:\n arannis:\n player: {name: Eric}\n character:\n name: Arannis\n classes: [{name: wizard}]\n")
|
||||
writeFile(t, filepath.Join(cfgDir, "party.yml"), string(partyBytes))
|
||||
party, err := config.ParseParty(partyBytes)
|
||||
|
||||
Reference in New Issue
Block a user