Wiki pipeline audit
Changes Made - page-index.json now includes generated meta/status pages, not just entity pages. - Wiki page count now comes from the final page index, so wiki pages: matches generated HTML files. - Page IDs now normalize /, \, and _ to : to prevent duplicate index entries for slash-bearing keys. - Added page-index validation for duplicate page_id and duplicate output_path.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package topdata
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -39,8 +40,9 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("BuildNative failed: %v", err)
|
||||
}
|
||||
if result.WikiPages != 1 {
|
||||
t.Fatalf("expected one generated entity page, got %d", result.WikiPages)
|
||||
generatedHTMLCount := countGeneratedWikiHTMLFiles(t, filepath.Join(root, ".cache", "wiki", "pages"))
|
||||
if result.WikiPages != generatedHTMLCount {
|
||||
t.Fatalf("expected wiki page count to match generated HTML files, got result=%d files=%d", result.WikiPages, generatedHTMLCount)
|
||||
}
|
||||
pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "athletics.html")
|
||||
got, err := os.ReadFile(pagePath)
|
||||
@@ -72,10 +74,20 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("read page index: %v", err)
|
||||
}
|
||||
var pageIndex wikiPageIndex
|
||||
if err := json.Unmarshal(indexRaw, &pageIndex); err != nil {
|
||||
t.Fatalf("parse page index: %v", err)
|
||||
}
|
||||
if len(pageIndex.Pages) != generatedHTMLCount {
|
||||
t.Fatalf("expected page-index entries to match generated HTML files, got index=%d files=%d", len(pageIndex.Pages), generatedHTMLCount)
|
||||
}
|
||||
indexText := string(indexRaw)
|
||||
if !strings.Contains(indexText, `"page_id": "skills:athletics"`) || !strings.Contains(indexText, `"output_path": "pages/skills/athletics.html"`) || !strings.Contains(indexText, `"edit_policy": "preserve_manual_sections"`) {
|
||||
t.Fatalf("expected deterministic page-index metadata, got:\n%s", indexText)
|
||||
}
|
||||
if !strings.Contains(indexText, `"page_id": "meta:wikistatus"`) || !strings.Contains(indexText, `"output_path": "pages/meta/wikistatus.html"`) || !strings.Contains(indexText, `"edit_policy": "generated_only"`) {
|
||||
t.Fatalf("expected status pages in page-index metadata, got:\n%s", indexText)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, ".cache", "wiki", "state.json")); err != nil {
|
||||
t.Fatalf("expected state file after first build: %v", err)
|
||||
}
|
||||
@@ -95,11 +107,29 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("second BuildNative failed: %v", err)
|
||||
}
|
||||
if second.WikiPages != 1 {
|
||||
t.Fatalf("expected a single generated skill wiki page after rebuild, got %d", second.WikiPages)
|
||||
if second.WikiPages != generatedHTMLCount {
|
||||
t.Fatalf("expected generated wiki page count after rebuild to remain stable, got %d want %d", second.WikiPages, generatedHTMLCount)
|
||||
}
|
||||
}
|
||||
|
||||
func countGeneratedWikiHTMLFiles(t *testing.T, root string) int {
|
||||
t.Helper()
|
||||
count := 0
|
||||
err := filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !d.IsDir() && strings.EqualFold(filepath.Ext(path), ".html") {
|
||||
count++
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("count generated wiki HTML files: %v", err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func TestWikiClassNamePrefersFullNameInsteadOfShortCode(t *testing.T) {
|
||||
ctx := &wikiContext{}
|
||||
got := ctx.resolveRowName("classes", map[string]any{
|
||||
@@ -111,6 +141,26 @@ func TestWikiClassNamePrefersFullNameInsteadOfShortCode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWikiPageIDForKeyNormalizesSlashAndUnderscoreSeparators(t *testing.T) {
|
||||
got := wikiPageIDForKey("feat:special/attacks_bull_rush")
|
||||
if want := "feat:special:attacks:bull:rush"; got != want {
|
||||
t.Fatalf("expected normalized page ID %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveWikiPageIndexRejectsDuplicateOutputPaths(t *testing.T) {
|
||||
err := saveWikiPageIndex(filepath.Join(t.TempDir(), "page-index.json"), wikiPageIndex{
|
||||
Version: wikiGeneratorVersion,
|
||||
Pages: []wikiPageIndexEntry{
|
||||
{PageID: "feat:special:attacks:bull:rush", OutputPath: "pages/feat/special/attacks/bull/rush.html"},
|
||||
{PageID: "feat:special/attacks:bull:rush", OutputPath: "pages/feat/special/attacks/bull/rush.html"},
|
||||
},
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), "duplicate wiki page-index output_path") {
|
||||
t.Fatalf("expected duplicate output_path validation error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildAndPackageBuildsWikiOnlyWhenRequested(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "skills"))
|
||||
@@ -153,8 +203,9 @@ func TestBuildAndPackageBuildsWikiOnlyWhenRequested(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("BuildAndPackageWithOptions with wiki failed: %v", err)
|
||||
}
|
||||
if result.WikiPages != 1 {
|
||||
t.Fatalf("expected one generated wiki page when requested, got %d", result.WikiPages)
|
||||
generatedHTMLCount := countGeneratedWikiHTMLFiles(t, filepath.Join(root, ".cache", "wiki", "pages"))
|
||||
if result.WikiPages != generatedHTMLCount {
|
||||
t.Fatalf("expected wiki page count to match generated HTML files when requested, got result=%d files=%d", result.WikiPages, generatedHTMLCount)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, ".cache", "wiki", "state.json")); err != nil {
|
||||
t.Fatalf("expected wiki state after explicit wiki build: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user