Repository navigation
bloom export: build a label, put a versioned file where a human works - #39
Conversation
Outputs live under their content hash and materialize at `.bloom/out/<label>.wav` — the right address for the engine and a useless one in a Finder window or an email attachment. `bloom export` takes the same patterns `build` takes, builds them, and copies each result to `~/Desktop` under the name you would say out loud: `//songs/creek/mix:main` becomes `creek-main.wav`, `//shared/assets:water` keeps `water.wav`, since shared material has no song to name. Three decisions worth stating. It exports what `play` would play, through `resolvePlayables`, so the two commands cannot drift on which file a label means — and so committed sources (assets, chosen variants) export straight from the song, no special case. It exports only the labels the patterns match. A build prints its dependencies because they are work it did; they are means, not products, and `bloom export creek` putting fifteen files on a Desktop would be a bug that reads as a feature. A missing destination is an error, not a mkdir. `--to ~/Desktps` is a typo, and creating it would bury the mistake under a directory that looks like success. Names need no sanitizing — labels are `[a-z0-9-]` by grammar — and collide only where a song has two labels of the same name in different packages. That is possible: the one-namespace rule (project-layout.md §4.3) covers sounds and assets, the `source:` namespace, so a track may share a sound's name. Both then take their package's scope into the name and every other label in the run keeps its plain one. Re-exporting overwrites and says `replaced` rather than accumulating `creek-main-2.wav`; the two status words are the same width, so the labels line up.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cb93ffc. Configure here.
Two changes from review of the first cut.
**Always the long name.** `//songs/creek/mix:main` exports as
`creek-mix-main-v1.wav`, not `creek-main.wav`, and shared material keeps
its shelf. The short form read better right up until a song has a track
and a sound of the same name — legal, since the one-namespace rule
covers sounds and assets, and the natural thing to do when a track plays
one sound — and then two different files want one name. Disambiguating
only on collision meant a name you could not predict without knowing the
rest of the project; a name that is always scoped is worth the extra
word.
**Exports are versioned, never overwritten.** Finishing something and
putting it somewhere is how people mark a version, and the previous one
is often the only copy of a decision later undone. A second export is
`-v2`, numbered from the highest already present — a gap means someone
threw that version away, and minting a second `-v2` would disagree with
them. Nothing in the destination is ever removed or overwritten,
including files this command did not write.
Re-exporting compares bytes against *every* existing version, newest
first, and writes nothing when one matches:
exported //songs/creek/mix:main → ~/Desktop/creek-mix-main-v1.wav
exported //songs/creek/mix:main → ~/Desktop/creek-mix-main-v2.wav
current //songs/creek/mix:main → ~/Desktop/creek-mix-main-v2.wav
reverted //songs/creek/mix:main → ~/Desktop/creek-mix-main-v1.wav (v2 is newer and different)
The last line is the case worth the machinery: export v1, change
something, export v2, change it back. Those bytes are v1 again. Filing
them as v3 would bury that, and a silent no-op would leave the newest
file on disk not being what you just built — so it names the version the
bytes are and the version that is still newest.
Searching every version rather than just the newest costs a hash per
candidate, so size is checked first (a stat, not a read): a mix that
differs audibly usually differs in length. Same-size candidates are
still hashed — a fader move keeps the length — and a test pins that the
filter cannot end the search early.
ninjudd
left a comment
There was a problem hiding this comment.
Reviewed at 930108c. Design reads well and the reasoning in the PR body holds up — versioning over overwriting, the long name, matching against every version rather than the newest, refusing to mkdir a typo'd destination. I verified the 18 tests and the full suite green on Node 24 (259 passed | 23 skipped, tsc --noEmit exit 0) in a scratch clone.
Two findings break invariants this PR states explicitly, and both are confirmed by running the code rather than reading it. Details inline; summary here.
P1 — a file differing only in case is silently overwritten. existingVersions matches case-sensitively; copyFileSync overwrites case-insensitively. On APFS (default, and the default destination is ~/Desktop) a hand-bounced Creek-Assets-Pad-v1.wav is destroyed in place — the directory listing still shows their filename, holding our bytes. This is exactly the scenario "never touches a file it did not write" pins; that test passes only because its fixture happens to use the same case.
P2 — a committed source that drifted from its declared hash exports as current. For asset and generation targets item.sha256 is the declared hash, which the build trusts without checking (src/graph/build.ts:153-155 — "check verifies content, the build system trusts the declaration"). Export compares candidates' real bytes against that declaration, so a bounced-over pad.wav reports current → creek-assets-pad-v1.wav while v1 holds different audio. Note the asymmetry: the same drift makes bloom build refuse when the asset is an input (build.ts:230-234), and this is the command whose product leaves the system.
P2 — the copy is not atomic. copyFileSync writes in place at the final name. Ctrl-C or ENOSPC mid-copy leaves a truncated -vN.wav that, because nothing is ever overwritten, is permanent — and poisons the family forever after: it is "newest and different", so every later export of matching bytes reports reverted (vN is newer and different). materialize already established copy-to-temp + rename for the analogous hazard (build.ts:194-204).
One fix covers the first and third: copy to ${to}.tmp-${process.pid} in the destination, then linkSync(tmp, to) and unlink the temp. linkSync is atomic and fails EEXIST on an existing destination, including a case-differing one — I checked both on APFS. (copyFileSync(..., constants.COPYFILE_EXCL) also refuses the case-differing name, if you'd rather not carry a temp file, but it leaves the atomicity gap.)
P3 — the doc paragraph describes different behaviour than the code. Non-blocking; noted inline.
Nothing else to flag. The bases collision guard is right to be an error, the size pre-filter is correctly pinned as unable to end the search early, and homeRelative's /Users/justinx case is a nice catch to have tested.
Three findings from the #39 review, all reproduced before fixing. **A file differing only in case was silently destroyed.** The version scan matched case-sensitively while APFS resolves case-insensitively, so someone's `Creek-Mix-Main-v1.wav` was invisible to the scan and then became our bytes *under their filename* — a directory listing does not even change. Confirmed on this machine: copyFileSync onto the lowercase name left one file, holding our content, still called theirs. Writes now go to a temp name in the destination and `link` into place. `link` fails EEXIST rather than truncating, including on a name that differs only in case, and the next version number is taken. The scan is also case-insensitive now — not for safety, which the link already gives, but for truthfulness: their v5 must count as 5, or our next export writes a "v1" that is newer in time than a v5 sitting beside it. **The same change makes a version complete or absent.** An interrupted copy left a truncated `-vN.wav`, and since nothing is ever overwritten that file was permanent: forever "newest and different", so every later matching export would report `reverted`. Now an interrupt leaves debris under a dotted `.part-<pid>` name that no scan matches. **A drifted committed source exported as `current`.** For assets and chosen variants the recorded hash is the *declared* one, which the build deliberately trusts and only verifies when consuming the file as an input. So a bounce written over pad.wav without re-importing compared equal to the previous export, and the command said `current` while the exported file was different audio from the project's. Export now hashes what it is about to copy and refuses when a committed source disagrees with its declaration — the guard build applies to inputs, on the command whose product leaves the machine. Playable gained `committed` to say which items carry a declared hash; typecheck caught the one hand-built Playable in click.test.ts, as it did in #35. Each fix has a test that fails without it, checked by reverting them one at a time. The case test alone did not isolate the scan (the link guard also saves the file), so there is a second test for the numbering. Docs: the paragraph said bytes are compared against the newest version when the code compares every version, and never mentioned `reverted`. Rewritten, including the two new guarantees. A citation I had drafted for project-core.md §3.5 turned out to be the cache-key decision, not the tamper guard, so it is described rather than cited.
|
Re-reviewed at P1, case-clobber — fixed and confirmed. Copy-to-dotted-temp plus Your A/B on the scan reverts correctly, and I confirmed it. Reverting the P2, drift — fixed, and refusing is the right call. Exporting drifted bytes as a new version would have put a file on someone's Desktop that nothing in the project describes, which is the failure this command can least afford. The Citation call was right. I verified Verified locally on Node 24: One new finding inline: the drift refusal fires inside the export loop, so a multi-label run can leave a correct file on the Desktop and print only an error. P3, and single-label export is unaffected. Two things blocking this that are not about the codeThis PR now conflicts with Resolving the conflict textually is not enough — it leaves a type error. The conflict is in I merged Worth noting the pattern: this call site has now broken in #35, in this PR, and again on the merge. A Nothing else outstanding from my side. Still yours to merge. |
The drift check ran per item inside the write loop while the name- collision guard was hoisted above it, so a multi-label run could land a correct file and then throw — a file on the Desktop with only an error on screen, which is worse than either outcome alone: the thing you can see disagrees with the thing you were told (#39 review P3). Both checks now run in one pass before anything is written. They reject the request, not one item of it, so that is where they belong. The hash each item is verified with is carried forward to the write loop, so this is a reordering rather than extra work. The test exports a clean asset and a drifted one in the same run and asserts the destination is untouched; it fails with the check back inside the write loop.
One conflict, in the hand-built Playables in click.test.ts. #38 taught withClick to re-hash, dropping the stale "carries it through untouched" comment; this branch made `committed` required. The resolution takes both, and adds the field to the re-hashes test #38 introduced — which the merge would otherwise have left as a type error the branch's own CI never saw, because a conflicting PR has no merge ref to build. That call site has now needed the same edit three times (#35, this PR, this merge). A test Playable factory would end it; noted for a follow-up rather than smuggled in here.
|
Verified at P3 fixed and confirmed. The merge resolution is right. Both hand-built CI genuinely ran this time. Independent verification on Node 24 at this head: All five threads resolved. Ready for you. |
…it (#40) Hand-built `Playable` literals in tests have broken three times running, each time in a way the usual signals missed: - `sha256` in #35 — invisible to vitest (which does not typecheck) and to `pnpm build` (which excludes tests), so every signal was green. - `committed` in #39. - Again merging #38 into #39: the re-hashes test #38 added needed the field too, a type error neither branch's own CI could see, because a conflicting pull request has no merge ref to build. `playable({ path })` fills every required field. The two call sites in `click.test.ts` use it. ### The property, verified rather than assumed I added a temporary required field to `Playable` and checked who breaks: ``` before updating the factory: src/commands/play.ts, src/testing/playable.ts after updating only the factory: src/commands/play.ts ``` `play.ts` is real code and has to change anyway. No test file does. ### Two small decisions `path` has no default. A Playable's job is to name a file, and defaulting it would turn a missing fixture into an ENOENT somewhere far away instead of a compile error at the call site. The helper lives in `src/testing/` and is excluded from `tsconfig.build.json`, so it does not ship in `dist`. `*.test.ts` was the only exclusion before; a helper that is not itself a test needed its own. `pnpm typecheck` exit 0, 301/301. Built in a git worktree off `main`, so the shared checkout — whose `dist` the global `bloom` symlinks into — was never switched or rebuilt. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only helper and test refactors; no production runtime behavior changes. > > **Overview** > Adds **`playable()`** in `src/testing/playable.ts` so tests can build a full **`Playable`** with defaults for `label`, `pkg`, `sha256`, and `committed`, while **`path` stays required** at the call site. > > **`click.test.ts`** now uses `playable({ path: src })` (and overrides `sha256` in the re-hash test) instead of hand-written literals. > > **`tsconfig.build.json`** excludes **`src/testing/**`** so the helper is not emitted to **`dist`** alongside test files. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit f3a353e. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->

Same syntax as
build; the result lands on~/Desktopas a numberedversion. Captured against a clone of field (
--toa scratch directory,rewritten here to
~/Desktop):--to <dir>sends them elsewhere.Why
Outputs live under their content hash and materialize at
.bloom/out/<label>.wav. That is the right address for the engine and auseless one in a Finder window or an email attachment — this is the one
command whose product is a file you take somewhere else.
Decisions worth reviewing
Versioned, never overwritten. Finishing something and putting it
somewhere is how people mark a version, and the previous one is often
the only copy of a decision later undone. Numbering is
max + 1overwhat is already there — a gap means someone threw that version away, and
minting a second
-v2would disagree with them. Nothing in thedestination is ever removed or overwritten, including files this command
did not write (pinned by a test that puts a hand-bounced
creek-sounds-pad-normalized-v1.wavin the way and checks it survivesbyte-for-byte).
Re-exporting is a no-op, against every version — not just the
newest. The
revertedline above is the case that motivates it:export v1, change something, export v2, change it back. Those bytes are
v1 again; filing them as v3 buries that, and a silent no-op would leave
the newest file on disk not being what you just built. So the result
names the version the bytes are and the version that is still newest.
The long name, always.
creek-mix-mainrather thancreek-main. Theshort form reads better until a song has a track and a sound of the same
name — legal (the one-namespace rule covers sounds and assets, the
source:namespace) and the natural thing to do when a track plays onesound — and then two different files want one name. Disambiguating only
on collision produced a name you could not predict without knowing the
rest of the project.
It exports what
playwould play, throughresolvePlayables, so thetwo commands cannot drift on which file a label means — and committed
sources (assets, chosen variants) export straight from the song with no
special case.
Only the labels the patterns match. A build prints its dependencies
because they are work it did; they are means, not products, and
bloom export creekscattering fifteen files across a Desktop would bea bug that reads like a feature.
A missing destination is an error, not a
mkdir.--to ~/Desktpsisa typo, and creating it would bury the mistake under something that
looks like success.
Cost
Searching every version costs a hash per candidate, so size is checked
first — a stat, not a read; a mix that differs audibly usually differs
in length. Same-size candidates are still hashed (a fader move keeps the
length), and a test pins that the filter cannot end the search early by
putting a same-size, different-content v2 in front of the real match.
Tests
18: the naming, the version scan (gaps, other labels, other extensions,
near-miss filenames),
homeRelative(including that/Users/justinxisnot
~x), and the behaviours above end to end against a real builtproject — each with an explicit
--toso no test can write to a realDesktop.
pnpm typecheckexit 0, 282/282.Branched off
main, so it is independent of #38.