Register prepared glossary input identities
This commit is contained in:
@@ -252,7 +252,14 @@ omitted roles, invalid selected sources, and nonmutation of native configuration
|
||||
|
||||
## Stage 6. Register shared glossary identities and canonical paths
|
||||
|
||||
Status: Pending
|
||||
Status: Complete
|
||||
|
||||
Registered the four nested prepared-input descriptors and retired the old
|
||||
source, with migration guidance for both consumer bindings. Focused artifact
|
||||
policy, prepared-input, and configuration tests cover all four identities,
|
||||
checksums, sizes, tampering and missing files. Existing preparation still uses
|
||||
the retired source until Stage 7, and maintained consumer fixtures are updated
|
||||
in Stage 16; related end-to-end tests are deferred until those cutovers.
|
||||
|
||||
Read roadmap “Shared input identities and cutover,” `artifactpolicy/policy.go`,
|
||||
`artifacts/prepared_input.go`, and the existing prepared-input tests.
|
||||
|
||||
@@ -13,10 +13,14 @@ import (
|
||||
const (
|
||||
SourceBoundsSession = "narratio.bounds.session"
|
||||
|
||||
SourceInputPlayers = "narratio.input.players"
|
||||
SourceInputParty = "narratio.input.party"
|
||||
SourceInputGlossary = "narratio.input.glossary"
|
||||
SourceInputSpellCatalog = "narratio.input.spell_catalog"
|
||||
SourceInputPlayers = "narratio.input.players"
|
||||
SourceInputParty = "narratio.input.party"
|
||||
SourceInputGlossary = "narratio.input.glossary"
|
||||
SourceInputGlossaryParty = "narratio.input.glossary.party"
|
||||
SourceInputGlossaryCampaign = "narratio.input.glossary.campaign"
|
||||
SourceInputGlossarySetting = "narratio.input.glossary.setting"
|
||||
SourceInputGlossarySpells = "narratio.input.glossary.spells"
|
||||
SourceInputSpellCatalog = "narratio.input.spell_catalog"
|
||||
|
||||
configuredSourcePrefix = "narratio.artifact."
|
||||
extractionSourcePrefix = "narratio.extraction."
|
||||
@@ -167,6 +171,9 @@ func DescribeScriptoriumInputSource(source string) (ScriptoriumInputSourceDescri
|
||||
if trimmed == "" {
|
||||
return ScriptoriumInputSourceDescriptor{}, ErrUnsupportedScriptoriumInputSource
|
||||
}
|
||||
if trimmed == SourceInputGlossary {
|
||||
return ScriptoriumInputSourceDescriptor{}, fmt.Errorf("%w: replace %s with an explicit narratio.input.glossary.<party|campaign|setting|spells> source", ErrUnsupportedScriptoriumInputSource, trimmed)
|
||||
}
|
||||
if prepared, ok := DescribePreparedInputSource(trimmed); ok {
|
||||
return ScriptoriumInputSourceDescriptor{
|
||||
Source: Source{ID: prepared.SourceID, Kind: SourceKindStableInput},
|
||||
@@ -205,11 +212,10 @@ var preparedInputSources = map[string]PreparedInputSourceDescriptor{
|
||||
ManifestKind: "party",
|
||||
Filename: "party.yml",
|
||||
},
|
||||
SourceInputGlossary: {
|
||||
SourceID: SourceInputGlossary,
|
||||
ManifestKind: "glossary",
|
||||
Filename: "glossary.yml",
|
||||
},
|
||||
SourceInputGlossaryParty: {SourceID: SourceInputGlossaryParty, ManifestKind: "glossary_party", Filename: "glossaries/party.yml"},
|
||||
SourceInputGlossaryCampaign: {SourceID: SourceInputGlossaryCampaign, ManifestKind: "glossary_campaign", Filename: "glossaries/campaign.yml"},
|
||||
SourceInputGlossarySetting: {SourceID: SourceInputGlossarySetting, ManifestKind: "glossary_setting", Filename: "glossaries/setting.yml"},
|
||||
SourceInputGlossarySpells: {SourceID: SourceInputGlossarySpells, ManifestKind: "glossary_spells", Filename: "glossaries/spells.yml"},
|
||||
SourceInputSpellCatalog: {
|
||||
SourceID: SourceInputSpellCatalog,
|
||||
ManifestKind: "spell_catalog",
|
||||
|
||||
@@ -169,7 +169,8 @@ func TestDescribeScriptoriumInputSource(t *testing.T) {
|
||||
{name: "built in markdown", source: "narratio.transcript.final_markdown", wantKind: SourceKindBuiltIn},
|
||||
{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 glossary input", source: SourceInputGlossaryCampaign, wantKind: SourceKindStableInput},
|
||||
{name: "retired glossary input", source: SourceInputGlossary, wantErr: ErrUnsupportedScriptoriumInputSource, wantErrLike: "replace"},
|
||||
{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},
|
||||
@@ -220,7 +221,10 @@ func TestDescribePreparedInputSource(t *testing.T) {
|
||||
}{
|
||||
{source: SourceInputPlayers, manifestKind: "players", filename: "players.yml"},
|
||||
{source: SourceInputParty, manifestKind: "party", filename: "party.yml"},
|
||||
{source: SourceInputGlossary, manifestKind: "glossary", filename: "glossary.yml"},
|
||||
{source: SourceInputGlossaryParty, manifestKind: "glossary_party", filename: "glossaries/party.yml"},
|
||||
{source: SourceInputGlossaryCampaign, manifestKind: "glossary_campaign", filename: "glossaries/campaign.yml"},
|
||||
{source: SourceInputGlossarySetting, manifestKind: "glossary_setting", filename: "glossaries/setting.yml"},
|
||||
{source: SourceInputGlossarySpells, manifestKind: "glossary_spells", filename: "glossaries/spells.yml"},
|
||||
{source: SourceInputSpellCatalog, manifestKind: "spell_catalog", filename: "spell_catalog.json"},
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,3 +105,14 @@ func TestGlossarySelectionsRejectInvalidTypesAndUnknownIDs(t *testing.T) {
|
||||
t.Fatalf("unknown selection: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetiredGlossarySourceHasMigrationGuidance(t *testing.T) {
|
||||
_, err := validateScriptoriumInputSource("recap", "terms", "narratio.input.glossary", nil, nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "replace") {
|
||||
t.Fatalf("Scriptorium migration: %v", err)
|
||||
}
|
||||
err = validateNotariusReferences(map[string]string{"glossary": "narratio.input.glossary"})
|
||||
if err == nil || !strings.Contains(err.Error(), "replace") {
|
||||
t.Fatalf("Notarius migration: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,9 @@ func validateNotariusReferences(references map[string]string) error {
|
||||
if source != strings.TrimSpace(source) {
|
||||
return fmt.Errorf("pipeline.notarius.references.%s source must be normalized", selector)
|
||||
}
|
||||
if source == artifactpolicy.SourceInputGlossary {
|
||||
return fmt.Errorf("pipeline.notarius.references.%s: replace %s with an explicit narratio.input.glossary.<party|campaign|setting|spells> source", selector, source)
|
||||
}
|
||||
if _, ok := artifactpolicy.DescribePreparedInputSource(source); !ok {
|
||||
return fmt.Errorf("pipeline.notarius.references.%s source %q is not a supported prepared input source", selector, source)
|
||||
}
|
||||
|
||||
@@ -207,6 +207,9 @@ func validateScriptoriumInputSource(
|
||||
trimmedSource := strings.TrimSpace(source)
|
||||
descriptor, err := artifactpolicy.DescribeScriptoriumInputSource(trimmedSource)
|
||||
if err != nil {
|
||||
if trimmedSource == artifactpolicy.SourceInputGlossary {
|
||||
return "", fmt.Errorf("pipeline.scriptorium.artifacts.%s.inputs.%s.source: replace %s with an explicit narratio.input.glossary.<party|campaign|setting|spells> source", artifactName, inputName, trimmedSource)
|
||||
}
|
||||
if errors.Is(err, artifactpolicy.ErrInvalidPreviousSessionSource) {
|
||||
return "", fmt.Errorf(
|
||||
"pipeline.scriptorium.artifacts.%s.inputs.%s.source %q must reference configured artifact key matching ^[a-z][a-z0-9_]*$",
|
||||
|
||||
Reference in New Issue
Block a user