The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 2 | |
| 3 | /** |
| 4 | * An explicit physical name for a test about explicitly provided names: |
| 5 | * `base` plus a short hash of the test stage (`test_$USER` by default), so it |
| 6 | * is the same on every run and never collides with another user's run. Tests |
| 7 | * that aren't about names pass no name and let the resource generate one. |
| 8 | * |
| 9 | * The suffix is 6 lowercase hex characters, so it fits names limited to |
| 10 | * letters and digits; `separator` joins it for names that don't allow `-`. |
| 11 | */ |
| 12 | export const testName = (base: string, separator = "-"): string => |
| 13 | `${base}${separator}${stageHash(Test.defaultStage())}`; |
| 14 | |
| 15 | /** |
| 16 | * The short stage hash `testName` appends, for names a test assembles itself |
| 17 | * (hostnames, route prefixes): the same on every run, distinct per user and |
| 18 | * worktree. |
| 19 | */ |
| 20 | export const stageSuffix = (): string => stageHash(Test.defaultStage()); |
| 21 | |
| 22 | // FNV-1a: deterministic and dependency-free. |
| 23 | const stageHash = (stage: string): string => { |
| 24 | let hash = 0x811c9dc5; |
| 25 | for (let i = 0; i < stage.length; i++) { |
| 26 | hash ^= stage.charCodeAt(i); |
| 27 | hash = Math.imul(hash, 0x01000193); |
| 28 | } |
| 29 | return (hash >>> 0).toString(16).padStart(8, "0").slice(0, 6); |
| 30 | }; |