fix(cli): a track with no beats answers an empty result, not an error (#7173)

* fix(cli): a track with no beats answers an empty result, not an error

* fix(cli): keep beats run under the complexity gate
This commit is contained in:
Miguel Ángel
2026-11-04 20:21:59 +00:00
committed by GitHub
parent 2679bcdee7
commit cffd70f2f9
3 changed files with 35 additions and 9 deletions
+2 -2
View File
@@ -778,8 +778,8 @@ into the audio; `strength` (0–1) is relative loudness. Beats you add, move, or
delete in Studio save back to the same file.
A track without a steady beat (ambient, rubato, too short) gets no beat file:
the command fails and writes nothing rather than inventing a grid. Results
match Studio's to within a frame or two — Studio decodes in the browser, often
the command answers an empty result (`count: 0`, exit 0) and writes nothing rather
than inventing a grid. Results match Studio's to within a frame or two — Studio decodes in the browser, often
at a different sample rate, which can shift a beat slightly.
### `audio`
+20 -3
View File
@@ -132,14 +132,31 @@ describe.skipIf(!canDecode)("hyperframes beats", () => {
expect(out).toMatch(/No music track found/);
});
it("writes nothing for a track with no steady beat", async () => {
it("answers a track with no steady beat with an empty result and writes nothing", async () => {
const dir = project("silent", null);
const { exitCode, out } = await runBeats(dir);
expect(exitCode).toBe(1);
expect(out).toMatch(/No beats detected in assets\/song\.wav/);
expect(exitCode).toBe(0);
expect(JSON.parse(out)).toEqual({
ok: true,
track: "assets/song.wav",
file: null,
count: 0,
bpm: null,
});
expect(existsSync(join(dir, "beats"))).toBe(false);
});
it("answers one ambient file with an empty beat list, for a person and for --json", async () => {
const dir = project("silent-file", null);
const song = join(dir, "assets", "song.wav");
const json = await runBeats(song);
expect(json.exitCode).toBe(0);
expect(JSON.parse(json.out)).toMatchObject({ ok: true, file: song, count: 0, beatTimes: [] });
const person = await runBeats(song, false);
expect(person.exitCode).toBe(0);
expect(person.out).toMatch(/No beats in /);
});
it("refuses a music src that resolves outside the project", async () => {
// An encoded `../` survives URL normalization and decodes to a parent path, so
// without a containment check the command reads ../../secret.wav and writes
+13 -4
View File
@@ -96,9 +96,16 @@ function report(file: string, result: MusicBeatAnalysis, json: boolean): void {
);
}
function answerNoBeats(rel: string, json: boolean): void {
if (json) {
console.log(JSON.stringify({ ok: true, track: rel, file: null, count: 0, bpm: null }, null, 2));
} else {
console.log(c.dim(`No beats in ${rel}; nothing written.`));
}
}
async function analyzeFile(audioPath: string, json: boolean): Promise<void> {
const result = await analyzeMusicFromSignal(await decode(audioPath));
if (result.beatTimes.length === 0) fail(`No beats detected in ${audioPath}.`);
if (json) {
console.log(
JSON.stringify(
@@ -115,6 +122,10 @@ async function analyzeFile(audioPath: string, json: boolean): Promise<void> {
);
return;
}
if (result.beatTimes.length === 0) {
console.log(c.dim(`No beats in ${audioPath}.`));
return;
}
console.log(
c.success(
`✓ ${result.beatTimes.length} beats in ${audioPath} (bpm ${result.bpm ?? "?"}, ${result.bpmConfidence})`,
@@ -153,9 +164,7 @@ export default defineCommand({
const result = await analyzeMusicFromSignal(await decode(audioPath));
// The Studio ignores a 0-beat file (treats it as a stale seed), so don't write one.
if (result.beatTimes.length === 0) {
fail(`No beats detected in ${rel} — nothing written. (Track may be silent/ambient.)`);
}
if (result.beatTimes.length === 0) return answerNoBeats(rel, Boolean(args.json));
const outPath = join(project.dir, "beats", `${rel}.json`);
if (!isSafePath(project.dir, outPath))