fix: require adoption worktree ownership metadata · Entire

fix: require adoption worktree ownership metadata

901ee9b·

peyton-alt·2w ago·2 files·+35 added/-1 removed

Sessions

0ed46044b4c8View transcript

[?
Session Adoption and Worktree Management FixesCodex·1 step](/content/gh/entireio/cli/session/019ef09e-1621-7183-8205-646a383a2faf#timeline-0ed46044b4c8/index.html)

Changes

2

338 unmodified lines

339
340
341
342
342
343
344
345

338 unmodified lines

if state.WorktreePath != "" {
        return sameAdoptPath(state.WorktreePath, sourceWorktree)
    }
    return true
    return false
}

func adoptSessionWorktreeLabel(state *session.State) string {

Mcmd/entire/cli/session_adopt.go+1/-1

1021 unmodified lines

1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061

1021 unmodified lines

}
}

func TestSessionAdopt_RejectsSourceSessionWithoutWorktreeMetadata(t *testing.T) {
    sourceRepo := setupAdoptRepo(t)

sessionID := "missing-worktree-metadata"
    lastInteraction := time.Now().Add(-1 * time.Minute)
    sourceStore := session.NewStateStoreWithDir(filepath.Join(sourceRepo, ".git", session.SessionStateDirName))
    if err := sourceStore.Save(context.Background(), &session.State{
        SessionID:           sessionID,
        AgentType:           agent.AgentTypeClaudeCode,
        StartedAt:           time.Now().Add(-5 * time.Minute),
        LastInteractionTime: &lastInteraction,
        Phase:               session.PhaseActive,
        BaseCommit:          testutil.GetHeadHash(t, sourceRepo),
    }); err != nil {
        t.Fatal(err)
    }

_, err := selectAdoptSourceSession(context.Background(), sourceStore, sourceRepo, sessionID)
    if err == nil {
        t.Fatal("selectAdoptSourceSession succeeded for explicit session without worktree metadata, want refusal")
    }
    if !strings.Contains(err.Error(), "belongs to") || !strings.Contains(err.Error(), "unknown") {
        t.Fatalf("selectAdoptSourceSession error = %v, want missing-worktree ownership refusal", err)
    }

_, err = selectAdoptSourceSession(context.Background(), sourceStore, sourceRepo, "")
    if err == nil {
        t.Fatal("selectAdoptSourceSession auto-selected session without worktree metadata, want no candidate")
    }
    if !strings.Contains(err.Error(), "no recent active sessions") {
        t.Fatalf("selectAdoptSourceSession error = %v, want no recent active sessions", err)
    }
}

func TestStateStoreForWorktreeIgnoresGitStderrOnSuccess(t *testing.T) {
    if runtime.GOOS == "windows" {
        t.Skip("uses a POSIX shell script fake git")

Mcmd/entire/cli/session_adopt_test.go+34