From 56f163879eee446c4e5a76ba176383c901d4304e Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 1 Dec 2021 16:06:27 -0500 Subject: [PATCH 01/78] Move daemon files into daemon directory. Rename Processor to DaemonDecider. Signed-off-by: Gene Johnston --- .../__unit__}/DaemonClient.unit.test.ts | 2 +- .../__unit__/DaemonDecider.unit.test.ts} | 30 ++++++------- .../DaemonClient.unit.test.ts.snap | 42 +++++++++++++++++++ packages/cli/src/{ => daemon}/DaemonClient.ts | 0 .../{Processor.ts => daemon/DaemonDecider.ts} | 40 +++++++++--------- packages/cli/src/main.ts | 8 ++-- 6 files changed, 82 insertions(+), 40 deletions(-) rename packages/cli/__tests__/{ => daemon/__unit__}/DaemonClient.unit.test.ts (98%) rename packages/cli/__tests__/{Processor.unit.test.ts => daemon/__unit__/DaemonDecider.unit.test.ts} (79%) create mode 100644 packages/cli/__tests__/daemon/__unit__/__snapshots__/DaemonClient.unit.test.ts.snap rename packages/cli/src/{ => daemon}/DaemonClient.ts (100%) rename packages/cli/src/{Processor.ts => daemon/DaemonDecider.ts} (84%) diff --git a/packages/cli/__tests__/DaemonClient.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/DaemonClient.unit.test.ts similarity index 98% rename from packages/cli/__tests__/DaemonClient.unit.test.ts rename to packages/cli/__tests__/daemon/__unit__/DaemonClient.unit.test.ts index 6a39ec160a..14e373378a 100644 --- a/packages/cli/__tests__/DaemonClient.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/DaemonClient.unit.test.ts @@ -13,7 +13,7 @@ jest.mock("net"); jest.mock("@zowe/imperative"); import * as net from "net"; import { Imperative } from "@zowe/imperative"; -import { DaemonClient } from "../src/DaemonClient"; +import { DaemonClient } from "../../../src/daemon/DaemonClient"; describe("DaemonClient tests", () => { diff --git a/packages/cli/__tests__/Processor.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/DaemonDecider.unit.test.ts similarity index 79% rename from packages/cli/__tests__/Processor.unit.test.ts rename to packages/cli/__tests__/daemon/__unit__/DaemonDecider.unit.test.ts index bce4414b9c..fdd5807753 100644 --- a/packages/cli/__tests__/Processor.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/DaemonDecider.unit.test.ts @@ -14,10 +14,10 @@ jest.mock("@zowe/imperative"); import * as net from "net"; import Mock = jest.Mock; import { Imperative } from "@zowe/imperative"; -import { Processor } from "../src/Processor"; -jest.mock("../src/DaemonClient"); +import { DaemonDecider } from "../../../src/daemon/DaemonDecider"; +jest.mock("../../../src/daemon//DaemonClient"); -describe("Processor tests", () => { +describe("DaemonDecider tests", () => { it("should call normal parse method if no daemon keyword", () => { @@ -47,10 +47,10 @@ describe("Processor tests", () => { return {on}; }); - const processor = new Processor(["--help"]); - processor.init(); + const daemonDecider = new DaemonDecider(["--help"]); + daemonDecider.init(); expect(on).not.toHaveBeenCalled(); - processor.process(); + daemonDecider.runOrUseDaemon(); expect(parse).toHaveBeenCalled(); }); @@ -93,16 +93,16 @@ describe("Processor tests", () => { return {on, listen}; }); - const processor = new Processor(["some/file/path", "zowe", "--daemon"]); - processor.init(); + const daemonDecider = new DaemonDecider(["some/file/path", "zowe", "--daemon"]); + daemonDecider.init(); expect(on).toHaveBeenCalledTimes(2); - processor.process(); + daemonDecider.runOrUseDaemon(); expect(parse).not.toHaveBeenCalled(); - (processor as any).close(); + (daemonDecider as any).close(); expect(log).toHaveBeenLastCalledWith("server closed"); let err; try { - (processor as any).error(new Error("data")); + (daemonDecider as any).error(new Error("data")); } catch (thrownError) { err = thrownError; } @@ -123,14 +123,14 @@ describe("Processor tests", () => { } }; - const processor = new Processor(["anything"]); + const daemonDecider = new DaemonDecider(["anything"]); const testPort = "1234"; - (processor as any).mParms = ["one", "two", "--daemon"]; + (daemonDecider as any).mParms = ["one", "two", "--daemon"]; process.env.ZOWE_DAEMON = testPort; - (processor as any).initialParse(); - expect((processor as any).mPort).toBe(parseInt(testPort, 10)); + (daemonDecider as any).initialParse(); + expect((daemonDecider as any).mPort).toBe(parseInt(testPort, 10)); }); }); diff --git a/packages/cli/__tests__/daemon/__unit__/__snapshots__/DaemonClient.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/__snapshots__/DaemonClient.unit.test.ts.snap new file mode 100644 index 0000000000..170cad2fff --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/__snapshots__/DaemonClient.unit.test.ts.snap @@ -0,0 +1,42 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`DaemonClient tests should process data when received 1`] = `"some data"`; + +exports[`DaemonClient tests should process data when received 2`] = ` +Object { + "stream": Object { + "on": [MockFunction] { + "calls": Array [ + Array [ + "end", + [Function], + ], + Array [ + "close", + [Function], + ], + Array [ + "data", + [Function], + ], + ], + "results": Array [ + Object { + "type": "return", + "value": undefined, + }, + Object { + "type": "return", + "value": undefined, + }, + Object { + "type": "return", + "value": undefined, + }, + ], + }, + }, +} +`; + +exports[`DaemonClient tests should shutdown when keyword is specified 1`] = `"Terminating server"`; diff --git a/packages/cli/src/DaemonClient.ts b/packages/cli/src/daemon/DaemonClient.ts similarity index 100% rename from packages/cli/src/DaemonClient.ts rename to packages/cli/src/daemon/DaemonClient.ts diff --git a/packages/cli/src/Processor.ts b/packages/cli/src/daemon/DaemonDecider.ts similarity index 84% rename from packages/cli/src/Processor.ts rename to packages/cli/src/daemon/DaemonDecider.ts index 4c2d5e9534..d87cbc0b71 100644 --- a/packages/cli/src/Processor.ts +++ b/packages/cli/src/daemon/DaemonDecider.ts @@ -22,15 +22,15 @@ import { DaemonClient } from "./DaemonClient"; /** * Initial paramter parse to handle conditionally starting as a persistent process (e.g. daemon mode) * @export - * @class Processor + * @class DaemonDecider */ -export class Processor { +export class DaemonDecider { /** * Default port number * @private * @static - * @memberof Processor + * @memberof DaemonDecider */ private static readonly DEFAULT_PORT = 4000; @@ -38,7 +38,7 @@ export class Processor { * Undocumented paramter for launching in server mode * @private * @static - * @memberof Processor + * @memberof DaemonDecider */ private static readonly DAEMON_KEY = "--daemon"; @@ -46,7 +46,7 @@ export class Processor { * Hold instance of a running server * @private * @type {net.Server} - * @memberof Processor + * @memberof DaemonDecider */ private mServer: net.Server; @@ -54,7 +54,7 @@ export class Processor { * Hold current port number for the server * @private * @type {number} - * @memberof Processor + * @memberof DaemonDecider */ private mPort: number; @@ -62,20 +62,20 @@ export class Processor { * Indicator for whether or not to start the server * @private * @type {boolean} - * @memberof Processor + * @memberof DaemonDecider */ private mStartServer: boolean; /** - * Creates an instance of Processor. + * Creates an instance of DaemonDecider. * @param {string[]} mParms - * @memberof Processor + * @memberof DaemonDecider */ constructor(private mParms: string[]) { } /** - * Initialize our processor parse and optionally start the server - * @memberof Processor + * Initialize our DaemonDecider parse and optionally start the server + * @memberof DaemonDecider */ public init() { @@ -94,9 +94,9 @@ export class Processor { /** * Method to immediately parse or otherwise start the server for later processing from * incoming socket connections. - * @memberof Processor + * @memberof DaemonDecider */ - public process() { + public runOrUseDaemon() { if (this.mServer) { this.mServer.listen(this.mPort, "127.0.0.1", () => { Imperative.api.appLogger.debug(`daemon server bound ${this.mPort}`); @@ -110,7 +110,7 @@ export class Processor { /** * Server close handler * @private - * @memberof Processor + * @memberof DaemonDecider */ private close() { Imperative.api.appLogger.debug(`server closed`); @@ -120,7 +120,7 @@ export class Processor { * Server error handler * @private * @param {Error} err - * @memberof Processor + * @memberof DaemonDecider */ private error(err: Error) { Imperative.api.appLogger.error(`daemon server error: ${err.message}`); @@ -130,11 +130,11 @@ export class Processor { /** * Perform initial parsing of undocumented parameters * @private - * @memberof Processor + * @memberof DaemonDecider */ private initialParse() { const numOfParms = this.mParms.length - 2; - this.mPort = Processor.DEFAULT_PORT; + this.mPort = DaemonDecider.DEFAULT_PORT; if (numOfParms > 0) { const parm = this.mParms[2]; @@ -143,7 +143,7 @@ export class Processor { * NOTE(Kelosky): For now, we use an undocumented paramter `--daemon`. If found first, * we bypass `yargs` and begin running this as a persistent Processor. */ - const portOffset = parm.indexOf(Processor.DAEMON_KEY); + const portOffset = parm.indexOf(DaemonDecider.DAEMON_KEY); if (portOffset > -1) { this.startServer = true; @@ -162,7 +162,7 @@ export class Processor { /** * Get whether or not to start the server * @private - * @memberof Processor + * @memberof DaemonDecider */ private get startServer() { return this.mStartServer; @@ -171,7 +171,7 @@ export class Processor { /** * Set whether or not to start the server * @private - * @memberof Processor + * @memberof DaemonDecider */ private set startServer(startServer) { this.mStartServer = startServer; diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts index 2870448450..408c98812e 100644 --- a/packages/cli/src/main.ts +++ b/packages/cli/src/main.ts @@ -18,7 +18,7 @@ timingApi.mark("PRE_IMPORT_IMPERATIVE"); import { IImperativeConfig, Imperative } from "@zowe/imperative"; import { Constants } from "./Constants"; import { inspect } from "util"; -import { Processor } from "./Processor"; +import { DaemonDecider } from "./daemon/DaemonDecider"; // TODO(Kelosky): if we remove this, imperative fails to find config in package.json & we must debug this. const config: IImperativeConfig = { @@ -35,8 +35,8 @@ const config: IImperativeConfig = { if(process.argv.includes("--daemon")) { config.daemonMode = true; } await Imperative.init(config); - const processor = new Processor(process.argv); - processor.init(); + const daemonDecider = new DaemonDecider(process.argv); + daemonDecider.init(); timingApi.mark("AFTER_INIT"); timingApi.measure("imperative.init", "BEFORE_INIT", "AFTER_INIT"); @@ -45,7 +45,7 @@ const config: IImperativeConfig = { timingApi.mark("BEFORE_PARSE"); - processor.process(); + daemonDecider.runOrUseDaemon(); timingApi.mark("AFTER_PARSE"); timingApi.measure("Imperative.parse", "BEFORE_PARSE", "AFTER_PARSE"); From 7249c308eca706ede8f791c0fda42fae7d37fd32 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 1 Dec 2021 18:07:08 -0500 Subject: [PATCH 02/78] Add skeleton commands for daemon enable & disable Signed-off-by: Gene Johnston --- packages/cli/src/daemon/Daemon.definition.ts | 28 +++++++++++ .../src/daemon/disable/Disable.definition.ts | 25 ++++++++++ .../cli/src/daemon/disable/Disable.handler.ts | 46 +++++++++++++++++++ .../src/daemon/enable/Enable.definition.ts | 25 ++++++++++ .../cli/src/daemon/enable/Enable.handler.ts | 46 +++++++++++++++++++ packages/cli/src/imperative.ts | 1 + 6 files changed, 171 insertions(+) create mode 100644 packages/cli/src/daemon/Daemon.definition.ts create mode 100644 packages/cli/src/daemon/disable/Disable.definition.ts create mode 100644 packages/cli/src/daemon/disable/Disable.handler.ts create mode 100644 packages/cli/src/daemon/enable/Enable.definition.ts create mode 100644 packages/cli/src/daemon/enable/Enable.handler.ts diff --git a/packages/cli/src/daemon/Daemon.definition.ts b/packages/cli/src/daemon/Daemon.definition.ts new file mode 100644 index 0000000000..4718b380dd --- /dev/null +++ b/packages/cli/src/daemon/Daemon.definition.ts @@ -0,0 +1,28 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ICommandDefinition } from "@zowe/imperative"; +import { EnableCommand } from "./enable/Enable.definition"; +import { DisableCommand } from "./disable/Disable.definition"; + +const definition: ICommandDefinition = { + name: "daemon", + type: "group", + summary: "Daemon operations", + description: "Perform operations that control the daemon-mode functionality of the Zowe-CLI. " + + "Daemon-mode runs the CLI command processor as a daemon to improve performance.", + children: [ + EnableCommand, + DisableCommand + ] +}; + +export = definition; diff --git a/packages/cli/src/daemon/disable/Disable.definition.ts b/packages/cli/src/daemon/disable/Disable.definition.ts new file mode 100644 index 0000000000..75a5000fa0 --- /dev/null +++ b/packages/cli/src/daemon/disable/Disable.definition.ts @@ -0,0 +1,25 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ICommandDefinition } from "@zowe/imperative"; + +export const DisableCommand: ICommandDefinition = { + name: "disable", + description: "Disables daemon-mode operation of the Zowe-CLI.", + type: "command", + handler: __dirname + "/Disable.handler", + examples: [ + { + description: "Disable daemon-mode", + options: "" + } + ] +}; diff --git a/packages/cli/src/daemon/disable/Disable.handler.ts b/packages/cli/src/daemon/disable/Disable.handler.ts new file mode 100644 index 0000000000..d2ba5ecc2e --- /dev/null +++ b/packages/cli/src/daemon/disable/Disable.handler.ts @@ -0,0 +1,46 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ICommandHandler, IHandlerParameters } from "@zowe/imperative"; + +/** + * Handler to disable daemon mode. + * @export + * @class Handler + * @implements {ICommandHandler} + */ +export default class DisableDaemonHandler implements ICommandHandler { + /** + * Process the disable daemon command and populates the response + * object as needed. + * + * @param {IHandlerParameters} cmdParams Parameters supplied by yargs + * + * @throws {ImperativeError} + */ + public process(cmdParams: IHandlerParameters): Promise { + if ( this.disableDaemon() ) { + cmdParams.response.console.log("Daemon mode disabled"); + } else { + cmdParams.response.console.log("Failed to disable daemon mode"); + } + return; + } + + /** + * Enable daemon mode. + * + * @returns True upon success. False otherwise. + */ + private disableDaemon(): boolean { + return true; + } +} diff --git a/packages/cli/src/daemon/enable/Enable.definition.ts b/packages/cli/src/daemon/enable/Enable.definition.ts new file mode 100644 index 0000000000..817a56d3ed --- /dev/null +++ b/packages/cli/src/daemon/enable/Enable.definition.ts @@ -0,0 +1,25 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ICommandDefinition } from "@zowe/imperative"; + +export const EnableCommand: ICommandDefinition = { + name: "enable", + description: "Enables daemon-mode operation of the Zowe-CLI.", + type: "command", + handler: __dirname + "/Enable.handler", + examples: [ + { + description: "Enable daemon-mode", + options: "" + } + ] +}; diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts new file mode 100644 index 0000000000..6aae27d497 --- /dev/null +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -0,0 +1,46 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ICommandHandler, IHandlerParameters } from "@zowe/imperative"; + +/** + * Handler to enable daemon mode. + * @export + * @class Handler + * @implements {ICommandHandler} + */ +export default class EnableDaemonHandler implements ICommandHandler { + /** + * Process the enable daemon command and populates the response + * object as needed. + * + * @param {IHandlerParameters} cmdParams Parameters supplied by yargs + * + * @throws {ImperativeError} + */ + public process(cmdParams: IHandlerParameters): Promise { + if ( this.enableDaemon() ) { + cmdParams.response.console.log("Daemon mode enabled"); + } else { + cmdParams.response.console.log("Failed to enable daemon mode"); + } + return; + } + + /** + * Enable daemon mode. + * + * @returns True upon success. False otherwise. + */ + private enableDaemon(): boolean { + return true; + } +} diff --git a/packages/cli/src/imperative.ts b/packages/cli/src/imperative.ts index 038d8105e9..ece4ef7ec6 100644 --- a/packages/cli/src/imperative.ts +++ b/packages/cli/src/imperative.ts @@ -30,6 +30,7 @@ import { ZosFilesOptions } from "./zosfiles/ZosFiles.options"; const config: IImperativeConfig = { productDisplayName: Constants.DISPLAY_NAME, commandModuleGlobs: [ + "daemon/*.definition!(.d).*s", "provisioning/*.definition!(.d).*s", "workflows/*.definition!(.d).*s", "zosconsole/*.definition!(.d).*s", From 480cc692a39735b240cb9d3db1ff951741b9c7ca Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 2 Dec 2021 09:26:36 -0500 Subject: [PATCH 03/78] Use imperative with system info utility Signed-off-by: Gene Johnston --- .../__packages__/cli-test-utils/package.json | 2 +- package-lock.json | 58 +++++++++---------- package.json | 2 +- packages/cli/package.json | 2 +- packages/core/package.json | 2 +- packages/provisioning/package.json | 2 +- packages/workflows/package.json | 2 +- packages/zosconsole/package.json | 2 +- packages/zosfiles/package.json | 2 +- packages/zosjobs/package.json | 2 +- packages/zosmf/package.json | 2 +- packages/zostso/package.json | 2 +- packages/zosuss/package.json | 2 +- 13 files changed, 41 insertions(+), 41 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/package.json b/__tests__/__packages__/cli-test-utils/package.json index ea86295d38..e4dea198ff 100644 --- a/__tests__/__packages__/cli-test-utils/package.json +++ b/__tests__/__packages__/cli-test-utils/package.json @@ -43,7 +43,7 @@ }, "devDependencies": { "@types/node": "^14.14.37", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "rimraf": "^3.0.2", "typescript": "^4.2.3" diff --git a/package-lock.json b/package-lock.json index 0bdac62420..0637bb34e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "__tests__/__packages__/*" ], "dependencies": { - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/perf-timing": "1.0.7" }, "devDependencies": { @@ -74,7 +74,7 @@ }, "devDependencies": { "@types/node": "^14.14.37", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "rimraf": "^3.0.2", "typescript": "^4.2.3" @@ -5355,9 +5355,9 @@ "link": true }, "node_modules/@zowe/imperative": { - "version": "5.0.0-next.202111292021", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.0.0-next.202111292021.tgz", - "integrity": "sha1-erUX5/ErG5oOqlx/iUodmcRG4PE=", + "version": "5.0.0-next.202112012301", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.0.0-next.202112012301.tgz", + "integrity": "sha1-E/+wyBPK72Lakrs/Lbfy9QJ2HEY=", "license": "EPL-2.0", "dependencies": { "@types/lodash-deep": "2.0.0", @@ -26422,7 +26422,7 @@ "license": "EPL-2.0", "dependencies": { "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.0.0-next.202111222227", "@zowe/zos-console-for-zowe-sdk": "7.0.0-next.202111222227", @@ -26480,7 +26480,7 @@ "devDependencies": { "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "chalk": "^4.1.0", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -26504,7 +26504,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -26534,7 +26534,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -26554,7 +26554,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -26577,7 +26577,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/zos-uss-for-zowe-sdk": "7.0.0-next.202111222227", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -26601,7 +26601,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -26621,7 +26621,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -26644,7 +26644,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -26667,7 +26667,7 @@ "@types/node": "^12.12.24", "@types/ssh2": "^0.5.44", "@zowe/cli-test-utils": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -30624,7 +30624,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.0.0-next.202111222227", "@zowe/zos-console-for-zowe-sdk": "7.0.0-next.202111222227", @@ -30661,7 +30661,7 @@ "@types/js-yaml": "^4.0.0", "@types/node": "^14.14.37", "@types/uuid": "^8.3.0", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "find-up": "^5.0.0", "js-yaml": "^4.0.0", @@ -30732,7 +30732,7 @@ "requires": { "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "chalk": "^4.1.0", "comment-json": "4.1.0", "eslint": "^7.32.0", @@ -30744,9 +30744,9 @@ } }, "@zowe/imperative": { - "version": "5.0.0-next.202111292021", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.0.0-next.202111292021.tgz", - "integrity": "sha1-erUX5/ErG5oOqlx/iUodmcRG4PE=", + "version": "5.0.0-next.202112012301", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.0.0-next.202112012301.tgz", + "integrity": "sha1-E/+wyBPK72Lakrs/Lbfy9QJ2HEY=", "requires": { "@types/lodash-deep": "2.0.0", "@types/yargs": "13.0.4", @@ -30882,7 +30882,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "js-yaml": "3.14.1", "madge": "^4.0.1", @@ -30905,7 +30905,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -30919,7 +30919,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/zos-uss-for-zowe-sdk": "7.0.0-next.202111222227", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -30935,7 +30935,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/zos-files-for-zowe-sdk": "7.0.0-next.202111222227", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -30950,7 +30950,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/zosmf-for-zowe-sdk": "7.0.0-next.202111222227", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -30965,7 +30965,7 @@ "@types/node": "^12.12.24", "@types/ssh2": "^0.5.44", "@zowe/cli-test-utils": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -30980,7 +30980,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/zos-files-for-zowe-sdk": "7.0.0-next.202111222227", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -30995,7 +30995,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/package.json b/package.json index f29b16cb77..a39936f988 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "prepare": "husky install" }, "dependencies": { - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/perf-timing": "1.0.7" }, "devDependencies": { diff --git a/packages/cli/package.json b/packages/cli/package.json index 10dfd99f2d..00c6b8a723 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -56,7 +56,7 @@ }, "dependencies": { "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.0.0-next.202111222227", "@zowe/zos-console-for-zowe-sdk": "7.0.0-next.202111222227", diff --git a/packages/core/package.json b/packages/core/package.json index b2855723e0..474c765504 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -50,7 +50,7 @@ "devDependencies": { "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "chalk": "^4.1.0", "eslint": "^7.32.0", "madge": "^4.0.1", diff --git a/packages/provisioning/package.json b/packages/provisioning/package.json index 02d8fe818f..59d59135db 100644 --- a/packages/provisioning/package.json +++ b/packages/provisioning/package.json @@ -51,7 +51,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/workflows/package.json b/packages/workflows/package.json index aa25c25add..128be6a32c 100644 --- a/packages/workflows/package.json +++ b/packages/workflows/package.json @@ -50,7 +50,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosconsole/package.json b/packages/zosconsole/package.json index 37825db3d9..93efc0c8ee 100644 --- a/packages/zosconsole/package.json +++ b/packages/zosconsole/package.json @@ -47,7 +47,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosfiles/package.json b/packages/zosfiles/package.json index 7b5f097368..88dcb1623d 100644 --- a/packages/zosfiles/package.json +++ b/packages/zosfiles/package.json @@ -51,7 +51,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "@zowe/zos-uss-for-zowe-sdk": "7.0.0-next.202111222227", "eslint": "^7.32.0", "madge": "^4.0.1", diff --git a/packages/zosjobs/package.json b/packages/zosjobs/package.json index 0a4c38e9f9..49d17926da 100644 --- a/packages/zosjobs/package.json +++ b/packages/zosjobs/package.json @@ -51,7 +51,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosmf/package.json b/packages/zosmf/package.json index d5ed7d4a8a..35ced36572 100644 --- a/packages/zosmf/package.json +++ b/packages/zosmf/package.json @@ -46,7 +46,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zostso/package.json b/packages/zostso/package.json index 1b6b292510..fe6f2f3cf9 100644 --- a/packages/zostso/package.json +++ b/packages/zostso/package.json @@ -50,7 +50,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosuss/package.json b/packages/zosuss/package.json index 84974c781a..380f6947fe 100644 --- a/packages/zosuss/package.json +++ b/packages/zosuss/package.json @@ -50,7 +50,7 @@ "@types/node": "^12.12.24", "@types/ssh2": "^0.5.44", "@zowe/cli-test-utils": "7.0.0-next.202111222227", - "@zowe/imperative": "5.0.0-next.202111292021", + "@zowe/imperative": "5.0.0-next.202112012301", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", From f888eb52de439b696ccf12f6a36b70001ff32a47 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 2 Dec 2021 13:26:31 -0500 Subject: [PATCH 04/78] Add skeleton unit tests for enable and disable. Signed-off-by: Gene Johnston --- .../__unit__/Daemon.definition.unit.test.ts | 23 ++++++ .../Daemon.definition.unit.test.ts.snap | 10 +++ .../disable/Disable.definition.unit.test.ts | 25 +++++++ .../disable/Disable.handler.unit.test.ts | 70 +++++++++++++++++++ .../Disable.definition.unit.test.ts.snap | 15 ++++ .../enable/Enable.definition.unit.test.ts | 25 +++++++ .../enable/Enable.handler.unit.test.ts | 70 +++++++++++++++++++ .../Enable.definition.unit.test.ts.snap | 15 ++++ 8 files changed, 253 insertions(+) create mode 100644 packages/cli/__tests__/daemon/__unit__/Daemon.definition.unit.test.ts create mode 100644 packages/cli/__tests__/daemon/__unit__/__snapshots__/Daemon.definition.unit.test.ts.snap create mode 100644 packages/cli/__tests__/daemon/__unit__/disable/Disable.definition.unit.test.ts create mode 100644 packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts create mode 100644 packages/cli/__tests__/daemon/__unit__/disable/__snapshots__/Disable.definition.unit.test.ts.snap create mode 100644 packages/cli/__tests__/daemon/__unit__/enable/Enable.definition.unit.test.ts create mode 100644 packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts create mode 100644 packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap diff --git a/packages/cli/__tests__/daemon/__unit__/Daemon.definition.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/Daemon.definition.unit.test.ts new file mode 100644 index 0000000000..5df257515e --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/Daemon.definition.unit.test.ts @@ -0,0 +1,23 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ICommandDefinition } from "@zowe/imperative"; + +describe("daemon group definition", () => { + it("should have the right command content", () => { + const numOfDaemonCmds = 2; + const definition: ICommandDefinition = require("../../../src/daemon/Daemon.definition"); + expect(definition).toBeDefined(); + expect(definition.children.length).toBe(numOfDaemonCmds); + delete definition.children; + expect(definition).toMatchSnapshot(); + }); +}); diff --git a/packages/cli/__tests__/daemon/__unit__/__snapshots__/Daemon.definition.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/__snapshots__/Daemon.definition.unit.test.ts.snap new file mode 100644 index 0000000000..786c7a627d --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/__snapshots__/Daemon.definition.unit.test.ts.snap @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`daemon group definition should have the right command content 1`] = ` +Object { + "description": "Perform operations that control the daemon-mode functionality of the Zowe-CLI. Daemon-mode runs the CLI command processor as a daemon to improve performance.", + "name": "daemon", + "summary": "Daemon operations", + "type": "group", +} +`; diff --git a/packages/cli/__tests__/daemon/__unit__/disable/Disable.definition.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/disable/Disable.definition.unit.test.ts new file mode 100644 index 0000000000..95bd51c455 --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/disable/Disable.definition.unit.test.ts @@ -0,0 +1,25 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ICommandDefinition } from "@zowe/imperative"; + +describe("daemon disable definition", () => { + it("should not have changed", () => { + const definition: ICommandDefinition = require("../../../../src/daemon/disable/Disable.definition").DisableCommand; + expect(definition).toBeDefined(); + delete definition.handler; + + // Should not contain children since this is a command + expect(definition.children).toBeUndefined(); + + expect(definition).toMatchSnapshot(); + }); +}); diff --git a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts new file mode 100644 index 0000000000..4e11c3c90e --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts @@ -0,0 +1,70 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ +import DisableDaemonHandler from "../../../../src/daemon/disable/Disable.handler"; + +describe("Disable daemon handler", () => { + let disableHandler: any; // use "any" so we can call private functions + let disableDaemonSpy: any; + + beforeAll(() => { + // instantiate our handler and spy on its private disableDaemon() function + disableHandler = new DisableDaemonHandler(); + disableDaemonSpy = jest.spyOn(disableHandler, "disableDaemon"); + }); + + describe("process method", () => { + it("should disable the daemon", async () => { + let apiMessage = ""; + let error; + let jsonObj; + let logMessage = ""; + try { + // Invoke the handler with a full set of mocked arguments and response functions + await disableHandler.process({ + arguments: { + $0: "fake", + _: ["fake"] + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + apiMessage = setMsgArgs; + }), + setObj: jest.fn((setObjArgs) => { + jsonObj = setObjArgs; + }) + }, + console: { + log: jest.fn((logArgs) => { + logMessage += "\n" + logArgs; + }) + }, + progress: {} + }, + profiles: {} + } as any); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(disableDaemonSpy).toHaveBeenCalledTimes(1); + expect(logMessage).toContain("Daemon mode disabled"); + }); + }); + + describe("disableDaemon method", () => { + it("should return true upon success", async () => { + const result = disableHandler.disableDaemon(); + expect(result).toBe(true); + }); + }); +}); diff --git a/packages/cli/__tests__/daemon/__unit__/disable/__snapshots__/Disable.definition.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/disable/__snapshots__/Disable.definition.unit.test.ts.snap new file mode 100644 index 0000000000..ff98863de4 --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/disable/__snapshots__/Disable.definition.unit.test.ts.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`daemon disable definition should not have changed 1`] = ` +Object { + "description": "Disables daemon-mode operation of the Zowe-CLI.", + "examples": Array [ + Object { + "description": "Disable daemon-mode", + "options": "", + }, + ], + "name": "disable", + "type": "command", +} +`; diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.definition.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.definition.unit.test.ts new file mode 100644 index 0000000000..f4b0201b52 --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.definition.unit.test.ts @@ -0,0 +1,25 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ICommandDefinition } from "@zowe/imperative"; + +describe("daemon enable definition", () => { + it("should not have changed", () => { + const definition: ICommandDefinition = require("../../../../src/daemon/enable/Enable.definition").EnableCommand; + expect(definition).toBeDefined(); + delete definition.handler; + + // Should not contain children since this is a command + expect(definition.children).toBeUndefined(); + + expect(definition).toMatchSnapshot(); + }); +}); diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts new file mode 100644 index 0000000000..5b022a2ce9 --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -0,0 +1,70 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ +import EnableDaemonHandler from "../../../../src/daemon/enable/Enable.handler"; + +describe("Enable daemon handler", () => { + let enableHandler: any; // use "any" so we can call private functions + let enableDaemonSpy: any; + + beforeAll(() => { + // instantiate our handler and spy on its private enableDaemon() function + enableHandler = new EnableDaemonHandler(); + enableDaemonSpy = jest.spyOn(enableHandler, "enableDaemon"); + }); + + describe("process method", () => { + it("should enable the daemon", async () => { + let apiMessage = ""; + let error; + let jsonObj; + let logMessage = ""; + try { + // Invoke the handler with a full set of mocked arguments and response functions + await enableHandler.process({ + arguments: { + $0: "fake", + _: ["fake"] + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + apiMessage = setMsgArgs; + }), + setObj: jest.fn((setObjArgs) => { + jsonObj = setObjArgs; + }) + }, + console: { + log: jest.fn((logArgs) => { + logMessage += "\n" + logArgs; + }) + }, + progress: {} + }, + profiles: {} + } as any); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(enableDaemonSpy).toHaveBeenCalledTimes(1); + expect(logMessage).toContain("Daemon mode enabled"); + }); + }); + + describe("enableDaemon method", () => { + it("should return true upon success", async () => { + const result = enableHandler.enableDaemon(); + expect(result).toBe(true); + }); + }); +}); diff --git a/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap new file mode 100644 index 0000000000..1bd8c3ab72 --- /dev/null +++ b/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`daemon enable definition should not have changed 1`] = ` +Object { + "description": "Enables daemon-mode operation of the Zowe-CLI.", + "examples": Array [ + Object { + "description": "Enable daemon-mode", + "options": "", + }, + ], + "name": "enable", + "type": "command", +} +`; From 0566ef8ec257d9cd27edc3601bd8dd4f1a4e5f06 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 2 Dec 2021 14:36:39 -0500 Subject: [PATCH 05/78] Add IDaemonCmdResult. Signed-off-by: Gene Johnston --- .../disable/Disable.handler.unit.test.ts | 4 +- .../enable/Enable.handler.unit.test.ts | 4 +- .../cli/src/daemon/disable/Disable.handler.ts | 17 +++++--- .../cli/src/daemon/doc/IDaemonCmdResult.ts | 32 ++++++++++++++ .../cli/src/daemon/enable/Enable.handler.ts | 43 ++++++++++++++++--- 5 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 packages/cli/src/daemon/doc/IDaemonCmdResult.ts diff --git a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts index 4e11c3c90e..ae03f5cbb8 100644 --- a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts @@ -63,8 +63,8 @@ describe("Disable daemon handler", () => { describe("disableDaemon method", () => { it("should return true upon success", async () => { - const result = disableHandler.disableDaemon(); - expect(result).toBe(true); + const cmdResult = disableHandler.disableDaemon(); + expect(cmdResult.success).toBe(true); }); }); }); diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 5b022a2ce9..776be83890 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -63,8 +63,8 @@ describe("Enable daemon handler", () => { describe("enableDaemon method", () => { it("should return true upon success", async () => { - const result = enableHandler.enableDaemon(); - expect(result).toBe(true); + const cmdResult = enableHandler.enableDaemon(); + expect(cmdResult.success).toBe(true); }); }); }); diff --git a/packages/cli/src/daemon/disable/Disable.handler.ts b/packages/cli/src/daemon/disable/Disable.handler.ts index d2ba5ecc2e..5b0ad465d1 100644 --- a/packages/cli/src/daemon/disable/Disable.handler.ts +++ b/packages/cli/src/daemon/disable/Disable.handler.ts @@ -10,6 +10,7 @@ */ import { ICommandHandler, IHandlerParameters } from "@zowe/imperative"; +import { IDaemonCmdResult } from "../doc/IDaemonCmdResult"; /** * Handler to disable daemon mode. @@ -27,10 +28,11 @@ export default class DisableDaemonHandler implements ICommandHandler { * @throws {ImperativeError} */ public process(cmdParams: IHandlerParameters): Promise { - if ( this.disableDaemon() ) { - cmdParams.response.console.log("Daemon mode disabled"); + const cmdResult = this.disableDaemon(); + if ( cmdResult.success ) { + cmdParams.response.console.log("Daemon mode disabled.\n" + cmdResult.msgText); } else { - cmdParams.response.console.log("Failed to disable daemon mode"); + cmdParams.response.console.log("Failed to disable daemon mode.\n" + cmdResult.msgText); } return; } @@ -40,7 +42,12 @@ export default class DisableDaemonHandler implements ICommandHandler { * * @returns True upon success. False otherwise. */ - private disableDaemon(): boolean { - return true; + private disableDaemon(): IDaemonCmdResult { + const cmdResult: IDaemonCmdResult = { + success: true, + msgText: "" + }; + + return cmdResult; } } diff --git a/packages/cli/src/daemon/doc/IDaemonCmdResult.ts b/packages/cli/src/daemon/doc/IDaemonCmdResult.ts new file mode 100644 index 0000000000..5e9ea94954 --- /dev/null +++ b/packages/cli/src/daemon/doc/IDaemonCmdResult.ts @@ -0,0 +1,32 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +/** + * Interface representing the result of a Dameon command. + * @export + * @interface IDaemonCmdResult + */ +export interface IDaemonCmdResult { + /** + * Success or failure. + * @type {string} + * @memberof IDaemonCmdResult + */ + success: boolean; + + /** + * Text message associated with our result. + * @type {string} + * @memberof IDaemonCmdResult + */ + msgText: string; +} + diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index 6aae27d497..d9f3b0829c 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -10,6 +10,7 @@ */ import { ICommandHandler, IHandlerParameters } from "@zowe/imperative"; +import { IDaemonCmdResult } from "../doc/IDaemonCmdResult"; /** * Handler to enable daemon mode. @@ -27,20 +28,50 @@ export default class EnableDaemonHandler implements ICommandHandler { * @throws {ImperativeError} */ public process(cmdParams: IHandlerParameters): Promise { - if ( this.enableDaemon() ) { - cmdParams.response.console.log("Daemon mode enabled"); + const cmdResult = this.enableDaemon(); + if ( cmdResult.success ) { + cmdParams.response.console.log("Daemon mode enabled.\n" + cmdResult.msgText); } else { - cmdParams.response.console.log("Failed to enable daemon mode"); + cmdParams.response.console.log("Failed to enable daemon mode.\n" + cmdResult.msgText); } return; } /** - * Enable daemon mode. + * Enable daemon mode. We extract our native executable and place it + * in ZOWE_CLI_HOME/bin. * * @returns True upon success. False otherwise. */ - private enableDaemon(): boolean { - return true; + private enableDaemon(): IDaemonCmdResult { + const cmdResult: IDaemonCmdResult = { + success: true, + msgText: "" + }; + + // determine our current OS + + // form the path to our prebuilds directory + + // find the tar file for our OS executable + + // form the path to our ZOWE_CLI_HOME bin directory + + // create the ZOWE_CLI_HOME bin directory if it does not exist + + // check the version of any existing executable + + // extract executable from the tar file into the bin directory + + // detect whether ZOWE_CLI_HOME/bin is already on our PATH + + // start the daemon if it is already on our PATH + + // Check if ZOWE_USE_DAEMON has a value + + // display results and directions to the user + + cmdResult.msgText = "Add ZOWE_CLI_HOME/bin to your path."; + return cmdResult; } } From ebee8b967c40b76ff605d758b1fe0e608e00f3ec Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Mon, 6 Dec 2021 17:02:40 -0500 Subject: [PATCH 06/78] Mock enableDaemon( ) to make this a unit test. Signed-off-by: Gene Johnston --- .../enable/Enable.handler.unit.test.ts | 102 ++++++++++++------ 1 file changed, 68 insertions(+), 34 deletions(-) diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 776be83890..cab4661c74 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -9,48 +9,65 @@ * */ import EnableDaemonHandler from "../../../../src/daemon/enable/Enable.handler"; +import { IDaemonCmdResult } from "../../../../src/daemon/doc/IDaemonCmdResult"; -describe("Enable daemon handler", () => { +describe("Handler for daemon enable", () => { let enableHandler: any; // use "any" so we can call private functions let enableDaemonSpy: any; + // command parms passed to process() by multiple tests + let apiMessage = ""; + let jsonObj; + let logMessage = ""; + const cmdParms = { + arguments: { + $0: "fake", + _: ["fake"] + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + apiMessage = setMsgArgs; + }), + setObj: jest.fn((setObjArgs) => { + jsonObj = setObjArgs; + }) + }, + console: { + log: jest.fn((logArgs) => { + logMessage += "\n" + logArgs; + }) + }, + progress: {} + }, + profiles: {} + } as any; + beforeAll(() => { // instantiate our handler and spy on its private enableDaemon() function enableHandler = new EnableDaemonHandler(); - enableDaemonSpy = jest.spyOn(enableHandler, "enableDaemon"); + enableDaemonSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "enableDaemon"); + }); + + beforeEach(() => { + // ensure that toHaveBeenCalledTimes does not accumulate for enableDaemonSpy between tests + jest.clearAllMocks(); }); describe("process method", () => { - it("should enable the daemon", async () => { - let apiMessage = ""; + it("should succeed when the enableDaemon function succeeds", async () => { let error; - let jsonObj; - let logMessage = ""; + const allOkMsg = "Everything worked ok"; + + const enableResultOk: IDaemonCmdResult = { + success: true, + msgText: allOkMsg + }; + enableDaemonSpy.mockImplementation(() => {return enableResultOk}); + try { // Invoke the handler with a full set of mocked arguments and response functions - await enableHandler.process({ - arguments: { - $0: "fake", - _: ["fake"] - }, - response: { - data: { - setMessage: jest.fn((setMsgArgs) => { - apiMessage = setMsgArgs; - }), - setObj: jest.fn((setObjArgs) => { - jsonObj = setObjArgs; - }) - }, - console: { - log: jest.fn((logArgs) => { - logMessage += "\n" + logArgs; - }) - }, - progress: {} - }, - profiles: {} - } as any); + await enableHandler.process(cmdParms); } catch (e) { error = e; } @@ -58,13 +75,30 @@ describe("Enable daemon handler", () => { expect(error).toBeUndefined(); expect(enableDaemonSpy).toHaveBeenCalledTimes(1); expect(logMessage).toContain("Daemon mode enabled"); + expect(logMessage).toContain(allOkMsg); }); - }); - describe("enableDaemon method", () => { - it("should return true upon success", async () => { - const cmdResult = enableHandler.enableDaemon(); - expect(cmdResult.success).toBe(true); + it("should fail when the enableDaemon function fails", async () => { + let error; + const badStuffMsg = "Some bad stuff happened"; + + const enableResultBad: IDaemonCmdResult = { + success: false, + msgText: badStuffMsg + }; + enableDaemonSpy.mockImplementation(() => {return enableResultBad}); + + try { + // Invoke the handler with a full set of mocked arguments and response functions + await enableHandler.process(cmdParms); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(enableDaemonSpy).toHaveBeenCalledTimes(1); + expect(logMessage).toContain("Failed to enable daemon mode"); + expect(logMessage).toContain(badStuffMsg); }); }); }); From 84e71c65701467389d197f80f4c28b34e0bc752f Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 7 Dec 2021 15:54:19 -0500 Subject: [PATCH 07/78] Add test for bogus OS. Signed-off-by: Gene Johnston --- .../enable/Enable.handler.unit.test.ts | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index cab4661c74..54c9ec9b5f 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -8,6 +8,9 @@ * Copyright Contributors to the Zowe Project. * */ + +import { ISystemInfo, ProcessUtils } from "@zowe/imperative"; + import EnableDaemonHandler from "../../../../src/daemon/enable/Enable.handler"; import { IDaemonCmdResult } from "../../../../src/daemon/doc/IDaemonCmdResult"; @@ -44,14 +47,13 @@ describe("Handler for daemon enable", () => { } as any; beforeAll(() => { - // instantiate our handler and spy on its private enableDaemon() function + // instantiate our handler enableHandler = new EnableDaemonHandler(); - enableDaemonSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "enableDaemon"); }); beforeEach(() => { - // ensure that toHaveBeenCalledTimes does not accumulate for enableDaemonSpy between tests - jest.clearAllMocks(); + // remove enableDaemon spy & mock between tests + enableDaemonSpy?.mockRestore(); }); describe("process method", () => { @@ -63,6 +65,9 @@ describe("Handler for daemon enable", () => { success: true, msgText: allOkMsg }; + + // spy on our handler's private enableDaemon() function + enableDaemonSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "enableDaemon"); enableDaemonSpy.mockImplementation(() => {return enableResultOk}); try { @@ -86,6 +91,9 @@ describe("Handler for daemon enable", () => { success: false, msgText: badStuffMsg }; + + // spy on our handler's private enableDaemon() function + enableDaemonSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "enableDaemon"); enableDaemonSpy.mockImplementation(() => {return enableResultBad}); try { @@ -100,5 +108,30 @@ describe("Handler for daemon enable", () => { expect(logMessage).toContain("Failed to enable daemon mode"); expect(logMessage).toContain(badStuffMsg); }); + + it("should fail when on an unsupported platform", async () => { + let error; + + const getBasicSystemInfoOrig = ProcessUtils.getBasicSystemInfo; + ProcessUtils.getBasicSystemInfo = jest.fn(() => { + return { + "arch": "BogusArch", + "platform": "BogusPlatform" + }; + }); + + + try { + // Invoke the handler with a full set of mocked arguments and response functions + await enableHandler.process(cmdParms); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(logMessage).toContain("Failed to enable daemon mode"); + expect(logMessage).toContain("Daemon mode is not supported on the 'BogusPlatform' operating system."); + ProcessUtils.getBasicSystemInfo = getBasicSystemInfoOrig; + }); }); }); From 74b3941c0cd9ea0ee49b9c21cf648c4b480281d6 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 7 Dec 2021 19:03:07 -0500 Subject: [PATCH 08/78] Add test for failure to create bin dir. Signed-off-by: Gene Johnston --- .../enable/Enable.handler.unit.test.ts | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 54c9ec9b5f..e2bc9be827 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -9,7 +9,7 @@ * */ -import { ISystemInfo, ProcessUtils } from "@zowe/imperative"; +import { ImperativeConfig, IO, ProcessUtils } from "@zowe/imperative"; import EnableDaemonHandler from "../../../../src/daemon/enable/Enable.handler"; import { IDaemonCmdResult } from "../../../../src/daemon/doc/IDaemonCmdResult"; @@ -34,6 +34,9 @@ describe("Handler for daemon enable", () => { }), setObj: jest.fn((setObjArgs) => { jsonObj = setObjArgs; + }), + setExitCode: jest.fn((exitCode) => { + return exitCode; }) }, console: { @@ -120,7 +123,6 @@ describe("Handler for daemon enable", () => { }; }); - try { // Invoke the handler with a full set of mocked arguments and response functions await enableHandler.process(cmdParms); @@ -133,5 +135,45 @@ describe("Handler for daemon enable", () => { expect(logMessage).toContain("Daemon mode is not supported on the 'BogusPlatform' operating system."); ProcessUtils.getBasicSystemInfo = getBasicSystemInfoOrig; }); + + it("should fail if a we cannot create a bin directory", async () => { + let error; + + // Mock the IO functions to simulate a failure creating a directory + const existsSyncOrig = IO.existsSync; + IO.createDirSync = jest.fn(() => { + return false; + }); + + const awfulThrownErr = "Some awful error was thrown"; + const createDirSyncOrig = IO.createDirSync; + IO.createDirSync = jest.fn(() => { + throw awfulThrownErr; + }); + + // cliHome is a getter property, so mock the property + const impCfg: ImperativeConfig = ImperativeConfig.instance; + const mockCliHomeDir = "NotaRealCliHomeDir"; + Object.defineProperty(impCfg, "cliHome", { + configurable: true, + get: jest.fn(() => { + return mockCliHomeDir; + }) + }); + + try { + // Invoke the handler with a full set of mocked arguments and response functions + await enableHandler.process(cmdParms); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(logMessage).toContain("Failed to enable daemon mode"); + expect(logMessage).toContain(`Unable to create directory '${mockCliHomeDir}`); + expect(logMessage).toContain("Reason: " + awfulThrownErr); + IO.existsSync = existsSyncOrig; + IO.createDirSync = createDirSyncOrig; + }); }); }); From 8b9f9cd98ffa43c2d824fcef9a7b8ddc7a5cf2cd Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 8 Dec 2021 14:01:41 -0500 Subject: [PATCH 09/78] Throw exceptions from private utility functions. Signed-off-by: Gene Johnston --- .../disable/Disable.handler.unit.test.ts | 72 ++++++----- .../enable/Enable.handler.unit.test.ts | 22 ++-- .../cli/src/daemon/disable/Disable.handler.ts | 34 ++--- .../cli/src/daemon/doc/IDaemonCmdResult.ts | 32 ----- .../cli/src/daemon/enable/Enable.handler.ts | 122 ++++++++++++++---- 5 files changed, 164 insertions(+), 118 deletions(-) delete mode 100644 packages/cli/src/daemon/doc/IDaemonCmdResult.ts diff --git a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts index ae03f5cbb8..7982374867 100644 --- a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts @@ -14,43 +14,53 @@ describe("Disable daemon handler", () => { let disableHandler: any; // use "any" so we can call private functions let disableDaemonSpy: any; + // command parms passed to process() by multiple tests + let apiMessage = ""; + let jsonObj; + let logMessage = ""; + const cmdParms = { + arguments: { + $0: "fake", + _: ["fake"] + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + apiMessage = setMsgArgs; + }), + setObj: jest.fn((setObjArgs) => { + jsonObj = setObjArgs; + }), + setExitCode: jest.fn((exitCode) => { + return exitCode; + }) + }, + console: { + log: jest.fn((logArgs) => { + logMessage += "\n" + logArgs; + }) + }, + progress: {} + }, + profiles: {} + } as any; + beforeAll(() => { // instantiate our handler and spy on its private disableDaemon() function disableHandler = new DisableDaemonHandler(); - disableDaemonSpy = jest.spyOn(disableHandler, "disableDaemon"); }); describe("process method", () => { it("should disable the daemon", async () => { - let apiMessage = ""; let error; - let jsonObj; - let logMessage = ""; + const allOkMsg = "Everything worked ok"; + + disableDaemonSpy = jest.spyOn(DisableDaemonHandler.prototype as any, "disableDaemon"); + disableDaemonSpy.mockImplementation(() => {return allOkMsg}); + try { // Invoke the handler with a full set of mocked arguments and response functions - await disableHandler.process({ - arguments: { - $0: "fake", - _: ["fake"] - }, - response: { - data: { - setMessage: jest.fn((setMsgArgs) => { - apiMessage = setMsgArgs; - }), - setObj: jest.fn((setObjArgs) => { - jsonObj = setObjArgs; - }) - }, - console: { - log: jest.fn((logArgs) => { - logMessage += "\n" + logArgs; - }) - }, - progress: {} - }, - profiles: {} - } as any); + await disableHandler.process(cmdParms); } catch (e) { error = e; } @@ -58,13 +68,7 @@ describe("Disable daemon handler", () => { expect(error).toBeUndefined(); expect(disableDaemonSpy).toHaveBeenCalledTimes(1); expect(logMessage).toContain("Daemon mode disabled"); - }); - }); - - describe("disableDaemon method", () => { - it("should return true upon success", async () => { - const cmdResult = disableHandler.disableDaemon(); - expect(cmdResult.success).toBe(true); + expect(logMessage).toContain(allOkMsg); }); }); }); diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index e2bc9be827..608963f5c9 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -9,10 +9,9 @@ * */ -import { ImperativeConfig, IO, ProcessUtils } from "@zowe/imperative"; +import { ImperativeConfig, ImperativeError, IO, ProcessUtils } from "@zowe/imperative"; import EnableDaemonHandler from "../../../../src/daemon/enable/Enable.handler"; -import { IDaemonCmdResult } from "../../../../src/daemon/doc/IDaemonCmdResult"; describe("Handler for daemon enable", () => { let enableHandler: any; // use "any" so we can call private functions @@ -64,14 +63,9 @@ describe("Handler for daemon enable", () => { let error; const allOkMsg = "Everything worked ok"; - const enableResultOk: IDaemonCmdResult = { - success: true, - msgText: allOkMsg - }; - // spy on our handler's private enableDaemon() function enableDaemonSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "enableDaemon"); - enableDaemonSpy.mockImplementation(() => {return enableResultOk}); + enableDaemonSpy.mockImplementation(() => {return allOkMsg}); try { // Invoke the handler with a full set of mocked arguments and response functions @@ -90,14 +84,14 @@ describe("Handler for daemon enable", () => { let error; const badStuffMsg = "Some bad stuff happened"; - const enableResultBad: IDaemonCmdResult = { - success: false, - msgText: badStuffMsg - }; - // spy on our handler's private enableDaemon() function enableDaemonSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "enableDaemon"); - enableDaemonSpy.mockImplementation(() => {return enableResultBad}); + enableDaemonSpy.mockImplementation(() => { + throw new ImperativeError({ + msg: badStuffMsg + }); + }); + try { // Invoke the handler with a full set of mocked arguments and response functions diff --git a/packages/cli/src/daemon/disable/Disable.handler.ts b/packages/cli/src/daemon/disable/Disable.handler.ts index 5b0ad465d1..fae1e44933 100644 --- a/packages/cli/src/daemon/disable/Disable.handler.ts +++ b/packages/cli/src/daemon/disable/Disable.handler.ts @@ -9,8 +9,7 @@ * */ -import { ICommandHandler, IHandlerParameters } from "@zowe/imperative"; -import { IDaemonCmdResult } from "../doc/IDaemonCmdResult"; +import { ICommandHandler, IHandlerParameters, ImperativeError } from "@zowe/imperative"; /** * Handler to disable daemon mode. @@ -28,26 +27,29 @@ export default class DisableDaemonHandler implements ICommandHandler { * @throws {ImperativeError} */ public process(cmdParams: IHandlerParameters): Promise { - const cmdResult = this.disableDaemon(); - if ( cmdResult.success ) { - cmdParams.response.console.log("Daemon mode disabled.\n" + cmdResult.msgText); - } else { - cmdParams.response.console.log("Failed to disable daemon mode.\n" + cmdResult.msgText); + let userMsg: string; + try { + userMsg = this.disableDaemon(); + } catch(impErr) { + cmdParams.response.console.log("Failed to disable daemon mode.\n" + (impErr as ImperativeError).message); + cmdParams.response.data.setExitCode(1); + return; } + + cmdParams.response.console.log("Daemon mode disabled.\n" + userMsg); + cmdParams.response.data.setExitCode(0); return; } /** * Enable daemon mode. * - * @returns True upon success. False otherwise. - */ - private disableDaemon(): IDaemonCmdResult { - const cmdResult: IDaemonCmdResult = { - success: true, - msgText: "" - }; - - return cmdResult; + * @throws {ImperativeError} + * + * @returns {string} An informational message to display to the user after + * successful completion of the operation. + */ + private disableDaemon(): string { + return "Pretend that we disabled daemon-mode."; } } diff --git a/packages/cli/src/daemon/doc/IDaemonCmdResult.ts b/packages/cli/src/daemon/doc/IDaemonCmdResult.ts deleted file mode 100644 index 5e9ea94954..0000000000 --- a/packages/cli/src/daemon/doc/IDaemonCmdResult.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* -* This program and the accompanying materials are made available under the terms of the -* Eclipse Public License v2.0 which accompanies this distribution, and is available at -* https://www.eclipse.org/legal/epl-v20.html -* -* SPDX-License-Identifier: EPL-2.0 -* -* Copyright Contributors to the Zowe Project. -* -*/ - -/** - * Interface representing the result of a Dameon command. - * @export - * @interface IDaemonCmdResult - */ -export interface IDaemonCmdResult { - /** - * Success or failure. - * @type {string} - * @memberof IDaemonCmdResult - */ - success: boolean; - - /** - * Text message associated with our result. - * @type {string} - * @memberof IDaemonCmdResult - */ - msgText: string; -} - diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index d9f3b0829c..c2a6a1acd3 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -9,8 +9,15 @@ * */ -import { ICommandHandler, IHandlerParameters } from "@zowe/imperative"; -import { IDaemonCmdResult } from "../doc/IDaemonCmdResult"; +import * as fs from "fs"; +import * as nodeJsPath from "path"; +// todo: import * as tar from "tar"; +import * as zlib from "zlib"; + +import { + ICommandHandler, IHandlerParameters, ImperativeConfig, ImperativeError, + IO, ISystemInfo, ProcessUtils +} from "@zowe/imperative"; /** * Handler to enable daemon mode. @@ -28,12 +35,17 @@ export default class EnableDaemonHandler implements ICommandHandler { * @throws {ImperativeError} */ public process(cmdParams: IHandlerParameters): Promise { - const cmdResult = this.enableDaemon(); - if ( cmdResult.success ) { - cmdParams.response.console.log("Daemon mode enabled.\n" + cmdResult.msgText); - } else { - cmdParams.response.console.log("Failed to enable daemon mode.\n" + cmdResult.msgText); + let userMsg: string; + try { + userMsg = this.enableDaemon(); + } catch(impErr) { + cmdParams.response.console.log("Failed to enable daemon mode.\n" + (impErr as ImperativeError).message); + cmdParams.response.data.setExitCode(1); + return; } + + cmdParams.response.console.log("Daemon mode enabled.\n" + userMsg); + cmdParams.response.data.setExitCode(0); return; } @@ -41,27 +53,64 @@ export default class EnableDaemonHandler implements ICommandHandler { * Enable daemon mode. We extract our native executable and place it * in ZOWE_CLI_HOME/bin. * - * @returns True upon success. False otherwise. + * @throws {ImperativeError} + * + * @returns {string} An informational message to display to the user after + * successful completion of the operation. */ - private enableDaemon(): IDaemonCmdResult { - const cmdResult: IDaemonCmdResult = { - success: true, - msgText: "" - }; - + private enableDaemon(): string { // determine our current OS + const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); - // form the path to our prebuilds directory - - // find the tar file for our OS executable + // form the path to our prebuilds tar file + let preBldTgz = __dirname + "../../../../prebuilds/zowe-"; + switch (sysInfo.platform) { + case "darwin": { + preBldTgz += "macos.tgz"; + break; + } + case "linux": { + preBldTgz += "linux.tgz"; + break; + } + case "win32": { + preBldTgz += "windows.tgz"; + break; + } + default: { + throw new ImperativeError({ + msg: `Daemon mode is not supported on the '${sysInfo.platform}' operating system.` + }); + } + } + preBldTgz = nodeJsPath.normalize(preBldTgz); - // form the path to our ZOWE_CLI_HOME bin directory + // form the path to the bin directory in ZOWE_CLI_HOME + const zoweHomeBin = nodeJsPath.normalize(ImperativeConfig.instance.cliHome + "/bin"); - // create the ZOWE_CLI_HOME bin directory if it does not exist + // Does the ZOWE_CLI_HOME bin directory exist? + if (IO.existsSync(zoweHomeBin)) { + if (IO.isDir(zoweHomeBin) == false) { + throw new ImperativeError({ + msg: `The existing file '${zoweHomeBin}' must be a directory.` + }); + } + } else { + // create the directory + try { + IO.createDirSync(zoweHomeBin); + } + catch(err) { + throw new ImperativeError({ + msg: `Unable to create directory '${zoweHomeBin}'.\nReason: ${err}` + }); + } + } - // check the version of any existing executable + // todo: check the version of any existing executable // extract executable from the tar file into the bin directory + this.unzipTgz(preBldTgz, zoweHomeBin, "todo"); // detect whether ZOWE_CLI_HOME/bin is already on our PATH @@ -71,7 +120,36 @@ export default class EnableDaemonHandler implements ICommandHandler { // display results and directions to the user - cmdResult.msgText = "Add ZOWE_CLI_HOME/bin to your path."; - return cmdResult; + return `You must add '${zoweHomeBin}' to your path.`; + } + + /** + * Unzip some or all of the content of a gzipped tar file. + * in ZOWE_CLI_HOME/bin. + * + * @param tgzFile The gzipped tar file that we will extract + * + * @param toDir The directory into whic we extract files + * + * @param extractRegex The Regex to match files to extract. + * + * @throws {ImperativeError} + */ + private unzipTgz(tgzFile: string, toDir: string, extractRegex: string): void { + console.log("Todo: unzipTgz:\n tgzFile = " + tgzFile + + "\n toDir = " + toDir + + "\n extractRegex = " + extractRegex + ); + + /* todo: + fs.createReadStream(tgzFile) + .on('error', function(err) { + throw new ImperativeError({ + msg: err + }); + }) + .pipe(zlib.Unzip()) + .pipe(tar.Parse()) + todo */ } } From a1a901c88415446e1b743e05539abc79c50e675b Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 8 Dec 2021 15:00:48 -0500 Subject: [PATCH 10/78] First cut on integration tests. Signed-off-by: Gene Johnston --- .../enable/__scripts__/daemon_enable.sh | 9 +++ .../enable/__scripts__/daemon_enable_help.sh | 9 +++ ...cli.daemon.enable.integration.test.ts.snap | 48 +++++++++++++ .../cli.daemon.enable.integration.test.ts | 70 +++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh create mode 100644 packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh create mode 100644 packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap create mode 100644 packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh new file mode 100644 index 0000000000..1d3b701ec4 --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +echo "================ daemon enable ===============" +zowe daemon enable +if [ $? -gt 0 ] +then + exit $? +fi diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh new file mode 100644 index 0000000000..08609e9030 --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +echo "================ daemon enable help ===============" +zowe daemon enable --help +if [ $? -gt 0 ] +then + exit $? +fi diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap b/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap new file mode 100644 index 0000000000..bcff11808f --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap @@ -0,0 +1,48 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`daemon enable should display the help 1`] = ` +"================ daemon enable help =============== + + COMMAND NAME + ------------ + + enable + + DESCRIPTION + ----------- + + Enables daemon-mode operation of the Zowe-CLI. + + USAGE + ----- + + zowe daemon enable [options] + + GLOBAL OPTIONS + -------------- + + --response-format-json | --rfj (boolean) + + Produce JSON formatted data from a command + + --help | -h (boolean) + + Display help text + + --help-examples (boolean) + + Display examples for all the commands in a group + + --help-web | --hw (boolean) + + Display HTML help in browser + + EXAMPLES + -------- + + - Enable daemon-mode: + + $ zowe daemon enable + +" +`; diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts new file mode 100644 index 0000000000..6aef17ffc0 --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -0,0 +1,70 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import * as fs from "fs"; +import * as nodeJsPath from "path"; + +let testEnvironment: ITestEnvironment; + +describe("daemon enable", () => { + const rimraf = require("rimraf").sync; + let pathToBin: string; + + beforeAll(async () => { + // Create the unique test environment + testEnvironment = await TestEnvironment.setUp({ + testName: "daemon_enable_integration", + skipProperties: true + }); + pathToBin = nodeJsPath.normalize(testEnvironment.workingDir + "/bin"); + }); + + beforeEach(async () => { + // Remove any existing bin directory + rimraf(pathToBin); + }); + + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should display the help", async () => { + const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); + expect(response.stdout.toString()).toMatchSnapshot(); + }); + + it("should fail if a bin file exists", async () => { + fs.writeFileSync(pathToBin, "not a directory"); + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Failed to enable daemon mode."); + expect(stdoutStr).toContain(`The existing file '${pathToBin}' must be a directory.`); + expect(response.status).toBe(1); + }); + + it("should place exe in a new bin dir", async () => { + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + expect(response.status).toBe(0); + // todo: confirm exe exists + }); + + it("should place exe in an existing bin dir", async () => { + fs.mkdirSync(pathToBin, 0o755); + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + expect(response.status).toBe(0); + // todo: confirm exe exists + }); +}); From b2c3d35d54027abca2aaff72fb3e8fa613a1d5d5 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 9 Dec 2021 16:08:26 -0500 Subject: [PATCH 11/78] Test no tgz, exe created, exe is overwritten. Signed-off-by: Gene Johnston --- .../cli.daemon.enable.integration.test.ts | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 6aef17ffc0..56a67d381f 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -9,9 +9,12 @@ * */ +import { IO, ISystemInfo, ProcessUtils } from "@zowe/imperative"; import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; + import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; + import * as fs from "fs"; import * as nodeJsPath from "path"; @@ -19,7 +22,9 @@ let testEnvironment: ITestEnvironment; describe("daemon enable", () => { const rimraf = require("rimraf").sync; + let exePath: string; let pathToBin: string; + let preBldTgz: string; beforeAll(async () => { // Create the unique test environment @@ -27,7 +32,37 @@ describe("daemon enable", () => { testName: "daemon_enable_integration", skipProperties: true }); + + // determine our current OS + const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); + + // form the path to our bin directory, executable, and prebuilds tgz file + preBldTgz = __dirname + "/../../../../prebuilds/zowe-"; + switch (sysInfo.platform) { + case "darwin": { + preBldTgz += "macos.tgz"; + exePath = "zowe"; + break; + } + case "linux": { + preBldTgz += "linux.tgz"; + exePath = "zowe"; + break; + } + case "win32": { + preBldTgz += "windows.tgz"; + exePath = "zowe.exe"; + break; + } + default: { + preBldTgz += "unknownOs.tgz"; + exePath = "exeForUnknownOs"; + throw "cli.daemon.enable.integration.test.ts: beforeAll: " + sysInfo.platform + " is not a known OS."; + } + } pathToBin = nodeJsPath.normalize(testEnvironment.workingDir + "/bin"); + exePath = nodeJsPath.normalize(pathToBin + "/" + exePath); + preBldTgz = nodeJsPath.normalize(preBldTgz); }); beforeEach(async () => { @@ -46,6 +81,22 @@ describe("daemon enable", () => { expect(response.stdout.toString()).toMatchSnapshot(); }); + it("should fail when the tgz file does not exist", async () => { + // temporarily remove the desired tgz file - keep an eye open for impact on parallel tests + const tempRenamedTgz = preBldTgz + "_temp_rename"; + fs.renameSync(preBldTgz, tempRenamedTgz); + + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + + // restore our tgz file for other tests + fs.renameSync(tempRenamedTgz, preBldTgz); + + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Failed to enable daemon mode."); + expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgz}`); + expect(response.status).toBe(1); + }); + it("should fail if a bin file exists", async () => { fs.writeFileSync(pathToBin, "not a directory"); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); @@ -58,13 +109,25 @@ describe("daemon enable", () => { it("should place exe in a new bin dir", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); expect(response.status).toBe(0); - // todo: confirm exe exists + expect(IO.existsSync(exePath)).toBe(true); }); it("should place exe in an existing bin dir", async () => { fs.mkdirSync(pathToBin, 0o755); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); expect(response.status).toBe(0); - // todo: confirm exe exists + expect(IO.existsSync(exePath)).toBe(true); + }); + + it("should overwite an existing exe", async () => { + const fakeExeContent = "This is not a real executable"; + fs.mkdirSync(pathToBin, 0o755); + fs.writeFileSync(exePath, fakeExeContent); + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + expect(response.status).toBe(0); + expect(IO.existsSync(exePath)).toBe(true); + + const exeStats = fs.statSync(exePath); + expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); }); }); From 9f39e2fc38874a116546cac35ac5075fbd016aa6 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 9 Dec 2021 16:49:59 -0500 Subject: [PATCH 12/78] Add semicolon for lint. Signed-off-by: Gene Johnston --- .../daemon/__unit__/disable/Disable.handler.unit.test.ts | 3 ++- .../daemon/__unit__/enable/Enable.handler.unit.test.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts index 7982374867..aecab93f6a 100644 --- a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts @@ -8,6 +8,7 @@ * Copyright Contributors to the Zowe Project. * */ + import DisableDaemonHandler from "../../../../src/daemon/disable/Disable.handler"; describe("Disable daemon handler", () => { @@ -56,7 +57,7 @@ describe("Disable daemon handler", () => { const allOkMsg = "Everything worked ok"; disableDaemonSpy = jest.spyOn(DisableDaemonHandler.prototype as any, "disableDaemon"); - disableDaemonSpy.mockImplementation(() => {return allOkMsg}); + disableDaemonSpy.mockImplementation(() => {return allOkMsg;}); try { // Invoke the handler with a full set of mocked arguments and response functions diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 608963f5c9..74de7f3e4d 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -65,7 +65,7 @@ describe("Handler for daemon enable", () => { // spy on our handler's private enableDaemon() function enableDaemonSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "enableDaemon"); - enableDaemonSpy.mockImplementation(() => {return allOkMsg}); + enableDaemonSpy.mockImplementation(() => {return allOkMsg;}); try { // Invoke the handler with a full set of mocked arguments and response functions From ec3c6ebf5504bde9601885a95849d4613a2ce814 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 9 Dec 2021 16:57:23 -0500 Subject: [PATCH 13/78] Add tar dependency. Signed-off-by: Gene Johnston --- package-lock.json | 96 ++++++++++++++++++++++++++++++++++++++- packages/cli/package.json | 3 +- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0637bb34e4..6deb8ab513 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26434,7 +26434,8 @@ "@zowe/zosmf-for-zowe-sdk": "7.0.0-next.202111222227", "get-stdin": "7.0.0", "lodash": "4.17.21", - "minimatch": "3.0.4" + "minimatch": "3.0.4", + "tar": "6.1.11" }, "bin": { "bright": "lib/main.js", @@ -26460,6 +26461,15 @@ "keytar": "7.7.0" } }, + "packages/cli/node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha1-Fb++U9LqtM9w8YqM1o6+Wzyx3s4=", + "license": "ISC", + "engines": { + "node": ">=10" + } + }, "packages/cli/node_modules/get-stdin": { "version": "7.0.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/get-stdin/-/get-stdin-7.0.0.tgz", @@ -26469,6 +26479,53 @@ "node": ">=8" } }, + "packages/cli/node_modules/minipass": { + "version": "3.1.6", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/minipass/-/minipass-3.1.6.tgz", + "integrity": "sha1-O4FQqmiKcRoVIa9eh3nB07tPRe4=", + "license": "ISC", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "packages/cli/node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha1-PrXtYmInVteaXw4qIh3+utdcL34=", + "license": "MIT", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, + "packages/cli/node_modules/tar": { + "version": "6.1.11", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/tar/-/tar-6.1.11.tgz", + "integrity": "sha1-Z2CjjwA6+hsv/Q/+npq70Oqz1iE=", + "license": "ISC", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^3.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 10" + } + }, + "packages/cli/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha1-m7knkNnA7/7GO+c1GeEaNQGaOnI=", + "license": "ISC" + }, "packages/core": { "name": "@zowe/core-for-zowe-sdk", "version": "7.0.0-next.202111222227", @@ -30644,14 +30701,51 @@ "minimatch": "3.0.4", "rimraf": "^2.6.3", "strip-ansi": "^6.0.1", + "tar": "6.1.11", "typedoc": "^0.16.0", "typescript": "^3.8.0" }, "dependencies": { + "chownr": { + "version": "2.0.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha1-Fb++U9LqtM9w8YqM1o6+Wzyx3s4=" + }, "get-stdin": { "version": "7.0.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/get-stdin/-/get-stdin-7.0.0.tgz", "integrity": "sha1-jV3pjxUXGhJcXlFmQ8em0OqKlvY=" + }, + "minipass": { + "version": "3.1.6", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/minipass/-/minipass-3.1.6.tgz", + "integrity": "sha1-O4FQqmiKcRoVIa9eh3nB07tPRe4=", + "requires": { + "yallist": "^4.0.0" + } + }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha1-PrXtYmInVteaXw4qIh3+utdcL34=" + }, + "tar": { + "version": "6.1.11", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/tar/-/tar-6.1.11.tgz", + "integrity": "sha1-Z2CjjwA6+hsv/Q/+npq70Oqz1iE=", + "requires": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^3.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha1-m7knkNnA7/7GO+c1GeEaNQGaOnI=" } } }, diff --git a/packages/cli/package.json b/packages/cli/package.json index 00c6b8a723..add1adaffa 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -68,7 +68,8 @@ "@zowe/zosmf-for-zowe-sdk": "7.0.0-next.202111222227", "get-stdin": "7.0.0", "lodash": "4.17.21", - "minimatch": "3.0.4" + "minimatch": "3.0.4", + "tar": "6.1.11" }, "devDependencies": { "@types/lodash": "^4.14.175", From 839ee54291db87ea2a76d4b2c862b6e066f8da2c Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 9 Dec 2021 17:14:27 -0500 Subject: [PATCH 14/78] Add @types/tar Signed-off-by: Gene Johnston --- package-lock.json | 42 +++++++++++++++++++++++++++++++++++++++ packages/cli/package.json | 1 + 2 files changed, 43 insertions(+) diff --git a/package-lock.json b/package-lock.json index 6deb8ab513..010ed3fead 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5043,6 +5043,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/minipass": { + "version": "3.1.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/minipass/-/minipass-3.1.0.tgz", + "integrity": "sha1-YW3MIgWYLUxyD0x+mp/dxJckUnM=", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/node": { "version": "12.20.37", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/node/-/node-12.20.37.tgz", @@ -5091,6 +5101,17 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/tar": { + "version": "6.1.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/tar/-/tar-6.1.1.tgz", + "integrity": "sha1-qzQewfFJ1+sqT03tVv+F8NT+fLU=", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/minipass": "*", + "@types/node": "*" + } + }, "node_modules/@types/uuid": { "version": "8.3.3", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/uuid/-/uuid-8.3.3.tgz", @@ -26444,6 +26465,7 @@ "devDependencies": { "@types/lodash": "^4.14.175", "@types/node": "^12.12.24", + "@types/tar": "6.1.1", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "comment-json": "^4.1.0", "eslint": "^7.32.0", @@ -30487,6 +30509,15 @@ "integrity": "sha1-7nceK6Sz3Fs3KTXVSf2WF780W4w=", "dev": true }, + "@types/minipass": { + "version": "3.1.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/minipass/-/minipass-3.1.0.tgz", + "integrity": "sha1-YW3MIgWYLUxyD0x+mp/dxJckUnM=", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/node": { "version": "12.20.37", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/node/-/node-12.20.37.tgz", @@ -30529,6 +30560,16 @@ "integrity": "sha1-CoUdO9lkmPolwzq3J47TvWXwbD4=", "dev": true }, + "@types/tar": { + "version": "6.1.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/tar/-/tar-6.1.1.tgz", + "integrity": "sha1-qzQewfFJ1+sqT03tVv+F8NT+fLU=", + "dev": true, + "requires": { + "@types/minipass": "*", + "@types/node": "*" + } + }, "@types/uuid": { "version": "8.3.3", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/uuid/-/uuid-8.3.3.tgz", @@ -30679,6 +30720,7 @@ "requires": { "@types/lodash": "^4.14.175", "@types/node": "^12.12.24", + "@types/tar": "6.1.1", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "@zowe/core-for-zowe-sdk": "7.0.0-next.202111222227", "@zowe/imperative": "5.0.0-next.202112012301", diff --git a/packages/cli/package.json b/packages/cli/package.json index add1adaffa..e64956889a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -74,6 +74,7 @@ "devDependencies": { "@types/lodash": "^4.14.175", "@types/node": "^12.12.24", + "@types/tar": "6.1.1", "@zowe/cli-test-utils": "7.0.0-next.202111222227", "comment-json": "^4.1.0", "eslint": "^7.32.0", From 2c02998288b7eddd528db5afa918ea2f8d05835e Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 9 Dec 2021 17:27:07 -0500 Subject: [PATCH 15/78] Unzip desired executable synchronously. Signed-off-by: Gene Johnston --- .../cli/src/daemon/enable/Enable.handler.ts | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index c2a6a1acd3..cc8d8f4c51 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -11,8 +11,7 @@ import * as fs from "fs"; import * as nodeJsPath from "path"; -// todo: import * as tar from "tar"; -import * as zlib from "zlib"; +import * as tar from "tar"; import { ICommandHandler, IHandlerParameters, ImperativeConfig, ImperativeError, @@ -34,10 +33,10 @@ export default class EnableDaemonHandler implements ICommandHandler { * * @throws {ImperativeError} */ - public process(cmdParams: IHandlerParameters): Promise { + public async process(cmdParams: IHandlerParameters): Promise { let userMsg: string; try { - userMsg = this.enableDaemon(); + userMsg = await this.enableDaemon(); } catch(impErr) { cmdParams.response.console.log("Failed to enable daemon mode.\n" + (impErr as ImperativeError).message); cmdParams.response.data.setExitCode(1); @@ -58,7 +57,7 @@ export default class EnableDaemonHandler implements ICommandHandler { * @returns {string} An informational message to display to the user after * successful completion of the operation. */ - private enableDaemon(): string { + private async enableDaemon(): Promise { // determine our current OS const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); @@ -83,7 +82,13 @@ export default class EnableDaemonHandler implements ICommandHandler { }); } } + preBldTgz = nodeJsPath.normalize(preBldTgz); + if (IO.existsSync(preBldTgz) == false) { + throw new ImperativeError({ + msg: `The zip file for your OS executable does not exist: ${preBldTgz}` + }); + } // form the path to the bin directory in ZOWE_CLI_HOME const zoweHomeBin = nodeJsPath.normalize(ImperativeConfig.instance.cliHome + "/bin"); @@ -110,7 +115,7 @@ export default class EnableDaemonHandler implements ICommandHandler { // todo: check the version of any existing executable // extract executable from the tar file into the bin directory - this.unzipTgz(preBldTgz, zoweHomeBin, "todo"); + await this.unzipTgz(preBldTgz, zoweHomeBin, ImperativeConfig.instance.rootCommandName); // detect whether ZOWE_CLI_HOME/bin is already on our PATH @@ -124,32 +129,37 @@ export default class EnableDaemonHandler implements ICommandHandler { } /** - * Unzip some or all of the content of a gzipped tar file. - * in ZOWE_CLI_HOME/bin. + * Unzip, from a gzipped tar file, any file that contains fileToExtract as a + * substring of the file name. The file will be placed into toDir. + * We expect toDir to already exist. * * @param tgzFile The gzipped tar file that we will extract * - * @param toDir The directory into whic we extract files + * @param toDir The directory into which we extract files * - * @param extractRegex The Regex to match files to extract. + * @param fileToExtract The file name (or substring of the file name) to extract. * * @throws {ImperativeError} + * @returns A void promise to synchronize this operation. */ - private unzipTgz(tgzFile: string, toDir: string, extractRegex: string): void { - console.log("Todo: unzipTgz:\n tgzFile = " + tgzFile + - "\n toDir = " + toDir + - "\n extractRegex = " + extractRegex - ); - - /* todo: - fs.createReadStream(tgzFile) - .on('error', function(err) { - throw new ImperativeError({ - msg: err + private async unzipTgz(tgzFile: string, toDir: string, fileToExtract: string): Promise { + return new Promise((resolve) => { + fs.createReadStream(tgzFile) + .on('error', function(err) { + throw new ImperativeError({ + msg: err + }); + }) + .pipe(new tar.Parse()) + .on('entry', function(entry: any) { + if (entry.type == "File" && (entry.path as string).includes(fileToExtract)) { + // do not include any path structure from the tgz, just the exe name + entry.pipe(fs.createWriteStream(nodeJsPath.resolve(toDir, nodeJsPath.basename(entry.path)))); + } + }) + .on("end", () => { + resolve(); }); - }) - .pipe(zlib.Unzip()) - .pipe(tar.Parse()) - todo */ + }); } } From b5913bbf2ac09f9e800ffb6c978c21a0813654a6 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 10 Dec 2021 14:22:31 -0500 Subject: [PATCH 16/78] Use fake TGZs from __resources__ for testing. Signed-off-by: Gene Johnston --- .../cli.daemon.enable.integration.test.ts | 39 ++++++++++++------ .../daemon/__resources__/zowe-linux.tgz | Bin 0 -> 224 bytes .../daemon/__resources__/zowe-macos.tar.gz | Bin 0 -> 319 bytes .../daemon/__resources__/zowe-windows.tgz | Bin 0 -> 226 bytes 4 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 packages/cli/__tests__/daemon/__resources__/zowe-linux.tgz create mode 100644 packages/cli/__tests__/daemon/__resources__/zowe-macos.tar.gz create mode 100644 packages/cli/__tests__/daemon/__resources__/zowe-windows.tgz diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 56a67d381f..46ed5e3b12 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -22,9 +22,11 @@ let testEnvironment: ITestEnvironment; describe("daemon enable", () => { const rimraf = require("rimraf").sync; + const fakeExeContent = "This is not a real executable"; + let exePath: string; let pathToBin: string; - let preBldTgz: string; + let preBldTgzPath: string; beforeAll(async () => { // Create the unique test environment @@ -37,32 +39,42 @@ describe("daemon enable", () => { const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); // form the path to our bin directory, executable, and prebuilds tgz file - preBldTgz = __dirname + "/../../../../prebuilds/zowe-"; + preBldTgzPath = "zowe-"; switch (sysInfo.platform) { case "darwin": { - preBldTgz += "macos.tgz"; + preBldTgzPath += "macos.tgz"; exePath = "zowe"; break; } case "linux": { - preBldTgz += "linux.tgz"; + preBldTgzPath += "linux.tgz"; exePath = "zowe"; break; } case "win32": { - preBldTgz += "windows.tgz"; + preBldTgzPath += "windows.tgz"; exePath = "zowe.exe"; break; } default: { - preBldTgz += "unknownOs.tgz"; + preBldTgzPath += "unknownOs.tgz"; exePath = "exeForUnknownOs"; throw "cli.daemon.enable.integration.test.ts: beforeAll: " + sysInfo.platform + " is not a known OS."; } } - pathToBin = nodeJsPath.normalize(testEnvironment.workingDir + "/bin"); - exePath = nodeJsPath.normalize(pathToBin + "/" + exePath); - preBldTgz = nodeJsPath.normalize(preBldTgz); + const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", preBldTgzPath); + const preBldDir = nodeJsPath.resolve(__dirname, "../../../../prebuilds"); + preBldTgzPath = nodeJsPath.resolve(preBldDir, preBldTgzPath); + pathToBin = nodeJsPath.resolve(testEnvironment.workingDir, "bin"); + exePath = nodeJsPath.resolve(pathToBin, exePath); + + // copy a fake tgz file from resources to our prebuilds directory for testing + if (!IO.existsSync(preBldDir)) { + IO.createDirSync(preBldDir); + } + if (!IO.existsSync(preBldTgzPath)) { + fs.copyFileSync(tgzResourcePath, preBldTgzPath); + } }); beforeEach(async () => { @@ -83,17 +95,17 @@ describe("daemon enable", () => { it("should fail when the tgz file does not exist", async () => { // temporarily remove the desired tgz file - keep an eye open for impact on parallel tests - const tempRenamedTgz = preBldTgz + "_temp_rename"; - fs.renameSync(preBldTgz, tempRenamedTgz); + const tempRenamedTgz = preBldTgzPath + "_temp_rename"; + fs.renameSync(preBldTgzPath, tempRenamedTgz); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); // restore our tgz file for other tests - fs.renameSync(tempRenamedTgz, preBldTgz); + fs.renameSync(tempRenamedTgz, preBldTgzPath); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Failed to enable daemon mode."); - expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgz}`); + expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); expect(response.status).toBe(1); }); @@ -127,6 +139,7 @@ describe("daemon enable", () => { expect(response.status).toBe(0); expect(IO.existsSync(exePath)).toBe(true); + // our test tgz file is more than 10 bytes larger than this fake tgz const exeStats = fs.statSync(exePath); expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); }); diff --git a/packages/cli/__tests__/daemon/__resources__/zowe-linux.tgz b/packages/cli/__tests__/daemon/__resources__/zowe-linux.tgz new file mode 100644 index 0000000000000000000000000000000000000000..e946f59bdd32a9fffb7abebf9e5ee94a83fc0dd8 GIT binary patch literal 224 zcmV<603ZJ!iwFS9h_hh?0PT`NY6CG0MZFH>4*vwf(jj~lixvgI-O4EKYRkUR6bAu2mk<13uWa1 literal 0 HcmV?d00001 diff --git a/packages/cli/__tests__/daemon/__resources__/zowe-macos.tar.gz b/packages/cli/__tests__/daemon/__resources__/zowe-macos.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..cfc2038be27609f9bf719efbc47f5653350bb004 GIT binary patch literal 319 zcmV-F0l@wriwFqFi?d+>1A1?FWi4%CV{daVbYXG;?b1z7!!Qs9;H)e44(|lTp>2Ev zDmJhH4&WwJk}8cO$0mf+<5Yl91+4nB;C+f@S$4)FKdc`q?*RsFZE`7XU5LZRI+zCXDtYi` z9iPW^a=(75Z0PC%gAK?{(^wA|8u+o!rrK}1^006+bl>q<% literal 0 HcmV?d00001 diff --git a/packages/cli/__tests__/daemon/__resources__/zowe-windows.tgz b/packages/cli/__tests__/daemon/__resources__/zowe-windows.tgz new file mode 100644 index 0000000000000000000000000000000000000000..45670bea623214b4bf0593c4385e375ad599dc1b GIT binary patch literal 226 zcmV<803H7yiwFQsh_hh?0PT`NY6Kw=MO_cf9sUU#o0-NlWR*=W;AjnYu&u!^)9IW( znm`Cy1~O#fLlCX{zlx&Xc%y+{N&O*u)Y=%M^d~=WebS>E&*OA9`eaP|H|Ee%N-W4F zL7LBX{z!U|FUPWyhcJZdV+$mq8gJB;aGWzaiTm;3=@xkhm;9|9wpjwI0&Pj*EiGKz cNi9~z%VLuspgNsSr}G=$0siky_W%e0052YA+W-In literal 0 HcmV?d00001 From 48368eba3f1162a7ccead81d0454a87531a5eb0c Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 10 Dec 2021 14:41:55 -0500 Subject: [PATCH 17/78] Add to description of the enable command. Signed-off-by: Gene Johnston --- packages/cli/src/daemon/enable/Enable.definition.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/daemon/enable/Enable.definition.ts b/packages/cli/src/daemon/enable/Enable.definition.ts index 817a56d3ed..2f0c45a116 100644 --- a/packages/cli/src/daemon/enable/Enable.definition.ts +++ b/packages/cli/src/daemon/enable/Enable.definition.ts @@ -13,7 +13,10 @@ import { ICommandDefinition } from "@zowe/imperative"; export const EnableCommand: ICommandDefinition = { name: "enable", - description: "Enables daemon-mode operation of the Zowe-CLI.", + description: "Enables daemon-mode operation of the Zowe-CLI. " + + "You only need to run the enable command once after each " + + "new installation of the Zowe-CLI. Afterwards, any zowe command " + + "will automatically start a daemon as needed.", type: "command", handler: __dirname + "/Enable.handler", examples: [ From fc0bfadcc38c567d4b9fe8a1f338c003a640b988 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 10 Dec 2021 17:28:44 -0500 Subject: [PATCH 18/78] Check PATH and ZOWE_USE_DAEMON. New msgs & help. Signed-off-by: Gene Johnston --- ...cli.daemon.enable.integration.test.ts.snap | 4 ++- .../cli.daemon.enable.integration.test.ts | 4 +-- .../disable/Disable.handler.unit.test.ts | 2 +- .../enable/Enable.handler.unit.test.ts | 8 ++--- .../Enable.definition.unit.test.ts.snap | 2 +- .../cli/src/daemon/disable/Disable.handler.ts | 4 +-- .../cli/src/daemon/enable/Enable.handler.ts | 33 +++++++++++++------ 7 files changed, 36 insertions(+), 21 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap b/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap index bcff11808f..2818b886c8 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap +++ b/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap @@ -11,7 +11,9 @@ exports[`daemon enable should display the help 1`] = ` DESCRIPTION ----------- - Enables daemon-mode operation of the Zowe-CLI. + Enables daemon-mode operation of the Zowe-CLI. You only need to run the enable + command once after each new installation of the Zowe-CLI. Afterwards, any zowe + command will automatically start a daemon as needed. USAGE ----- diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 46ed5e3b12..aa288582c6 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -104,7 +104,7 @@ describe("daemon enable", () => { fs.renameSync(tempRenamedTgz, preBldTgzPath); const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Failed to enable daemon mode."); + expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); expect(response.status).toBe(1); }); @@ -113,7 +113,7 @@ describe("daemon enable", () => { fs.writeFileSync(pathToBin, "not a directory"); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Failed to enable daemon mode."); + expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); expect(stdoutStr).toContain(`The existing file '${pathToBin}' must be a directory.`); expect(response.status).toBe(1); }); diff --git a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts index aecab93f6a..007c79b4c5 100644 --- a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts @@ -68,7 +68,7 @@ describe("Disable daemon handler", () => { expect(error).toBeUndefined(); expect(disableDaemonSpy).toHaveBeenCalledTimes(1); - expect(logMessage).toContain("Daemon mode disabled"); + expect(logMessage).toContain("Zowe CLI daemon mode disabled"); expect(logMessage).toContain(allOkMsg); }); }); diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 74de7f3e4d..e246e19826 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -76,7 +76,7 @@ describe("Handler for daemon enable", () => { expect(error).toBeUndefined(); expect(enableDaemonSpy).toHaveBeenCalledTimes(1); - expect(logMessage).toContain("Daemon mode enabled"); + expect(logMessage).toContain("Zowe CLI daemon mode enabled."); expect(logMessage).toContain(allOkMsg); }); @@ -102,7 +102,7 @@ describe("Handler for daemon enable", () => { expect(error).toBeUndefined(); expect(enableDaemonSpy).toHaveBeenCalledTimes(1); - expect(logMessage).toContain("Failed to enable daemon mode"); + expect(logMessage).toContain("Failed to enable Zowe CLI daemon mode"); expect(logMessage).toContain(badStuffMsg); }); @@ -125,7 +125,7 @@ describe("Handler for daemon enable", () => { } expect(error).toBeUndefined(); - expect(logMessage).toContain("Failed to enable daemon mode"); + expect(logMessage).toContain("Failed to enable Zowe CLI daemon mode"); expect(logMessage).toContain("Daemon mode is not supported on the 'BogusPlatform' operating system."); ProcessUtils.getBasicSystemInfo = getBasicSystemInfoOrig; }); @@ -163,7 +163,7 @@ describe("Handler for daemon enable", () => { } expect(error).toBeUndefined(); - expect(logMessage).toContain("Failed to enable daemon mode"); + expect(logMessage).toContain("Failed to enable Zowe CLI daemon mode"); expect(logMessage).toContain(`Unable to create directory '${mockCliHomeDir}`); expect(logMessage).toContain("Reason: " + awfulThrownErr); IO.existsSync = existsSyncOrig; diff --git a/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap index 1bd8c3ab72..f6088bf15d 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap +++ b/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap @@ -2,7 +2,7 @@ exports[`daemon enable definition should not have changed 1`] = ` Object { - "description": "Enables daemon-mode operation of the Zowe-CLI.", + "description": "Enables daemon-mode operation of the Zowe-CLI. You only need to run the enable command once after each new installation of the Zowe-CLI. Afterwards, any zowe command will automatically start a daemon as needed.", "examples": Array [ Object { "description": "Enable daemon-mode", diff --git a/packages/cli/src/daemon/disable/Disable.handler.ts b/packages/cli/src/daemon/disable/Disable.handler.ts index fae1e44933..4dcccd68ac 100644 --- a/packages/cli/src/daemon/disable/Disable.handler.ts +++ b/packages/cli/src/daemon/disable/Disable.handler.ts @@ -31,12 +31,12 @@ export default class DisableDaemonHandler implements ICommandHandler { try { userMsg = this.disableDaemon(); } catch(impErr) { - cmdParams.response.console.log("Failed to disable daemon mode.\n" + (impErr as ImperativeError).message); + cmdParams.response.console.log("Failed to disable Zowe CLI daemon mode.\n" + (impErr as ImperativeError).message); cmdParams.response.data.setExitCode(1); return; } - cmdParams.response.console.log("Daemon mode disabled.\n" + userMsg); + cmdParams.response.console.log("Zowe CLI daemon mode disabled.\n" + userMsg); cmdParams.response.data.setExitCode(0); return; } diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index cc8d8f4c51..97c60538cb 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -38,12 +38,12 @@ export default class EnableDaemonHandler implements ICommandHandler { try { userMsg = await this.enableDaemon(); } catch(impErr) { - cmdParams.response.console.log("Failed to enable daemon mode.\n" + (impErr as ImperativeError).message); + cmdParams.response.console.log("Failed to enable Zowe CLI daemon mode.\n" + (impErr as ImperativeError).message); cmdParams.response.data.setExitCode(1); return; } - cmdParams.response.console.log("Daemon mode enabled.\n" + userMsg); + cmdParams.response.console.log("Zowe CLI daemon mode enabled.\n" + userMsg); cmdParams.response.data.setExitCode(0); return; } @@ -112,20 +112,33 @@ export default class EnableDaemonHandler implements ICommandHandler { } } - // todo: check the version of any existing executable - // extract executable from the tar file into the bin directory await this.unzipTgz(preBldTgz, zoweHomeBin, ImperativeConfig.instance.rootCommandName); - // detect whether ZOWE_CLI_HOME/bin is already on our PATH - - // start the daemon if it is already on our PATH + // display the version of the executable + let userInfoMsg: string = "Zowe CLI native executable version = 'todo: get the version'."; - // Check if ZOWE_USE_DAEMON has a value + // if ZOWE_CLI_HOME/bin is not on our PATH, add an instruction to add it + if (process.env?.PATH?.length > 0) { + if (!process.env.PATH.includes(zoweHomeBin)) { + userInfoMsg += `\n\nAdd '${zoweHomeBin}' to your path.` + + "\nOtherwise, you will continue to run the classic Zowe CLI interpreter."; + } + } - // display results and directions to the user + // if ZOWE_USE_DAEMON is set, and turned off, add a warning message + if (process.env?.ZOWE_USE_DAEMON?.length > 0) { + switch (process.env.ZOWE_USE_DAEMON) { + case "no": + case "false": + case "0": { + userInfoMsg += `\n\nYour ZOWE_USE_DAEMON environment variable is set to '${process.env.ZOWE_USE_DAEMON}'.` + + "\nYou must remove it, or set it to 'yes' to use daemon mode."; + } + } + } - return `You must add '${zoweHomeBin}' to your path.`; + return userInfoMsg; } /** From f30e63b45d2b2e1ac2b429bdb72110ae809a2acc Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 10 Dec 2021 18:10:49 -0500 Subject: [PATCH 19/78] Add tests for bin on the PATH and not on the PATH. Signed-off-by: Gene Johnston --- .../cli.daemon.enable.integration.test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index aa288582c6..9fb704324d 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -121,6 +121,8 @@ describe("daemon enable", () => { it("should place exe in a new bin dir", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); expect(response.status).toBe(0); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(IO.existsSync(exePath)).toBe(true); }); @@ -128,6 +130,31 @@ describe("daemon enable", () => { fs.mkdirSync(pathToBin, 0o755); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); expect(response.status).toBe(0); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(IO.existsSync(exePath)).toBe(true); + }); + + it("should identify that bin is not on the PATH", async () => { + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + expect(response.status).toBe(0); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain(`Add '${pathToBin}' to your path`); + expect(stdoutStr).toContain("Otherwise, you will continue to run the classic Zowe CLI interpreter"); + expect(IO.existsSync(exePath)).toBe(true); + }); + + it("should NOT talk about PATH when bin is on the PATH", async () => { + const pathOrig = testEnvironment.env["PATH"]; + testEnvironment.env["PATH"] = pathToBin + nodeJsPath.delimiter + process.env.PATH; + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + testEnvironment.env["PATH"] = pathOrig; + + expect(response.status).toBe(0); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your path`); expect(IO.existsSync(exePath)).toBe(true); }); From 8ef00a4207cf0f28e23c43424d3574c53cbb9f54 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 10 Dec 2021 18:40:08 -0500 Subject: [PATCH 20/78] Add tests for ZOWE_USE_DAEMON. Signed-off-by: Gene Johnston --- .../cli.daemon.enable.integration.test.ts | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 9fb704324d..6baaa164b6 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -135,6 +135,19 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); }); + it("should overwite an existing exe", async () => { + const fakeExeContent = "This is not a real executable"; + fs.mkdirSync(pathToBin, 0o755); + fs.writeFileSync(exePath, fakeExeContent); + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + expect(response.status).toBe(0); + expect(IO.existsSync(exePath)).toBe(true); + + // our test tgz file is more than 10 bytes larger than this fake tgz + const exeStats = fs.statSync(exePath); + expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); + }); + it("should identify that bin is not on the PATH", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); expect(response.status).toBe(0); @@ -145,7 +158,7 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); }); - it("should NOT talk about PATH when bin is on the PATH", async () => { + it("should say nothing when bin is already on the PATH", async () => { const pathOrig = testEnvironment.env["PATH"]; testEnvironment.env["PATH"] = pathToBin + nodeJsPath.delimiter + process.env.PATH; const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); @@ -158,16 +171,38 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); }); - it("should overwite an existing exe", async () => { - const fakeExeContent = "This is not a real executable"; - fs.mkdirSync(pathToBin, 0o755); - fs.writeFileSync(exePath, fakeExeContent); + it("should identify that ZOWE_USE_DAEMON is set to 'no'", async () => { + testEnvironment.env["ZOWE_USE_DAEMON"] = "no"; const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + delete testEnvironment.env.ZOWE_USE_DAEMON; + expect(response.status).toBe(0); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Your ZOWE_USE_DAEMON environment variable is set to 'no'"); + expect(stdoutStr).toContain("You must remove it, or set it to 'yes' to use daemon mode"); expect(IO.existsSync(exePath)).toBe(true); + }); - // our test tgz file is more than 10 bytes larger than this fake tgz - const exeStats = fs.statSync(exePath); - expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); + it("should say nothing when ZOWE_USE_DAEMON is unset", async () => { + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + expect(response.status).toBe(0); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(testEnvironment.env["ZOWE_USE_DAEMON"]).toBeFalsy(); + expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); + expect(IO.existsSync(exePath)).toBe(true); + }); + + it("should say nothing when ZOWE_USE_DAEMON is set to 'yes'", async () => { + testEnvironment.env["ZOWE_USE_DAEMON"] = "yes"; + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + delete testEnvironment.env.ZOWE_USE_DAEMON; + + expect(response.status).toBe(0); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); + expect(IO.existsSync(exePath)).toBe(true); }); }); From 6bb34b16313a382c873eee68b7b2c7e2f3e938ba Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Mon, 13 Dec 2021 09:33:34 -0500 Subject: [PATCH 21/78] Update snapshot for daemon operations. Signed-off-by: Gene Johnston --- .../__snapshots__/BrightHelpTests.integration.test.ts.snap | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/__tests__/help/__integration__/__snapshots__/BrightHelpTests.integration.test.ts.snap b/packages/cli/__tests__/help/__integration__/__snapshots__/BrightHelpTests.integration.test.ts.snap index 358b0dcc74..93c09b4d41 100644 --- a/packages/cli/__tests__/help/__integration__/__snapshots__/BrightHelpTests.integration.test.ts.snap +++ b/packages/cli/__tests__/help/__integration__/__snapshots__/BrightHelpTests.integration.test.ts.snap @@ -27,6 +27,7 @@ exports[`Root level help tests top level help should contain support link 1`] = auth Connect to Zowe API ML authentication service config Manage JSON project and global configuration + daemon Daemon operations plugins Install and manage plug-ins. profiles Create and manage configuration profiles. (deprecated) From 017ab25b6885efcae9a85047dbdb038540234c23 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Mon, 13 Dec 2021 13:19:42 -0500 Subject: [PATCH 22/78] Update Snapshot for --dcd flag. Signed-off-by: Gene Johnston --- .../__unit__/__snapshots__/DaemonClient.unit.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/__tests__/daemon/__unit__/__snapshots__/DaemonClient.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/__snapshots__/DaemonClient.unit.test.ts.snap index 170cad2fff..e5807d90b4 100644 --- a/packages/cli/__tests__/daemon/__unit__/__snapshots__/DaemonClient.unit.test.ts.snap +++ b/packages/cli/__tests__/daemon/__unit__/__snapshots__/DaemonClient.unit.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`DaemonClient tests should process data when received 1`] = `"some data"`; +exports[`DaemonClient tests should process data when received 1`] = `"some data --dcd PWD"`; exports[`DaemonClient tests should process data when received 2`] = ` Object { From 3c001786200062ec2ab527d1afaba2e68ffc81aa Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Mon, 13 Dec 2021 13:20:32 -0500 Subject: [PATCH 23/78] Clear logMessage before each test. Signed-off-by: Gene Johnston --- .../__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index e246e19826..ed0b92ea19 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -56,6 +56,7 @@ describe("Handler for daemon enable", () => { beforeEach(() => { // remove enableDaemon spy & mock between tests enableDaemonSpy?.mockRestore(); + logMessage = ""; }); describe("process method", () => { From 3f4d4fabe132606fe59de894cefba27509305463 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Mon, 13 Dec 2021 15:42:59 -0500 Subject: [PATCH 24/78] Ensure TGZ file exists in prebuilds for unit tests. Signed-off-by: Gene Johnston --- .../cli.daemon.enable.integration.test.ts | 18 +++++---- .../enable/Enable.handler.unit.test.ts | 38 ++++++++++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 6baaa164b6..375b8f88b6 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -38,33 +38,35 @@ describe("daemon enable", () => { // determine our current OS const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); - // form the path to our bin directory, executable, and prebuilds tgz file - preBldTgzPath = "zowe-"; + // form our tgz file name + let tgzFileName = "zowe-"; switch (sysInfo.platform) { case "darwin": { - preBldTgzPath += "macos.tgz"; + tgzFileName += "macos.tgz"; exePath = "zowe"; break; } case "linux": { - preBldTgzPath += "linux.tgz"; + tgzFileName += "linux.tgz"; exePath = "zowe"; break; } case "win32": { - preBldTgzPath += "windows.tgz"; + tgzFileName += "windows.tgz"; exePath = "zowe.exe"; break; } default: { - preBldTgzPath += "unknownOs.tgz"; + tgzFileName += "unknownOs.tgz"; exePath = "exeForUnknownOs"; throw "cli.daemon.enable.integration.test.ts: beforeAll: " + sysInfo.platform + " is not a known OS."; } } - const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", preBldTgzPath); + + // form the path to our bin directory, executable, and prebuilds tgz file + const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", tgzFileName); const preBldDir = nodeJsPath.resolve(__dirname, "../../../../prebuilds"); - preBldTgzPath = nodeJsPath.resolve(preBldDir, preBldTgzPath); + preBldTgzPath = nodeJsPath.resolve(preBldDir, tgzFileName); pathToBin = nodeJsPath.resolve(testEnvironment.workingDir, "bin"); exePath = nodeJsPath.resolve(pathToBin, exePath); diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index ed0b92ea19..831cc30500 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -9,10 +9,13 @@ * */ -import { ImperativeConfig, ImperativeError, IO, ProcessUtils } from "@zowe/imperative"; +import { ImperativeConfig, ImperativeError, IO, ProcessUtils, ISystemInfo } from "@zowe/imperative"; import EnableDaemonHandler from "../../../../src/daemon/enable/Enable.handler"; +import * as fs from "fs"; +import * as nodeJsPath from "path"; + describe("Handler for daemon enable", () => { let enableHandler: any; // use "any" so we can call private functions let enableDaemonSpy: any; @@ -51,6 +54,39 @@ describe("Handler for daemon enable", () => { beforeAll(() => { // instantiate our handler enableHandler = new EnableDaemonHandler(); + + // form our tgz file name + const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); + let tgzFileName = "zowe-"; + switch (sysInfo.platform) { + case "darwin": { + tgzFileName += "macos.tgz"; + break; + } + case "linux": { + tgzFileName += "linux.tgz"; + break; + } + case "win32": { + tgzFileName += "windows.tgz"; + break; + } + default: { + tgzFileName += "unknownOs.tgz"; + throw "Enable.handler.unit.test.ts: beforeAll: " + sysInfo.platform + " is not a known OS."; + } + } + + // copy a fake tgz file from resources to our prebuilds directory for testing + const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", tgzFileName); + const preBldDir = nodeJsPath.resolve(__dirname, "../../../../prebuilds"); + const preBldTgzPath = nodeJsPath.resolve(preBldDir, tgzFileName); + if (!IO.existsSync(preBldDir)) { + IO.createDirSync(preBldDir); + } + if (!IO.existsSync(preBldTgzPath)) { + fs.copyFileSync(tgzResourcePath, preBldTgzPath); + } }); beforeEach(() => { From 8b5a47f97941326495ccf52697bb06808075ac2e Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 15 Dec 2021 15:50:44 -0500 Subject: [PATCH 25/78] Do not run Daemon commands from executable. Display connection diagnostics on 5th connection retry. Signed-off-by: Gene Johnston --- zowex/src/main.rs | 107 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 18 deletions(-) diff --git a/zowex/src/main.rs b/zowex/src/main.rs index bd3d9bddec..3248812989 100644 --- a/zowex/src/main.rs +++ b/zowex/src/main.rs @@ -42,6 +42,7 @@ const EXIT_CODE_CANNOT_START_DAEMON: i32 = 103; const EXIT_CODE_DEAMON_NOT_RUNNING_AFTER_START: i32 = 104; const EXIT_CODE_DAEMON_FAILED_TO_RUN_CMD: i32 = 105; const EXIT_CODE_FAILED_TO_RUN_NODEJS_CMD: i32 = 106; +const EXIT_CODE_CANT_RUN_DAEMON_CMD: i32 = 107; struct DaemonProcInfo { is_running: bool, @@ -83,12 +84,15 @@ fn main() -> std::io::Result<()> { _args.drain(..1); // remove first (exe name) + // daemon commands that overwrite our executable cannot be run by our executable + exit_when_alt_cmd_needed(&_args); + let cmd_result: Result; if user_wants_daemon() { /* Convert our vector of arguments into a single string of arguments * for transmittal to the daemon. */ - let arg_string = arg_vec_to_string(_args); + let arg_string = arg_vec_to_string(&_args); // send command to the daemon match run_daemon_command(arg_string) { @@ -129,6 +133,54 @@ fn main() -> std::io::Result<()> { } } +/** + * Determine if the command to run is a "zowe daemon" command that we cannot + * run from our executable. For such commands, display a zowe NodeJs command + * that can be run instead, and exit the current command. + * + * @param cmd_line_args + * The user-supplied command line arguments to the zowe command. + * Each argument is in its own vector element. + */ +fn exit_when_alt_cmd_needed(cmd_line_args: &Vec) { + // commands other than daemon commands can be run by our exe + if cmd_line_args.len() < 2 { + return; + } + if cmd_line_args[0] != "daemon" { + return; + } + if cmd_line_args[1] != "enable" && cmd_line_args[1] != "disable" { + return; + } + + // we can run any of the help requests for the daemon commands + if cmd_line_args.len() >= 3 { + let third_parm: &str = cmd_line_args[2].as_str(); + match third_parm { + "--help" | "-h" | "--h" | "--help-web" | "--hw" | "--help-examples" => return, + _ => { /* pass on through to next statement */ } + } + } + + // show the NodeJS zowe command that the user can run instead + println!("You cannot run this 'daemon' command while using the Zowe-CLI native executable."); + println!("Copy and paste the following command instead:"); + let mut zowe_cmd_to_show = String::new(); + let njs_zowe_path = get_nodejs_zowe_path(); + + if njs_zowe_path.contains(' ') { + zowe_cmd_to_show.push('"'); + zowe_cmd_to_show.push_str(&njs_zowe_path); + zowe_cmd_to_show.push('"'); + } else { + zowe_cmd_to_show.push_str(&njs_zowe_path); + } + println!("{} {}", zowe_cmd_to_show, arg_vec_to_string(cmd_line_args)); + + std::process::exit(EXIT_CODE_CANT_RUN_DAEMON_CMD); +} + /** * Convert a vector of command line arguments into a single string of arguments. * @param cmd_line_args @@ -137,7 +189,7 @@ fn main() -> std::io::Result<()> { * @returns * A String containing all of the command line arguments. */ -fn arg_vec_to_string(arg_vec: Vec) -> String { +fn arg_vec_to_string(arg_vec: &Vec) -> String { let mut arg_string = String::new(); let mut arg_count = 1; for next_arg in arg_vec.iter() { @@ -181,14 +233,19 @@ fn run_daemon_command(mut args: String) -> std::io::Result<()> { Ok(talk(&_resp, &mut stream)?) } +/** + * Attempt to make a TCP connection to the daemon. + * Iterate to enable a slow system to start the daemon. + */ fn establish_connection(host: String, port: String) -> std::io::Result { - /* Attempt to make a TCP connection to the daemon. - * Iterate to enable a slow system to start the daemon. - */ + const THREE_MIN_OF_RETRIES: i32 = 60; + const RETRY_TO_SHOW_DIAG: i32 = 5; + let host_port_conn_str = format!("{}:{}", host, port); - let mut conn_attempt = 1; + let mut conn_retries = 0; let mut we_started_daemon = false; let mut cmd_to_show: String = String::new(); + let stream = loop { let conn_result = TcpStream::connect(&host_port_conn_str); if let Ok(good_stream) = conn_result { @@ -201,7 +258,7 @@ fn establish_connection(host: String, port: String) -> std::io::Result std::io::Result THREE_MIN_OF_RETRIES { + println!("Terminating after {} connection retries.", THREE_MIN_OF_RETRIES); std::process::exit(EXIT_CODE_CANNOT_CONNECT_TO_RUNNING_DAEMON); } // pause between attempts to connect thread::sleep(Duration::from_secs(3)); - if conn_attempt == 1 && we_started_daemon == false || conn_attempt > 1 { - println!("Attempting to connect to Zowe daemon again ..."); + + // before we wait too long, show diagnostics + if conn_retries == RETRY_TO_SHOW_DIAG { + println!("\nThe Zowe daemon was started with these options:"); + if we_started_daemon { + println!("Command = {}", cmd_to_show); + } else { + println!("Command = {}", daemon_proc_info.cmd); + } + println!("Process name = {} pid = {} host = {} port = {}\n", + daemon_proc_info.name, daemon_proc_info.pid, host, port + ); + } + + let retry_msg; + if we_started_daemon { + retry_msg = "Waiting for the Zowe daemon to start"; + } else { + retry_msg = "Attempting to connect to the Zowe daemon"; + } + if conn_retries > 0 { + println!("{} ({} of {})", retry_msg, conn_retries, THREE_MIN_OF_RETRIES); } - conn_attempt = conn_attempt + 1; + conn_retries = conn_retries + 1; }; Ok(stream) From c98b5b77559b95fed229cf886161d7032d83c36b Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 16 Dec 2021 10:54:31 -0500 Subject: [PATCH 26/78] Add new undoc'ed flag --version-exe. Signed-off-by: Gene Johnston --- zowex/src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/zowex/src/main.rs b/zowex/src/main.rs index 3248812989..a50a2a3d10 100644 --- a/zowex/src/main.rs +++ b/zowex/src/main.rs @@ -35,6 +35,7 @@ const DEFAULT_PORT: i32 = 4000; const X_ZOWE_DAEMON_REPLY: &str = "daemon-client"; +const EXIT_CODE_SUCCESS: i32 = 0; const EXIT_CODE_CANNOT_CONNECT_TO_RUNNING_DAEMON: i32 = 100; const EXIT_CODE_CANNOT_GET_MY_PATH: i32 = 101; const EXIT_CODE_NO_NODEJS_ZOWE_ON_PATH: i32 = 102; @@ -81,13 +82,21 @@ struct DaemonResponse { fn main() -> std::io::Result<()> { // turn args into vector let mut _args: Vec = env::args().collect(); + let cmd_result: Result; _args.drain(..1); // remove first (exe name) + // Do we only need to display our version? + if _args.len() <= 1 { + if _args[0] == "--version-exe" { + println!("{}", env!("CARGO_PKG_VERSION")); + std::process::exit(EXIT_CODE_SUCCESS); + } + } + // daemon commands that overwrite our executable cannot be run by our executable exit_when_alt_cmd_needed(&_args); - let cmd_result: Result; if user_wants_daemon() { /* Convert our vector of arguments into a single string of arguments * for transmittal to the daemon. From 211151d45e7a5f7cee674943c502848220f33b87 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 16 Dec 2021 13:46:26 -0500 Subject: [PATCH 27/78] Display the version of the "enabled" exe. Signed-off-by: Gene Johnston --- .../cli/src/daemon/enable/Enable.handler.ts | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index 97c60538cb..1ed1cda454 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -12,9 +12,10 @@ import * as fs from "fs"; import * as nodeJsPath from "path"; import * as tar from "tar"; +import { execSync, StdioOptions } from "child_process"; import { - ICommandHandler, IHandlerParameters, ImperativeConfig, ImperativeError, + CliUtils, ICommandHandler, IHandlerParameters, ImperativeConfig, ImperativeError, IO, ISystemInfo, ProcessUtils } from "@zowe/imperative"; @@ -115,8 +116,27 @@ export default class EnableDaemonHandler implements ICommandHandler { // extract executable from the tar file into the bin directory await this.unzipTgz(preBldTgz, zoweHomeBin, ImperativeConfig.instance.rootCommandName); + /* Even though we await the unzip above, the OS still considers the exe file in-use + * for a while. We will get the following error message when trying to run the exe. + * "The process cannot access the file because it is being used by another process." + * So, we wait a little bit. + */ + const halfSecOfMillis = 500; + await CliUtils.sleep(halfSecOfMillis); + // display the version of the executable - let userInfoMsg: string = "Zowe CLI native executable version = 'todo: get the version'."; + let userInfoMsg: string = "Zowe CLI native executable version = "; + const zoweExePath = nodeJsPath.resolve(zoweHomeBin, "zowe"); + const pipe: StdioOptions = ["pipe", "pipe", process.stderr]; + try { + const execOutput = execSync(`"${zoweExePath}" --version-exe`, { + stdio: pipe + }); + // remove any newlines from the version number + userInfoMsg += execOutput.toString().replace(/\r?\n|\r/g, ""); + } catch (err) { + userInfoMsg += err.message; + } // if ZOWE_CLI_HOME/bin is not on our PATH, add an instruction to add it if (process.env?.PATH?.length > 0) { From ac17fb46596247e96290e13e4300c878644285e9 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 16 Dec 2021 14:22:52 -0500 Subject: [PATCH 28/78] Update version for new enhancements. Signed-off-by: Gene Johnston --- package.json | 2 ++ zowex/Cargo.lock | 2 +- zowex/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1133e3c592..c6edac5154 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ ], "scripts": { "build": "gulp updateLicense && lerna run build && npm run lint && npm run checkTestsCompile && npm run circularDependencyCheck", + "build:exe": "cd zowex && cargo build && cargo test", "clean": "lerna run --parallel clean", + "clean:exe": "cd zowex && cargo clean", "installWithBuild": "npm install && npm run build", "checkTestsCompile": "echo \"Checking that test source compiles...\" && tsc --project __tests__/test-tsconfig.json --noEmit", "circularDependencyCheck": "lerna run --parallel circularDependencyCheck -- -- --warning --no-spinner", diff --git a/zowex/Cargo.lock b/zowex/Cargo.lock index 9779ffec49..9d810c2b01 100644 --- a/zowex/Cargo.lock +++ b/zowex/Cargo.lock @@ -299,7 +299,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "zowe" -version = "0.4.1" +version = "0.5.0" dependencies = [ "pathsearch", "rpassword", diff --git a/zowex/Cargo.toml b/zowex/Cargo.toml index 344c1291bf..f2482df067 100644 --- a/zowex/Cargo.toml +++ b/zowex/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zowe" -version = "0.4.1" +version = "0.5.0" authors = ["Zowe Project"] edition = "2018" license = "EPL-2.0" From 0336723cc2b4423dbe6ab82c64d58b5679e67aa0 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 16 Dec 2021 15:19:23 -0500 Subject: [PATCH 29/78] Update tests to check for version message. Signed-off-by: Gene Johnston --- .../enable/cli.daemon.enable.integration.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 375b8f88b6..7b6d2922d6 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -125,6 +125,7 @@ describe("daemon enable", () => { expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(IO.existsSync(exePath)).toBe(true); }); @@ -134,6 +135,7 @@ describe("daemon enable", () => { expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(IO.existsSync(exePath)).toBe(true); }); @@ -155,6 +157,7 @@ describe("daemon enable", () => { expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).toContain(`Add '${pathToBin}' to your path`); expect(stdoutStr).toContain("Otherwise, you will continue to run the classic Zowe CLI interpreter"); expect(IO.existsSync(exePath)).toBe(true); @@ -169,6 +172,7 @@ describe("daemon enable", () => { expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your path`); expect(IO.existsSync(exePath)).toBe(true); }); @@ -181,6 +185,7 @@ describe("daemon enable", () => { expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).toContain("Your ZOWE_USE_DAEMON environment variable is set to 'no'"); expect(stdoutStr).toContain("You must remove it, or set it to 'yes' to use daemon mode"); expect(IO.existsSync(exePath)).toBe(true); From bcabe634effc446f7fd35019e3ac4187df987eff Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 16 Dec 2021 18:59:41 -0500 Subject: [PATCH 30/78] Fix bug on number of parms for --version-exe flag. Signed-off-by: Gene Johnston --- zowex/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zowex/src/main.rs b/zowex/src/main.rs index a50a2a3d10..d0403c05ca 100644 --- a/zowex/src/main.rs +++ b/zowex/src/main.rs @@ -87,7 +87,7 @@ fn main() -> std::io::Result<()> { _args.drain(..1); // remove first (exe name) // Do we only need to display our version? - if _args.len() <= 1 { + if _args.len() >= 1 { if _args[0] == "--version-exe" { println!("{}", env!("CARGO_PKG_VERSION")); std::process::exit(EXIT_CODE_SUCCESS); From d40cdfa6f415d01483dbf996b2aedef586734149 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 16 Dec 2021 19:07:24 -0500 Subject: [PATCH 31/78] Create a direct test of our zowe executable. Signed-off-by: Gene Johnston --- .../__scripts__/run_zowe_exe.sh | 11 +++ .../cli.zowe.exe.integration.test.ts | 68 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 packages/cli/__tests__/daemon/__integration__/__scripts__/run_zowe_exe.sh create mode 100644 packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts diff --git a/packages/cli/__tests__/daemon/__integration__/__scripts__/run_zowe_exe.sh b/packages/cli/__tests__/daemon/__integration__/__scripts__/run_zowe_exe.sh new file mode 100644 index 0000000000..df30964979 --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/__scripts__/run_zowe_exe.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# our first parm is the execuable to run. +# All remaining parms are passed to that executable +echo "Zowe EXE test command = $*" +$* +if [ $? -gt 0 ] +then + exit $? +fi diff --git a/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts new file mode 100644 index 0000000000..ee6113f7f6 --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts @@ -0,0 +1,68 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import * as nodeJsPath from "path"; + +import { IO, ProcessUtils, ISystemInfo } from "@zowe/imperative"; + +import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; +import { ITestPropertiesSchema } from "../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; +import { TestEnvironment } from "../../../../../__tests__/__src__/environment/TestEnvironment"; + +let testEnvironment: ITestEnvironment; + +describe("Zowe native executable", () => { + let zoweExePath: string; + let canTestExe: boolean = true; + + beforeAll(async () => { + // Create the unique test environment + testEnvironment = await TestEnvironment.setUp({ + testName: "zowe_exe_integration", + skipProperties: true + }); + + // determine executable file extension for our current OS + let exeExt: string; + const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); + if (sysInfo.platform == "win32") { + exeExt = ".exe"; + } else { + exeExt = ""; + } + + // Form the path name to our executable. + const zoweExeGrandParentDir: string = nodeJsPath.normalize(__dirname + "/../../../../../zowex/target"); + zoweExePath = nodeJsPath.normalize(zoweExeGrandParentDir + "/release/zowe" + exeExt); + if (!IO.existsSync(zoweExePath)) { + zoweExePath = nodeJsPath.normalize(zoweExeGrandParentDir + "/debug/zowe" + exeExt); + if (!IO.existsSync(zoweExePath)) { + canTestExe = false; + zoweExePath = "./NoZoweExeExists"; + } + } + }); + + it("should display its version number", async () => { + if (canTestExe) { + const response = runCliScript( + __dirname + "/__scripts__/run_zowe_exe.sh", testEnvironment, + [zoweExePath, "--version-exe"] + ); + expect(response.stdout.toString()).toMatch(/[0-9]\.[0-9]\.[0-9]/); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); + } else { + // just skip this executable test + expect(true).toBe(true); + } + }); +}); From 091b05f91db3d550513ad587d498d64f5f3e1db9 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 17 Dec 2021 10:36:09 -0500 Subject: [PATCH 32/78] Remove snapshot so test runs as exe or typescript. Move test for exit status to end to get error messages. Signed-off-by: Gene Johnston --- ...cli.daemon.enable.integration.test.ts.snap | 50 ------------------- .../cli.daemon.enable.integration.test.ts | 28 +++++++---- 2 files changed, 19 insertions(+), 59 deletions(-) delete mode 100644 packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap b/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap deleted file mode 100644 index 2818b886c8..0000000000 --- a/packages/cli/__tests__/daemon/__integration__/enable/__snapshots__/cli.daemon.enable.integration.test.ts.snap +++ /dev/null @@ -1,50 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`daemon enable should display the help 1`] = ` -"================ daemon enable help =============== - - COMMAND NAME - ------------ - - enable - - DESCRIPTION - ----------- - - Enables daemon-mode operation of the Zowe-CLI. You only need to run the enable - command once after each new installation of the Zowe-CLI. Afterwards, any zowe - command will automatically start a daemon as needed. - - USAGE - ----- - - zowe daemon enable [options] - - GLOBAL OPTIONS - -------------- - - --response-format-json | --rfj (boolean) - - Produce JSON formatted data from a command - - --help | -h (boolean) - - Display help text - - --help-examples (boolean) - - Display examples for all the commands in a group - - --help-web | --hw (boolean) - - Display HTML help in browser - - EXAMPLES - -------- - - - Enable daemon-mode: - - $ zowe daemon enable - -" -`; diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 7b6d2922d6..f50ab8ebd9 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -90,9 +90,18 @@ describe("daemon enable", () => { it("should display the help", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("COMMAND NAME"); + expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe-CLI."); + expect(stdoutStr).toContain("USAGE"); + expect(stdoutStr).toContain("zowe daemon enable [options]"); + expect(stdoutStr).toContain("GLOBAL OPTIONS"); + expect(stdoutStr).toContain("--help | -h (boolean)"); + expect(stdoutStr).toContain("EXAMPLES"); + expect(stdoutStr).toContain("Enable daemon-mode:"); + expect(stdoutStr).toContain("$ zowe daemon enable"); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); - expect(response.stdout.toString()).toMatchSnapshot(); }); it("should fail when the tgz file does not exist", async () => { @@ -122,21 +131,21 @@ describe("daemon enable", () => { it("should place exe in a new bin dir", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); }); it("should place exe in an existing bin dir", async () => { fs.mkdirSync(pathToBin, 0o755); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); }); it("should overwite an existing exe", async () => { @@ -144,23 +153,24 @@ describe("daemon enable", () => { fs.mkdirSync(pathToBin, 0o755); fs.writeFileSync(exePath, fakeExeContent); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - expect(response.status).toBe(0); + expect(response.stdout.toString()).toContain("Zowe CLI daemon mode enabled"); expect(IO.existsSync(exePath)).toBe(true); // our test tgz file is more than 10 bytes larger than this fake tgz const exeStats = fs.statSync(exePath); expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); + expect(response.status).toBe(0); }); it("should identify that bin is not on the PATH", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).toContain(`Add '${pathToBin}' to your path`); expect(stdoutStr).toContain("Otherwise, you will continue to run the classic Zowe CLI interpreter"); expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); }); it("should say nothing when bin is already on the PATH", async () => { @@ -169,12 +179,12 @@ describe("daemon enable", () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); testEnvironment.env["PATH"] = pathOrig; - expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your path`); expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); }); it("should identify that ZOWE_USE_DAEMON is set to 'no'", async () => { @@ -182,23 +192,23 @@ describe("daemon enable", () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); delete testEnvironment.env.ZOWE_USE_DAEMON; - expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).toContain("Your ZOWE_USE_DAEMON environment variable is set to 'no'"); expect(stdoutStr).toContain("You must remove it, or set it to 'yes' to use daemon mode"); expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); }); it("should say nothing when ZOWE_USE_DAEMON is unset", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(testEnvironment.env["ZOWE_USE_DAEMON"]).toBeFalsy(); expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); }); it("should say nothing when ZOWE_USE_DAEMON is set to 'yes'", async () => { @@ -206,10 +216,10 @@ describe("daemon enable", () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); delete testEnvironment.env.ZOWE_USE_DAEMON; - expect(response.status).toBe(0); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); }); }); From 612f5ee9c0368793664eecf80c354230c519736a Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 17 Dec 2021 19:14:54 -0500 Subject: [PATCH 33/78] Make fake EXEs > 2000 bytes so tests treat as real Signed-off-by: Gene Johnston --- .../daemon/__resources__/zowe-linux.tgz | Bin 224 -> 329 bytes .../daemon/__resources__/zowe-macos.tar.gz | Bin 319 -> 406 bytes .../daemon/__resources__/zowe-windows.tgz | Bin 226 -> 332 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/packages/cli/__tests__/daemon/__resources__/zowe-linux.tgz b/packages/cli/__tests__/daemon/__resources__/zowe-linux.tgz index e946f59bdd32a9fffb7abebf9e5ee94a83fc0dd8..7a073d96a823056c167f8efd75dce05405bc5144 100644 GIT binary patch literal 329 zcmV-P0k-}hiwFSU7`{1hdzJ#XG;%Lg}7^}}krwiQBD?NQ&q%dQnwx9sl3qPty*70<84va6u2 zE}#@5`l`K1)-TkH(gFB+<#Pap!Js7NOivy*&I4MYcakaM+R#l?Kd<-NrC=tQTmp&K zx(Gg5h`G;3&qa^%vttU>Lv#>{2cx2>xbaBY3DS8_GMcHWdm4RHsqkD<^frkwh9dT zE&I60W{zWKkX{cloLlt_W=vD(Hw+lUiJK8A@`f~1t}$<%e}X;`Ts_>+K-UGg;1=A1 bTW|~RzrwAGii(Pg{+2!f``EK=01yBGB1E69 literal 224 zcmV<603ZJ!iwFS9h_hh?0PT`NY6CG0MZFH>4*vwf(jj~lixvgI-O4EKYRkUR6bAu2mk<13uWa1 diff --git a/packages/cli/__tests__/daemon/__resources__/zowe-macos.tar.gz b/packages/cli/__tests__/daemon/__resources__/zowe-macos.tar.gz index cfc2038be27609f9bf719efbc47f5653350bb004..f3527a69787b6d0835a9fa049ecd8eba571736b3 100644 GIT binary patch literal 406 zcmV;H0crjpiwFp87`In9>7hG#^A=0e;U%K=bTnhbzp)DDu0UNSh@3kjxRU&&yT$@7O$nkGk(r~0myk( zRlp#?_r~oc%d;Y{c#)MQKsMvNWKggJ;H?t|fJQXm#Vw5XJv%z~&ws54WIqhgcxV8| zH|&pj#w!-iznWziWmQsqR)q8C>;O#X&-g)V{Xw2uX@Ra+`VJtVSE9yNs|F3cXak}H ze8<{5F{k!OlZW|AYH!sDqxMjXuG0>T@4$t1UgQ*X>poYczp4SJ!68kC7F|mV4;V6` z*2ZA%)R-m>_DYYSz1b-TgLExW285=BM&MGDP8Z%$@^UGop{490njU|F{8$U zx)ny$4vht?DMGky7$t;4X+jh1v|qHKgjrA?1$Dt=Q`6Q)_Rj96%1KPAGzoX;g|%C6 zQbb1^l4Lm-VdL~*T(h~jk-}c>PFqD8+DILmqj9xNaTO<0o_c`4geAW0EVHw A7ytkO literal 319 zcmV-F0l@wriwFqFi?d+>1A1?FWi4%CV{daVbYXG;?b1z7!!Qs9;H)e44(|lTp>2Ev zDmJhH4&WwJk}8cO$0mf+<5Yl91+4nB;C+f@S$4)FKdc`q?*RsFZE`7XU5LZRI+zCXDtYi` z9iPW^a=(75Z0PC%gAK?{(^wA|8u+o!rrK}1^006+bl>q<% diff --git a/packages/cli/__tests__/daemon/__resources__/zowe-windows.tgz b/packages/cli/__tests__/daemon/__resources__/zowe-windows.tgz index 45670bea623214b4bf0593c4385e375ad599dc1b..649ee41baa5364beed6ea4530d6e0f3d7f692570 100644 GIT binary patch literal 332 zcmV-S0ki%eiwFQo8NFcy0PT`ZPQx$|g|m*7JIoR`RZ`k|1$!2V4HuX?)7s$Lk$)P} z(=%=>sMu2h@>7(=$-H@=tvR@nX7oi)(qFai2cefHN{w|jD zu7b9@f>Ma+tM)2czfdnq2jJ_K&jAnygOZdpJ$cwT4`_jhL#BvpL$juSUhlO_!Avl@ z1QM-v5qz=`bDxbq7Cpw#jww(N(Lp3$jEbV-#v^4XNasDtXr`v_X)taAm;6N>j5;b{ z2jn4z9%<(o$L4=*-tEx#oYvG&_(op<;P#v`=fMK0(4&mx0|dtv7|&&F$U#lb3$iY4 z6&Une_HmKT9H-16y&ht?wCW?6F-@KCFklF0ZbqcY8`4a<#=LQU3Hm^A^KgFzx-GZ` ex8N4sf?II^6>e2jR8&;-xAXxT`)Jkx5C8yUi=8F_ literal 226 zcmV<803H7yiwFQsh_hh?0PT`NY6Kw=MO_cf9sUU#o0-NlWR*=W;AjnYu&u!^)9IW( znm`Cy1~O#fLlCX{zlx&Xc%y+{N&O*u)Y=%M^d~=WebS>E&*OA9`eaP|H|Ee%N-W4F zL7LBX{z!U|FUPWyhcJZdV+$mq8gJB;aGWzaiTm;3=@xkhm;9|9wpjwI0&Pj*EiGKz cNi9~z%VLuspgNsSr}G=$0siky_W%e0052YA+W-In From b5229e564c9de00b0adbd8b0d13c6b0b8305acda Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 17 Dec 2021 19:16:32 -0500 Subject: [PATCH 34/78] Add "which" module to devDependencies. Signed-off-by: Gene Johnston --- package-lock.json | 270 +++++++++++++++++++++++++++------------------- package.json | 2 + 2 files changed, 162 insertions(+), 110 deletions(-) diff --git a/package-lock.json b/package-lock.json index bc3610c493..225877e5f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@types/jest": "^22.2.3", "@types/node": "^12.12.24", "@types/uuid": "^8.3.0", + "@types/which": "2.0.1", "@typescript-eslint/eslint-plugin": "^4.29.0", "@typescript-eslint/parser": "^4.29.0", "ansi-colors": "^4.1.1", @@ -57,7 +58,8 @@ "typedoc": "^0.16.0", "typedoc-plugin-external-module-map": "^1.2.1", "typescript": "^3.8.0", - "uuid": "^3.3.2" + "uuid": "^3.3.2", + "which": "2.0.2" } }, "__tests__/__packages__/cli-test-utils": { @@ -972,6 +974,19 @@ "semver": "bin/semver" } }, + "node_modules/@evocateur/pacote/node_modules/which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, "node_modules/@gar/promisify": { "version": "1.1.2", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@gar/promisify/-/promisify-1.1.2.tgz", @@ -4556,21 +4571,6 @@ "node": ">= 4" } }, - "node_modules/@npmcli/git/node_modules/which": { - "version": "2.0.2", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", - "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", - "license": "ISC", - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, "node_modules/@npmcli/git/node_modules/yallist": { "version": "4.0.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/yallist/-/yallist-4.0.0.tgz", @@ -5121,6 +5121,13 @@ "integrity": "sha1-xqYGhtlT29Gx1F5m9Ozb1dRxtNA=", "license": "MIT" }, + "node_modules/@types/which": { + "version": "2.0.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/which/-/which-2.0.1.tgz", + "integrity": "sha1-J+zWf5FbfD1rpVITW7HuzWbmNQE=", + "dev": true, + "license": "MIT" + }, "node_modules/@types/yargs": { "version": "13.0.4", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/yargs/-/yargs-13.0.4.tgz", @@ -8265,6 +8272,19 @@ "semver": "bin/semver" } }, + "node_modules/cross-spawn/node_modules/which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, "node_modules/cssom": { "version": "0.3.8", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/cssom/-/cssom-0.3.8.tgz", @@ -9711,22 +9731,6 @@ "node": ">=8" } }, - "node_modules/eslint/node_modules/which": { - "version": "2.0.2", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", - "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", - "dev": true, - "license": "ISC", - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, "node_modules/espree": { "version": "7.3.1", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/espree/-/espree-7.3.1.tgz", @@ -11781,6 +11785,19 @@ "node": ">=0.10.0" } }, + "node_modules/global-prefix/node_modules/which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, "node_modules/globals": { "version": "13.12.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/globals/-/globals-13.12.0.tgz", @@ -17012,24 +17029,6 @@ "uuid": "dist/bin/uuid" } }, - "node_modules/jest-stare/node_modules/which": { - "version": "2.0.2", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", - "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", - "dev": true, - "license": "ISC", - "optional": true, - "peer": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, "node_modules/jest-stare/node_modules/write-file-atomic": { "version": "3.0.3", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/write-file-atomic/-/write-file-atomic-3.0.3.tgz", @@ -19687,6 +19686,19 @@ "semver": "bin/semver" } }, + "node_modules/node-gyp/node_modules/which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/node-int64/-/node-int64-0.4.0.tgz", @@ -19718,6 +19730,19 @@ "semver": "bin/semver" } }, + "node_modules/node-notifier/node_modules/which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, "node_modules/node-releases": { "version": "2.0.1", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/node-releases/-/node-releases-2.0.1.tgz", @@ -19875,6 +19900,19 @@ "node": ">=4" } }, + "node_modules/npm-lifecycle/node_modules/which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, "node_modules/npm-normalize-package-bin": { "version": "1.0.1", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz", @@ -21079,21 +21117,6 @@ "node": ">=10" } }, - "node_modules/pacote/node_modules/which": { - "version": "2.0.2", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", - "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", - "license": "ISC", - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, "node_modules/pacote/node_modules/yallist": { "version": "4.0.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/yallist/-/yallist-4.0.0.tgz", @@ -26114,16 +26137,18 @@ } }, "node_modules/which": { - "version": "1.3.1", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", - "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", - "dev": true, + "version": "2.0.2", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", + "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", "license": "ISC", "dependencies": { "isexe": "^2.0.0" }, "bin": { - "which": "bin/which" + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" } }, "node_modules/which-boxed-primitive": { @@ -27371,6 +27396,15 @@ "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/semver/-/semver-5.7.1.tgz", "integrity": "sha1-qVT5Ma66UI0we78Gnv8MAclhFvc=", "dev": true + }, + "which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } } } }, @@ -30105,14 +30139,6 @@ "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/retry/-/retry-0.12.0.tgz", "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=" }, - "which": { - "version": "2.0.2", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", - "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", - "requires": { - "isexe": "^2.0.0" - } - }, "yallist": { "version": "4.0.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/yallist/-/yallist-4.0.0.tgz", @@ -30600,6 +30626,12 @@ "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/uuid/-/uuid-8.3.3.tgz", "integrity": "sha1-xqYGhtlT29Gx1F5m9Ozb1dRxtNA=" }, + "@types/which": { + "version": "2.0.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/which/-/which-2.0.1.tgz", + "integrity": "sha1-J+zWf5FbfD1rpVITW7HuzWbmNQE=", + "dev": true + }, "@types/yargs": { "version": "13.0.4", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@types/yargs/-/yargs-13.0.4.tgz", @@ -33116,6 +33148,15 @@ "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/semver/-/semver-5.7.1.tgz", "integrity": "sha1-qVT5Ma66UI0we78Gnv8MAclhFvc=", "dev": true + }, + "which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } } } }, @@ -34087,15 +34128,6 @@ "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha1-rhbxZE2HPsrYQ7AwexQzYtTEIXI=", "dev": true - }, - "which": { - "version": "2.0.2", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", - "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", - "dev": true, - "requires": { - "isexe": "^2.0.0" - } } } }, @@ -35670,6 +35702,17 @@ "ini": "^1.3.4", "is-windows": "^1.0.1", "which": "^1.2.14" + }, + "dependencies": { + "which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + } } }, "globals": { @@ -39449,17 +39492,6 @@ "optional": true, "peer": true }, - "which": { - "version": "2.0.2", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", - "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", - "dev": true, - "optional": true, - "peer": true, - "requires": { - "isexe": "^2.0.0" - } - }, "write-file-atomic": { "version": "3.0.3", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/write-file-atomic/-/write-file-atomic-3.0.3.tgz", @@ -41438,6 +41470,15 @@ "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/semver/-/semver-5.7.1.tgz", "integrity": "sha1-qVT5Ma66UI0we78Gnv8MAclhFvc=", "dev": true + }, + "which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } } } }, @@ -41465,6 +41506,15 @@ "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/semver/-/semver-5.7.1.tgz", "integrity": "sha1-qVT5Ma66UI0we78Gnv8MAclhFvc=", "dev": true + }, + "which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } } } }, @@ -41580,6 +41630,15 @@ "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha1-SrzYUq0y3Xuqv+m0DgCjbbXzkuY=", "dev": true + }, + "which": { + "version": "1.3.1", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", + "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } } } }, @@ -42440,14 +42499,6 @@ } } }, - "which": { - "version": "2.0.2", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", - "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", - "requires": { - "isexe": "^2.0.0" - } - }, "yallist": { "version": "4.0.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/yallist/-/yallist-4.0.0.tgz", @@ -46091,10 +46142,9 @@ } }, "which": { - "version": "1.3.1", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-1.3.1.tgz", - "integrity": "sha1-pFBD1U9YBTFtqNYvn1CRjT2nCwo=", - "dev": true, + "version": "2.0.2", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/which/-/which-2.0.2.tgz", + "integrity": "sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE=", "requires": { "isexe": "^2.0.0" } diff --git a/package.json b/package.json index c6edac5154..17aa84fa61 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@types/jest": "^22.2.3", "@types/node": "^12.12.24", "@types/uuid": "^8.3.0", + "@types/which": "2.0.1", "@typescript-eslint/eslint-plugin": "^4.29.0", "@typescript-eslint/parser": "^4.29.0", "ansi-colors": "^4.1.1", @@ -84,6 +85,7 @@ "typedoc": "^0.16.0", "typedoc-plugin-external-module-map": "^1.2.1", "typescript": "^3.8.0", + "which": "2.0.2", "uuid": "^3.3.2" }, "jest": { From bf36f242d06f9530c837ad98df41551ba8378b8d Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 17 Dec 2021 19:20:38 -0500 Subject: [PATCH 35/78] Accept responses from typescript zowe or EXE. Signed-off-by: Gene Johnston --- .../cli.daemon.enable.integration.test.ts | 209 ++++++++++++------ 1 file changed, 146 insertions(+), 63 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index f50ab8ebd9..5ec38801b4 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -9,24 +9,29 @@ * */ +import * as fs from "fs"; +import * as nodeJsPath from "path"; +import * as which from "which"; + import { IO, ISystemInfo, ProcessUtils } from "@zowe/imperative"; import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; -import * as fs from "fs"; -import * as nodeJsPath from "path"; - let testEnvironment: ITestEnvironment; describe("daemon enable", () => { const rimraf = require("rimraf").sync; const fakeExeContent = "This is not a real executable"; + const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe-CLI native executable."; + const exeCantRunDaemonMsg2: string = "Copy and paste the following command instead:"; + const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 107; let exePath: string; let pathToBin: string; let preBldTgzPath: string; + let isZoweExe: boolean = false; // is the zowe command that we will run an executable? beforeAll(async () => { // Create the unique test environment @@ -77,6 +82,16 @@ describe("daemon enable", () => { if (!IO.existsSync(preBldTgzPath)) { fs.copyFileSync(tgzResourcePath, preBldTgzPath); } + + // Get the zowe program from the PATH that will be used in the test + const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); + + // We know that our zowe EXE will be bigger than our zowe scripts + const exeMinSize: number = 2000; + const zowePgmStats = fs.statSync(zowePgmInPath); + if (zowePgmStats.size >= exeMinSize) { + isZoweExe = true; + } }); beforeEach(async () => { @@ -89,19 +104,26 @@ describe("daemon enable", () => { }); it("should display the help", async () => { - const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("COMMAND NAME"); - expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe-CLI."); - expect(stdoutStr).toContain("USAGE"); - expect(stdoutStr).toContain("zowe daemon enable [options]"); - expect(stdoutStr).toContain("GLOBAL OPTIONS"); - expect(stdoutStr).toContain("--help | -h (boolean)"); - expect(stdoutStr).toContain("EXAMPLES"); - expect(stdoutStr).toContain("Enable daemon-mode:"); - expect(stdoutStr).toContain("$ zowe daemon enable"); - expect(response.stderr.toString()).toBe(""); - expect(response.status).toBe(0); + /* Our EXE can display help, but actually launching the daemon causes the + * convoluted set of zowe EXEs, fake zowe EXEs, and zowe scripts to hang. + * Just skip this test for the EXE. For the remaining tests, the EXE + * works completely within itself, and never launches the daemon. + */ + if (!isZoweExe) { + const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("COMMAND NAME"); + expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe-CLI."); + expect(stdoutStr).toContain("USAGE"); + expect(stdoutStr).toContain("zowe daemon enable [options]"); + expect(stdoutStr).toContain("GLOBAL OPTIONS"); + expect(stdoutStr).toContain("--help | -h (boolean)"); + expect(stdoutStr).toContain("EXAMPLES"); + expect(stdoutStr).toContain("Enable daemon-mode:"); + expect(stdoutStr).toContain("$ zowe daemon enable"); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); + } }); it("should fail when the tgz file does not exist", async () => { @@ -115,37 +137,61 @@ describe("daemon enable", () => { fs.renameSync(tempRenamedTgz, preBldTgzPath); const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); - expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); - expect(response.status).toBe(1); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); + expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); + expect(response.status).toBe(1); + } }); it("should fail if a bin file exists", async () => { fs.writeFileSync(pathToBin, "not a directory"); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); - expect(stdoutStr).toContain(`The existing file '${pathToBin}' must be a directory.`); - expect(response.status).toBe(1); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); + expect(stdoutStr).toContain(`The existing file '${pathToBin}' must be a directory.`); + expect(response.status).toBe(1); + } }); it("should place exe in a new bin dir", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); - expect(stdoutStr).toContain("Zowe CLI native executable version ="); - expect(IO.existsSync(exePath)).toBe(true); - expect(response.status).toBe(0); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); + expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); + } }); it("should place exe in an existing bin dir", async () => { fs.mkdirSync(pathToBin, 0o755); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); - expect(stdoutStr).toContain("Zowe CLI native executable version ="); - expect(IO.existsSync(exePath)).toBe(true); - expect(response.status).toBe(0); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); + expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); + } }); it("should overwite an existing exe", async () => { @@ -153,38 +199,57 @@ describe("daemon enable", () => { fs.mkdirSync(pathToBin, 0o755); fs.writeFileSync(exePath, fakeExeContent); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - expect(response.stdout.toString()).toContain("Zowe CLI daemon mode enabled"); - expect(IO.existsSync(exePath)).toBe(true); + const stdoutStr = response.stdout.toString(); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(IO.existsSync(exePath)).toBe(true); - // our test tgz file is more than 10 bytes larger than this fake tgz - const exeStats = fs.statSync(exePath); - expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); - expect(response.status).toBe(0); + // our test tgz file is more than 10 bytes larger than this fake tgz + const exeStats = fs.statSync(exePath); + expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); + expect(response.status).toBe(0); + } }); it("should identify that bin is not on the PATH", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); - expect(stdoutStr).toContain("Zowe CLI native executable version ="); - expect(stdoutStr).toContain(`Add '${pathToBin}' to your path`); - expect(stdoutStr).toContain("Otherwise, you will continue to run the classic Zowe CLI interpreter"); - expect(IO.existsSync(exePath)).toBe(true); - expect(response.status).toBe(0); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); + expect(stdoutStr).toContain(`Add '${pathToBin}' to your path`); + expect(stdoutStr).toContain("Otherwise, you will continue to run the classic Zowe CLI interpreter"); + expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); + } }); it("should say nothing when bin is already on the PATH", async () => { const pathOrig = testEnvironment.env["PATH"]; - testEnvironment.env["PATH"] = pathToBin + nodeJsPath.delimiter + process.env.PATH; + testEnvironment.env["PATH"] = pathToBin + nodeJsPath.delimiter + testEnvironment.env["PATH"]; const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); testEnvironment.env["PATH"] = pathOrig; const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); - expect(stdoutStr).toContain("Zowe CLI native executable version ="); - expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your path`); - expect(IO.existsSync(exePath)).toBe(true); - expect(response.status).toBe(0); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); + expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your path`); + expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); + } }); it("should identify that ZOWE_USE_DAEMON is set to 'no'", async () => { @@ -193,22 +258,34 @@ describe("daemon enable", () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); - expect(stdoutStr).toContain("Zowe CLI native executable version ="); - expect(stdoutStr).toContain("Your ZOWE_USE_DAEMON environment variable is set to 'no'"); - expect(stdoutStr).toContain("You must remove it, or set it to 'yes' to use daemon mode"); - expect(IO.existsSync(exePath)).toBe(true); - expect(response.status).toBe(0); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).toContain("Zowe CLI native executable version ="); + expect(stdoutStr).toContain("Your ZOWE_USE_DAEMON environment variable is set to 'no'"); + expect(stdoutStr).toContain("You must remove it, or set it to 'yes' to use daemon mode"); + expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); + } }); it("should say nothing when ZOWE_USE_DAEMON is unset", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); - expect(testEnvironment.env["ZOWE_USE_DAEMON"]).toBeFalsy(); - expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); - expect(IO.existsSync(exePath)).toBe(true); - expect(response.status).toBe(0); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(testEnvironment.env["ZOWE_USE_DAEMON"]).toBeFalsy(); + expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); + expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); + } }); it("should say nothing when ZOWE_USE_DAEMON is set to 'yes'", async () => { @@ -217,9 +294,15 @@ describe("daemon enable", () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); - expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); - expect(IO.existsSync(exePath)).toBe(true); - expect(response.status).toBe(0); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); + expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); + expect(IO.existsSync(exePath)).toBe(true); + expect(response.status).toBe(0); + } }); }); From 8fb980e294ac0d42edaa7c877720927d05cae9d2 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 28 Dec 2021 17:08:55 -0500 Subject: [PATCH 36/78] Remove empty 'else' branch of a test. Signed-off-by: Gene Johnston --- .../daemon/__integration__/cli.zowe.exe.integration.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts index ee6113f7f6..a20b5f6106 100644 --- a/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts @@ -60,9 +60,6 @@ describe("Zowe native executable", () => { expect(response.stdout.toString()).toMatch(/[0-9]\.[0-9]\.[0-9]/); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); - } else { - // just skip this executable test - expect(true).toBe(true); } }); }); From 3453dc2ca3800c22334bd63585ccea59038fced6 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 28 Dec 2021 17:09:46 -0500 Subject: [PATCH 37/78] Add child_process to __mocks__. Signed-off-by: Gene Johnston --- __mocks__/child_process.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 __mocks__/child_process.ts diff --git a/__mocks__/child_process.ts b/__mocks__/child_process.ts new file mode 100644 index 0000000000..55dd2c071c --- /dev/null +++ b/__mocks__/child_process.ts @@ -0,0 +1,37 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +'use strict'; + +const child_process: any = jest.genMockFromModule("child_process"); + +let execSyncOutout: string = "ExecSyncNeverSet"; + +// tests can set their our output valu for execSync +function setExecSyncOutput(outputVal: string) { + execSyncOutout = outputVal; +} + +// Mock function to use for child_process.execSync +function execSyncMock(cmd: string, options: Object) { + if (execSyncOutout === "ExecSyncNeverSet") { + // run the real execSync + const execSyncReal = require.requireActual("child_process").execSync; + return execSyncReal(cmd, options); + } else { + // return the output that the test set with setExecSyncOutput(). + return execSyncOutout; + } +} + +child_process.setExecSyncOutput = setExecSyncOutput; +child_process.execSync = execSyncMock; +module.exports = child_process; \ No newline at end of file From 7438a4483f2dec12ff5a266d0bf5c25e2811a40f Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 28 Dec 2021 17:14:48 -0500 Subject: [PATCH 38/78] Dup int-tests in unit-tests for coverage numbers. Signed-off-by: Gene Johnston --- .../enable/Enable.handler.unit.test.ts | 361 +++++++++++++++--- 1 file changed, 303 insertions(+), 58 deletions(-) diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 831cc30500..1b42ee7fb9 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -8,6 +8,7 @@ * Copyright Contributors to the Zowe Project. * */ +jest.mock("child_process"); // using child_process from the __mocks__ directory import { ImperativeConfig, ImperativeError, IO, ProcessUtils, ISystemInfo } from "@zowe/imperative"; @@ -19,37 +20,10 @@ import * as nodeJsPath from "path"; describe("Handler for daemon enable", () => { let enableHandler: any; // use "any" so we can call private functions let enableDaemonSpy: any; - - // command parms passed to process() by multiple tests - let apiMessage = ""; - let jsonObj; + let unzipTgzSpy: any; + let preBldDir: string; + let preBldTgzPath: string; let logMessage = ""; - const cmdParms = { - arguments: { - $0: "fake", - _: ["fake"] - }, - response: { - data: { - setMessage: jest.fn((setMsgArgs) => { - apiMessage = setMsgArgs; - }), - setObj: jest.fn((setObjArgs) => { - jsonObj = setObjArgs; - }), - setExitCode: jest.fn((exitCode) => { - return exitCode; - }) - }, - console: { - log: jest.fn((logArgs) => { - logMessage += "\n" + logArgs; - }) - }, - progress: {} - }, - profiles: {} - } as any; beforeAll(() => { // instantiate our handler @@ -79,8 +53,8 @@ describe("Handler for daemon enable", () => { // copy a fake tgz file from resources to our prebuilds directory for testing const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", tgzFileName); - const preBldDir = nodeJsPath.resolve(__dirname, "../../../../prebuilds"); - const preBldTgzPath = nodeJsPath.resolve(preBldDir, tgzFileName); + preBldDir = nodeJsPath.resolve(__dirname, "../../../../prebuilds"); + preBldTgzPath = nodeJsPath.resolve(preBldDir, tgzFileName); if (!IO.existsSync(preBldDir)) { IO.createDirSync(preBldDir); } @@ -92,10 +66,51 @@ describe("Handler for daemon enable", () => { beforeEach(() => { // remove enableDaemon spy & mock between tests enableDaemonSpy?.mockRestore(); + unzipTgzSpy?.mockRestore(); logMessage = ""; }); + afterAll(() => { + // remove the fake prebuild files that we created + if (IO.existsSync(preBldTgzPath)) { + IO.deleteFile(preBldTgzPath); + } + if (IO.existsSync(preBldDir)) { + IO.deleteDir(preBldDir); + } + }); + describe("process method", () => { + // command parms passed to process() by multiple tests + let apiMessage = ""; + let jsonObj; + const cmdParms = { + arguments: { + $0: "fake", + _: ["fake"] + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + apiMessage = setMsgArgs; + }), + setObj: jest.fn((setObjArgs) => { + jsonObj = setObjArgs; + }), + setExitCode: jest.fn((exitCode) => { + return exitCode; + }) + }, + console: { + log: jest.fn((logArgs) => { + logMessage += "\n" + logArgs; + }) + }, + progress: {} + }, + profiles: {} + } as any; + it("should succeed when the enableDaemon function succeeds", async () => { let error; const allOkMsg = "Everything worked ok"; @@ -142,10 +157,21 @@ describe("Handler for daemon enable", () => { expect(logMessage).toContain("Failed to enable Zowe CLI daemon mode"); expect(logMessage).toContain(badStuffMsg); }); + }); // end process method - it("should fail when on an unsupported platform", async () => { - let error; + describe("enableDaemon method", () => { + // cliHome is a getter property, so mock the property + const impCfg: ImperativeConfig = ImperativeConfig.instance; + const cliHomeDirMock = "NotaRealCliHomeDir"; + Object.defineProperty(impCfg, "cliHome", { + configurable: true, + get: jest.fn(() => { + return cliHomeDirMock; + }) + }); + const zoweBinDirMock = cliHomeDirMock + nodeJsPath.sep + "bin"; + it("should fail on an unsupported platform", async () => { const getBasicSystemInfoOrig = ProcessUtils.getBasicSystemInfo; ProcessUtils.getBasicSystemInfo = jest.fn(() => { return { @@ -154,57 +180,276 @@ describe("Handler for daemon enable", () => { }; }); + let error; try { - // Invoke the handler with a full set of mocked arguments and response functions - await enableHandler.process(cmdParms); + await enableHandler.enableDaemon(); } catch (e) { error = e; } - expect(error).toBeUndefined(); - expect(logMessage).toContain("Failed to enable Zowe CLI daemon mode"); - expect(logMessage).toContain("Daemon mode is not supported on the 'BogusPlatform' operating system."); + expect(error.mMessage).toBe("Daemon mode is not supported on the 'BogusPlatform' operating system."); ProcessUtils.getBasicSystemInfo = getBasicSystemInfoOrig; }); - it("should fail if a we cannot create a bin directory", async () => { + it("should fail when the tgz file does not exist", async () => { + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn(() => { + return false; + }); + let error; + try { + await enableHandler.enableDaemon(); + } catch (e) { + error = e; + } - // Mock the IO functions to simulate a failure creating a directory + expect(error.mMessage).toBe(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); + IO.existsSync = existsSyncOrig; + }); + + it("should fail when a bin file exists", async () => { const existsSyncOrig = IO.existsSync; - IO.createDirSync = jest.fn(() => { + IO.existsSync = jest.fn(() => { + return true; + }); + + const isDirOrig = IO.isDir; + IO.isDir = jest.fn(() => { return false; }); - const awfulThrownErr = "Some awful error was thrown"; + let error; + try { + await enableHandler.enableDaemon(); + } catch (e) { + error = e; + } + + expect(error.mMessage).toContain("The existing file '" + zoweBinDirMock + "' must be a directory."); + IO.existsSync = existsSyncOrig; + IO.isDir = isDirOrig; + }); + + it("should fail if a we cannot create a bin directory", async () => { + // Mock the IO functions to simulate a failure creating a directory + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn() + .mockReturnValueOnce(true) // for tgz file + .mockReturnValueOnce(false); // for bin dir + + const awfulThrownErr = "Some awful directory creation error was thrown"; const createDirSyncOrig = IO.createDirSync; IO.createDirSync = jest.fn(() => { throw awfulThrownErr; }); - // cliHome is a getter property, so mock the property - const impCfg: ImperativeConfig = ImperativeConfig.instance; - const mockCliHomeDir = "NotaRealCliHomeDir"; - Object.defineProperty(impCfg, "cliHome", { - configurable: true, - get: jest.fn(() => { - return mockCliHomeDir; - }) + let error; + try { + await enableHandler.enableDaemon(); + } catch (e) { + error = e; + } + + expect(error.mMessage).toContain(`Unable to create directory '${cliHomeDirMock}`); + expect(error.mMessage).toContain(`Reason: ${awfulThrownErr}`); + IO.existsSync = existsSyncOrig; + IO.createDirSync = createDirSyncOrig; + }); + + it("should return a message that it cannot launch the EXE", async () => { + // Mock the IO functions to simulate stuff is working + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn(() => { + return true; + }); + + const isDirOrig = IO.isDir; + IO.isDir = jest.fn(() => { + return true; }); + const createDirSyncOrig = IO.createDirSync; + IO.createDirSync = jest.fn(); + + // spy on our handler's private enableDaemon() function + unzipTgzSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "unzipTgz"); + unzipTgzSpy.mockImplementation((tgzFile: string, toDir: string, fileToExtract: string) => {return;}); + + let error; + let userInfoMsg: string; try { - // Invoke the handler with a full set of mocked arguments and response functions - await enableHandler.process(cmdParms); + userInfoMsg = await enableHandler.enableDaemon(); } catch (e) { error = e; } expect(error).toBeUndefined(); - expect(logMessage).toContain("Failed to enable Zowe CLI daemon mode"); - expect(logMessage).toContain(`Unable to create directory '${mockCliHomeDir}`); - expect(logMessage).toContain("Reason: " + awfulThrownErr); + expect(unzipTgzSpy).toHaveBeenCalledTimes(1); + + // we set a bogus cliHome, so we know it cannot launch the executable + expect(userInfoMsg).toContain("Zowe CLI native executable version = Command failed:"); + IO.existsSync = existsSyncOrig; + IO.isDir = isDirOrig; IO.createDirSync = createDirSyncOrig; }); - }); -}); + + it("should return a message with the version number of the EXE", async () => { + // Mock the IO functions to simulate stuff is working + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn(() => { + return true; + }); + + const isDirOrig = IO.isDir; + IO.isDir = jest.fn(() => { + return true; + }); + + const createDirSyncOrig = IO.createDirSync; + IO.createDirSync = jest.fn(); + + // This uses child_process from the __mocks__ directory + const exeVerNumMock = "9.9.9"; + require("child_process").setExecSyncOutput(exeVerNumMock); + + // spy on our handler's private enableDaemon() function + unzipTgzSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "unzipTgz"); + unzipTgzSpy.mockImplementation((tgzFile: string, toDir: string, fileToExtract: string) => {return;}); + + let error; + let userInfoMsg: string; + try { + userInfoMsg = await enableHandler.enableDaemon(); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(unzipTgzSpy).toHaveBeenCalledTimes(1); + expect(userInfoMsg).toContain("Zowe CLI native executable version = " + exeVerNumMock); + + IO.existsSync = existsSyncOrig; + IO.isDir = isDirOrig; + IO.createDirSync = createDirSyncOrig; + }); + + it("should return a message to add our bin to your PATH", async () => { + // Mock the IO functions to simulate stuff is working + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn(() => { + return true; + }); + + const isDirOrig = IO.isDir; + IO.isDir = jest.fn(() => { + return true; + }); + + const createDirSyncOrig = IO.createDirSync; + IO.createDirSync = jest.fn(); + + const pathOrig = process.env.PATH; + process.env.PATH = "ThisPathDoesNotcontainOurBinDir"; + + // spy on our handler's private enableDaemon() function + unzipTgzSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "unzipTgz"); + unzipTgzSpy.mockImplementation((tgzFile: string, toDir: string, fileToExtract: string) => {return;}); + + let error; + let userInfoMsg: string; + try { + userInfoMsg = await enableHandler.enableDaemon(); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(unzipTgzSpy).toHaveBeenCalledTimes(1); + expect(userInfoMsg).toContain(`Add '${zoweBinDirMock}' to your path.`); + + IO.existsSync = existsSyncOrig; + IO.isDir = isDirOrig; + IO.createDirSync = createDirSyncOrig; + process.env.PATH = pathOrig; + }); + + it("should not mention ZOWE_USE_DAEMON if is unset", async () => { + // Mock the IO functions to simulate stuff is working + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn(() => { + return true; + }); + + const isDirOrig = IO.isDir; + IO.isDir = jest.fn(() => { + return true; + }); + + const createDirSyncOrig = IO.createDirSync; + IO.createDirSync = jest.fn(); + + // spy on our handler's private enableDaemon() function + unzipTgzSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "unzipTgz"); + unzipTgzSpy.mockImplementation((tgzFile: string, toDir: string, fileToExtract: string) => {return;}); + + let error; + let userInfoMsg: string; + try { + userInfoMsg = await enableHandler.enableDaemon(); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(unzipTgzSpy).toHaveBeenCalledTimes(1); + expect(userInfoMsg).not.toContain("Your ZOWE_USE_DAEMON environment variable is set"); + expect(userInfoMsg).not.toContain("You must remove it, or set it to 'yes' to use daemon mode."); + + IO.existsSync = existsSyncOrig; + IO.isDir = isDirOrig; + IO.createDirSync = createDirSyncOrig; + }); + + it("should instruct that ZOWE_USE_DAEMON should be removed", async () => { + // Mock the IO functions to simulate stuff is working + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn(() => { + return true; + }); + + const isDirOrig = IO.isDir; + IO.isDir = jest.fn(() => { + return true; + }); + + const createDirSyncOrig = IO.createDirSync; + IO.createDirSync = jest.fn(); + + // spy on our handler's private enableDaemon() function + unzipTgzSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "unzipTgz"); + unzipTgzSpy.mockImplementation((tgzFile: string, toDir: string, fileToExtract: string) => {return;}); + + // force the message to reset ZOWE_USE_DAEMON variable + const noDaemonVal = "no"; + process.env.ZOWE_USE_DAEMON = noDaemonVal; + + let error; + let userInfoMsg: string; + try { + userInfoMsg = await enableHandler.enableDaemon(); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(unzipTgzSpy).toHaveBeenCalledTimes(1); + expect(userInfoMsg).toContain(`Your ZOWE_USE_DAEMON environment variable is set to '${noDaemonVal}'.`); + expect(userInfoMsg).toContain("You must remove it, or set it to 'yes' to use daemon mode."); + + IO.existsSync = existsSyncOrig; + IO.isDir = isDirOrig; + IO.createDirSync = createDirSyncOrig; + }); }); // end enableDaemon method +}); // end Handler From 76a7db2b61f8fd3e5f444a961669a8474f083459 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 29 Dec 2021 10:31:39 -0500 Subject: [PATCH 39/78] Add COMSPEC to NodeJS zowe command on Windows Signed-off-by: Gene Johnston --- zowex/src/main.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/zowex/src/main.rs b/zowex/src/main.rs index d0403c05ca..77ecaa35a7 100644 --- a/zowex/src/main.rs +++ b/zowex/src/main.rs @@ -175,9 +175,30 @@ fn exit_when_alt_cmd_needed(cmd_line_args: &Vec) { // show the NodeJS zowe command that the user can run instead println!("You cannot run this 'daemon' command while using the Zowe-CLI native executable."); println!("Copy and paste the following command instead:"); + + // let mut zowe_cmd_to_show = String::new(); - let njs_zowe_path = get_nodejs_zowe_path(); + if env::consts::OS == "windows" { + // We use COMSPEC so that the command will work for CMD and PowerShell + match env::var("COMSPEC") { + Ok(comspec_val) => { + if comspec_val.len() > 0 { + if comspec_val.contains(' ') { + zowe_cmd_to_show.push('"'); + zowe_cmd_to_show.push_str(&comspec_val); + zowe_cmd_to_show.push('"'); + } else { + zowe_cmd_to_show.push_str(&comspec_val); + } + zowe_cmd_to_show.push_str(" /C "); + } + }, + Err(_e) => { /* do not add COMSPEC */ }, + } + } + // add the zowe nodeJS path to our command + let njs_zowe_path = get_nodejs_zowe_path(); if njs_zowe_path.contains(' ') { zowe_cmd_to_show.push('"'); zowe_cmd_to_show.push_str(&njs_zowe_path); From 01179f1525e73630d410734e84537180f664eb0b Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 29 Dec 2021 16:51:35 -0500 Subject: [PATCH 40/78] Add the "find-process" package. Signed-off-by: Gene Johnston --- package-lock.json | 42 +++++++++++++++++++++++++++++++++++++++ packages/cli/package.json | 1 + 2 files changed, 43 insertions(+) diff --git a/package-lock.json b/package-lock.json index 225877e5f8..1fcb49d063 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10341,6 +10341,29 @@ "node": ">=0.10.0" } }, + "node_modules/find-process": { + "version": "1.4.7", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/find-process/-/find-process-1.4.7.tgz", + "integrity": "sha1-jHaWIlkhbDge8QmTcUZbW0OeoSE=", + "license": "MIT", + "dependencies": { + "chalk": "^4.0.0", + "commander": "^5.1.0", + "debug": "^4.1.1" + }, + "bin": { + "find-process": "bin/find-process.js" + } + }, + "node_modules/find-process/node_modules/commander": { + "version": "5.1.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/commander/-/commander-5.1.0.tgz", + "integrity": "sha1-Rqu9FlL44Fm92u+Zu9yyrZzxea4=", + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, "node_modules/find-up": { "version": "4.1.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/find-up/-/find-up-4.1.0.tgz", @@ -26492,6 +26515,7 @@ "@zowe/zos-uss-for-zowe-sdk": "7.0.0-next.202112102143", "@zowe/zos-workflows-for-zowe-sdk": "7.0.0-next.202112102143", "@zowe/zosmf-for-zowe-sdk": "7.0.0-next.202112102143", + "find-process": "1.4.7", "get-stdin": "7.0.0", "lodash": "4.17.21", "minimatch": "3.0.4", @@ -30793,6 +30817,7 @@ "@zowe/zosmf-for-zowe-sdk": "7.0.0-next.202112102143", "comment-json": "^4.1.0", "eslint": "^7.32.0", + "find-process": "1.4.7", "get-stdin": "7.0.0", "js-yaml": "^3.13.1", "keytar": "7.7.0", @@ -34655,6 +34680,23 @@ "integrity": "sha1-mzERErxsYSehbgFsbF1/GeCAXFs=", "dev": true }, + "find-process": { + "version": "1.4.7", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/find-process/-/find-process-1.4.7.tgz", + "integrity": "sha1-jHaWIlkhbDge8QmTcUZbW0OeoSE=", + "requires": { + "chalk": "^4.0.0", + "commander": "^5.1.0", + "debug": "^4.1.1" + }, + "dependencies": { + "commander": { + "version": "5.1.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/commander/-/commander-5.1.0.tgz", + "integrity": "sha1-Rqu9FlL44Fm92u+Zu9yyrZzxea4=" + } + } + }, "find-up": { "version": "4.1.0", "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/find-up/-/find-up-4.1.0.tgz", diff --git a/packages/cli/package.json b/packages/cli/package.json index 1cd5bf821a..c5afdf5534 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -67,6 +67,7 @@ "@zowe/zos-uss-for-zowe-sdk": "7.0.0-next.202112102143", "@zowe/zos-workflows-for-zowe-sdk": "7.0.0-next.202112102143", "@zowe/zosmf-for-zowe-sdk": "7.0.0-next.202112102143", + "find-process": "1.4.7", "get-stdin": "7.0.0", "lodash": "4.17.21", "minimatch": "3.0.4", From 78073155f3862fb3da9f5b6df34e90fe634dc215 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 29 Dec 2021 16:55:10 -0500 Subject: [PATCH 41/78] Complete the implementation of disable. Signed-off-by: Gene Johnston --- .../cli/src/daemon/disable/Disable.handler.ts | 82 +++++++++++++++++-- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/daemon/disable/Disable.handler.ts b/packages/cli/src/daemon/disable/Disable.handler.ts index 4dcccd68ac..b372dd40d2 100644 --- a/packages/cli/src/daemon/disable/Disable.handler.ts +++ b/packages/cli/src/daemon/disable/Disable.handler.ts @@ -9,7 +9,12 @@ * */ -import { ICommandHandler, IHandlerParameters, ImperativeError } from "@zowe/imperative"; +import * as nodeJsPath from "path"; + +import { + ICommandHandler, IHandlerParameters, ImperativeConfig, ImperativeError, + IO, ISystemInfo, ProcessUtils +} from "@zowe/imperative"; /** * Handler to disable daemon mode. @@ -26,30 +31,91 @@ export default class DisableDaemonHandler implements ICommandHandler { * * @throws {ImperativeError} */ - public process(cmdParams: IHandlerParameters): Promise { - let userMsg: string; + public async process(cmdParams: IHandlerParameters): Promise { try { - userMsg = this.disableDaemon(); + await this.disableDaemon(); } catch(impErr) { cmdParams.response.console.log("Failed to disable Zowe CLI daemon mode.\n" + (impErr as ImperativeError).message); cmdParams.response.data.setExitCode(1); return; } - cmdParams.response.console.log("Zowe CLI daemon mode disabled.\n" + userMsg); + cmdParams.response.console.log("Zowe CLI daemon mode is disabled."); cmdParams.response.data.setExitCode(0); return; } /** - * Enable daemon mode. + * Disable daemon mode. * * @throws {ImperativeError} * * @returns {string} An informational message to display to the user after * successful completion of the operation. */ - private disableDaemon(): string { - return "Pretend that we disabled daemon-mode."; + private async disableDaemon(): Promise { + // form the path to the bin directory in ZOWE_CLI_HOME + let zoweExePath = nodeJsPath.normalize(ImperativeConfig.instance.cliHome + "/bin/"); + + // determine our current OS + const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); + + // add the right EXE file name for the current OS + switch (sysInfo.platform) { + case "darwin" || "linux": { + zoweExePath += "zowe"; + break; + } + case "win32": { + zoweExePath += "zowe.exe"; + break; + } + default: { + throw new ImperativeError({ + msg: `Daemon mode is not supported on the '${sysInfo.platform}' operating system.` + }); + } + } + + // remove the EXE if it exists + if (IO.existsSync(zoweExePath)) { + IO.deleteFile(zoweExePath); + } + + // find processes running "node" + let procArray; + try { + const findProc = require('find-process'); + procArray = await findProc('name', 'node', true); + } catch(err) { + /* This catch is not invoked, because the find-process.finders[].win32.utils.spawn function + * does not add an on("error") event handler for the child_process.spawn() function it calls. + * Thus, ENOENT is emitted as an uncatchable event. Thanks find-process! + * If a user gets an error like this, just tell him that powershell is not on his PATH. + * Typically it should be. The same type of error might occur on Linux if 'ps' were not + * on the user's PATH. + */ + let powerShellHint = ""; + if (err.includes("powershell.exe ENOENT")) { + powerShellHint = "\nPowershell.exe may not be on your PATH."; + } + throw new ImperativeError({ + msg: "Failed while searching for the Zowe-CLI daemon process.\n" + + `Reason: ${err}` + + powerShellHint + }); + } + + /* Paths in proc list on Windows sometimes have forward slash + * and sometimes backslash, so allow either. + */ + const zoweCmdRegEx = "@zowe[/|\\\\]cli[/|\\\\]lib[/|\\\\]main.js"; + + // match and kill any running Zowe daemon + for (const nextProc of procArray) { + if (nextProc.cmd.match(zoweCmdRegEx) && nextProc.cmd.includes("--daemon")) { + process.kill(nextProc.pid, "SIGINT"); + } + } } } From 8c3efcb584fde2077a5b169640775cee77178c1e Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 30 Dec 2021 10:06:22 -0500 Subject: [PATCH 42/78] Alter test to match new output. Signed-off-by: Gene Johnston --- .../daemon/__unit__/disable/Disable.handler.unit.test.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts index 007c79b4c5..5ca2d4f8a1 100644 --- a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts @@ -53,12 +53,10 @@ describe("Disable daemon handler", () => { describe("process method", () => { it("should disable the daemon", async () => { - let error; - const allOkMsg = "Everything worked ok"; - disableDaemonSpy = jest.spyOn(DisableDaemonHandler.prototype as any, "disableDaemon"); - disableDaemonSpy.mockImplementation(() => {return allOkMsg;}); + disableDaemonSpy.mockImplementation(() => {return;}); + let error; try { // Invoke the handler with a full set of mocked arguments and response functions await disableHandler.process(cmdParms); @@ -68,8 +66,7 @@ describe("Disable daemon handler", () => { expect(error).toBeUndefined(); expect(disableDaemonSpy).toHaveBeenCalledTimes(1); - expect(logMessage).toContain("Zowe CLI daemon mode disabled"); - expect(logMessage).toContain(allOkMsg); + expect(logMessage).toContain("Zowe CLI daemon mode is disabled."); }); }); }); From a8a17e871366b51841b862adb415745f4f3e5b1d Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 30 Dec 2021 11:14:39 -0500 Subject: [PATCH 43/78] Fix semantic error in switch-case for platform. Signed-off-by: Gene Johnston --- packages/cli/src/daemon/disable/Disable.handler.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/daemon/disable/Disable.handler.ts b/packages/cli/src/daemon/disable/Disable.handler.ts index b372dd40d2..cb527b8795 100644 --- a/packages/cli/src/daemon/disable/Disable.handler.ts +++ b/packages/cli/src/daemon/disable/Disable.handler.ts @@ -62,7 +62,8 @@ export default class DisableDaemonHandler implements ICommandHandler { // add the right EXE file name for the current OS switch (sysInfo.platform) { - case "darwin" || "linux": { + case "darwin": + case "linux": { zoweExePath += "zowe"; break; } From 30aa518f635e70443c5d44606cc80576d4260591 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 30 Dec 2021 16:15:09 -0500 Subject: [PATCH 44/78] Fix garbled indent. Signed-off-by: Gene Johnston --- .../daemon/__unit__/enable/Enable.handler.unit.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 1b42ee7fb9..74a2c9eb0f 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -451,5 +451,6 @@ describe("Handler for daemon enable", () => { IO.existsSync = existsSyncOrig; IO.isDir = isDirOrig; IO.createDirSync = createDirSyncOrig; - }); }); // end enableDaemon method + }); + }); // end enableDaemon method }); // end Handler From 925c2b51a439a4856ec8c2698a663fa4a262ae0c Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 30 Dec 2021 16:16:44 -0500 Subject: [PATCH 45/78] Add real tests. Signed-off-by: Gene Johnston --- .../disable/Disable.handler.unit.test.ts | 310 ++++++++++++++++-- 1 file changed, 277 insertions(+), 33 deletions(-) diff --git a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts index 5ca2d4f8a1..2ea26bf97d 100644 --- a/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/disable/Disable.handler.unit.test.ts @@ -9,50 +9,65 @@ * */ +import * as nodeJsPath from "path"; + +import { ImperativeConfig, ImperativeError, IO, ProcessUtils, ISystemInfo } from "@zowe/imperative"; + import DisableDaemonHandler from "../../../../src/daemon/disable/Disable.handler"; describe("Disable daemon handler", () => { let disableHandler: any; // use "any" so we can call private functions let disableDaemonSpy: any; - // command parms passed to process() by multiple tests - let apiMessage = ""; - let jsonObj; - let logMessage = ""; - const cmdParms = { - arguments: { - $0: "fake", - _: ["fake"] - }, - response: { - data: { - setMessage: jest.fn((setMsgArgs) => { - apiMessage = setMsgArgs; - }), - setObj: jest.fn((setObjArgs) => { - jsonObj = setObjArgs; - }), - setExitCode: jest.fn((exitCode) => { - return exitCode; - }) - }, - console: { - log: jest.fn((logArgs) => { - logMessage += "\n" + logArgs; - }) - }, - progress: {} - }, - profiles: {} - } as any; - beforeAll(() => { // instantiate our handler and spy on its private disableDaemon() function disableHandler = new DisableDaemonHandler(); }); + beforeEach(() => { + // remove disableDaemon spy + disableDaemonSpy?.mockRestore(); + }); + describe("process method", () => { - it("should disable the daemon", async () => { + // command parms passed to process() by multiple tests + let apiMessage = ""; + let jsonObj; + let logMessage = ""; + const cmdParms = { + arguments: { + $0: "fake", + _: ["fake"] + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + apiMessage = setMsgArgs; + }), + setObj: jest.fn((setObjArgs) => { + jsonObj = setObjArgs; + }), + setExitCode: jest.fn((exitCode) => { + return exitCode; + }) + }, + console: { + log: jest.fn((logArgs) => { + logMessage += "\n" + logArgs; + }) + }, + progress: {} + }, + profiles: {} + } as any; + + beforeEach(() => { + // clear logMessage contents + logMessage = ""; + }); + + it("should succeed when the disableDaemon function succeeds", async () => { + // spy on our handler's private disableDaemon() function disableDaemonSpy = jest.spyOn(DisableDaemonHandler.prototype as any, "disableDaemon"); disableDaemonSpy.mockImplementation(() => {return;}); @@ -68,5 +83,234 @@ describe("Disable daemon handler", () => { expect(disableDaemonSpy).toHaveBeenCalledTimes(1); expect(logMessage).toContain("Zowe CLI daemon mode is disabled."); }); - }); + + it("should fail when the disableDaemon function fails", async () => { + const badStuffMsg = "Some bad exception happened"; + + // spy on our handler's private enableDaemon() function + disableDaemonSpy = jest.spyOn(DisableDaemonHandler.prototype as any, "disableDaemon"); + disableDaemonSpy.mockImplementation(() => { + throw new ImperativeError({ + msg: badStuffMsg + }); + }); + + let error; + try { + // Invoke the handler with a full set of mocked arguments and response functions + await disableHandler.process(cmdParms); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + expect(disableDaemonSpy).toHaveBeenCalledTimes(1); + expect(logMessage).toContain("Failed to disable Zowe CLI daemon mode"); + expect(logMessage).toContain(badStuffMsg); + }); + }); // end process method + describe("disableDaemon method", () => { + // cliHome is a getter property, so mock the property + const impCfg: ImperativeConfig = ImperativeConfig.instance; + Object.defineProperty(impCfg, "cliHome", { + configurable: true, + get: jest.fn(() => { + return "NotaRealCliHomeDir"; + }) + }); + + let fakeZoweExePath: string; + + beforeAll(async () => { + // form our EXE file name path + fakeZoweExePath = ImperativeConfig.instance.cliHome + nodeJsPath.sep + "bin" + nodeJsPath.sep; + const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); + switch (sysInfo.platform) { + case "darwin": + case "linux": { + fakeZoweExePath += "zowe"; + break; + } + case "win32": { + fakeZoweExePath += "zowe.exe"; + break; + } + default: { + fakeZoweExePath += "exeForUnknownOs"; + throw "cli.daemon.enable.integration.test.ts: beforeAll: " + sysInfo.platform + " is not a known OS."; + } + } + + // our unit tests will never delete a file + IO.deleteFile = jest.fn(() => { + return; + }); + + }); + + it("should run on windows", async () => { + const getBasicSystemInfoOrig = ProcessUtils.getBasicSystemInfo; + ProcessUtils.getBasicSystemInfo = jest.fn(() => { + return { + "arch": "DoesNotMatterForThisTest", + "platform": "win32" + }; + }); + + let error; + try { + await disableHandler.disableDaemon(); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + ProcessUtils.getBasicSystemInfo = getBasicSystemInfoOrig; + }); + + it("should run on linux", async () => { + const getBasicSystemInfoOrig = ProcessUtils.getBasicSystemInfo; + ProcessUtils.getBasicSystemInfo = jest.fn(() => { + return { + "arch": "DoesNotMatterForThisTest", + "platform": "linux" + }; + }); + + let error; + try { + await disableHandler.disableDaemon(); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + ProcessUtils.getBasicSystemInfo = getBasicSystemInfoOrig; + }); + + it("should run on mac", async () => { + const getBasicSystemInfoOrig = ProcessUtils.getBasicSystemInfo; + ProcessUtils.getBasicSystemInfo = jest.fn(() => { + return { + "arch": "DoesNotMatterForThisTest", + "platform": "darwin" + }; + }); + + let error; + try { + await disableHandler.disableDaemon(); + } catch (e) { + error = e; + } + + expect(error).toBeUndefined(); + ProcessUtils.getBasicSystemInfo = getBasicSystemInfoOrig; + }); + + it("should fail on an unsupported platform", async () => { + const getBasicSystemInfoOrig = ProcessUtils.getBasicSystemInfo; + ProcessUtils.getBasicSystemInfo = jest.fn(() => { + return { + "arch": "BogusArch", + "platform": "BogusPlatform" + }; + }); + + let error; + try { + await disableHandler.disableDaemon(); + } catch (e) { + error = e; + } + + expect(error.mMessage).toBe("Daemon mode is not supported on the 'BogusPlatform' operating system."); + ProcessUtils.getBasicSystemInfo = getBasicSystemInfoOrig; + }); + + it("should succeed when no EXE exists", async () => { + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn(() => { + return false; + }); + + let error; + try { + await disableHandler.disableDaemon(); + } catch (e) { + error = e; + } + + expect(IO.existsSync).toHaveBeenCalledTimes(1); + expect(IO.existsSync).toHaveBeenCalledWith(fakeZoweExePath); + expect(IO.deleteFile).toHaveBeenCalledTimes(0); + expect(error).toBeUndefined(); + IO.existsSync = existsSyncOrig; + }); + + it("should delete an existing EXE", async () => { + const existsSyncOrig = IO.existsSync; + IO.existsSync = jest.fn(() => { + return true; + }); + + let error; + try { + await disableHandler.disableDaemon(); + } catch (e) { + error = e; + } + + expect(IO.existsSync).toHaveBeenCalledTimes(1); + expect(IO.existsSync).toHaveBeenCalledWith(fakeZoweExePath); + expect(IO.deleteFile).toHaveBeenCalledTimes(1); + expect(error).toBeUndefined(); + IO.existsSync = existsSyncOrig; + }); + + it("should succeed when no daemon is running", async () => { + const killSpy = jest.spyOn(process, 'kill').mockImplementation(() => {return;}); + + let error; + try { + await disableHandler.disableDaemon(); + } catch (e) { + error = e; + } + + expect(killSpy).toHaveBeenCalledTimes(0); + expect(error).toBeUndefined(); + }); + + it("should succeed when a zowe daemon is running", async () => { + const killSpy = jest.spyOn(process, 'kill').mockImplementation(() => {return;}); + + /* The find-process module returns a single function as its default export. + * This concoction enables us to override that function. + */ + const fakePid = 1234567890; + const findProcMock = jest.fn(); + jest.mock('find-process', () => findProcMock); + findProcMock.mockImplementation(() => { + return[{ + "name": "node", + "pid": fakePid, + "cmd": "node /some/path/to/@zowe/cli/lib/main.js --daemon" + }]; + }); + + let error; + try { + await disableHandler.disableDaemon(); + } catch (e) { + error = e; + } + + expect(findProcMock).toHaveBeenCalledTimes(1); + expect(findProcMock).toHaveBeenCalledWith("name", "node", true); + expect(killSpy).toHaveBeenCalledTimes(1); + expect(killSpy).toHaveBeenCalledWith(fakePid, "SIGINT"); + expect(error).toBeUndefined(); + }); + }); // end disableDaemon method }); From 0e9b76619455c430dbeb037797d241f35151b646 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 30 Dec 2021 16:45:57 -0500 Subject: [PATCH 46/78] Add disable help script. Signed-off-by: Gene Johnston --- .../disable/__scripts__/daemon_disable_help.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh diff --git a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh new file mode 100644 index 0000000000..3531cbed84 --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +echo "================ daemon enable help ===============" +zowe daemon disable --help +if [ $? -gt 0 ] +then + exit $? +fi From 3c4d9cbc6dd02a6fc1794b6d704e5fcb672265dd Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 30 Dec 2021 17:25:40 -0500 Subject: [PATCH 47/78] Add disable script. Signed-off-by: Gene Johnston --- .../disable/__scripts__/daemon_disable.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh diff --git a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh new file mode 100644 index 0000000000..c46d4fc560 --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +echo "================ daemon enable ===============" +zowe daemon disable +if [ $? -gt 0 ] +then + exit $? +fi From 2b49cb6d18842c791514b62196a2e8a9f9ddc57b Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Sun, 2 Jan 2022 20:11:30 -0500 Subject: [PATCH 48/78] Add integration tests. Signed-off-by: Gene Johnston --- .../cli.daemon.disable.integration.test.ts | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts diff --git a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts new file mode 100644 index 0000000000..b0d36f7e9c --- /dev/null +++ b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts @@ -0,0 +1,203 @@ +/* +* This program and the accompanying materials are made available under the terms of the +* Eclipse Public License v2.0 which accompanies this distribution, and is available at +* https://www.eclipse.org/legal/epl-v20.html +* +* SPDX-License-Identifier: EPL-2.0 +* +* Copyright Contributors to the Zowe Project. +* +*/ + +import * as fs from "fs"; +import * as nodeJsPath from "path"; +import * as which from "which"; +import { exec } from "child_process"; + + +import { IO, ISystemInfo, ProcessUtils } from "@zowe/imperative"; +import { ITestEnvironment, runCliScript } from "@zowe/cli-test-utils"; + +import { TestEnvironment } from "../../../../../../__tests__/__src__/environment/TestEnvironment"; +import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema"; + +let testEnvironment: ITestEnvironment; + +describe("daemon disable", () => { + const rimraf = require("rimraf").sync; + const fakeExeContent = "This is not a real executable"; + const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe-CLI native executable."; + const exeCantRunDaemonMsg2: string = "Copy and paste the following command instead:"; + const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 107; + + let exePath: string; + let pathToBin: string; + let preBldTgzPath: string; // zzz + let isZoweExe: boolean = false; // is the zowe command that we will run an executable? + + beforeAll(async () => { + // Create the unique test environment + testEnvironment = await TestEnvironment.setUp({ + testName: "daemon_disable_integration", + skipProperties: true + }); + + // determine our current OS + const sysInfo: ISystemInfo = ProcessUtils.getBasicSystemInfo(); + + // form our tgz file name + let tgzFileName = "zowe-"; + switch (sysInfo.platform) { + case "darwin": { + tgzFileName += "macos.tgz"; + exePath = "zowe"; + break; + } + case "linux": { + tgzFileName += "linux.tgz"; + exePath = "zowe"; + break; + } + case "win32": { + tgzFileName += "windows.tgz"; + exePath = "zowe.exe"; + break; + } + default: { + tgzFileName += "unknownOs.tgz"; + exePath = "exeForUnknownOs"; + throw "cli.daemon.disable.integration.test.ts: beforeAll: " + sysInfo.platform + " is not a known OS."; + } + } + + // form the path to our bin directory, executable, and prebuilds tgz file + const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", tgzFileName); + preBldTgzPath = nodeJsPath.resolve(__dirname, "../../../../prebuilds", tgzFileName); + pathToBin = nodeJsPath.resolve(testEnvironment.workingDir, "bin"); + exePath = nodeJsPath.resolve(pathToBin, exePath); + + /* zzz move into a test - copy target/debug/exe to cliHome/bin/exe + if (!IO.existsSync(pathToBin)) { + IO.createDirSync(pathToBin); + } + if (!IO.existsSync(exePath)) { + fs.copyFileSync(tgzResourcePath, exePath); + } + */ + + // Get the zowe program from the PATH that will be used in the test + const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); + + // We know that our zowe EXE will be bigger than our zowe scripts + const exeMinSize: number = 2000; + const zowePgmStats = fs.statSync(zowePgmInPath); + if (zowePgmStats.size >= exeMinSize) { + isZoweExe = true; + } + }); + + afterAll(async () => { + await TestEnvironment.cleanUp(testEnvironment); + }); + + it("should display the help", async () => { + /* Our EXE can display help, but actually launching the daemon causes the + * convoluted set of zowe EXEs, fake zowe EXEs, and zowe scripts to hang. + * Just skip this test for the EXE. For the remaining tests, the EXE + * works completely within itself, and never launches the daemon. + */ + if (!isZoweExe) { + const response = runCliScript(__dirname + "/__scripts__/daemon_disable_help.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("COMMAND NAME"); + expect(stdoutStr).toContain("Disables daemon-mode operation of the Zowe-CLI."); + expect(stdoutStr).toContain("USAGE"); + expect(stdoutStr).toContain("zowe daemon disable [options]"); + expect(stdoutStr).toContain("GLOBAL OPTIONS"); + expect(stdoutStr).toContain("--help | -h (boolean)"); + expect(stdoutStr).toContain("EXAMPLES"); + expect(stdoutStr).toContain("Disable daemon-mode:"); + expect(stdoutStr).toContain("$ zowe daemon disable"); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); + } + }); + + it("should succeed when no EXE exists", async () => { + if (IO.existsSync(pathToBin)) { + rimraf(pathToBin); + } + const response = runCliScript(__dirname + "/__scripts__/daemon_disable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + if (isZoweExe) { + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } else { + expect(stdoutStr).toContain("Zowe CLI daemon mode is disabled."); + expect(response.status).toBe(0); + } + }); + + it("should delete an existing EXE", async () => { + if (!isZoweExe) { + if (!IO.existsSync(pathToBin)) { + IO.createDirSync(pathToBin); + } + if (!IO.existsSync(exePath)) { + IO.createFileSync(exePath); + } + const response = runCliScript(__dirname + "/__scripts__/daemon_disable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode is disabled."); + expect(IO.existsSync(exePath)).toBe(false); + expect(response.status).toBe(0); + } + }); + + it("should succeed when no daemon is running", async () => { + if (!isZoweExe) { + // find any running daemon + const findProc = require('find-process'); + const procArray = await findProc('name', 'node', true); + + // match and kill any running Zowe daemon + const zoweCmdRegEx = "@zowe[/|\\\\]cli[/|\\\\]lib[/|\\\\]main.js"; + for (const nextProc of procArray) { + if (nextProc.cmd.match(zoweCmdRegEx) && nextProc.cmd.includes("--daemon")) { + process.kill(nextProc.pid, "SIGINT"); + } + } + + const response = runCliScript(__dirname + "/__scripts__/daemon_disable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode is disabled."); + expect(IO.existsSync(exePath)).toBe(false); + expect(response.status).toBe(0); + } + }); + + it("should stop a running zowe daemon", async () => { + if (!isZoweExe) { + // start a daemon + exec("zowe --daemon"); + + // run disable + const response = runCliScript(__dirname + "/__scripts__/daemon_disable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("Zowe CLI daemon mode is disabled."); + expect(IO.existsSync(exePath)).toBe(false); + expect(response.status).toBe(0); + + // match any running Zowe daemon + const findProc = require('find-process'); + const procArray = await findProc('name', 'node', true); + const zoweCmdRegEx = "@zowe[/|\\\\]cli[/|\\\\]lib[/|\\\\]main.js"; + for (const nextProc of procArray) { + if (nextProc.cmd.match(zoweCmdRegEx) && nextProc.cmd.includes("--daemon")) { + expect("we should not find a daemon").toContain("so the disable command failed."); + } + } + } + }); +}); From 978a29d1b1a4c5da1f931ee05232107604d9f40d Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Sun, 2 Jan 2022 20:36:14 -0500 Subject: [PATCH 49/78] Run help test for either EXE or nodeJS script. Signed-off-by: Gene Johnston --- .../cli.daemon.enable.integration.test.ts | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 5ec38801b4..e59355290f 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -104,26 +104,19 @@ describe("daemon enable", () => { }); it("should display the help", async () => { - /* Our EXE can display help, but actually launching the daemon causes the - * convoluted set of zowe EXEs, fake zowe EXEs, and zowe scripts to hang. - * Just skip this test for the EXE. For the remaining tests, the EXE - * works completely within itself, and never launches the daemon. - */ - if (!isZoweExe) { - const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("COMMAND NAME"); - expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe-CLI."); - expect(stdoutStr).toContain("USAGE"); - expect(stdoutStr).toContain("zowe daemon enable [options]"); - expect(stdoutStr).toContain("GLOBAL OPTIONS"); - expect(stdoutStr).toContain("--help | -h (boolean)"); - expect(stdoutStr).toContain("EXAMPLES"); - expect(stdoutStr).toContain("Enable daemon-mode:"); - expect(stdoutStr).toContain("$ zowe daemon enable"); - expect(response.stderr.toString()).toBe(""); - expect(response.status).toBe(0); - } + const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("COMMAND NAME"); + expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe-CLI."); + expect(stdoutStr).toContain("USAGE"); + expect(stdoutStr).toContain("zowe daemon enable [options]"); + expect(stdoutStr).toContain("GLOBAL OPTIONS"); + expect(stdoutStr).toContain("--help | -h (boolean)"); + expect(stdoutStr).toContain("EXAMPLES"); + expect(stdoutStr).toContain("Enable daemon-mode:"); + expect(stdoutStr).toContain("$ zowe daemon enable"); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); }); it("should fail when the tgz file does not exist", async () => { From 443171c0c66383bc3635bc6213744eb2bf547ed3 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 4 Jan 2022 11:33:04 -0500 Subject: [PATCH 50/78] Update design doc overview. Signed-off-by: Gene Johnston --- zowex/design.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zowex/design.md b/zowex/design.md index 3b47bab424..738dc31f31 100644 --- a/zowex/design.md +++ b/zowex/design.md @@ -1,6 +1,10 @@ # Daemon Mode Design Overview -Zowe CLI start up time can be slow 3 - 15 seconds. Part of the reason this operation can be slow is the overhead involved in startup of the Node.js runtime (measured with V8 instrumentations). +Zowe CLI start up time can be slow: 3 - 15 seconds. This often occurs in virtualized environments where the directories, into which the Zowe CLI is installed, are geographically remote from the server that hosts the virtualized environments. Part of the reason this operation can be slow is the overhead involved in the startup of the Node.js runtime (measured with V8 instrumentations). The Node.js modules used by the Zowe CLI must be loaded every time a user issues another zowe command. The module loading process can be time consuming due to the delays associated with network transfers over a large geographic distance. + +A customer site can address this situation by installing Zowe CLI onto a disk that is located in the same geographic location as the site's server of virtual environments. Pointing the ZOWE_CLI_HOME directory to a disk drive co-located with the server will also help. + +When the Zowe CLI user community at a given customer site does not have the adminstrative privileges to control where the Zowe CLI is installed, an alternative approach is to use the Zowe-CLI daemon to significantly improve performance. ## Solution Overview @@ -85,7 +89,7 @@ The daemon client sends messages to server like: zowe --version Starting a background process to increase performance ... 7.0.0-next.202111111904 - + zowe --version 7.0.0-next.202111111904 ``` From cc74a770d598a2583b350e237b3adbe7d0d5c232 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 4 Jan 2022 12:05:12 -0500 Subject: [PATCH 51/78] Add a comment to kick-start Jenkins PR pipeline Signed-off-by: Gene Johnston --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 5cc1cf3763..98118693a5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,6 +9,12 @@ * * */ +/* A PR pipeline was not created by jenkins because it cannot find Jenkinsfile. + * But this is the Jenkinsfile, and it is obviously here. + * This comment was just added so that I can push the Jenkinsfile and hope that + * Jenkins will pick it up. This comment can be deleted at any time. + */ + @Library('shared-pipelines') import org.zowe.pipelines.nodejs.NodeJSPipeline import org.zowe.pipelines.nodejs.models.SemverLevel From 5b3162c2c867f05d2229999a1a0a0bf266cdffdc Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 4 Jan 2022 14:25:25 -0500 Subject: [PATCH 52/78] Add THREE_SEC_DELAY constant. Signed-off-by: Gene Johnston --- zowex/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zowex/src/main.rs b/zowex/src/main.rs index 77ecaa35a7..cf6f208b42 100644 --- a/zowex/src/main.rs +++ b/zowex/src/main.rs @@ -268,6 +268,7 @@ fn run_daemon_command(mut args: String) -> std::io::Result<()> { * Iterate to enable a slow system to start the daemon. */ fn establish_connection(host: String, port: String) -> std::io::Result { + const THREE_SEC_DELAY: u64 = 3; const THREE_MIN_OF_RETRIES: i32 = 60; const RETRY_TO_SHOW_DIAG: i32 = 5; @@ -313,7 +314,7 @@ fn establish_connection(host: String, port: String) -> std::io::Result Date: Tue, 4 Jan 2022 14:40:27 -0500 Subject: [PATCH 53/78] Remove some unused code. Signed-off-by: Gene Johnston --- .../disable/cli.daemon.disable.integration.test.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts index b0d36f7e9c..82b842c3c4 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts @@ -32,7 +32,6 @@ describe("daemon disable", () => { let exePath: string; let pathToBin: string; - let preBldTgzPath: string; // zzz let isZoweExe: boolean = false; // is the zowe command that we will run an executable? beforeAll(async () => { @@ -72,19 +71,9 @@ describe("daemon disable", () => { // form the path to our bin directory, executable, and prebuilds tgz file const tgzResourcePath = nodeJsPath.resolve(__dirname, "../../__resources__", tgzFileName); - preBldTgzPath = nodeJsPath.resolve(__dirname, "../../../../prebuilds", tgzFileName); pathToBin = nodeJsPath.resolve(testEnvironment.workingDir, "bin"); exePath = nodeJsPath.resolve(pathToBin, exePath); - /* zzz move into a test - copy target/debug/exe to cliHome/bin/exe - if (!IO.existsSync(pathToBin)) { - IO.createDirSync(pathToBin); - } - if (!IO.existsSync(exePath)) { - fs.copyFileSync(tgzResourcePath, exePath); - } - */ - // Get the zowe program from the PATH that will be used in the test const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); From 4a17912d7351788c65201481838a2e90c06fb19b Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 4 Jan 2022 15:48:03 -0500 Subject: [PATCH 54/78] Change Zowe-CLI to Zowe CLI Signed-off-by: Gene Johnston --- .../disable/cli.daemon.disable.integration.test.ts | 4 ++-- .../enable/cli.daemon.enable.integration.test.ts | 4 ++-- .../__snapshots__/Daemon.definition.unit.test.ts.snap | 2 +- .../__snapshots__/Disable.definition.unit.test.ts.snap | 2 +- .../daemon/__unit__/enable/Enable.handler.unit.test.ts | 1 + .../enable/__snapshots__/Enable.definition.unit.test.ts.snap | 2 +- packages/cli/src/daemon/Daemon.definition.ts | 2 +- packages/cli/src/daemon/disable/Disable.definition.ts | 2 +- packages/cli/src/daemon/disable/Disable.handler.ts | 2 +- packages/cli/src/daemon/enable/Enable.definition.ts | 4 ++-- zowex/src/main.rs | 2 +- 11 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts index 82b842c3c4..27566fdb46 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts @@ -26,7 +26,7 @@ let testEnvironment: ITestEnvironment; describe("daemon disable", () => { const rimraf = require("rimraf").sync; const fakeExeContent = "This is not a real executable"; - const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe-CLI native executable."; + const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe CLI native executable."; const exeCantRunDaemonMsg2: string = "Copy and paste the following command instead:"; const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 107; @@ -99,7 +99,7 @@ describe("daemon disable", () => { const response = runCliScript(__dirname + "/__scripts__/daemon_disable_help.sh", testEnvironment); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("COMMAND NAME"); - expect(stdoutStr).toContain("Disables daemon-mode operation of the Zowe-CLI."); + expect(stdoutStr).toContain("Disables daemon-mode operation of the Zowe CLI."); expect(stdoutStr).toContain("USAGE"); expect(stdoutStr).toContain("zowe daemon disable [options]"); expect(stdoutStr).toContain("GLOBAL OPTIONS"); diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index e59355290f..6d299f6175 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -24,7 +24,7 @@ let testEnvironment: ITestEnvironment; describe("daemon enable", () => { const rimraf = require("rimraf").sync; const fakeExeContent = "This is not a real executable"; - const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe-CLI native executable."; + const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe CLI native executable."; const exeCantRunDaemonMsg2: string = "Copy and paste the following command instead:"; const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 107; @@ -107,7 +107,7 @@ describe("daemon enable", () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("COMMAND NAME"); - expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe-CLI."); + expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe CLI."); expect(stdoutStr).toContain("USAGE"); expect(stdoutStr).toContain("zowe daemon enable [options]"); expect(stdoutStr).toContain("GLOBAL OPTIONS"); diff --git a/packages/cli/__tests__/daemon/__unit__/__snapshots__/Daemon.definition.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/__snapshots__/Daemon.definition.unit.test.ts.snap index 786c7a627d..e1c9df287f 100644 --- a/packages/cli/__tests__/daemon/__unit__/__snapshots__/Daemon.definition.unit.test.ts.snap +++ b/packages/cli/__tests__/daemon/__unit__/__snapshots__/Daemon.definition.unit.test.ts.snap @@ -2,7 +2,7 @@ exports[`daemon group definition should have the right command content 1`] = ` Object { - "description": "Perform operations that control the daemon-mode functionality of the Zowe-CLI. Daemon-mode runs the CLI command processor as a daemon to improve performance.", + "description": "Perform operations that control the daemon-mode functionality of the Zowe CLI. Daemon-mode runs the CLI command processor as a daemon to improve performance.", "name": "daemon", "summary": "Daemon operations", "type": "group", diff --git a/packages/cli/__tests__/daemon/__unit__/disable/__snapshots__/Disable.definition.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/disable/__snapshots__/Disable.definition.unit.test.ts.snap index ff98863de4..6e99427591 100644 --- a/packages/cli/__tests__/daemon/__unit__/disable/__snapshots__/Disable.definition.unit.test.ts.snap +++ b/packages/cli/__tests__/daemon/__unit__/disable/__snapshots__/Disable.definition.unit.test.ts.snap @@ -2,7 +2,7 @@ exports[`daemon disable definition should not have changed 1`] = ` Object { - "description": "Disables daemon-mode operation of the Zowe-CLI.", + "description": "Disables daemon-mode operation of the Zowe CLI.", "examples": Array [ Object { "description": "Disable daemon-mode", diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 74a2c9eb0f..f13e689621 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -8,6 +8,7 @@ * Copyright Contributors to the Zowe Project. * */ + jest.mock("child_process"); // using child_process from the __mocks__ directory import { ImperativeConfig, ImperativeError, IO, ProcessUtils, ISystemInfo } from "@zowe/imperative"; diff --git a/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap b/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap index f6088bf15d..5b49455654 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap +++ b/packages/cli/__tests__/daemon/__unit__/enable/__snapshots__/Enable.definition.unit.test.ts.snap @@ -2,7 +2,7 @@ exports[`daemon enable definition should not have changed 1`] = ` Object { - "description": "Enables daemon-mode operation of the Zowe-CLI. You only need to run the enable command once after each new installation of the Zowe-CLI. Afterwards, any zowe command will automatically start a daemon as needed.", + "description": "Enables daemon-mode operation of the Zowe CLI. You only need to run the enable command once after each new installation of the Zowe CLI. Afterwards, any zowe command will automatically start a daemon as needed.", "examples": Array [ Object { "description": "Enable daemon-mode", diff --git a/packages/cli/src/daemon/Daemon.definition.ts b/packages/cli/src/daemon/Daemon.definition.ts index 4718b380dd..f923ae5e4b 100644 --- a/packages/cli/src/daemon/Daemon.definition.ts +++ b/packages/cli/src/daemon/Daemon.definition.ts @@ -17,7 +17,7 @@ const definition: ICommandDefinition = { name: "daemon", type: "group", summary: "Daemon operations", - description: "Perform operations that control the daemon-mode functionality of the Zowe-CLI. " + + description: "Perform operations that control the daemon-mode functionality of the Zowe CLI. " + "Daemon-mode runs the CLI command processor as a daemon to improve performance.", children: [ EnableCommand, diff --git a/packages/cli/src/daemon/disable/Disable.definition.ts b/packages/cli/src/daemon/disable/Disable.definition.ts index 75a5000fa0..0e58916f9e 100644 --- a/packages/cli/src/daemon/disable/Disable.definition.ts +++ b/packages/cli/src/daemon/disable/Disable.definition.ts @@ -13,7 +13,7 @@ import { ICommandDefinition } from "@zowe/imperative"; export const DisableCommand: ICommandDefinition = { name: "disable", - description: "Disables daemon-mode operation of the Zowe-CLI.", + description: "Disables daemon-mode operation of the Zowe CLI.", type: "command", handler: __dirname + "/Disable.handler", examples: [ diff --git a/packages/cli/src/daemon/disable/Disable.handler.ts b/packages/cli/src/daemon/disable/Disable.handler.ts index cb527b8795..46892404fa 100644 --- a/packages/cli/src/daemon/disable/Disable.handler.ts +++ b/packages/cli/src/daemon/disable/Disable.handler.ts @@ -101,7 +101,7 @@ export default class DisableDaemonHandler implements ICommandHandler { powerShellHint = "\nPowershell.exe may not be on your PATH."; } throw new ImperativeError({ - msg: "Failed while searching for the Zowe-CLI daemon process.\n" + msg: "Failed while searching for the Zowe CLI daemon process.\n" + `Reason: ${err}` + powerShellHint }); diff --git a/packages/cli/src/daemon/enable/Enable.definition.ts b/packages/cli/src/daemon/enable/Enable.definition.ts index 2f0c45a116..17e7ba337a 100644 --- a/packages/cli/src/daemon/enable/Enable.definition.ts +++ b/packages/cli/src/daemon/enable/Enable.definition.ts @@ -13,9 +13,9 @@ import { ICommandDefinition } from "@zowe/imperative"; export const EnableCommand: ICommandDefinition = { name: "enable", - description: "Enables daemon-mode operation of the Zowe-CLI. " + + description: "Enables daemon-mode operation of the Zowe CLI. " + "You only need to run the enable command once after each " + - "new installation of the Zowe-CLI. Afterwards, any zowe command " + + "new installation of the Zowe CLI. Afterwards, any zowe command " + "will automatically start a daemon as needed.", type: "command", handler: __dirname + "/Enable.handler", diff --git a/zowex/src/main.rs b/zowex/src/main.rs index cf6f208b42..aebbe52b0e 100644 --- a/zowex/src/main.rs +++ b/zowex/src/main.rs @@ -173,7 +173,7 @@ fn exit_when_alt_cmd_needed(cmd_line_args: &Vec) { } // show the NodeJS zowe command that the user can run instead - println!("You cannot run this 'daemon' command while using the Zowe-CLI native executable."); + println!("You cannot run this 'daemon' command while using the Zowe CLI native executable."); println!("Copy and paste the following command instead:"); // From 158f42e6c7d26d2b86e4726e71b2cabcaa3f92e2 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 4 Jan 2022 16:15:12 -0500 Subject: [PATCH 55/78] Remove comment to start Jenkins. It did not help. Signed-off-by: Gene Johnston --- Jenkinsfile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 98118693a5..5cc1cf3763 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,12 +9,6 @@ * * */ -/* A PR pipeline was not created by jenkins because it cannot find Jenkinsfile. - * But this is the Jenkinsfile, and it is obviously here. - * This comment was just added so that I can push the Jenkinsfile and hope that - * Jenkins will pick it up. This comment can be deleted at any time. - */ - @Library('shared-pipelines') import org.zowe.pipelines.nodejs.NodeJSPipeline import org.zowe.pipelines.nodejs.models.SemverLevel From febc43c8a3bc29e589312666d29dc580f7f5cf70 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 4 Jan 2022 16:24:49 -0500 Subject: [PATCH 56/78] Change 'path' text to 'PATH'. Signed-off-by: Gene Johnston --- .../enable/cli.daemon.enable.integration.test.ts | 4 ++-- .../daemon/__unit__/enable/Enable.handler.unit.test.ts | 2 +- packages/cli/src/daemon/enable/Enable.handler.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 6d299f6175..2062fbbd18 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -218,7 +218,7 @@ describe("daemon enable", () => { } else { expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); - expect(stdoutStr).toContain(`Add '${pathToBin}' to your path`); + expect(stdoutStr).toContain(`Add '${pathToBin}' to your PATH`); expect(stdoutStr).toContain("Otherwise, you will continue to run the classic Zowe CLI interpreter"); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); @@ -239,7 +239,7 @@ describe("daemon enable", () => { } else { expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); - expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your path`); + expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your PATH`); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); } diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index f13e689621..8f2368779c 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -368,7 +368,7 @@ describe("Handler for daemon enable", () => { expect(error).toBeUndefined(); expect(unzipTgzSpy).toHaveBeenCalledTimes(1); - expect(userInfoMsg).toContain(`Add '${zoweBinDirMock}' to your path.`); + expect(userInfoMsg).toContain(`Add '${zoweBinDirMock}' to your PATH.`); IO.existsSync = existsSyncOrig; IO.isDir = isDirOrig; diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index 1ed1cda454..78add1b6b3 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -141,7 +141,7 @@ export default class EnableDaemonHandler implements ICommandHandler { // if ZOWE_CLI_HOME/bin is not on our PATH, add an instruction to add it if (process.env?.PATH?.length > 0) { if (!process.env.PATH.includes(zoweHomeBin)) { - userInfoMsg += `\n\nAdd '${zoweHomeBin}' to your path.` + + userInfoMsg += `\n\nAdd '${zoweHomeBin}' to your PATH.` + "\nOtherwise, you will continue to run the classic Zowe CLI interpreter."; } } From d77bd9fca2e29a68691920a3162b5a978ddfa55f Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 4 Jan 2022 16:59:00 -0500 Subject: [PATCH 57/78] Add daemon enable and disable to the changelog. Signed-off-by: Gene Johnston --- packages/cli/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index bd2844018c..cfac3a33bd 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to the Zowe CLI package will be documented in this file. +## Recent Changes + +- Enhancement: Add the commands `zowe daemon enable` and `zowe daemon disable`. These commands enable end-users to set up daemon mode without having to download a separate executable and place it by hand into some directory. +- **Next Breaking**: The Daemon-related class named `Processor` was renamed to `DaemonDecider`. + + ## `7.0.0-next.202112081943` - **Next Breaking**: Remove hardcoded `--dcd` argument sent between imperative daemon server and client. From e18f24c991ef317410f6f2236deadc7f2e255c12 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 5 Jan 2022 15:55:37 -0500 Subject: [PATCH 58/78] Fix typo in MacOs TGZ. Signed-off-by: Gene Johnston --- .../{zowe-macos.tar.gz => zowe-macos.tgz} | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/cli/__tests__/daemon/__resources__/{zowe-macos.tar.gz => zowe-macos.tgz} (100%) diff --git a/packages/cli/__tests__/daemon/__resources__/zowe-macos.tar.gz b/packages/cli/__tests__/daemon/__resources__/zowe-macos.tgz similarity index 100% rename from packages/cli/__tests__/daemon/__resources__/zowe-macos.tar.gz rename to packages/cli/__tests__/daemon/__resources__/zowe-macos.tgz From 1d17d13eb2706b040f2c8f60c3af798dfc664333 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 5 Jan 2022 16:28:45 -0500 Subject: [PATCH 59/78] Fix some Sonar complaints. Signed-off-by: Gene Johnston --- packages/cli/src/daemon/disable/Disable.handler.ts | 1 - packages/cli/src/daemon/enable/Enable.handler.ts | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/daemon/disable/Disable.handler.ts b/packages/cli/src/daemon/disable/Disable.handler.ts index 46892404fa..8d19cdcde7 100644 --- a/packages/cli/src/daemon/disable/Disable.handler.ts +++ b/packages/cli/src/daemon/disable/Disable.handler.ts @@ -42,7 +42,6 @@ export default class DisableDaemonHandler implements ICommandHandler { cmdParams.response.console.log("Zowe CLI daemon mode is disabled."); cmdParams.response.data.setExitCode(0); - return; } /** diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index 78add1b6b3..2741ba2573 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -46,7 +46,6 @@ export default class EnableDaemonHandler implements ICommandHandler { cmdParams.response.console.log("Zowe CLI daemon mode enabled.\n" + userMsg); cmdParams.response.data.setExitCode(0); - return; } /** @@ -85,7 +84,7 @@ export default class EnableDaemonHandler implements ICommandHandler { } preBldTgz = nodeJsPath.normalize(preBldTgz); - if (IO.existsSync(preBldTgz) == false) { + if (!IO.existsSync(preBldTgz)) { throw new ImperativeError({ msg: `The zip file for your OS executable does not exist: ${preBldTgz}` }); @@ -96,7 +95,7 @@ export default class EnableDaemonHandler implements ICommandHandler { // Does the ZOWE_CLI_HOME bin directory exist? if (IO.existsSync(zoweHomeBin)) { - if (IO.isDir(zoweHomeBin) == false) { + if (!IO.isDir(zoweHomeBin)) { throw new ImperativeError({ msg: `The existing file '${zoweHomeBin}' must be a directory.` }); From 4d7e8dd93c015b8c4810823c865f0b7c31148d5a Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 5 Jan 2022 16:48:09 -0500 Subject: [PATCH 60/78] Remove unneeded EXE guard on help test, Signed-off-by: Gene Johnston --- .../cli.daemon.disable.integration.test.ts | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts index 27566fdb46..a1db4c5857 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts @@ -76,11 +76,12 @@ describe("daemon disable", () => { // Get the zowe program from the PATH that will be used in the test const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); + console.log("TODO: Remove this: zowePgmInPath = " + zowePgmInPath); // We know that our zowe EXE will be bigger than our zowe scripts - const exeMinSize: number = 2000; + const maxScriptSize: number = 2000; const zowePgmStats = fs.statSync(zowePgmInPath); - if (zowePgmStats.size >= exeMinSize) { + if (zowePgmStats.size >= maxScriptSize) { isZoweExe = true; } }); @@ -90,26 +91,19 @@ describe("daemon disable", () => { }); it("should display the help", async () => { - /* Our EXE can display help, but actually launching the daemon causes the - * convoluted set of zowe EXEs, fake zowe EXEs, and zowe scripts to hang. - * Just skip this test for the EXE. For the remaining tests, the EXE - * works completely within itself, and never launches the daemon. - */ - if (!isZoweExe) { - const response = runCliScript(__dirname + "/__scripts__/daemon_disable_help.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("COMMAND NAME"); - expect(stdoutStr).toContain("Disables daemon-mode operation of the Zowe CLI."); - expect(stdoutStr).toContain("USAGE"); - expect(stdoutStr).toContain("zowe daemon disable [options]"); - expect(stdoutStr).toContain("GLOBAL OPTIONS"); - expect(stdoutStr).toContain("--help | -h (boolean)"); - expect(stdoutStr).toContain("EXAMPLES"); - expect(stdoutStr).toContain("Disable daemon-mode:"); - expect(stdoutStr).toContain("$ zowe daemon disable"); - expect(response.stderr.toString()).toBe(""); - expect(response.status).toBe(0); - } + const response = runCliScript(__dirname + "/__scripts__/daemon_disable_help.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("COMMAND NAME"); + expect(stdoutStr).toContain("Disables daemon-mode operation of the Zowe CLI."); + expect(stdoutStr).toContain("USAGE"); + expect(stdoutStr).toContain("zowe daemon disable [options]"); + expect(stdoutStr).toContain("GLOBAL OPTIONS"); + expect(stdoutStr).toContain("--help | -h (boolean)"); + expect(stdoutStr).toContain("EXAMPLES"); + expect(stdoutStr).toContain("Disable daemon-mode:"); + expect(stdoutStr).toContain("$ zowe daemon disable"); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); }); it("should succeed when no EXE exists", async () => { From 0aeedda00d3aca51d60aef3cf5027e2dee096931 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 5 Jan 2022 16:49:10 -0500 Subject: [PATCH 61/78] Add temp code to debug pipelines. Signed-off-by: Gene Johnston --- .../__integration__/enable/__scripts__/daemon_enable_help.sh | 2 ++ .../enable/cli.daemon.enable.integration.test.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh index 08609e9030..ed5f173393 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e +echo "================ TODO: Remove this ===============" +echo PATH = $PATH echo "================ daemon enable help ===============" zowe daemon enable --help if [ $? -gt 0 ] diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 2062fbbd18..020de761b0 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -85,11 +85,12 @@ describe("daemon enable", () => { // Get the zowe program from the PATH that will be used in the test const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); + console.log("TODO: Remove this: zowePgmInPath = " + zowePgmInPath); // We know that our zowe EXE will be bigger than our zowe scripts - const exeMinSize: number = 2000; + const maxScriptSize: number = 2000; const zowePgmStats = fs.statSync(zowePgmInPath); - if (zowePgmStats.size >= exeMinSize) { + if (zowePgmStats.size >= maxScriptSize) { isZoweExe = true; } }); From c2f303a56f577bbd63091d8926bc5e78f070c104 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 5 Jan 2022 17:01:54 -0500 Subject: [PATCH 62/78] Remove console.log statements. Signed-off-by: Gene Johnston --- .../disable/cli.daemon.disable.integration.test.ts | 1 - .../__integration__/enable/cli.daemon.enable.integration.test.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts index a1db4c5857..fa1b210324 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts @@ -76,7 +76,6 @@ describe("daemon disable", () => { // Get the zowe program from the PATH that will be used in the test const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); - console.log("TODO: Remove this: zowePgmInPath = " + zowePgmInPath); // We know that our zowe EXE will be bigger than our zowe scripts const maxScriptSize: number = 2000; diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 020de761b0..b0c064d282 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -85,7 +85,6 @@ describe("daemon enable", () => { // Get the zowe program from the PATH that will be used in the test const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); - console.log("TODO: Remove this: zowePgmInPath = " + zowePgmInPath); // We know that our zowe EXE will be bigger than our zowe scripts const maxScriptSize: number = 2000; From 44c15792288e3529022b8b2be91556e9fd025218 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Wed, 5 Jan 2022 18:30:53 -0500 Subject: [PATCH 63/78] Add more temp debugging code. Signed-off-by: Gene Johnston --- .../__integration__/enable/__scripts__/daemon_enable.sh | 2 ++ .../enable/cli.daemon.enable.integration.test.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh index 1d3b701ec4..31e7480157 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e +echo "================ TODO: Remove this ===============" +echo PATH = $PATH echo "================ daemon enable ===============" zowe daemon enable if [ $? -gt 0 ] diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index b0c064d282..8ee051c533 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -32,6 +32,8 @@ describe("daemon enable", () => { let pathToBin: string; let preBldTgzPath: string; let isZoweExe: boolean = false; // is the zowe command that we will run an executable? + let zowePgmInPath: string; // TODO: Remove this - make it a const below + let zowePgmStats: any; // TODO: Remove this - make it a const below beforeAll(async () => { // Create the unique test environment @@ -84,11 +86,11 @@ describe("daemon enable", () => { } // Get the zowe program from the PATH that will be used in the test - const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); + zowePgmInPath = which.sync('zowe', { path: testEnvironment.env.PATH }); // We know that our zowe EXE will be bigger than our zowe scripts const maxScriptSize: number = 2000; - const zowePgmStats = fs.statSync(zowePgmInPath); + zowePgmStats = fs.statSync(zowePgmInPath); if (zowePgmStats.size >= maxScriptSize) { isZoweExe = true; } @@ -251,6 +253,7 @@ describe("daemon enable", () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); + expect(zowePgmInPath).toContain("TODO: Remove this"); if (isZoweExe) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); @@ -266,6 +269,7 @@ describe("daemon enable", () => { }); it("should say nothing when ZOWE_USE_DAEMON is unset", async () => { + delete testEnvironment.env.ZOWE_USE_DAEMON; const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); if (isZoweExe) { @@ -287,6 +291,7 @@ describe("daemon enable", () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); + expect(zowePgmStats.size).toEqual(999); // TODO: Remove this if (isZoweExe) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); From cfd636cabeb66778b0b261bec74f2a95e35344b7 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 6 Jan 2022 12:47:05 -0500 Subject: [PATCH 64/78] Different temp debugging code. Signed-off-by: Gene Johnston --- .../__integration__/enable/__scripts__/daemon_enable.sh | 6 ++---- .../enable/__scripts__/daemon_enable_help.sh | 7 +++---- .../enable/cli.daemon.enable.integration.test.ts | 8 ++------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh index 31e7480157..42bab3f906 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh @@ -2,10 +2,8 @@ set -e echo "================ TODO: Remove this ===============" +where zowe echo PATH = $PATH echo "================ daemon enable ===============" zowe daemon enable -if [ $? -gt 0 ] -then - exit $? -fi +exit $? diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh index ed5f173393..5b910dd606 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh @@ -2,10 +2,9 @@ set -e echo "================ TODO: Remove this ===============" +where zowe echo PATH = $PATH echo "================ daemon enable help ===============" zowe daemon enable --help -if [ $? -gt 0 ] -then - exit $? -fi +exit $? + diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 8ee051c533..e5e976c617 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -32,8 +32,6 @@ describe("daemon enable", () => { let pathToBin: string; let preBldTgzPath: string; let isZoweExe: boolean = false; // is the zowe command that we will run an executable? - let zowePgmInPath: string; // TODO: Remove this - make it a const below - let zowePgmStats: any; // TODO: Remove this - make it a const below beforeAll(async () => { // Create the unique test environment @@ -86,11 +84,11 @@ describe("daemon enable", () => { } // Get the zowe program from the PATH that will be used in the test - zowePgmInPath = which.sync('zowe', { path: testEnvironment.env.PATH }); + const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); // We know that our zowe EXE will be bigger than our zowe scripts const maxScriptSize: number = 2000; - zowePgmStats = fs.statSync(zowePgmInPath); + const zowePgmStats = fs.statSync(zowePgmInPath); if (zowePgmStats.size >= maxScriptSize) { isZoweExe = true; } @@ -253,7 +251,6 @@ describe("daemon enable", () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); - expect(zowePgmInPath).toContain("TODO: Remove this"); if (isZoweExe) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); @@ -291,7 +288,6 @@ describe("daemon enable", () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); - expect(zowePgmStats.size).toEqual(999); // TODO: Remove this if (isZoweExe) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); From a0ef7c2bde184ad6a17b357ddad9a936e2bdf111 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 6 Jan 2022 12:51:05 -0500 Subject: [PATCH 65/78] Temp debugging code 5. Signed-off-by: Gene Johnston --- .../daemon/__integration__/enable/__scripts__/daemon_enable.sh | 1 + .../__integration__/enable/__scripts__/daemon_enable_help.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh index 42bab3f906..9306846b11 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh @@ -6,4 +6,5 @@ where zowe echo PATH = $PATH echo "================ daemon enable ===============" zowe daemon enable +echo "====== After zowe command TODO: Remove this =======" exit $? diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh index 5b910dd606..3d30f2ef41 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh @@ -6,5 +6,6 @@ where zowe echo PATH = $PATH echo "================ daemon enable help ===============" zowe daemon enable --help +echo "====== After zowe command TODO: Remove this =======" exit $? From 0b304c34e42ece017e4d290a12209ecbccfc6382 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 6 Jan 2022 14:38:31 -0500 Subject: [PATCH 66/78] Change isZoweExe into a function. Signed-off-by: Gene Johnston --- .../cli.daemon.disable.integration.test.ts | 31 ++++--- .../cli.daemon.enable.integration.test.ts | 88 ++++++++++++------- 2 files changed, 72 insertions(+), 47 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts index fa1b210324..b2ebd4fc12 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts @@ -90,19 +90,24 @@ describe("daemon disable", () => { }); it("should display the help", async () => { - const response = runCliScript(__dirname + "/__scripts__/daemon_disable_help.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("COMMAND NAME"); - expect(stdoutStr).toContain("Disables daemon-mode operation of the Zowe CLI."); - expect(stdoutStr).toContain("USAGE"); - expect(stdoutStr).toContain("zowe daemon disable [options]"); - expect(stdoutStr).toContain("GLOBAL OPTIONS"); - expect(stdoutStr).toContain("--help | -h (boolean)"); - expect(stdoutStr).toContain("EXAMPLES"); - expect(stdoutStr).toContain("Disable daemon-mode:"); - expect(stdoutStr).toContain("$ zowe daemon disable"); - expect(response.stderr.toString()).toBe(""); - expect(response.status).toBe(0); + /* Our EXE will spawn a daemon to get the help. We do not want a daemon as part of this test suite. + * We just want to confirm that our enable help is reasonable. + */ + if (!isZoweExe) { + const response = runCliScript(__dirname + "/__scripts__/daemon_disable_help.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("COMMAND NAME"); + expect(stdoutStr).toContain("Disables daemon-mode operation of the Zowe CLI."); + expect(stdoutStr).toContain("USAGE"); + expect(stdoutStr).toContain("zowe daemon disable [options]"); + expect(stdoutStr).toContain("GLOBAL OPTIONS"); + expect(stdoutStr).toContain("--help | -h (boolean)"); + expect(stdoutStr).toContain("EXAMPLES"); + expect(stdoutStr).toContain("Disable daemon-mode:"); + expect(stdoutStr).toContain("$ zowe daemon disable"); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); + } }); it("should succeed when no EXE exists", async () => { diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index e5e976c617..c2e7c712c9 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -31,7 +31,21 @@ describe("daemon enable", () => { let exePath: string; let pathToBin: string; let preBldTgzPath: string; - let isZoweExe: boolean = false; // is the zowe command that we will run an executable? + + // is the zowe command that we will run an executable? + const isZoweExe = (): boolean => { + // Get the zowe program from the PATH that will be used in the test + const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); + + // We know that our zowe EXE will be bigger than our zowe scripts + const maxScriptSize: number = 2000; + const zowePgmStats = fs.statSync(zowePgmInPath); + if (zowePgmStats.size >= maxScriptSize) { + return true; + } + return false; + }; + beforeAll(async () => { // Create the unique test environment @@ -82,16 +96,6 @@ describe("daemon enable", () => { if (!IO.existsSync(preBldTgzPath)) { fs.copyFileSync(tgzResourcePath, preBldTgzPath); } - - // Get the zowe program from the PATH that will be used in the test - const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); - - // We know that our zowe EXE will be bigger than our zowe scripts - const maxScriptSize: number = 2000; - const zowePgmStats = fs.statSync(zowePgmInPath); - if (zowePgmStats.size >= maxScriptSize) { - isZoweExe = true; - } }); beforeEach(async () => { @@ -104,19 +108,24 @@ describe("daemon enable", () => { }); it("should display the help", async () => { - const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - expect(stdoutStr).toContain("COMMAND NAME"); - expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe CLI."); - expect(stdoutStr).toContain("USAGE"); - expect(stdoutStr).toContain("zowe daemon enable [options]"); - expect(stdoutStr).toContain("GLOBAL OPTIONS"); - expect(stdoutStr).toContain("--help | -h (boolean)"); - expect(stdoutStr).toContain("EXAMPLES"); - expect(stdoutStr).toContain("Enable daemon-mode:"); - expect(stdoutStr).toContain("$ zowe daemon enable"); - expect(response.stderr.toString()).toBe(""); - expect(response.status).toBe(0); + /* Our EXE will spawn a daemon to get the help. We do not want a daemon as part of this test suite. + * We just want to confirm that our enable help is reasonable. + */ + if (!isZoweExe()) { + const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain("COMMAND NAME"); + expect(stdoutStr).toContain("Enables daemon-mode operation of the Zowe CLI."); + expect(stdoutStr).toContain("USAGE"); + expect(stdoutStr).toContain("zowe daemon enable [options]"); + expect(stdoutStr).toContain("GLOBAL OPTIONS"); + expect(stdoutStr).toContain("--help | -h (boolean)"); + expect(stdoutStr).toContain("EXAMPLES"); + expect(stdoutStr).toContain("Enable daemon-mode:"); + expect(stdoutStr).toContain("$ zowe daemon enable"); + expect(response.stderr.toString()).toBe(""); + expect(response.status).toBe(0); + } }); it("should fail when the tgz file does not exist", async () => { @@ -130,7 +139,7 @@ describe("daemon enable", () => { fs.renameSync(tempRenamedTgz, preBldTgzPath); const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -139,13 +148,14 @@ describe("daemon enable", () => { expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); expect(response.status).toBe(1); } + expect(response.stderr.toString()).toBe(""); }); it("should fail if a bin file exists", async () => { fs.writeFileSync(pathToBin, "not a directory"); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -154,12 +164,13 @@ describe("daemon enable", () => { expect(stdoutStr).toContain(`The existing file '${pathToBin}' must be a directory.`); expect(response.status).toBe(1); } + expect(response.stderr.toString()).toBe(""); }); it("should place exe in a new bin dir", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -169,13 +180,14 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); } + expect(response.stderr.toString()).toBe(""); }); it("should place exe in an existing bin dir", async () => { fs.mkdirSync(pathToBin, 0o755); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -185,6 +197,7 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); } + expect(response.stderr.toString()).toBe(""); }); it("should overwite an existing exe", async () => { @@ -193,7 +206,7 @@ describe("daemon enable", () => { fs.writeFileSync(exePath, fakeExeContent); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -206,12 +219,13 @@ describe("daemon enable", () => { expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); expect(response.status).toBe(0); } + expect(response.stderr.toString()).toBe(""); }); it("should identify that bin is not on the PATH", async () => { const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -223,16 +237,18 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); } + expect(response.stderr.toString()).toBe(""); }); it("should say nothing when bin is already on the PATH", async () => { const pathOrig = testEnvironment.env["PATH"]; testEnvironment.env["PATH"] = pathToBin + nodeJsPath.delimiter + testEnvironment.env["PATH"]; + const weRanOurExe = isZoweExe(); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); testEnvironment.env["PATH"] = pathOrig; const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (weRanOurExe) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -243,6 +259,7 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); } + expect(response.stderr.toString()).toBe(""); }); it("should identify that ZOWE_USE_DAEMON is set to 'no'", async () => { @@ -251,7 +268,7 @@ describe("daemon enable", () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -263,13 +280,14 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); } + expect(response.stderr.toString()).toBe(""); }); it("should say nothing when ZOWE_USE_DAEMON is unset", async () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -280,6 +298,7 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); } + expect(response.stderr.toString()).toBe(""); }); it("should say nothing when ZOWE_USE_DAEMON is set to 'yes'", async () => { @@ -288,7 +307,7 @@ describe("daemon enable", () => { delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); - if (isZoweExe) { + if (isZoweExe()) { expect(stdoutStr).toContain(exeCantRunDaemonMsg1); expect(stdoutStr).toContain(exeCantRunDaemonMsg2); expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); @@ -298,5 +317,6 @@ describe("daemon enable", () => { expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); } + expect(response.stderr.toString()).toBe(""); }); }); From 9a152927c804eea32c7de397edf097f6264356d8 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 6 Jan 2022 16:20:10 -0500 Subject: [PATCH 67/78] execSync to spawnSync for SonarCube security Signed-off-by: Gene Johnston --- __mocks__/child_process.ts | 34 ++++++++++++++++--- .../enable/__scripts__/daemon_enable.sh | 1 - .../enable/__scripts__/daemon_enable_help.sh | 1 - .../enable/Enable.handler.unit.test.ts | 4 +-- .../cli/src/daemon/enable/Enable.handler.ts | 19 +++++++---- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/__mocks__/child_process.ts b/__mocks__/child_process.ts index 55dd2c071c..c1234bdf79 100644 --- a/__mocks__/child_process.ts +++ b/__mocks__/child_process.ts @@ -13,25 +13,49 @@ const child_process: any = jest.genMockFromModule("child_process"); -let execSyncOutout: string = "ExecSyncNeverSet"; +const useRealFunction: string = "useRealFunction"; +let execSyncOutput: string = useRealFunction; +const spawnSyncOutput = { + "stdout": useRealFunction +}; -// tests can set their our output valu for execSync +// tests can set their own output value for execSync function setExecSyncOutput(outputVal: string) { - execSyncOutout = outputVal; + execSyncOutput = outputVal; } +// tests can set their own output value for spawnSync +function setSpawnSyncOutput(outputVal: string) { + spawnSyncOutput.stdout = outputVal; +} // Mock function to use for child_process.execSync function execSyncMock(cmd: string, options: Object) { - if (execSyncOutout === "ExecSyncNeverSet") { + if (execSyncOutput === useRealFunction) { // run the real execSync const execSyncReal = require.requireActual("child_process").execSync; return execSyncReal(cmd, options); } else { // return the output that the test set with setExecSyncOutput(). - return execSyncOutout; + return execSyncOutput; + } +} + +// Mock function to use for child_process.spawnSync +function spawnSyncMock(cmd: string, args: [string], options: Object) { + if (spawnSyncOutput.stdout === useRealFunction) { + // run the real spawnSync + const spawnSyncReal = require.requireActual("child_process").spawnSync; + return spawnSyncReal(cmd, args, options); + } else { + // return the output that the test set with setSpawnSyncOutput(). + return spawnSyncOutput; } } child_process.setExecSyncOutput = setExecSyncOutput; child_process.execSync = execSyncMock; + +child_process.setSpawnSyncOutput = setSpawnSyncOutput; +child_process.spawnSync = spawnSyncMock; + module.exports = child_process; \ No newline at end of file diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh index 9306846b11..d9ab9a74a3 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh @@ -2,7 +2,6 @@ set -e echo "================ TODO: Remove this ===============" -where zowe echo PATH = $PATH echo "================ daemon enable ===============" zowe daemon enable diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh index 3d30f2ef41..fc3e07c965 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh @@ -2,7 +2,6 @@ set -e echo "================ TODO: Remove this ===============" -where zowe echo PATH = $PATH echo "================ daemon enable help ===============" zowe daemon enable --help diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 8f2368779c..973c4ba6d1 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -289,7 +289,7 @@ describe("Handler for daemon enable", () => { expect(unzipTgzSpy).toHaveBeenCalledTimes(1); // we set a bogus cliHome, so we know it cannot launch the executable - expect(userInfoMsg).toContain("Zowe CLI native executable version = Command failed:"); + expect(userInfoMsg).toContain("Zowe CLI native executable version = Failed to get version number"); IO.existsSync = existsSyncOrig; IO.isDir = isDirOrig; @@ -313,7 +313,7 @@ describe("Handler for daemon enable", () => { // This uses child_process from the __mocks__ directory const exeVerNumMock = "9.9.9"; - require("child_process").setExecSyncOutput(exeVerNumMock); + require("child_process").setSpawnSyncOutput(exeVerNumMock); // spy on our handler's private enableDaemon() function unzipTgzSpy = jest.spyOn(EnableDaemonHandler.prototype as any, "unzipTgz"); diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index 2741ba2573..53ac4ee241 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -12,7 +12,7 @@ import * as fs from "fs"; import * as nodeJsPath from "path"; import * as tar from "tar"; -import { execSync, StdioOptions } from "child_process"; +import { spawnSync, StdioOptions } from "child_process"; import { CliUtils, ICommandHandler, IHandlerParameters, ImperativeConfig, ImperativeError, @@ -63,6 +63,7 @@ export default class EnableDaemonHandler implements ICommandHandler { // form the path to our prebuilds tar file let preBldTgz = __dirname + "../../../../prebuilds/zowe-"; + let exeFileName = "zowe"; switch (sysInfo.platform) { case "darwin": { preBldTgz += "macos.tgz"; @@ -74,6 +75,7 @@ export default class EnableDaemonHandler implements ICommandHandler { } case "win32": { preBldTgz += "windows.tgz"; + exeFileName += ".exe"; break; } default: { @@ -125,14 +127,19 @@ export default class EnableDaemonHandler implements ICommandHandler { // display the version of the executable let userInfoMsg: string = "Zowe CLI native executable version = "; - const zoweExePath = nodeJsPath.resolve(zoweHomeBin, "zowe"); + const zoweExePath = nodeJsPath.resolve(zoweHomeBin, exeFileName); const pipe: StdioOptions = ["pipe", "pipe", process.stderr]; try { - const execOutput = execSync(`"${zoweExePath}" --version-exe`, { - stdio: pipe + const spawnResult = spawnSync(zoweExePath, ["--version-exe"], { + stdio: pipe, + shell: false }); - // remove any newlines from the version number - userInfoMsg += execOutput.toString().replace(/\r?\n|\r/g, ""); + if (spawnResult.stdout) { + // remove any newlines from the version number + userInfoMsg += spawnResult.stdout.toString().replace(/\r?\n|\r/g, ""); + } else { + userInfoMsg += "Failed to get version number"; + } } catch (err) { userInfoMsg += err.message; } From cc61a1ecdc9f671dc13d8b0f38fcb0b6cf3f1956 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Thu, 6 Jan 2022 18:12:32 -0500 Subject: [PATCH 68/78] Add temp debugging code 6. Signed-off-by: Gene Johnston --- .../enable/cli.daemon.enable.integration.test.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index c2e7c712c9..baa0329a33 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -241,11 +241,13 @@ describe("daemon enable", () => { }); it("should say nothing when bin is already on the PATH", async () => { + /* TODO: Remove comment const pathOrig = testEnvironment.env["PATH"]; testEnvironment.env["PATH"] = pathToBin + nodeJsPath.delimiter + testEnvironment.env["PATH"]; + */ const weRanOurExe = isZoweExe(); const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - testEnvironment.env["PATH"] = pathOrig; + // TODO: Remove comment: testEnvironment.env["PATH"] = pathOrig; const stdoutStr = response.stdout.toString(); if (weRanOurExe) { @@ -263,9 +265,9 @@ describe("daemon enable", () => { }); it("should identify that ZOWE_USE_DAEMON is set to 'no'", async () => { - testEnvironment.env["ZOWE_USE_DAEMON"] = "no"; + // TODO: Remove comment: testEnvironment.env["ZOWE_USE_DAEMON"] = "no"; const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - delete testEnvironment.env.ZOWE_USE_DAEMON; + // TODO: Remove comment: delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); if (isZoweExe()) { @@ -302,9 +304,9 @@ describe("daemon enable", () => { }); it("should say nothing when ZOWE_USE_DAEMON is set to 'yes'", async () => { - testEnvironment.env["ZOWE_USE_DAEMON"] = "yes"; + // TODO: Remove comment: testEnvironment.env["ZOWE_USE_DAEMON"] = "yes"; const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - delete testEnvironment.env.ZOWE_USE_DAEMON; + // TODO: Remove comment: delete testEnvironment.env.ZOWE_USE_DAEMON; const stdoutStr = response.stdout.toString(); if (isZoweExe()) { From 1a02ef57021ad158a2094896d4f4b4740e2c3649 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 7 Jan 2022 10:59:46 -0500 Subject: [PATCH 69/78] Move all EXE tests into the EXE test suite. Signed-off-by: Gene Johnston --- .../cli.zowe.exe.integration.test.ts | 36 +++- .../disable/__scripts__/daemon_disable.sh | 5 +- .../__scripts__/daemon_disable_help.sh | 5 +- .../cli.daemon.disable.integration.test.ts | 31 ++- .../enable/__scripts__/daemon_enable.sh | 3 - .../enable/__scripts__/daemon_enable_help.sh | 3 - .../cli.daemon.enable.integration.test.ts | 178 +++++++----------- 7 files changed, 114 insertions(+), 147 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts index a20b5f6106..314a679bf3 100644 --- a/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/cli.zowe.exe.integration.test.ts @@ -20,8 +20,12 @@ import { TestEnvironment } from "../../../../../__tests__/__src__/environment/Te let testEnvironment: ITestEnvironment; describe("Zowe native executable", () => { + const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe CLI native executable."; + const exeCantRunDaemonMsg2: string = "Copy and paste the following command instead:"; + const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 107; + let zoweExePath: string; - let canTestExe: boolean = true; + let willRunZoweExe: boolean = true; beforeAll(async () => { // Create the unique test environment @@ -45,14 +49,14 @@ describe("Zowe native executable", () => { if (!IO.existsSync(zoweExePath)) { zoweExePath = nodeJsPath.normalize(zoweExeGrandParentDir + "/debug/zowe" + exeExt); if (!IO.existsSync(zoweExePath)) { - canTestExe = false; + willRunZoweExe = false; zoweExePath = "./NoZoweExeExists"; } } }); it("should display its version number", async () => { - if (canTestExe) { + if (willRunZoweExe) { const response = runCliScript( __dirname + "/__scripts__/run_zowe_exe.sh", testEnvironment, [zoweExePath, "--version-exe"] @@ -62,4 +66,30 @@ describe("Zowe native executable", () => { expect(response.status).toBe(0); } }); + + it("should refuse to run the enable command", async () => { + if (willRunZoweExe) { + const response = runCliScript( + __dirname + "/__scripts__/run_zowe_exe.sh", testEnvironment, + [zoweExePath, "daemon", "enable"] + ); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } + }); + + it("should refuse to run the disable command", async () => { + if (willRunZoweExe) { + const response = runCliScript( + __dirname + "/__scripts__/run_zowe_exe.sh", testEnvironment, + [zoweExePath, "daemon", "disable"] + ); + const stdoutStr = response.stdout.toString(); + expect(stdoutStr).toContain(exeCantRunDaemonMsg1); + expect(stdoutStr).toContain(exeCantRunDaemonMsg2); + expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); + } + }); }); diff --git a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh index c46d4fc560..ace9d61e2d 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh +++ b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh @@ -3,7 +3,4 @@ set -e echo "================ daemon enable ===============" zowe daemon disable -if [ $? -gt 0 ] -then - exit $? -fi +exit $? diff --git a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh index 3531cbed84..dc0345feed 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh +++ b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh @@ -3,7 +3,4 @@ set -e echo "================ daemon enable help ===============" zowe daemon disable --help -if [ $? -gt 0 ] -then - exit $? -fi +exit $? diff --git a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts index b2ebd4fc12..722ecc175d 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/disable/cli.daemon.disable.integration.test.ts @@ -26,13 +26,10 @@ let testEnvironment: ITestEnvironment; describe("daemon disable", () => { const rimraf = require("rimraf").sync; const fakeExeContent = "This is not a real executable"; - const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe CLI native executable."; - const exeCantRunDaemonMsg2: string = "Copy and paste the following command instead:"; - const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 107; let exePath: string; let pathToBin: string; - let isZoweExe: boolean = false; // is the zowe command that we will run an executable? + let willRunNodeJsZowe: boolean = true; // is the zowe command that we will run our Node.js script? beforeAll(async () => { // Create the unique test environment @@ -81,7 +78,7 @@ describe("daemon disable", () => { const maxScriptSize: number = 2000; const zowePgmStats = fs.statSync(zowePgmInPath); if (zowePgmStats.size >= maxScriptSize) { - isZoweExe = true; + willRunNodeJsZowe = false; } }); @@ -93,7 +90,7 @@ describe("daemon disable", () => { /* Our EXE will spawn a daemon to get the help. We do not want a daemon as part of this test suite. * We just want to confirm that our enable help is reasonable. */ - if (!isZoweExe) { + if (willRunNodeJsZowe) { const response = runCliScript(__dirname + "/__scripts__/daemon_disable_help.sh", testEnvironment); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("COMMAND NAME"); @@ -111,23 +108,19 @@ describe("daemon disable", () => { }); it("should succeed when no EXE exists", async () => { - if (IO.existsSync(pathToBin)) { - rimraf(pathToBin); - } - const response = runCliScript(__dirname + "/__scripts__/daemon_disable.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - if (isZoweExe) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe) { + if (IO.existsSync(pathToBin)) { + rimraf(pathToBin); + } + const response = runCliScript(__dirname + "/__scripts__/daemon_disable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode is disabled."); expect(response.status).toBe(0); } }); it("should delete an existing EXE", async () => { - if (!isZoweExe) { + if (willRunNodeJsZowe) { if (!IO.existsSync(pathToBin)) { IO.createDirSync(pathToBin); } @@ -143,7 +136,7 @@ describe("daemon disable", () => { }); it("should succeed when no daemon is running", async () => { - if (!isZoweExe) { + if (willRunNodeJsZowe) { // find any running daemon const findProc = require('find-process'); const procArray = await findProc('name', 'node', true); @@ -165,7 +158,7 @@ describe("daemon disable", () => { }); it("should stop a running zowe daemon", async () => { - if (!isZoweExe) { + if (willRunNodeJsZowe) { // start a daemon exec("zowe --daemon"); diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh index d9ab9a74a3..839aaea684 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable.sh @@ -1,9 +1,6 @@ #!/bin/bash set -e -echo "================ TODO: Remove this ===============" -echo PATH = $PATH echo "================ daemon enable ===============" zowe daemon enable -echo "====== After zowe command TODO: Remove this =======" exit $? diff --git a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh index fc3e07c965..a56e202a62 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh +++ b/packages/cli/__tests__/daemon/__integration__/enable/__scripts__/daemon_enable_help.sh @@ -1,10 +1,7 @@ #!/bin/bash set -e -echo "================ TODO: Remove this ===============" -echo PATH = $PATH echo "================ daemon enable help ===============" zowe daemon enable --help -echo "====== After zowe command TODO: Remove this =======" exit $? diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index baa0329a33..636a181307 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -24,16 +24,14 @@ let testEnvironment: ITestEnvironment; describe("daemon enable", () => { const rimraf = require("rimraf").sync; const fakeExeContent = "This is not a real executable"; - const exeCantRunDaemonMsg1: string = "You cannot run this 'daemon' command while using the Zowe CLI native executable."; - const exeCantRunDaemonMsg2: string = "Copy and paste the following command instead:"; const EXIT_CODE_CANT_RUN_DAEMON_CMD: number = 107; let exePath: string; let pathToBin: string; let preBldTgzPath: string; - // is the zowe command that we will run an executable? - const isZoweExe = (): boolean => { + // is the zowe command that we will run our Node.js script? + const willRunNodeJsZowe = (): boolean => { // Get the zowe program from the PATH that will be used in the test const zowePgmInPath: string = which.sync('zowe', { path: testEnvironment.env.PATH }); @@ -41,9 +39,9 @@ describe("daemon enable", () => { const maxScriptSize: number = 2000; const zowePgmStats = fs.statSync(zowePgmInPath); if (zowePgmStats.size >= maxScriptSize) { - return true; + return false; } - return false; + return true; }; @@ -111,7 +109,7 @@ describe("daemon enable", () => { /* Our EXE will spawn a daemon to get the help. We do not want a daemon as part of this test suite. * We just want to confirm that our enable help is reasonable. */ - if (!isZoweExe()) { + if (willRunNodeJsZowe()) { const response = runCliScript(__dirname + "/__scripts__/daemon_enable_help.sh", testEnvironment); const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("COMMAND NAME"); @@ -129,88 +127,69 @@ describe("daemon enable", () => { }); it("should fail when the tgz file does not exist", async () => { - // temporarily remove the desired tgz file - keep an eye open for impact on parallel tests - const tempRenamedTgz = preBldTgzPath + "_temp_rename"; - fs.renameSync(preBldTgzPath, tempRenamedTgz); + if (willRunNodeJsZowe()) { + // temporarily remove the desired tgz file - keep an eye open for impact on parallel tests + const tempRenamedTgz = preBldTgzPath + "_temp_rename"; + fs.renameSync(preBldTgzPath, tempRenamedTgz); - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - // restore our tgz file for other tests - fs.renameSync(tempRenamedTgz, preBldTgzPath); + // restore our tgz file for other tests + fs.renameSync(tempRenamedTgz, preBldTgzPath); - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); expect(response.status).toBe(1); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should fail if a bin file exists", async () => { - fs.writeFileSync(pathToBin, "not a directory"); - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + fs.writeFileSync(pathToBin, "not a directory"); + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); expect(stdoutStr).toContain(`The existing file '${pathToBin}' must be a directory.`); expect(response.status).toBe(1); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should place exe in a new bin dir", async () => { - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should place exe in an existing bin dir", async () => { - fs.mkdirSync(pathToBin, 0o755); - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + fs.mkdirSync(pathToBin, 0o755); + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should overwite an existing exe", async () => { - const fakeExeContent = "This is not a real executable"; - fs.mkdirSync(pathToBin, 0o755); - fs.writeFileSync(exePath, fakeExeContent); - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + const fakeExeContent = "This is not a real executable"; + fs.mkdirSync(pathToBin, 0o755); + fs.writeFileSync(exePath, fakeExeContent); + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(IO.existsSync(exePath)).toBe(true); @@ -218,107 +197,84 @@ describe("daemon enable", () => { const exeStats = fs.statSync(exePath); expect(exeStats.size).toBeGreaterThan(fakeExeContent.length + 10); expect(response.status).toBe(0); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should identify that bin is not on the PATH", async () => { - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).toContain(`Add '${pathToBin}' to your PATH`); expect(stdoutStr).toContain("Otherwise, you will continue to run the classic Zowe CLI interpreter"); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should say nothing when bin is already on the PATH", async () => { - /* TODO: Remove comment - const pathOrig = testEnvironment.env["PATH"]; - testEnvironment.env["PATH"] = pathToBin + nodeJsPath.delimiter + testEnvironment.env["PATH"]; - */ - const weRanOurExe = isZoweExe(); - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - // TODO: Remove comment: testEnvironment.env["PATH"] = pathOrig; - - const stdoutStr = response.stdout.toString(); - if (weRanOurExe) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + const pathOrig = testEnvironment.env["PATH"]; + testEnvironment.env["PATH"] = pathToBin + nodeJsPath.delimiter + testEnvironment.env["PATH"]; + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + testEnvironment.env["PATH"] = pathOrig; + + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your PATH`); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should identify that ZOWE_USE_DAEMON is set to 'no'", async () => { - // TODO: Remove comment: testEnvironment.env["ZOWE_USE_DAEMON"] = "no"; - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - // TODO: Remove comment: delete testEnvironment.env.ZOWE_USE_DAEMON; - - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + testEnvironment.env["ZOWE_USE_DAEMON"] = "no"; + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + delete testEnvironment.env.ZOWE_USE_DAEMON; + + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).toContain("Zowe CLI native executable version ="); expect(stdoutStr).toContain("Your ZOWE_USE_DAEMON environment variable is set to 'no'"); expect(stdoutStr).toContain("You must remove it, or set it to 'yes' to use daemon mode"); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should say nothing when ZOWE_USE_DAEMON is unset", async () => { - delete testEnvironment.env.ZOWE_USE_DAEMON; - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + delete testEnvironment.env.ZOWE_USE_DAEMON; + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(testEnvironment.env["ZOWE_USE_DAEMON"]).toBeFalsy(); expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); it("should say nothing when ZOWE_USE_DAEMON is set to 'yes'", async () => { - // TODO: Remove comment: testEnvironment.env["ZOWE_USE_DAEMON"] = "yes"; - const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); - // TODO: Remove comment: delete testEnvironment.env.ZOWE_USE_DAEMON; - - const stdoutStr = response.stdout.toString(); - if (isZoweExe()) { - expect(stdoutStr).toContain(exeCantRunDaemonMsg1); - expect(stdoutStr).toContain(exeCantRunDaemonMsg2); - expect(response.status).toBe(EXIT_CODE_CANT_RUN_DAEMON_CMD); - } else { + if (willRunNodeJsZowe()) { + testEnvironment.env["ZOWE_USE_DAEMON"] = "yes"; + const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment); + delete testEnvironment.env.ZOWE_USE_DAEMON; + + const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Zowe CLI daemon mode enabled"); expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to"); expect(IO.existsSync(exePath)).toBe(true); expect(response.status).toBe(0); + expect(response.stderr.toString()).toBe(""); } - expect(response.stderr.toString()).toBe(""); }); }); From 407bb4ca157c9d3a0b5e0c2d4a7e43383b9f36e6 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 7 Jan 2022 13:51:06 -0500 Subject: [PATCH 70/78] Updated zowex/design.md with latest behavior. Signed-off-by: Gene Johnston --- zowex/design.md | 85 +++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/zowex/design.md b/zowex/design.md index 738dc31f31..2c8e1094c0 100644 --- a/zowex/design.md +++ b/zowex/design.md @@ -1,50 +1,70 @@ # Daemon Mode Design Overview -Zowe CLI start up time can be slow: 3 - 15 seconds. This often occurs in virtualized environments where the directories, into which the Zowe CLI is installed, are geographically remote from the server that hosts the virtualized environments. Part of the reason this operation can be slow is the overhead involved in the startup of the Node.js runtime (measured with V8 instrumentations). The Node.js modules used by the Zowe CLI must be loaded every time a user issues another zowe command. The module loading process can be time consuming due to the delays associated with network transfers over a large geographic distance. +Zowe CLI start-up time can be slow: 3 - 15 seconds. This often occurs in virtualized environments where the directories, into which the Zowe CLI is installed, are geographically remote from the server that hosts the virtualized environments. Part of the reason this operation can be slow is the overhead involved in the startup of the Node.js runtime (measured with V8 instrumentations). The Node.js modules used by the Zowe CLI must be loaded every time a user issues another zowe command. The module loading process can be time consuming due to the delays associated with network transfers over a large geographic distance. -A customer site can address this situation by installing Zowe CLI onto a disk that is located in the same geographic location as the site's server of virtual environments. Pointing the ZOWE_CLI_HOME directory to a disk drive co-located with the server will also help. +A customer site can address this situation by installing Zowe CLI onto a disk that is located in the same geographic location as the site's server of virtual environments. Pointing the ZOWE_CLI_HOME directory to a disk drive that is also co-located with the server will also help. When the Zowe CLI user community at a given customer site does not have the adminstrative privileges to control where the Zowe CLI is installed, an alternative approach is to use the Zowe-CLI daemon to significantly improve performance. ## Solution Overview -We can run Zowe CLI as a persistent process “daemon” to have a one-time startup of the Node.js cost and have a native-built, Rust client to communicate with the daemon via TCP/IP sockets. +The Zowe CLI can run as a persistent “daemon” process to absorb the one-time startup of Node.js modules. A native executable client will then communicate with the daemon via TCP/IP sockets. -Root level help, `zowe --help` response time is reduced from ~3 seconds to just under ` second in daemon mode. +Root level help, `zowe --help` response time is reduced from ~3 seconds to just under 1 second in daemon mode. At a site with a remote virtualized environment, the response time can change from around 30 seconds to around 2 seconds. In testing a solution, the root command tree takes longer to execute than lower level command tree items, e.g. `zowe -h` is observably slower than `zowe jobs list -h` which has near instantaneous response time -### Rust Client +## Native executable Client -Native Rust client calls Zowe CLI persistent process (daemon). An env var can be set for the port to connect to tcp socket. `ZOWE_DAEMON=` environmental variable used or default `4000`. +Our native executable client communicates with the Zowe CLI persistent process (daemon) over a TCP/IP socket. An environment variable can set the TCP/IP port for the daemon. The environment variable named `ZOWE_DAEMON=` is used for the port. If that variable is unset, the default is `4000`. -Rust binderies are released on GitHub and could also be released on scoop, cargo, chocolatey, windows command installer, etc... +## Enabling daemon-mode -Rust client sets `--daemon-client-directory` (or `--dcd`) for Zowe CLI / imperative usage which is the daemon client directory. This flag is hidden from Zowe help display -since it's not intended for end users. +Executables for all supported operating systems are included in the Zowe CLI NPM package. To make use of daemon mode, you must run the command `zowe daemon enable`. That command will copy the correct 'zowe' executable for your operating system into your $ZOWE_CLI_HOME/bin directory. You will be instructed to place the $ZOWE_CLI_HOME/bin directory on your PATH ahead of the directory into which NPM installed the Node.js 'zowe' script. After that, each 'zowe' command that you run will run the native executable. -Rust client is called `zowe.exe`. +When you run your next 'zowe' command, the executable will automatically launch the daemon in the background and it then sends your desired command to the daemon for processing. Your first such command will be slow, because the daemon process must be started. All future 'zowe' commands will then be much faster. -Imperative is updated in several places to write to a stream in addition to / instead of stdout & stderr. Stream is passed in yargs "context" which is our own user data. +The daemon will continue to run until you close your comamnd-line terminal window. If you logout and login to your computer each day, your first 'zowe' command in your terminal window will automatically start the daemon. -`--dcd` hidden, global flag added for Zowe CLI operations that implicitly depend on the current working directory. For example, Zowe CLI daemon could be running at any arbitrary location on the system; however, we want `zowe` to operate against whatever directory it was run. `--dcd` allows for alternate `dcd`. + + Example: + + ```text + zowe --version + Starting a background process to increase performance ... + 7.0.0-next.202111111904 + + zowe --version + 7.0.0-next.202111111904 + ``` + + +## Disabling daemon-mode + +If you want to stop using daemon mode, you can issue the `zowe daemon disable` command. That command will remove the zowe executable from your $ZOWE_CLI_HOME/bin directory and it will stop any running Zowe daemon. + +## Implementation Details + +The Zowe executable is written in the Rust programming language. + +Imperative is updated in several places to write to a stream in addition to / instead of stdout & stderr. A stream is passed in yargs "context" which is our own user data. ### Zowe CLI Server -Zowe CLI is updated to launch a server if an undocumented `--daemon` parm is detected. The server is a simple tcpip server. +The Node.js zowe script is updated to launch a server when an undocumented `--daemon` parm is supplied. The server is a simple tcpip server. -- server startup is managed by `packages/cli/Processor.ts` -- daemon communication is managed by `packages/cli/DaemonClient.ts` +- Server startup is managed by `packages/cli/src/daemon/DaemonDecider.ts` +- Daemon communication is managed by `packages/cli/src/daemon/DaemonClient.ts` ### Protocol At a high level: -1. Zowe CLI server is started via `zowe --daemon` manually or via native `zowe` client -2. `zowe` native client calls pass zowe commands to the server via tcp -3. zowe server responds with text data from command output as it normally would, but response is directed towards socket connection instead of to console +1. Zowe CLI server is started automatically by the native `zowe` executable client. It can also be started manually by running the Node.js Zowe script as `YourPathtoNodeJsScript/zowe --daemon`, although this is not the reccommended approach due to its greater complexity. +2. The `zowe` native executable client passes zowe commands to the server via TCP/IP. +3. The Zowe daemon responds with text data from command output as it normally would, but the response is directed onto its socket connection instead of to a console window. -However, Zowe CLI also has features like: +Since the Zowe CLI has features like: - progress bars - writing to stderr @@ -52,13 +72,13 @@ However, Zowe CLI also has features like: - exiting process with non-zero - writing output to stdout & stderr -So, we use a JSON object to describe communication between both server and client. +we use a JSON object to describe communication between both server and client. -`IDaemonRequest.ts` & `IDaemonResponse.ts` in the imperative repo describe some of rules and keyword / value parts for data sent between server and client. +`IDaemonRequest.ts` & `IDaemonResponse.ts` in the imperative repo describe some of rules and keyword / value parts for data sent between the server and client. #### Examples -The daemon server may send sample messages to daemon client like: +The daemon server may send sample messages to the daemon client like: ``` "{\"stdout\":\"ca11 (default) \\nca112\\ntest\\ntso1\\n\"}" "{\"stderr\":\"\\nWarning: The command 'profiles list' is deprecated.\\n\"} @@ -71,26 +91,7 @@ Or: {"prompt":"Enter the host name of your service: "} ``` -The daemon client sends messages to server like: +The daemon client sends messages to the daemon server like: ``` {"reply":"zosmf.com\r\n","id":"daemon-client"} ``` -### Testing - -- Obtain zowe.exe binary for your platform and place it into a directory that is earlier in your PATH than the directory which contains the NodeJS zowe scripts (like zowe.cmd). - -- Run any zowe command as you normally would. - - The first time you run any zowe command, the command will automatically start a daemon in the background. It will then run your desired command. Since that first command must start the daemon, that first zowe command will actually run slower than a traditional zowe command. However, every zowe command afterward will run significantly faster. The daemon will continue to run in the background until you close your terminal window. - - Example: - - ```text - zowe --version - Starting a background process to increase performance ... - 7.0.0-next.202111111904 - - zowe --version - 7.0.0-next.202111111904 - ``` - From 6f31e793267ac3f466becd0bbcbd12a07b6be295 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Fri, 7 Jan 2022 16:57:40 -0500 Subject: [PATCH 71/78] Remove zowex reference in doc link. Signed-off-by: Gene Johnston --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index abe4e9c1e4..3c853cd910 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ To try out early access features, install the "next" release of Zowe CLI (`npm i For documentation about these features, see these files: - [Using Global Profile Configuration](https://github.com/zowe/zowe-cli/blob/next/docs/Early%20Access%20-%20Using%20Global%20Profile%20Configuration.md) -- [Using Daemon Mode with "zowex"](https://github.com/zowe/zowe-cli/blob/next/zowex/design.md) +- [Daemon Mode Design Overview](https://github.com/zowe/zowe-cli/blob/next/zowex/design.md) ## Documentation From 25c9a63fa7b557d5bcb6b49563c13fa41e9941b0 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Mon, 10 Jan 2022 16:44:08 -0500 Subject: [PATCH 72/78] Use version of imperative that fixes colors hack. Signed-off-by: Gene Johnston --- .../__packages__/cli-test-utils/package.json | 2 +- package-lock.json | 240 +++++++++--------- package.json | 6 +- packages/cli/package.json | 2 +- packages/core/package.json | 2 +- packages/provisioning/package.json | 2 +- packages/workflows/package.json | 2 +- packages/zosconsole/package.json | 2 +- packages/zosfiles/package.json | 2 +- packages/zosjobs/package.json | 2 +- packages/zoslogs/package.json | 2 +- packages/zosmf/package.json | 2 +- packages/zostso/package.json | 2 +- packages/zosuss/package.json | 2 +- 14 files changed, 133 insertions(+), 137 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/package.json b/__tests__/__packages__/cli-test-utils/package.json index e51651f924..3b36e10a0b 100644 --- a/__tests__/__packages__/cli-test-utils/package.json +++ b/__tests__/__packages__/cli-test-utils/package.json @@ -43,7 +43,7 @@ }, "devDependencies": { "@types/node": "^14.14.37", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "rimraf": "^3.0.2", "typescript": "^4.2.3" diff --git a/package-lock.json b/package-lock.json index 95c8ec580b..da5d4e1d39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "__tests__/__packages__/*" ], "dependencies": { - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/perf-timing": "1.0.7" }, "devDependencies": { @@ -76,7 +76,7 @@ }, "devDependencies": { "@types/node": "^14.14.37", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "rimraf": "^3.0.2", "typescript": "^4.2.3" @@ -4971,16 +4971,16 @@ "link": true }, "node_modules/@zowe/imperative": { - "version": "5.0.0-next.202112221912", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.0.0-next.202112221912.tgz", - "integrity": "sha1-BcJYWXQnLPhMCkBGk7rr/7qlnAw=", + "version": "5.0.0-next.202201102100", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.0.0-next.202201102100.tgz", + "integrity": "sha1-1UiNDTnv4jJxUtld9fEKhIz/ejM=", "license": "EPL-2.0", "dependencies": { "@types/lodash-deep": "2.0.0", "@types/yargs": "13.0.4", "@zowe/perf-timing": "1.0.7", "chalk": "2.4.2", - "cli-table3": "0.6.0", + "cli-table3": "0.6.1", "comment-json": "4.1.0", "dataobject-parser": "1.2.1", "deepmerge": "4.2.2", @@ -4996,13 +4996,13 @@ "lodash": "4.17.21", "lodash-deep": "2.0.0", "log4js": "6.3.0", - "markdown-it": "12.0.4", + "markdown-it": "12.3.2", "moment": "2.20.1", "mustache": "2.3.0", "npm-package-arg": "8.1.1", "opener": "1.5.2", "pacote": "11.1.4", - "prettyjson": "1.2.1", + "prettyjson": "1.2.2", "progress": "2.0.3", "read": "1.0.7", "readline-sync": "1.4.10", @@ -5030,6 +5030,11 @@ "node": ">=4" } }, + "node_modules/@zowe/imperative/node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, "node_modules/@zowe/imperative/node_modules/chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -5043,6 +5048,20 @@ "node": ">=4" } }, + "node_modules/@zowe/imperative/node_modules/cli-table3": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.1.tgz", + "integrity": "sha512-w0q/enDHhPLq44ovMGdQeeDLvwxwavsJX7oQGYt/LrBlYsyaxyDnp6z3QzFut/6kLLKnlcUVJLrpB7KBfgG/RA==", + "dependencies": { + "string-width": "^4.2.0" + }, + "engines": { + "node": "10.* || >= 12.*" + }, + "optionalDependencies": { + "colors": "1.4.0" + } + }, "node_modules/@zowe/imperative/node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -5091,6 +5110,33 @@ "node": ">=4" } }, + "node_modules/@zowe/imperative/node_modules/markdown-it": { + "version": "12.3.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", + "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==", + "dependencies": { + "argparse": "^2.0.1", + "entities": "~2.1.0", + "linkify-it": "^3.0.1", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + }, + "bin": { + "markdown-it": "bin/markdown-it.js" + } + }, + "node_modules/@zowe/imperative/node_modules/prettyjson": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/prettyjson/-/prettyjson-1.2.2.tgz", + "integrity": "sha512-hDso231aQslRQPJjuSMIyUTN5CmW78AwEHlvigOs9E9IO+blW1AJTCJC6pQ8FArBSFsp5ZUdZsWXCUfXiD2D0w==", + "dependencies": { + "colors": "1.4.0", + "minimist": "^1.2.0" + }, + "bin": { + "prettyjson": "bin/prettyjson" + } + }, "node_modules/@zowe/imperative/node_modules/rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", @@ -6790,21 +6836,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/cli-table3": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.0.tgz", - "integrity": "sha512-gnB85c3MGC7Nm9I/FkiasNBOKjOiO1RNuXXarQms37q4QMpWdlbBgD/VnOStA2faG1dpXMv31RFApjX1/QdgWQ==", - "dependencies": { - "object-assign": "^4.1.0", - "string-width": "^4.2.0" - }, - "engines": { - "node": "10.* || >= 12.*" - }, - "optionalDependencies": { - "colors": "^1.1.2" - } - }, "node_modules/cli-width": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.1.tgz", @@ -16788,26 +16819,6 @@ "node": ">=0.10.0" } }, - "node_modules/markdown-it": { - "version": "12.0.4", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.0.4.tgz", - "integrity": "sha512-34RwOXZT8kyuOJy25oJNJoulO8L0bTHYWXcdZBYZqFnjIy3NgjeoM3FmPXIOFQ26/lSHYMr8oc62B6adxXcb3Q==", - "dependencies": { - "argparse": "^2.0.1", - "entities": "~2.1.0", - "linkify-it": "^3.0.1", - "mdurl": "^1.0.1", - "uc.micro": "^1.0.5" - }, - "bin": { - "markdown-it": "bin/markdown-it.js" - } - }, - "node_modules/markdown-it/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" - }, "node_modules/marked": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/marked/-/marked-0.8.2.tgz", @@ -20058,18 +20069,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/prettyjson": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/prettyjson/-/prettyjson-1.2.1.tgz", - "integrity": "sha1-/P+rQdGcq0365eV15kJGYZsS0ok=", - "dependencies": { - "colors": "^1.1.2", - "minimist": "^1.2.0" - }, - "bin": { - "prettyjson": "bin/prettyjson" - } - }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -24329,7 +24328,7 @@ "license": "EPL-2.0", "dependencies": { "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.0.0-next.202112281543", "@zowe/zos-console-for-zowe-sdk": "7.0.0-next.202112281543", @@ -24433,7 +24432,7 @@ "devDependencies": { "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "chalk": "^4.1.0", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -24457,7 +24456,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -24486,7 +24485,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -24506,7 +24505,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -24529,7 +24528,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/zos-uss-for-zowe-sdk": "7.0.0-next.202112281543", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -24553,7 +24552,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -24573,7 +24572,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -24593,7 +24592,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -24616,7 +24615,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -24639,7 +24638,7 @@ "@types/node": "^12.12.24", "@types/ssh2": "^0.5.44", "@zowe/cli-test-utils": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -28606,7 +28605,7 @@ "@types/tar": "6.1.1", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.0.0-next.202112281543", "@zowe/zos-console-for-zowe-sdk": "7.0.0-next.202112281543", @@ -28677,7 +28676,7 @@ "@types/js-yaml": "^4.0.0", "@types/node": "^14.14.37", "@types/uuid": "^8.3.0", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "find-up": "^5.0.0", "js-yaml": "^4.0.0", @@ -28748,7 +28747,7 @@ "requires": { "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "chalk": "^4.1.0", "comment-json": "4.1.0", "eslint": "^7.32.0", @@ -28760,15 +28759,15 @@ } }, "@zowe/imperative": { - "version": "5.0.0-next.202112221912", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.0.0-next.202112221912.tgz", - "integrity": "sha1-BcJYWXQnLPhMCkBGk7rr/7qlnAw=", + "version": "5.0.0-next.202201102100", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.0.0-next.202201102100.tgz", + "integrity": "sha1-1UiNDTnv4jJxUtld9fEKhIz/ejM=", "requires": { "@types/lodash-deep": "2.0.0", "@types/yargs": "13.0.4", "@zowe/perf-timing": "1.0.7", "chalk": "2.4.2", - "cli-table3": "0.6.0", + "cli-table3": "0.6.1", "comment-json": "4.1.0", "dataobject-parser": "1.2.1", "deepmerge": "4.2.2", @@ -28784,13 +28783,13 @@ "lodash": "4.17.21", "lodash-deep": "2.0.0", "log4js": "6.3.0", - "markdown-it": "12.0.4", + "markdown-it": "12.3.2", "moment": "2.20.1", "mustache": "2.3.0", "npm-package-arg": "8.1.1", "opener": "1.5.2", "pacote": "11.1.4", - "prettyjson": "1.2.1", + "prettyjson": "1.2.2", "progress": "2.0.3", "read": "1.0.7", "readline-sync": "1.4.10", @@ -28812,6 +28811,11 @@ "color-convert": "^1.9.0" } }, + "argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -28822,6 +28826,15 @@ "supports-color": "^5.3.0" } }, + "cli-table3": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.1.tgz", + "integrity": "sha512-w0q/enDHhPLq44ovMGdQeeDLvwxwavsJX7oQGYt/LrBlYsyaxyDnp6z3QzFut/6kLLKnlcUVJLrpB7KBfgG/RA==", + "requires": { + "colors": "1.4.0", + "string-width": "^4.2.0" + } + }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -28858,6 +28871,27 @@ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, + "markdown-it": { + "version": "12.3.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", + "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==", + "requires": { + "argparse": "^2.0.1", + "entities": "~2.1.0", + "linkify-it": "^3.0.1", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + } + }, + "prettyjson": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/prettyjson/-/prettyjson-1.2.2.tgz", + "integrity": "sha512-hDso231aQslRQPJjuSMIyUTN5CmW78AwEHlvigOs9E9IO+blW1AJTCJC6pQ8FArBSFsp5ZUdZsWXCUfXiD2D0w==", + "requires": { + "colors": "1.4.0", + "minimist": "^1.2.0" + } + }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", @@ -28897,7 +28931,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "js-yaml": "3.14.1", "madge": "^4.0.1", @@ -28920,7 +28954,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -28934,7 +28968,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/zos-uss-for-zowe-sdk": "7.0.0-next.202112281543", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -28950,7 +28984,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/zos-files-for-zowe-sdk": "7.0.0-next.202112281543", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -28965,7 +28999,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -28979,7 +29013,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/zosmf-for-zowe-sdk": "7.0.0-next.202112281543", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -28994,7 +29028,7 @@ "@types/node": "^12.12.24", "@types/ssh2": "^0.5.44", "@zowe/cli-test-utils": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -29009,7 +29043,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/zos-files-for-zowe-sdk": "7.0.0-next.202112281543", "eslint": "^7.32.0", "madge": "^4.0.1", @@ -29024,7 +29058,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -30300,16 +30334,6 @@ "integrity": "sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==", "dev": true }, - "cli-table3": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.0.tgz", - "integrity": "sha512-gnB85c3MGC7Nm9I/FkiasNBOKjOiO1RNuXXarQms37q4QMpWdlbBgD/VnOStA2faG1dpXMv31RFApjX1/QdgWQ==", - "requires": { - "colors": "^1.1.2", - "object-assign": "^4.1.0", - "string-width": "^4.2.0" - } - }, "cli-width": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.1.tgz", @@ -38215,25 +38239,6 @@ "object-visit": "^1.0.0" } }, - "markdown-it": { - "version": "12.0.4", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.0.4.tgz", - "integrity": "sha512-34RwOXZT8kyuOJy25oJNJoulO8L0bTHYWXcdZBYZqFnjIy3NgjeoM3FmPXIOFQ26/lSHYMr8oc62B6adxXcb3Q==", - "requires": { - "argparse": "^2.0.1", - "entities": "~2.1.0", - "linkify-it": "^3.0.1", - "mdurl": "^1.0.1", - "uc.micro": "^1.0.5" - }, - "dependencies": { - "argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" - } - } - }, "marked": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/marked/-/marked-0.8.2.tgz", @@ -40791,15 +40796,6 @@ "parse-ms": "^2.1.0" } }, - "prettyjson": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/prettyjson/-/prettyjson-1.2.1.tgz", - "integrity": "sha1-/P+rQdGcq0365eV15kJGYZsS0ok=", - "requires": { - "colors": "^1.1.2", - "minimist": "^1.2.0" - } - }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", diff --git a/package.json b/package.json index 50835fdcc8..47e5d12155 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "prepare": "husky install" }, "dependencies": { - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/perf-timing": "1.0.7" }, "devDependencies": { @@ -85,8 +85,8 @@ "typedoc": "^0.16.0", "typedoc-plugin-external-module-map": "^1.2.1", "typescript": "^3.8.0", - "which": "2.0.2", - "uuid": "^3.3.2" + "uuid": "^3.3.2", + "which": "2.0.2" }, "jest": { "globals": { diff --git a/packages/cli/package.json b/packages/cli/package.json index c37e9dcd2e..2356c7a59e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -56,7 +56,7 @@ }, "dependencies": { "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.0.0-next.202112281543", "@zowe/zos-console-for-zowe-sdk": "7.0.0-next.202112281543", diff --git a/packages/core/package.json b/packages/core/package.json index 5f2802a367..355bbcea1e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -50,7 +50,7 @@ "devDependencies": { "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "chalk": "^4.1.0", "eslint": "^7.32.0", "madge": "^4.0.1", diff --git a/packages/provisioning/package.json b/packages/provisioning/package.json index afcb514c13..79ea428eed 100644 --- a/packages/provisioning/package.json +++ b/packages/provisioning/package.json @@ -51,7 +51,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/workflows/package.json b/packages/workflows/package.json index de424172b2..35b5259f0e 100644 --- a/packages/workflows/package.json +++ b/packages/workflows/package.json @@ -50,7 +50,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosconsole/package.json b/packages/zosconsole/package.json index fadfd4d75d..3cdc2e0d44 100644 --- a/packages/zosconsole/package.json +++ b/packages/zosconsole/package.json @@ -47,7 +47,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosfiles/package.json b/packages/zosfiles/package.json index f07ffcb82d..be1e4c959f 100644 --- a/packages/zosfiles/package.json +++ b/packages/zosfiles/package.json @@ -51,7 +51,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "@zowe/zos-uss-for-zowe-sdk": "7.0.0-next.202112281543", "eslint": "^7.32.0", "madge": "^4.0.1", diff --git a/packages/zosjobs/package.json b/packages/zosjobs/package.json index 22cf85bc5b..e934a8396e 100644 --- a/packages/zosjobs/package.json +++ b/packages/zosjobs/package.json @@ -51,7 +51,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zoslogs/package.json b/packages/zoslogs/package.json index 214df6faf7..87d9e84131 100644 --- a/packages/zoslogs/package.json +++ b/packages/zoslogs/package.json @@ -47,7 +47,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosmf/package.json b/packages/zosmf/package.json index 5ddd72c5d8..fa55ed1cef 100644 --- a/packages/zosmf/package.json +++ b/packages/zosmf/package.json @@ -46,7 +46,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zostso/package.json b/packages/zostso/package.json index df68f26838..c1370877f3 100644 --- a/packages/zostso/package.json +++ b/packages/zostso/package.json @@ -50,7 +50,7 @@ "@types/node": "^12.12.24", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosuss/package.json b/packages/zosuss/package.json index 90d8e993d2..5d3a358d50 100644 --- a/packages/zosuss/package.json +++ b/packages/zosuss/package.json @@ -50,7 +50,7 @@ "@types/node": "^12.12.24", "@types/ssh2": "^0.5.44", "@zowe/cli-test-utils": "7.0.0-next.202112281543", - "@zowe/imperative": "5.0.0-next.202112221912", + "@zowe/imperative": "5.0.0-next.202201102100", "eslint": "^7.32.0", "madge": "^4.0.1", "rimraf": "^2.6.3", From dfea3dc93bb7b3b88af38bf2a5f583be625a1882 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Mon, 10 Jan 2022 20:06:55 -0500 Subject: [PATCH 73/78] zowex ver to 0.6.0. sysinfo ver to 0.22.5 Signed-off-by: Gene Johnston --- zowex/Cargo.lock | 10 +++++----- zowex/Cargo.toml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/zowex/Cargo.lock b/zowex/Cargo.lock index 8006961977..5fc4d97a94 100644 --- a/zowex/Cargo.lock +++ b/zowex/Cargo.lock @@ -131,9 +131,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.107" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "log" @@ -297,9 +297,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.21.1" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb6c2c4a6ca462f07ca89841a2618dca6e405304d19ae238997e64915d89f513" +checksum = "7f1bfab07306a27332451a662ca9c8156e3a9986f82660ba9c8e744fe8455d43" dependencies = [ "cfg-if", "core-foundation-sys", @@ -414,7 +414,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "zowe" -version = "0.5.0" +version = "0.6.0" dependencies = [ "atty", "base64", diff --git a/zowex/Cargo.toml b/zowex/Cargo.toml index 71e3821f59..fed479d0d0 100644 --- a/zowex/Cargo.toml +++ b/zowex/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zowe" -version = "0.5.0" +version = "0.6.0" authors = ["Zowe Project"] edition = "2018" license = "EPL-2.0" @@ -15,5 +15,5 @@ pathsearch = "0.2.0" rpassword = "5.0.1" serde = { version = "1.0.130", features = ["derive"]} serde_json = "1.0.69" -sysinfo = "0.21.1" +sysinfo = "0.22.5" whoami = "1.2.1" \ No newline at end of file From 9e06c6004c39bd2ed417370cd069d7f8b2d171bb Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 11 Jan 2022 10:47:20 -0500 Subject: [PATCH 74/78] Move "which" dependency into packages/cli. Signed-off-by: Gene Johnston --- package-lock.json | 12 +++++++----- package.json | 4 +--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 396eba77c1..25e1eb3aff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,6 @@ "@types/jest": "^22.2.3", "@types/node": "^12.12.24", "@types/uuid": "^8.3.0", - "@types/which": "2.0.1", "@typescript-eslint/eslint-plugin": "^4.29.0", "@typescript-eslint/parser": "^4.29.0", "ansi-colors": "^4.1.1", @@ -58,8 +57,7 @@ "typedoc": "^0.16.0", "typedoc-plugin-external-module-map": "^1.2.1", "typescript": "^3.8.0", - "uuid": "^3.3.2", - "which": "2.0.2" + "uuid": "^3.3.2" } }, "__tests__/__packages__/cli-test-utils": { @@ -24357,6 +24355,7 @@ "@types/lodash": "^4.14.175", "@types/node": "^12.12.24", "@types/tar": "6.1.1", + "@types/which": "2.0.1", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "comment-json": "^4.1.0", "eslint": "^7.32.0", @@ -24365,7 +24364,8 @@ "rimraf": "^2.6.3", "strip-ansi": "^6.0.1", "typedoc": "^0.16.0", - "typescript": "^3.8.0" + "typescript": "^3.8.0", + "which": "2.0.2" }, "engines": { "node": ">=8.0.0" @@ -28607,6 +28607,7 @@ "@types/lodash": "^4.14.175", "@types/node": "^12.12.24", "@types/tar": "6.1.1", + "@types/which": "2.0.1", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "@zowe/core-for-zowe-sdk": "7.0.0-next.202112281543", "@zowe/imperative": "5.0.0-next.202201102100", @@ -28633,7 +28634,8 @@ "strip-ansi": "^6.0.1", "tar": "6.1.11", "typedoc": "^0.16.0", - "typescript": "^3.8.0" + "typescript": "^3.8.0", + "which": "2.0.2" }, "dependencies": { "chownr": { diff --git a/package.json b/package.json index 47e5d12155..6c5aa1cc30 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "@types/jest": "^22.2.3", "@types/node": "^12.12.24", "@types/uuid": "^8.3.0", - "@types/which": "2.0.1", "@typescript-eslint/eslint-plugin": "^4.29.0", "@typescript-eslint/parser": "^4.29.0", "ansi-colors": "^4.1.1", @@ -85,8 +84,7 @@ "typedoc": "^0.16.0", "typedoc-plugin-external-module-map": "^1.2.1", "typescript": "^3.8.0", - "uuid": "^3.3.2", - "which": "2.0.2" + "uuid": "^3.3.2" }, "jest": { "globals": { From 8e326e3595698f5ff4abfd2d0e741d2be92909d6 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 11 Jan 2022 10:48:33 -0500 Subject: [PATCH 75/78] One more "which" dependency into packages/cli. Signed-off-by: Gene Johnston --- packages/cli/package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 2356c7a59e..5b751f5d0a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -77,6 +77,7 @@ "@types/lodash": "^4.14.175", "@types/node": "^12.12.24", "@types/tar": "6.1.1", + "@types/which": "2.0.1", "@zowe/cli-test-utils": "7.0.0-next.202112281543", "comment-json": "^4.1.0", "eslint": "^7.32.0", @@ -85,7 +86,8 @@ "rimraf": "^2.6.3", "strip-ansi": "^6.0.1", "typedoc": "^0.16.0", - "typescript": "^3.8.0" + "typescript": "^3.8.0", + "which": "2.0.2" }, "optionalDependencies": { "keytar": "7.7.0" From 06b82fc093a13f2485a8d01e430a141239e13e04 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 11 Jan 2022 10:49:23 -0500 Subject: [PATCH 76/78] Change "zip file" to "archive". Signed-off-by: Gene Johnston --- .../enable/cli.daemon.enable.integration.test.ts | 2 +- .../daemon/__unit__/enable/Enable.handler.unit.test.ts | 2 +- packages/cli/src/daemon/enable/Enable.handler.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts index 636a181307..1482b88444 100644 --- a/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts +++ b/packages/cli/__tests__/daemon/__integration__/enable/cli.daemon.enable.integration.test.ts @@ -139,7 +139,7 @@ describe("daemon enable", () => { const stdoutStr = response.stdout.toString(); expect(stdoutStr).toContain("Failed to enable Zowe CLI daemon mode."); - expect(stdoutStr).toContain(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); + expect(stdoutStr).toContain(`The archive for your OS executable does not exist: ${preBldTgzPath}`); expect(response.status).toBe(1); expect(response.stderr.toString()).toBe(""); } diff --git a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts index 973c4ba6d1..f28f29807a 100644 --- a/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts +++ b/packages/cli/__tests__/daemon/__unit__/enable/Enable.handler.unit.test.ts @@ -205,7 +205,7 @@ describe("Handler for daemon enable", () => { error = e; } - expect(error.mMessage).toBe(`The zip file for your OS executable does not exist: ${preBldTgzPath}`); + expect(error.mMessage).toBe(`The archive for your OS executable does not exist: ${preBldTgzPath}`); IO.existsSync = existsSyncOrig; }); diff --git a/packages/cli/src/daemon/enable/Enable.handler.ts b/packages/cli/src/daemon/enable/Enable.handler.ts index 53ac4ee241..57803c07e0 100644 --- a/packages/cli/src/daemon/enable/Enable.handler.ts +++ b/packages/cli/src/daemon/enable/Enable.handler.ts @@ -88,7 +88,7 @@ export default class EnableDaemonHandler implements ICommandHandler { preBldTgz = nodeJsPath.normalize(preBldTgz); if (!IO.existsSync(preBldTgz)) { throw new ImperativeError({ - msg: `The zip file for your OS executable does not exist: ${preBldTgz}` + msg: `The archive for your OS executable does not exist: ${preBldTgz}` }); } From 707a94cacecad6e8e39ad5eec692a6703f30b6c4 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 11 Jan 2022 11:14:51 -0500 Subject: [PATCH 77/78] Change order of changelog entries. Signed-off-by: Gene Johnston --- packages/cli/CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 1339e071db..c017498a00 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -4,11 +4,10 @@ All notable changes to the Zowe CLI package will be documented in this file. ## Recent Changes -- Enhancement: Add the commands `zowe daemon enable` and `zowe daemon disable`. These commands enable end-users to set up daemon mode without having to download a separate executable and place it by hand into some directory. -- **Next Breaking**: The Daemon-related class named `Processor` was renamed to `DaemonDecider`. - - BugFix: Update Imperative to absorb bugfixes introduced in version `5.0.0-next.202201102100`. +- Enhancement: Add the commands `zowe daemon enable` and `zowe daemon disable`. These commands enable end-users to set up daemon mode without having to download a separate executable and place it by hand into some directory. - Enhancement: Refactored communication between Imperative daemon client and server. Previously the client only sent CLI arguments and the current working directory. Now it sends a JSON object that also includes environment variables and input piped from stdin. [#1179](https://github.com/zowe/zowe-cli/issues/1179) +- **Next Breaking**: The Daemon-related class named `Processor` was renamed to `DaemonDecider`. - **Next Breaking**: Remove `--dcd` argument which was reserved for `--daemon-current-directory`. - **Next Breaking**: Add user check to daemon communication From e33e3e5a67eb3d2721cc48d9b72564553f506511 Mon Sep 17 00:00:00 2001 From: Gene Johnston Date: Tue, 11 Jan 2022 11:15:29 -0500 Subject: [PATCH 78/78] Fix mislabeled test scripts. Signed-off-by: Gene Johnston --- .../__integration__/disable/__scripts__/daemon_disable.sh | 2 +- .../__integration__/disable/__scripts__/daemon_disable_help.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh index ace9d61e2d..f994b30aac 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh +++ b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -echo "================ daemon enable ===============" +echo "================ daemon disable ===============" zowe daemon disable exit $? diff --git a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh index dc0345feed..478ff423bf 100644 --- a/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh +++ b/packages/cli/__tests__/daemon/__integration__/disable/__scripts__/daemon_disable_help.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -echo "================ daemon enable help ===============" +echo "================ daemon disable help ===============" zowe daemon disable --help exit $?