|
1 | 1 | import { afterEach, describe, expect, test } from "bun:test"; |
2 | 2 | import { readFile, writeFile } from "node:fs/promises"; |
3 | 3 | import { join } from "node:path"; |
4 | | -import { UserCancellationError } from "../../../errors/errors"; |
| 4 | +import { |
| 5 | + LegacyDeployError, |
| 6 | + LegacyDeployWarningExit, |
| 7 | + UserCancellationError, |
| 8 | +} from "../../../errors/errors"; |
5 | 9 | import { createRootHandler } from "../../index"; |
6 | 10 | import { DEFAULT_GLOBAL_CONFIG } from "../../../globalConfig"; |
7 | 11 | import { ValueContext } from "../../../router"; |
@@ -344,7 +348,52 @@ describe("project deploy handler", () => { |
344 | 348 | ); |
345 | 349 | const subject = await testDeployCommand({ outputs: {} }, [], { runV0Deploy: async () => 7 }); |
346 | 350 |
|
347 | | - await expect(subject.run(["--yes"])).rejects.toMatchObject({ exitCode: 7 }); |
| 351 | + const error = await subject.run(["--yes"]).then( |
| 352 | + () => undefined, |
| 353 | + (caught: unknown) => caught, |
| 354 | + ); |
| 355 | + expect(error).toBeInstanceOf(LegacyDeployError); |
| 356 | + expect(error).toMatchObject({ exitCode: 7, meta: { legacyDeployExitCode: 7 } }); |
| 357 | + await assertMetricEmitted(subject.telemetryFilePath, "cli.command_run", { |
| 358 | + command_path: "/agentcore/deploy", |
| 359 | + exit_reason: "failure", |
| 360 | + error_name: "LegacyDeployError", |
| 361 | + legacy_deploy_exit_code: 7, |
| 362 | + }); |
| 363 | + expect(subject.calls).toEqual([]); |
| 364 | + }); |
| 365 | + |
| 366 | + test("preserves v0's warning exit code without reporting a failed deploy", async () => { |
| 367 | + await inProjectWithTargets(); |
| 368 | + await writeFile( |
| 369 | + join(process.cwd(), "agentcore", "agentcore.json"), |
| 370 | + JSON.stringify({ name: "orders", version: 1 }), |
| 371 | + ); |
| 372 | + const subject = await testDeployCommand({ outputs: {} }, [], { runV0Deploy: async () => 2 }); |
| 373 | + |
| 374 | + const error = await subject.run(["--yes"]).then( |
| 375 | + () => undefined, |
| 376 | + (caught: unknown) => caught, |
| 377 | + ); |
| 378 | + expect(error).toBeInstanceOf(LegacyDeployWarningExit); |
| 379 | + expect(error).toMatchObject({ |
| 380 | + name: "LegacyDeployWarningExit", |
| 381 | + exitCode: 2, |
| 382 | + }); |
| 383 | + await assertMetricEmitted(subject.telemetryFilePath, "cli.command_run", { |
| 384 | + command_path: "/agentcore/deploy", |
| 385 | + exit_reason: "success", |
| 386 | + legacy_deploy_exit_code: 2, |
| 387 | + }); |
| 388 | + const events = (await readFile(subject.telemetryFilePath, "utf8")) |
| 389 | + .trim() |
| 390 | + .split("\n") |
| 391 | + .map((line) => JSON.parse(line)); |
| 392 | + const warningRun = events.find( |
| 393 | + (event) => |
| 394 | + event.metricName === "cli.command_run" && event.attrs.legacy_deploy_exit_code === 2, |
| 395 | + ); |
| 396 | + expect(warningRun?.attrs).not.toHaveProperty("error_name"); |
348 | 397 | expect(subject.calls).toEqual([]); |
349 | 398 | }); |
350 | 399 |
|
|
0 commit comments