Allow optional hak releases
This commit is contained in:
@@ -1039,6 +1039,127 @@ func TestBuildSplitsMultipleHAKGroupsDeterministically(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildExcludesOptionalHAKsFromModuleOrder(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||
mustMkdir(t, filepath.Join(root, "assets", "core"))
|
||||
mustMkdir(t, filepath.Join(root, "assets", "optional"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.json"), `{
|
||||
"module": {
|
||||
"name": "Test Module",
|
||||
"resref": "testmod",
|
||||
"hak_order": ["group:core", "group:optional"]
|
||||
},
|
||||
"paths": {
|
||||
"source": "src",
|
||||
"assets": "assets",
|
||||
"build": "build"
|
||||
},
|
||||
"haks": [
|
||||
{
|
||||
"name": "core",
|
||||
"priority": 1,
|
||||
"max_bytes": 0,
|
||||
"split": false,
|
||||
"include": ["core/**"]
|
||||
},
|
||||
{
|
||||
"name": "optional",
|
||||
"priority": 2,
|
||||
"max_bytes": 0,
|
||||
"split": false,
|
||||
"optional": true,
|
||||
"include": ["optional/**"]
|
||||
}
|
||||
]
|
||||
}
|
||||
`)
|
||||
mustWriteFile(t, filepath.Join(root, "src", "module", "module.ifo.json"), `{
|
||||
"file_type": "IFO ",
|
||||
"file_version": "V3.2",
|
||||
"root": {
|
||||
"struct_type": 0,
|
||||
"fields": [
|
||||
{
|
||||
"label": "Mod_Name",
|
||||
"type": "CExoString",
|
||||
"value": "Test Module"
|
||||
},
|
||||
{
|
||||
"label": "Mod_HakList",
|
||||
"type": "List",
|
||||
"value": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
mustWriteFile(t, filepath.Join(root, "assets", "core", "a.tga"), "core-data")
|
||||
mustWriteFile(t, filepath.Join(root, "assets", "optional", "b.tga"), "optional-data")
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
result, err := BuildHAKs(p)
|
||||
if err != nil {
|
||||
t.Fatalf("build haks: %v", err)
|
||||
}
|
||||
if len(result.HAKPaths) != 2 {
|
||||
t.Fatalf("expected 2 hak outputs, got %d", len(result.HAKPaths))
|
||||
}
|
||||
|
||||
rawManifest, err := os.ReadFile(filepath.Join(root, "build", "haks.json"))
|
||||
if err != nil {
|
||||
t.Fatalf("read manifest: %v", err)
|
||||
}
|
||||
var manifest BuildManifest
|
||||
if err := json.Unmarshal(rawManifest, &manifest); err != nil {
|
||||
t.Fatalf("parse manifest: %v", err)
|
||||
}
|
||||
if got, want := strings.Join(manifest.ModuleHAKs, ","), "core"; got != want {
|
||||
t.Fatalf("unexpected module hak order: got %q want %q", got, want)
|
||||
}
|
||||
if len(manifest.HAKs) != 2 {
|
||||
t.Fatalf("expected 2 manifest hak entries, got %d", len(manifest.HAKs))
|
||||
}
|
||||
if manifest.HAKs[0].Name != "core" || manifest.HAKs[0].Optional {
|
||||
t.Fatalf("unexpected primary hak manifest entry: %#v", manifest.HAKs[0])
|
||||
}
|
||||
if manifest.HAKs[1].Name != "optional" || !manifest.HAKs[1].Optional {
|
||||
t.Fatalf("unexpected optional hak manifest entry: %#v", manifest.HAKs[1])
|
||||
}
|
||||
|
||||
applyResult, err := ApplyHAKManifest(p, filepath.Join(root, "build", "haks.json"))
|
||||
if err != nil {
|
||||
t.Fatalf("apply hak manifest: %v", err)
|
||||
}
|
||||
if applyResult.HAKCount != 1 {
|
||||
t.Fatalf("expected 1 applied hak entry, got %d", applyResult.HAKCount)
|
||||
}
|
||||
|
||||
updated, err := os.ReadFile(filepath.Join(root, "src", "module", "module.ifo.json"))
|
||||
if err != nil {
|
||||
t.Fatalf("read updated ifo: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(updated), "\"value\": \"core\"") {
|
||||
t.Fatalf("updated ifo missing primary hak:\n%s", string(updated))
|
||||
}
|
||||
if strings.Contains(string(updated), "\"value\": \"optional\"") {
|
||||
t.Fatalf("updated ifo should not contain optional hak:\n%s", string(updated))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildSkipsEmptyHAKGroupsInModuleOrder(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src"))
|
||||
|
||||
Reference in New Issue
Block a user