mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
fix(python): validate marshal coverage and consolidate pyc tests (#14036)
This commit is contained in:
1 parent
ca26f2ac84
commit
4ff98b84fb
9 files changed
+234
-273
No files matched your search
@@ -66,28 +66,6 @@ const report: PythonPyc = {
|
||||
],
|
||||
};
|
||||
|
||||
it.each([
|
||||
{
|
||||
flags: 1,
|
||||
hash_based: true,
|
||||
source_hash_hex: "",
|
||||
source_mtime: null,
|
||||
source_size: null,
|
||||
},
|
||||
{ flags: 1 },
|
||||
])("refuses inconsistent provider header facts %j", async (header) => {
|
||||
const result = await new PythonPycService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: async () =>
|
||||
ok({ ...report, header: { ...report.header, ...header } }),
|
||||
}).inspect({ path: report.artifact.path });
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisOutputError" },
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
const service = new PythonPycService({
|
||||
@@ -110,25 +88,6 @@ it("rejects a relative path and extra arguments before reading", async () => {
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
|
||||
it("records the selected artifact and the header plus marshal ranges", async () => {
|
||||
const result = await new PythonPycService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => Promise.resolve(ok(report)),
|
||||
}).inspect({ path: report.artifact.path });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value).toMatchObject({
|
||||
confidence: "observed",
|
||||
subject: { identity: { format: "file" } },
|
||||
normalized_result: report,
|
||||
});
|
||||
expect(result.value.locations).toEqual([
|
||||
{ kind: "artifact-path", path: report.artifact.path },
|
||||
{ kind: "file-offset-range", start: 0, end: 16 },
|
||||
{ kind: "file-offset-range", start: 16, end: report.artifact.bytes },
|
||||
]);
|
||||
});
|
||||
|
||||
it("retains completed pyc Evidence and the opaque caller reason on late cancellation", async () => {
|
||||
const controller = new AbortController();
|
||||
const reason = new AnalysisInputError("opaque caller metadata");
|
||||
@@ -176,24 +135,30 @@ it("retains a pre-admission cancellation reason without calling the pyc provider
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
|
||||
it("preserves malformed provider output instead of relabeling it as a late abort", async () => {
|
||||
const controller = new AbortController();
|
||||
const service = new PythonPycService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: async () => {
|
||||
controller.abort(new Error("later caller stop"));
|
||||
return ok({
|
||||
...report,
|
||||
artifact: { ...report.artifact, path: "/different.pyc" },
|
||||
});
|
||||
},
|
||||
});
|
||||
const result = await service.inspect(
|
||||
{ path: report.artifact.path },
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
if (result.ok) throw new Error("Expected output failure");
|
||||
expect(result.error).toBeInstanceOf(AnalysisOutputError);
|
||||
expect(result.error.partialObservation).toBeUndefined();
|
||||
});
|
||||
it.each([
|
||||
[
|
||||
"artifact identity",
|
||||
{ ...report, artifact: { ...report.artifact, path: "/different.pyc" } },
|
||||
],
|
||||
["header facts", { ...report, header: { ...report.header, flags: 1 } }],
|
||||
] as const)(
|
||||
"preserves a provider %s failure instead of relabeling it as a late abort",
|
||||
async (_name, badReport) => {
|
||||
const controller = new AbortController();
|
||||
const service = new PythonPycService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: async () => {
|
||||
controller.abort(new Error("later caller stop"));
|
||||
return ok(badReport);
|
||||
},
|
||||
});
|
||||
const result = await service.inspect(
|
||||
{ path: report.artifact.path },
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
if (result.ok) throw new Error("Expected output failure");
|
||||
expect(result.error).toBeInstanceOf(AnalysisOutputError);
|
||||
expect(result.error.partialObservation).toBeUndefined();
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user