fix(browser): report non-absolute export paths at their input field (#7097)

This commit is contained in:
Saiyam Jain
2026-10-27 19:03:49 +05:30
committed by GitHub
parent 84f62f76e5
commit 097cd2c988
2 changed files with 70 additions and 12 deletions
+13 -9
View File
@@ -85,16 +85,20 @@ export const exportWebScriptsValidated = async (
resources: ArtifactResourceScope,
options: ExecutionOptions = {},
): Promise<Result<Evidence, AnalysisError>> => {
if (!isAbsolute(input.capture_path) || !isAbsolute(input.output_directory))
const invalidPaths = (["capture_path", "output_directory"] as const).filter(
(field) => !isAbsolute(input[field]),
);
if (invalidPaths.length > 0)
return err(
new AnalysisInputError(OPERATION, undefined, [
{
path: [],
reason: "invalid_format",
message:
"capture_path and output_directory must be absolute filesystem paths on this host.",
},
]),
new AnalysisInputError(
OPERATION,
undefined,
invalidPaths.map((field) => ({
path: [field],
reason: "invalid_format" as const,
message: `${field} must be an absolute filesystem path on this host.`,
})),
),
);
try {
if (options.signal?.aborted)
@@ -761,7 +761,9 @@ describe("captured script final commit cancellation", () => {
});
},
);
});
describe("captured script path validation", () => {
it("identifies a missing capture file and rejected host path syntax", async () => {
const { input, resources } = await setup();
const missing = await exportWebScripts(
@@ -784,15 +786,67 @@ describe("captured script final commit cancellation", () => {
],
},
});
const relative = await exportWebScripts(
const relativeCapture = await exportWebScripts(
{
...input,
capture_path: "capture.json",
},
resources,
);
if (relative.ok) throw new Error("Expected host path error");
expect(relative.error._tag).toBe("AnalysisInputError");
if (relativeCapture.ok) throw new Error("Expected host path error");
expect(relativeCapture.error).toMatchObject({
_tag: "AnalysisInputError",
issues: [
{
path: ["capture_path"],
reason: "invalid_format",
message:
"capture_path must be an absolute filesystem path on this host.",
},
],
});
const relativeOutput = await exportWebScripts(
{
...input,
output_directory: "dist",
},
resources,
);
if (relativeOutput.ok) throw new Error("Expected host path error");
expect(relativeOutput.error).toMatchObject({
_tag: "AnalysisInputError",
issues: [
{
path: ["output_directory"],
reason: "invalid_format",
message:
"output_directory must be an absolute filesystem path on this host.",
},
],
});
const bothRelative = await exportWebScripts(
{
capture_path: "capture.json",
output_directory: "dist",
},
resources,
);
if (bothRelative.ok) throw new Error("Expected host path error");
expect(bothRelative.error).toMatchObject({
_tag: "AnalysisInputError",
issues: [
{
path: ["capture_path"],
reason: "invalid_format",
},
{
path: ["output_directory"],
reason: "invalid_format",
},
],
});
});
});