* fix(exec): match Windows environment key identity (#5618) Centralize os/exec-compatible environment-key comparison and use it for credential, metrics, Git-hook, trace, and repro subprocess filters. Preserve exact Unix semantics and Unicode near-collisions. Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com> * fix(worktree): scrub inherited Git routing state Establish CWD as the worktree repository boundary before discovery can consume inherited Git routing. Fence the startup config probe, clear routing in-process before root pre-run discovery, and retain command-owned subprocess scrubbing as defense in depth without changing PID or signal semantics. Fixes #5531 Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell * refactor(worktree): explain owned filtering and remove an unused shim Document why filtering the fresh routing slice in place is safe and call the shared routing-key classifier directly from tests. Retain the two forwarders used by production worktree subprocess/removal paths. Review: https://github.com/gastownhall/beads/pull/5623#pullrequestreview-5098421671 Bead: saa-cgh.23 Agent-Signature: unknown-model/unknown-reasoning * fix(config): isolate identity and tracked-file Git probes from routing Reuse the worktree routing owner for GetIdentity and isGitTracked so explicit cwd/path selection is not displaced by inherited repository, index or injected config state. Preserve identity precedence and the tracked-secret refusal contract, with real target/decoy regressions. Follow-up: https://github.com/gastownhall/beads/issues/6222 Dependency: https://github.com/gastownhall/beads/pull/5623 Reported-by: bee-ghosttrack Bead: saa-cgh.93 Agent-Signature: unknown-model/unknown-reasoning * test(execenv): exercise every environment operation under both host rules Thread the host choice through narrow private helpers behind the existing exported functions. Keep one normalization owner and retain native wrapper tests; the additional table covers both host branches for equality, prefix matching, last-wins lookup, filtering and input preservation. Review: https://github.com/gastownhall/beads/pull/5672#pullrequestreview-5096948965 Bead: saa-cgh.78 Agent-Signature: unknown-model/unknown-reasoning * docs(worktree): explain startup Git environment scope (saa-cgh.23) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * test(execenv): exercise exported host policy wiring (saa-cgh.78) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(config): share subprocess key identity for Git routing (saa-cgh.93) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(hooks): isolate tracked-file guard from Git routing (saa-cgh.98) Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6356. Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(config): isolate role commands from Git routing (saa-cgh.99) Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6357. Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * test(env): exercise shared key helpers on native Windows (saa-cgh.78) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * refactor(gitenv): share key parsing and normalize routing membership once (saa-cgh.93) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * docs(config): explain role command routing policy (saa-cgh.99) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(hooks): retain legitimate inherited tracking context (saa-cgh.98) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * test(hooks): isolate trusted global configuration fixture (saa-cgh.98) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(hooks): isolate role cleanup in the selected repository (saa-cgh.109.4) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(hooks): reset only common local role configuration (saa-cgh.109.10) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(hooks): scope hooks-path cleanup to selected common config (saa-cgh.109.11) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * test(hooks): make worktree role preservation independent (saa-cgh.120) Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell * Report selected config read failures during hook reset (saa-cgh.120) Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell * fix(hooks): keep successful config stdout separate from diagnostics (saa-cgh.120) Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell * fix(config): pin role writes to fresh common context (GH#6384) (saa-cgh.120.3) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(config): retain Git diagnostics from role writes (saa-cgh.120.3) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * test(config): assert the actual Git lock diagnostic (saa-cgh.120.3) Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell * fix(config,hooks): restore the inherited-tracking fallback in the secret guard Maintainer review fixes for PR #6454 (adopt-pr iteration 1). The scorecard approved at 913/1000 with no blocker or major surviving synthesis; these are the non-gating findings that were cheap to close while the fixup was open. Finding 1 (minor, security) is the only in-range regression in the report. The range switched internal/config.isGitTracked from the inherited environment to gitenv.ScrubRouting only, so a config.yaml tracked solely through legitimate routing -- a bare repository whose work tree is named by GIT_DIR/GIT_WORK_TREE -- reported untracked, and a secret-key write that upstream-base refused was silently allowed. Restores the scrubbed-then-inherited union the same stack already gave cmd/bd.isGitTrackedFile. Finding 4 (nit) composes with it rather than conflicting, so both land as one change: the inherited probe now runs only when the scrubbed probe failed for a configuration reason. git's exit codes discriminate exactly -- 0 tracked, 1 repository reached but path untracked (final), 128 no reachable repository -- so the ordinary untracked-hook miss no longer spawns a second `git ls-files` while the bare-work-tree fallback is preserved. Finding 2 (minor). scrubWorktreeRemovalGitEnvForOS keyed its stricter no-optional-locks policy on strings.ToUpper while the rest of the PR uses execenv key identity. The two disagree in both directions on Windows: GIT_OPTIONAL_LOCKS with a dotted capital I (U+0130) survived the scrub although Git honors it, and GIT_OPTIONAL_LOCK with a long s (U+017F) was dropped although os/exec keeps it distinct. normalizeWorktreeGitEnvKey is deleted in favour of execenv.KeyEqualForOS. Base applied ToUpper on all platforms, so this is a consistency fix in newly rewritten code, not a regression. Finding 5 (nit). The comment above resetHooksPathIfBeadsManaged's probe asserted that repoRoot and commonDir share the cached Git context. Probed false: with cwd A and GIT_DIR=B/.git, `git rev-parse --git-common-dir --show-toplevel` prints B/.git and A. Restated as intent. Finding 3 (scrubGitHookEnv is a fifth, strictly weaker routing scrubber) is deliberately not taken here: cmd/bd/export_auto.go is untouched by this range, so the hazard is byte-identical at base, and the synthesis scoped it to a follow-up bead rather than growing this stack. Each fix is mutation-proved. Reverting isGitTracked reds only the new TestSecretGitTrackingHonorsInheritedBareWorkTree -- including "refusal = <nil>", the actual security consequence -- while the incumbent decoy test stays green, so the pin adds coverage rather than duplicating it. Restoring ToUpper reds only the new Windows row, showing both directions at once. TestGuardHookWritePathHonorsInheritedRepository gains a fixture guard asserting its scrubbed probe fails for a configuration reason rather than exit 1, so a future fixture change cannot silently make the fallback unreachable. scrubWorktreeRemovalGitEnvForOS had no test at all before this. Green locally: ./internal/config, ./internal/execenv, ./internal/gitenv, ./internal/githooksenv, ./internal/gittraceenv, ./internal/metrics, ./scripts, ./internal/beads (the GIT_CONFIG_GLOBAL blast radius neither reviewer ran), and a blast-radius cmd/bd run over the hooks, worktree, role and uninstall suites. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com> Co-authored-by: Bee <bee@ghosttrack.com> Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local> Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
131 lines
4.7 KiB
Go
131 lines
4.7 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/dolthub/dolt/go/store/blobstore"
|
|
"github.com/steveyegge/beads/internal/execenv"
|
|
"github.com/steveyegge/beads/internal/githooksenv"
|
|
)
|
|
|
|
// TestResetDataRefNamesMatchDolt keeps the locally pinned data-plane ref
|
|
// names in sync with the constants dolt's git blobstore actually publishes
|
|
// (store/blobstore/git_refs.go). If a dolt bump renames either ref, this
|
|
// fails instead of reset-data silently deleting the wrong refs.
|
|
func TestResetDataRefNamesMatchDolt(t *testing.T) {
|
|
if gitDoltDataRef != blobstore.DoltDataRef {
|
|
t.Errorf("gitDoltDataRef = %q, dolt publishes %q", gitDoltDataRef, blobstore.DoltDataRef)
|
|
}
|
|
if want := "refs/heads/" + blobstore.DefaultInfoBranch; gitDoltInfoRef != want {
|
|
t.Errorf("gitDoltInfoRef = %q, dolt publishes %q", gitDoltInfoRef, want)
|
|
}
|
|
}
|
|
|
|
func TestEnvWithNoGitHooksPreservesExistingParameters(t *testing.T) {
|
|
const existing = "'user.email=ci@example.com'"
|
|
t.Setenv(githooksenv.ParametersEnv, existing)
|
|
t.Setenv("BEADS_TEST_NO_HOOKS_KEEP", "GIT_CONFIG_PARAMETERS=unrelated-value")
|
|
|
|
// Build the expected slice independently of Without/DisabledEnv so a
|
|
// stale entry cannot hide behind Extract's last-wins lookup.
|
|
var want []string
|
|
for _, entry := range os.Environ() {
|
|
if !execenv.KeyEqual(execenv.EntryKey(entry), githooksenv.ParametersEnv) {
|
|
want = append(want, entry)
|
|
}
|
|
}
|
|
want = append(want, githooksenv.ParametersEnv+"="+existing+" "+githooksenv.NoHooksParam)
|
|
if got := envWithNoGitHooks(); !slices.Equal(got, want) {
|
|
t.Fatalf("envWithNoGitHooks() differs from the expected environment: got %d entries, want %d", len(got), len(want))
|
|
}
|
|
}
|
|
|
|
func TestClassifyResetDataRemote(t *testing.T) {
|
|
makeBareGitRepo := func(t *testing.T) string {
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "HEAD"), []byte("ref: refs/heads/main\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(dir, "objects"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return dir
|
|
}
|
|
makeDoltFileStore := func(t *testing.T) string {
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "manifest"), []byte("x"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return dir
|
|
}
|
|
|
|
bareRepo := makeBareGitRepo(t)
|
|
fileStore := makeDoltFileStore(t)
|
|
emptyDir := t.TempDir()
|
|
strangeDir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(strangeDir, "notes.txt"), []byte("x"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
url string
|
|
want resetDataKind
|
|
wantErr bool
|
|
}{
|
|
{"git+https", "git+https://github.com/org/repo.git", resetDataGitBacked, false},
|
|
{"git+ssh", "git+ssh://git@github.com/org/repo.git", resetDataGitBacked, false},
|
|
{"scp-style", "git@github.com:org/repo.git", resetDataGitBacked, false},
|
|
{"git+file", "git+file://" + bareRepo, resetDataGitBacked, false},
|
|
{"file url to bare git repo", "file://" + bareRepo, resetDataGitBacked, false},
|
|
{"bare path to bare git repo", bareRepo, resetDataGitBacked, false},
|
|
{"file url to dolt store", "file://" + fileStore, resetDataFileStore, false},
|
|
{"bare path to dolt store", fileStore, resetDataFileStore, false},
|
|
{"file url to missing dir", "file://" + filepath.Join(emptyDir, "nope"), resetDataFileAbsent, false},
|
|
{"file url to empty dir", "file://" + emptyDir, resetDataFileAbsent, false},
|
|
{"file url to unrecognized dir", "file://" + strangeDir, 0, true},
|
|
{"aws", "aws://[table:bucket]/db", resetDataUnsupported, false},
|
|
{"gs", "gs://bucket/db", resetDataUnsupported, false},
|
|
{"dolthub", "dolthub://org/db", resetDataUnsupported, false},
|
|
{"https hosted", "https://doltremoteapi.dolthub.com/org/db", resetDataUnsupported, false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := classifyResetDataRemote(tt.url)
|
|
if tt.wantErr {
|
|
if err == nil {
|
|
t.Fatalf("classifyResetDataRemote(%q) = %v, want error", tt.url, got)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("classifyResetDataRemote(%q): %v", tt.url, err)
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("classifyResetDataRemote(%q) = %v, want %v", tt.url, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestResetDataGitURL(t *testing.T) {
|
|
tests := []struct {
|
|
url string
|
|
want string
|
|
}{
|
|
{"git+https://github.com/org/repo.git", "https://github.com/org/repo.git"},
|
|
{"git+ssh://git@github.com/org/repo.git", "ssh://git@github.com/org/repo.git"},
|
|
{"git+file:///tmp/remote.git", "file:///tmp/remote.git"},
|
|
{"git@github.com:org/repo.git", "git@github.com:org/repo.git"},
|
|
{"file:///tmp/remote.git", "file:///tmp/remote.git"},
|
|
{"/tmp/remote.git", "file:///tmp/remote.git"},
|
|
}
|
|
for _, tt := range tests {
|
|
if got := resetDataGitURL(tt.url); got != tt.want {
|
|
t.Errorf("resetDataGitURL(%q) = %q, want %q", tt.url, got, tt.want)
|
|
}
|
|
}
|
|
}
|