fix 前端优化
This commit is contained in:
@@ -141,7 +141,9 @@ json_post() {
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
printf 'POST %s failed with HTTP %s\n' "$url" "$status" >&2
|
||||
if [[ ! -s "$output_file" ]] || ! response_code_is_duplicate "$output_file"; then
|
||||
printf 'POST %s failed with HTTP %s\n' "$url" "$status" >&2
|
||||
fi
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
@@ -154,6 +156,28 @@ json_get() {
|
||||
curl -fsS "$@" "$url" >"$output_file"
|
||||
}
|
||||
|
||||
response_code_is_duplicate() {
|
||||
local file="$1"
|
||||
node -e 'const fs=require("fs"); const data=JSON.parse(fs.readFileSync(process.argv[1],"utf8")); process.exit(data.code === "duplicate" || data.code === "duplicate_resource" ? 0 : 1);' "$file" 2>/dev/null
|
||||
}
|
||||
|
||||
register_plugin_manifest() {
|
||||
local label="$1"
|
||||
local plugin_id="$2"
|
||||
local request_file="$3"
|
||||
local response_file="$4"
|
||||
if json_post "$API_URL/game-plugins/register-manifest" "$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/game-plugins/$plugin_id" "$response_file" "${AUTH_HEADER[@]}"
|
||||
return 0
|
||||
fi
|
||||
printf '%s manifest registration failed; platform response:\n' "$label" >&2
|
||||
sed -n '1,160p' "$response_file" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
require_file_contains() {
|
||||
local file="$1"
|
||||
local pattern="$2"
|
||||
@@ -183,6 +207,43 @@ json_id() {
|
||||
node -e 'const fs=require("fs"); const data=JSON.parse(fs.readFileSync(process.argv[1],"utf8")); const id=data.instance?.id || data.serverInstance?.id || data.id || ((data.items||[])[0]||{}).id; if (!id) process.exit(2); process.stdout.write(id);' "$1"
|
||||
}
|
||||
|
||||
require_scum_manifest_contract() {
|
||||
local file="$1"
|
||||
node - "$file" <<'NODE'
|
||||
const fs = require("fs");
|
||||
const file = process.argv[2];
|
||||
const plugin = JSON.parse(fs.readFileSync(file, "utf8"));
|
||||
const missing = [];
|
||||
const declaredPermissions = Array.isArray(plugin.declaredPermissions) ? plugin.declaredPermissions : [];
|
||||
const bridgeActions = Array.isArray(plugin.bridgeActions) ? plugin.bridgeActions : [];
|
||||
const lifecycleProfiles = plugin.runtimeProfiles?.lifecycleProfiles ?? [];
|
||||
const clientManagers = plugin.runtimeProfiles?.clientManagers ?? [];
|
||||
if (!declaredPermissions.includes("server.run.distribution")) {
|
||||
missing.push("server.run.distribution permission");
|
||||
}
|
||||
if (!declaredPermissions.includes("server.client-manager.manage")) {
|
||||
missing.push("server.client-manager.manage permission");
|
||||
}
|
||||
if (!bridgeActions.includes("run.distribution.request")) {
|
||||
missing.push("run.distribution.request bridge action");
|
||||
}
|
||||
if (!lifecycleProfiles.some((profile) => profile.key === "run-local")) {
|
||||
missing.push("run-local runtime profile");
|
||||
}
|
||||
if (!clientManagers.some((profile) => profile.key === "scum-client-manager")) {
|
||||
missing.push("scum-client-manager runtime profile");
|
||||
}
|
||||
if (!plugin.gameClientBridge?.commands?.length) {
|
||||
missing.push("game client bridge declarations");
|
||||
}
|
||||
if (missing.length > 0) {
|
||||
console.error(`SCUM plugin registration is stale or incomplete: missing ${missing.join(", ")}`);
|
||||
console.error("Run scripts/local-debug-reset.sh, restart the local debug stack, then rerun scripts/local-debug-smoke.sh.");
|
||||
process.exit(1);
|
||||
}
|
||||
NODE
|
||||
}
|
||||
|
||||
wait_for_distribution_build() {
|
||||
local distribution_file="$1"
|
||||
local job_file="$2"
|
||||
@@ -311,9 +372,7 @@ fs.writeFileSync(outputPath, JSON.stringify({
|
||||
NODE
|
||||
|
||||
printf 'registering dev plugin through platform API\n'
|
||||
if ! json_post "$API_URL/game-plugins/register-manifest" "$WORK_DIR/register-plugin.request.json" "$WORK_DIR/register-plugin.response.json" "${AUTH_HEADER[@]}"; then
|
||||
json_get "$API_URL/game-plugins/game.example" "$WORK_DIR/register-plugin.response.json" "${AUTH_HEADER[@]}"
|
||||
fi
|
||||
register_plugin_manifest "dev plugin" "game.example" "$WORK_DIR/register-plugin.request.json" "$WORK_DIR/register-plugin.response.json"
|
||||
reject_forbidden_fragments "$WORK_DIR/register-plugin.response.json"
|
||||
|
||||
node - "$ROOT_DIR/plugins/examples/scum-server-plugin/manifest.json" "$WORK_DIR/register-scum-plugin.request.json" <<'NODE'
|
||||
@@ -330,6 +389,7 @@ const localRunCapabilities = [
|
||||
"dependencies.check",
|
||||
"dependencies.install",
|
||||
"logs.backfill",
|
||||
...source.runtimeProfiles.clientManagers.flatMap((manager) => manager.deployment?.requiredRunCapabilities ?? []),
|
||||
...source.capabilities.filter((capability) => capability.startsWith("remote."))
|
||||
];
|
||||
const localRuntimeProfiles = {
|
||||
@@ -342,7 +402,9 @@ const localRuntimeProfiles = {
|
||||
start: "actions/start.json",
|
||||
stop: "actions/stop.json"
|
||||
}
|
||||
}]
|
||||
}],
|
||||
transportProfiles: source.runtimeProfiles?.transportProfiles ?? [],
|
||||
clientManagers: source.runtimeProfiles?.clientManagers ?? []
|
||||
};
|
||||
const manifest = {
|
||||
id: source.id,
|
||||
@@ -365,7 +427,8 @@ const manifest = {
|
||||
ai: source.ai,
|
||||
productionLifecycle: source.productionLifecycle,
|
||||
remoteAccess: source.remoteAccess,
|
||||
runtimeProfiles: localRuntimeProfiles
|
||||
runtimeProfiles: localRuntimeProfiles,
|
||||
gameClientBridge: source.gameClientBridge
|
||||
};
|
||||
fs.writeFileSync(outputPath, JSON.stringify({
|
||||
manifestRef: "artifact://manifests/game.scum/0.1.0",
|
||||
@@ -374,10 +437,9 @@ fs.writeFileSync(outputPath, JSON.stringify({
|
||||
NODE
|
||||
|
||||
printf 'registering SCUM plugin through platform API\n'
|
||||
if ! json_post "$API_URL/game-plugins/register-manifest" "$WORK_DIR/register-scum-plugin.request.json" "$WORK_DIR/register-scum-plugin.response.json" "${AUTH_HEADER[@]}"; then
|
||||
json_get "$API_URL/game-plugins/game.scum" "$WORK_DIR/register-scum-plugin.response.json" "${AUTH_HEADER[@]}"
|
||||
fi
|
||||
register_plugin_manifest "SCUM plugin" "game.scum" "$WORK_DIR/register-scum-plugin.request.json" "$WORK_DIR/register-scum-plugin.response.json"
|
||||
reject_forbidden_fragments "$WORK_DIR/register-scum-plugin.response.json"
|
||||
require_scum_manifest_contract "$WORK_DIR/register-scum-plugin.response.json"
|
||||
|
||||
printf 'waiting for run endpoint heartbeat\n'
|
||||
for _ in $(seq 1 20); do
|
||||
|
||||
Reference in New Issue
Block a user