From 389c93239042f29444690df8619961a31a33764a Mon Sep 17 00:00:00 2001 From: rendianmeng Date: Thu, 30 Jul 2026 11:38:40 +0800 Subject: [PATCH] test(runtime): expect npm --version probe in command pack install Co-authored-by: Cursor --- packages/runtime/tests/command-packs.test.ts | 23 +++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/runtime/tests/command-packs.test.ts b/packages/runtime/tests/command-packs.test.ts index 19546d7..6ea9dca 100644 --- a/packages/runtime/tests/command-packs.test.ts +++ b/packages/runtime/tests/command-packs.test.ts @@ -58,6 +58,11 @@ fs.appendFileSync( }) + "\\n", ); +if (args[0] === "--version") { + process.stdout.write("10.0.0\\n"); + process.exit(0); +} + const manifestPath = path.join(cwd, "package.json"); const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); manifest.dependencies ??= {}; @@ -205,8 +210,9 @@ test("installs once on success and restores the previous version after validatio env: Record; }, ); - expect(successfulCalls).toHaveLength(1); - expect(successfulCalls[0]?.env).toEqual({ + // runNpm probes `npm --version` before each install/uninstall. + expect(successfulCalls.map((call) => call.args[0])).toEqual(["--version", "install"]); + expect(successfulCalls[1]?.env).toEqual({ registry: "https://registry.example.test", catalog: null, recursive: null, @@ -228,14 +234,11 @@ test("installs once on success and restores the previous version after validatio env: Record; }, ); - expect(rollbackCalls).toHaveLength(2); - expect(rollbackCalls[0]?.args.slice(0, 2)).toEqual([ - "install", - "@ali/bailian-plugin-agent@broken", - ]); - expect(rollbackCalls[1]?.args.slice(0, 2)).toEqual([ - "install", - "@ali/bailian-plugin-agent@1.0.0", + expect(rollbackCalls.map((call) => call.args.slice(0, 2))).toEqual([ + ["--version"], + ["install", "@ali/bailian-plugin-agent@broken"], + ["--version"], + ["install", "@ali/bailian-plugin-agent@1.0.0"], ]); const manifest = JSON.parse(