Add Notarius reference configuration vocabulary

This commit is contained in:
2026-08-29 14:55:24 +00:00
parent 42ed81cbe1
commit 5831c0c9e6
12 changed files with 476 additions and 42 deletions

View File

@@ -13,9 +13,10 @@ import (
const (
SourceBoundsSession = "narratio.bounds.session"
SourceInputPlayers = "narratio.input.players"
SourceInputParty = "narratio.input.party"
SourceInputGlossary = "narratio.input.glossary"
SourceInputPlayers = "narratio.input.players"
SourceInputParty = "narratio.input.party"
SourceInputGlossary = "narratio.input.glossary"
SourceInputSpellCatalog = "narratio.input.spell_catalog"
configuredSourcePrefix = "narratio.artifact."
extractionSourcePrefix = "narratio.extraction."
@@ -52,9 +53,18 @@ type Source struct {
// ScriptoriumInputSourceDescriptor describes one validated Scriptorium input source.
type ScriptoriumInputSourceDescriptor struct {
Source Source
PreparedInput *PreparedInputSourceDescriptor
PreviousSession *PreviousSessionSourceDescriptor
}
// PreparedInputSourceDescriptor describes a prepared stable input's source,
// manifest kind, and canonical staged filename.
type PreparedInputSourceDescriptor struct {
SourceID string
ManifestKind string
Filename string
}
// PreviousSessionSourceDescriptor describes one canonical previous-session input source.
type PreviousSessionSourceDescriptor struct {
SourceID string
@@ -158,9 +168,10 @@ func DescribeScriptoriumInputSource(source string) (ScriptoriumInputSourceDescri
if trimmed == "" {
return ScriptoriumInputSourceDescriptor{}, ErrUnsupportedScriptoriumInputSource
}
if IsStableInputSource(trimmed) {
if prepared, ok := DescribePreparedInputSource(trimmed); ok {
return ScriptoriumInputSourceDescriptor{
Source: Source{ID: trimmed, Kind: SourceKindStableInput},
Source: Source{ID: prepared.SourceID, Kind: SourceKindStableInput},
PreparedInput: &prepared,
}, nil
}
if strings.HasPrefix(trimmed, "narratio.previous_session.artifact") {
@@ -188,12 +199,38 @@ func DescribeScriptoriumInputSource(source string) (ScriptoriumInputSourceDescri
// IsStableInputSource reports whether source is a prepared stable input source
// available only to Scriptorium input resolution.
func IsStableInputSource(source string) bool {
switch strings.TrimSpace(source) {
case SourceInputPlayers, SourceInputParty, SourceInputGlossary:
return true
default:
return false
}
_, ok := DescribePreparedInputSource(source)
return ok
}
var preparedInputSources = map[string]PreparedInputSourceDescriptor{
SourceInputPlayers: {
SourceID: SourceInputPlayers,
ManifestKind: "players",
Filename: "players.yml",
},
SourceInputParty: {
SourceID: SourceInputParty,
ManifestKind: "party",
Filename: "party.yml",
},
SourceInputGlossary: {
SourceID: SourceInputGlossary,
ManifestKind: "glossary",
Filename: "glossary.yml",
},
SourceInputSpellCatalog: {
SourceID: SourceInputSpellCatalog,
ManifestKind: "spell_catalog",
Filename: "spell_catalog.json",
},
}
// DescribePreparedInputSource returns the canonical descriptor for a prepared
// stable input source.
func DescribePreparedInputSource(source string) (PreparedInputSourceDescriptor, bool) {
descriptor, ok := preparedInputSources[strings.TrimSpace(source)]
return descriptor, ok
}
// DescribePreviousSessionSource validates a canonical previous-session source id

View File

@@ -170,6 +170,7 @@ func TestDescribeScriptoriumInputSource(t *testing.T) {
{name: "prepared players input", source: "narratio.input.players", wantKind: SourceKindStableInput},
{name: "prepared party input", source: "narratio.input.party", wantKind: SourceKindStableInput},
{name: "prepared glossary input", source: "narratio.input.glossary", wantKind: SourceKindStableInput},
{name: "prepared spell catalog input", source: "narratio.input.spell_catalog", wantKind: SourceKindStableInput},
{name: "configured", source: "narratio.artifact.session_recap", wantKind: SourceKindConfiguredArtifact, wantKey: "session_recap"},
{name: "previous", source: "narratio.previous_session.artifact.session_recap", wantKind: SourceKindPreviousArtifact, wantKey: "session_recap", wantPrev: true},
{name: "invalid previous", source: "narratio.previous_session.artifact.", wantErr: ErrInvalidPreviousSessionSource},
@@ -211,6 +212,43 @@ func TestDescribeScriptoriumInputSource(t *testing.T) {
}
}
func TestDescribePreparedInputSource(t *testing.T) {
tests := []struct {
source string
manifestKind string
filename string
}{
{source: SourceInputPlayers, manifestKind: "players", filename: "players.yml"},
{source: SourceInputParty, manifestKind: "party", filename: "party.yml"},
{source: SourceInputGlossary, manifestKind: "glossary", filename: "glossary.yml"},
{source: SourceInputSpellCatalog, manifestKind: "spell_catalog", filename: "spell_catalog.json"},
}
for _, tt := range tests {
t.Run(tt.manifestKind, func(t *testing.T) {
descriptor, ok := DescribePreparedInputSource(" " + tt.source + " ")
if !ok {
t.Fatalf("DescribePreparedInputSource(%q) ok = false", tt.source)
}
if descriptor.SourceID != tt.source || descriptor.ManifestKind != tt.manifestKind || descriptor.Filename != tt.filename {
t.Fatalf("DescribePreparedInputSource(%q) = %#v", tt.source, descriptor)
}
scriptoriumDescriptor, err := DescribeScriptoriumInputSource(tt.source)
if err != nil {
t.Fatalf("DescribeScriptoriumInputSource(%q) error = %v", tt.source, err)
}
if scriptoriumDescriptor.PreparedInput == nil || *scriptoriumDescriptor.PreparedInput != descriptor {
t.Fatalf("prepared input descriptor = %#v, want %#v", scriptoriumDescriptor.PreparedInput, descriptor)
}
})
}
if _, ok := DescribePreparedInputSource("narratio.input.unknown"); ok {
t.Fatal("DescribePreparedInputSource(unknown) ok = true")
}
}
func TestValidateInputConfiguredReference(t *testing.T) {
configured := map[string]struct{}{"session_recap": {}}