refactor(test): keep coverage at behavioral boundaries (#474)

* refactor(test): keep coverage at behavioral boundaries

* fix(ci): restore package workflow temp-root classification
This commit is contained in:
morluto
2026-08-11 18:34:32 +08:00
committed by GitHub
parent d65730c4c2
commit d4dc940bd8
117 changed files with 1519 additions and 2419 deletions
@@ -0,0 +1,99 @@
import { describe, expect, it } from "vitest";
import { ProcessCaptureError } from "../../../src/application/ProcessCaptureError.js";
import { analysisErrorProjectionSchema } from "../../../src/contracts/errorSchemas.js";
import {
ArtifactOperationError,
EvidenceFileError,
HopperRemoteError,
InvestigationWorkspaceError,
UnknownRegistryError,
projectAnalysisError,
type AnalysisError,
} from "../../../src/domain/errors.js";
describe("analysis error projection contract", () => {
it("accepts every closed error-reason variant without exposing diagnostics", () => {
const variants: AnalysisError[] = [
...(
[
"cancelled",
"format",
"integrity",
"limit",
"path",
"policy",
"unavailable",
"io",
] as const
).map(
(reason) => new ArtifactOperationError("inventory_artifact", reason),
),
...(
[
"disabled",
"outside-root",
"not-file",
"too-large",
"exists",
"invalid-json",
"io",
] as const
).map((reason) => new EvidenceFileError("read", reason)),
...(
[
"disabled",
"outside-root",
"not-file",
"too-large",
"invalid-json",
"integrity",
"locked",
"revision-conflict",
"name-conflict",
"io",
] as const
).map((reason) => new InvestigationWorkspaceError("update", reason)),
...(
[
"not-found",
"already-exists",
"revision-conflict",
"invalid-transition",
"integrity",
"limit",
] as const
).map((reason) => new UnknownRegistryError(reason)),
...(
[
"capture_failed",
"cleanup_incomplete",
"permission_required",
"cancelled",
] as const
).map(
(reason) =>
new ProcessCaptureError("SECRET capture diagnostic", { reason }),
),
...(
[
"remote",
"authorization",
"invalid_request",
"bridge_exception",
] as const
).map((diagnostic) => new HopperRemoteError(9, "safe", diagnostic)),
];
expect(variants).toHaveLength(39);
for (const variant of variants) {
const projected = projectAnalysisError(variant);
expect(
analysisErrorProjectionSchema.safeParse(projected),
JSON.stringify({ variant, projected }),
).toMatchObject({ success: true });
expect(projected.code).toMatch(/^[a-z][a-z0-9_]*$/u);
expect(JSON.stringify(projected)).not.toContain("SECRET");
}
});
});
@@ -1,9 +1,6 @@
import { createHash } from "node:crypto";
import { fc, it } from "@fast-check/vitest";
import { describe, expect } from "vitest";
import type { BinaryTarget } from "../../../src/domain/binaryTarget.js";
import {
assessManagedGraphOmissions,
managedGraphEvidenceCoverage,
@@ -16,38 +13,12 @@ import {
} from "../../../src/domain/knownPageCoverage.js";
import { inspectManagedMembersBytes } from "../../../src/dotnet/ManagedMemberInspector.js";
import { inspectManagedNativeBoundariesBytes } from "../../../src/dotnet/ManagedNativeBoundaryInspector.js";
import { buildManagedPeFixture } from "../../fixtures/managedPe.js";
const MEMBER_LIMITS = {
typeOffset: 0,
typeLimit: 100,
methodOffset: 0,
methodLimit: 100,
fieldOffset: 0,
fieldLimit: 100,
memberRefOffset: 0,
memberRefLimit: 100,
edgeOffset: 0,
edgeLimit: 100,
instructionAnchorLimit: 100,
maxMetadataBytes: 1024 * 1024,
maxTableRows: 1_000,
maxHeapItemBytes: 1024 * 1024,
maxMethodBodyBytes: 1024 * 1024,
maxMethodInstructions: 1_000,
};
const BOUNDARY_LIMITS = {
moduleRefOffset: 0,
moduleRefLimit: 100,
importOffset: 0,
importLimit: 100,
implementationOffset: 0,
implementationLimit: 100,
maxMetadataBytes: 1024 * 1024,
maxTableRows: 1_000,
maxHeapItemBytes: 1024 * 1024,
};
import {
buildManagedPeFixture,
managedPeFixtureTarget,
MANAGED_MEMBER_FIXTURE_LIMITS,
MANAGED_NATIVE_BOUNDARY_FIXTURE_LIMITS,
} from "../../../src/dotnet/ManagedPe.fixture.js";
const limitPair = fc
.tuple(fc.integer({ min: 1, max: 12 }), fc.integer({ min: 1, max: 12 }))
@@ -182,25 +153,19 @@ const fixtureBytes = buildManagedPeFixture({
},
readyToRun: true,
});
const fixtureTarget: BinaryTarget = {
path: "/fixture/ManagedCoverage.exe",
sha256: createHash("sha256").update(fixtureBytes).digest("hex"),
kind: "executable",
format: "pe",
architecture: "x86",
availableArchitectures: ["x86"],
executableRole: "application",
managed: true,
};
const fixtureTarget = managedPeFixtureTarget(
fixtureBytes,
"/fixture/ManagedCoverage.exe",
);
const fixtureMembers = inspectManagedMembersBytes(
fixtureBytes,
fixtureTarget,
MEMBER_LIMITS,
MANAGED_MEMBER_FIXTURE_LIMITS,
);
const fixtureBoundaries = inspectManagedNativeBoundariesBytes(
fixtureBytes,
fixtureTarget,
BOUNDARY_LIMITS,
MANAGED_NATIVE_BOUNDARY_FIXTURE_LIMITS,
);
const managedSources = (totals: readonly number[]) => ({