fakeSessionID makes a deterministic v4-shaped UUID derived from slug. Used by insertTask to satisfy the session-id invariant on non-backlog rows without entangling tests with real Claude session lifecycles. The format passes sessionUUIDRe so tests that pin --session-id-style behavior keep working.
(slug string)
| 57 | // session lifecycles. The format passes sessionUUIDRe so tests that |
| 58 | // pin --session-id-style behavior keep working. |
| 59 | func fakeSessionID(slug string) string { |
| 60 | // FNV-64 hash → 16 hex chars, padded to 32 for v4 layout. |
| 61 | const fnvOff = 0xcbf29ce484222325 |
| 62 | const fnvPri = 0x100000001b3 |
| 63 | h := uint64(fnvOff) |
| 64 | for _, b := range []byte(slug) { |
| 65 | h ^= uint64(b) |
| 66 | h *= fnvPri |
| 67 | } |
| 68 | // Build "xxxxxxxx-xxxx-4xxx-8xxx-xxxxxxxxxxxx" from one hash + slug filler. |
| 69 | first := fmt.Sprintf("%016x", h) |
| 70 | // Use the slug bytes (zero-padded) as additional entropy for the |
| 71 | // last 12 chars so distinct slugs that hash-collide still differ. |
| 72 | pad := slug |
| 73 | for len(pad) < 12 { |
| 74 | pad += "0" |
| 75 | } |
| 76 | tailRaw := []byte(pad)[:12] |
| 77 | for i, b := range tailRaw { |
| 78 | // Force into hex range. |
| 79 | tailRaw[i] = "0123456789abcdef"[uint(b)%16] |
| 80 | } |
| 81 | tail := string(tailRaw) |
| 82 | return fmt.Sprintf("%s-%s-4%s-8%s-%s", first[:8], first[8:12], first[12:15], first[15:16]+first[0:2], tail) |
| 83 | } |
no outgoing calls
no test coverage detected