beads/cmd/bd/mol_seed.go
Okano, Osamu 9b4896f0e8
Fix formula search paths for worktree-aware beads dirs (#3235)
* fix(formula): resolve worktree-aware search paths (beads-oto)

intent(formula): worktree users should resolve formulas from the active shared .beads registry instead of cwd-only paths

decision(formula-search): route CLI help, formula lookup, and distill output hints through formula.DefaultSearchPaths so search path display matches runtime behavior

constraint(worktree): keep cwd/.beads fallback when no beads project is resolved so local formula registries still work before init

* fix(formula): align mol seed help with resolved search paths

intent(formula-help): worktree users should see the active beads workspace path instead of stale cwd-based guidance
constraint(formula-runtime): seed already resolves formulas through the shared default search helper so this change only updates the displayed contract

* test(formula): isolate worktree parser repo hooks

intent(formula-tests): keep worktree search path coverage focused on formula resolution instead of developer git hook state
constraint(git-test-repos): global core.hooksPath can inject failing pre-commit hooks into temp repos and break the setup commit
decision(formula-tests): reuse ForceRepoLocalHooksPath so the new worktree test follows the repo's existing git test isolation rule

* test(formula): simplify search-path test setup (beads-6kum)

intent(formula-tests): keep the new search-path coverage easy to extend without re-reading repetitive test scaffolding
constraint(formula-tests): helper extraction must preserve the hook-isolation and cache-reset behavior added for worktree coverage
decision(formula-tests): centralize repo init, fixture writing, and canonical path handling into local test helpers so each case stays focused on its assertions
2026-04-13 11:01:28 -07:00

77 lines
2.2 KiB
Go

package main
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
var molSeedCmd = &cobra.Command{
Use: "seed <formula-name>",
Short: "Verify formula accessibility",
Long: `Verify that a formula is accessible and can be cooked.
The seed command checks formula search paths to ensure a formula exists
and can be loaded. This is useful for verifying system health before
attempting to spawn work from a formula.
Formula search paths (checked in order):
1. <resolved-beads-dir>/formulas/ (active project)
2. ~/.beads/formulas/ (user level)
3. $GT_ROOT/.beads/formulas/ (orchestrator level, if GT_ROOT set)
Examples:
bd mol seed mol-feature # Verify specific formula
bd mol seed mol-review --var name=test # Verify with variable substitution`,
Args: cobra.ExactArgs(1),
Run: runMolSeed,
}
func runMolSeed(cmd *cobra.Command, args []string) {
varFlags, _ := cmd.Flags().GetStringArray("var")
// Parse variables (for formula condition filtering if needed)
vars := make(map[string]string)
for _, v := range varFlags {
parts := strings.SplitN(v, "=", 2)
if len(parts) != 2 {
FatalError("invalid variable format '%s', expected 'key=value'", v)
}
vars[parts[0]] = parts[1]
}
// Verify single formula
formulaName := args[0]
if err := verifyFormula(formulaName, vars); err != nil {
FatalError("%v", err)
}
if !jsonOutput {
fmt.Printf("✓ Formula %q accessible\n", formulaName)
} else {
outputJSON(map[string]interface{}{
"status": "ok",
"formula": formulaName,
})
}
}
// verifyFormula checks if a formula can be loaded and cooked
func verifyFormula(formulaName string, vars map[string]string) error {
// Try to cook the formula - this verifies:
// 1. Formula exists in search path
// 2. Formula syntax is valid
// 3. Formula can be resolved (extends, etc.)
// 4. Formula can be cooked to subgraph
_, err := resolveAndCookFormulaWithVars(formulaName, nil, vars)
if err != nil {
return fmt.Errorf("formula %q not accessible: %w", formulaName, err)
}
return nil
}
func init() {
molSeedCmd.Flags().StringArray("var", []string{}, "Variable substitution for condition filtering (key=value)")
molCmd.AddCommand(molSeedCmd)
}