|
1 | 1 | // Configure wizard tests keep workspace-owned effects on the configured default agent. |
2 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 3 | +import { retainLegacyDefaultAgentId } from "../config/legacy.default-agent-owner.js"; |
3 | 4 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
4 | 5 | import type { RuntimeEnv } from "../runtime.js"; |
5 | 6 |
|
@@ -159,6 +160,192 @@ describe("runConfigureWizard default-agent ownership", () => { |
159 | 160 | ); |
160 | 161 | }); |
161 | 162 |
|
| 163 | + it("uses the configured system agent when ownership is explicit", async () => { |
| 164 | + const baseConfig = { |
| 165 | + agents: { |
| 166 | + ownership: "explicit", |
| 167 | + defaults: { |
| 168 | + workspace: "/tmp/global-workspace", |
| 169 | + systemAgent: { agentId: "main" }, |
| 170 | + }, |
| 171 | + entries: { |
| 172 | + MAIN: { |
| 173 | + agentDir: "/tmp/main-agent", |
| 174 | + }, |
| 175 | + ops: { |
| 176 | + agentDir: "/tmp/ops-agent", |
| 177 | + workspace: "/tmp/ops-workspace", |
| 178 | + }, |
| 179 | + }, |
| 180 | + }, |
| 181 | + } satisfies OpenClawConfig; |
| 182 | + mocks.state.snapshot = { |
| 183 | + exists: true, |
| 184 | + valid: true, |
| 185 | + hash: "config-hash", |
| 186 | + config: baseConfig, |
| 187 | + sourceConfig: baseConfig, |
| 188 | + issues: [], |
| 189 | + }; |
| 190 | + mocks.text.mockResolvedValue("/tmp/new-main-workspace"); |
| 191 | + |
| 192 | + await runConfigureWizard( |
| 193 | + { command: "configure", sections: ["workspace", "plugins", "skills"] }, |
| 194 | + runtime, |
| 195 | + ); |
| 196 | + |
| 197 | + expect(mocks.commitConfig).toHaveBeenCalledWith( |
| 198 | + expect.objectContaining({ |
| 199 | + nextConfig: expect.objectContaining({ |
| 200 | + agents: expect.objectContaining({ |
| 201 | + defaults: expect.objectContaining({ workspace: "/tmp/global-workspace" }), |
| 202 | + entries: { |
| 203 | + MAIN: { |
| 204 | + agentDir: "/tmp/main-agent", |
| 205 | + workspace: "/tmp/new-main-workspace", |
| 206 | + }, |
| 207 | + ops: { |
| 208 | + agentDir: "/tmp/ops-agent", |
| 209 | + workspace: "/tmp/ops-workspace", |
| 210 | + }, |
| 211 | + }, |
| 212 | + }), |
| 213 | + }), |
| 214 | + }), |
| 215 | + ); |
| 216 | + expect(mocks.setupPluginConfig).toHaveBeenCalledWith( |
| 217 | + expect.objectContaining({ workspaceDir: "/tmp/new-main-workspace" }), |
| 218 | + ); |
| 219 | + expect(mocks.setupSkills).toHaveBeenCalledWith( |
| 220 | + expect.any(Object), |
| 221 | + "/tmp/new-main-workspace", |
| 222 | + runtime, |
| 223 | + expect.any(Object), |
| 224 | + ); |
| 225 | + expect(mocks.ensureWorkspaceAndSessions).toHaveBeenCalledWith( |
| 226 | + "/tmp/new-main-workspace", |
| 227 | + runtime, |
| 228 | + expect.objectContaining({ agentId: "main" }), |
| 229 | + ); |
| 230 | + }); |
| 231 | + |
| 232 | + it("preserves the legacy default owner when system-agent ownership is not explicit", async () => { |
| 233 | + const baseConfig = { |
| 234 | + agents: { |
| 235 | + defaults: { |
| 236 | + workspace: "/tmp/global-workspace", |
| 237 | + systemAgent: { agentId: "main" }, |
| 238 | + }, |
| 239 | + entries: { |
| 240 | + MAIN: { agentDir: "/tmp/main-agent" }, |
| 241 | + ops: { |
| 242 | + default: true, |
| 243 | + agentDir: "/tmp/ops-agent", |
| 244 | + workspace: "/tmp/ops-workspace", |
| 245 | + }, |
| 246 | + }, |
| 247 | + }, |
| 248 | + } satisfies OpenClawConfig; |
| 249 | + mocks.state.snapshot = { |
| 250 | + exists: true, |
| 251 | + valid: true, |
| 252 | + hash: "config-hash", |
| 253 | + config: baseConfig, |
| 254 | + sourceConfig: baseConfig, |
| 255 | + issues: [], |
| 256 | + }; |
| 257 | + mocks.text.mockResolvedValue("/tmp/new-ops-workspace"); |
| 258 | + |
| 259 | + await runConfigureWizard( |
| 260 | + { command: "configure", sections: ["workspace", "plugins", "skills"] }, |
| 261 | + runtime, |
| 262 | + ); |
| 263 | + |
| 264 | + expect(mocks.setupPluginConfig).toHaveBeenCalledWith( |
| 265 | + expect.objectContaining({ workspaceDir: "/tmp/new-ops-workspace" }), |
| 266 | + ); |
| 267 | + expect(mocks.setupSkills).toHaveBeenCalledWith( |
| 268 | + expect.any(Object), |
| 269 | + "/tmp/new-ops-workspace", |
| 270 | + runtime, |
| 271 | + expect.any(Object), |
| 272 | + ); |
| 273 | + expect(mocks.ensureWorkspaceAndSessions).toHaveBeenCalledWith( |
| 274 | + "/tmp/new-ops-workspace", |
| 275 | + runtime, |
| 276 | + expect.objectContaining({ agentId: "ops" }), |
| 277 | + ); |
| 278 | + expect(mocks.commitConfig).toHaveBeenCalledWith( |
| 279 | + expect.objectContaining({ |
| 280 | + nextConfig: expect.objectContaining({ |
| 281 | + agents: expect.objectContaining({ |
| 282 | + entries: expect.objectContaining({ |
| 283 | + MAIN: expect.not.objectContaining({ workspace: "/tmp/new-ops-workspace" }), |
| 284 | + ops: expect.objectContaining({ workspace: "/tmp/new-ops-workspace" }), |
| 285 | + }), |
| 286 | + }), |
| 287 | + }), |
| 288 | + }), |
| 289 | + ); |
| 290 | + }); |
| 291 | + |
| 292 | + it("keeps a workspace-less legacy owner on the global workspace", async () => { |
| 293 | + const baseConfig = { |
| 294 | + agents: { |
| 295 | + defaults: { |
| 296 | + workspace: "/tmp/global-workspace", |
| 297 | + systemAgent: { agentId: "main" }, |
| 298 | + }, |
| 299 | + entries: { |
| 300 | + main: { agentDir: "/tmp/main-agent" }, |
| 301 | + ops: { |
| 302 | + agentDir: "/tmp/ops-agent", |
| 303 | + }, |
| 304 | + }, |
| 305 | + }, |
| 306 | + } satisfies OpenClawConfig; |
| 307 | + retainLegacyDefaultAgentId(baseConfig, "ops"); |
| 308 | + mocks.state.snapshot = { |
| 309 | + exists: true, |
| 310 | + valid: true, |
| 311 | + hash: "config-hash", |
| 312 | + config: baseConfig, |
| 313 | + sourceConfig: baseConfig, |
| 314 | + issues: [], |
| 315 | + }; |
| 316 | + mocks.text.mockResolvedValue("/tmp/new-global-workspace"); |
| 317 | + |
| 318 | + await runConfigureWizard( |
| 319 | + { command: "configure", sections: ["workspace", "plugins", "skills"] }, |
| 320 | + runtime, |
| 321 | + ); |
| 322 | + |
| 323 | + expect(mocks.commitConfig).toHaveBeenCalledWith( |
| 324 | + expect.objectContaining({ |
| 325 | + nextConfig: expect.objectContaining({ |
| 326 | + agents: expect.objectContaining({ |
| 327 | + defaults: expect.objectContaining({ workspace: "/tmp/new-global-workspace" }), |
| 328 | + entries: baseConfig.agents.entries, |
| 329 | + }), |
| 330 | + }), |
| 331 | + }), |
| 332 | + ); |
| 333 | + expect(mocks.setupPluginConfig).toHaveBeenCalledWith( |
| 334 | + expect.objectContaining({ workspaceDir: "/tmp/new-global-workspace" }), |
| 335 | + ); |
| 336 | + expect(mocks.setupSkills).toHaveBeenCalledWith( |
| 337 | + expect.any(Object), |
| 338 | + "/tmp/new-global-workspace", |
| 339 | + runtime, |
| 340 | + expect.any(Object), |
| 341 | + ); |
| 342 | + expect(mocks.ensureWorkspaceAndSessions).toHaveBeenCalledWith( |
| 343 | + "/tmp/new-global-workspace", |
| 344 | + runtime, |
| 345 | + expect.objectContaining({ agentId: "ops" }), |
| 346 | + ); |
| 347 | + }); |
| 348 | + |
162 | 349 | it("does not persist an unprovisionable workspace", async () => { |
163 | 350 | mocks.ensureWorkspaceAndSessions.mockRejectedValueOnce(new Error("workspace is unwritable")); |
164 | 351 |
|
|
0 commit comments