Register prepared glossary input identities

This commit is contained in:
2026-11-27 16:24:08 +00:00
parent caddd668ca
commit 1bb1daa1f2
8 changed files with 81 additions and 13 deletions

View File

@@ -48,6 +48,9 @@ type PreparedInputIdentity struct {
func ResolvePreparedInput(paths SessionPaths, m *manifest.Manifest, sourceID string) (PreparedInputIdentity, error) {
descriptor, ok := artifactpolicy.DescribePreparedInputSource(sourceID)
if !ok {
if sourceID == artifactpolicy.SourceInputGlossary {
return PreparedInputIdentity{}, fmt.Errorf("retired prepared input source %q: select an explicit narratio.input.glossary.<party|campaign|setting|spells> source", sourceID)
}
return PreparedInputIdentity{}, fmt.Errorf("unsupported prepared input source %q", sourceID)
}

View File

@@ -185,7 +185,7 @@ func preparedInputFixture(
t.Fatalf("DescribePreparedInputSource(%q) ok = false", sourceID)
}
canonicalPath := filepath.Join(paths.InputsDir, descriptor.Filename)
if err := os.MkdirAll(paths.InputsDir, 0o755); err != nil {
if err := os.MkdirAll(filepath.Dir(canonicalPath), 0o755); err != nil {
t.Fatalf("MkdirAll(inputs) error = %v", err)
}
if err := os.WriteFile(canonicalPath, payload, 0o644); err != nil {
@@ -204,3 +204,34 @@ func preparedInputFixture(
}}
return paths, m, canonicalPath, checksum
}
func TestResolvePreparedGlossaryDocuments(t *testing.T) {
for _, source := range []string{artifactpolicy.SourceInputGlossaryParty, artifactpolicy.SourceInputGlossaryCampaign, artifactpolicy.SourceInputGlossarySetting, artifactpolicy.SourceInputGlossarySpells} {
t.Run(source, func(t *testing.T) {
payload := []byte("sample: {entries: []}\n")
paths, m, file, checksum := preparedInputFixture(t, source, payload)
got, err := ResolvePreparedInput(paths, m, source)
if err != nil {
t.Fatal(err)
}
if got.Path != file || got.Checksum != checksum || got.Size != int64(len(payload)) || !strings.Contains(got.RelativePath, "inputs/glossaries/") {
t.Fatalf("identity: %+v", got)
}
if err := os.WriteFile(file, []byte("changed"), 0644); err != nil {
t.Fatal(err)
}
if _, err := ResolvePreparedInput(paths, m, source); err == nil || !strings.Contains(err.Error(), "checksum") {
t.Fatalf("tampered input: %v", err)
}
if err := os.Remove(file); err != nil {
t.Fatal(err)
}
if _, err := ResolvePreparedInput(paths, m, source); err == nil {
t.Fatal("missing input accepted")
}
})
}
if _, err := ResolvePreparedInput(SessionPaths{}, nil, artifactpolicy.SourceInputGlossary); err == nil || !strings.Contains(err.Error(), "replace") && !strings.Contains(err.Error(), "explicit") {
t.Fatalf("retired source: %v", err)
}
}