|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 5 | +source "$ROOT_DIR/scripts/lib/docker-e2e-logs.sh" |
| 6 | + |
| 7 | +IMAGE_NAME="${OPENCLAW_PLUGIN_UPDATE_E2E_IMAGE:-openclaw-plugin-update-e2e}" |
| 8 | +SKIP_BUILD="${OPENCLAW_PLUGIN_UPDATE_E2E_SKIP_BUILD:-0}" |
| 9 | + |
| 10 | +if [ "$SKIP_BUILD" = "1" ]; then |
| 11 | + echo "Reusing Docker image: $IMAGE_NAME" |
| 12 | +else |
| 13 | + echo "Building Docker image..." |
| 14 | + run_logged plugin-update-build docker build -t "$IMAGE_NAME" -f "$ROOT_DIR/scripts/e2e/Dockerfile" "$ROOT_DIR" |
| 15 | +fi |
| 16 | + |
| 17 | +echo "Running unchanged plugin update smoke..." |
| 18 | +docker run --rm \ |
| 19 | + -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \ |
| 20 | + -e OPENCLAW_SKIP_CHANNELS=1 \ |
| 21 | + -e OPENCLAW_SKIP_PROVIDERS=1 \ |
| 22 | + "$IMAGE_NAME" \ |
| 23 | + bash -lc "set -euo pipefail |
| 24 | +entry=dist/index.mjs |
| 25 | +[ -f \"\$entry\" ] || entry=dist/index.js |
| 26 | +export NPM_CONFIG_REGISTRY=http://127.0.0.1:4873 |
| 27 | +
|
| 28 | +mkdir -p \"\$HOME/.openclaw/extensions/lossless-claw\" |
| 29 | +cat > \"\$HOME/.openclaw/extensions/lossless-claw/package.json\" <<'JSON' |
| 30 | +{ |
| 31 | + \"name\": \"@example/lossless-claw\", |
| 32 | + \"version\": \"0.9.0\" |
| 33 | +} |
| 34 | +JSON |
| 35 | +cat > \"\$HOME/.openclaw/openclaw.json\" <<'JSON' |
| 36 | +{ |
| 37 | + \"plugins\": { |
| 38 | + \"installs\": { |
| 39 | + \"lossless-claw\": { |
| 40 | + \"source\": \"npm\", |
| 41 | + \"spec\": \"@example/[email protected]\", |
| 42 | + \"installPath\": \"~/.openclaw/extensions/lossless-claw\", |
| 43 | + \"resolvedName\": \"@example/lossless-claw\", |
| 44 | + \"resolvedVersion\": \"0.9.0\", |
| 45 | + \"resolvedSpec\": \"@example/[email protected]\", |
| 46 | + \"integrity\": \"sha512-same\", |
| 47 | + \"shasum\": \"same\" |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | +JSON |
| 53 | +
|
| 54 | +cat > /tmp/openclaw-e2e-registry.mjs <<'NODE' |
| 55 | +import http from 'node:http'; |
| 56 | +
|
| 57 | +const metadata = { |
| 58 | + name: '@example/lossless-claw', |
| 59 | + 'dist-tags': { latest: '0.9.0' }, |
| 60 | + versions: { |
| 61 | + '0.9.0': { |
| 62 | + name: '@example/lossless-claw', |
| 63 | + version: '0.9.0', |
| 64 | + dist: { |
| 65 | + integrity: 'sha512-same', |
| 66 | + shasum: 'same', |
| 67 | + tarball: 'http://127.0.0.1:4873/@example/lossless-claw/-/lossless-claw-0.9.0.tgz' |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +}; |
| 72 | +
|
| 73 | +const server = http.createServer((req, res) => { |
| 74 | + if (req.url === '/@example%2flossless-claw' || req.url === '/@example%2Flossless-claw') { |
| 75 | + res.writeHead(200, { 'content-type': 'application/json' }); |
| 76 | + res.end(JSON.stringify(metadata)); |
| 77 | + return; |
| 78 | + } |
| 79 | + res.writeHead(404, { 'content-type': 'text/plain' }); |
| 80 | + res.end('not found: ' + req.url); |
| 81 | +}); |
| 82 | +
|
| 83 | +server.listen(4873, '127.0.0.1'); |
| 84 | +NODE |
| 85 | +node /tmp/openclaw-e2e-registry.mjs >/tmp/openclaw-e2e-registry.log 2>&1 & |
| 86 | +registry_pid=\$! |
| 87 | +trap 'kill \"\$registry_pid\" >/dev/null 2>&1 || true' EXIT |
| 88 | +
|
| 89 | +registry_ready=0 |
| 90 | +for _ in \$(seq 1 50); do |
| 91 | + if node --input-type=module -e ' |
| 92 | + import http from \"node:http\"; |
| 93 | + const req = http.get(\"http://127.0.0.1:4873/@example%2flossless-claw\", (res) => { |
| 94 | + process.exit(res.statusCode === 200 ? 0 : 1); |
| 95 | + }); |
| 96 | + req.on(\"error\", () => process.exit(1)); |
| 97 | + req.setTimeout(200, () => { |
| 98 | + req.destroy(); |
| 99 | + process.exit(1); |
| 100 | + }); |
| 101 | + '; then |
| 102 | + registry_ready=1 |
| 103 | + break |
| 104 | + fi |
| 105 | + sleep 0.1 |
| 106 | +done |
| 107 | +if [ \"\$registry_ready\" -ne 1 ]; then |
| 108 | + echo \"Local npm metadata registry failed to start\" |
| 109 | + cat /tmp/openclaw-e2e-registry.log || true |
| 110 | + exit 1 |
| 111 | +fi |
| 112 | +
|
| 113 | +before_hash=\$(node --input-type=module -e ' |
| 114 | + import crypto from \"node:crypto\"; |
| 115 | + import fs from \"node:fs\"; |
| 116 | + import os from \"node:os\"; |
| 117 | + import path from \"node:path\"; |
| 118 | + const file = path.join(os.homedir(), \".openclaw\", \"openclaw.json\"); |
| 119 | + process.stdout.write(crypto.createHash(\"sha256\").update(fs.readFileSync(file)).digest(\"hex\")); |
| 120 | +') |
| 121 | +
|
| 122 | +node \"\$entry\" plugins update @example/lossless-claw > /tmp/plugin-update-output.log 2>&1 |
| 123 | +
|
| 124 | +after_hash=\$(node --input-type=module -e ' |
| 125 | + import crypto from \"node:crypto\"; |
| 126 | + import fs from \"node:fs\"; |
| 127 | + import os from \"node:os\"; |
| 128 | + import path from \"node:path\"; |
| 129 | + const file = path.join(os.homedir(), \".openclaw\", \"openclaw.json\"); |
| 130 | + process.stdout.write(crypto.createHash(\"sha256\").update(fs.readFileSync(file)).digest(\"hex\")); |
| 131 | +') |
| 132 | +
|
| 133 | +if [ \"\$before_hash\" != \"\$after_hash\" ]; then |
| 134 | + echo \"Config changed unexpectedly\" |
| 135 | + cat /tmp/plugin-update-output.log |
| 136 | + exit 1 |
| 137 | +fi |
| 138 | +if grep -q 'Downloading @example/lossless-claw' /tmp/plugin-update-output.log; then |
| 139 | + echo \"Unexpected npm download/reinstall path\" |
| 140 | + cat /tmp/plugin-update-output.log |
| 141 | + exit 1 |
| 142 | +fi |
| 143 | +if ! grep -q 'lossless-claw is up to date (0.9.0).' /tmp/plugin-update-output.log; then |
| 144 | + echo \"Expected up-to-date output missing\" |
| 145 | + cat /tmp/plugin-update-output.log |
| 146 | + exit 1 |
| 147 | +fi |
| 148 | +cat /tmp/plugin-update-output.log |
| 149 | +" |
| 150 | + |
| 151 | +echo "Plugin update unchanged Docker E2E passed." |
0 commit comments