Adjust the prompt FS layout and test strategy
This commit is contained in:
@@ -2,8 +2,11 @@ Optional reference material for this Dungeons & Dragons campaign is provided
|
||||
below. Use it only to disambiguate names, aliases, speakers, campaign terms, or
|
||||
spell names already present in the transcript.
|
||||
|
||||
Roster reference:
|
||||
{{ input "roster" }}
|
||||
Player list reference:
|
||||
{{ input "players" }}
|
||||
|
||||
Party roster reference:
|
||||
{{ input "party" }}
|
||||
|
||||
Glossary reference:
|
||||
{{ input "glossary" }}
|
||||
|
||||
@@ -19,7 +19,8 @@ type ModulePromptFile struct {
|
||||
}
|
||||
|
||||
// ModulePromptFS builds a prompt filesystem for a module directory from
|
||||
// module-owned prompt files plus the common D&D shared prompt files.
|
||||
// module-owned prompt files plus common D&D shared prompt files under the
|
||||
// module's sharedassets subdirectory.
|
||||
func ModulePromptFS(moduleDir string, moduleFS fs.FS, files []ModulePromptFile) (fs.FS, error) {
|
||||
return modulePromptFS(moduleDir, moduleFS, files, embeddedAssets)
|
||||
}
|
||||
@@ -60,7 +61,7 @@ func modulePromptFS(moduleDir string, moduleFS fs.FS, files []ModulePromptFile,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read shared prompt asset %s: %w", name, err)
|
||||
}
|
||||
assets["assets/prompts/"+cleanModuleDir+"/"+name] = append([]byte(nil), data...)
|
||||
assets["assets/prompts/"+cleanModuleDir+"/sharedassets/"+name] = append([]byte(nil), data...)
|
||||
}
|
||||
return assets, nil
|
||||
}
|
||||
|
||||
@@ -20,18 +20,21 @@ func TestModulePromptFSCombinesModuleAndSharedPrompts(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := map[string]string{
|
||||
"assets/prompts/dnd.test/dnd.test.yaml": "id: dnd.test",
|
||||
"assets/prompts/dnd.test/task.md": "task",
|
||||
"assets/prompts/dnd.test/common-dnd-system.md": "You work with Dungeons & Dragons gameplay transcripts.",
|
||||
"assets/prompts/dnd.test/common-dnd-transcript.md": "{{ input \"transcript\" }}",
|
||||
"assets/prompts/dnd.test/common-dnd-references.md": "Roster reference:",
|
||||
"assets/prompts/dnd.test/dnd.test.yaml": "id: dnd.test",
|
||||
"assets/prompts/dnd.test/task.md": "task",
|
||||
"assets/prompts/dnd.test/sharedassets/common-dnd-system.md": "",
|
||||
"assets/prompts/dnd.test/sharedassets/common-dnd-transcript.md": "",
|
||||
"assets/prompts/dnd.test/sharedassets/common-dnd-references.md": "",
|
||||
}
|
||||
for path, want := range tests {
|
||||
data, err := fs.ReadFile(fsys, path)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile(%q) error = %v, want nil", path, err)
|
||||
}
|
||||
if !strings.Contains(string(data), want) {
|
||||
if len(data) == 0 {
|
||||
t.Fatalf("ReadFile(%q) returned empty content", path)
|
||||
}
|
||||
if want != "" && !strings.Contains(string(data), want) {
|
||||
t.Fatalf("ReadFile(%q) = %q, want substring %q", path, data, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user