mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-21 02:54:25 +00:00
fix(ci): use native coverage coordinates for repository modules
This commit is contained in:
@@ -4,8 +4,10 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { isInternalThread } from "node:worker_threads";
|
||||
|
||||
const cliEntry = new URL("../../bin/omniroute.mjs", import.meta.url);
|
||||
const cliRoot = fileURLToPath(new URL("../../bin/cli/", import.meta.url));
|
||||
const cliTsxBridge = new URL("native-cli-v8-tsx.mjs", import.meta.url).href;
|
||||
const nativeModuleRoots = ["bin", "scripts"].map((directory) =>
|
||||
fileURLToPath(new URL(`../../${directory}/`, import.meta.url))
|
||||
);
|
||||
// Node loads these modules natively in workers, CLI diagnostics, MCP and catalog checks.
|
||||
const nativeSources = new Set(
|
||||
[
|
||||
@@ -57,7 +59,9 @@ function loadNativeCoverageSource(url, context, nextLoad) {
|
||||
shortCircuit: true,
|
||||
};
|
||||
}
|
||||
if (filename.startsWith(cliRoot) && filename.endsWith(".mjs")) {
|
||||
// tsx rewrites dynamic imports even in JavaScript, giving these Node entry
|
||||
// points different V8 coordinates than their bare CLI or gate invocations.
|
||||
if (filename.endsWith(".mjs") && nativeModuleRoots.some((root) => filename.startsWith(root))) {
|
||||
return { format: "module", source: readFileSync(filename), shortCircuit: true };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,18 +136,31 @@ test("without the preload, tsx and the worker still exhibit distinct layouts", a
|
||||
assert.notEqual(parent.functions[0].ranges[0].endOffset, native.functions[0].ranges[0].endOffset);
|
||||
});
|
||||
|
||||
test("CLI and tray coverage keep the Node layout before and after tsx registration", async (t) => {
|
||||
test("CLI and maintenance scripts keep the Node coverage layout through tsx registration", async (t) => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "native-cli-coverage-"));
|
||||
t.after(() => rm(directory, { recursive: true, force: true }));
|
||||
const entry = new URL("bin/cli/utils/cliToken.mjs", root).href;
|
||||
const aliasResolver = new URL("bin/aliasResolver.mjs", root).href;
|
||||
const translation = new URL("scripts/i18n/run-translation.mjs", root).href;
|
||||
const lifecycle = new URL("scripts/check/check-model-lifecycle.mjs", root).href;
|
||||
const dependency = new URL("bin/cli/data-dir.mjs", root).href;
|
||||
const tray = new URL("bin/cli/runtime/trayRuntime.ts", root).href;
|
||||
const trayEntry = new URL("bin/cli/tray/traySystray.mjs", root).href;
|
||||
const windows = new URL("src/shared/platform/windowsProcess.ts", root).href;
|
||||
const cliTsx = new URL("scripts/ci/native-cli-v8-tsx.mjs", root).href;
|
||||
const query = `${entry}?coverage-fixture=1`;
|
||||
const required = new Set([entry, query, dependency, tray, trayEntry, windows]);
|
||||
const imports = [entry, query, tray, trayEntry]
|
||||
const required = new Set([
|
||||
entry,
|
||||
query,
|
||||
dependency,
|
||||
tray,
|
||||
trayEntry,
|
||||
windows,
|
||||
aliasResolver,
|
||||
translation,
|
||||
lifecycle,
|
||||
]);
|
||||
const imports = [entry, query, tray, trayEntry, aliasResolver, translation, lifecycle]
|
||||
.map((url) => `await import(${JSON.stringify(url)});`)
|
||||
.join("\n");
|
||||
|
||||
@@ -194,6 +207,46 @@ test("CLI and tray coverage keep the Node layout before and after tsx registrati
|
||||
);
|
||||
});
|
||||
|
||||
test("the global-install alias fixtures keep native coverage after late tsx registration", async (t) => {
|
||||
const coverage = await mkdtemp(join(tmpdir(), "late-tsx-alias-coverage-"));
|
||||
t.after(() => rm(coverage, { recursive: true, force: true }));
|
||||
const driver = "tests/unit/cli/alias-resolver-12073.test.ts";
|
||||
const source = new URL("bin/aliasResolver.mjs", root);
|
||||
const sourceLength = (await readFile(source, "utf8")).length;
|
||||
const env = {
|
||||
...process.env,
|
||||
NODE_OPTIONS: `--import=${preload.href}`,
|
||||
NODE_V8_COVERAGE: coverage,
|
||||
OMNIROUTE_CI_SYNC_TSX_CACHE: coverage,
|
||||
};
|
||||
delete env.NODE_TEST_CONTEXT;
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[
|
||||
"--import",
|
||||
"tsx/esm",
|
||||
"--test",
|
||||
"--test-name-pattern",
|
||||
"keeps global-install-style alias imports working|retains module.register",
|
||||
driver,
|
||||
],
|
||||
{ cwd: root, env, stdio: "pipe", timeout: 60_000 }
|
||||
);
|
||||
|
||||
let evaluated = 0;
|
||||
for (const file of await readdir(coverage)) {
|
||||
if (!file.endsWith(".json")) continue;
|
||||
const report = JSON.parse(await readFile(join(coverage, file), "utf8"));
|
||||
const sample = report.result.find(({ url }) => url === source.href);
|
||||
if (!sample || !report.result.some(({ url }) => url.endsWith("/[eval1]"))) continue;
|
||||
evaluated++;
|
||||
assert.equal(Boolean(report["source-map-cache"]?.[source.href]), false, source.href);
|
||||
const [{ startOffset, endOffset }] = sample.functions[0].ranges;
|
||||
assert.deepEqual([startOffset, endOffset], [0, sourceLength]);
|
||||
}
|
||||
assert.equal(evaluated, 2, "both actual late-TSX launchers must emit coverage");
|
||||
});
|
||||
|
||||
test("the CLI doctor and native tray diagnostic share coverage coordinates", async (t) => {
|
||||
const coverage = await mkdtemp(join(tmpdir(), "doctor-native-coverage-"));
|
||||
t.after(() => rm(coverage, { recursive: true, force: true }));
|
||||
|
||||
@@ -13,6 +13,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { parseNodeVersion } from "../../../src/shared/utils/nodeRuntimeSupport.ts";
|
||||
|
||||
import { registerAliasResolver, resolveAlias } from "../../../bin/aliasResolver.mjs";
|
||||
import { nativeCoverageArgs } from "../../_helpers/nativeCoverageArgs.ts";
|
||||
|
||||
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||
const REPO_ROOT = join(__dirname, "..", "..", "..");
|
||||
@@ -24,6 +25,9 @@ const NODE_26_SKIP_REASON =
|
||||
// Child import() specifiers must be real file URLs. A Windows drive letter in
|
||||
// a bare path would otherwise be parsed as a URL scheme.
|
||||
const repoFileUrl = (relPath: string) => pathToFileURL(join(REPO_ROOT, relPath)).href;
|
||||
const coverageTsxImport = nativeCoverageArgs().length
|
||||
? repoFileUrl("scripts/ci/native-cli-v8-tsx.mjs")
|
||||
: undefined;
|
||||
|
||||
function runChild(script: string, cwd = REPO_ROOT) {
|
||||
const result = spawnSync(process.execPath, ["--input-type=module", "-e", script], {
|
||||
@@ -44,7 +48,7 @@ describe("aliasResolver Node 26 registration (#12073)", () => {
|
||||
{ skip: NODE_VERSION.major >= 26 ? false : NODE_26_SKIP_REASON },
|
||||
() => {
|
||||
const script = `
|
||||
await import("tsx/esm");
|
||||
await import(${JSON.stringify(coverageTsxImport ?? "tsx/esm")});
|
||||
const { registerAliasResolver } = await import(${JSON.stringify(repoFileUrl("bin/aliasResolver.mjs"))});
|
||||
const ok = await registerAliasResolver(${JSON.stringify(REPO_ROOT)});
|
||||
if (!ok) { console.error("FAIL: registerAliasResolver returned false"); process.exit(2); }
|
||||
@@ -71,7 +75,7 @@ describe("aliasResolver Node 26 registration (#12073)", () => {
|
||||
const globalInstallCwd = mkdtempSync(join(tmpdir(), "alias-resolver-global-install-"));
|
||||
try {
|
||||
const script = `
|
||||
await import(${JSON.stringify(repoFileUrl("node_modules/tsx/dist/esm/index.mjs"))});
|
||||
await import(${JSON.stringify(coverageTsxImport ?? repoFileUrl("node_modules/tsx/dist/esm/index.mjs"))});
|
||||
const { registerAliasResolver } = await import(${JSON.stringify(repoFileUrl("bin/aliasResolver.mjs"))});
|
||||
const ok = await registerAliasResolver(${JSON.stringify(REPO_ROOT)});
|
||||
if (!ok) { console.error("FAIL: registerAliasResolver returned false"); process.exit(2); }
|
||||
@@ -101,7 +105,7 @@ describe("aliasResolver Node 26 registration (#12073)", () => {
|
||||
|
||||
it("retains module.register() for simulated legacy runtimes", () => {
|
||||
const script = `
|
||||
await import("tsx/esm");
|
||||
await import(${JSON.stringify(coverageTsxImport ?? "tsx/esm")});
|
||||
const { createRequire, syncBuiltinESMExports } = await import("node:module");
|
||||
const require = createRequire(import.meta.url);
|
||||
const cjsModule = require("node:module");
|
||||
|
||||
Reference in New Issue
Block a user