|
1 | 1 | // Wizard server-method tests cover stable lifecycle errors for process-local sessions. |
2 | 2 | import { expectDefined } from "@openclaw/normalization-core"; |
3 | 3 | import { describe, expect, it, vi } from "vitest"; |
| 4 | +import { createSafeGatewayRestartPreflight } from "../../infra/restart-coordinator.js"; |
| 5 | +import { |
| 6 | + getActiveGatewayRootWorkCount, |
| 7 | + resetGatewayWorkAdmission, |
| 8 | + runWithGatewayIndependentRootWorkAdmission, |
| 9 | +} from "../../process/gateway-work-admission.js"; |
4 | 10 | import type { RuntimeEnv } from "../../runtime.js"; |
5 | 11 | import { createDeferred } from "../../shared/deferred.js"; |
6 | 12 | import type { WizardPrompter } from "../../wizard/prompts.js"; |
@@ -138,6 +144,44 @@ describe("hosted wizard runtime isolation", () => { |
138 | 144 | }); |
139 | 145 |
|
140 | 146 | describe("wizard setup ownership", () => { |
| 147 | + it("retains gateway work admission between requests until the wizard settles", async () => { |
| 148 | + resetGatewayWorkAdmission(); |
| 149 | + const runnerSettled = createDeferred(); |
| 150 | + const tracker = createWizardSessionTracker(); |
| 151 | + const context = { |
| 152 | + ...tracker, |
| 153 | + wizardRunner: async (_opts: unknown, _runtime: RuntimeEnv, prompter: WizardPrompter) => { |
| 154 | + prompter.progress("working"); |
| 155 | + await runnerSettled.promise; |
| 156 | + }, |
| 157 | + }; |
| 158 | + |
| 159 | + try { |
| 160 | + await runWithGatewayIndependentRootWorkAdmission(async () => { |
| 161 | + const respond = vi.fn(); |
| 162 | + await expectDefined( |
| 163 | + wizardHandlers["wizard.start"], |
| 164 | + "wizard.start test invariant", |
| 165 | + )({ params: { mode: "local" }, respond, context } as never); |
| 166 | + expect(respond.mock.calls[0]?.[1]).toMatchObject({ status: "running" }); |
| 167 | + }); |
| 168 | + |
| 169 | + expect(getActiveGatewayRootWorkCount()).toBe(1); |
| 170 | + expect(createSafeGatewayRestartPreflight()).toMatchObject({ |
| 171 | + safe: false, |
| 172 | + blockers: [expect.objectContaining({ kind: "root-request", count: 1 })], |
| 173 | + }); |
| 174 | + runnerSettled.resolve(); |
| 175 | + await vi.waitFor(() => { |
| 176 | + expect(getActiveGatewayRootWorkCount()).toBe(0); |
| 177 | + }); |
| 178 | + expect(createSafeGatewayRestartPreflight().safe).toBe(true); |
| 179 | + } finally { |
| 180 | + runnerSettled.resolve(); |
| 181 | + resetGatewayWorkAdmission(); |
| 182 | + } |
| 183 | + }); |
| 184 | + |
141 | 185 | it("blocks a replacement wizard until the cancelled runner settles", async () => { |
142 | 186 | const runnerSettled = createDeferred(); |
143 | 187 | const tracker = createWizardSessionTracker(); |
|
0 commit comments