Skip to content

uf init sub-tool execs inherit cwd: Go tests regenerate scaffold litter under cmd/unbound-force #1200

Backlog

Description

@jflowers

Summary

uf init's post-scaffold sub-tool initialization (initSubTools in internal/scaffold/scaffold.go) executes dewey, replicator, specify, openspec, and gaze through opts.ExecCmd — the exec.Command(name, args...).CombinedOutput() default with no cmd.Dir — so every sub-tool writes its output into the process cwd instead of the scaffold TargetDir. The npm-based review-plugin activation path has the same inherited-cwd behavior.

When the cmd/unbound-force package tests run (TestRunInit_FreshDir and TestRunInit_ForceFlag call runInit with targetDir: t.TempDir() and real default exec hooks), the test binary's cwd is cmd/unbound-force/, and with the toolchain present on PATH every sub-tool initialization lands inside the repo:

  • dewey init → .uf/dewey/graph.db, .github/workflows/dewey-distill.yml.example
  • replicator init → .uf/replicator/cells.json
  • specify init --here --integration opencode --offline --force → .specify/ (the --here flag explicitly targets cwd)
  • openspec init --tools opencode → openspec/
  • gaze init → .opencode/ integration files
  • review-plugin activation (npm install) → .opencode/node_modules

Reproduction

rm -rf cmd/unbound-force/{.github,.opencode,.specify,.uf,.devcontainer,openspec}
go test -race -count=1 ./cmd/unbound-force/
ls -A cmd/unbound-force/ | grep -v '\.go$'
# → .devcontainer .github .opencode .specify .uf openspec  (all six regenerated)

Bisection (2026-11-24): the full six-directory litter regenerates from this package's suite alone (~175s run, exit 0). It also regenerates on every make test / make coverage-gate / make check run.

Evidence anchors

  • internal/scaffold/scaffold.go:109-110 — defaultExecCmd = exec.Command(name, args...).CombinedOutput() (no cmd.Dir)
  • internal/scaffold/scaffold.go:115-116 — defaultExecCmdInDir(dir, name, ...) exists but is unused by the tool-init paths
  • internal/scaffold/scaffold.go:2712, 2729, 2751 — initDewey execs dewey init / dewey index --no-embeddings via ExecCmd (inherited cwd)
  • internal/scaffold/scaffold.go:2797 — initSimpleTool execs <tool> init [args...] via ExecCmd (inherited cwd)
  • internal/scaffold/scaffold.go:2559-2571 — simpleTools table (replicator, specify with --here, openspec, gaze)
  • internal/scaffold/scaffold.go:2578-2700 — initSubTools dispatch, gated only by opts.LookPath(tool)
  • internal/setup/setup.go:140 — same unanchored exec.Command(...).CombinedOutput() pattern
  • cmd/unbound-force/main_test.go:15-91 — TestRunInit_FreshDir (real exec hooks, temp target, test cwd = package dir)

Historical masking

.gitignore lines 58/65-70 (commit 641a5af, 2026-04-13, "Prevent stray tool directories in subdirectories") mask five of the six directories (cmd/**/.opencode/, cmd/**/.uf/, cmd/**/.specify/, cmd/**/openspec/, .devcontainer/); only .github/ surfaces in git status, so the condition has been invisible in normal workflows since April.

Recommended fix

Anchor every post-scaffold sub-tool exec to the resolved absolute TargetDir:

  1. Route the tool-init execs through the existing ExecCmdInDir hook with opts.TargetDir: initDewey (scaffold.go:2712/2729/2751) and initSimpleTool (scaffold.go:2797) — opts.ExecCmdInDir(opts.TargetDir, tool.name, args...).
  2. Same anchoring for the npm review-plugin activation path wherever it shells out.
  3. internal/setup/setup.go:140 — set cmd.Dir to the resolved target for tool installs.
  4. Guardrail: resolve TargetDir to an absolute path at Run() entry and validate it against path traversal before any exec or write.
  5. Longer term (separate consideration): an exec-name allowlist for ExecCmd consumers, and migrating process-wide os.Chdir test helpers to t.Chdir.

Per the AGENTS.md commit-scope rule (tooling-scaffold changes ride their own branch, never a feature branch), this fix should ship on a dedicated branch/change. Filed from the opsx/intent-satisfaction-check pipeline after the writer was bisected during its phase-2 gate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions