






















@@ -0,0 +1,155 @@
1+#!/usr/bin/env bash
2+# Verifies status/doctor UX for a configured plugin channel whose setup entry
3+# fails because a staged dependency tree is corrupt.
4+set -euo pipefail
5+6+ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
7+TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/openclaw-status-corrupt-plugin-deps.XXXXXX")"
8+cleanup() {
9+ rm -rf "$TMP_DIR"
10+}
11+trap cleanup EXIT
12+13+HOME_DIR="$TMP_DIR/home"
14+STATE_DIR="$TMP_DIR/state"
15+CONFIG_PATH="$TMP_DIR/openclaw.json"
16+PLUGIN_DIR="$TMP_DIR/plugin"
17+STAGE_DIR="$TMP_DIR/stage"
18+mkdir -p "$HOME_DIR" "$STATE_DIR" "$PLUGIN_DIR" "$STAGE_DIR/node_modules/ansi-escapes"
19+printf "corrupt rename residue\n" > "$STAGE_DIR/node_modules/ansi-escapes/.openclaw-rename-tmp"
20+21+cat > "$PLUGIN_DIR/package.json" <<'JSON'
22+{
23+ "name": "@example/openclaw-e2e-corrupt-chat",
24+ "version": "1.0.0",
25+ "openclaw": {
26+ "extensions": ["./index.cjs"],
27+ "setupEntry": "./setup-entry.cjs"
28+ }
29+}
30+JSON
31+32+cat > "$PLUGIN_DIR/openclaw.plugin.json" <<'JSON'
33+{
34+ "id": "e2e-corrupt-chat",
35+ "configSchema": {
36+ "type": "object",
37+ "additionalProperties": false,
38+ "properties": {}
39+ },
40+ "channelConfigs": {
41+ "e2e-corrupt-chat": {
42+ "label": "E2E Corrupt Chat",
43+ "description": "E2E corrupt dependency fixture",
44+ "schema": {
45+ "type": "object",
46+ "additionalProperties": false,
47+ "properties": {
48+ "enabled": { "type": "boolean" },
49+ "token": { "type": "string" }
50+ }
51+ }
52+ }
53+ },
54+ "channels": ["e2e-corrupt-chat"],
55+ "channelEnvVars": {
56+ "e2e-corrupt-chat": ["E2E_CORRUPT_CHAT_TOKEN"]
57+ }
58+}
59+JSON
60+61+cat > "$PLUGIN_DIR/index.cjs" <<'JS'
62+module.exports = {
63+ id: "e2e-corrupt-chat",
64+ register() {}
65+};
66+JS
67+68+cat > "$PLUGIN_DIR/setup-entry.cjs" <<'JS'
69+const fs = require("node:fs");
70+const path = require("node:path");
71+72+const stageDir = process.env.OPENCLAW_PLUGIN_STAGE_DIR || "";
73+const renameResidue = path.join(stageDir, "node_modules", "ansi-escapes", ".openclaw-rename-tmp");
74+if (fs.existsSync(renameResidue)) {
75+ const err = new Error("ENOTEMPTY: directory not empty, rename 'ansi-escapes'");
76+ err.code = "ENOTEMPTY";
77+ throw err;
78+}
79+80+const plugin = {
81+ id: "e2e-corrupt-chat",
82+ meta: {
83+ id: "e2e-corrupt-chat",
84+ label: "E2E Corrupt Chat",
85+ selectionLabel: "E2E Corrupt Chat",
86+ docsPath: "/channels/e2e-corrupt-chat",
87+ blurb: "E2E corrupt dependency fixture"
88+ },
89+ capabilities: { chatTypes: ["direct"] },
90+ config: {
91+ listAccountIds: () => ["default"],
92+ resolveAccount: () => ({ accountId: "default", token: "configured" }),
93+ isEnabled: () => true,
94+ isConfigured: () => true,
95+ hasConfiguredState: () => true
96+ },
97+ outbound: { deliveryMode: "direct" }
98+};
99+100+module.exports = { plugin };
101+JS
102+103+cat > "$CONFIG_PATH" <<JSON
104+{
105+ "gateway": { "mode": "local" },
106+ "plugins": {
107+ "enabled": true,
108+ "bundledDiscovery": "allowlist",
109+ "load": { "paths": ["$PLUGIN_DIR"] },
110+ "allow": ["e2e-corrupt-chat"]
111+ },
112+ "channels": {
113+ "e2e-corrupt-chat": { "enabled": true, "token": "configured" }
114+ }
115+}
116+JSON
117+118+run_openclaw() {
119+ HOME="$HOME_DIR" \
120+ OPENCLAW_HOME="$STATE_DIR" \
121+ OPENCLAW_STATE_DIR="$STATE_DIR" \
122+ OPENCLAW_CONFIG_PATH="$CONFIG_PATH" \
123+ OPENCLAW_PLUGIN_STAGE_DIR="$STAGE_DIR" \
124+ OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 \
125+ OPENCLAW_NO_ONBOARD=1 \
126+ OPENCLAW_NO_PROMPT=1 \
127+ OPENCLAW_SKIP_CHANNELS=1 \
128+ OPENCLAW_SKIP_PROVIDERS=1 \
129+ COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
130+ NO_COLOR=1 \
131+ node "$ROOT_DIR/scripts/run-node.mjs" "$@"
132+}
133+134+BEFORE="$TMP_DIR/status-before.txt"
135+DOCTOR="$TMP_DIR/doctor.txt"
136+AFTER="$TMP_DIR/status-after.txt"
137+138+run_openclaw status --all --timeout 1 > "$BEFORE"
139+grep -F "e2e-corrupt-chat" "$BEFORE" >/dev/null
140+grep -F "plugin load failed: dependency tree corrupted; run openclaw doctor --fix" "$BEFORE" >/dev/null
141+142+run_openclaw doctor --fix --non-interactive --yes > "$DOCTOR"
143+if [[ -e "$STAGE_DIR" ]]; then
144+echo "doctor --fix did not remove corrupt plugin stage dir: $STAGE_DIR" >&2
145+exit 1
146+fi
147+148+run_openclaw status --all --timeout 1 > "$AFTER"
149+grep -F "E2E Corrupt Chat" "$AFTER" >/dev/null
150+if grep -F "plugin load failed: dependency tree corrupted" "$AFTER" >/dev/null; then
151+echo "status still reports corrupt plugin dependency tree after doctor --fix" >&2
152+exit 1
153+fi
154+155+echo "Status corrupt plugin dependency E2E passed."
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。