60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import * as barrel from "./index.js";
|
|
|
|
/**
|
|
* Guards the public API surface of the package. The barrel (`index.ts`) is the
|
|
* only entrypoint declared in `package.json#exports`, so a renamed or dropped
|
|
* re-export would silently break every consumer (api / worker / web). These
|
|
* tests assert that each runtime symbol is not merely present but wired to the
|
|
* correct underlying implementation.
|
|
*/
|
|
describe("public API barrel", () => {
|
|
it("re-exports exactly the expected runtime symbols", () => {
|
|
expect(Object.keys(barrel).sort()).toEqual(
|
|
[
|
|
"HISTOGRAM_BUCKETS_SECONDS",
|
|
"createDefaultMetrics",
|
|
"createMetricsRegistry",
|
|
"isMetricsEnabled",
|
|
"redactMetricsToken",
|
|
"validateMetricsTokenAuth",
|
|
].sort(),
|
|
);
|
|
});
|
|
|
|
it("re-exports the shared histogram bucket constant verbatim", () => {
|
|
expect(barrel.HISTOGRAM_BUCKETS_SECONDS).toEqual([
|
|
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10,
|
|
]);
|
|
});
|
|
|
|
it("re-exports a working isMetricsEnabled", () => {
|
|
expect(barrel.isMetricsEnabled({ METRICS_ENABLED: "true" })).toBe(true);
|
|
expect(barrel.isMetricsEnabled({ METRICS_ENABLED: "false" })).toBe(false);
|
|
});
|
|
|
|
it("re-exports a working redactMetricsToken", () => {
|
|
expect(barrel.redactMetricsToken(undefined)).toBe("<unset>");
|
|
expect(barrel.redactMetricsToken("abcdef1234567890abcdef")).toBe("abcd…ef");
|
|
});
|
|
|
|
it("re-exports a working validateMetricsTokenAuth", () => {
|
|
expect(barrel.validateMetricsTokenAuth({ metricsEnabled: false })).toEqual({
|
|
ok: false,
|
|
status: 403,
|
|
code: "metrics_disabled",
|
|
});
|
|
});
|
|
|
|
it("re-exports a registry factory and default-metric factory that compose", async () => {
|
|
const registry = barrel.createMetricsRegistry({
|
|
serviceName: "api",
|
|
collectDefaultProcessMetrics: false,
|
|
});
|
|
const metrics = barrel.createDefaultMetrics(registry);
|
|
metrics.activeTenants.set(3);
|
|
const text = await registry.metrics();
|
|
expect(text).toContain('active_tenants{service="api"} 3');
|
|
});
|
|
});
|