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