Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/instrumentation-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}
}

export async function registerNodejs(): Promise<void> {

Check failure on line 71 in src/instrumentation-node.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 31 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=diegosouzapw_OmniRoute&issues=AZ6fiY6nr9478Y5ebr4b&open=AZ6fiY6nr9478Y5ebr4b&pullRequest=3335
// Initialize proxy fetch patch FIRST (before any HTTP requests)
await import("@omniroute/open-sse/index.ts");
console.log("[STARTUP] Global fetch proxy patch initialized");
Expand Down Expand Up @@ -226,7 +226,7 @@
await bootstrapEmbeddedServices();
console.log("[STARTUP] Embedded services bootstrap complete");
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);

Check warning on line 229 in src/instrumentation-node.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'err' will use Object's default stringification format ('[object Object]') when stringified.

See more on https://sonarcloud.io/project/issues?id=diegosouzapw_OmniRoute&issues=AZ6fiY6nr9478Y5ebr4c&open=AZ6fiY6nr9478Y5ebr4c&pullRequest=3335
console.warn("[STARTUP] Embedded services bootstrap failed (non-fatal):", msg);
}

Expand All @@ -234,15 +234,17 @@
const { initEmbedWsProxy } = await import("@/lib/services/embedWsProxy");
initEmbedWsProxy();
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);

Check warning on line 237 in src/instrumentation-node.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'err' will use Object's default stringification format ('[object Object]') when stringified.

See more on https://sonarcloud.io/project/issues?id=diegosouzapw_OmniRoute&issues=AZ6fiY6nr9478Y5ebr4d&open=AZ6fiY6nr9478Y5ebr4d&pullRequest=3335
console.warn("[STARTUP] Embed WS proxy failed to start (non-fatal):", msg);
}

try {
const { autoRefreshDaemon } = await import("@/open-sse/services/autoRefreshDaemon");
const { autoRefreshDaemon } = await import(
"@omniroute/open-sse/services/autoRefreshDaemon"
);
autoRefreshDaemon.start();
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);

Check warning on line 247 in src/instrumentation-node.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'err' will use Object's default stringification format ('[object Object]') when stringified.

See more on https://sonarcloud.io/project/issues?id=diegosouzapw_OmniRoute&issues=AZ6fiY6nr9478Y5ebr4e&open=AZ6fiY6nr9478Y5ebr4e&pullRequest=3335
console.warn("[STARTUP] Auto-refresh daemon failed to start (non-fatal):", msg);
}
}
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/no-src-open-sse-alias.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Regression guard (#3292 / v3.8.13 Electron release fragment).
*
* `@/*` maps to `src/*`, but the streaming engine lives in the `open-sse/`
* workspace (alias `@omniroute/open-sse/*`). So an import of `@/open-sse/...`
* resolves to the non-existent `src/open-sse/...` and throws
* "Cannot find module '@/open-sse/...'" at runtime in the built standalone.
*
* This bit the #3292 auto-refresh daemon: `instrumentation-node.ts` did
* `await import("@/open-sse/services/autoRefreshDaemon")`. It was caught by a
* try/catch (non-fatal), so typecheck and the dev server stayed green, but the
* packaged Electron app's strict startup-log smoke test failed on the
* "Cannot find module" line. This test fails fast on any such alias.
*/

import test from "node:test";
import assert from "node:assert/strict";
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";

const srcRoot = join(import.meta.dirname, "../../src");

function walk(dir: string): string[] {
const out: string[] = [];
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
if (statSync(full).isDirectory()) {
out.push(...walk(full));
} else if (/\.(ts|tsx|js|mjs)$/.test(entry)) {
out.push(full);
}
}
return out;
}

test("src/ never imports the open-sse workspace via the @/ alias (use @omniroute/open-sse)", () => {
const offenders: string[] = [];
for (const file of walk(srcRoot)) {
const src = readFileSync(file, "utf8");
// matches from "@/open-sse/... and import("@/open-sse/...
if (/["'`]@\/open-sse\//.test(src)) {
const line = src.split("\n").findIndex((l) => /["'`]@\/open-sse\//.test(l)) + 1;
offenders.push(`${file.replace(srcRoot, "src")}:${line}`);
}
Comment on lines +41 to +44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation only reports the first offending line per file because of findIndex. If a file contains multiple invalid imports, the developer will have to fix them one by one, running the tests repeatedly.

We can optimize this to scan the file once and report all offending lines at once.

    const lines = src.split("\n");
    for (let i = 0; i < lines.length; i++) {
      if (/["\x27\x60]@\/open-sse\//.test(lines[i])) {
        offenders.push(file.replace(srcRoot, "src") + ":" + (i + 1));
      }
    }

}
assert.deepEqual(
offenders,
[],
`@/open-sse/* resolves to the non-existent src/open-sse/* and throws "Cannot find module" at runtime. Use @omniroute/open-sse/* instead. Offenders:\n${offenders.join("\n")}`
);
});