Configuration hardening

This commit is contained in:
2026-05-07 21:33:53 +02:00
parent bba0d2fb45
commit d1b20684f5
14 changed files with 1335 additions and 176 deletions
+96
View File
@@ -199,6 +199,102 @@ func TestValidateProjectWarnsForMissingScriptReferences(t *testing.T) {
}
}
func TestValidateProjectUsesConfiguredBuiltinScriptPrefixes(t *testing.T) {
root := t.TempDir()
mustMkdir(t, filepath.Join(root, "src", "dialogs"))
mustMkdir(t, filepath.Join(root, "assets"))
mustMkdir(t, filepath.Join(root, "build"))
mustWriteFile(t, filepath.Join(root, "nwn-tool.yaml"), `
module:
name: Test Module
resref: testmod
paths:
source: src
assets: assets
build: build
validation:
builtin_script_prefixes:
- custom_
`)
mustWriteFile(t, filepath.Join(root, "src", "dialogs", "merchant.dlg.json"), `{
"file_type": "DLG ",
"file_version": "V3.2",
"root": {
"struct_type": 0,
"fields": [
{
"label": "Script",
"type": "ResRef",
"value": "custom_open_store"
}
]
}
}
`)
p, err := project.Load(root)
if err != nil {
t.Fatalf("load project: %v", err)
}
if err := p.ValidateLayout(); err != nil {
t.Fatalf("validate layout: %v", err)
}
if err := p.Scan(); err != nil {
t.Fatalf("scan: %v", err)
}
report := ValidateProject(p)
if report.HasErrors() || report.WarningCount() != 0 {
t.Fatalf("expected configured script prefix to suppress warning, got %#v", report.Diagnostics)
}
}
func TestValidateProjectUsesConfiguredRequiredFields(t *testing.T) {
root := t.TempDir()
mustMkdir(t, filepath.Join(root, "src", "module"))
mustMkdir(t, filepath.Join(root, "assets"))
mustMkdir(t, filepath.Join(root, "build"))
mustWriteFile(t, filepath.Join(root, "nwn-tool.yaml"), `
module:
name: Test Module
resref: testmod
paths:
source: src
assets: assets
build: build
validation:
required_fields:
ifo: []
`)
mustWriteFile(t, filepath.Join(root, "src", "module", "module.ifo.json"), `{
"file_type": "IFO ",
"file_version": "V3.2",
"root": {
"struct_type": 0,
"fields": []
}
}
`)
p, err := project.Load(root)
if err != nil {
t.Fatalf("load project: %v", err)
}
if err := p.ValidateLayout(); err != nil {
t.Fatalf("validate layout: %v", err)
}
if err := p.Scan(); err != nil {
t.Fatalf("scan: %v", err)
}
report := ValidateProject(p)
if report.HasErrors() {
t.Fatalf("expected configured required fields to suppress IFO error, got %#v", report.Diagnostics)
}
}
func TestValidateProjectReportsDecompiledModelsWithoutFailingValidation(t *testing.T) {
root := t.TempDir()
mustMkdir(t, filepath.Join(root, "src"))