From dd796023b96ac336ee1633dc1c5932ccc8c968c1 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Mon, 16 Nov 2026 16:56:19 +0530 Subject: [PATCH 1/5] style: fix existing eslint errors in base-class.ts and open.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The next commit changes both files, and lint-staged runs eslint --fix on every staged file, so their existing errors would block it. eslint --fix: indentation, quote style, let to const, Array to T[]. By hand: drop an unused catch parameter, wrap two JSDoc lines, and add eslint-disable-next-line for long user-facing strings, one URL and the require() of the user's config file, so none of that text or behaviour changes. No functional change. .talismanrc gets a checksum entry for base-class.ts: Talisman flags the moved "key" type annotations (parseEnvVariablesString, envKeys) as potential secrets; they are not. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .talismanrc | 2 + src/adapters/base-class.ts | 78 ++++++++++++++++++++----------------- src/commands/launch/open.ts | 6 ++- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/.talismanrc b/.talismanrc index d59b6132..69e49a56 100644 --- a/.talismanrc +++ b/.talismanrc @@ -43,4 +43,6 @@ fileignoreconfig: checksum: db8bc45f6d8aa3daebae621920c8618b6e23d1a20984dee0749d91bfa5c1530c - filename: test/unit/base-command.test.ts checksum: 4612c2a41c9d5a7af887f77842feee0a6f6a28ba95a094282b5e9aa20dba6c8c +- filename: src/adapters/base-class.ts + checksum: 89acc2a399bbf689d5920aea4fd85a8ab89dadab8bd9ada462faa8a0fafae1d8 version: "1.0" diff --git a/src/adapters/base-class.ts b/src/adapters/base-class.ts index 796eff2d..76010455 100755 --- a/src/adapters/base-class.ts +++ b/src/adapters/base-class.ts @@ -50,7 +50,7 @@ export default class BaseClass { public apolloClient: ApolloClient; public projectCreationRetryCount: number = 0; public apolloLogsClient: ApolloClient | undefined; - public envVariables: Array> = []; + public envVariables: Record[] = []; public managementSdk: ContentstackClient | undefined; constructor(options: AdapterConstructorInputs) { @@ -165,16 +165,16 @@ export default class BaseClass { const variables = this.config.provider === 'FileUpload' ? { - query: { uploadUid: this.config.uploadUid }, - } + query: { uploadUid: this.config.uploadUid }, + } : { - query: { - provider: this.config.provider, - repoName: fullName, - branchName: defaultBranch, - ...(namespace ? { namespace } : {}), - }, - }; + query: { + provider: this.config.provider, + repoName: fullName, + branchName: defaultBranch, + ...(namespace ? { namespace } : {}), + }, + }; this.config.framework = (await this.apolloClient .query({ query, variables }) .then( @@ -184,7 +184,7 @@ export default class BaseClass { }, }) => framework, ) - .catch((_error) => { + .catch(() => { // this.log("Something went wrong. Please try again.", "warn"); // this.log(error, "error"); // this.exit(1); @@ -249,6 +249,7 @@ export default class BaseClass { if (listOfStacks.length === 0) { this.log( + // eslint-disable-next-line max-len 'No stacks were found in your organization, or you do not have access to any. Please create a stack in the organization to proceed in the organization.', 'error', ); @@ -327,7 +328,7 @@ export default class BaseClass { * @return {*} {Array<{key: string, value: string}>} * @memberof BaseClass */ - private parseEnvVariablesString(envString: string): Array<{ key: string; value: string }> { + private parseEnvVariablesString(envString: string): { key: string; value: string }[] { return map(split(envString, ','), (pair) => { const trimmedPair = (pair as string).trim(); const colonIndex = trimmedPair.indexOf(':'); @@ -354,6 +355,7 @@ export default class BaseClass { type: 'input', name: 'variable', message: + // eslint-disable-next-line max-len 'Enter key and value with a colon between them, and use a comma(,) for the key-value pair. Format: :, : Ex: APP_ENV:prod, TEST_ENV:testVal', }) .then((variable) => this.parseEnvVariablesString(variable as string)); @@ -389,6 +391,7 @@ export default class BaseClass { let data: Record = {}; if (this.config.config && existsSync(this.config.config)) { + // eslint-disable-next-line @typescript-eslint/no-require-imports data = require(this.config.config); } @@ -416,6 +419,7 @@ export default class BaseClass { if (includes(this.config.supportedAdapters, this.config.provider)) { const baseUrl = this.config.host.startsWith('http') ? this.config.host : `https://${this.config.host}`; + // eslint-disable-next-line max-len const gitHubConnectUrl = `${baseUrl.replace('api', 'app').replace('io', 'com')}/#!/launch/settings/connected-accounts`; this.log(`You can connect your ${this.config.provider} account to the UI using the following URL:`, 'info'); this.log(gitHubConnectUrl, { color: 'green' }); @@ -505,7 +509,7 @@ export default class BaseClass { */ inquireRequireValidation(input: any): string | boolean { if (isEmpty(input)) { - return "This field can't be empty."; + return 'This field can\'t be empty.'; } return true; @@ -540,7 +544,8 @@ export default class BaseClass { variablePreparationType.length > 1 ) { this.log( - "The 'Skip adding environment variables' option cannot be combined with other environment variable options. Please choose either 'Skip adding environment variables' or one or more of the other available options.", + // eslint-disable-next-line max-len + 'The \'Skip adding environment variables\' option cannot be combined with other environment variable options. Please choose either \'Skip adding environment variables\' or one or more of the other available options.', 'error', ); this.exit(1); @@ -585,7 +590,7 @@ export default class BaseClass { this.exit(1); } if (!isEmpty(localEnv)) { - let envKeys: Record = keys(localEnv); + const envKeys: Record = keys(localEnv); const existingEnvKeys = map(this.envVariables, 'key'); const localEnvData = map(envKeys, (key) => ({ key, @@ -630,22 +635,22 @@ export default class BaseClass { this.envVariables = map(cloneDeep(this.envVariables), (variable) => { switch (variable.key) { - case 'CONTENTSTACK_API_HOST': - case 'CONTENTSTACK_CDN': - if (variable.value.startsWith('http')) { - const url = new URL(variable.value); - variable.value = url?.host || this.config.host; - } - break; - case 'CONTENTSTACK_ENVIRONMENT': - variable.value = this.config.stackEnvironment; - break; - case 'CONTENTSTACK_API_KEY': - variable.value = this.config.selectedStack.api_key; - break; - case 'CONTENTSTACK_DELIVERY_TOKEN': - variable.value = this.config.deliveryToken?.token; - break; + case 'CONTENTSTACK_API_HOST': + case 'CONTENTSTACK_CDN': + if (variable.value.startsWith('http')) { + const url = new URL(variable.value); + variable.value = url?.host || this.config.host; + } + break; + case 'CONTENTSTACK_ENVIRONMENT': + variable.value = this.config.stackEnvironment; + break; + case 'CONTENTSTACK_API_KEY': + variable.value = this.config.selectedStack.api_key; + break; + case 'CONTENTSTACK_DELIVERY_TOKEN': + variable.value = this.config.deliveryToken?.token; + break; } return variable; @@ -662,9 +667,9 @@ export default class BaseClass { ...(this.config.flags['show-variables'] ? this.envVariables : this.envVariables.map(({ key, value }) => ({ - key, - value: replace(value, /./g, '*'), - }))), + key, + value: replace(value, /./g, '*'), + }))), ]; const headers = [{ value: 'key' }, { value: 'value' }]; @@ -710,7 +715,7 @@ export default class BaseClass { if (msgType === 'info') { forEach(message, (log: DeploymentLogResp | ServerLogResp) => { - let formattedLogTimestamp = new Date(log.timestamp).toISOString()?.slice(0, 23)?.replace('T', ' '); + const formattedLogTimestamp = new Date(log.timestamp).toISOString()?.slice(0, 23)?.replace('T', ' '); this.log(`${formattedLogTimestamp}: ${log.message}`, msgType); }); } else if (msgType === 'error') { @@ -740,7 +745,7 @@ export default class BaseClass { await ux.inquire({ type: 'confirm', name: 'deployLatestSource', - message: "Would you like to change the project's name and try again?", + message: 'Would you like to change the project\'s name and try again?', }) ) { this.config.projectName = await ux.inquire({ @@ -781,6 +786,7 @@ export default class BaseClass { if (!environment) { this.log( + // eslint-disable-next-line max-len `Environment "${environmentFlagInput}" not found in this project. Please provide a valid environment name or UID.`, 'error', ); diff --git a/src/commands/launch/open.ts b/src/commands/launch/open.ts index 76a6c244..d4817d16 100755 --- a/src/commands/launch/open.ts +++ b/src/commands/launch/open.ts @@ -74,7 +74,8 @@ export default class Open extends BaseCommand { } /** - * @method checkAndSetProjectDetails - validate and set project details (ex. organizationUid, uid, environment, deployment) + * @method checkAndSetProjectDetails - validate and set project details + * (ex. organizationUid, uid, environment, deployment) * * @return {*} {Promise} * @memberof Logs @@ -104,7 +105,8 @@ export default class Open extends BaseCommand { } /** - * @method validateAndSelectEnvironment - check whether environment is validate or not. If not then option to select environment + * @method validateAndSelectEnvironment - check whether environment is validate or not. + * If not then option to select environment * * @return {*} {Promise} * @memberof Logs From a587b17bfceec1173906a3560fc33d4dabe5d38a Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Mon, 16 Nov 2026 16:58:13 +0530 Subject: [PATCH 2/5] fix(deps): upgrade open to 11 and @oclif/core to 4.14 to clear Snyk findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit open@8.4.2 (SNYK-JS-OPEN-22112123, High) is fixed only in open 11, which is ESM-only. The CLI compiles to CommonJS, where TypeScript turns import() into require(), so the three browser-open call sites now go through util/open-url.ts, which loads open with a native dynamic import. The GitHub-connect step and launch:open await it, so the process cannot exit before the browser starts; the delayed deployment-URL open keeps its fire-and-forget timer. Opening the browser stays best effort: open 11 rejects when the launcher fails, and every caller prints the URL first, so openUrl swallows that instead of failing the command (or crashing with an unhandled rejection after a successful deploy). @oclif/core moves from 4.11.14 to 4.14.0 within the existing ^4.2.7 range (lockfile only). 4.14 uses ejs 6, which drops the ejs > jake > filelist > minimatch@5.1.9 path behind SNYK-JS-MINIMATCH-22111072. An override pins @oclif/core's own minimatch to ^11.0.1, as on v2-dev. Two findings remain reported, not ignored. Neither has an upgrade, so neither fails --fail-on=all: adm-zip@0.6.1 (SNYK-JS-ADMZIP-21707815), and open@8.4.2 pulled in by @contentstack/cli-utilities, whose latest release (2.0.2) still depends on open ^8.4.2. Integration tests now mock util/open-url instead of open, and stub @oclif/core's getPlatform, which 4.14 implements with a native import('wsl-utils') that Jest's VM cannot run. .talismanrc: base-class.ts checksum refreshed for its new content. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .talismanrc | 2 +- package-lock.json | 355 +++++++++++++++++++++------- package.json | 7 +- src/adapters/base-class.ts | 6 +- src/commands/launch/open.ts | 10 +- src/util/open-url.test.ts | 8 + src/util/open-url.ts | 15 ++ test/integration/jest.setup.ts | 11 +- test/integration/specs/open.test.ts | 5 +- 9 files changed, 314 insertions(+), 105 deletions(-) create mode 100644 src/util/open-url.test.ts create mode 100644 src/util/open-url.ts diff --git a/.talismanrc b/.talismanrc index 69e49a56..90a75668 100644 --- a/.talismanrc +++ b/.talismanrc @@ -44,5 +44,5 @@ fileignoreconfig: - filename: test/unit/base-command.test.ts checksum: 4612c2a41c9d5a7af887f77842feee0a6f6a28ba95a094282b5e9aa20dba6c8c - filename: src/adapters/base-class.ts - checksum: 89acc2a399bbf689d5920aea4fd85a8ab89dadab8bd9ada462faa8a0fafae1d8 + checksum: 75753f8762fc2fd3810672e7070bbdd48b152ec1ad90b18eb1ad5c817a9705aa version: "1.0" diff --git a/package-lock.json b/package-lock.json index cf011a90..09f75fa4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "graphql": "^16.9.0", "ini": "^3.0.1", "lodash": "^4.18.1", - "open": "^8.4.2", + "open": "^11.0.4", "rollup": "^4.59.0", "winston": "^3.17.0" }, @@ -929,6 +929,44 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/@contentstack/cli-utilities/node_modules/define-lazy-prop": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz", + "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@contentstack/cli-utilities/node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "license": "MIT", + "dependencies": { + "is-docker": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@contentstack/cli-utilities/node_modules/open": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-8.4.2.tgz", + "integrity": "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==", + "license": "MIT", + "dependencies": { + "define-lazy-prop": "^2.0.0", + "is-docker": "^2.1.1", + "is-wsl": "^2.2.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@contentstack/management": { "version": "1.31.2", "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.31.2.tgz", @@ -2479,10 +2517,9 @@ } }, "node_modules/@isaacs/nonrecursive-glob-match": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.0.3.tgz", - "integrity": "sha512-SI7kyKHq4XXDRozw+r9GlRZkia1ZkFrpLW98r2IC2Bpr8YkFGE3fvjzmxCG0x78A++69HmDNrDvSMYBZmHGpKA==", - "dev": true, + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.1.0.tgz", + "integrity": "sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw==", "license": "BlueOak-1.0.0" }, "node_modules/@istanbuljs/load-nyc-config": { @@ -2974,7 +3011,9 @@ } }, "node_modules/@oclif/core": { - "version": "4.11.14", + "version": "4.14.0", + "resolved": "https://registry.npmjs.org/@oclif/core/-/core-4.14.0.tgz", + "integrity": "sha512-QCJIZoVJxV7jywgVAUlsQwl3dr3Sa21kfi5z9KrYolbexWJUtFSEtMoNiBWojD05mYycLnB50gp/VxlGdaOCRA==", "license": "MIT", "dependencies": { "ansi-escapes": "^4.3.2", @@ -2982,10 +3021,9 @@ "clean-stack": "^3.0.1", "cli-spinners": "^2.9.2", "debug": "^4.4.3", - "ejs": "^3.1.10", + "ejs": "^6", "get-package-type": "^0.1.0", "indent-string": "^4.0.0", - "is-wsl": "^2.2.0", "lilconfig": "^3.1.3", "minimatch": "^10.2.5", "semver": "^7.8.1", @@ -2994,12 +3032,69 @@ "tinyglobby": "^0.2.17", "widest-line": "^3.1.0", "wordwrap": "^1.0.0", - "wrap-ansi": "^7.0.0" + "wrap-ansi": "^7.0.0", + "wsl-utils": "^0.4.0" }, "engines": { "node": ">=18.0.0" } }, + "node_modules/@oclif/core/node_modules/ejs": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-6.0.1.tgz", + "integrity": "sha512-UaaM14yby8U3k02ihS1Bmj5Kz2d7CCQM1scxpgs4Mhkq8F1wR2gl3+Ts4h5Ne4Mnt7M9m4Dw7jsuMr3+xO4vZA==", + "license": "Apache-2.0", + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.12.18" + } + }, + "node_modules/@oclif/core/node_modules/minimatch": { + "version": "11.0.8", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.8.tgz", + "integrity": "sha512-nFQuYSTVrGvysVBps5Ih+0BdnYFN/Cj3C816r6+p7yK+FHrVLGE4O4N9AFwykrlNlvM2HYt+Rad1Uiro6h88Ig==", + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/nonrecursive-glob-match": "^1.1.0", + "brace-expansion": "^5.0.12" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@oclif/core/node_modules/powershell-utils": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/powershell-utils/-/powershell-utils-0.1.0.tgz", + "integrity": "sha512-dM0jVuXJPsDN6DvRpea484tCUaMiXWjuCn++HGTqUWzGDjv5tZkEZldAJ/UMlqRYGFrD/etByo4/xOuC/snX2A==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@oclif/core/node_modules/wsl-utils": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/wsl-utils/-/wsl-utils-0.4.0.tgz", + "integrity": "sha512-9YmF+2sFEd+T7TkwlmE337F0IVzfDvDknhtpBQxxXzEOfgPphGlFYpyx0cTuCIFj8/p+sqwBYAeGxOMNSzPPDA==", + "license": "MIT", + "dependencies": { + "is-wsl": "^3.1.0", + "powershell-utils": "^0.1.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@oclif/plugin-help": { "version": "6.2.53", "license": "MIT", @@ -3354,9 +3449,6 @@ "cpu": [ "arm" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3370,9 +3462,6 @@ "cpu": [ "arm" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3386,9 +3475,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3402,9 +3488,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3418,9 +3501,6 @@ "cpu": [ "loong64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3434,9 +3514,6 @@ "cpu": [ "loong64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3450,9 +3527,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3466,9 +3540,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3482,9 +3553,6 @@ "cpu": [ "riscv64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3498,9 +3566,6 @@ "cpu": [ "riscv64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3514,9 +3579,6 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3530,9 +3592,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3546,9 +3605,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4406,9 +4462,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4423,9 +4476,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4440,9 +4490,6 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4457,9 +4504,6 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4474,9 +4518,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4491,9 +4532,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4508,9 +4546,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4525,9 +4560,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4542,9 +4574,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4559,9 +4588,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -5452,6 +5478,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/bundle-name": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-4.1.1.tgz", + "integrity": "sha512-DdH81/zPLVS11EUgWq3tEu/xn+EzljlMYooDNdzWEnFha3R3NBMpMV1UqYIpjYHV/SgpFKMIX1Oh7o06SjM/oA==", + "license": "MIT", + "dependencies": { + "run-applescript": "^7.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/bytes": { "version": "3.1.2", "license": "MIT", @@ -6371,6 +6412,34 @@ "node": ">=0.10.0" } }, + "node_modules/default-browser": { + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-5.5.1.tgz", + "integrity": "sha512-m1pAzaJgZ/gssEqlOhJkPJp8Xly7QyW6xcrkUa2KKcDeDSEMP7X8xipU3snUcfisTQx0w1AGae+9UtJSfVnXGw==", + "license": "MIT", + "dependencies": { + "bundle-name": "^4.1.0", + "default-browser-id": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser-id": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/default-browser-id/-/default-browser-id-5.0.1.tgz", + "integrity": "sha512-x1VCxdX4t+8wVfd1so/9w+vQ4vx7lKd2Qp5tDRutErwmR85OgmfX7RlLRMWafRMY7hbEiXIbudNrjOAPa/hL8Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/default-require-extensions": { "version": "3.0.1", "dev": true, @@ -6421,10 +6490,15 @@ } }, "node_modules/define-lazy-prop": { - "version": "2.0.0", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz", + "integrity": "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==", "license": "MIT", "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/define-properties": { @@ -6558,6 +6632,7 @@ }, "node_modules/ejs": { "version": "3.1.10", + "dev": true, "license": "Apache-2.0", "dependencies": { "jake": "^10.8.5" @@ -7815,6 +7890,7 @@ }, "node_modules/filelist": { "version": "1.0.6", + "dev": true, "license": "Apache-2.0", "dependencies": { "minimatch": "^5.0.1" @@ -7822,12 +7898,14 @@ }, "node_modules/filelist/node_modules/balanced-match": { "version": "1.0.2", + "dev": true, "license": "MIT" }, "node_modules/filelist/node_modules/brace-expansion": { "version": "2.1.7", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz", "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==", + "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^1.0.0" @@ -7835,6 +7913,7 @@ }, "node_modules/filelist/node_modules/minimatch": { "version": "5.1.9", + "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" @@ -9561,6 +9640,8 @@ }, "node_modules/is-docker": { "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", "license": "MIT", "bin": { "is-docker": "cli.js" @@ -9653,6 +9734,51 @@ "node": ">=0.10.0" } }, + "node_modules/is-in-ssh": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-in-ssh/-/is-in-ssh-1.0.0.tgz", + "integrity": "sha512-jYa6Q9rH90kR1vKB6NM7qqd1mge3Fx4Dhw5TVlK1MUBqhEOuCagrEHMevNuCcbECmXZ0ThXkRm+Ymr51HwEPAw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-inside-container": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", + "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", + "license": "MIT", + "dependencies": { + "is-docker": "^3.0.0" + }, + "bin": { + "is-inside-container": "cli.js" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-inside-container/node_modules/is-docker": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", + "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", + "license": "MIT", + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-interactive": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", @@ -9918,13 +10044,18 @@ } }, "node_modules/is-wsl": { - "version": "2.2.0", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.1.tgz", + "integrity": "sha512-e6rvdUCiQCAuumZslxRJWR/Doq4VpPR82kqclvcS0efgt430SlGIk05vdCN58+VrzgtIcfNODjozVielycD4Sw==", "license": "MIT", "dependencies": { - "is-docker": "^2.0.0" + "is-inside-container": "^1.0.0" }, "engines": { - "node": ">=8" + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/isarray": { @@ -10052,6 +10183,7 @@ }, "node_modules/jake": { "version": "10.9.4", + "dev": true, "license": "Apache-2.0", "dependencies": { "async": "^3.2.6", @@ -11507,6 +11639,7 @@ }, "node_modules/minimatch": { "version": "10.2.5", + "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "brace-expansion": "^5.0.5" @@ -12286,15 +12419,20 @@ } }, "node_modules/open": { - "version": "8.4.2", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/open/-/open-11.0.4.tgz", + "integrity": "sha512-++Zlftm0kVLPmzC06t6epuWmcRMDbI4z5P3NNX979WA/k23+NtSOynEGzsVfZwguKw2mi5umVgnBlJQMwRz4Pg==", "license": "MIT", "dependencies": { - "define-lazy-prop": "^2.0.0", - "is-docker": "^2.1.1", - "is-wsl": "^2.2.0" + "default-browser": "^5.5.1", + "define-lazy-prop": "^3.0.0", + "is-in-ssh": "^1.0.0", + "is-inside-container": "^1.0.0", + "powershell-utils": "^0.2.1", + "wsl-utils": "^1.0.0" }, "engines": { - "node": ">=12" + "node": ">=20" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -12607,6 +12745,7 @@ }, "node_modules/picocolors": { "version": "1.1.1", + "dev": true, "license": "ISC" }, "node_modules/picomatch": { @@ -12785,6 +12924,18 @@ "node": ">= 0.4" } }, + "node_modules/powershell-utils": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/powershell-utils/-/powershell-utils-0.2.1.tgz", + "integrity": "sha512-C+y9x90UElAddDZmV4qOx9W53B61PO7cIqWz2dQsWlwswuq4mr8NEwytdGKboYbQlGZ3awrkTeNvcZiZNHnQ8A==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "dev": true, @@ -13592,6 +13743,18 @@ "fsevents": "~2.3.2" } }, + "node_modules/run-applescript": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.1.0.tgz", + "integrity": "sha512-DPe5pVFaAsinSaV6QjQ6gdiedWDcRCbUuiQfQa2wmWV7+xC9bGulGI8+TdRmoFkAPaBXk8CrAbnlY2ISniJ47Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/run-async": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/run-async/-/run-async-4.0.6.tgz", @@ -15786,6 +15949,22 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/wsl-utils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wsl-utils/-/wsl-utils-1.0.1.tgz", + "integrity": "sha512-c16PKLIRxBYpR3jSWsdS7SFp0COm5SOQdiFjY818dYFHJbMGuLBszpF07LBWmOS1uzrHa9VGdynsEgoeKy0oOQ==", + "license": "MIT", + "dependencies": { + "is-wsl": "^3.1.0", + "powershell-utils": "^0.2.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/xdg-basedir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", diff --git a/package.json b/package.json index 6bc8f8ce..6012cfd1 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "graphql": "^16.9.0", "ini": "^3.0.1", "lodash": "^4.18.1", - "open": "^8.4.2", + "open": "^11.0.4", "rollup": "^4.59.0", "winston": "^3.17.0" }, @@ -114,7 +114,10 @@ }, "tmp": "^0.2.4", "serialize-javascript": "^7.1.0", - "diff": "^8.0.3" + "diff": "^8.0.3", + "@oclif/core": { + "minimatch": "^11.0.1" + } }, "engines": { "node": ">=22.0.0" diff --git a/src/adapters/base-class.ts b/src/adapters/base-class.ts index 76010455..d6b7e557 100755 --- a/src/adapters/base-class.ts +++ b/src/adapters/base-class.ts @@ -1,4 +1,3 @@ -import open from 'open'; import dotEnv from 'dotenv'; import map from 'lodash/map'; import keys from 'lodash/keys'; @@ -19,6 +18,7 @@ import { writeFileSync, existsSync, readFileSync } from 'fs'; import { cliux as ux, ContentstackClient } from '@contentstack/cli-utilities'; import { print, GraphqlApiClient, LogPolling, getOrganizations } from '../util'; +import { openUrl } from '../util/open-url'; import { FILE_UPLOAD_SIZE_LIMIT_USER_MESSAGE, isLaunchDeploymentFileSizeRelatedError } from '../util/deployment-errors'; import { branchesQuery, @@ -423,7 +423,7 @@ export default class BaseClass { const gitHubConnectUrl = `${baseUrl.replace('api', 'app').replace('io', 'com')}/#!/launch/settings/connected-accounts`; this.log(`You can connect your ${this.config.provider} account to the UI using the following URL:`, 'info'); this.log(gitHubConnectUrl, { color: 'green' }); - open(gitHubConnectUrl); + await openUrl(gitHubConnectUrl); this.exit(1); } else if (emit) { this.$event.emit('provider-changed'); @@ -834,7 +834,7 @@ export default class BaseClass { if (openOnUi) { // NOTE delaying to open the deployment url. If we open quickly it's showing site not reachable setTimeout(() => { - open(deploymentUrl); + openUrl(deploymentUrl); }, 6000); } } diff --git a/src/commands/launch/open.ts b/src/commands/launch/open.ts index d4817d16..e3925896 100755 --- a/src/commands/launch/open.ts +++ b/src/commands/launch/open.ts @@ -1,4 +1,3 @@ -import open from 'open'; import map from 'lodash/map'; import find from 'lodash/find'; import isEmpty from 'lodash/isEmpty'; @@ -7,6 +6,7 @@ import { FlagInput, Flags, cliux as ux } from '@contentstack/cli-utilities'; import { BaseCommand } from '../../base-command'; import { environmentsQuery } from '../../graphql'; import { print, Logger, selectOrg, selectProject } from '../../util'; +import { openUrl } from '../../util/open-url'; export default class Open extends BaseCommand { static description = 'Open a website for an environment'; @@ -44,7 +44,7 @@ export default class Open extends BaseCommand { if (!this.flags.environment) await this.getConfig(); if (this.sharedConfig.currentConfig?.uid && !isEmpty(this.sharedConfig.currentConfig?.deployments)) { - this.openWebsite(); + await this.openWebsite(); } else { await this.prepareProjectDetails(); } @@ -55,7 +55,7 @@ export default class Open extends BaseCommand { * * @memberof Open */ - openWebsite() { + async openWebsite(): Promise { const [deployment] = this.sharedConfig.currentConfig?.deployments || []; if (!isEmpty(deployment)) { @@ -66,7 +66,7 @@ export default class Open extends BaseCommand { { message: 'Deployment URL', bold: true }, { message: deploymentUrl, color: 'cyan' }, ]); - open(deploymentUrl); + await openUrl(deploymentUrl); } else { this.log('Website URL not found.!', 'error'); this.exit(1); @@ -101,7 +101,7 @@ export default class Open extends BaseCommand { await this.validateAndSelectEnvironment(); - this.openWebsite(); + await this.openWebsite(); } /** diff --git a/src/util/open-url.test.ts b/src/util/open-url.test.ts new file mode 100644 index 00000000..d0ef5eea --- /dev/null +++ b/src/util/open-url.test.ts @@ -0,0 +1,8 @@ +import { openUrl } from './open-url'; + +describe('openUrl', () => { + it('resolves instead of rejecting when the browser cannot be opened', async () => { + // Jest's VM cannot run the native import(), so this exercises the failure path. + await expect(openUrl('https://example.com')).resolves.toBeUndefined(); + }); +}); diff --git a/src/util/open-url.ts b/src/util/open-url.ts new file mode 100644 index 00000000..f518a623 --- /dev/null +++ b/src/util/open-url.ts @@ -0,0 +1,15 @@ +type OpenModule = { default: (target: string) => Promise }; + +// open is ESM-only from v11. Under "module": "commonjs" TypeScript compiles import() to require(), +// so the import is created at runtime to keep it a native dynamic import. +const importOpen = new Function('return import("open")') as () => Promise; + +/** Best effort: every caller prints the URL first, so a browser that cannot be opened is not an error. */ +export async function openUrl(url: string): Promise { + try { + const { default: open } = await importOpen(); + await open(url); + } catch { + // ignore + } +} diff --git a/test/integration/jest.setup.ts b/test/integration/jest.setup.ts index be9e0ac7..83623607 100644 --- a/test/integration/jest.setup.ts +++ b/test/integration/jest.setup.ts @@ -1,6 +1,11 @@ -jest.mock('open', () => ({ - __esModule: true, - default: jest.fn(async () => ({ pid: 1 })), +jest.mock('../../src/util/open-url', () => ({ + openUrl: jest.fn(async () => undefined), +})); + +// @oclif/core resolves the platform with a native import('wsl-utils'), which Jest's VM cannot run. +jest.mock(`${process.cwd()}/node_modules/@oclif/core/lib/util/os.js`, () => ({ + ...jest.requireActual(`${process.cwd()}/node_modules/@oclif/core/lib/util/os.js`), + getPlatform: async () => require('node:os').platform(), })); jest.mock('@contentstack/cli-utilities/lib/contentstack-management-sdk', () => ({ diff --git a/test/integration/specs/open.test.ts b/test/integration/specs/open.test.ts index 04879bcb..bc5fd467 100644 --- a/test/integration/specs/open.test.ts +++ b/test/integration/specs/open.test.ts @@ -1,9 +1,8 @@ -import open from 'open'; - import Open from '../../../src/commands/launch/open'; +import { openUrl } from '../../../src/util/open-url'; import { cma, fixtures, prompts, runCommand, Session, startSession } from '../harness'; -const openMock = open as unknown as jest.Mock; +const openMock = openUrl as unknown as jest.Mock; describe('launch:open', () => { let session: Session; From 9a39697f89aa3f8c3cbe4b2dbc2bffac56e823b7 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Mon, 16 Nov 2026 17:13:15 +0530 Subject: [PATCH 3/5] test: keep the integration harness's git calls out of the repo when run from a hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Git exports GIT_DIR and the other repo-local variables to hooks, and the pre-push hook runs npm test. With them set, the harness's git init, config, commit and remote add in its temp projects acted on this repository: a push from a worktree left "initial commit" commits on the branch and set user.name, user.email, commit.gpgsign and core.bare in the shared .git/config. jest.global-setup.ts now clears the variables `git rev-parse --local-env-vars` lists. It runs in Jest's parent process, so the child processes the harness and the CLI spawn inherit the clean environment (setupFiles only change the sandbox's copy of process.env). #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- test/integration/jest.global-setup.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/integration/jest.global-setup.ts b/test/integration/jest.global-setup.ts index 72eb2117..ec64854a 100644 --- a/test/integration/jest.global-setup.ts +++ b/test/integration/jest.global-setup.ts @@ -10,6 +10,16 @@ const TEMP_PREFIXES = [ ]; const STALE_AFTER_MS = 60 * 60 * 1000; +// Git exports these to hooks, and the pre-push hook runs this suite. Left set, every git call the harness +// and the CLI make in the temp projects would act on this repository instead (from `git rev-parse +// --local-env-vars`). Cleared here, in the parent process, so child processes inherit the clean env. +const GIT_LOCAL_ENV_VARS = [ + 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT', + 'GIT_OBJECT_DIRECTORY', 'GIT_DIR', 'GIT_WORK_TREE', 'GIT_IMPLICIT_WORK_TREE', 'GIT_GRAFT_FILE', + 'GIT_INDEX_FILE', 'GIT_NO_REPLACE_OBJECTS', 'GIT_REPLACE_REF_BASE', 'GIT_PREFIX', 'GIT_SHALLOW_FILE', + 'GIT_COMMON_DIR', +]; + const sweepStaleTempDirs = (): void => { const now = Date.now(); for (const entry of readdirSync(tmpdir())) { @@ -26,6 +36,7 @@ const sweepStaleTempDirs = (): void => { }; export default async function globalSetup(): Promise { + for (const name of GIT_LOCAL_ENV_VARS) delete process.env[name]; sweepStaleTempDirs(); process.env.LAUNCH_CLI_ITEST_RUN_DIR = mkdtempSync(join(tmpdir(), 'launch-cli-itest-run-')); } From 081d551ebab93b4d92c3b2ad93173c64b55167aa Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Mon, 16 Nov 2026 20:26:01 +0530 Subject: [PATCH 4/5] fix: address review on the open helper, lockfile and harness docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - open-url.ts: create the dynamic importer lazily inside openUrl's try. Built at module load, new Function threw EvalError under --disallow-code-generation-from-strings, so every command importing the helper crashed instead of just not opening a browser. - openUrl takes an optional loader, and the tests inject a fake open to cover the success path (called with the URL) plus both failure paths, instead of relying on Jest's VM rejecting the native import. - Drop the code comments added in this PR (AGENTS.md: no code comments); the rationale lives in the commit messages and the PR description. - AGENTS.md: the integration harness now replaces src/util/open-url and @oclif/core's getPlatform rather than the open package, and jest.global-setup.ts clears git's repo-local env vars. - @oclif/core range raised to ^4.14.0 so installs cannot keep a 4.11.x that still carries the flagged minimatch path. - package-lock.json: restore the 23 "libc" fields npm 10 dropped, copied from development for the same package versions. npm 11 (release CI) re-resolves the file without changes. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- AGENTS.md | 11 +++-- package-lock.json | 71 ++++++++++++++++++++++++++- package.json | 2 +- src/util/open-url.test.ts | 25 ++++++++-- src/util/open-url.ts | 12 ++--- test/integration/jest.global-setup.ts | 3 -- test/integration/jest.setup.ts | 1 - 7 files changed, 106 insertions(+), 19 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5de3c03e..01a44623 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,9 +14,14 @@ Integration tests (`test/integration/`) exist to catch what unit tests cannot: they run a real oclif command end to end and assert on what the CLI *does*. - Run them with `npm run test:integration` (they are also part of `npm test`). -- Only three things are replaced: the terminal prompt (`inquirer`), the `open` package, and - the Contentstack management SDK, which resolves its base URL as `https://:443` and so - cannot be pointed at a local server. Apollo, the GraphQL documents, the CLI config store, +- Only these are replaced: the terminal prompt (`inquirer`), the browser opener + (`src/util/open-url`; the CLI never imports the `open` package directly, so mocking `open` has no + effect), `@oclif/core`'s `getPlatform` (it runs a native `import('wsl-utils')` that Jest's VM + cannot execute), and the Contentstack management SDK, which resolves its base URL as + `https://:443` and so cannot be pointed at a local server. +- `jest.global-setup.ts` clears git's repo-local environment variables (`git rev-parse + --local-env-vars`). Git exports them to hooks, and the pre-push hook runs this suite; left set, + the harness's git calls in its temp projects would act on this repository instead. Apollo, the GraphQL documents, the CLI config store, flag parsing, the filesystem and `git` all run for real. - The Launch API is a local HTTP server (`test/integration/harness/launch-api.ts`) that the CLI reaches through a temporary region config. It records every GraphQL operation, so tests assert diff --git a/package-lock.json b/package-lock.json index 09f75fa4..cd038d78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@apollo/client": "^3.14.0", "@contentstack/cli-command": "^2.0.2", "@contentstack/cli-utilities": "^2.0.2", - "@oclif/core": "^4.2.7", + "@oclif/core": "^4.14.0", "@oclif/plugin-help": "^6.2.25", "@rollup/plugin-commonjs": "^28.0.2", "@rollup/plugin-json": "^6.1.0", @@ -3449,6 +3449,9 @@ "cpu": [ "arm" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3462,6 +3465,9 @@ "cpu": [ "arm" ], + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3475,6 +3481,9 @@ "cpu": [ "arm64" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3488,6 +3497,9 @@ "cpu": [ "arm64" ], + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3501,6 +3513,9 @@ "cpu": [ "loong64" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3514,6 +3529,9 @@ "cpu": [ "loong64" ], + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3527,6 +3545,9 @@ "cpu": [ "ppc64" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3540,6 +3561,9 @@ "cpu": [ "ppc64" ], + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3553,6 +3577,9 @@ "cpu": [ "riscv64" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3566,6 +3593,9 @@ "cpu": [ "riscv64" ], + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -3579,6 +3609,9 @@ "cpu": [ "s390x" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3592,6 +3625,9 @@ "cpu": [ "x64" ], + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -3605,6 +3641,9 @@ "cpu": [ "x64" ], + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4462,6 +4501,9 @@ "arm64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4476,6 +4518,9 @@ "arm64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4490,6 +4535,9 @@ "loong64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4504,6 +4552,9 @@ "loong64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4518,6 +4569,9 @@ "ppc64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4532,6 +4586,9 @@ "riscv64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4546,6 +4603,9 @@ "riscv64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ @@ -4560,6 +4620,9 @@ "s390x" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4574,6 +4637,9 @@ "x64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ @@ -4588,6 +4654,9 @@ "x64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ diff --git a/package.json b/package.json index 6012cfd1..b0ee06a4 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@apollo/client": "^3.14.0", "@contentstack/cli-command": "^2.0.2", "@contentstack/cli-utilities": "^2.0.2", - "@oclif/core": "^4.2.7", + "@oclif/core": "^4.14.0", "@oclif/plugin-help": "^6.2.25", "@rollup/plugin-commonjs": "^28.0.2", "@rollup/plugin-json": "^6.1.0", diff --git a/src/util/open-url.test.ts b/src/util/open-url.test.ts index d0ef5eea..cff2cbd9 100644 --- a/src/util/open-url.test.ts +++ b/src/util/open-url.test.ts @@ -1,8 +1,27 @@ import { openUrl } from './open-url'; describe('openUrl', () => { - it('resolves instead of rejecting when the browser cannot be opened', async () => { - // Jest's VM cannot run the native import(), so this exercises the failure path. - await expect(openUrl('https://example.com')).resolves.toBeUndefined(); + it('opens the URL with the loaded open package', async () => { + const open = jest.fn(async () => undefined); + + await openUrl('https://example.com', async () => ({ default: open })); + + expect(open).toHaveBeenCalledWith('https://example.com'); + }); + + it('resolves when the open package cannot be loaded', async () => { + await expect( + openUrl('https://example.com', async () => { + throw new Error('load failed'); + }), + ).resolves.toBeUndefined(); + }); + + it('resolves when opening the browser fails', async () => { + const open = jest.fn(async () => { + throw new Error('spawn failed'); + }); + + await expect(openUrl('https://example.com', async () => ({ default: open }))).resolves.toBeUndefined(); }); }); diff --git a/src/util/open-url.ts b/src/util/open-url.ts index f518a623..b76cee82 100644 --- a/src/util/open-url.ts +++ b/src/util/open-url.ts @@ -1,15 +1,13 @@ type OpenModule = { default: (target: string) => Promise }; +type LoadOpen = () => Promise; -// open is ESM-only from v11. Under "module": "commonjs" TypeScript compiles import() to require(), -// so the import is created at runtime to keep it a native dynamic import. -const importOpen = new Function('return import("open")') as () => Promise; +const loadOpen: LoadOpen = async () => new Function('return import("open")')() as Promise; -/** Best effort: every caller prints the URL first, so a browser that cannot be opened is not an error. */ -export async function openUrl(url: string): Promise { +export async function openUrl(url: string, load: LoadOpen = loadOpen): Promise { try { - const { default: open } = await importOpen(); + const { default: open } = await load(); await open(url); } catch { - // ignore + return; } } diff --git a/test/integration/jest.global-setup.ts b/test/integration/jest.global-setup.ts index ec64854a..22f06ac0 100644 --- a/test/integration/jest.global-setup.ts +++ b/test/integration/jest.global-setup.ts @@ -10,9 +10,6 @@ const TEMP_PREFIXES = [ ]; const STALE_AFTER_MS = 60 * 60 * 1000; -// Git exports these to hooks, and the pre-push hook runs this suite. Left set, every git call the harness -// and the CLI make in the temp projects would act on this repository instead (from `git rev-parse -// --local-env-vars`). Cleared here, in the parent process, so child processes inherit the clean env. const GIT_LOCAL_ENV_VARS = [ 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT', 'GIT_OBJECT_DIRECTORY', 'GIT_DIR', 'GIT_WORK_TREE', 'GIT_IMPLICIT_WORK_TREE', 'GIT_GRAFT_FILE', diff --git a/test/integration/jest.setup.ts b/test/integration/jest.setup.ts index 83623607..080141a0 100644 --- a/test/integration/jest.setup.ts +++ b/test/integration/jest.setup.ts @@ -2,7 +2,6 @@ jest.mock('../../src/util/open-url', () => ({ openUrl: jest.fn(async () => undefined), })); -// @oclif/core resolves the platform with a native import('wsl-utils'), which Jest's VM cannot run. jest.mock(`${process.cwd()}/node_modules/@oclif/core/lib/util/os.js`, () => ({ ...jest.requireActual(`${process.cwd()}/node_modules/@oclif/core/lib/util/os.js`), getPlatform: async () => require('node:os').platform(), From ccdb47aef6b7ea7184c9381a232c0f15843c6e23 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Tue, 17 Nov 2026 10:59:35 +0530 Subject: [PATCH 5/5] fix: address second review on the harness docs and openUrl tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AGENTS.md: the "all run for real" sentence had been joined onto the new git-env bullet; it closes the "Only these are replaced" bullet again, so the harness contract reads as before. - open-url.test.ts: the failure-path tests now keep the happy path's assertions (AGENTS.md: do not skip assertions in edge-case tests). The load-failure test checks the loader was called; the open-failure test checks open was called with the URL. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- AGENTS.md | 6 +++--- src/util/open-url.test.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 01a44623..e1020be3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,11 +18,11 @@ (`src/util/open-url`; the CLI never imports the `open` package directly, so mocking `open` has no effect), `@oclif/core`'s `getPlatform` (it runs a native `import('wsl-utils')` that Jest's VM cannot execute), and the Contentstack management SDK, which resolves its base URL as - `https://:443` and so cannot be pointed at a local server. + `https://:443` and so cannot be pointed at a local server. Apollo, the GraphQL documents, + the CLI config store, flag parsing, the filesystem and `git` all run for real. - `jest.global-setup.ts` clears git's repo-local environment variables (`git rev-parse --local-env-vars`). Git exports them to hooks, and the pre-push hook runs this suite; left set, - the harness's git calls in its temp projects would act on this repository instead. Apollo, the GraphQL documents, the CLI config store, - flag parsing, the filesystem and `git` all run for real. + the harness's git calls in its temp projects would act on this repository instead. - The Launch API is a local HTTP server (`test/integration/harness/launch-api.ts`) that the CLI reaches through a temporary region config. It records every GraphQL operation, so tests assert on the operations and variables the CLI actually sent rather than on internal method calls. diff --git a/src/util/open-url.test.ts b/src/util/open-url.test.ts index cff2cbd9..c58f67ca 100644 --- a/src/util/open-url.test.ts +++ b/src/util/open-url.test.ts @@ -10,11 +10,13 @@ describe('openUrl', () => { }); it('resolves when the open package cannot be loaded', async () => { - await expect( - openUrl('https://example.com', async () => { - throw new Error('load failed'); - }), - ).resolves.toBeUndefined(); + const load = jest.fn(async () => { + throw new Error('load failed'); + }); + + await expect(openUrl('https://example.com', load)).resolves.toBeUndefined(); + + expect(load).toHaveBeenCalledTimes(1); }); it('resolves when opening the browser fails', async () => { @@ -23,5 +25,7 @@ describe('openUrl', () => { }); await expect(openUrl('https://example.com', async () => ({ default: open }))).resolves.toBeUndefined(); + + expect(open).toHaveBeenCalledWith('https://example.com'); }); });