59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
APP_CONTEXT_BUDGET,
|
|
APP_LOCAL_FEATURE_BUDGET,
|
|
CONTEXT_FEATURE_BUDGET,
|
|
SCALE_PROFILES,
|
|
} from "./scale-profile.ts";
|
|
import { createSyntheticTopology } from "./synthetic-topology.ts";
|
|
|
|
describe("scale profiles and synthetic topology", () => {
|
|
it("defines the exact S0-S4 profiles", () => {
|
|
expect(SCALE_PROFILES).toEqual({
|
|
S0: 100,
|
|
S1: 1_000,
|
|
S2: 10_000,
|
|
S3: 100_000,
|
|
S4: 1_000_000,
|
|
});
|
|
});
|
|
|
|
it("grows global topology without growing a selected local app beyond its budgets", () => {
|
|
const small = createSyntheticTopology({ globalFeatures: 100 });
|
|
const huge = createSyntheticTopology({ globalFeatures: 1_000_000 });
|
|
|
|
expect(huge.apps[0]?.contexts.length).toBeLessThanOrEqual(APP_CONTEXT_BUDGET);
|
|
expect(huge.apps[0]?.localFeatureCount).toBeLessThanOrEqual(APP_LOCAL_FEATURE_BUDGET);
|
|
expect(huge.apps[0]?.localFeatureCount).toBe(small.apps[0]?.localFeatureCount);
|
|
});
|
|
|
|
it.each(Object.entries(SCALE_PROFILES))(
|
|
"%s partitions %i features into budget-respecting apps and contexts",
|
|
(_profile, globalFeatures) => {
|
|
const topology = createSyntheticTopology({ globalFeatures });
|
|
expect(topology.appCount * APP_CONTEXT_BUDGET * CONTEXT_FEATURE_BUDGET).toBeGreaterThanOrEqual(
|
|
globalFeatures,
|
|
);
|
|
for (const index of [0, topology.appCount - 1]) {
|
|
const app = topology.apps[index];
|
|
expect(app?.contexts.length).toBeLessThanOrEqual(APP_CONTEXT_BUDGET);
|
|
for (const context of app?.contexts ?? []) {
|
|
expect(context.featureIds.length).toBeLessThanOrEqual(CONTEXT_FEATURE_BUDGET);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
|
|
it("models S4 compactly instead of materializing a million features", () => {
|
|
const before = process.memoryUsage().heapUsed;
|
|
const topology = createSyntheticTopology({ globalFeatures: 1_000_000 });
|
|
const after = process.memoryUsage().heapUsed;
|
|
|
|
expect(topology.appCount).toBe(10_000);
|
|
expect(after - before).toBeLessThan(16 * 1024 * 1024);
|
|
expect(topology.apps[10_000]).toBeUndefined();
|
|
expect(() => topology.app("app-10000")).toThrow(RangeError);
|
|
});
|
|
});
|