Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
describe("package exports", () => {
it("every feature module has a subpath export entry", {
timeout: 5000,
}, () => {
const pkg = JSON.parse(
readFileSync(join(__dirname, "..", "package.json"), "utf-8")
);
const keys = Object.keys(pkg.exports);
for (const expected of [
".",
"./source/file-source",
"./sink/file-sink",
"./adapter/server-adapter",
"./fx/plugin-chain",
"./error-codes",
]) {
expect(keys).toContain(expected);
}
});
it("sideEffects is false", { timeout: 5000 }, () => {
const pkg = JSON.parse(
readFileSync(join(__dirname, "..", "package.json"), "utf-8")
);
expect(pkg.sideEffects).toBe(false);
});
it("engines pins node >=22", { timeout: 5000 }, () => {
const pkg = JSON.parse(
readFileSync(join(__dirname, "..", "package.json"), "utf-8")
);
expect(pkg.engines.node).toMatch(/22/);
});
});

View File

@@ -0,0 +1,43 @@
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { WavCodec } from "@suaveplan/audio-codecs";
import {
afterEach,
beforeEach,
describe,
expect,
it,
} from "@suaveplan/testing/runner";
import { FileSinkAdapter, FileSourceAdapter } from "../src/index.js";
describe("integration", () => {
let dir: string;
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), "aes-int-"));
});
afterEach(async () => {
await rm(dir, { recursive: true, force: true });
});
it("load then save round-trips through a real node:fs.mkdtemp tmpdir", {
timeout: 30_000,
}, async () => {
const inPath = join(dir, "in.wav");
const outPath = join(dir, "out.wav");
const wav = await WavCodec.encode([new Float32Array(256)], {
sampleRate: 44_100,
bitDepth: 16,
format: "pcm",
});
await writeFile(inPath, wav);
const source = new FileSourceAdapter();
const sink = new FileSinkAdapter();
const doc = await source.load(inPath);
await sink.save(doc, outPath, "wav");
const back = await source.load(outPath);
expect(back.sourceLength).toBe(doc.sourceLength);
expect(back.channels).toBe(doc.channels);
});
});

View File

@@ -0,0 +1,54 @@
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { WavCodec } from "@suaveplan/audio-codecs";
import {
afterEach,
beforeEach,
describe,
expect,
it,
} from "@suaveplan/testing/runner";
import fc from "fast-check";
import { FileSinkAdapter, FileSourceAdapter } from "../src/index.js";
describe("property: load+save round-trip preserves sample count", () => {
let dir: string;
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), "aes-prop-"));
});
afterEach(async () => {
await rm(dir, { recursive: true, force: true });
});
it("load then save preserves sample count across a real tmpdir round-trip", {
timeout: 30_000,
}, async () => {
await fc.assert(
fc.asyncProperty(
fc.integer({ min: 16, max: 256 }),
async (samples) => {
const inPath = join(dir, `i-${samples}.wav`);
const outPath = join(dir, `o-${samples}.wav`);
const wav = await WavCodec.encode(
[new Float32Array(samples)],
{
sampleRate: 44_100,
bitDepth: 16,
format: "pcm",
}
);
await writeFile(inPath, wav);
const source = new FileSourceAdapter();
const sink = new FileSinkAdapter();
const doc = await source.load(inPath);
await sink.save(doc, outPath, "wav");
const back = await source.load(outPath);
expect(back.sourceLength).toBe(samples);
}
),
{ numRuns: 5 }
);
});
});

View File

@@ -0,0 +1,67 @@
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const ROOT = join(__dirname, "..", "src");
function walkTs(dir: string): string[] {
const out: string[] = [];
for (const name of readdirSync(dir)) {
const full = join(dir, name);
if (statSync(full).isDirectory()) out.push(...walkTs(full));
else if (
full.endsWith(".ts") &&
!full.endsWith(".test.ts") &&
!full.endsWith(".bench.ts")
) {
out.push(full);
}
}
return out;
}
describe("purity", () => {
it("source tree references no browser globals", { timeout: 5000 }, () => {
const banned = ["AudioContext", "AudioBuffer", "AudioWorklet"];
for (const file of walkTs(ROOT)) {
const text = readFileSync(file, "utf-8");
for (const term of banned) {
expect(text.includes(term)).toBe(false);
}
}
});
it("dependency set is limited to the declared workspace deps and zod", {
timeout: 5000,
}, () => {
const pkg = JSON.parse(
readFileSync(join(__dirname, "..", "package.json"), "utf-8")
);
const deps = Object.keys(pkg.dependencies ?? {}).sort();
const allowed = [
"@opentelemetry/api",
"@suaveplan/audio-codecs",
"@suaveplan/audio-core",
"@suaveplan/audio-timeline",
"@suaveplan/audio-transport",
"@suaveplan/error",
"@suaveplan/opentelemetry",
"@suaveplan/streams",
"@suaveplan/types",
"tslib",
"zod",
].sort();
expect(deps).toEqual(allowed);
});
it("importing the package mutates no global state", {
timeout: 5000,
}, async () => {
// Importing twice should not mutate globalThis between calls.
await import("../src/index.js");
const before = Object.keys(globalThis).length;
await import("../src/index.js");
const after = Object.keys(globalThis).length;
expect(after).toBe(before);
});
});