Merge pull request #1775 from pikasTech/fix/1774-nc01-durable-bridge
fix: 修复 NC01 durable bridge ConfigMap 入口判定
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { createHash, createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
||||
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
||||
import { mkdtempSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
||||
import { mkdir, open, readFile, readdir, rename, stat, unlink } from "node:fs/promises";
|
||||
import { createServer } from "node:http";
|
||||
import { tmpdir } from "node:os";
|
||||
@@ -1359,4 +1359,13 @@ function positiveIntegerEnv(name) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) startServer();
|
||||
export function isMainModule(argvPath = process.argv[1], moduleUrl = import.meta.url) {
|
||||
if (!argvPath) return false;
|
||||
try {
|
||||
return pathToFileURL(realpathSync(argvPath)).href === pathToFileURL(realpathSync(new URL(moduleUrl))).href;
|
||||
} catch {
|
||||
return pathToFileURL(argvPath).href === moduleUrl;
|
||||
}
|
||||
}
|
||||
|
||||
if (isMainModule()) startServer();
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { createHash, createHmac } from "node:crypto";
|
||||
import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { createServer } from "node:http";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import test from "node:test";
|
||||
import {
|
||||
createGithubSyncHandler,
|
||||
createDurableInboxStore,
|
||||
createDurableSyncController,
|
||||
createSyncCoordinator,
|
||||
isMainModule,
|
||||
run,
|
||||
runResult,
|
||||
syncRepository,
|
||||
@@ -18,6 +20,22 @@ import {
|
||||
|
||||
const zeroDelay = async () => {};
|
||||
|
||||
test("main module detection follows Kubernetes ConfigMap symlinks", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "gitea-sync-main-"));
|
||||
try {
|
||||
const dataDirectory = join(root, "..data");
|
||||
const source = join(dataDirectory, "server.mjs");
|
||||
const mounted = join(root, "server.mjs");
|
||||
mkdirSync(dataDirectory);
|
||||
writeFileSync(source, "export {};\n", { flag: "wx" });
|
||||
symlinkSync(join("..data", "server.mjs"), mounted);
|
||||
|
||||
assert.equal(isMainModule(mounted, pathToFileURL(source).href), true);
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("HTTP 202 waits for durable acceptance but does not claim refs are committed", async () => {
|
||||
const repo = fakeRepo("one");
|
||||
const logs = [];
|
||||
@@ -689,7 +707,7 @@ test("git subprocesses fail closed before launch when the shared deadline is exh
|
||||
test("async process runner handles spawn errors and kills the whole subprocess group at deadline", async () => {
|
||||
const missing = await runResult(["unidesk-command-that-does-not-exist"], 100);
|
||||
assert.equal(missing.status, null);
|
||||
assert.match(missing.stderr, /ENOENT/);
|
||||
assert.match(missing.stderr, /ENOENT|Executable not found/u);
|
||||
|
||||
const root = mkdtempSync(join(tmpdir(), "unidesk-gitea-process-tree-"));
|
||||
const marker = join(root, "child-survived");
|
||||
|
||||
Reference in New Issue
Block a user