Merge pull request #3343 from code-yeongyu/refactor/ultrawork-cleanup-pass

refactor: trim duplicate logic and dead internal exports
This commit is contained in:
YeonGyu-Kim
2026-04-11 23:12:16 +09:00
committed by GitHub
8 changed files with 80 additions and 73 deletions
+1 -19
View File
@@ -3,6 +3,7 @@ import type {
OpenClawGateway,
OpenClawReplyListenerConfig,
} from "./types"
export { validateGatewayUrl } from "./gateway-url-validation"
const DEFAULT_REPLY_POLL_INTERVAL_MS = 3000
const MIN_REPLY_POLL_INTERVAL_MS = 500
@@ -97,22 +98,3 @@ export function resolveGateway(
return { gatewayName: mapping.gateway, gateway, instruction: mapping.instruction }
}
export function validateGatewayUrl(url: string): boolean {
try {
const parsed = new URL(url)
if (parsed.protocol === "https:") return true
if (
parsed.protocol === "http:" &&
(parsed.hostname === "localhost" ||
parsed.hostname === "127.0.0.1" ||
parsed.hostname === "::1" ||
parsed.hostname === "[::1]")
) {
return true
}
return false
} catch {
return false
}
}
+1 -20
View File
@@ -1,30 +1,11 @@
import { spawn } from "bun"
import { validateGatewayUrl } from "./gateway-url-validation"
import type { OpenClawGateway, WakeResult } from "./types"
const DEFAULT_HTTP_TIMEOUT_MS = 10_000
const DEFAULT_COMMAND_TIMEOUT_MS = 5_000
const MIN_COMMAND_TIMEOUT_MS = 100
const MAX_COMMAND_TIMEOUT_MS = 300_000
const SHELL_METACHAR_RE = /[|&;><`$()]/
export function validateGatewayUrl(url: string): boolean {
try {
const parsed = new URL(url)
if (parsed.protocol === "https:") return true
if (
parsed.protocol === "http:" &&
(parsed.hostname === "localhost" ||
parsed.hostname === "127.0.0.1" ||
parsed.hostname === "::1" ||
parsed.hostname === "[::1]")
) {
return true
}
return false
} catch {
return false
}
}
export function interpolateInstruction(
template: string,
@@ -0,0 +1,34 @@
import { describe, expect, test } from "bun:test"
import { validateGatewayUrl } from "./gateway-url-validation"
describe("validateGatewayUrl", () => {
test("allows https and local http while rejecting remote or invalid urls", () => {
// given representative gateway urls
const httpsRemote = "https://example.com"
const httpRemote = "http://example.com"
const httpLocalhost = "http://localhost:3000"
const httpLoopback = "http://127.0.0.1:3000"
const httpIpv6Loopback = "http://[::1]:3000"
const invalidUrl = "not-a-url"
// when validating each url
const results = {
httpsRemote: validateGatewayUrl(httpsRemote),
httpRemote: validateGatewayUrl(httpRemote),
httpLocalhost: validateGatewayUrl(httpLocalhost),
httpLoopback: validateGatewayUrl(httpLoopback),
httpIpv6Loopback: validateGatewayUrl(httpIpv6Loopback),
invalidUrl: validateGatewayUrl(invalidUrl),
}
// then only https and localhost loopback urls are allowed
expect(results).toEqual({
httpsRemote: true,
httpRemote: false,
httpLocalhost: true,
httpLoopback: true,
httpIpv6Loopback: true,
invalidUrl: false,
})
})
})
+18
View File
@@ -0,0 +1,18 @@
export function validateGatewayUrl(url: string): boolean {
try {
const parsed = new URL(url)
if (parsed.protocol === "https:") return true
if (
parsed.protocol === "http:" &&
(parsed.hostname === "localhost" ||
parsed.hostname === "127.0.0.1" ||
parsed.hostname === "::1" ||
parsed.hostname === "[::1]")
) {
return true
}
return false
} catch {
return false
}
}