mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-16 20:02:45 +03:00
* docs: bring the provider count to the live 358 across the reference, diagrams and llm.txt mirrors * chore(skills): regenerate the cli-tunnel SKILL.md for the tunnel create positional * test: clear the ESLint errors in the volcengine upsert and resource-pressure tests * test(autoCombo): complete the mode-pack ProviderCandidate fixtures for the open-sse typecheck * fix(ci): allow the opencode-plugin-v2 workspace package in the pack artifact policy * docs: list the WAL, vacuum, sql.js and pressure self-restart env vars in .env.example * refactor(db): move the synced-model provider purge into its persistence module to break the models/providers cycle * test(memory): use a plain label for the rerank loopback key fixture so gitleaks stays at zero * chore(ci): register the eleven covering unit tests in stryker tap.testFiles * test(grok-cli): run the reset-credit tests on a fixture clock inside the captured token window * test(combo): seed real provider connections for the reset-aware strategy tests * fix(db): keep operator custom models out of the listing-only synced catalog reader * fix(i18n): translate the new settings and combo keys for vi and pt-BR and restore the zh-TW glossary term * fix(sse): carry the upstream error code and type through the provider execution pipeline * test(sse): re-point the chatCore and combo source guards at the split modules and refresh the translate-path golden * fix(oauth): keep the server-only OAuth constants out of the provider detail client bundle * test: align the sql.js, webpack, injection-scan and error-boundary guards with their merged contracts * docs(changelog): record the v3.8.51 base-red sweep * fix(sse): anchor the glued-prefix sk- credential pattern so error redaction scans in linear time * docs(changelog): note the linear credential scan in the base-red sweep --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
145 lines
4.6 KiB
TypeScript
145 lines
4.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import { createRequire } from "node:module";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
import { ModuleKind, ScriptTarget, transpileModule } from "typescript";
|
|
|
|
interface WebpackStats {
|
|
hasErrors(): boolean;
|
|
toJson(options: Record<string, boolean>): {
|
|
errors?: unknown[];
|
|
warnings?: unknown[];
|
|
};
|
|
}
|
|
|
|
interface WebpackCompiler {
|
|
run(callback: (error?: Error | null, stats?: WebpackStats) => void): void;
|
|
close(callback: (error?: Error | null) => void): void;
|
|
}
|
|
|
|
type WebpackFactory = (config: Record<string, unknown>) => WebpackCompiler;
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const { webpack } = require("next/dist/compiled/webpack/webpack") as {
|
|
webpack: WebpackFactory;
|
|
};
|
|
|
|
function renderIssue(issue: unknown): string {
|
|
if (typeof issue === "string") return issue;
|
|
if (issue && typeof issue === "object" && "message" in issue) {
|
|
return String((issue as { message: unknown }).message);
|
|
}
|
|
return JSON.stringify(issue);
|
|
}
|
|
|
|
async function compileRuntimeRequireModules(): Promise<string[]> {
|
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-webpack-create-require-"));
|
|
const sourcePaths = [
|
|
"src/lib/db/adapters/runtimeRequire.ts",
|
|
"src/lib/machineToken.ts",
|
|
"open-sse/services/browserPool.ts",
|
|
"open-sse/utils/tlsClient.ts",
|
|
] as const;
|
|
const entries: Record<string, string> = {};
|
|
|
|
try {
|
|
for (const sourcePath of sourcePaths) {
|
|
const source = fs.readFileSync(path.resolve(sourcePath), "utf8");
|
|
const output = transpileModule(source, {
|
|
compilerOptions: {
|
|
module: ModuleKind.ESNext,
|
|
target: ScriptTarget.ES2022,
|
|
},
|
|
fileName: sourcePath,
|
|
}).outputText;
|
|
const entryName = path.basename(sourcePath, ".ts");
|
|
// Next's server compilation feeds SWC output through javascript/auto.
|
|
// A .mjs fixture would take Webpack's javascript/esm parser path and miss
|
|
// the createRequire warning emitted by the production build.
|
|
const entryPath = path.join(tempDir, `${entryName}.js`);
|
|
fs.writeFileSync(entryPath, output, "utf8");
|
|
entries[entryName] = entryPath;
|
|
}
|
|
|
|
const compiler = webpack({
|
|
devtool: false,
|
|
entry: entries,
|
|
externals: [
|
|
"../../src/lib/db/proxies",
|
|
"@/shared/utils/runtimeTimeouts",
|
|
"better-sqlite3",
|
|
"bun:sqlite",
|
|
"sql.js",
|
|
"sqlite-vec",
|
|
"playwright",
|
|
"wreq-js",
|
|
// browserPool.ts imports `./obscura.ts`. The isolated webpack compile
|
|
// has no repo tree, so treat the sibling as external instead of
|
|
// erroring "Can't resolve './obscura.ts'".
|
|
"./obscura.ts",
|
|
"./tlsFirstByteWatchdog.ts",
|
|
],
|
|
externalsPresets: { node: true },
|
|
mode: "development",
|
|
module: {
|
|
parser: {
|
|
javascript: {
|
|
createRequire: true,
|
|
},
|
|
},
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
type: "javascript/auto",
|
|
},
|
|
],
|
|
},
|
|
output: {
|
|
filename: "[name].js",
|
|
path: path.join(tempDir, "dist"),
|
|
},
|
|
target: "node",
|
|
});
|
|
|
|
const stats = await new Promise<WebpackStats>((resolve, reject) => {
|
|
compiler.run((error, result) => {
|
|
if (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
if (!result) {
|
|
reject(new Error("Webpack completed without stats"));
|
|
return;
|
|
}
|
|
resolve(result);
|
|
});
|
|
});
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
compiler.close((error) => (error ? reject(error) : resolve()));
|
|
});
|
|
|
|
const report = stats.toJson({ all: false, errors: true, warnings: true });
|
|
assert.equal(stats.hasErrors(), false, (report.errors ?? []).map(renderIssue).join("\n"));
|
|
return (report.warnings ?? []).map(renderIssue);
|
|
} finally {
|
|
fs.rmSync(tempDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
}
|
|
}
|
|
|
|
test("Webpack does not warn while parsing optional runtime modules", async () => {
|
|
const warnings = await compileRuntimeRequireModules();
|
|
const runtimeModuleWarnings = warnings.filter(
|
|
(warning) =>
|
|
warning.includes("module.createRequire failed parsing argument") ||
|
|
warning.includes("Critical dependency: the request of a dependency is an expression") ||
|
|
warning.includes(
|
|
"Critical dependency: require function is used in a way in which dependencies cannot be statically extracted"
|
|
)
|
|
);
|
|
|
|
assert.deepEqual(runtimeModuleWarnings, []);
|
|
});
|