mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
test: coverage campaign and mutation testing across five packages (#628)
Coverage 83.6 to 87.36% lines, 81.63 to 84.14% branches. Mutation testing across five packages: image-engine 85, media-engine 92, doc-engine 87, shared+enterprise 86, apps/api security and jobs slice. Runs all five lanes weekly. Fixes the silently-broken mutation CI (babel pin), a redact-pdf envelope-shape test bug, an untested enterprise license valid-signature path, and an audit test that only exercised a hand-copied reproduction. Test and config only, no product code changes beyond the babel pin and one test-only oidc export. Full suite: 16,712 pass, 0 fail.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
ALL_AUDIT_EVENTS,
|
||||
registerAuditEvents,
|
||||
} from "../../../packages/shared/src/audit-events.js";
|
||||
|
||||
// registerAuditEvents appends only events not already present. Pins the
|
||||
// `!includes` dedup guard, the push, and the loop.
|
||||
describe("registerAuditEvents", () => {
|
||||
it("appends a genuinely new event", () => {
|
||||
const novel = "CUSTOM_EVENT_ONE";
|
||||
expect(ALL_AUDIT_EVENTS).not.toContain(novel);
|
||||
registerAuditEvents([novel]);
|
||||
expect(ALL_AUDIT_EVENTS).toContain(novel);
|
||||
});
|
||||
|
||||
it("does not duplicate an already-registered core event (kills the !includes guard)", () => {
|
||||
const before = ALL_AUDIT_EVENTS.filter((e) => e === "LOGIN_SUCCESS").length;
|
||||
registerAuditEvents(["LOGIN_SUCCESS"]);
|
||||
const after = ALL_AUDIT_EVENTS.filter((e) => e === "LOGIN_SUCCESS").length;
|
||||
expect(before).toBe(1);
|
||||
expect(after).toBe(1);
|
||||
});
|
||||
|
||||
it("adds only the new entries from a mixed list, iterating every element", () => {
|
||||
registerAuditEvents(["LOGOUT", "CUSTOM_EVENT_TWO"]);
|
||||
expect(ALL_AUDIT_EVENTS.filter((e) => e === "LOGOUT").length).toBe(1);
|
||||
expect(ALL_AUDIT_EVENTS).toContain("CUSTOM_EVENT_TWO");
|
||||
});
|
||||
|
||||
it("an empty list is a no-op", () => {
|
||||
const len = ALL_AUDIT_EVENTS.length;
|
||||
registerAuditEvents([]);
|
||||
expect(ALL_AUDIT_EVENTS.length).toBe(len);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
CONVERSION_PRESET_BY_ID,
|
||||
expandConversionPresets,
|
||||
} from "../../../packages/shared/src/conversion-presets.js";
|
||||
|
||||
// Targets the expansion logic in expandConversionPresets (L593-L599): the
|
||||
// name/description templates and the executionHint derivation
|
||||
// (base?.executionHint ?? (cfg.modality === "image" ? "fast" : "long")).
|
||||
|
||||
describe("expandConversionPresets name/description templates", () => {
|
||||
it("builds name and description from the preset's from/to for every preset", () => {
|
||||
const tools = expandConversionPresets();
|
||||
expect(tools.length).toBeGreaterThan(0);
|
||||
for (const tool of tools) {
|
||||
const preset = CONVERSION_PRESET_BY_ID[tool.id];
|
||||
expect(preset).toBeDefined();
|
||||
expect(tool.name).toBe(`${preset.from} to ${preset.to}`);
|
||||
expect(tool.description).toBe(`Convert ${preset.from} to ${preset.to}`);
|
||||
expect(tool.route).toBe(`/${preset.id}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("expandConversionPresets executionHint derivation", () => {
|
||||
it("without a base tool: image modality is fast, every other modality is long", () => {
|
||||
const tools = expandConversionPresets();
|
||||
// Prove both arms of the ternary are exercised across the catalog.
|
||||
const image = tools.filter((t) => t.modality === "image");
|
||||
const other = tools.filter((t) => t.modality !== "image");
|
||||
expect(image.length).toBeGreaterThan(0);
|
||||
for (const t of image) expect(t.executionHint).toBe("fast");
|
||||
for (const t of other) expect(t.executionHint).toBe("long");
|
||||
});
|
||||
|
||||
it("with a base tool present, the base's executionHint wins over the modality default", () => {
|
||||
// Give every base an explicit "long" hint; image presets would default to
|
||||
// "fast", so if they come back "long" the base override (the ?? left side)
|
||||
// is what produced it.
|
||||
const bases = new Set(Object.values(CONVERSION_PRESET_BY_ID).map((p) => p.base));
|
||||
const baseTools = [...bases].map((id) => ({ id, executionHint: "long" as const }));
|
||||
const tools = expandConversionPresets(baseTools);
|
||||
const image = tools.filter((t) => t.modality === "image");
|
||||
expect(image.length).toBeGreaterThan(0);
|
||||
for (const t of image) expect(t.executionHint).toBe("long");
|
||||
});
|
||||
|
||||
it("a base tool with a fast hint overrides a non-image modality default of long", () => {
|
||||
const bases = new Set(Object.values(CONVERSION_PRESET_BY_ID).map((p) => p.base));
|
||||
const baseTools = [...bases].map((id) => ({ id, executionHint: "fast" as const }));
|
||||
const tools = expandConversionPresets(baseTools);
|
||||
const other = tools.filter((t) => t.modality !== "image");
|
||||
if (other.length > 0) for (const t of other) expect(t.executionHint).toBe("fast");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getRequiredBundlesForTool } from "../../../packages/shared/src/features.js";
|
||||
import {
|
||||
PIPELINE_TEMPLATES,
|
||||
type PipelineTemplate,
|
||||
templateRequiredBundles,
|
||||
} from "../../../packages/shared/src/pipeline-templates.js";
|
||||
|
||||
// templateRequiredBundles collects the deduped union of the bundles required by
|
||||
// each step's tool. Pins the two loops, the Set-based dedup, and the spread.
|
||||
describe("templateRequiredBundles", () => {
|
||||
it("returns the deduped union of per-step bundles for every prebuilt template", () => {
|
||||
for (const t of PIPELINE_TEMPLATES) {
|
||||
const expected = new Set(t.steps.flatMap((s) => getRequiredBundlesForTool(s.toolId)));
|
||||
const result = templateRequiredBundles(t);
|
||||
expect(new Set(result)).toEqual(expected);
|
||||
expect(result.length).toBe(new Set(result).size); // no duplicates
|
||||
}
|
||||
});
|
||||
|
||||
it("dedupes when the same bundle-requiring tool appears in two steps", () => {
|
||||
const withBundle = PIPELINE_TEMPLATES.flatMap((t) => t.steps.map((s) => s.toolId)).find(
|
||||
(id) => getRequiredBundlesForTool(id).length > 0,
|
||||
);
|
||||
// Every shipped AI-pipeline template should carry at least one bundle tool.
|
||||
expect(withBundle).toBeDefined();
|
||||
const bundles = getRequiredBundlesForTool(withBundle as string);
|
||||
const template: PipelineTemplate = {
|
||||
...PIPELINE_TEMPLATES[0],
|
||||
steps: [
|
||||
{ toolId: withBundle as string, settings: {} },
|
||||
{ toolId: withBundle as string, settings: {} },
|
||||
],
|
||||
};
|
||||
const result = templateRequiredBundles(template);
|
||||
expect(new Set(result)).toEqual(new Set(bundles));
|
||||
expect(result.length).toBe(bundles.length); // two identical steps collapse to one set
|
||||
});
|
||||
|
||||
it("returns an empty array when no step requires a bundle", () => {
|
||||
const plain = PIPELINE_TEMPLATES.flatMap((t) => t.steps.map((s) => s.toolId)).find(
|
||||
(id) => getRequiredBundlesForTool(id).length === 0,
|
||||
);
|
||||
expect(plain).toBeDefined();
|
||||
const template: PipelineTemplate = {
|
||||
...PIPELINE_TEMPLATES[0],
|
||||
steps: [{ toolId: plain as string, settings: {} }],
|
||||
};
|
||||
expect(templateRequiredBundles(template)).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user