From eeef085b6824f3364a26f174837fbfc7fca0f3bb Mon Sep 17 00:00:00 2001 From: Santiago Bosio Date: Wed, 23 Oct 2024 13:56:42 -0300 Subject: [PATCH] Fix for command 'ps -x' (sudo) for app in a Private Space (#3051) --- packages/cli/src/commands/ps/index.ts | 16 ++--- packages/cli/src/lib/types/dyno_extended.d.ts | 16 ++--- .../test/unit/commands/ps/index.unit.test.ts | 64 +++++++++++++++++++ 3 files changed, 80 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/commands/ps/index.ts b/packages/cli/src/commands/ps/index.ts index a19e477a4c..352c960634 100644 --- a/packages/cli/src/commands/ps/index.ts +++ b/packages/cli/src/commands/ps/index.ts @@ -57,16 +57,16 @@ function printExtended(dynos: DynoExtended[]) { ID: {get: (dyno: DynoExtended) => dyno.id}, Process: {get: (dyno: DynoExtended) => dyno.name}, State: {get: (dyno: DynoExtended) => `${dyno.state} ${ago(new Date(dyno.updated_at))}`}, - Region: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.region : ''}, - 'Execution Plane': {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.execution_plane : ''}, - Fleet: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.fleet : ''}, - Instance: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.instance : ''}, - IP: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.ip : ''}, - Port: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.port.toString() : ''}, - AZ: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.az : ''}, + Region: {get: (dyno: DynoExtended) => dyno.extended?.region ? dyno.extended.region : ''}, + 'Execution Plane': {get: (dyno: DynoExtended) => dyno.extended?.execution_plane ? dyno.extended.execution_plane : ''}, + Fleet: {get: (dyno: DynoExtended) => dyno.extended?.fleet ? dyno.extended.fleet : ''}, + Instance: {get: (dyno: DynoExtended) => dyno.extended?.instance ? dyno.extended.instance : ''}, + IP: {get: (dyno: DynoExtended) => dyno.extended?.ip ? dyno.extended.ip : ''}, + Port: {get: (dyno: DynoExtended) => dyno.extended?.port ? dyno.extended.port.toString() : ''}, + AZ: {get: (dyno: DynoExtended) => dyno.extended?.az ? dyno.extended.az : ''}, Release: {get: (dyno: DynoExtended) => dyno.release.version}, Command: {get: (dyno: DynoExtended) => truncate(dyno.command)}, - Route: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.route : ''}, + Route: {get: (dyno: DynoExtended) => dyno.extended?.route ? dyno.extended.route : ''}, Size: {get: (dyno: DynoExtended) => dyno.size}, }, { diff --git a/packages/cli/src/lib/types/dyno_extended.d.ts b/packages/cli/src/lib/types/dyno_extended.d.ts index 1c44a190e4..17233ba8c5 100644 --- a/packages/cli/src/lib/types/dyno_extended.d.ts +++ b/packages/cli/src/lib/types/dyno_extended.d.ts @@ -5,13 +5,13 @@ export interface DynoExtended extends Required { * Extended information. */ extended?: { - az: string, - execution_plane: string, - fleet: string, - instance: string, - ip: string, - port: number, - region: string, - route: string, + az: string | null, + execution_plane: string | null, + fleet: string | null, + instance: string | null, + ip: string | null, + port: number | null, + region: string | null, + route: string | null, } } diff --git a/packages/cli/test/unit/commands/ps/index.unit.test.ts b/packages/cli/test/unit/commands/ps/index.unit.test.ts index fa20809d73..7c75e144c0 100644 --- a/packages/cli/test/unit/commands/ps/index.unit.test.ts +++ b/packages/cli/test/unit/commands/ps/index.unit.test.ts @@ -193,6 +193,70 @@ describe('ps', function () { expect(stderr.output).to.equal('') }) + it('shows extended info for Private Space app', async function () { + const api = nock('https://api.heroku.com') + .get('/account') + .reply(200, {id: '1234'}) + .get('/apps/myapp') + .reply(200, {name: 'myapp'}) + .get('/apps/myapp/dynos?extended=true') + .reply(200, [{ + id: '100', + command: 'npm start', + size: 'Eco', + name: 'web.1', + type: 'web', + updated_at: hourAgo, + state: 'up', + release: {id: '10', version: '40'}, + extended: { + az: null, + execution_plane: null, + fleet: null, + instance: 'instance', + ip: '10.0.0.1', + port: null, + region: 'us', + route: null, + }, + }, { + id: '101', + command: 'bash', + size: 'Eco', + name: 'run.1', + type: 'run', + updated_at: hourAgo, + state: 'up', + release: {id: '10', version: '40'}, + extended: { + az: null, + execution_plane: null, + fleet: null, + instance: 'instance', + ip: '10.0.0.1', + port: null, + region: 'us', + route: null, + }, + }]) + + await runCommand(Cmd, [ + '--app', + 'myapp', + '--extended', + ]) + + api.done() + + expect(heredoc(stdout.output)).to.equal(heredoc` + Id Process State Region Execution plane Fleet Instance Ip Port Az Release Command Route Size + ─── ─────── ─────────────────────────────────────── ────── ─────────────── ───── ──────── ──────── ──── ── ─────── ───────── ───── ──── + 101 run.1 up ${hourAgoStr} (~ 1h ago) us instance 10.0.0.1 40 bash Eco + 100 web.1 up ${hourAgoStr} (~ 1h ago) us instance 10.0.0.1 40 npm start Eco + `) + expect(stderr.output).to.equal('') + }) + it('shows shield dynos in extended info if app is in a shielded private space', async function () { const api = nock('https://api.heroku.com') .get('/account')