(a: string, b: string)
| 48 | * transitive instead of degenerating into V8's order-dependent output. |
| 49 | */ |
| 50 | export function compareAgentIds(a: string, b: string): number { |
| 51 | if (a === b) return 0; |
| 52 | if (a === 'main') return -1; |
| 53 | if (b === 'main') return 1; |
| 54 | const na = /^agent-(\d+)$/.exec(a); |
| 55 | const nb = /^agent-(\d+)$/.exec(b); |
| 56 | if (na && nb) return Number(na[1]) - Number(nb[1]); |
| 57 | if (na) return -1; // all agent-N sort before any non-agent-N id |
| 58 | if (nb) return 1; |
| 59 | return a.localeCompare(b); |
| 60 | } |
no test coverage detected