From d80de92babd1583de641cc5b67540c58168f598f Mon Sep 17 00:00:00 2001 From: dada-yan Date: Sat, 14 Nov 2026 15:19:48 +1100 Subject: [PATCH] fix(console): preserve snapshot builds when cleanup fails Signed-off-by: dada-yan --- web/console/package-lock.json | 616 ++++++++++++++++++ web/console/package.json | 1 + web/console/src/api.ts | 5 - .../src/dialogs/BuildSnapshot.test.tsx | 158 +++++ web/console/src/dialogs/BuildSnapshot.tsx | 94 ++- 5 files changed, 841 insertions(+), 33 deletions(-) create mode 100644 web/console/src/dialogs/BuildSnapshot.test.tsx diff --git a/web/console/package-lock.json b/web/console/package-lock.json index 08bbfe97..e322317d 100644 --- a/web/console/package-lock.json +++ b/web/console/package-lock.json @@ -16,6 +16,7 @@ "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", "@vitejs/plugin-react": "^6.1.2", + "jsdom": "^28.1.0", "typescript": "^7.0.2", "vite": "^8.3.5", "vite-plugin-singlefile": "^2.3.4", @@ -25,6 +26,232 @@ "node": ">=20" } }, + "node_modules/@acemir/cssom": { + "version": "0.9.33", + "resolved": "https://registry.npmjs.org/@acemir/cssom/-/cssom-0.9.33.tgz", + "integrity": "sha512-52IMmrBsIsDZLp/KFM+KmaMLJ8GTj113K+iFGFCoOjstZSZbsAxMJE8KYtwao7bz1LsEG810ts1m5wvkVEqPlg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@asamuzakjp/css-color": { + "version": "5.1.11", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-5.1.11.tgz", + "integrity": "sha512-KVw6qIiCTUQhByfTd78h2yD1/00waTmm9uy/R7Ck/ctUyAPj+AEDLkQIdJW0T8+qGgj3j5bpNKK7Q3G+LedJWg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@asamuzakjp/generational-cache": "^1.0.1", + "@csstools/css-calc": "^3.2.0", + "@csstools/css-color-parser": "^4.1.0", + "@csstools/css-parser-algorithms": "^4.0.0", + "@csstools/css-tokenizer": "^4.0.0" + }, + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + } + }, + "node_modules/@asamuzakjp/dom-selector": { + "version": "6.8.1", + "resolved": "https://registry.npmjs.org/@asamuzakjp/dom-selector/-/dom-selector-6.8.1.tgz", + "integrity": "sha512-MvRz1nCqW0fsy8Qz4dnLIvhOlMzqDVBabZx6lH+YywFDdjXhMY37SmpV1XFX3JzG5GWHn63j6HX6QPr3lZXHvQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@asamuzakjp/nwsapi": "^2.3.9", + "bidi-js": "^1.0.3", + "css-tree": "^3.1.0", + "is-potential-custom-element-name": "^1.0.1", + "lru-cache": "^11.2.6" + } + }, + "node_modules/@asamuzakjp/generational-cache": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@asamuzakjp/generational-cache/-/generational-cache-1.0.1.tgz", + "integrity": "sha512-wajfB8KqzMCN2KGNFdLkReeHncd0AslUSrvHVvvYWuU8ghncRJoA50kT3zP9MVL0+9g4/67H+cdvBskj9THPzg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + } + }, + "node_modules/@asamuzakjp/nwsapi": { + "version": "2.3.9", + "resolved": "https://registry.npmjs.org/@asamuzakjp/nwsapi/-/nwsapi-2.3.9.tgz", + "integrity": "sha512-n8GuYSrI9bF7FFZ/SjhwevlHc8xaVlb/7HmHelnc/PZXBD2ZR49NnN9sMMuDdEGPeeRQ5d0hqlSlEpgCX3Wl0Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/@bramus/specificity": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/@bramus/specificity/-/specificity-2.4.3.tgz", + "integrity": "sha512-0GEz8qJWokkUVYQYRukmkSHIFNoBH8QTreeHrAFbvz1XFYc3Y+puhMs8PQ5x8GNugiC2l5jvDBXKLbBIByeSBw==", + "dev": true, + "license": "MIT", + "dependencies": { + "css-tree": "^3.2.1" + }, + "bin": { + "specificity": "bin/cli.js" + } + }, + "node_modules/@csstools/color-helpers": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-6.1.2.tgz", + "integrity": "sha512-grhRy3OKmniaAEKXMjua5z/EODX0MSqBGjunw8+j/3HQjOnahs2AGhvEOIYVUWcU6ScApbhLhVrQTX8XqrMrow==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT-0", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/@csstools/css-calc": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-3.4.3.tgz", + "integrity": "sha512-iex20d8CHVkyvg6B7UKV7uHnI2Bqo9g+EFfT9E0y+GvTvhZ/DwONJ+9aKb1dlqm0ZiGsL5RXjp0fCoJYnkeDjA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=20.19.0" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^4.0.2", + "@csstools/css-tokenizer": "^4.0.2" + } + }, + "node_modules/@csstools/css-color-parser": { + "version": "4.2.7", + "resolved": "https://registry.npmjs.org/@csstools/css-color-parser/-/css-color-parser-4.2.7.tgz", + "integrity": "sha512-zgm9yjQz5iJB4VL8RyVwd71TWB8Q89FSxt/NzXoWqPSkEBOVtn9L6vAPtSc9hpKfB0Awo/AL2VKFHjYetBLFHQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "dependencies": { + "@csstools/color-helpers": "^6.1.2", + "@csstools/css-calc": "^3.4.3" + }, + "engines": { + "node": ">=20.19.0" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^4.0.2", + "@csstools/css-tokenizer": "^4.0.2" + } + }, + "node_modules/@csstools/css-parser-algorithms": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-4.0.2.tgz", + "integrity": "sha512-40cSKyMvK+tq4qz6Awrlye2WGuOKt3FwPgtGg6KTfbHOWNw+Rk1rzbAtZnZ6IBhsY491HLRnDXwoyBAijmmILA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=20.19.0" + }, + "peerDependencies": { + "@csstools/css-tokenizer": "^4.0.2" + } + }, + "node_modules/@csstools/css-syntax-patches-for-csstree": { + "version": "1.1.16", + "resolved": "https://registry.npmjs.org/@csstools/css-syntax-patches-for-csstree/-/css-syntax-patches-for-csstree-1.1.16.tgz", + "integrity": "sha512-LsDbJPP/B8cPasUJyTA5S99F7C4G93ngW8hUluXz8CFeOaaRnBPtBiIlvgcPYU0HmHNz8CXg+1vwFrIB4F6Dgw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT-0", + "peerDependencies": { + "css-tree": "^3.2.1" + }, + "peerDependenciesMeta": { + "css-tree": { + "optional": true + } + } + }, + "node_modules/@csstools/css-tokenizer": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-4.0.2.tgz", + "integrity": "sha512-OoKoR0f76dCY666JlcbhmVTs2drYj1GUXZTYTcbUgJjh9Nv41aFfZ21bPQTERm5+L5cBDo466NltB2lplS5GBw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/@exodus/bytes": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/@exodus/bytes/-/bytes-1.16.0.tgz", + "integrity": "sha512-IcpW84uEn3N7ETtNZMlxKhfl6Pec8rUNGOTBtWbK1FKhJxIFAptZyVrvVRVBimAJxJCgc3PxepxkdWWG4DVzfA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + }, + "peerDependencies": { + "@noble/hashes": "^1.8.0 || ^2.0.0" + }, + "peerDependenciesMeta": { + "@noble/hashes": { + "optional": true + } + } + }, "node_modules/@jridgewell/sourcemap-codec": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", @@ -849,6 +1076,16 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, "node_modules/assertion-error": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", @@ -859,6 +1096,16 @@ "node": ">=12" } }, + "node_modules/bidi-js": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/bidi-js/-/bidi-js-1.1.0.tgz", + "integrity": "sha512-fX1Onk0tdVPC7obPWB5EbJ1z7NVhLq4m2xZLq2YXBkxzMXIGRpNMU88n0EPgWseKl12J7zXs7qrDxPK4sRs2fg==", + "dev": true, + "license": "MIT", + "dependencies": { + "require-from-string": "^2.0.2" + } + }, "node_modules/chai": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", @@ -876,6 +1123,36 @@ "dev": true, "license": "MIT" }, + "node_modules/css-tree": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.2.1.tgz", + "integrity": "sha512-X7sjQzceUhu1u7Y/ylrRZFU2FS6LRiFVp6rKLPg23y3x3c3DOKAwuXGDp+PAGjh6CSnCjYeAul8pcT8bAl+lSA==", + "dev": true, + "license": "MIT", + "dependencies": { + "mdn-data": "2.27.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0" + } + }, + "node_modules/cssstyle": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-6.2.0.tgz", + "integrity": "sha512-Fm5NvhYathRnXNVndkUsCCuR63DCLVVwGOOwQw782coXFi5HhkXdu289l59HlXZBawsyNccXfWRYvLzcDCdDig==", + "dev": true, + "license": "MIT", + "dependencies": { + "@asamuzakjp/css-color": "^5.0.1", + "@csstools/css-syntax-patches-for-csstree": "^1.0.28", + "css-tree": "^3.1.0", + "lru-cache": "^11.2.6" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/csstype": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", @@ -883,6 +1160,45 @@ "dev": true, "license": "MIT" }, + "node_modules/data-urls": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-7.0.0.tgz", + "integrity": "sha512-23XHcCF+coGYevirZceTVD7NdJOqVn+49IHyxgszm+JIiHLoB2TkmPtsYkNWT1pvRSGkc35L6NHs0yHkN2SumA==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-mimetype": "^5.0.0", + "whatwg-url": "^16.0.0" + }, + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/decimal.js": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz", + "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==", + "dev": true, + "license": "MIT" + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", @@ -893,6 +1209,19 @@ "node": ">=8" } }, + "node_modules/entities": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-9.0.0.tgz", + "integrity": "sha512-oJFNDJg3kTPwAD1cNn2+WmUq4wFoo09npc3Ydf1D7ED4smRiWrsKnaLxykrTWgyGEcusc87P5dxlAleol9kpkg==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/es-module-lexer": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", @@ -953,6 +1282,95 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/html-encoding-sniffer": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-6.0.0.tgz", + "integrity": "sha512-CV9TW3Y3f8/wT0BRFc1/KAVQ3TUHiXmaAb6VW9vtiMFf7SLoMd1PdAc4W3KFOFETBJUb90KatHqlsZMWV+R9Gg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@exodus/bytes": "^1.6.0" + }, + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + } + }, + "node_modules/http-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", + "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/jsdom": { + "version": "28.1.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-28.1.0.tgz", + "integrity": "sha512-0+MoQNYyr2rBHqO1xilltfDjV9G7ymYGlAUazgcDLQaUf8JDHbuGwsxN6U9qWaElZ4w1B2r7yEGIL3GdeW3Rug==", + "dev": true, + "license": "MIT", + "dependencies": { + "@acemir/cssom": "^0.9.31", + "@asamuzakjp/dom-selector": "^6.8.1", + "@bramus/specificity": "^2.4.2", + "@exodus/bytes": "^1.11.0", + "cssstyle": "^6.0.1", + "data-urls": "^7.0.0", + "decimal.js": "^10.6.0", + "html-encoding-sniffer": "^6.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.6", + "is-potential-custom-element-name": "^1.0.1", + "parse5": "^8.0.0", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^6.0.0", + "undici": "^7.21.0", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^8.0.1", + "whatwg-mimetype": "^5.0.0", + "whatwg-url": "^16.0.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + }, + "peerDependencies": { + "canvas": "^3.0.0" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, "node_modules/lightningcss": { "version": "1.33.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", @@ -1214,6 +1632,16 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/lru-cache": { + "version": "11.5.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.3.tgz", + "integrity": "sha512-U4N8FgzmWxc8k1VH8Kr6lQg18U7Fjvby6wXHVRX/ZZ7IwWbRMgrRbP0Wrb5q5NVinryp4SQampHKdvtecItxUg==", + "dev": true, + "license": "BlueOak-1.0.0", + "engines": { + "node": "20 || >=22" + } + }, "node_modules/magic-string": { "version": "0.30.21", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", @@ -1224,6 +1652,20 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/mdn-data": { + "version": "2.27.1", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.27.1.tgz", + "integrity": "sha512-9Yubnt3e8A0OKwxYSXyhLymGW4sCufcLG6VdiDdUGVkPhpqLxlvP5vl1983gQjJl3tqbrM731mjaZaP68AgosQ==", + "dev": true, + "license": "CC0-1.0" + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, "node_modules/nanoid": { "version": "3.3.20", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", @@ -1257,6 +1699,19 @@ "node": ">=12.20.0" } }, + "node_modules/parse5": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-8.1.1.tgz", + "integrity": "sha512-EcR/6WDcU7b2N3vQSxKALCk9lXGtUMQxXio008OEMBE0kavu/7JLfBEeFPzi43nMqVDSbEn3QCK+BMCc9zO//w==", + "dev": true, + "license": "MIT", + "dependencies": { + "entities": "^9.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/pathe": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", @@ -1313,6 +1768,16 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/react": { "version": "19.3.1", "resolved": "https://registry.npmjs.org/react/-/react-19.3.1.tgz", @@ -1334,6 +1799,16 @@ "react": "^19.3.1" } }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/rolldown": { "version": "1.2.16", "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.16.tgz", @@ -1368,6 +1843,19 @@ "@rolldown/binding-win32-x64-msvc": "1.2.16" } }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "license": "ISC", + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, "node_modules/scheduler": { "version": "0.28.0", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.28.0.tgz", @@ -1405,6 +1893,13 @@ "dev": true, "license": "MIT" }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true, + "license": "MIT" + }, "node_modules/tinybench": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", @@ -1449,6 +1944,52 @@ "node": ">=14.0.0" } }, + "node_modules/tldts": { + "version": "7.5.2", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-7.5.2.tgz", + "integrity": "sha512-p+JwEdxIWQx033pMvW9ULBbyC1Eg6JtWo2Mo0jbC8TVSjp2QrHFE+WKs8JpMGc3ECMsmBpU2RH/25NgX3k1ulg==", + "dev": true, + "license": "MIT", + "dependencies": { + "tldts-core": "^7.5.2" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "7.5.2", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-7.5.2.tgz", + "integrity": "sha512-8W1topazDwhMKbm2I83IPa57Ow5VUxFgLbXv42+vSILnv8FY5OHvdEY/tS6WoWeMbxkHZQhra5cmeFHriKptSQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/tough-cookie": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-6.1.0.tgz", + "integrity": "sha512-FTxc8u8Kl2tz0Lat1u8ksvcy8bwHRyEMawwTWybo51JqaC6O7SvfuhAKg+Ld6VqyIe2QRJBzY9HA7y2WyFRT2w==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "tldts": "^7.0.5" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/tr46": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-6.0.0.tgz", + "integrity": "sha512-bLVMLPtstlZ4iMQHpFHTR7GAGj2jxi8Dg0s2h2MafAE4uSWF98FC/3MomU51iQAMf8/qDUbKWf5GxuvvVcXEhw==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/typescript": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz", @@ -1484,6 +2025,16 @@ "@typescript/typescript-win32-x64": "7.0.2" } }, + "node_modules/undici": { + "version": "7.30.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.30.2.tgz", + "integrity": "sha512-mLyPQnHwUxaM/rideoK/+KL8DaAJLRl4aBCfmX444aCSLnIaomqPLtNRe2jdCYcsk5wZzXrDIQC8ZeYNRAYyIA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.18.1" + } + }, "node_modules/undici-types": { "version": "8.9.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.9.0.tgz", @@ -1681,6 +2232,54 @@ } } }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dev": true, + "license": "MIT", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/webidl-conversions": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-8.0.1.tgz", + "integrity": "sha512-BMhLD/Sw+GbJC21C/UgyaZX41nPt8bUTg+jWyDeg7e7YN4xOM05YPSIXceACnXVtqyEw/LMClUQMtMZ+PGGpqQ==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=20" + } + }, + "node_modules/whatwg-mimetype": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-5.0.0.tgz", + "integrity": "sha512-sXcNcHOC51uPGF0P/D4NVtrkjSU2fNsm9iog4ZvZJsL3rjoDAzXZhkm2MWt1y+PUdggKAYVoMAIYcs78wJ51Cw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20" + } + }, + "node_modules/whatwg-url": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-16.0.1.tgz", + "integrity": "sha512-1to4zXBxmXHV3IiSSEInrreIlu02vUOvrhxJJH5vcxYTBDAx51cqZiKdyTxlecdKNSjj8EcxGBxNf6Vg+945gw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@exodus/bytes": "^1.11.0", + "tr46": "^6.0.0", + "webidl-conversions": "^8.0.1" + }, + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + } + }, "node_modules/why-is-node-running": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", @@ -1697,6 +2296,23 @@ "engines": { "node": ">=8" } + }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true, + "license": "MIT" } } } diff --git a/web/console/package.json b/web/console/package.json index b8041605..44fc8c9a 100644 --- a/web/console/package.json +++ b/web/console/package.json @@ -23,6 +23,7 @@ "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", "@vitejs/plugin-react": "^6.1.2", + "jsdom": "^28.1.0", "typescript": "^7.0.2", "vite": "^8.3.5", "vite-plugin-singlefile": "^2.3.4", diff --git a/web/console/src/api.ts b/web/console/src/api.ts index 07a42b59..0fe0dc45 100644 --- a/web/console/src/api.ts +++ b/web/console/src/api.ts @@ -60,8 +60,3 @@ export async function apiDelete(path: string): Promise { throw new Error(m || String(r.status)); } } - -// A DELETE whose answer nobody waits on: tidying up after a build. -export function deleteQuietly(path: string): Promise { - return fetch(path, { method: "DELETE", headers: { authorization: "Bearer " + auth.token } }); -} diff --git a/web/console/src/dialogs/BuildSnapshot.test.tsx b/web/console/src/dialogs/BuildSnapshot.test.tsx new file mode 100644 index 00000000..03756fef --- /dev/null +++ b/web/console/src/dialogs/BuildSnapshot.test.tsx @@ -0,0 +1,158 @@ +// @vitest-environment jsdom +import { act } from "react"; +import { createRoot, type Root } from "react-dom/client"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { setToken } from "../api"; +import { BuildSnapshot } from "./BuildSnapshot"; + +const buildId = "build-a"; +const sandboxPath = "/v1/sandboxes/" + buildId; +const snapshot = { tag: "python-v1", node_id: "node-a" }; +let root: Root | undefined; +let container: HTMLElement | undefined; + +beforeEach(() => { + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); + setToken("test-master-token"); + window.sessionStorage.setItem("sandstorm-build", JSON.stringify({ + id: buildId, token: "test-build-token", node: "node-a", cwd: "/root", + })); +}); + +afterEach(async () => { + await unmountBuilder(); + window.sessionStorage.clear(); + setToken(null); + vi.unstubAllGlobals(); +}); + +function mockMaster() { + const requests: string[] = []; + let deletes = 0; + vi.stubGlobal("fetch", vi.fn(async (path: string, init?: RequestInit) => { + const request = `${init?.method ?? "GET"} ${path}`; + requests.push(request); + switch (request) { + case "GET /v1/templates": + return Response.json([]); + case `GET ${sandboxPath}`: + return Response.json({ id: buildId }); + case `POST ${sandboxPath}/exec`: + return Response.json({ exit_code: 0, stdout: "/root" }); + case `POST ${sandboxPath}/branch`: + return Response.json(snapshot); + case `DELETE ${sandboxPath}`: + if (deletes++ === 0) return Response.json({ error: "cleanup unavailable" }, { status: 503 }); + return new Response(null, { status: 204 }); + default: + throw new Error(`Unexpected request: ${request}`); + } + })); + return requests; +} + +async function mountBuilder(onSaved = vi.fn()) { + container = document.body.appendChild(document.createElement("div")); + root = createRoot(container); + await act(async () => { + root!.render( {}} onLive={() => {}} onSaved={onSaved} />); + }); + return onSaved; +} + +async function unmountBuilder() { + if (!root) return; + await act(async () => { root!.unmount(); }); + container!.remove(); + root = undefined; + container = undefined; +} + +function visibleButton(name: string) { + return Array.from(document.querySelectorAll("button")).find( + (button) => button.textContent?.trim() === name && !button.closest("[hidden]"), + ); +} + +async function click(name: string) { + const button = visibleButton(name); + expect(button, `visible button "${name}"`).toBeDefined(); + await act(async () => { button!.click(); }); +} + +async function saveSnapshot() { + const name = document.querySelector('[aria-label="Snapshot name"]')!; + name.value = snapshot.tag; + await click("Save snapshot"); +} + +function terminal() { + return document.querySelector('[role="log"]')?.textContent; +} + +function rememberedBuild() { + const raw = window.sessionStorage.getItem("sandstorm-build"); + return raw ? JSON.parse(raw) : null; +} + +describe("snapshot builder cleanup", () => { + it("keeps a saved snapshot and retries only deletion after HTTP 503", async () => { + const requests = mockMaster(); + const onSaved = await mountBuilder(); + await saveSnapshot(); + + expect(onSaved).toHaveBeenCalledOnce(); + expect(terminal()).toContain(`Saved ${snapshot.tag}`); + expect(terminal()).toContain("cleanup unavailable"); + expect(terminal()).not.toContain(`Deleted the build sandbox ${buildId}`); + expect(rememberedBuild()).toMatchObject({ id: buildId }); + expect(visibleButton("Save snapshot")).toBeUndefined(); + expect(visibleButton("Fork a sandbox from it")).toBeDefined(); + + await click("Retry delete sandbox"); + + expect(terminal()).toContain(`Deleted the build sandbox ${buildId}`); + expect(rememberedBuild()).toBeNull(); + expect(onSaved).toHaveBeenCalledOnce(); + expect(requests.filter((request) => request.endsWith("/branch"))).toEqual([`POST ${sandboxPath}/branch`]); + expect(requests.filter((request) => request.startsWith("DELETE "))).toEqual([ + `DELETE ${sandboxPath}`, `DELETE ${sandboxPath}`, + ]); + }); + + it("resumes pending deletion after a reload without saving the snapshot again", async () => { + const requests = mockMaster(); + await mountBuilder(); + await saveSnapshot(); + await unmountBuilder(); + + const onSaved = await mountBuilder(); + expect(rememberedBuild()).toMatchObject({ id: buildId }); + expect(visibleButton("Save snapshot")).toBeUndefined(); + expect(visibleButton("Fork a sandbox from it")).toBeDefined(); + await click("Retry delete sandbox"); + + expect(rememberedBuild()).toBeNull(); + expect(onSaved).not.toHaveBeenCalled(); + expect(requests.filter((request) => request.endsWith("/branch"))).toEqual([`POST ${sandboxPath}/branch`]); + }); + + it("keeps a discardable build after HTTP 503 and clears it after HTTP 204", async () => { + const requests = mockMaster(); + await mountBuilder(); + await click("Discard"); + await click("Click again to discard"); + + expect(terminal()).toContain("cleanup unavailable"); + expect(rememberedBuild()).toMatchObject({ id: buildId }); + expect(visibleButton("Save snapshot")).toBeDefined(); + + await click("Discard"); + await click("Click again to discard"); + + expect(rememberedBuild()).toBeNull(); + expect(requests.filter((request) => request.startsWith("DELETE "))).toEqual([ + `DELETE ${sandboxPath}`, `DELETE ${sandboxPath}`, + ]); + }); +}); diff --git a/web/console/src/dialogs/BuildSnapshot.tsx b/web/console/src/dialogs/BuildSnapshot.tsx index 42accca2..ecd5a8cb 100644 --- a/web/console/src/dialogs/BuildSnapshot.tsx +++ b/web/console/src/dialogs/BuildSnapshot.tsx @@ -14,7 +14,7 @@ import { useEffect, useLayoutEffect, useReducer, useRef, type KeyboardEvent } from "react"; import { createPortal } from "react-dom"; import type { CreatedSandbox, ExecView, SnapshotView, TemplateEntry } from "../types"; -import { api, ApiError, auth, deleteQuietly } from "../api"; +import { api, apiDelete, ApiError, auth } from "../api"; import { backendName, placeBody, placeNote, placeOptions, templateLabel } from "../backends"; import { errorText, mib } from "../format"; import { st } from "../state"; @@ -24,12 +24,12 @@ import { useArm, useEscape } from "../components/hooks"; interface Build { id: string | null; token: string | null; node: string | null; base: string; cwd: string; - running: boolean; saved: SnapshotView | null; checked: boolean; from: "template" | "snapshot"; hist: string[]; at: number; + running: boolean; saved: SnapshotView | null; cleanupPending: boolean; checked: boolean; from: "template" | "snapshot"; hist: string[]; at: number; } const BD_TIMEOUT = 1800; function loadBuild(): Build { - const bd: Build = { id: null, token: null, node: null, base: "", cwd: "", running: false, saved: null, checked: false, from: "template", hist: [], at: 0 }; + const bd: Build = { id: null, token: null, node: null, base: "", cwd: "", running: false, saved: null, cleanupPending: false, checked: false, from: "template", hist: [], at: 0 }; try { Object.assign(bd, JSON.parse(session.get("sandstorm-build") || "{}")); } catch { /* none kept */ } if (!String(bd.cwd || "").startsWith("/")) bd.cwd = ""; if (!Array.isArray(bd.hist)) bd.hist = []; @@ -37,7 +37,10 @@ function loadBuild(): Build { return bd; } function keepBuild(bd: Build): void { - if (bd.id) session.set("sandstorm-build", JSON.stringify({ id: bd.id, token: bd.token, node: bd.node, base: bd.base, cwd: bd.cwd, hist: bd.hist.slice(-200) })); + if (bd.id) session.set("sandstorm-build", JSON.stringify({ + id: bd.id, token: bd.token, node: bd.node, base: bd.base, cwd: bd.cwd, hist: bd.hist.slice(-200), + cleanupPending: bd.cleanupPending, saved: bd.cleanupPending ? bd.saved : null, + })); else session.remove("sandstorm-build"); } // Escapes a terminal would act on are noise in a page. @@ -68,7 +71,7 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) { const [, render] = useReducer((n: number) => n + 1, 0); const builderStep = render; const termEl = useRef(null), inEl = useRef(null), tagEl = useRef(null); - const cleanupEl = useRef(null), startEl = useRef(null); + const cleanupEl = useRef(null), startEl = useRef(null), retryEl = useRef(null); const openRef = useRef(open); openRef.current = open; const focusIn = useRef(false); const [isArmed, arm, disarm] = useArm(); @@ -122,6 +125,11 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) { } function bdBusy(on: boolean) { b.running = on; if (!on && b.id && openRef.current) focusIn.current = true; builderStep(); } + function clearBuildSandbox() { + b.id = null; b.token = null; b.cwd = ""; b.cleanupPending = false; + keepBuild(b); + } + async function builderOptions() { if (!auth.token) return; try { @@ -141,8 +149,16 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) { // A build left from before a reload: carry on with it if it is still there. if (b.id && !b.checked) { b.checked = true; - try { await api(`/v1/sandboxes/${encodeURIComponent(b.id)}`); termLine("dim", `Carrying on with build sandbox ${b.id}.`); } - catch (e) { if ((e as ApiError).status === 404) { termLine("dim", `Build sandbox ${b.id} is gone; start another.`); b.id = null; keepBuild(b); } } + const id = b.id; + try { + await api(`/v1/sandboxes/${encodeURIComponent(id)}`); + if (b.id === id) termLine("dim", `Carrying on with build sandbox ${id}.`); + } catch (e) { + if ((e as ApiError).status === 404 && b.id === id && !b.running) { + termLine("dim", `Build sandbox ${id} is gone.`); + clearBuildSandbox(); + } + } } } catch (e) { if (String((e as Error).message) !== "401") termLine("bad", errorText(e)); } builderStep(); @@ -154,13 +170,16 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) { useEffect(() => { if (!open) return; void builderOptions(); - const t = setTimeout(() => (b.id ? inEl.current : startEl.current)?.focus(), 30); + const t = setTimeout(() => (b.cleanupPending ? retryEl.current : b.id ? inEl.current : startEl.current)?.focus(), 30); return () => clearTimeout(t); }, [open]); // Closing leaves a build sandbox running, to come back to. useEscape(open, onClose); useEffect(() => { onLive(!!b.id); }); - useLayoutEffect(() => { if (focusIn.current && inEl.current && !inEl.current.disabled) { focusIn.current = false; inEl.current.focus(); } }); + useLayoutEffect(() => { + const target = b.cleanupPending ? retryEl.current : inEl.current; + if (focusIn.current && target && !target.disabled) { focusIn.current = false; target.focus(); } + }); const start = async () => { const from = b.from, base = ui.current.base; @@ -222,8 +241,10 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) { }; const save = async () => { + if (!b.id || b.running || b.cleanupPending) return; const tag = tagEl.current!.value.trim(), why = tagProblem(tag); if (why) { ui.current.tagHint = why; builderStep(); tagEl.current!.focus(); return; } + const cleanup = cleanupEl.current!.checked; bdBusy(true); try { await bdReady(); @@ -232,13 +253,12 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) { b.saved = snap; ui.current.tagHint = ""; termLine("ok", `Saved ${snap.tag} on ${snap.node_id}${snap.size_bytes != null ? ` · ${mib(snap.size_bytes)}` : ""}. A new sandbox forks from it with {"snapshot_tag": "${snap.tag}"}.`); - if (cleanupEl.current!.checked) { - const id = b.id || ""; - await deleteQuietly("/v1/sandboxes/" + encodeURIComponent(id)); - b.id = null; b.token = null; b.cwd = ""; keepBuild(b); - termLine("dim", `Deleted the build sandbox ${id}.`); + if (cleanup) { + b.cleanupPending = true; + keepBuild(b); } onSaved(); + if (cleanup) await deleteBuild(); } catch (e) { termLine("bad", errorText(e)); } finally { bdBusy(false); } }; @@ -253,16 +273,32 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) { finally { bdBusy(false); } }; const again = () => { b.saved = null; termClear(); void builderOptions(); builderStep(); }; + + async function deleteBuild(clearTerminal = false) { + const id = b.id; + if (!id) return; + try { + await apiDelete("/v1/sandboxes/" + encodeURIComponent(id)); + clearBuildSandbox(); + if (clearTerminal) termClear(); + termLine("dim", `Deleted the build sandbox ${id}.`); + } catch (e) { + termLine("bad", `Could not delete the build sandbox ${id}: ${errorText(e)}`); + } + } + + const retryCleanup = async () => { + if (!b.cleanupPending || b.running) return; + bdBusy(true); + try { await deleteBuild(); } + finally { bdBusy(false); } + }; + const discard = async () => { - if (!arm("discard")) return; + if (b.running || b.cleanupPending || !arm("discard")) return; disarm(); bdBusy(true); - try { - await deleteQuietly("/v1/sandboxes/" + encodeURIComponent(b.id || "")); - termLine("dim", `Deleted the build sandbox ${b.id}. Nothing was saved from it.`); - b.id = null; b.token = null; b.cwd = ""; keepBuild(b); - termClear(); - } catch (e) { termLine("bad", errorText(e)); } + try { await deleteBuild(true); } finally { bdBusy(false); } }; const setFrom = (v: "template" | "snapshot") => { @@ -276,6 +312,7 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) { // say), and the save bar under it. The terminal's lines are written to it // directly, so whether it has any is read from it. const live = !!b.id, running = b.running, saved = b.saved; + const cleanupPending = b.cleanupPending; const termHas = !!termEl.current?.childElementCount; const u = ui.current; return createPortal( @@ -283,8 +320,8 @@ export function BuildSnapshot({ open, onClose, onLive, onSaved }: Props) {

Build a snapshot

-
{live ? <>{b.id} on {b.node || "?"} · from {b.base} : saved ? `Saved ${saved.tag}` : ""}
- +
{live ? <>{b.id} on {b.node || "?"} · from {b.base}{cleanupPending && saved && ` · Saved ${saved.tag}`} : saved ? `Saved ${saved.tag}` : ""}
+