Files
OmniRoute/tests/unit/pack-artifact-policy.test.ts
Diego Rodrigues de Sa e Souza b6c65efd28 fix(build): include webdav-handler.mjs in dist/ bundle (#3687)
server-ws.mjs imports ./webdav-handler.mjs but the assembleStandalone
pipeline did not copy it from scripts/dev/, causing a startup crash on
any fresh install of v3.8.22 (ERR_MODULE_NOT_FOUND).

Fix: add the copy entry to assembleStandalone.mjs, add it to
APP_STAGING_ALLOWED_EXACT_PATHS and PACK_ARTIFACT_REQUIRED_PATHS in
pack-artifact-policy.ts, and add a regression test.

Hotfix validated live on VPS (192.168.0.15): server-ws.mjs resolves the
module and the process starts healthy after the file was deployed.
2026-06-11 22:07:32 -03:00

105 lines
3.5 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
APP_STAGING_ALLOWED_EXACT_PATHS,
APP_STAGING_ALLOWED_PATH_PREFIXES,
PACK_ARTIFACT_ALLOWED_EXACT_PATHS,
PACK_ARTIFACT_ALLOWED_PATH_PREFIXES,
PACK_ARTIFACT_REQUIRED_PATHS,
findMissingArtifactPaths,
findUnexpectedArtifactPaths,
normalizeArtifactPath,
} from "../../scripts/build/pack-artifact-policy.ts";
test("normalizeArtifactPath normalizes slashes and leading relative markers", () => {
assert.equal(
normalizeArtifactPath("./app\\scripts\\ad-hoc\\test.js"),
"app/scripts/ad-hoc/test.js"
);
});
test("findUnexpectedArtifactPaths flags staged app files outside the allowlist", () => {
const unexpectedPaths = findUnexpectedArtifactPaths(
[
"open-sse/services/compression/engines/rtk/filters/generic-output.json",
"open-sse/services/compression/rules/en/filler.json",
"package-lock.json",
"scripts/dev/sync-env.mjs",
"server.js",
],
{
exactPaths: APP_STAGING_ALLOWED_EXACT_PATHS,
prefixPaths: APP_STAGING_ALLOWED_PATH_PREFIXES,
}
);
assert.deepEqual(unexpectedPaths, ["package-lock.json"]);
});
test("findUnexpectedArtifactPaths flags app pack files outside the allowlist", () => {
const unexpectedPaths = findUnexpectedArtifactPaths(
[
"dist/open-sse/services/compression/engines/rtk/filters/generic-output.json",
"dist/open-sse/services/compression/rules/en/filler.json",
"dist/server.js",
"dist/scripts/dev/sync-env.mjs",
"dist/scripts/build/prepublish.mjs",
"docs/extra.md",
],
{
exactPaths: PACK_ARTIFACT_ALLOWED_EXACT_PATHS,
prefixPaths: PACK_ARTIFACT_ALLOWED_PATH_PREFIXES,
}
);
assert.deepEqual(unexpectedPaths, ["dist/scripts/build/prepublish.mjs", "docs/extra.md"]);
});
test("webdav-handler.mjs is allowed in staging dist/ (server-ws.mjs dependency, missed in 3.8.22 build)", () => {
const unexpectedPaths = findUnexpectedArtifactPaths(["webdav-handler.mjs"], {
exactPaths: APP_STAGING_ALLOWED_EXACT_PATHS,
prefixPaths: APP_STAGING_ALLOWED_PATH_PREFIXES,
});
assert.deepEqual(unexpectedPaths, []);
});
test("setupPolyfill.ts is allowed in the tarball (bin/omniroute.mjs imports it at startup)", () => {
const unexpectedPaths = findUnexpectedArtifactPaths(["open-sse/utils/setupPolyfill.ts"], {
exactPaths: PACK_ARTIFACT_ALLOWED_EXACT_PATHS,
prefixPaths: PACK_ARTIFACT_ALLOWED_PATH_PREFIXES,
});
assert.deepEqual(unexpectedPaths, []);
});
test("findMissingArtifactPaths flags missing root runtime files in the tarball", () => {
const missingPaths = findMissingArtifactPaths(
[
"dist/server.js",
"bin/omniroute.mjs",
"package.json",
"scripts/build/postinstall.mjs",
"scripts/build/postinstallSupport.mjs",
],
PACK_ARTIFACT_REQUIRED_PATHS
);
// findMissingArtifactPaths returns the missing required paths sorted
// alphabetically (bin/ < dist/ < scripts/ < src/), minus the paths present
// above (dist/server.js, bin/omniroute.mjs, package.json, the postinstall scripts).
assert.deepEqual(missingPaths, [
"bin/cli/program.mjs",
"bin/mcp-server.mjs",
"bin/nodeRuntimeSupport.mjs",
"dist/open-sse/services/compression/engines/rtk/filters/generic-output.json",
"dist/open-sse/services/compression/rules/en/filler.json",
"dist/peer-stamp.mjs",
"dist/responses-ws-proxy.mjs",
"dist/server-ws.mjs",
"dist/webdav-handler.mjs",
"scripts/build/native-binary-compat.mjs",
"src/shared/utils/nodeRuntimeSupport.ts",
]);
});