( baseName: string, teamName: string | undefined, )
| 265 | * @internal Exported for testing |
| 266 | */ |
| 267 | export async function generateUniqueTeammateName( |
| 268 | baseName: string, |
| 269 | teamName: string | undefined, |
| 270 | ): Promise<string> { |
| 271 | if (!teamName) { |
| 272 | return baseName |
| 273 | } |
| 274 | |
| 275 | const teamFile = await readTeamFileAsync(teamName) |
| 276 | if (!teamFile) { |
| 277 | return baseName |
| 278 | } |
| 279 | |
| 280 | const existingNames = new Set(teamFile.members.map(m => m.name.toLowerCase())) |
| 281 | |
| 282 | // If the base name doesn't exist, use it as-is |
| 283 | if (!existingNames.has(baseName.toLowerCase())) { |
| 284 | return baseName |
| 285 | } |
| 286 | |
| 287 | // Find the next available suffix |
| 288 | let suffix = 2 |
| 289 | while (existingNames.has(`${baseName}-${suffix}`.toLowerCase())) { |
| 290 | suffix++ |
| 291 | } |
| 292 | |
| 293 | return `${baseName}-${suffix}` |
| 294 | } |
| 295 | |
| 296 | // ============================================================================ |
| 297 | // Spawn Handlers |
no test coverage detected