Automatic spellknown/spellgain null-filling (#12)
Implemented on branches `feature/topdata-row-extensions` in both `toolkit` and `module`. **Scope Audited** - Toolkit native topdata collection/build path. - Project config/effective config validation. - Module `nwn-tool.yaml` topdata config and topdata README. **Changes Made** - Added `topdata.row_extensions` config with `repeat_last` support. - Added glob dataset matching and build-time row extension for plain native datasets in [native.go](/home/vicky/Projects/nwnee-shadowsoverwestgate/toolkit/internal/topdata/native.go:641). - Extension copies emitted columns from the highest authored `Level`, increments `Level`, and assigns sequential `id`s through target level. - Enabled rules for `classes/spellsgained/*` and `classes/spellsknown/*` to level 60 in [nwn-tool.yaml](/home/vicky/Projects/nwnee-shadowsoverwestgate/module/nwn-tool.yaml:90). - Updated toolkit/module docs. **Configuration / Compatibility** - New public config type: `TopDataRowExtensionConfig` in [project.go](/home/vicky/Projects/nwnee-shadowsoverwestgate/toolkit/internal/project/project.go:233). - Existing behavior is unchanged unless a repo opts into `topdata.row_extensions`. - Source JSON and lockfiles are not updated for generated extension rows. **Tests / Validation** - Added project config tests for loading and validation. - Added native topdata tests for extension behavior, glob application, preserving manually authored rows, unmatched datasets, and failure cases. - Ran: - `go test ./internal/project ./internal/topdata` - `go test ./internal/topdata -run TestBuildNativeKeepsGeneratedIDsStableAcrossRepeatedBuilds` - `/tmp/sow-toolkit-rowext config validate` in `module` - `/tmp/sow-toolkit-rowext validate-topdata` in `module` - `/tmp/sow-toolkit-rowext build-topdata --force`, then inspected generated rows: `cls_spgn_acolyte.2da` now reaches row `59` / level `60`. **Remaining Notes** - `validate-topdata` still reports the pre-existing portrait lock warnings for `cotbl/cotbl_` and `lantern/lantern_`. - `build-topdata --force` briefly rewrote three spellbook JSON files as a side effect; I reverted those, leaving only the intended YAML/docs changes in `module`. Reviewed-on: https://gitea.westgate.pw/ShadowsOverWestgate/sow-tools/pulls/12 Co-authored-by: vickydotbat <vickydotbat@tutamail.com> Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit is contained in:
@@ -13544,6 +13544,175 @@ func TestBuildNativeSupportsLoosePlainTableAtTopdataDataRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeExtendsConfiguredPlainRowsByRepeatingLastLevel(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "classes", "spellsgained"))
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "classes", "spellsknown"))
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "ruleset"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "classes", "spellsgained", "acolyte.json"), `{
|
||||
"output": "cls_spgn_acolyte.2da",
|
||||
"columns": ["Level", "SpellLevel0", "SpellLevel1"],
|
||||
"rows": [
|
||||
{"id": 0, "Level": 1, "SpellLevel0": 3, "SpellLevel1": 1},
|
||||
{"id": 1, "Level": 2, "SpellLevel0": 4, "SpellLevel1": 2},
|
||||
{"id": 2, "Level": 3, "SpellLevel0": 5, "SpellLevel1": 3}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "classes", "spellsknown", "bard_4th.json"), `{
|
||||
"output": "cls_spkn_bard4.2da",
|
||||
"columns": ["Level", "SpellLevel0", "SpellLevel1"],
|
||||
"rows": [
|
||||
{"id": 0, "Level": 1, "SpellLevel0": 2, "SpellLevel1": null},
|
||||
{"id": 1, "Level": 2, "SpellLevel0": 3, "SpellLevel1": 1}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "ruleset", "base.json"), `{
|
||||
"output": "ruleset.2da",
|
||||
"columns": ["Name", "Value"],
|
||||
"rows": [
|
||||
{"id": 0, "Name": "TEST_RULE", "Value": "1"}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ReferenceBuilder = ""
|
||||
proj.Config.TopData.RowExtensions = []project.TopDataRowExtensionConfig{
|
||||
{Dataset: "classes/spellsgained/*", Mode: "repeat_last", LevelColumn: "Level", TargetLevel: 5},
|
||||
{Dataset: "classes/spellsknown/*", Mode: "repeat_last", LevelColumn: "Level", TargetLevel: 5},
|
||||
}
|
||||
result, err := BuildNativeWithOptions(proj, NativeBuildOptions{BuildWiki: false}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildNativeWithOptions failed: %v", err)
|
||||
}
|
||||
|
||||
gained := read2DATable(t, filepath.Join(result.Output2DADir, "cls_spgn_acolyte.2da"))
|
||||
for rowID, values := range map[string]map[string]string{
|
||||
"2": {"Level": "3", "SpellLevel0": "5", "SpellLevel1": "3"},
|
||||
"3": {"Level": "4", "SpellLevel0": "5", "SpellLevel1": "3"},
|
||||
"4": {"Level": "5", "SpellLevel0": "5", "SpellLevel1": "3"},
|
||||
} {
|
||||
for column, want := range values {
|
||||
if got := gained.cell(rowID, column); got != want {
|
||||
t.Fatalf("spellsgained row %s column %s: got %q, want %q", rowID, column, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
known := read2DATable(t, filepath.Join(result.Output2DADir, "cls_spkn_bard4.2da"))
|
||||
if got := known.cell("4", "Level"); got != "5" {
|
||||
t.Fatalf("expected spellsknown glob rule to extend to level 5, got row 4 Level %q", got)
|
||||
}
|
||||
if got := known.cell("4", "SpellLevel1"); got != "1" {
|
||||
t.Fatalf("expected spellsknown generated row to copy last authored values, got SpellLevel1 %q", got)
|
||||
}
|
||||
|
||||
ruleset := read2DATable(t, filepath.Join(result.Output2DADir, "ruleset.2da"))
|
||||
if got := ruleset.cell("1", "Value"); got != "" {
|
||||
t.Fatalf("expected unmatched ruleset table to remain unextended, got row 1 Value %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeExtendsConfiguredRowsAfterHighestAuthoredLevel(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "classes", "spellsgained"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "classes", "spellsgained", "acolyte.json"), `{
|
||||
"output": "cls_spgn_acolyte.2da",
|
||||
"columns": ["Level", "SpellLevel0", "SpellLevel1"],
|
||||
"rows": [
|
||||
{"id": 0, "Level": 1, "SpellLevel0": 3, "SpellLevel1": 1},
|
||||
{"id": 1, "Level": 2, "SpellLevel0": 4, "SpellLevel1": 2},
|
||||
{"id": 2, "Level": 3, "SpellLevel0": 5, "SpellLevel1": 3},
|
||||
{"id": 3, "Level": 4, "SpellLevel0": 6, "SpellLevel1": 4}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ReferenceBuilder = ""
|
||||
proj.Config.TopData.RowExtensions = []project.TopDataRowExtensionConfig{
|
||||
{Dataset: "classes/spellsgained/*", Mode: "repeat_last", LevelColumn: "Level", TargetLevel: 5},
|
||||
}
|
||||
result, err := BuildNativeWithOptions(proj, NativeBuildOptions{BuildWiki: false}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildNativeWithOptions failed: %v", err)
|
||||
}
|
||||
|
||||
table := read2DATable(t, filepath.Join(result.Output2DADir, "cls_spgn_acolyte.2da"))
|
||||
if got := table.cell("3", "SpellLevel0"); got != "6" {
|
||||
t.Fatalf("expected authored row 3 to be preserved, got SpellLevel0 %q", got)
|
||||
}
|
||||
if got := table.cell("4", "Level"); got != "5" {
|
||||
t.Fatalf("expected generation to start after highest authored level, got row 4 Level %q", got)
|
||||
}
|
||||
if got := table.cell("4", "SpellLevel0"); got != "6" {
|
||||
t.Fatalf("expected generated row to copy level 4 values, got SpellLevel0 %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeRejectsInvalidConfiguredRowExtensions(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
rows string
|
||||
levelColumn string
|
||||
targetLevel int
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty rows",
|
||||
rows: `[]`,
|
||||
levelColumn: "Level",
|
||||
targetLevel: 5,
|
||||
want: "requires at least one authored row",
|
||||
},
|
||||
{
|
||||
name: "missing level column",
|
||||
rows: `[{"id": 0, "Level": 1, "SpellLevel0": 1}]`,
|
||||
levelColumn: "ClassLevel",
|
||||
targetLevel: 5,
|
||||
want: `level_column "ClassLevel" is not present`,
|
||||
},
|
||||
{
|
||||
name: "nonnumeric level",
|
||||
rows: `[{"id": 0, "Level": "one", "SpellLevel0": 1}]`,
|
||||
levelColumn: "Level",
|
||||
targetLevel: 5,
|
||||
want: `level_column "Level" must be numeric`,
|
||||
},
|
||||
{
|
||||
name: "target below authored",
|
||||
rows: `[{"id": 0, "Level": 6, "SpellLevel0": 1}]`,
|
||||
levelColumn: "Level",
|
||||
targetLevel: 5,
|
||||
want: "target_level 5 is below highest authored Level 6",
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "classes", "spellsgained"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "classes", "spellsgained", "acolyte.json"), `{
|
||||
"output": "cls_spgn_acolyte.2da",
|
||||
"columns": ["Level", "SpellLevel0"],
|
||||
"rows": `+tc.rows+`
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ReferenceBuilder = ""
|
||||
proj.Config.TopData.RowExtensions = []project.TopDataRowExtensionConfig{
|
||||
{Dataset: "classes/spellsgained/*", Mode: "repeat_last", LevelColumn: tc.levelColumn, TargetLevel: tc.targetLevel},
|
||||
}
|
||||
_, err := BuildNativeWithOptions(proj, NativeBuildOptions{BuildWiki: false}, nil)
|
||||
if err == nil {
|
||||
t.Fatal("expected BuildNativeWithOptions to fail")
|
||||
}
|
||||
if !strings.Contains(err.Error(), tc.want) {
|
||||
t.Fatalf("expected error containing %q, got %v", tc.want, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeGeneratesSpellColumnsFromClassSpellbooks(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
writeMinimalSpellbookProject(t, root)
|
||||
|
||||
Reference in New Issue
Block a user