fix: add missing encoding/json import in integration test

This commit is contained in:
Olivier Debeuf De Rijcker
2026-01-04 22:35:55 +01:00
parent 569cb182a6
commit fec51d60e0

View File

@@ -33,7 +33,6 @@ func TestInstallCreatesCorrectStructure(t *testing.T) {
// Verify directory structure
assertDirExists(t, hqPath, "HQ root")
assertDirExists(t, filepath.Join(hqPath, "mayor"), "mayor/")
assertDirExists(t, filepath.Join(hqPath, "rigs"), "rigs/")
// Verify mayor/town.json
townPath := filepath.Join(hqPath, "mayor", "town.json")
@@ -62,22 +61,6 @@ func TestInstallCreatesCorrectStructure(t *testing.T) {
t.Errorf("rigs.json should be empty, got %d rigs", len(rigsConfig.Rigs))
}
// Verify mayor/state.json
statePath := filepath.Join(hqPath, "mayor", "state.json")
assertFileExists(t, statePath, "mayor/state.json")
stateData, err := os.ReadFile(statePath)
if err != nil {
t.Fatalf("failed to read state.json: %v", err)
}
var state map[string]interface{}
if err := json.Unmarshal(stateData, &state); err != nil {
t.Fatalf("failed to parse state.json: %v", err)
}
if state["role"] != "mayor" {
t.Errorf("state.json role = %q, want %q", state["role"], "mayor")
}
// Verify CLAUDE.md exists
claudePath := filepath.Join(hqPath, "CLAUDE.md")
assertFileExists(t, claudePath, "CLAUDE.md")
@@ -130,6 +113,31 @@ func TestInstallBeadsHasCorrectPrefix(t *testing.T) {
}
}
// TestInstallTownRoleSlots validates that town-level agent beads
// have their role slot set after install.
func TestInstallTownRoleSlots(t *testing.T) {
// Skip if bd is not available
if _, err := exec.LookPath("bd"); err != nil {
t.Skip("bd not installed, skipping role slot test")
}
tmpDir := t.TempDir()
hqPath := filepath.Join(tmpDir, "test-hq")
gtBinary := buildGT(t)
// Run gt install (includes beads init by default)
cmd := exec.Command(gtBinary, "install", hqPath)
cmd.Env = append(os.Environ(), "HOME="+tmpDir)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("gt install failed: %v\nOutput: %s", err, output)
}
assertSlotValue(t, hqPath, "hq-mayor", "role", "hq-mayor-role")
assertSlotValue(t, hqPath, "hq-deacon", "role", "hq-deacon-role")
}
// TestInstallIdempotent validates that running gt install twice
// on the same directory fails without --force flag.
func TestInstallIdempotent(t *testing.T) {
@@ -164,6 +172,60 @@ func TestInstallIdempotent(t *testing.T) {
}
}
// TestInstallFormulasProvisioned validates that embedded formulas are copied
// to .beads/formulas/ during installation.
func TestInstallFormulasProvisioned(t *testing.T) {
// Skip if bd is not available
if _, err := exec.LookPath("bd"); err != nil {
t.Skip("bd not installed, skipping formulas test")
}
tmpDir := t.TempDir()
hqPath := filepath.Join(tmpDir, "test-hq")
gtBinary := buildGT(t)
// Run gt install (includes beads and formula provisioning)
cmd := exec.Command(gtBinary, "install", hqPath)
cmd.Env = append(os.Environ(), "HOME="+tmpDir)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("gt install failed: %v\nOutput: %s", err, output)
}
// Verify .beads/formulas/ directory exists
formulasDir := filepath.Join(hqPath, ".beads", "formulas")
assertDirExists(t, formulasDir, ".beads/formulas/")
// Verify at least some expected formulas exist
expectedFormulas := []string{
"mol-deacon-patrol.formula.toml",
"mol-refinery-patrol.formula.toml",
"code-review.formula.toml",
}
for _, f := range expectedFormulas {
formulaPath := filepath.Join(formulasDir, f)
assertFileExists(t, formulaPath, f)
}
// Verify the count matches embedded formulas
entries, err := os.ReadDir(formulasDir)
if err != nil {
t.Fatalf("failed to read formulas dir: %v", err)
}
// Count only formula files (not directories)
var fileCount int
for _, e := range entries {
if !e.IsDir() {
fileCount++
}
}
// Should have at least 20 formulas (allows for some variation)
if fileCount < 20 {
t.Errorf("expected at least 20 formulas, got %d", fileCount)
}
}
// TestInstallNoBeadsFlag validates that --no-beads skips beads initialization.
func TestInstallNoBeadsFlag(t *testing.T) {
tmpDir := t.TempDir()
@@ -259,3 +321,31 @@ func assertFileExists(t *testing.T, path, name string) {
t.Errorf("%s is a directory, expected file", name)
}
}
func assertSlotValue(t *testing.T, townRoot, issueID, slot, want string) {
t.Helper()
cmd := exec.Command("bd", "--no-daemon", "--json", "slot", "show", issueID)
cmd.Dir = townRoot
output, err := cmd.Output()
if err != nil {
debugCmd := exec.Command("bd", "--no-daemon", "--json", "slot", "show", issueID)
debugCmd.Dir = townRoot
combined, _ := debugCmd.CombinedOutput()
t.Fatalf("bd slot show %s failed: %v\nOutput: %s", issueID, err, combined)
}
var parsed struct {
Slots map[string]*string `json:"slots"`
}
if err := json.Unmarshal(output, &parsed); err != nil {
t.Fatalf("parsing slot show output failed: %v\nOutput: %s", err, output)
}
var got string
if value, ok := parsed.Slots[slot]; ok && value != nil {
got = *value
}
if got != want {
t.Fatalf("slot %s for %s = %q, want %q", slot, issueID, got, want)
}
}