chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:39:12 +08:00
commit d8dcd5f6d1
8604 changed files with 2479390 additions and 0 deletions
@@ -0,0 +1,59 @@
import { test, describe, after } from "node:test";
import assert from "node:assert/strict";
// NOTE: importing liveServer.ts triggers the module-level auto-start guard at
// the bottom of the file. isBuildOrTest() short-circuits it because:
// - process.argv for the Node test runner includes "--test"
// - process.env.NODE_ENV is typically "test" in this suite
// Either condition is sufficient — no socket is opened.
const originalEnv = process.env.OMNIROUTE_ENABLE_LIVE_WS;
after(() => {
// Restore original env so other tests in the same process are unaffected.
if (originalEnv === undefined) {
delete process.env.OMNIROUTE_ENABLE_LIVE_WS;
} else {
process.env.OMNIROUTE_ENABLE_LIVE_WS = originalEnv;
}
});
// Dynamically import so we can verify the named export exists.
const { isLiveWsEnabled } = await import("../../../src/server/ws/liveServer.ts");
describe("isLiveWsEnabled — default-ON behavior", () => {
test("unset → true (default ON)", () => {
delete process.env.OMNIROUTE_ENABLE_LIVE_WS;
assert.equal(isLiveWsEnabled(), true);
});
test('"0" → false', () => {
process.env.OMNIROUTE_ENABLE_LIVE_WS = "0";
assert.equal(isLiveWsEnabled(), false);
});
test('"false" → false', () => {
process.env.OMNIROUTE_ENABLE_LIVE_WS = "false";
assert.equal(isLiveWsEnabled(), false);
});
test('"FALSE" → false (case-insensitive)', () => {
process.env.OMNIROUTE_ENABLE_LIVE_WS = "FALSE";
assert.equal(isLiveWsEnabled(), false);
});
test('"1" → true', () => {
process.env.OMNIROUTE_ENABLE_LIVE_WS = "1";
assert.equal(isLiveWsEnabled(), true);
});
test('"true" → true', () => {
process.env.OMNIROUTE_ENABLE_LIVE_WS = "true";
assert.equal(isLiveWsEnabled(), true);
});
test('"TRUE" → true (case-insensitive)', () => {
process.env.OMNIROUTE_ENABLE_LIVE_WS = "TRUE";
assert.equal(isLiveWsEnabled(), true);
});
});
+62
View File
@@ -0,0 +1,62 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { writeFileSync, mkdtempSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { validateBinaryMagic, platformBinaryLabel } from "../../../bin/cli/runtime/magicBytes.mjs";
const dir = mkdtempSync(join(tmpdir(), "magic-test-"));
test("detects ELF", () => {
const p = join(dir, "fake.so");
writeFileSync(p, Buffer.from([0x7f, 0x45, 0x4c, 0x46, 0, 0, 0, 0]));
assert.equal(validateBinaryMagic(p), "elf");
});
test("detects Mach-O 64-bit BE", () => {
const p = join(dir, "fake.dylib");
writeFileSync(p, Buffer.from([0xfe, 0xed, 0xfa, 0xcf, 0, 0, 0, 0]));
assert.equal(validateBinaryMagic(p), "macho");
});
test("detects Mach-O LE", () => {
const p = join(dir, "fake-le.dylib");
writeFileSync(p, Buffer.from([0xcf, 0xfa, 0xed, 0xfe, 0, 0, 0, 0]));
assert.equal(validateBinaryMagic(p), "macho-le");
});
test("detects Mach-O fat binary", () => {
const p = join(dir, "fake.fat");
writeFileSync(p, Buffer.from([0xca, 0xfe, 0xba, 0xbe, 0, 0, 0, 0]));
assert.equal(validateBinaryMagic(p), "macho-fat");
});
test("detects PE (MZ)", () => {
const p = join(dir, "fake.node");
writeFileSync(p, Buffer.from([0x4d, 0x5a, 0, 0, 0, 0, 0, 0]));
assert.equal(validateBinaryMagic(p), "pe");
});
test("returns null for non-binary", () => {
const p = join(dir, "fake.txt");
writeFileSync(p, "hello world", "utf-8");
assert.equal(validateBinaryMagic(p), null);
});
test("returns null for missing file", () => {
assert.equal(validateBinaryMagic(join(dir, "nope.bin")), null);
});
test("returns null for too-short file", () => {
const p = join(dir, "short.bin");
writeFileSync(p, Buffer.from([0x7f, 0x45]));
assert.equal(validateBinaryMagic(p), null);
});
test("platformBinaryLabel matches process.platform", () => {
const expected =
process.platform === "win32" ? "pe" : process.platform === "darwin" ? "macho" : "elf";
assert.equal(platformBinaryLabel(), expected);
});
test.after(() => rmSync(dir, { recursive: true, force: true }));
@@ -0,0 +1,41 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { join } from "node:path";
// Regression guard for upstream PR decolua/9router#1827 (issue #1812):
// better-sqlite3 < 12.10.1 ships no prebuilt binary for Node 26 (ABI 147),
// causing "Could not locate the bindings file" on startup. The pinned runtime
// versions MUST be >= 12.10.1 so omniroute boots on Node 26.x.
const MIN = [12, 10, 1] as const;
function parseSemver(v: string): [number, number, number] {
const m = v.match(/(\d+)\.(\d+)\.(\d+)/);
assert.ok(m, `version "${v}" must contain semver`);
return [Number(m[1]), Number(m[2]), Number(m[3])];
}
function gte(a: readonly [number, number, number], b: readonly [number, number, number]) {
for (let i = 0; i < 3; i++) {
if (a[i] > b[i]) return true;
if (a[i] < b[i]) return false;
}
return true;
}
function readPin(file: string): string {
const src = readFileSync(join(process.cwd(), file), "utf8");
const m = src.match(/BETTER_SQLITE3_VERSION\s*=\s*["'`]([^"'`]+)["'`]/);
assert.ok(m, `BETTER_SQLITE3_VERSION not found in ${file}`);
return m[1];
}
test("bin/cli/runtime/nativeDeps.mjs pins better-sqlite3 >= 12.10.1 (Node 26 prebuilt)", () => {
const pin = readPin("bin/cli/runtime/nativeDeps.mjs");
assert.ok(gte(parseSemver(pin), MIN), `pin "${pin}" must be >= 12.10.1`);
});
test("bin/cli/runtime/sqliteRuntime.mjs pins better-sqlite3 >= 12.10.1 (Node 26 prebuilt)", () => {
const pin = readPin("bin/cli/runtime/sqliteRuntime.mjs");
assert.ok(gte(parseSemver(pin), MIN), `pin "${pin}" must be >= 12.10.1`);
});
+48
View File
@@ -0,0 +1,48 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { existsSync } from "node:fs";
import { join } from "node:path";
import { homedir } from "node:os";
import { loadSqliteRuntime, clearRuntimeCache } from "../../../bin/cli/runtime/sqliteRuntime.mjs";
test("loadSqliteRuntime returns a result with driver and source", async () => {
clearRuntimeCache();
const r = await loadSqliteRuntime();
assert.ok(r, "result is truthy");
assert.ok(typeof r.driver === "object", "driver is object");
assert.ok(typeof r.source === "string", "source is string");
});
test("loaded driver is one of the known kinds", async () => {
clearRuntimeCache();
const r = await loadSqliteRuntime();
assert.ok(
["better-sqlite3", "node-sqlite", "sql-js"].includes(r.driver.kind),
`kind="${r.driver.kind}" must be known`
);
});
test("loadSqliteRuntime caches the result (same object reference)", async () => {
clearRuntimeCache();
const a = await loadSqliteRuntime();
const b = await loadSqliteRuntime();
assert.strictEqual(a, b, "second call returns cached object");
});
test("runtime dir exists after loadSqliteRuntime when runtime source used", async () => {
clearRuntimeCache();
const r = await loadSqliteRuntime();
if (r.source === "runtime-installed-now" || r.source === "runtime") {
const runtimeDir = join(homedir(), ".omniroute", "runtime");
assert.ok(existsSync(runtimeDir), "runtime dir created");
}
});
test("clearRuntimeCache allows fresh resolution", async () => {
clearRuntimeCache();
const first = await loadSqliteRuntime();
clearRuntimeCache();
const second = await loadSqliteRuntime();
// Both should resolve to the same kind, but are different call results
assert.equal(first.driver.kind, second.driver.kind, "same driver kind after cache clear");
});