Title: mcpx testing: one seed per run -- format (UUIDv7), derivation, and how it reaches every test · Issue #1949 · developing-today/code · GitHub
Open Graph Title: mcpx testing: one seed per run -- format (UUIDv7), derivation, and how it reaches every test · Issue #1949 · developing-today/code
X Title: mcpx testing: one seed per run -- format (UUIDv7), derivation, and how it reaches every test · Issue #1949 · developing-today/code
Description: Relocated from dezren39/darwin-nix#121 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/ni...
Open Graph Description: Relocated from dezren39/darwin-nix#121 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc...
X Description: Relocated from dezren39/darwin-nix#121 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue refe...
Opengraph URL: https://github.com/developing-today/code/issues/1949
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx testing: one seed per run -- format (UUIDv7), derivation, and how it reaches every test","articleBody":"Relocated from dezren39/nix#121 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix numbering).\n\nParent: #93\n\n## Summary\n\nDecide the **run seed**: what one looks like, how every random input in every test is derived from it, how it reaches every `go test` process (locally and in CI), and how a failure is reproduced from it with one command. Per #91 this is step 1 of the testing strategy: it must land before the first randomized test does, or the first fuzz failure is unreproducible.\n\nWhere the seeds are *stored* and *collected* is #122. Which library consumes the seed is #123. Generator registry and versioning detail is #124.\n\n## Original notes\n\n> - testing\n> - agents should make at least 1 simple, new test for every bug observed from any source, when cheap to do so-- aggresively test many permutations. \n> - you can absolutely rely on fuzzing anywhere you can fit it and you should whenever you can-- but you _must_ use a single seed per-run to generate all inputs. (this could eventually be discussed with careful consideration.) it should be appended into a test tracking structured file in the repo and it can be committed. ideally main branch commit's seed or pr merge seed should make it back into file eventually. to prevent churn, maybe ci appends the seed into a gha var (race/overwrite risk?), or attached as artifact to each workflow in init job before tests begin-- a collector job can scoop them up sometime later. once a day/week/on-release/every-100-commits. im thinking touch tests/seeds/\u003cseed> or uv has a seed generate job. anyways ci it should end up in that dir, then as an artifact if gha and main branch, then passed into the test matrix. if uv test without arg- warn, generate and write it yourself pass it to all tests, if some other testing method there should not be a static seed, throw for empty or setup should make the seed. avoid changing how seed generates data. im not sure if a convenient uuid with time, v7?, is valid, but as long as its enough entropy whatever works. either put nothing in their or compact json, consider seeds/v1/id/\u003cfirst 2 char>/\u003cseed>\u003c--symlink: seeds/yyyy/mm/dd/\u003cseed> avoiding conflicts is important.\n\n\"uv test\" in the notes: mcpx is Go and has no uv. This issue reads it as **\"the test entrypoint/wrapper\"** -- a `just` recipe or `pkgs/mcpx/scripts/test.sh` that everyone (agents, humans, CI) calls instead of bare `go test`.\n\n## Current state (re-checked at 05c78b2)\n\n| Fact | Where |\n| --- | --- |\n| No randomness in any test: 735 `func Test*` across 64 files, no `math/rand`, `testing/quick`, rapid, `Fuzz*`. Clean slate: no existing inputs to preserve. | `rg` over `pkgs/mcpx` |\n| No test wrapper. CI calls `go test ./... -count=1` directly; the repo `justfile` has no mcpx test recipe. | `.github/workflows/mcpx.yml`; `rg mcpx justfile` (no hits) |\n| `go test ./...` builds **one test binary per package and runs each as a separate process**. Anything minted inside a test process is per package, not per run. | `go help test` |\n| e2e passes `os.Environ()` into every `mcpx` subprocess, so an env var reaches the daemon and runtimes for free. | `internal/e2e/e2e_test.go:52` |\n| Only flags in a fixed \"cacheable\" set keep `go test` results cacheable; `-shuffle` and any `-args` flag disable caching. A test that reads an env var is cached keyed on that var's value. | `go help test` lines 76-89 |\n| `-shuffle off,on,N`: N is an integer seed and is printed for reproducibility. | `go help testflag` |\n| `math/rand/v2`: `NewChaCha8(seed [32]byte)`, `NewPCG(seed1, seed2 uint64)`. `go doc math/rand/v2` makes **no** promise that `Rand` methods (`IntN`, `Shuffle`, `Perm`, ...) return the same values across Go releases; the ChaCha8 stream itself is specified (chacha8rand, C2SP). | `go doc math/rand/v2` |\n| `google/uuid` v1.6.0 (already an indirect dep) implements `NewV7` with the 12-bit `rand_a` filled from the sub-millisecond clock, not randomness. | `github.com/google/uuid@v1.6.0/version7.go:80-103` |\n| `package.nix` `checkPhase` re-runs 18 unit packages inside the nix sandbox, where no seed env var exists. | `pkgs/mcpx/package.nix` |\n| `internal/logging/trace.go:168` records every `MCPX_*` env var into traces, so `MCPX_TEST_SEED` would show up in daemon traces from e2e runs (useful). Settings env names are `\"MCPX_\" + path` (`internal/settings/schema.go:220-224`), so a future setting under `test.` would collide with `MCPX_TEST_*`. | |\n| `MCPX_TEST_SEED` would be an `MCPX_*` variable that the code reads and no setting declares, which is exactly the class #172 (in flight) inventories. #172's recommended guard bans `os.Getenv(\"MCPX_*\")` outside the settings package unless the name is on an allowlist with a reason. The seed helper's read needs that allowlist entry, or `_test.go` files and `internal/testsupport` need to be out of the guard's scope. #171's `TestNoHandRolledSettingEnv` (`internal/settings/consumed_test.go:145`) only covers names the registry owns, so it does not flag the seed variable today. | #172 |\n\n## Design\n\n### 1. Seed format\n\n| Format | Distinct across runs | Human-copyable | Time-ordered | Notes |\n| --- | --- | --- | --- | --- |\n| u64 integer | 64 bits | yes | no | what `-shuffle` and rapid take; too easy to hand-pick (\"seed 1\") |\n| UUIDv4 | 122 bits | yes | no | standard, but no ordering |\n| random 128/256-bit hex | 128/256 bits | long | no | entropy beyond ~64 bits buys nothing here (see below) |\n| **UUIDv7** | 74 bits (62 with google/uuid) + ms timestamp | yes | **yes** | recommended |\n| derived from `run_id`/`run_attempt` | ~34 bits of run id | yes | yes | CI-only, predictable; evaluated in #122 |\n\nFacts for v7 (RFC 9562 section 5.7): 48-bit `unix_ts_ms`, 4-bit version, 12-bit `rand_a`, 2-bit variant, 62-bit `rand_b`. RFC 9562 section 6.2 lets implementations spend `rand_a` on sub-ms precision or a counter, which is what google/uuid does -- so budget **62** random bits, not 74. Either is ample: a collision needs two runs in the *same millisecond* and then a ~2^31 birthday bound on the random part.\n\nEntropy is not the constraint anyway. A PRNG needs a fixed-size key (ChaCha8: 32 bytes), so the id is **never** used as a key directly: it is hashed into one (section 2). What the id needs is to be *distinct* per run and *easy to copy*; v7 adds free time ordering (ids sort by mint time, and the date is recoverable from the id without a lookup, which #122 uses).\n\n**Recommendation:** mint UUIDv7 (canonical lowercase, 36 chars). On *input*, accept any string matching `[A-Za-z0-9._-]{1,128}` (so a human can reproduce with an old id, and the format is not locked in forever); only the wrapper and CI mint, and they mint v7.\n\nMinting without a Go dependency (works in a CI init job before `setup-go`, and on macOS where BSD `date` has no `%3N`):\n\n```sh\npython3 -c \"import os,time;b=bytearray(int(time.time()*1000).to_bytes(6,'big')+os.urandom(10));b[6]=b[6]&15|0x70;b[8]=b[8]&63|0x80;h=b.hex();print(f'{h[:8]}-{h[8:12]}-{h[12:16]}-{h[16:20]}-{h[20:]}')\"\n# e.g. 01a0f101-2378-7c1c-9dc1-5a1ae1571eca (74 random bits)\n```\n\n### 2. Derivation: one root, many independent streams\n\n```\nroot = SHA-256(\"mcpx-test-seed/v1\\x00\" || seedID)\nstream(t, g@v) = SHA-256(root || 0x00 || \"g@v\" || 0x00 || t.Name()) -> ChaCha8 key\nshuffle = int64(big-endian(SHA-256(root || \"shuffle\")[:8]) & MaxInt63) -> go test -shuffle=N\nrapid (if used) = non-zero uint64 from SHA-256(root || \"rapid\") -> RAPID_SEED\n```\n\n- Adding, removing or reordering tests never shifts another test's inputs (each stream is keyed by test name, not by draw order in the process).\n- Changing generator `g` (a new version) never shifts generator `h`'s inputs.\n- Renaming a test changes its inputs. Acceptable; documented.\n- `v1` in the domain tag is the **derivation** version. Changing the derivation is `v2`; old seeds replay under `v1`.\n\n### 3. \"avoid changing how seed generates data\"\n\n- **Same commit + same seed reproduces exactly**, always -- the commit pins the generator code. Generator stability matters only for **cross-commit replay** (an old stored seed against today's code), which is what the stored seeds in #122 are for.\n- Every generator is `name@version`. Any change that alters its output for the same stream is a new version; the old version is kept while any stored seed references it, or frozen. Registry detail in #124.\n- **Guard test:** per `generator@version`, a checked-in hash of its first N outputs from a fixed test-vector key. It fails when a generator's output changes without a version bump -- including when a Go upgrade changes `IntN`/`Shuffle` (not promised stable). The test vector pins the *generator*; it is not a static seed for testing mcpx, which the notes forbid.\n- To shrink Go-release coupling: generators draw only `Uint64()` from the ChaCha8 source and do their own range reduction (a few lines), so the only external dependency is ChaCha8's specified stream.\n\n### 4. How the seed reaches tests\n\n- **`MCPX_TEST_SEED`** env var is the one channel. Reserve the `MCPX_TEST_*` prefix (a settings guard can assert no setting path starts with `test.`).\n- **`internal/testsupport/seed`** helper, read lazily: `seed.Rand(t, gen)` derives the stream for `(t.Name(), gen@version)` and registers a `t.Cleanup` that, if `t.Failed()`, logs the seed, test, generator and the exact reproduce command. Packages that never call it never read the env var and **stay cacheable**; packages that do are re-run whenever the seed changes (correct).\n- No `TestMain` needed anywhere.\n- **Wrapper** (`just mcpx-test` or `pkgs/mcpx/scripts/test.sh`; exact home decided with #99): mints **once** if unset, exports it, derives and passes `-shuffle=N`, runs `go test` with any extra args. One seed for every package process.\n\n### 5. No seed given\n\n| Situation | Behaviour |\n| --- | --- |\n| Wrapper, `MCPX_TEST_SEED` unset or empty | warn on stderr, mint v7, print `MCPX_TEST_SEED=\u003cid>`, write it to a gitignored `pkgs/mcpx/.cache/test-seed/last` (+ local history), export, run. |\n| Bare `go test`, unset or empty | helper mints once **per process** (`sync.Once`), logs a warning on first use: \"no MCPX_TEST_SEED; generated \u003cid> for this package only -- use the wrapper for one seed per run\". Still reproducible (the id is printed on failure). |\n| CI (`CI=true` / `GITHUB_ACTIONS=true`), unset or empty | **fail** (helper `t.Fatal`, wrapper exit 1). CI must never mint inside a test process. |\n| Anywhere | never a static default in code. |\n\n\"write it yourself\": locally the seed is written to a **gitignored** file, not the committed store -- local runs committing into the repo would be the churn the notes want to avoid. Committed seeds come from CI via #122 (open question below).\n\n### 6. Reproduce from a seed (one command)\n\n```sh\nMCPX_TEST_SEED=01a0f101-2378-7c1c-9dc1-5a1ae1571eca just mcpx-test -run '^TestX$' ./internal/codegen\n```\n\nThe wrapper derives the same `-shuffle` value from the seed. The helper prints exactly this line on failure, with the commit. In CI, a `workflow_dispatch` input `seed` re-runs the whole matrix on CI runners with a given seed.\n\nCaveat: this reproduces **inputs and test order**, not timing. Execution is not deterministic (#126); a timing bug may need several tries under the same seed.\n\n### 7. Minting in CI (mechanism only; the matrix is #95's)\n\n```yaml\njobs:\n seed:\n runs-on: ubuntu-latest\n outputs:\n seed: ${{ steps.mint.outputs.seed }}\n steps:\n - id: mint\n env: { SEED_IN: \"${{ inputs.seed }}\" } # workflow_dispatch override\n run: |\n seed=\"${SEED_IN:-$(python3 -c '...v7 one-liner above...')}\"\n echo \"seed=$seed\" >> \"$GITHUB_OUTPUT\"\n echo \"MCPX_TEST_SEED=\\`$seed\\`\" >> \"$GITHUB_STEP_SUMMARY\"\n jq -n --arg seed \"$seed\" --arg sha \"$GITHUB_SHA\" --arg ref \"$GITHUB_REF\" \\\n --arg event \"$GITHUB_EVENT_NAME\" --arg run \"$GITHUB_RUN_ID\" --arg attempt \"$GITHUB_RUN_ATTEMPT\" \\\n '$ARGS.named' > seed.json\n - uses: actions/upload-artifact@v4\n with: { name: test-seed, path: seed.json }\n test:\n needs: seed\n env: { MCPX_TEST_SEED: \"${{ needs.seed.outputs.seed }}\" }\n # matrix owned by #95\n```\n\n- \"Re-run failed jobs\" reuses the outputs of the already-successful `seed` job, so failed shards re-run **with the same seed** (desired: a same-seed pass is a flake, not a seed-dependent bug -- input for #99's flake policy). \"Re-run all jobs\" mints a new seed. (Verify on the first real run.)\n- The artifact is what #122's collector scoops up.\n- **Nix `checkPhase`:** the sandbox has no seed and a nix build should stay deterministic. Recommend `checkPhase` sets `MCPX_TEST_FUZZ=off` (generators run only their checked-in regression inputs), or #95 drops the double run of unit tests entirely. Flagged to #95.\n\n## Approaches\n\n### A -- `TestMain` in every package mints or reads the seed (least recommended)\nAbout 30 `TestMain`s. Bare `go test ./...` then produces ~30 different seeds for one \"run\", and a new package without a `TestMain` is silently unseeded. Printing happens at process start, far from the failure. Nothing here is better than C.\n\n### B -- a `-seed` test flag (registered in `TestMain`) plus a wrapper\nFamiliar (`-rapid.seed`, `-shuffle` look like this). But `go test ./... -args -seed=X` **errors** in every package whose test binary does not define `-seed` (\"flag provided but not defined\"), so every package needs the `TestMain` from A anyway; and any `-args` flag disables `go test` caching for all packages, including the ones that never use randomness. Could be offered *in addition* to the env var for single-package runs, but it adds a second channel to keep in sync.\n\nA variant that fixes bare `go test ./...` without a wrapper: all package test binaries are children of the same `go` process, so the first to start could create `$TMPDIR/mcpx-test-seed.\u003cppid>` (write temp + `os.Link`, atomic) and the rest read it. Clever, ~30 lines, but breaks under `-exec`, `go test -c`, IDE runners and `go test` inside `nix build`. Not the default; possible later.\n\n### C -- env var + lazy helper + one wrapper that mints once (recommended)\nAs in sections 4-7. One channel that works for subprocesses (e2e, daemon, runtimes), keeps unrelated packages cacheable, needs no per-package boilerplate, fails closed in CI, and gives a one-command reproduction. The wrapper is also where #99's \"what to run locally\" policy naturally lives. It does not need to reap daemons: #182 fixed #52's leak in the harness itself (`newEnv` cleans up with `stop --all` and sets `MCPX_AUTOSTART_IDLE_EXIT=60s`, `internal/e2e/e2e_test.go:68,79`).\n\n## Open questions\n\n- Wrapper home: `just mcpx-test` in the repo `justfile`, `pkgs/mcpx/scripts/test.sh`, or both (just calling the script)? Windows (in the #97 env wish-list) favours a script that also runs under Git Bash, or a Go `cmd` under `internal/testsupport/cmd`.\n- Should local seeds ever reach the committed store (e.g. only failing ones, via an explicit `just mcpx-seed-keep`)? Default proposed: no.\n- `-shuffle` disables test caching; is shuffling on by default locally, or CI-only (#99 decides)?\n- Env var name: `MCPX_TEST_SEED` (proposed) vs `MCPX_SEED`. Whichever it is, reserve the prefix in #172's allowlist when that lands, so the \"read but never declared\" guard treats it as test-only rather than as a missing setting.\n- Accept arbitrary strings as seed ids on input, or v7 only? Proposed: accept, but the store (#122) only files v7 ids minted by CI.\n- Budget knob (`MCPX_TEST_FUZZ=off|quick|ci|soak`) belongs here or in #124? Proposed: named here, sized in #124 with #95.\n\n## Ease · Impact · Related\n\n**Ease** S (helper + wrapper ~150 lines; CI init job ~20 lines) · **Impact** high (every randomized test depends on it)\n**Depends on / related:** #91 (strategy step 1), #93, #122, #123, #124, #125 (lands it), #126; #95 (consumes the `seed` job output, owns the matrix and the nix double run), #99 (wrapper as the local entrypoint, `-shuffle` and flake policy), #172 (in flight: its allowlist must admit the seed variable), #52 (closed, fixed in #182; the harness cleans up after itself now, so the wrapper has nothing to reap).\n\nSecurity/auth deferred; see tracker.\n\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-28T22:40:49Z","url":"https://github.com/developing-today/code/issues/1949"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:12135896-0332-fba1-c0ee-c3fbd8ce5e5d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 846A:1A09C8:34EF40:45438C:6B0617FD |
| html-safe-nonce | a3f285846229a1e2c108424c142a4a2981b56816c8f29ef2600fa7d12ec9c865 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDZBOjFBMDlDODozNEVGNDA6NDU0MzhDOjZCMDYxN0ZEIiwidmlzaXRvcl9pZCI6IjUyNDgwMjA3ODU1OTEwOTczNDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3704ba7cc64c52a3e428ee79761acbdcd9f770ad087b8941683dda1d152aa7a6 |
| hovercard-subject-tag | issue:6088831108 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/1949/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4b77eadf76596c74f83bb574b8e8999bffd51921a460954c2b2919ca7edf4348/developing-today/code/issues/1949 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4b77eadf76596c74f83bb574b8e8999bffd51921a460954c2b2919ca7edf4348/developing-today/code/issues/1949 |
| og:image:alt | Relocated from dezren39/darwin-nix#121 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 97d4714e567728e1f85f88b0cf68c89f0f8a3dc41e8869af7aeb8195ad990374 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 866f202ebf7ac5aff8f633417d9fd8a53818a977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width