Fix local run freshness and plugin asset handling

This commit is contained in:
npc0-hue
2026-08-22 19:45:00 +08:00
parent bb5e48b29c
commit ebd616c549
23 changed files with 312 additions and 58 deletions
+1 -1
View File
@@ -9,6 +9,6 @@ Use these root-level commands for day-to-day work:
- `scripts/dev-reset.sh`: stop the stack and delete only the safe local debug data root.
- `scripts/browser-acceptance.sh`: run the full self-starting browser acceptance suite.
- `scripts/check-structure.sh`: verify required repository structure.
- `scripts/check-all.sh`: run structure, backend, frontend, and plugin checks.
- `scripts/check-all.sh`: run structure, backend, frontend, plugin checks, and the independent Run checkout tests when `RUN_SOURCE_DIR` or `run/` is available.
Implementation details for the managed local stack live under `scripts/local-debug/`. Prefer the root commands above instead of calling those internals directly.
+7
View File
@@ -2,6 +2,7 @@
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
RUN_SOURCE_DIR="${RUN_SOURCE_DIR:-${RUN_REPO_DIR:-$ROOT_DIR/run}}"
ensure_node_deps() {
local dir="$1"
@@ -14,6 +15,12 @@ ensure_node_deps() {
(cd "$ROOT_DIR/platform" && go test ./...)
if [[ -d "$RUN_SOURCE_DIR/.git" ]]; then
(cd "$RUN_SOURCE_DIR" && go test ./...)
else
printf 'independent run checkout not found at %s; skipping run checks\n' "$RUN_SOURCE_DIR"
fi
ensure_node_deps "$ROOT_DIR/platform_web"
(cd "$ROOT_DIR/platform_web" && npm run typecheck && npm run test && npm run build)
+32 -5
View File
@@ -378,6 +378,23 @@ create_server_workflow() {
exit 1
}
create_server_instance() {
local label="$1"
local server_id="$2"
local request_file="$3"
local response_file="$4"
if json_post "$API_URL/server-instances" "$request_file" "$response_file" "${AUTH_HEADER[@]}"; then
return 0
fi
if [[ -s "$response_file" ]] && response_code_is_duplicate "$response_file"; then
json_get "$API_URL/server-instances/$server_id" "$response_file" "${AUTH_HEADER[@]}"
return 0
fi
printf '%s server creation failed; platform response:\n' "$label" >&2
sed -n '1,160p' "$response_file" >&2
exit 1
}
require_file_contains() {
local file="$1"
local pattern="$2"
@@ -970,9 +987,14 @@ function readAssetFiles(manifest) {
return (manifest.assetFiles ?? []).map((file) => ({
path: file.path,
mode: file.mode,
content: fs.readFileSync(path.join(manifestDir, file.path), "utf8")
...readAssetFileContent(path.join(manifestDir, file.path), file.path)
}));
}
function readAssetFileContent(assetPath, logicalPath) {
const body = fs.readFileSync(assetPath);
if (/\.(?:json|cmd|sh|sql|txt|ya?ml)$/i.test(logicalPath)) return { content: body.toString("utf8") };
return { content: body.toString("base64"), encoding: "base64" };
}
const manifest = {
id: source.id,
name: source.name,
@@ -1046,9 +1068,14 @@ function readAssetFiles(manifest) {
return (manifest.assetFiles ?? []).map((file) => ({
path: file.path,
mode: file.mode,
content: fs.readFileSync(path.join(manifestDir, file.path), "utf8")
...readAssetFileContent(path.join(manifestDir, file.path), file.path)
}));
}
function readAssetFileContent(assetPath, logicalPath) {
const body = fs.readFileSync(assetPath);
if (/\.(?:json|cmd|sh|sql|txt|ya?ml)$/i.test(logicalPath)) return { content: body.toString("utf8") };
return { content: body.toString("base64"), encoding: "base64" };
}
const localRunCapabilities = [
"process.install",
"process.start",
@@ -1149,8 +1176,8 @@ cat >"$WORK_DIR/create-log-session-server.request.json" <<JSON
{
"id": "$LOG_SESSION_SERVER_ID",
"pluginId": "game.example",
"name": "Current Log Session Smoke $SMOKE_INVOCATION_ID",
"idempotencyKey": "local-debug-log-session-create-$SMOKE_INVOCATION_ID"
"runEndpointId": "$RUN_ENDPOINT_ID",
"name": "Current Log Session Smoke $SMOKE_INVOCATION_ID"
}
JSON
@@ -1224,7 +1251,7 @@ create_server_workflow "dev" "$SERVER_LOCAL_ID" "$WORK_DIR/create-server.request
reject_forbidden_fragments "$WORK_DIR/create-server.response.json"
printf 'creating current supervised log session fixture server\n'
create_server_workflow "log session fixture" "$LOG_SESSION_SERVER_ID" "$WORK_DIR/create-log-session-server.request.json" "$WORK_DIR/create-log-session-server.response.json"
create_server_instance "log session fixture" "$LOG_SESSION_SERVER_ID" "$WORK_DIR/create-log-session-server.request.json" "$WORK_DIR/create-log-session-server.response.json"
reject_forbidden_fragments "$WORK_DIR/create-log-session-server.response.json"
printf 'creating SCUM server lifecycle workflows through platform API\n'
+87 -5
View File
@@ -60,6 +60,39 @@ wait_for_pid_exit() {
return 1
}
hash_stream() {
shasum -a 256 | awk '{print $1}'
}
tracked_tree_fingerprint() {
local repo_dir="$1"
shift
(
cd "$repo_dir"
{
git ls-files -z -- "$@"
git ls-files -z --others --exclude-standard -- "$@"
} | sort -z | while IFS= read -r -d '' file; do
[[ -f "$file" ]] || continue
shasum -a 256 "$file"
done
git diff --binary -- "$@"
) | hash_stream
}
file_fingerprint() {
local file="$1"
if [[ ! -f "$file" ]]; then
printf 'missing:%s\n' "$file" | hash_stream
return 0
fi
shasum -a 256 "$file" | awk '{print $1}'
}
combined_fingerprint() {
printf '%s\n' "$@" | hash_stream
}
descendant_pids() {
local pid="$1"
local child
@@ -148,17 +181,30 @@ ensure_port_available() {
start_service() {
local name="$1"
local service_dir="$2"
local fingerprint="$3"
local pid_file="$LOCAL_DEBUG_PID_DIR/$name.pid"
shift 2
local fingerprint_file="$LOCAL_DEBUG_PID_DIR/$name.fingerprint"
shift 3
if [[ -f "$pid_file" ]]; then
local existing_pid
existing_pid="$(cat "$pid_file")"
if kill -0 "$existing_pid" 2>/dev/null; then
local previous_fingerprint=""
if [[ -n "$fingerprint" && -f "$fingerprint_file" ]]; then
previous_fingerprint="$(cat "$fingerprint_file")"
fi
if [[ -n "$fingerprint" && "$previous_fingerprint" != "$fingerprint" ]]; then
printf '%s source or environment changed; restarting pid %s\n' "$name" "$existing_pid"
stop_pid_tree "$name" "$existing_pid"
rm -f "$pid_file"
else
printf '%s already running with pid %s\n' "$name" "$existing_pid"
return 0
fi
else
rm -f "$pid_file" "$fingerprint_file"
fi
rm -f "$pid_file"
fi
printf 'starting %s\n' "$name"
@@ -167,6 +213,11 @@ start_service() {
exec nohup "$@" >"$LOCAL_DEBUG_LOG_DIR/$name.log" 2>&1
) >/dev/null 2>&1 &
printf '%s' "$!" >"$pid_file"
if [[ -n "$fingerprint" ]]; then
printf '%s' "$fingerprint" >"$fingerprint_file"
else
rm -f "$fingerprint_file"
fi
printf '%s pid %s log %s\n' "$name" "$(cat "$pid_file")" "$LOCAL_DEBUG_LOG_DIR/$name.log"
}
@@ -202,10 +253,26 @@ printf 'platform log: %s\n' "$LOCAL_DEBUG_LOG_DIR/platform.log"
printf 'run log: %s\n' "$LOCAL_DEBUG_LOG_DIR/run.log"
printf 'platform_web log: %s\n' "$LOCAL_DEBUG_LOG_DIR/platform_web.log"
platform_fingerprint="$(combined_fingerprint \
"$(tracked_tree_fingerprint "$ROOT_DIR" platform scripts/dev-start.sh scripts/local-debug)" \
"PLATFORM_ADDR=$PLATFORM_ADDR" \
"PLATFORM_STORAGE_BACKEND=$PLATFORM_STORAGE_BACKEND" \
"PLATFORM_METADATA_PATH=$PLATFORM_METADATA_PATH" \
"PLATFORM_LOG_BODY_BACKEND=$PLATFORM_LOG_BODY_BACKEND" \
"PLATFORM_RUN_RELEASE_URL=$PLATFORM_RUN_RELEASE_URL" \
"PLATFORM_BUILDER_IMAGE=$PLATFORM_BUILDER_IMAGE" \
"PLATFORM_BUILDER_SOURCE_DIR=$PLATFORM_BUILDER_SOURCE_DIR" \
"PLATFORM_BUILDER_SOURCE_REVISION=$PLATFORM_BUILDER_SOURCE_REVISION")"
web_fingerprint="$(combined_fingerprint \
"$(tracked_tree_fingerprint "$ROOT_DIR" platform_web package.json package-lock.json scripts/dev-start.sh scripts/local-debug)" \
"PLATFORM_API_PROXY=$PLATFORM_API_PROXY" \
"VITE_PLATFORM_API_BASE_URL=$VITE_PLATFORM_API_BASE_URL" \
"VITE_ENABLE_LOCAL_AUTH_FALLBACK=$VITE_ENABLE_LOCAL_AUTH_FALLBACK")"
ensure_port_available platform "$LOCAL_DEBUG_PLATFORM_PORT"
ensure_port_available platform_web "$LOCAL_DEBUG_WEB_PORT"
start_service platform "$ROOT_DIR/platform" env \
start_service platform "$ROOT_DIR/platform" "$platform_fingerprint" env \
GOCACHE="$GOCACHE" \
PLATFORM_ADDR="$PLATFORM_ADDR" \
PLATFORM_STORAGE_BACKEND="$PLATFORM_STORAGE_BACKEND" \
@@ -230,7 +297,7 @@ start_service platform "$ROOT_DIR/platform" env \
wait_for_url platform "$(local_debug_platform_url)/healthz"
start_service platform_web "$ROOT_DIR" env \
start_service platform_web "$ROOT_DIR" "$web_fingerprint" env \
PLATFORM_API_PROXY="$PLATFORM_API_PROXY" \
VITE_PLATFORM_API_BASE_URL="$VITE_PLATFORM_API_BASE_URL" \
VITE_ENABLE_LOCAL_AUTH_FALLBACK="$VITE_ENABLE_LOCAL_AUTH_FALLBACK" \
@@ -240,7 +307,22 @@ wait_for_url platform_web "$(local_debug_web_url)"
stop_orphaned_run_bootstrap
local_debug_build_bootstrap_run
start_service run "$(dirname "$RUN_BOOTSTRAP_BIN")" env \
run_fingerprint="$(combined_fingerprint \
"$(tracked_tree_fingerprint "$RUN_SOURCE_DIR" .)" \
"$(file_fingerprint "$RUN_BOOTSTRAP_BIN")" \
"RUN_MODE=$RUN_MODE" \
"RUN_PLATFORM_URL=$RUN_PLATFORM_URL" \
"RUN_ENDPOINT_ID=$RUN_ENDPOINT_ID" \
"RUN_DISPLAY_NAME=$RUN_DISPLAY_NAME" \
"RUN_VERSION=$RUN_VERSION" \
"RUN_WORKSPACE_ROOT=$RUN_WORKSPACE_ROOT" \
"RUN_BUILD_SOURCE_ROOT=$RUN_BUILD_SOURCE_ROOT" \
"RUN_SPOOL_ROOT=$RUN_SPOOL_ROOT" \
"RUN_MAX_JOBS=$RUN_MAX_JOBS" \
"RUN_HEARTBEAT_INTERVAL_MS=$RUN_HEARTBEAT_INTERVAL_MS" \
"RUN_POLL_INTERVAL_MS=$RUN_POLL_INTERVAL_MS" \
"RUN_RETRY_BACKOFF_MS=$RUN_RETRY_BACKOFF_MS")"
start_service run "$(dirname "$RUN_BOOTSTRAP_BIN")" "$run_fingerprint" env \
GOCACHE="$GOCACHE" \
RUN_MODE="$RUN_MODE" \
RUN_PLATFORM_URL="$RUN_PLATFORM_URL" \