Headers: - Every JavaScript file (sources, front, scripts, tests) starts with a /** @file … */ header, in the three levels used by sokko-g: a short description for simple files; Utilisé par / Attention / @see for shared modules; a full header (context, entry points, callers, dependencies, pitfalls) for index.js, the music queue, the web server, the storage manager and the jukebox page script. - No @author, @version or @since: git already knows. - test/fileHeaders.test.js fails `npm run check` when a header is missing or a central file's header is incomplete. Stylesheet (no visual change, checked by comparing every element's computed styles in Chromium at 1280, 800 and 400 px, hover included): - Role header and section comments. - Transparent shades derive from the colour variables with color-mix() instead of copied rgba() values; new tokens for repeated values (text, text on accent, accent gradient, white veils, shadow). - Native nesting for buttons, the live indicator, upload rows and home cards; drop the unused .hero__visual--large and redundant rules. - Utility classes move to the end so they win over components. The library list's u-mt-1, which never applied (.list reset it), is removed to keep the layout as it was. Docs: CONTRIBUTING.md describes the language, header and stylesheet conventions; CLAUDE.md points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
4.1 KiB
JavaScript
121 lines
4.1 KiB
JavaScript
/**
|
|
* @file Vérifie la bibliothèque dans un dossier temporaire : chemins portables, migration de l'ancien
|
|
* fichier et complément des durées manquantes.
|
|
*/
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
test("the library persists portable entries and restores absolute runtime paths", async () => {
|
|
const originalDirectory = process.cwd();
|
|
const temporaryDirectory = fs.mkdtempSync(
|
|
path.join(os.tmpdir(), "palico-storage-")
|
|
);
|
|
|
|
try {
|
|
process.chdir(temporaryDirectory);
|
|
const storage = await import(
|
|
`../src/web/storage/storageManager.js?test=${Date.now()}`
|
|
);
|
|
storage.ensureStorageLayout();
|
|
|
|
const uploadedPath = path.join(storage.TEMP_DIR, "upload");
|
|
fs.writeFileSync(uploadedPath, "fake audio content");
|
|
const track = storage.registerUploadedFile(
|
|
{
|
|
path: uploadedPath,
|
|
originalname: "sample.mp3",
|
|
size: 18,
|
|
mimetype: "audio/mpeg",
|
|
},
|
|
{ permanent: true, uploader: "test", title: "Sample" }
|
|
);
|
|
|
|
const persisted = JSON.parse(
|
|
fs.readFileSync(
|
|
path.join(temporaryDirectory, "storage/runtime/library.json"),
|
|
"utf8"
|
|
)
|
|
);
|
|
assert.equal(persisted.length, 1);
|
|
assert.equal("path" in persisted[0], false);
|
|
|
|
const restored = storage.findPermanentTrack(track.libraryTrackId);
|
|
assert.equal(path.dirname(restored.path), storage.PERMANENT_DIR);
|
|
assert.equal(fs.existsSync(restored.path), true);
|
|
} finally {
|
|
process.chdir(originalDirectory);
|
|
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("legacy library entries migrate without their absolute paths", async () => {
|
|
const originalDirectory = process.cwd();
|
|
const temporaryDirectory = fs.mkdtempSync(
|
|
path.join(os.tmpdir(), "palico-migration-")
|
|
);
|
|
|
|
try {
|
|
process.chdir(temporaryDirectory);
|
|
fs.mkdirSync("storage", { recursive: true });
|
|
fs.writeFileSync(
|
|
"storage/library.json",
|
|
JSON.stringify([
|
|
{
|
|
id: "legacy",
|
|
storedName: "legacy.mp3",
|
|
path: "/old/server/storage/permanent/legacy.mp3",
|
|
},
|
|
])
|
|
);
|
|
|
|
const storage = await import(
|
|
`../src/web/storage/storageManager.js?migration=${Date.now()}`
|
|
);
|
|
storage.ensureStorageLayout();
|
|
|
|
const migrated = JSON.parse(
|
|
fs.readFileSync("storage/runtime/library.json", "utf8")
|
|
);
|
|
assert.deepEqual(migrated, [{ id: "legacy", storedName: "legacy.mp3" }]);
|
|
} finally {
|
|
process.chdir(originalDirectory);
|
|
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("library metadata backfill fills the missing durations", async () => {
|
|
const originalDirectory = process.cwd();
|
|
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "palico-storage-"));
|
|
|
|
try {
|
|
process.chdir(temporaryDirectory);
|
|
const storage = await import(`../src/web/storage/storageManager.js?backfill=${Date.now()}`);
|
|
storage.ensureStorageLayout();
|
|
const uploadedPath = path.join(storage.TEMP_DIR, "upload");
|
|
fs.writeFileSync(uploadedPath, "fake audio content");
|
|
storage.registerUploadedFile(
|
|
{ path: uploadedPath, originalname: "old.mp3", size: 18, mimetype: "audio/mpeg" },
|
|
{ permanent: true, uploader: "test", title: "Old" }
|
|
);
|
|
|
|
// libraryMetadata.js importe storageManager.js sans paramètre : on passe par la même
|
|
// instance de module que lui, avec le répertoire de travail temporaire.
|
|
const { backfillLibraryMetadata } = await import("../src/web/storage/libraryMetadata.js");
|
|
const shared = await import("../src/web/storage/storageManager.js");
|
|
shared.ensureStorageLayout();
|
|
const updated = await backfillLibraryMetadata({
|
|
probe: async () => ({ duration: 42, artist: "Palico", title: null }),
|
|
});
|
|
|
|
assert.equal(updated.length, 1);
|
|
assert.equal(shared.getPermanentLibrary()[0].duration, 42);
|
|
assert.equal(shared.getPermanentLibrary()[0].artist, "Palico");
|
|
} finally {
|
|
process.chdir(originalDirectory);
|
|
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
}
|
|
});
|