bailinghub 0.9.4 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +6 -6
- package/README.md +6 -6
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_CLIENT_QUICKSTART.en.md +1 -3
- package/docs/AGENT_CLIENT_QUICKSTART.md +1 -1
- package/docs/AGENT_CLIENT_RUNTIME_API.en.md +87 -2
- package/docs/AGENT_CLIENT_RUNTIME_API.md +36 -2
- package/docs/AGENT_KNOWLEDGE_API.en.md +77 -0
- package/docs/AGENT_KNOWLEDGE_API.md +86 -0
- package/docs/AGENT_TASK_CONTROL.md +4 -4
- package/docs/AGENT_TASK_CONTROL_FOUNDATION.md +1 -1
- package/docs/ARCHITECTURE.md +4 -0
- package/docs/CHANGELOG.en.md +24 -1
- package/docs/CHANGELOG.md +24 -1
- package/docs/COMPATIBILITY.en.md +27 -1
- package/docs/CONTRACT.en.md +1 -1
- package/docs/CONTRACT.md +1 -1
- package/docs/IMPLEMENTATION_STATUS.en.md +28 -15
- package/docs/IMPLEMENTATION_STATUS.md +28 -15
- package/docs/INDEPENDENT_VALIDATION.en.md +6 -4
- package/docs/INDEPENDENT_VALIDATION.md +6 -4
- package/docs/INTEGRATION_WALKTHROUGH.md +65 -0
- package/docs/MODEL_BILLING.en.md +2 -0
- package/docs/MODEL_BILLING.md +6 -2
- package/docs/MODEL_CONTINUATION.en.md +54 -0
- package/docs/MODEL_CONTINUATION.md +54 -0
- package/docs/MODEL_OUTPUT_BUDGET.en.md +69 -0
- package/docs/MODEL_OUTPUT_BUDGET.md +69 -0
- package/docs/OPERATIONS.en.md +16 -4
- package/docs/OPERATIONS.md +16 -4
- package/docs/QUICKSTART.md +1 -1
- package/docs/README.en.md +7 -0
- package/docs/README.md +7 -0
- package/docs/RELEASE_NOTES_NEXT.en.md +3 -3
- package/docs/RELEASE_NOTES_NEXT.md +3 -3
- package/docs/RELEASE_NOTES_v0.10.0.en.md +58 -0
- package/docs/RELEASE_NOTES_v0.10.0.md +58 -0
- package/docs/RELEASE_NOTES_v0.10.1.en.md +41 -0
- package/docs/RELEASE_NOTES_v0.10.1.md +41 -0
- package/docs/UPGRADE_PLAN.en.md +118 -0
- package/docs/UPGRADE_PLAN.md +124 -0
- package/docs/UPGRADE_v0.10.0.en.md +47 -0
- package/docs/UPGRADE_v0.10.0.md +47 -0
- package/docs/UPGRADE_v0.10.1.en.md +66 -0
- package/docs/UPGRADE_v0.10.1.md +66 -0
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +38 -22
- package/package.json +10 -5
- package/schemas/tool-definition.schema.json +13 -0
- package/scripts/check-doc-links.mjs +6 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-php-sdk-artifacts.mjs +152 -0
- package/scripts/check-php-sdk-artifacts.test.mjs +99 -0
- package/scripts/check-release-consistency.test.mjs +2 -2
- package/scripts/doctor-upgrade-plan.test.ts +205 -0
- package/scripts/doctor-upgrade-plan.ts +276 -0
- package/scripts/doctor.ts +4 -1
- package/scripts/e2e-console-approval-details.mjs +134 -0
- package/scripts/e2e-console-config-races.mjs +180 -0
- package/scripts/e2e-console-kb-audit.mjs +170 -0
- package/scripts/e2e-console-operations-audit.mjs +152 -0
- package/scripts/e2e-console-runtime-audit.mjs +179 -0
- package/scripts/e2e-console-settings-audit.mjs +125 -0
- package/scripts/e2e-console-troubleshooting-extra.mjs +267 -0
- package/scripts/e2e-console.mjs +476 -7
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +9 -1
- package/scripts/sdk-declaration-contract-test.ts +34 -0
- package/scripts/sdk-p1-check.mjs +62 -26
- package/scripts/verify-github-repo.mjs +8 -0
- package/sdk/dotnet/Bailing.Connect/BailingConnect.cs +4 -4
- package/sdk/dotnet/README.md +8 -0
- package/sdk/dotnet/tests/Declaration/Declaration.csproj +11 -0
- package/sdk/dotnet/tests/Declaration/Program.cs +74 -0
- package/sdk/go/README.md +8 -0
- package/sdk/go/bailingconnect/connect.go +5 -5
- package/sdk/go/bailingconnect/declaration_test.go +107 -0
- package/sdk/java/README.md +13 -0
- package/sdk/java/src/main/java/com/bailing/connect/BailingConnect.java +4 -4
- package/sdk/java/tests/DeclarationTest.java +70 -0
- package/sdk/node/README.md +8 -0
- package/sdk/node/src/index.mjs +4 -4
- package/sdk/node/tests/declaration.test.mjs +41 -0
- package/sdk/php/README.md +16 -0
- package/sdk/php/src/Attributes/AiTool.php +4 -4
- package/sdk/php/src/SpecBuilder.php +8 -8
- package/sdk/php/tests/declaration-serialization.php +103 -0
- package/sdk/php7/README.md +14 -0
- package/sdk/php7/src/ToolDef.php +3 -3
- package/sdk/php7/src/ToolSpec.php +8 -13
- package/sdk/php7/tests/declaration-serialization.php +103 -0
- package/sdk/python/README.md +8 -0
- package/sdk/python/bailing_connect/__init__.py +6 -6
- package/sdk/python/tests/test_declaration.py +61 -0
- package/src/app/agent-client-runtime.test.ts +115 -2
- package/src/app/agent-client-runtime.ts +40 -11
- package/src/app/agent-knowledge.test.ts +171 -0
- package/src/app/agent-knowledge.ts +233 -0
- package/src/app/agent-tool-catalog-revision.test.ts +31 -0
- package/src/app/agent-tool-invocations.test.ts +7 -2
- package/src/app/agent-tool-invocations.ts +67 -7
- package/src/app/approval-continuations.test.ts +49 -1
- package/src/app/http.test.ts +16 -1
- package/src/app/http.ts +3 -3
- package/src/app/kernel-boot-recovery.mysql.test.ts +132 -0
- package/src/app/kernel-boot-recovery.test.ts +157 -0
- package/src/app/kernel.ts +12 -8
- package/src/app/readiness.mysql.test.ts +120 -0
- package/src/app/readiness.test.ts +111 -26
- package/src/app/readiness.ts +26 -22
- package/src/app/runtime-lifecycle.ts +34 -3
- package/src/app/tool-approvals.test.ts +83 -0
- package/src/app/tool-approvals.ts +25 -7
- package/src/app/tool-proxy-payload.test.ts +81 -0
- package/src/app/tool-proxy.ts +24 -2
- package/src/core/config/console-diagnostic-location.test.ts +36 -0
- package/src/core/config/console-form-guard.test.ts +69 -0
- package/src/core/config/console-task-location.test.ts +64 -0
- package/src/core/contracts/explicit-capability-values.test.ts +62 -0
- package/src/core/contracts/openapi-tools.ts +18 -7
- package/src/core/contracts/schema-readiness.ts +11 -0
- package/src/core/contracts/tool-annotations.ts +4 -4
- package/src/core/contracts/tool-definition.ts +26 -0
- package/src/core/contracts/tool-guidance.test.ts +77 -0
- package/src/core/contracts/tool-guidance.ts +31 -0
- package/src/core/contracts/tool-input-limits.ts +15 -0
- package/src/core/contracts/tools-idempotency.test.ts +90 -0
- package/src/core/contracts/tools.ts +52 -9
- package/src/core/runtime/agent-execution-memory.test.ts +64 -0
- package/src/core/runtime/agent-execution-memory.ts +63 -0
- package/src/core/state/state-contracts.ts +3 -0
- package/src/infrastructure/config/config-observability-ledger.ts +2 -0
- package/src/infrastructure/schema/schema-readiness.ts +29 -0
- package/src/infrastructure/state/state-mysql.ts +3 -0
- package/src/modules/usage/contracts.ts +7 -0
- package/src/modules/usage/http.ts +2 -0
- package/src/modules/usage/model-continuation.test.ts +109 -0
- package/src/modules/usage/model-gateway.ts +5 -1
- package/src/modules/usage/output-budget.mysql.test.ts +84 -0
- package/src/modules/usage/output-budget.test.ts +167 -0
- package/src/modules/usage/output-budget.ts +73 -0
- package/src/modules/usage/provider-stream.test.ts +22 -0
- package/src/modules/usage/provider.ts +2 -3
- package/src/modules/usage/repository.ts +6 -0
- package/src/modules/usage/test-harness.ts +4 -2
- package/src/routes/admin-approval-view.test.ts +109 -0
- package/src/routes/admin-approval-view.ts +36 -0
- package/src/routes/admin-readiness.test.ts +52 -0
- package/src/routes/admin-runtime-ux.test.ts +51 -0
- package/src/routes/admin-runtime-ux.ts +25 -0
- package/src/routes/admin-runtime.ts +36 -8
- package/src/routes/admin.ts +9 -0
- package/src/routes/agent-api.test.ts +80 -1
- package/src/routes/agent-api.ts +63 -4
- package/src/routes/agent-tool-detail.test.ts +140 -0
- package/src/routes/public-default.ts +1 -1
- package/src/services/kb-agent.test.ts +84 -0
- package/src/services/kb.ts +73 -0
- package/web/connect/bailing-connect-php.tgz +0 -0
- package/web/connect/bailing-connect-php7.tgz +0 -0
- package/web/console/assets/Accounts-CjIBO3sU.css +1 -0
- package/web/console/assets/Accounts-Dhyw-7wF.js +3 -0
- package/web/console/assets/AgentClients-BA0M26-I.css +1 -0
- package/web/console/assets/AgentClients-DWxb8-ko.js +1 -0
- package/web/console/assets/AgentTasks-DOyxANnx.css +1 -0
- package/web/console/assets/AgentTasks-DUHD4dzr.js +2 -0
- package/web/console/assets/Approvals-Brl-2uJq.css +1 -0
- package/web/console/assets/Approvals-CQx1YWxW.js +1 -0
- package/web/console/assets/Audit--QcdVlMh.js +1 -0
- package/web/console/assets/Audit-DAdmOnIs.css +1 -0
- package/web/console/assets/{BrandLockup-CffORQse.js → BrandLockup-DQcaW4Nt.js} +1 -1
- package/web/console/assets/Channels-DJJU3ksE.css +1 -0
- package/web/console/assets/Channels-cGS5WfQ-.js +105 -0
- package/web/console/assets/ChatEntries-BYpji27B.css +1 -0
- package/web/console/assets/ChatEntries-nh23Iz5O.js +7 -0
- package/web/console/assets/Clients-CX5EeYio.js +3 -0
- package/web/console/assets/Clients-CbZAou8E.css +1 -0
- package/web/console/assets/Cost-C6oQvz9P.css +1 -0
- package/web/console/assets/Cost-DOZfdNS9.js +1 -0
- package/web/console/assets/Credentials--aHs57yV.css +1 -0
- package/web/console/assets/Credentials-sy6W9Sac.js +1 -0
- package/web/console/assets/Diagnostics-CKs27Dnv.css +1 -0
- package/web/console/assets/Diagnostics-CyoM1XrZ.js +1 -0
- package/web/console/assets/Executors-2Upi6bOS.css +1 -0
- package/web/console/assets/Executors-BQqqiFwt.js +1 -0
- package/web/console/assets/HelpTip-DLlhaGQp.js +1 -0
- package/web/console/assets/HelpTip-bbDEyuqV.css +1 -0
- package/web/console/assets/Kb-5R3ce4UU.js +5 -0
- package/web/console/assets/Kb-BM_PYi11.css +1 -0
- package/web/console/assets/{Login-CGgLGTE1.js → Login-YKeUwdgo.js} +1 -1
- package/web/console/assets/Projects-DHwHrPT9.css +1 -0
- package/web/console/assets/Projects-Grgb6fOv.js +1 -0
- package/web/console/assets/Routes-DR_Yf02e.css +1 -0
- package/web/console/assets/Routes-DYgrXlRJ.js +138 -0
- package/web/console/assets/Runs-CwTddJJj.js +3 -0
- package/web/console/assets/Runs-D4FOvNfu.css +1 -0
- package/web/console/assets/Setup-Ca0b1d1-.css +1 -0
- package/web/console/assets/Setup-D_xUPNDq.js +1 -0
- package/web/console/assets/Shell-BTg8Vw_L.css +1 -0
- package/web/console/assets/Shell-Dfam2Uoj.js +1 -0
- package/web/console/assets/StorageBuckets-7QLBpV4a.css +1 -0
- package/web/console/assets/StorageBuckets-CP6e50wI.js +1 -0
- package/web/console/assets/SystemSettings-BRYKyJNa.js +1 -0
- package/web/console/assets/SystemSettings-HsXGx0aH.css +1 -0
- package/web/console/assets/SystemStatus-B-VfRsQd.css +1 -0
- package/web/console/assets/SystemStatus-CbPsDsGt.js +1 -0
- package/web/console/assets/Targets-1j4-g6rC.css +1 -0
- package/web/console/assets/Targets-C2LkR2AF.js +1 -0
- package/web/console/assets/Tools-C9HPJqJb.css +1 -0
- package/web/console/assets/Tools-C9JNJUS0.js +2 -0
- package/web/console/assets/Usage-D1Mv6vGY.js +1 -0
- package/web/console/assets/Usage-DMOzUsqh.css +1 -0
- package/web/console/assets/UsageAccess-77LmGCm6.js +1 -0
- package/web/console/assets/UsageAccess-C6ZGxEgJ.css +1 -0
- package/web/console/assets/{UsageHelp-CzS2gI40.js → UsageHelp-BmuiE1Ew.js} +1 -1
- package/web/console/assets/client-route-draft-DxZRxKPT.js +1 -0
- package/web/console/assets/console-location-Csv-xsnl.js +1 -0
- package/web/console/assets/form-guard-8GrFpry0.js +1 -0
- package/web/console/assets/{index-65JiiUr4.js → index-B_5UfiTw.js} +1 -1
- package/web/console/assets/index-MjZJEFIN.js +2 -0
- package/web/console/assets/{request-DKycpD7z.js → request-rqm6MT0s.js} +1 -1
- package/web/console/assets/runtime-feedback-gPfZVNvY.js +1 -0
- package/web/console/assets/{schema-SCiNxBlR.js → schema-o3mK4mid.js} +1 -1
- package/web/console/assets/task-page-location-DWiGtAln.js +1 -0
- package/web/console/assets/use-list-location-FvLFt0Tq.css +1 -0
- package/web/console/assets/use-list-location-cIPy2cKM.js +1 -0
- package/web/console/assets/use-unsaved-form-DScKD0h9.js +1 -0
- package/web/console/assets/{util-DZYfJ5Zo.js → util-B40VqOwl.js} +1 -1
- package/web/console/assets/{vendor-element-8cVcdt5T.js → vendor-element-BT8tHCFk.js} +1 -1
- package/web/console/assets/{vendor-mammoth-CnDA23N0.js → vendor-mammoth-CVIXVxTN.js} +1 -1
- package/web/console/assets/{vendor-vue-Co7x2FW6.js → vendor-vue-DhbG0vd4.js} +7 -7
- package/web/console/index.html +3 -3
- package/web-admin/package-lock.json +4 -4
- package/web-admin/package.json +1 -1
- package/web-admin/src/client-route-draft.ts +25 -0
- package/web-admin/src/components/AgentSetupPanel.vue +54 -41
- package/web-admin/src/components/HelpTip.vue +4 -1
- package/web-admin/src/components/ListLocationBar.vue +22 -0
- package/web-admin/src/components/NotificationOutboxPanel.vue +35 -7
- package/web-admin/src/console-entry.test.ts +26 -0
- package/web-admin/src/console-entry.ts +20 -0
- package/web-admin/src/console-location.ts +35 -0
- package/web-admin/src/form-guard.ts +35 -0
- package/web-admin/src/layout/Shell.vue +18 -65
- package/web-admin/src/onboarding-state.test.ts +174 -0
- package/web-admin/src/onboarding-state.ts +122 -0
- package/web-admin/src/pages/Accounts.vue +44 -24
- package/web-admin/src/pages/AgentClients.vue +47 -29
- package/web-admin/src/pages/AgentTasks.vue +57 -12
- package/web-admin/src/pages/Approvals.vue +105 -25
- package/web-admin/src/pages/Audit.vue +15 -6
- package/web-admin/src/pages/Channels.vue +136 -43
- package/web-admin/src/pages/ChatEntries.vue +96 -41
- package/web-admin/src/pages/Clients.vue +87 -26
- package/web-admin/src/pages/Cost.vue +15 -4
- package/web-admin/src/pages/Credentials.vue +63 -32
- package/web-admin/src/pages/Diagnostics.vue +103 -54
- package/web-admin/src/pages/Executors.vue +103 -40
- package/web-admin/src/pages/Kb.vue +278 -128
- package/web-admin/src/pages/Projects.vue +44 -16
- package/web-admin/src/pages/Routes.vue +168 -247
- package/web-admin/src/pages/Runs.vue +163 -91
- package/web-admin/src/pages/Setup.vue +182 -291
- package/web-admin/src/pages/StorageBuckets.vue +61 -25
- package/web-admin/src/pages/SystemSettings.vue +76 -51
- package/web-admin/src/pages/SystemStatus.vue +54 -30
- package/web-admin/src/pages/Targets.vue +45 -17
- package/web-admin/src/pages/Tools.vue +133 -68
- package/web-admin/src/pages/Usage.vue +64 -25
- package/web-admin/src/pages/UsageAccess.vue +11 -8
- package/web-admin/src/route-call-snippets.test.ts +82 -0
- package/web-admin/src/route-call-snippets.ts +178 -0
- package/web-admin/src/router.ts +11 -29
- package/web-admin/src/runtime-feedback.ts +43 -0
- package/web-admin/src/task-page-location.ts +66 -0
- package/web-admin/src/usage-output-budget.test.ts +26 -0
- package/web-admin/src/usage-output-budget.ts +46 -0
- package/web-admin/src/use-list-location.ts +24 -0
- package/web-admin/src/use-unsaved-form.ts +38 -0
- package/web-admin/tests/model-output-budget.browser.mjs +69 -0
- package/web/console/assets/Accounts-Bervi5JU.css +0 -1
- package/web/console/assets/Accounts-Dhj6PjXP.js +0 -3
- package/web/console/assets/AgentClients-CMy8StAH.js +0 -1
- package/web/console/assets/AgentClients-i52AI6YV.css +0 -1
- package/web/console/assets/AgentTasks-BsG850Il.css +0 -1
- package/web/console/assets/AgentTasks-DA1xZdmP.js +0 -2
- package/web/console/assets/Approvals-DIsd7R8N.js +0 -1
- package/web/console/assets/Approvals-DlTSHl_7.css +0 -1
- package/web/console/assets/Audit-AUDABLTX.js +0 -1
- package/web/console/assets/Audit-CSu6_3oD.css +0 -1
- package/web/console/assets/Channels-B8rjsM0S.js +0 -105
- package/web/console/assets/Channels-CCn0L1jg.css +0 -1
- package/web/console/assets/ChatEntries-DsYtcXN6.css +0 -1
- package/web/console/assets/ChatEntries-iZjJMEUZ.js +0 -7
- package/web/console/assets/Clients-CSHIsaWU.css +0 -1
- package/web/console/assets/Clients-CwgpGCSD.js +0 -3
- package/web/console/assets/Cost-B2tNxu71.js +0 -1
- package/web/console/assets/Cost-CjT39DSZ.css +0 -1
- package/web/console/assets/Credentials-BuwFB-fV.js +0 -1
- package/web/console/assets/Credentials-ioLP0qYN.css +0 -1
- package/web/console/assets/Diagnostics-Ya05PTDp.css +0 -1
- package/web/console/assets/Diagnostics-z5glms11.js +0 -1
- package/web/console/assets/Executors-Bc4SvjeH.js +0 -1
- package/web/console/assets/Executors-CjhEM54c.css +0 -1
- package/web/console/assets/HelpTip-CA6Bm7Nx.css +0 -1
- package/web/console/assets/HelpTip-Dtdt2tKR.js +0 -1
- package/web/console/assets/Kb-BRbRHxLy.js +0 -5
- package/web/console/assets/Kb-CzIzd9xr.css +0 -1
- package/web/console/assets/Projects-Bm8AjsNx.css +0 -1
- package/web/console/assets/Projects-CPWw3con.js +0 -1
- package/web/console/assets/Routes-CMIaE0Bx.js +0 -124
- package/web/console/assets/Routes-CyXV4Pba.css +0 -1
- package/web/console/assets/Runs-B8HuE700.js +0 -3
- package/web/console/assets/Runs-Bv6CV_Hk.css +0 -1
- package/web/console/assets/Setup-D7nxgn-9.css +0 -1
- package/web/console/assets/Setup-G8RKzliR.js +0 -1
- package/web/console/assets/Shell-DimHgraJ.js +0 -1
- package/web/console/assets/Shell-ykb-tUfo.css +0 -1
- package/web/console/assets/StorageBuckets-CVgpZRWY.css +0 -1
- package/web/console/assets/StorageBuckets-CiVYXIE2.js +0 -1
- package/web/console/assets/SystemSettings-BjiHyrXO.css +0 -1
- package/web/console/assets/SystemSettings-DF8sZNen.js +0 -1
- package/web/console/assets/SystemStatus-BlHywK13.js +0 -1
- package/web/console/assets/SystemStatus-I11I67rw.css +0 -1
- package/web/console/assets/Targets-BXaoPoAJ.js +0 -1
- package/web/console/assets/Targets-DTb5tn6z.css +0 -1
- package/web/console/assets/Tools-B22lNHXq.js +0 -2
- package/web/console/assets/Tools-DU8ei6sd.css +0 -1
- package/web/console/assets/Usage-C02EzoI2.js +0 -1
- package/web/console/assets/Usage-CAeDGjrb.css +0 -1
- package/web/console/assets/UsageAccess-CGGaWTuj.css +0 -1
- package/web/console/assets/UsageAccess-DOb-cyPE.js +0 -1
- package/web/console/assets/index-CK0ZCTZv.js +0 -2
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
4
|
+
import { resolve, join, extname } from 'node:path';
|
|
5
|
+
import { chromium } from 'playwright';
|
|
6
|
+
|
|
7
|
+
// Synthetic server and intercepted API only. Never contacts a deployed hub.
|
|
8
|
+
const assets = resolve(process.env.BAILING_CONSOLE_DIR || 'web/console');
|
|
9
|
+
const mime = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml' };
|
|
10
|
+
const server = createServer((req, res) => {
|
|
11
|
+
const url = new URL(req.url || '/', 'http://localhost');
|
|
12
|
+
let file = resolve(assets, url.pathname.replace(/^\/console\/?/, '') || 'index.html');
|
|
13
|
+
if (!file.startsWith(assets + '/') && file !== assets) { res.writeHead(404).end(); return; }
|
|
14
|
+
if (!existsSync(file) || statSync(file).isDirectory()) file = join(assets, 'index.html');
|
|
15
|
+
res.writeHead(200, { 'content-type': mime[extname(file)] || 'application/octet-stream' }).end(readFileSync(file));
|
|
16
|
+
});
|
|
17
|
+
await new Promise(done => server.listen(0, '127.0.0.1', done));
|
|
18
|
+
const base = `http://127.0.0.1:${server.address().port}`;
|
|
19
|
+
const browser = await chromium.launch({ headless: true });
|
|
20
|
+
|
|
21
|
+
const failures = [];
|
|
22
|
+
const context = await browser.newContext();
|
|
23
|
+
const page = await context.newPage();
|
|
24
|
+
page.setDefaultTimeout(8000);
|
|
25
|
+
page.on('pageerror', e => failures.push(e.message));
|
|
26
|
+
let adminWrites = 0, adminReadFail = false, costFail = true;
|
|
27
|
+
let pendingCost, pendingSummary, pendingRequests, pendingMember;
|
|
28
|
+
let deferCost = false, deferSummary = false, deferRequests = false, deferMember = false;
|
|
29
|
+
const account = id => ({id, label: `账户-${id}`, kind: 'organization', state: 'active'});
|
|
30
|
+
const summary = id => ({ accountId: id, grant: null, plan: null, availableUsd: 0, consumedUsd: 0, currentPeriodConsumedUsd: 0, overageUsd: 0, pendingRequests: 0, resetAt: null, expiresAt: null });
|
|
31
|
+
const cost = days => ({ days, total: { jobs: days, cost_usd: days, tokens: days }, by_day: [], by_target: [], by_route: [] });
|
|
32
|
+
await context.route('**/health', r => r.fulfill({json: {status:'ok', configBackend:true, queue:{}}}));
|
|
33
|
+
await context.route('**/branding', r => r.fulfill({status:404, json:{}}));
|
|
34
|
+
await context.route('**/admin/api/**', async r => {
|
|
35
|
+
const u = new URL(r.request().url()), path = u.pathname, method = r.request().method();
|
|
36
|
+
const json = v => r.fulfill({json:v});
|
|
37
|
+
const fail = v => r.fulfill({status:503,json:{error:v}});
|
|
38
|
+
if (path.endsWith('/me')) return json({username:'fixture-admin',role:'admin',perms:['*']});
|
|
39
|
+
if (path === '/admin/api/admins') {
|
|
40
|
+
if(method === 'POST') { adminWrites++;adminReadFail = true;return json({username:'fixture-new',generated_password:'fixture-generated-only-once'}); }
|
|
41
|
+
return adminReadFail ? fail('fixture_refresh_failed') : json({list:[],roles:['admin','viewer']});
|
|
42
|
+
}
|
|
43
|
+
if (path === '/admin/api/cost') {
|
|
44
|
+
if(costFail) return fail('fixture_cost_failed');
|
|
45
|
+
if(deferCost && u.searchParams.get('days') === '7') { pendingCost = () => json(cost(7));return; }
|
|
46
|
+
return json(cost(Number(u.searchParams.get('days'))));
|
|
47
|
+
}
|
|
48
|
+
if(path === '/admin/api/usage/accounts') return json({items:['a','b'].map(account), next_cursor:null});
|
|
49
|
+
if(path === '/admin/api/usage/billing/plans') return json({items:[],billing_ready:true,period_allowance_supported:true});
|
|
50
|
+
if(path === '/admin/api/usage/services' || path === '/admin/api/usage/issuers') return json({items:[]});
|
|
51
|
+
const s = path.match(/\/billing\/accounts\/(a|b)\/summary$/);
|
|
52
|
+
if(s) {
|
|
53
|
+
if(deferSummary && s[1] === 'a') {pendingSummary = () => fail('STALE_SUMMARY_FAILURE');return;}
|
|
54
|
+
return json(summary(s[1]));
|
|
55
|
+
}
|
|
56
|
+
const q = path.match(/\/billing\/accounts\/(a|b)\/requests$/);
|
|
57
|
+
if(q) {
|
|
58
|
+
if(deferRequests && q[1] === 'a') {pendingRequests = () => fail('STALE_REQUEST_FAILURE');return;}
|
|
59
|
+
return json({items:[],next_cursor:null});
|
|
60
|
+
}
|
|
61
|
+
const m = path.match(/\/usage\/accounts\/(a|b)$/);
|
|
62
|
+
if(m) {
|
|
63
|
+
if(deferMember && m[1] === 'a') {pendingMember = () => fail('STALE_MEMBER_FAILURE');return;}
|
|
64
|
+
return json({account:account(m[1]),members:[]});
|
|
65
|
+
}
|
|
66
|
+
if(path.endsWith('/capabilities'))return json({});
|
|
67
|
+
if(path.endsWith('/status'))return json({executors:[]});
|
|
68
|
+
if(path.startsWith('/admin/api/config-schemas/'))return json({required:[],properties:{}});
|
|
69
|
+
assert.equal(method,'GET',`Unexpected mutation ${method} ${path}`);
|
|
70
|
+
return json([]);
|
|
71
|
+
});
|
|
72
|
+
async function until(check) {
|
|
73
|
+
for(let i=0;i<100;i++){if(check())return;await new Promise(r=>setTimeout(r,20));}
|
|
74
|
+
throw new Error('Fixture request not reached');
|
|
75
|
+
}
|
|
76
|
+
async function closeDrawer() {
|
|
77
|
+
await page.locator('.el-drawer__close-btn:visible').click();
|
|
78
|
+
await page.locator('.el-drawer:visible').waitFor({state:'hidden'});
|
|
79
|
+
await page.locator('.el-overlay:visible').first().waitFor({state:'hidden'});
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
await page.goto(`${base}/console/accounts`);
|
|
83
|
+
await page.getByRole('button',{name:'新建账号',exact:true}).click();
|
|
84
|
+
let drawer = page.getByRole('dialog',{name:'新建账号',exact:true});
|
|
85
|
+
await drawer.getByPlaceholder('如 ops-admin').fill('fixture-new');
|
|
86
|
+
await drawer.getByRole('button',{name:'取消',exact:true}).click();
|
|
87
|
+
await page.locator('.el-message-box').getByRole('button',{name:'继续编辑',exact:true}).click();
|
|
88
|
+
assert.equal(await drawer.getByPlaceholder('如 ops-admin').inputValue(),'fixture-new');
|
|
89
|
+
await drawer.getByRole('button',{name:'保存',exact:true}).click();
|
|
90
|
+
await page.locator('.el-message-box').getByText('fixture-generated-only-once',{exact:false}).waitFor();
|
|
91
|
+
await page.getByText('fixture_refresh_failed',{exact:true}).waitFor();
|
|
92
|
+
assert.equal(adminWrites,1);
|
|
93
|
+
await page.locator('.el-message-box__headerbtn').click();
|
|
94
|
+
await page.locator('.el-overlay:visible').first().waitFor({state:'hidden'});
|
|
95
|
+
|
|
96
|
+
await page.goto(`${base}/console/cost`);
|
|
97
|
+
await page.getByText('成本数据读取失败',{exact:true}).waitFor();
|
|
98
|
+
assert.equal(await page.locator('.overview').count(),0,'failed read must not show zero cost');
|
|
99
|
+
costFail=false;
|
|
100
|
+
await page.getByRole('button',{name:'刷新',exact:true}).click();
|
|
101
|
+
await page.locator('.metric.primary').getByText('30 天窗口',{exact:true}).waitFor();
|
|
102
|
+
deferCost=true;
|
|
103
|
+
await page.locator('.head .el-select').click();
|
|
104
|
+
await page.getByRole('option',{name:'近 7 天',exact:true}).click();
|
|
105
|
+
await until(()=>pendingCost);
|
|
106
|
+
await page.locator('.head .el-select').click();
|
|
107
|
+
await page.getByRole('option',{name:'近 90 天',exact:true}).click();
|
|
108
|
+
await page.locator('.metric.primary').getByText('90 天窗口',{exact:true}).waitFor();
|
|
109
|
+
await pendingCost();
|
|
110
|
+
await page.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r))));
|
|
111
|
+
assert.equal(await page.locator('.metric.primary em').innerText(),'90 天窗口');
|
|
112
|
+
costFail=true;
|
|
113
|
+
await page.getByRole('button',{name:'刷新',exact:true}).click();
|
|
114
|
+
await page.getByText('以下为上次读取的 90 天旧快照',{exact:false}).waitFor();
|
|
115
|
+
|
|
116
|
+
await page.goto(`${base}/console/usage`);
|
|
117
|
+
await page.getByRole('tab',{name:'账户用量',exact:true}).click();
|
|
118
|
+
deferSummary=true;
|
|
119
|
+
await page.getByRole('button',{name:'账户-a',exact:true}).click();
|
|
120
|
+
await until(()=>pendingSummary);
|
|
121
|
+
await closeDrawer();
|
|
122
|
+
await page.getByRole('button',{name:'账户-b',exact:true}).click();
|
|
123
|
+
await page.getByRole('dialog',{name:'账户-b',exact:true}).getByRole('heading',{name:'尚未开通套餐',exact:true}).waitFor();
|
|
124
|
+
await pendingSummary();
|
|
125
|
+
await page.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r))));
|
|
126
|
+
assert.equal(await page.getByText('STALE_SUMMARY_FAILURE',{exact:false}).count(),0);
|
|
127
|
+
await closeDrawer();
|
|
128
|
+
deferSummary=false;deferRequests=true;
|
|
129
|
+
await page.getByRole('button',{name:'账户-a',exact:true}).click();
|
|
130
|
+
await until(()=>pendingRequests);
|
|
131
|
+
await closeDrawer();
|
|
132
|
+
await page.getByRole('button',{name:'账户-b',exact:true}).click();
|
|
133
|
+
await page.getByRole('dialog',{name:'账户-b',exact:true}).getByRole('heading',{name:'尚未开通套餐',exact:true}).waitFor();
|
|
134
|
+
await pendingRequests();
|
|
135
|
+
await page.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r))));
|
|
136
|
+
assert.equal(await page.getByText('STALE_REQUEST_FAILURE',{exact:false}).count(),0);
|
|
137
|
+
|
|
138
|
+
await page.goto(`${base}/console/usage-access?tab=accounts`);
|
|
139
|
+
deferMember=true;
|
|
140
|
+
await page.getByRole('button',{name:'账户-a',exact:true}).click();
|
|
141
|
+
await until(()=>pendingMember);
|
|
142
|
+
await closeDrawer();
|
|
143
|
+
await page.getByRole('button',{name:'账户-b',exact:true}).click();
|
|
144
|
+
await page.getByRole('dialog',{name:'账户-b',exact:true}).waitFor();
|
|
145
|
+
await pendingMember();
|
|
146
|
+
await page.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r))));
|
|
147
|
+
assert.equal(await page.getByText('STALE_MEMBER_FAILURE',{exact:false}).count(),0);
|
|
148
|
+
assert.deepEqual(failures,[]);
|
|
149
|
+
console.log('✓ admin password survives failed refresh; draft protection; cost failures/race; account detail ownership');
|
|
150
|
+
} finally {
|
|
151
|
+
await browser.close(); await new Promise(r=>server.close(r));
|
|
152
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
4
|
+
import { resolve, join, extname } from 'node:path';
|
|
5
|
+
import { chromium } from 'playwright';
|
|
6
|
+
|
|
7
|
+
// Synthetic server and intercepted API only. Never contacts a deployed hub.
|
|
8
|
+
const assets = resolve(process.env.BAILING_CONSOLE_DIR || 'web/console');
|
|
9
|
+
const mime = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml' };
|
|
10
|
+
const server = createServer((req, res) => {
|
|
11
|
+
const url = new URL(req.url || '/', 'http://localhost');
|
|
12
|
+
let file = resolve(assets, url.pathname.replace(/^\/console\/?/, '') || 'index.html');
|
|
13
|
+
if (!file.startsWith(assets + '/') && file !== assets) { res.writeHead(404).end(); return; }
|
|
14
|
+
if (!existsSync(file) || statSync(file).isDirectory()) file = join(assets, 'index.html');
|
|
15
|
+
res.writeHead(200, { 'content-type': mime[extname(file)] || 'application/octet-stream' }).end(readFileSync(file));
|
|
16
|
+
});
|
|
17
|
+
await new Promise(done => server.listen(0, '127.0.0.1', done));
|
|
18
|
+
const base = `http://127.0.0.1:${server.address().port}`;
|
|
19
|
+
const browser = await chromium.launch({ headless: true });
|
|
20
|
+
const now = new Date().toISOString();
|
|
21
|
+
const failures = [];
|
|
22
|
+
let writes = 0;
|
|
23
|
+
async function scenario(readonly = false) {
|
|
24
|
+
const context = await browser.newContext();
|
|
25
|
+
let tokenFails = false, dispatchFails = false, saveFails = false, revealReads = 0, releaseFirstToken;
|
|
26
|
+
const firstTokenGate = new Promise(done => { releaseFirstToken = done; });
|
|
27
|
+
let releaseChannelWrite, releaseRuleWrite;
|
|
28
|
+
const channelWriteGate = new Promise(done => { releaseChannelWrite = done; });
|
|
29
|
+
const ruleWriteGate = new Promise(done => { releaseRuleWrite = done; });
|
|
30
|
+
const page = await context.newPage();
|
|
31
|
+
page.setDefaultTimeout(8000);
|
|
32
|
+
page.on('pageerror', error => failures.push(error.message));
|
|
33
|
+
await context.route('**/health', route => route.fulfill({ json: { status: 'ok', configBackend: true, queue: {} } }));
|
|
34
|
+
await context.route('**/admin/api/**', async route => {
|
|
35
|
+
const url = new URL(route.request().url()), path = url.pathname, method = route.request().method();
|
|
36
|
+
const json = value => route.fulfill({ json: value });
|
|
37
|
+
const fail = message => route.fulfill({ status: 503, json: { error: message } });
|
|
38
|
+
if (path === '/admin/api/me') return json({ username: readonly ? 'reader' : 'operator', role: readonly ? 'viewer' : 'admin', perms: readonly ? ['runs:read', 'channels:read'] : ['*'] });
|
|
39
|
+
if (path === '/admin/api/executor-tokens') {
|
|
40
|
+
if (method !== 'GET') { writes++; return saveFails ? fail('fixture_save_failed') : json({ token: 'demo-not-a-real-token' }); }
|
|
41
|
+
return tokenFails ? fail('fixture_token_read_failed') : json([{ name: 'fixture-worker', token: '****', enabled: true, allowed_targets: ['fixture-target'], description: '测试令牌' }]);
|
|
42
|
+
}
|
|
43
|
+
if (path === '/admin/api/dispatch-status') return dispatchFails ? fail('fixture_dispatch_read_failed') : json({ now, summary: { queued: 2, running: 0, dispatched: 0, delayed_queued: 0, expired_leases: 0, blocked_threads: 0 }, by_target: [], leases: [], blocked_threads: [] });
|
|
44
|
+
if (path === '/admin/api/executors') return json([{ executor_id: 'fixture-worker-online', online: true, targets: ['fixture-target'], last_seen_at: now, capabilities: {} }]);
|
|
45
|
+
if (path === '/admin/api/channels') {
|
|
46
|
+
if (method !== 'GET') { writes++; await channelWriteGate; return fail('fixture_channel_save_failed'); }
|
|
47
|
+
return json([{ name: 'fixture-channel', kind: 'wecom', route_key: 'fixture-route', enabled: true, config: { corpid: 'fixture', agentid: '1', has_secret: true } }]);
|
|
48
|
+
}
|
|
49
|
+
if (path === '/admin/api/alert-rules') {
|
|
50
|
+
if (method !== 'GET') { writes++; await ruleWriteGate; return fail('fixture_rule_save_failed'); }
|
|
51
|
+
return json([{ id: 1, channel: 'fixture-channel', event_prefix: 'executor_offline', recipients: ['fixture-operator'], enabled: true, cooldown_min: 30 }]);
|
|
52
|
+
}
|
|
53
|
+
if (path === '/admin/api/clients') return json(['a', 'b'].map(id => ({ app_id: `fixture-${id}`, name: `接入方 ${id.toUpperCase()}`, allowed_channels: ['fixture-channel'] })));
|
|
54
|
+
if (/^\/admin\/api\/clients\/fixture-[ab]\/token$/.test(path)) {
|
|
55
|
+
revealReads++;
|
|
56
|
+
if (path.includes('fixture-a/')) await firstTokenGate;
|
|
57
|
+
return json({ token: path.includes('fixture-a/') ? 'demo-token-A' : 'demo-token-B' });
|
|
58
|
+
}
|
|
59
|
+
if (path === '/admin/api/targets') { assert.equal(readonly, false, 'viewer must not request unavailable target directory'); return json([{ name: 'fixture-target', kind: 'executor' }]); }
|
|
60
|
+
if (path.startsWith('/admin/api/config-schemas/')) return json({ required: [], properties: {} });
|
|
61
|
+
if (path === '/admin/api/status') return json({ executors: [] });
|
|
62
|
+
if (path === '/admin/api/capabilities') return json({});
|
|
63
|
+
if (path === '/admin/api/instance-branding') return json({});
|
|
64
|
+
if (method !== 'GET') { writes++; throw new Error(`Unexpected mutation ${method} ${path}`); }
|
|
65
|
+
return json([]);
|
|
66
|
+
});
|
|
67
|
+
const tokens = () => page.locator('#executor-tokens');
|
|
68
|
+
const dispatch = () => page.locator('#dispatch');
|
|
69
|
+
const drawer = () => page.getByRole('dialog', { name: '编辑令牌', exact: true });
|
|
70
|
+
await page.goto(`${base}/console/executors`);
|
|
71
|
+
await tokens().getByText('fixture-worker', { exact: true }).waitFor();
|
|
72
|
+
await dispatch().locator('.dispatchStats').waitFor();
|
|
73
|
+
if (readonly) {
|
|
74
|
+
for (const name of ['签发令牌', '复制完整令牌', '编辑', '注销']) assert.equal(await page.getByRole('button', { name, exact: true }).count(), 0, `viewer saw ${name}`);
|
|
75
|
+
await page.goto(`${base}/console/channels`);
|
|
76
|
+
await page.getByText('fixture-channel', { exact: true }).first().waitFor();
|
|
77
|
+
for (const name of ['新建渠道', '新建规则', '编辑', '删']) assert.equal(await page.getByRole('button', { name, exact: true }).count(), 0, `channel reader saw ${name}`);
|
|
78
|
+
await page.getByRole('button', { name: '调用代码', exact: true }).click();
|
|
79
|
+
await page.getByText('当前账号不能读取接入方目录;代码保留 token 占位,请由管理员核对推送授权。', { exact: true }).waitFor();
|
|
80
|
+
assert.equal(await page.getByText('还没有接入方被授权推送', { exact: false }).count(), 0, 'missing directory permission is not no authorization');
|
|
81
|
+
assert.equal(revealReads, 0);
|
|
82
|
+
releaseFirstToken(); await context.close(); return;
|
|
83
|
+
}
|
|
84
|
+
// First-load failure must not be described as an empty registry or a healthy zero queue.
|
|
85
|
+
tokenFails = dispatchFails = true;
|
|
86
|
+
await page.reload();
|
|
87
|
+
await tokens().getByText('令牌读取失败', { exact: true }).waitFor();
|
|
88
|
+
await dispatch().getByText('调度租约读取失败', { exact: true }).waitFor();
|
|
89
|
+
assert.equal(await tokens().getByText('还没有执行器令牌。', { exact: false }).count(), 0);
|
|
90
|
+
assert.equal(await dispatch().locator('.dispatchStats').count(), 0);
|
|
91
|
+
assert.equal(await dispatch().getByText('暂无在途租约', { exact: true }).count(), 0);
|
|
92
|
+
// Retry restores normal data; later failures retain and explicitly label the old snapshot.
|
|
93
|
+
tokenFails = dispatchFails = false;
|
|
94
|
+
await tokens().getByRole('button', { name: '刷新令牌', exact: true }).click();
|
|
95
|
+
await dispatch().getByRole('button', { name: '刷新', exact: true }).click();
|
|
96
|
+
await tokens().getByText('fixture-worker', { exact: true }).waitFor();
|
|
97
|
+
await dispatch().locator('.dispatchStats').waitFor();
|
|
98
|
+
tokenFails = dispatchFails = true;
|
|
99
|
+
await tokens().getByRole('button', { name: '刷新令牌', exact: true }).click();
|
|
100
|
+
await dispatch().getByRole('button', { name: '刷新', exact: true }).click();
|
|
101
|
+
await tokens().getByText('以下为上次读取的旧快照', { exact: false }).waitFor();
|
|
102
|
+
await dispatch().getByText('以下为上次读取的旧快照', { exact: false }).waitFor();
|
|
103
|
+
assert.equal(await tokens().getByRole('button', { name: '编辑', exact: true }).isEnabled(), false);
|
|
104
|
+
tokenFails = dispatchFails = false;
|
|
105
|
+
await tokens().getByRole('button', { name: '刷新令牌', exact: true }).click();
|
|
106
|
+
await tokens().getByRole('button', { name: '编辑', exact: true }).click();
|
|
107
|
+
const description = drawer().getByPlaceholder('如 开发环境 worker / 合作方执行器', { exact: true });
|
|
108
|
+
await description.fill('保留这一段修改');
|
|
109
|
+
await drawer().getByRole('button', { name: '取消', exact: true }).click();
|
|
110
|
+
await page.locator('.el-message-box').getByRole('button', { name: '继续编辑', exact: true }).click();
|
|
111
|
+
assert.equal(await description.inputValue(), '保留这一段修改');
|
|
112
|
+
saveFails = true;
|
|
113
|
+
await drawer().getByRole('button', { name: '保存', exact: true }).click();
|
|
114
|
+
await drawer().getByText('fixture_save_failed', { exact: true }).waitFor();
|
|
115
|
+
assert.equal(await description.inputValue(), '保留这一段修改');
|
|
116
|
+
await drawer().locator('.el-drawer__close-btn').click();
|
|
117
|
+
await page.locator('.el-message-box').getByRole('button', { name: '放弃修改', exact: true }).click();
|
|
118
|
+
await drawer().waitFor({ state: 'hidden' });
|
|
119
|
+
// Channel code must not combine B's selected identity with A's delayed credential.
|
|
120
|
+
await page.goto(`${base}/console/channels`);
|
|
121
|
+
await page.getByRole('button', { name: '调用代码', exact: true }).click();
|
|
122
|
+
const code = page.getByRole('dialog', { name: '调用代码 · 经「fixture-channel」渠道主动推消息', exact: true });
|
|
123
|
+
await code.getByText('正在读取所选接入方凭证,代码暂用占位符。', { exact: true }).waitFor();
|
|
124
|
+
await code.locator('.code-context-select .el-select__wrapper').click();
|
|
125
|
+
await page.getByRole('option', { name: '接入方 B(fixture-b)', exact: true }).click();
|
|
126
|
+
await code.locator('.snippet-code').first().filter({ hasText: 'demo-token-B' }).waitFor();
|
|
127
|
+
const firstTokenResponse = page.waitForResponse(response => response.url().endsWith('/admin/api/clients/fixture-a/token'));
|
|
128
|
+
releaseFirstToken();
|
|
129
|
+
await firstTokenResponse;
|
|
130
|
+
await page.evaluate(() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done))));
|
|
131
|
+
assert.equal(await code.locator('.snippet-code').first().textContent().then(text => text.includes('demo-token-A')), false);
|
|
132
|
+
assert.equal(await code.locator('.snippet-code').first().textContent().then(text => text.includes('demo-token-B')), true);
|
|
133
|
+
assert.equal(revealReads, 2);
|
|
134
|
+
await code.locator('.el-dialog__headerbtn').click();
|
|
135
|
+
await code.waitFor({ state: 'hidden' });
|
|
136
|
+
// Both channel and alert-rule editors keep drafts on cancel/failed saves,
|
|
137
|
+
// and cannot be edited or dismissed (X, backdrop, Escape) while saving.
|
|
138
|
+
for (const isRule of [false, true]) {
|
|
139
|
+
const scope = isRule ? page.locator('#alert-rules') : page.locator('.el-card').first();
|
|
140
|
+
await scope.getByRole('button', { name: '编辑', exact: true }).click();
|
|
141
|
+
const editor = page.getByRole('dialog', { name: isRule ? '编辑告警规则' : '编辑渠道', exact: true });
|
|
142
|
+
if (!isRule) await editor.getByRole('tab', { name: '发布', exact: true }).click();
|
|
143
|
+
const notes = isRule ? editor.getByRole('textbox', { name: '说明(可选)', exact: true }) : editor.getByRole('tabpanel', { name: '发布', exact: true }).getByRole('textbox');
|
|
144
|
+
const draft = isRule ? '保留告警草稿' : '保留渠道草稿';
|
|
145
|
+
await notes.fill(draft);
|
|
146
|
+
await editor.getByRole('button', { name: '取消', exact: true }).click();
|
|
147
|
+
await page.locator('.el-message-box').getByRole('button', { name: '继续编辑', exact: true }).click();
|
|
148
|
+
assert.equal(await notes.inputValue(), draft);
|
|
149
|
+
const saveRequest = page.waitForRequest(request => request.method() === 'POST' && request.url().endsWith(isRule ? '/admin/api/alert-rules' : '/admin/api/channels'));
|
|
150
|
+
await editor.getByRole('button', { name: '保存', exact: true }).click();
|
|
151
|
+
await saveRequest;
|
|
152
|
+
assert.equal(await notes.isDisabled(), true, 'saving must lock editor inputs');
|
|
153
|
+
assert.equal(await editor.getByRole('button', { name: '取消', exact: true }).isDisabled(), true);
|
|
154
|
+
await editor.locator('.el-drawer__close-btn').click();
|
|
155
|
+
assert.equal(await editor.isVisible(), true, 'saving must block X');
|
|
156
|
+
await page.locator('.el-overlay').filter({ has: editor }).click({ position: { x: 5, y: 5 } });
|
|
157
|
+
assert.equal(await editor.isVisible(), true, 'saving must block backdrop');
|
|
158
|
+
await page.keyboard.press('Escape');
|
|
159
|
+
assert.equal(await editor.isVisible(), true, 'saving must block Escape');
|
|
160
|
+
if (isRule) releaseRuleWrite(); else releaseChannelWrite();
|
|
161
|
+
await editor.getByText(isRule ? 'fixture_rule_save_failed' : 'fixture_channel_save_failed', { exact: true }).waitFor();
|
|
162
|
+
assert.equal(await notes.inputValue(), draft, 'failed save must retain draft');
|
|
163
|
+
assert.equal(await notes.isEnabled(), true, 'failed save must allow retry');
|
|
164
|
+
await editor.locator('.el-drawer__close-btn').click();
|
|
165
|
+
await page.locator('.el-message-box').getByRole('button', { name: '放弃修改', exact: true }).click();
|
|
166
|
+
await editor.waitFor({ state: 'hidden' });
|
|
167
|
+
}
|
|
168
|
+
await context.close();
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
await scenario(true);
|
|
172
|
+
await scenario(false);
|
|
173
|
+
assert.equal(writes, 3, 'only the three deliberate failed fixture saves should write');
|
|
174
|
+
assert.deepEqual(failures, []);
|
|
175
|
+
console.log('✓ executor final audit: read-only permissions, honest failed reads/retry/stale snapshots, drawer draft protection/save error retention, channel read-only boundaries, credential response ownership and both channel/rule drawer draft/busy/error protections');
|
|
176
|
+
} finally {
|
|
177
|
+
await browser.close();
|
|
178
|
+
await new Promise(done => server.close(done));
|
|
179
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
4
|
+
import { resolve, join, extname } from 'node:path';
|
|
5
|
+
import { chromium } from 'playwright';
|
|
6
|
+
|
|
7
|
+
// Fully synthetic API and files; never saves branding to an actual hub.
|
|
8
|
+
const assets = resolve(process.env.BAILING_CONSOLE_DIR || 'web/console');
|
|
9
|
+
const mime = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml' };
|
|
10
|
+
const server = createServer((req, res) => {
|
|
11
|
+
const url = new URL(req.url || '/', 'http://localhost');
|
|
12
|
+
let file = resolve(assets, url.pathname.replace(/^\/console\/?/, '') || 'index.html');
|
|
13
|
+
if (!file.startsWith(assets + '/') && file !== assets) { res.writeHead(404).end(); return; }
|
|
14
|
+
if (!existsSync(file) || statSync(file).isDirectory()) file = join(assets, 'index.html');
|
|
15
|
+
res.writeHead(200, { 'content-type': mime[extname(file)] || 'application/octet-stream' }).end(readFileSync(file));
|
|
16
|
+
});
|
|
17
|
+
await new Promise(done => server.listen(0, '127.0.0.1', done));
|
|
18
|
+
const base = `http://127.0.0.1:${server.address().port}`;
|
|
19
|
+
const browser = await chromium.launch({ headless: true });
|
|
20
|
+
const context = await browser.newContext();
|
|
21
|
+
await context.addInitScript(() => {
|
|
22
|
+
const Reader = window.FileReader;
|
|
23
|
+
window.__pendingBrandingReads = [];
|
|
24
|
+
window.__completedBrandingReads = 0;
|
|
25
|
+
window.FileReader = class extends Reader {
|
|
26
|
+
readAsDataURL(file) {
|
|
27
|
+
this.addEventListener('loadend', () => { window.__completedBrandingReads++; });
|
|
28
|
+
window.__pendingBrandingReads.push(() => super.readAsDataURL(file));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
const page = await context.newPage();
|
|
33
|
+
page.setDefaultTimeout(8000);
|
|
34
|
+
const errors = [], writes = [];
|
|
35
|
+
page.on('pageerror', error => errors.push(error.message));
|
|
36
|
+
let readFails = true, saveFails = false, holdSave = false, releaseSave;
|
|
37
|
+
let branding = { site_name: '原实例名称', browser_title: '原浏览器标题', site_description: '', site_keywords: [], login_heading: '原登录标题', login_subheading: '', has_logo: false, has_favicon: false, logo_url: null, favicon_url: null, revision: 'fixture', updated_at: null };
|
|
38
|
+
await context.route('**/health', route => route.fulfill({ json: { status: 'ok', configBackend: true, queue: {} } }));
|
|
39
|
+
await context.route('**/admin/api/**', async route => {
|
|
40
|
+
const path = new URL(route.request().url()).pathname;
|
|
41
|
+
const json = value => route.fulfill({ json: value });
|
|
42
|
+
if (path === '/admin/api/me') return json({ username: 'fixture', role: 'admin', perms: ['*'] });
|
|
43
|
+
if (path === '/admin/api/instance-branding') {
|
|
44
|
+
if (route.request().method() === 'PUT') {
|
|
45
|
+
const payload = route.request().postDataJSON(); writes.push(payload);
|
|
46
|
+
if (holdSave) await new Promise(done => { releaseSave = done; });
|
|
47
|
+
if (saveFails) return route.fulfill({ status: 503, json: { error: 'fixture_save_failed' } });
|
|
48
|
+
branding = { ...branding, ...payload }; delete branding.logo_data_url; delete branding.favicon_data_url;
|
|
49
|
+
return json({ branding, management: { source: 'local', writable: true } });
|
|
50
|
+
}
|
|
51
|
+
if (readFails) return route.fulfill({ status: 503, json: { error: 'fixture_read_failed' } });
|
|
52
|
+
return json({ branding, management: { source: 'local', writable: true } });
|
|
53
|
+
}
|
|
54
|
+
if (path === '/admin/api/status') return json({ executors: [] });
|
|
55
|
+
if (path === '/admin/api/conversation-audits') return json({ items: [], has_more: false, next_offset: null });
|
|
56
|
+
if (path.startsWith('/admin/api/config-schemas/')) return json({ required: [], properties: {} });
|
|
57
|
+
if (route.request().method() !== 'GET') throw new Error(`Unexpected mutation ${path}`);
|
|
58
|
+
return json([]);
|
|
59
|
+
});
|
|
60
|
+
const form = page.locator('.settings-page');
|
|
61
|
+
const name = form.getByRole('textbox', { name: '网站名称', exact: true });
|
|
62
|
+
const refresh = form.getByRole('button', { name: '刷新', exact: true });
|
|
63
|
+
const save = form.getByRole('button', { name: '保存设置', exact: true });
|
|
64
|
+
const prompt = () => page.locator('.el-message-box');
|
|
65
|
+
try {
|
|
66
|
+
await page.goto(`${base}/console/settings`);
|
|
67
|
+
await form.getByText('实例外观读取失败', { exact: true }).waitFor();
|
|
68
|
+
assert.equal(await name.isEnabled(), false);
|
|
69
|
+
assert.equal(await save.count(), 0);
|
|
70
|
+
readFails = false;
|
|
71
|
+
await refresh.click();
|
|
72
|
+
await name.waitFor();
|
|
73
|
+
await page.waitForFunction(() => document.querySelector('.settings-page input[placeholder="如:企业智能运营中枢"]')?.value === '原实例名称');
|
|
74
|
+
await name.fill('保留的实例名称草稿');
|
|
75
|
+
await refresh.click();
|
|
76
|
+
await prompt().getByRole('button', { name: '继续编辑', exact: true }).click();
|
|
77
|
+
assert.equal(await name.inputValue(), '保留的实例名称草稿');
|
|
78
|
+
await page.getByRole('menuitem', { name: '任务', exact: true }).click();
|
|
79
|
+
await prompt().getByRole('button', { name: '继续编辑', exact: true }).click();
|
|
80
|
+
assert.equal(new URL(page.url()).pathname, '/console/settings');
|
|
81
|
+
assert.equal(await name.inputValue(), '保留的实例名称草稿');
|
|
82
|
+
// Failed refresh retains the draft rather than clearing it after confirmation.
|
|
83
|
+
readFails = true;
|
|
84
|
+
await refresh.click();
|
|
85
|
+
await prompt().getByRole('button', { name: '放弃修改', exact: true }).click();
|
|
86
|
+
await form.getByText('当前保留上次读取的内容和未保存修改', { exact: false }).waitFor();
|
|
87
|
+
assert.equal(await name.inputValue(), '保留的实例名称草稿');
|
|
88
|
+
readFails = false;
|
|
89
|
+
saveFails = true;
|
|
90
|
+
await save.click();
|
|
91
|
+
await form.getByText('实例外观保存未完成', { exact: true }).waitFor();
|
|
92
|
+
assert.equal(await name.inputValue(), '保留的实例名称草稿');
|
|
93
|
+
// A pending save freezes editing and refresh; only one mutation is issued.
|
|
94
|
+
saveFails = false; holdSave = true;
|
|
95
|
+
await save.click();
|
|
96
|
+
await page.waitForFunction(() => document.querySelector('.settings-page input[placeholder="如:企业智能运营中枢"]')?.disabled);
|
|
97
|
+
assert.equal(await refresh.isEnabled(), false);
|
|
98
|
+
assert.equal(await form.getByRole('button', { name: '选择图片', exact: true }).isEnabled(), false);
|
|
99
|
+
await save.evaluate(button => button.click());
|
|
100
|
+
assert.equal(writes.length, 2);
|
|
101
|
+
while (!releaseSave) await new Promise(done => setTimeout(done, 10));
|
|
102
|
+
holdSave = false; releaseSave();
|
|
103
|
+
await page.waitForFunction(() => !document.querySelector('.settings-page input[placeholder="如:企业智能运营中枢"]')?.disabled);
|
|
104
|
+
assert.equal(await form.getByText('有未保存修改', { exact: true }).count(), 0);
|
|
105
|
+
// Remove a still-reading image, save the removal, then resolve the old FileReader.
|
|
106
|
+
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aB1sAAAAASUVORK5CYII=', 'base64');
|
|
107
|
+
await form.locator('input[type="file"]').first().setInputFiles({ name: 'fixture.png', mimeType: 'image/png', buffer: png });
|
|
108
|
+
await form.getByText('正在读取图片…', { exact: true }).waitFor();
|
|
109
|
+
assert.equal(await save.isEnabled(), false);
|
|
110
|
+
await form.locator('.asset-grid .el-card').first().getByRole('button', { name: '移除', exact: true }).click();
|
|
111
|
+
await save.click();
|
|
112
|
+
await page.waitForFunction(() => !document.querySelector('.settings-page input[placeholder="如:企业智能运营中枢"]')?.disabled);
|
|
113
|
+
assert.equal(writes.at(-1).logo_data_url, null);
|
|
114
|
+
await page.evaluate(() => window.__pendingBrandingReads.shift()());
|
|
115
|
+
await page.waitForFunction(() => window.__completedBrandingReads === 1);
|
|
116
|
+
await page.evaluate(() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done))));
|
|
117
|
+
assert.equal(await form.locator('.logo-preview img').count(), 0);
|
|
118
|
+
assert.equal(await form.getByText('有未保存修改', { exact: true }).count(), 0);
|
|
119
|
+
assert.equal(writes.length, 3);
|
|
120
|
+
assert.deepEqual(errors, []);
|
|
121
|
+
console.log('✓ instance branding: initial read failure, refresh/route draft protection, retained save errors, busy lock and removed-image late-read isolation');
|
|
122
|
+
} finally {
|
|
123
|
+
releaseSave?.();
|
|
124
|
+
await context.close(); await browser.close(); await new Promise(done => server.close(done));
|
|
125
|
+
}
|