From 5d873a0c9fde2696a779546eeebf008b012ffccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ey=C3=BE=C3=B3r=20Magn=C3=BAsson?= Date: Fri, 9 Aug 2019 17:12:13 +0200 Subject: [PATCH] fix(server): re-use Garden instance when running commands for API calls --- garden-service/src/server/commands.ts | 6 +----- garden-service/test/unit/src/server/server.ts | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/garden-service/src/server/commands.ts b/garden-service/src/server/commands.ts index 8375e9a296..fe49c2649d 100644 --- a/garden-service/src/server/commands.ts +++ b/garden-service/src/server/commands.ts @@ -66,10 +66,6 @@ export async function resolveRequest( // Prepare arguments for command action. const command = commandSpec.command - // TODO: Creating a new Garden instance is not ideal, - // need to revisit once we've refactored the TaskGraph and config resolution. - const cmdGarden = await Garden.factory(garden.projectRoot, garden.opts) - // We generally don't want actions to log anything in the server. const cmdLog = log.placeholder(LogLevel.silly, { childEntriesInheritLevel: true }) @@ -78,7 +74,7 @@ export async function resolveRequest( const cmdOpts = mapParams(ctx, request.parameters, optParams) return command.action({ - garden: cmdGarden, + garden, log: cmdLog, headerLog: cmdLog, footerLog: cmdLog, diff --git a/garden-service/test/unit/src/server/server.ts b/garden-service/test/unit/src/server/server.ts index 7e83dc21bc..18590e5542 100644 --- a/garden-service/test/unit/src/server/server.ts +++ b/garden-service/test/unit/src/server/server.ts @@ -194,6 +194,10 @@ describe("startServer", () => { it("should correctly map arguments and options to commands", (done) => { const id = uuid.v4() onMessage((req) => { + // Ignore other events such as taskPending and taskProcessing and wait for the command result + if ((req).type !== "commandResult") { + return + } const taskResult = taskResultOutputs((req).result) const result = { ...req,