mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-11 14:50:02 +00:00
fix(media-use): clean failed asset reservations (#2627)
* fix(media-use): clean failed asset reservations * test(media-use): pin installer guidance exactly
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import { mkdtempSync, rmSync, readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs";
|
||||
import {
|
||||
mkdtempSync,
|
||||
rmSync,
|
||||
readFileSync,
|
||||
writeFileSync,
|
||||
mkdirSync,
|
||||
existsSync,
|
||||
readdirSync,
|
||||
} from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import {
|
||||
@@ -9,6 +17,7 @@ import {
|
||||
findByEntity,
|
||||
nextId,
|
||||
allocateId,
|
||||
withReservedFileSync,
|
||||
normalizePrompt,
|
||||
manifestPath,
|
||||
mediaDir,
|
||||
@@ -164,6 +173,38 @@ function runTests() {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("failed reservation rollback preserves another completed reservation", () => {
|
||||
setup();
|
||||
const kept = withReservedFileSync(tmp, "bgm", ".wav", (reservation) => {
|
||||
writeFileSync(reservation.fullPath, "completed asset");
|
||||
return reservation;
|
||||
});
|
||||
|
||||
assert.throws(
|
||||
() =>
|
||||
withReservedFileSync(tmp, "bgm", ".wav", () => {
|
||||
throw new Error("populate failed");
|
||||
}),
|
||||
/populate failed/,
|
||||
);
|
||||
|
||||
assert.equal(kept.id, "bgm_001");
|
||||
assert.equal(readFileSync(kept.fullPath, "utf8"), "completed asset");
|
||||
assert.deepStrictEqual(readdirSync(typeDirPath(tmp, "bgm")), ["bgm_001.wav"]);
|
||||
assert.equal(allocateId(tmp, "bgm", ".wav").id, "bgm_002");
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("empty reservation result releases the placeholder", () => {
|
||||
setup();
|
||||
assert.equal(
|
||||
withReservedFileSync(tmp, "image", ".jpg", () => null),
|
||||
null,
|
||||
);
|
||||
assert.deepStrictEqual(readdirSync(typeDirPath(tmp, "image")), []);
|
||||
cleanup();
|
||||
});
|
||||
|
||||
test("findByEntity matches case-insensitively", () => {
|
||||
setup();
|
||||
appendRecord(tmp, makeRecord({ entity: "GitHub", type: "icon" }));
|
||||
|
||||
Reference in New Issue
Block a user