( t *testing.T, sessions *fakeSessionManager, )
| 3149 | } |
| 3150 | |
| 3151 | func newDetachedHarnessTaskRuntimeForTest( |
| 3152 | t *testing.T, |
| 3153 | sessions *fakeSessionManager, |
| 3154 | ) (*taskRuntime, workspacepkg.RuntimeResolver, aghconfig.HomePaths) { |
| 3155 | t.Helper() |
| 3156 | |
| 3157 | if sessions == nil { |
| 3158 | sessions = &fakeSessionManager{} |
| 3159 | } |
| 3160 | |
| 3161 | db := openDaemonTestGlobalDB(t) |
| 3162 | homePaths := testHomePaths(t) |
| 3163 | resolver, err := workspacepkg.NewResolver( |
| 3164 | db, |
| 3165 | workspacepkg.WithHomePaths(homePaths), |
| 3166 | workspacepkg.WithLogger(discardLogger()), |
| 3167 | workspacepkg.WithConfigLoader(func(rootDir string) (aghconfig.Config, error) { |
| 3168 | return aghconfig.LoadForHome(homePaths, aghconfig.WithWorkspaceRoot(rootDir)) |
| 3169 | }), |
| 3170 | ) |
| 3171 | if err != nil { |
| 3172 | t.Fatalf("workspace.NewResolver() error = %v", err) |
| 3173 | } |
| 3174 | registeredWorkspaces := make(map[string]struct{}) |
| 3175 | for _, info := range sessions.infos { |
| 3176 | if info == nil { |
| 3177 | continue |
| 3178 | } |
| 3179 | workspaceID := strings.TrimSpace(info.WorkspaceID) |
| 3180 | if workspaceID == "" { |
| 3181 | workspaceID = "global" |
| 3182 | } |
| 3183 | if _, ok := registeredWorkspaces[workspaceID]; !ok { |
| 3184 | if err := db.InsertWorkspace(testutil.Context(t), workspacepkg.Workspace{ |
| 3185 | ID: workspaceID, |
| 3186 | Name: workspaceID, |
| 3187 | RootDir: filepath.Join(t.TempDir(), workspaceID), |
| 3188 | CreatedAt: time.Now().UTC(), |
| 3189 | UpdatedAt: time.Now().UTC(), |
| 3190 | }); err != nil { |
| 3191 | t.Fatalf("InsertWorkspace(%q) error = %v", workspaceID, err) |
| 3192 | } |
| 3193 | registeredWorkspaces[workspaceID] = struct{}{} |
| 3194 | } |
| 3195 | agentName := strings.TrimSpace(info.AgentName) |
| 3196 | if agentName == "" { |
| 3197 | agentName = "daemon-test-agent" |
| 3198 | } |
| 3199 | if err := db.RegisterSession(testutil.Context(t), store.SessionInfo{ |
| 3200 | ID: info.ID, |
| 3201 | Name: info.Name, |
| 3202 | AgentName: agentName, |
| 3203 | WorkspaceID: workspaceID, |
| 3204 | Channel: strings.TrimSpace(info.Channel), |
| 3205 | SessionType: string(info.Type), |
| 3206 | State: string(info.State), |
| 3207 | CreatedAt: time.Now().UTC(), |
| 3208 | UpdatedAt: time.Now().UTC(), |
no test coverage detected