整体优化

This commit is contained in:
imengying committed 2026-08-18 21:10:44 +08:00
1 parent 467961eedf
commit e153d0ad10
30 files changed
+554 -317

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
root_dir=$(CDPATH= cd -- "$script_dir/.." && pwd)
NODEFLARE_VERSION=$(sh "$script_dir/resolve-version.sh")
VITE_NODEFLARE_VERSION=$NODEFLARE_VERSION
export NODEFLARE_VERSION VITE_NODEFLARE_VERSION
export VITE_NODEFLARE_VERSION
cd "$root_dir"
bun run --cwd frontend build
+1 -2
View File
@@ -4,8 +4,7 @@ set -eu
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
root_dir=$(CDPATH= cd -- "$script_dir/.." && pwd)
NODEFLARE_VERSION=$(sh "$script_dir/resolve-version.sh")
VITE_NODEFLARE_VERSION=$NODEFLARE_VERSION
export NODEFLARE_VERSION VITE_NODEFLARE_VERSION
export NODEFLARE_VERSION
cd "$root_dir"
current_build_key=$(sh scripts/build-key.sh worker 2>/dev/null || true)
+11
View File
@@ -11,6 +11,17 @@ fi
if [ -z "$raw" ]; then
raw=$(git -C "$root_dir" describe --tags --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' 2>/dev/null || true)
fi
if [ -z "$raw" ]; then
remote_version=$(
git -C "$root_dir" ls-remote --tags --refs origin \
'refs/tags/v[0-9]*.[0-9]*.[0-9]*' 2>/dev/null |
awk '{ sub(/^refs\/tags\//, "", $2); print $2 }' |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
sort -V |
tail -n 1
) || remote_version=
raw=$remote_version
fi
if [ -z "$raw" ]; then
raw=$(sed -n 's/^[[:space:]]*"version": "\([^"]*\)",*$/\1/p' "$root_dir/package.json" | sed -n '1p')
fi
+2
View File
@@ -109,6 +109,8 @@ server_json=$(request -H "Authorization: Bearer $admin_token" \
"$MONITOR_BASE_URL/api/admin/servers")
server_id=$(printf '%s' "$server_json" | jq -er '.id')
agent_token=$(printf '%s' "$server_json" | jq -er '.agent_token')
MONITOR_BASE_URL="$MONITOR_BASE_URL" MONITOR_ADMIN_TOKEN="$admin_token" \
MONITOR_AGENT_TOKEN="$agent_token" node scripts/websocket-smoke.mjs
token_without_admin_status=$(monitor_curl --silent --output /dev/null --write-out '%{http_code}' \
"$MONITOR_BASE_URL/api/admin/servers/$server_id/token")
[ "$token_without_admin_status" = "401" ]
+82
View File
@@ -0,0 +1,82 @@
import WebSocket from "ws";
const baseUrl = process.env.MONITOR_BASE_URL;
const adminToken = process.env.MONITOR_ADMIN_TOKEN;
const agentToken = process.env.MONITOR_AGENT_TOKEN;
if (!baseUrl || !adminToken || !agentToken) {
throw new Error("MONITOR_BASE_URL, MONITOR_ADMIN_TOKEN and MONITOR_AGENT_TOKEN are required");
}
function websocketUrl(path) {
const url = new URL(path, baseUrl);
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
return url.toString();
}
function openSocket(path, token) {
return new Promise((resolve, reject) => {
const socket = new WebSocket(websocketUrl(path), {
headers: { Authorization: `Bearer ${token}` },
});
const timer = setTimeout(() => {
socket.terminate();
reject(new Error(`${path} WebSocket handshake timed out`));
}, 5_000);
socket.once("open", () => {
clearTimeout(timer);
resolve(socket);
});
socket.once("unexpected-response", (_request, response) => {
clearTimeout(timer);
reject(new Error(`${path} WebSocket returned HTTP ${response.statusCode}`));
});
socket.once("error", (error) => {
clearTimeout(timer);
reject(error);
});
});
}
function waitForMessage(socket, expected) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => reject(new Error(`WebSocket did not receive ${expected}`)), 5_000);
socket.once("message", (data) => {
clearTimeout(timer);
const message = data.toString();
if (message !== expected) reject(new Error(`Expected ${expected}, received ${message}`));
else resolve();
});
socket.once("error", (error) => {
clearTimeout(timer);
reject(error);
});
});
}
function closeSocket(socket) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
socket.terminate();
reject(new Error("WebSocket close timed out"));
}, 5_000);
socket.once("close", () => {
clearTimeout(timer);
resolve();
});
socket.once("error", (error) => {
clearTimeout(timer);
reject(error);
});
socket.close();
});
}
const dashboard = await openSocket("/api/ws", adminToken);
const pong = waitForMessage(dashboard, "pong");
dashboard.send("ping");
await pong;
await closeSocket(dashboard);
const agent = await openSocket("/api/agent/live", agentToken);
await closeSocket(agent);