feat(ingestion): add wiki index rebuilder and audit log
This commit is contained in:
76
ingestion/internal/wiki/index_test.go
Normal file
76
ingestion/internal/wiki/index_test.go
Normal file
@@ -0,0 +1,76 @@
|
||||
// ingestion/internal/wiki/index_test.go
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func setupWikiDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "wiki", "concepts"), 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "wiki", "entities"), 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "wiki", "sources"), 0o755))
|
||||
require.NoError(t, os.WriteFile(
|
||||
filepath.Join(dir, "wiki", "concepts", "tdd.md"),
|
||||
[]byte("---\ntitle: TDD\n---\n\n## Definition\n\nTest-driven development is a discipline.\n"),
|
||||
0o644,
|
||||
))
|
||||
return dir
|
||||
}
|
||||
|
||||
func TestRebuildIndex(t *testing.T) {
|
||||
dir := setupWikiDir(t)
|
||||
require.NoError(t, RebuildIndex(dir, "2026-04-22"))
|
||||
|
||||
content, err := os.ReadFile(filepath.Join(dir, "wiki", "index.md"))
|
||||
require.NoError(t, err)
|
||||
s := string(content)
|
||||
assert.Contains(t, s, "# Wiki Index")
|
||||
assert.Contains(t, s, "2026-04-22")
|
||||
assert.Contains(t, s, "[[tdd|TDD]]")
|
||||
assert.Contains(t, s, "## Concepts")
|
||||
}
|
||||
|
||||
func TestRebuildIndex_EmptyWiki(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "wiki", "concepts"), 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "wiki", "entities"), 0o755))
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "wiki", "sources"), 0o755))
|
||||
|
||||
require.NoError(t, RebuildIndex(dir, "2026-04-22"))
|
||||
content, err := os.ReadFile(filepath.Join(dir, "wiki", "index.md"))
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(content), "# Wiki Index")
|
||||
}
|
||||
|
||||
func TestAppendLog(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, AppendLog(dir, "shape-up-book",
|
||||
[]string{"wiki/sources/shape-up.md", "wiki/concepts/betting-table.md"},
|
||||
nil, "2026-04-22"))
|
||||
|
||||
content, err := os.ReadFile(filepath.Join(dir, "log.md"))
|
||||
require.NoError(t, err)
|
||||
s := string(content)
|
||||
assert.Contains(t, s, "shape-up-book")
|
||||
assert.Contains(t, s, "wiki/sources/shape-up.md")
|
||||
assert.True(t, strings.HasPrefix(s, "## 2026-04-22"))
|
||||
}
|
||||
|
||||
func TestAppendLog_AppendsOnSecondCall(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, AppendLog(dir, "source-a", []string{"wiki/sources/a.md"}, nil, "2026-04-22"))
|
||||
require.NoError(t, AppendLog(dir, "source-b", []string{"wiki/sources/b.md"}, nil, "2026-04-22"))
|
||||
|
||||
content, err := os.ReadFile(filepath.Join(dir, "log.md"))
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(content), "source-a")
|
||||
assert.Contains(t, string(content), "source-b")
|
||||
}
|
||||
Reference in New Issue
Block a user