Skip to content

Commit 7408a52

Browse files
committed
fix run:inside argument parsing order and add regression tests for dyno-command mapping
1 parent 74bbdfb commit 7408a52

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

src/commands/run/inside.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import debugFactory from 'debug'
66
import tsheredoc from 'tsheredoc'
77

88
import Dyno from '../../lib/run/dyno.js'
9-
import {buildCommandWithLauncher} from '../../lib/run/helpers.js'
9+
import {buildCommandWithLauncher, revertSortedArgs} from '../../lib/run/helpers.js'
1010

1111
const debug = debugFactory('heroku:run:inside')
1212
const heredoc = tsheredoc.default
1313

1414
export default class RunInside extends Command {
1515
static args = {
16-
command: Args.string({
17-
description: 'command to run (Heroku automatically prepends \'launcher\' to the command)',
18-
required: true,
19-
}),
2016
dyno_name: Args.string({
2117
description: 'name of the dyno to run command inside',
2218
required: true,
2319
}),
20+
command: Args.string({
21+
description: 'command to run (Heroku automatically prepends \'launcher\' to the command)',
22+
required: true,
23+
}),
2424
}
2525

2626
static description = 'run a command inside an existing dyno (for Fir-generation apps only)'
@@ -57,13 +57,15 @@ export default class RunInside extends Command {
5757

5858
async run() {
5959
const {args, argv, flags} = await this.parse(RunInside)
60+
const orderedArgs = revertSortedArgs(process.argv, argv as string[])
61+
const commandArgs = orderedArgs.slice(1)
6062

6163
const {dyno_name: dynoName} = args
6264
const {app: appName, 'exit-code': exitCode, listen, 'no-launcher': noLauncher} = flags
6365

6466
const opts = {
6567
app: appName,
66-
command: await buildCommandWithLauncher(this.heroku, appName, argv.slice(1) as string[], noLauncher),
68+
command: await buildCommandWithLauncher(this.heroku, appName, commandArgs, noLauncher),
6769
dyno: dynoName,
6870
'exit-code': exitCode,
6971
heroku: this.heroku,

test/unit/commands/run/inside.unit.test.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ describe('run:inside', function () {
3232
nock('https://api.heroku.com')
3333
.get('/apps/myapp')
3434
.reply(200, {name: 'myapp', stack: {name: 'heroku-20'}})
35-
.post('/apps/myapp/dynos/web.1')
35+
.post('/apps/myapp/dynos/web.1', body => {
36+
expect(body.command).to.equal('bash')
37+
return true
38+
})
3639
.reply(201, {
3740
attach_url: 'rendezvous://rendezvous.runtime.heroku.com:5000',
3841
command: 'bash',
@@ -88,7 +91,10 @@ describe('run:inside', function () {
8891
nock('https://api.heroku.com')
8992
.get('/apps/myapp')
9093
.reply(200, {name: 'myapp', stack: {name: 'cnb'}})
91-
.post('/apps/myapp/dynos/web.1')
94+
.post('/apps/myapp/dynos/web.1', body => {
95+
expect(body.command).to.equal('bash')
96+
return true
97+
})
9298
.reply(201, {
9399
attach_url: 'rendezvous://rendezvous.runtime.heroku.com:5000',
94100
command: 'bash',
@@ -111,4 +117,34 @@ describe('run:inside', function () {
111117
// Expected to fail when trying to connect
112118
})
113119
})
120+
121+
it('prepends launcher by default on cnb apps', async function () {
122+
nock('https://api.heroku.com')
123+
.get('/apps/myapp')
124+
.reply(200, {name: 'myapp', stack: {name: 'cnb'}})
125+
.post('/apps/myapp/dynos/web.1', body => {
126+
expect(body.command).to.equal('launcher bash')
127+
return true
128+
})
129+
.reply(201, {
130+
attach_url: 'rendezvous://rendezvous.runtime.heroku.com:5000',
131+
command: 'launcher bash',
132+
created_at: '2020-01-01T00:00:00Z',
133+
id: '12345678-1234-1234-1234-123456789012',
134+
name: 'web.1',
135+
size: 'basic',
136+
state: 'starting',
137+
type: 'web',
138+
updated_at: '2020-01-01T00:00:00Z',
139+
})
140+
141+
await runCommand(RunInside, [
142+
'web.1',
143+
'bash',
144+
'--app',
145+
'myapp',
146+
]).catch(() => {
147+
// Expected to fail when trying to connect
148+
})
149+
})
114150
})

0 commit comments

Comments
 (0)