@heroku/mcp-server 1.2.8 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tools/data.js +1 -1
- package/dist/tools/data.spec.js +13 -13
- package/dist/tools/maintenance.spec.js +2 -2
- package/dist/tools/pipelines.spec.js +6 -6
- package/dist/tools/ps.spec.js +7 -7
- package/dist/utils/command-builder.js +16 -2
- package/dist/utils/command-builder.spec.js +43 -10
- package/package.json +5 -4
package/dist/tools/data.js
CHANGED
|
@@ -121,7 +121,7 @@ export const registerPgPsqlTool = (server, herokuRepl) => {
|
|
|
121
121
|
const command = new CommandBuilder(TOOL_COMMAND_MAP.PG_PSQL)
|
|
122
122
|
.addFlags({
|
|
123
123
|
app: options.app,
|
|
124
|
-
command:
|
|
124
|
+
command: options.command?.replaceAll('\n', ' ') ?? '',
|
|
125
125
|
file: options.file,
|
|
126
126
|
credential: options.credential
|
|
127
127
|
})
|
package/dist/tools/data.spec.js
CHANGED
|
@@ -27,7 +27,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
27
27
|
mocks.herokuRepl.executeCommand.resolves('psql (14.9)\nType "help" for help.\n\nmyapp::DATABASE=> ');
|
|
28
28
|
await toolCallback({ app: 'myapp' });
|
|
29
29
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
30
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app=myapp
|
|
30
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app='myapp'`);
|
|
31
31
|
});
|
|
32
32
|
it('should build correct command with all parameters', async () => {
|
|
33
33
|
mocks.herokuRepl.executeCommand.resolves('Query executed successfully\n');
|
|
@@ -39,7 +39,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
39
39
|
database: 'HEROKU_POSTGRESQL_RED'
|
|
40
40
|
});
|
|
41
41
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
42
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app=myapp --command=
|
|
42
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app='myapp' --command='SELECT * FROM users' --file='query.sql' --credential='mycred' -- 'HEROKU_POSTGRESQL_RED'`);
|
|
43
43
|
});
|
|
44
44
|
it('should handle error response', async () => {
|
|
45
45
|
const errorResponse = '<<<ERROR>>>\nError: Database not found\n<<<END ERROR>>>\n';
|
|
@@ -81,7 +81,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
81
81
|
const builtCommand = mocks.herokuRepl.executeCommand.firstCall.args[0];
|
|
82
82
|
// The newline was replaced by a space BEFORE reaching CommandBuilder, so the
|
|
83
83
|
// command is NOT rejected and the built command contains the space-joined SQL.
|
|
84
|
-
expect(builtCommand).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app=myapp --command=
|
|
84
|
+
expect(builtCommand).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app='myapp' --command='SELECT 1; SELECT 2;'`);
|
|
85
85
|
// Confirm no raw LF survived in the command sent to the CLI.
|
|
86
86
|
expect(builtCommand).to.not.include('\n');
|
|
87
87
|
});
|
|
@@ -127,14 +127,14 @@ describe('PostgreSQL Tools', () => {
|
|
|
127
127
|
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
128
128
|
await toolCallback({ app: 'myapp' });
|
|
129
129
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
130
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_INFO} --app=myapp`);
|
|
130
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_INFO} --app='myapp'`);
|
|
131
131
|
});
|
|
132
132
|
it('should build correct command with database parameter', async () => {
|
|
133
133
|
const successResponse = '=== HEROKU_POSTGRESQL_RED\nPlan: Standard-0\nStatus: Available\n';
|
|
134
134
|
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
135
135
|
await toolCallback({ app: 'myapp', database: 'HEROKU_POSTGRESQL_RED' });
|
|
136
136
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
137
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_INFO} --app=myapp -- HEROKU_POSTGRESQL_RED`);
|
|
137
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_INFO} --app='myapp' -- 'HEROKU_POSTGRESQL_RED'`);
|
|
138
138
|
});
|
|
139
139
|
it('should handle error response', async () => {
|
|
140
140
|
const errorResponse = '<<<ERROR>>>\nError: Database not found\n<<<END ERROR>>>\n';
|
|
@@ -172,7 +172,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
172
172
|
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
173
173
|
await toolCallback({ app: 'myapp' });
|
|
174
174
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
175
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PS} --app=myapp`);
|
|
175
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PS} --app='myapp'`);
|
|
176
176
|
});
|
|
177
177
|
it('should build correct command with all parameters', async () => {
|
|
178
178
|
const successResponse = ' pid | state | source | running_for | waiting | query | memory\n-----+-------+--------+-------------+---------+-------+--------\n';
|
|
@@ -183,7 +183,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
183
183
|
database: 'HEROKU_POSTGRESQL_RED'
|
|
184
184
|
});
|
|
185
185
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
186
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PS} --app=myapp --verbose -- HEROKU_POSTGRESQL_RED`);
|
|
186
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PS} --app='myapp' --verbose -- 'HEROKU_POSTGRESQL_RED'`);
|
|
187
187
|
});
|
|
188
188
|
it('should handle error response', async () => {
|
|
189
189
|
const errorResponse = '<<<ERROR>>>\nError: Database not found\n<<<END ERROR>>>\n';
|
|
@@ -221,7 +221,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
221
221
|
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
222
222
|
await toolCallback({ app: 'myapp', pid: 12345 });
|
|
223
223
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
224
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_KILL} --app=myapp -- 12345`);
|
|
224
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_KILL} --app='myapp' -- '12345'`);
|
|
225
225
|
});
|
|
226
226
|
it('should build correct command with all parameters', async () => {
|
|
227
227
|
const successResponse = 'Terminating process 12345... done\n';
|
|
@@ -233,7 +233,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
233
233
|
database: 'HEROKU_POSTGRESQL_RED'
|
|
234
234
|
});
|
|
235
235
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
236
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_KILL} --app=myapp --force -- 12345 HEROKU_POSTGRESQL_RED`);
|
|
236
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_KILL} --app='myapp' --force -- '12345' 'HEROKU_POSTGRESQL_RED'`);
|
|
237
237
|
});
|
|
238
238
|
it('should handle error response', async () => {
|
|
239
239
|
const errorResponse = '<<<ERROR>>>\nError: Process not found\n<<<END ERROR>>>\n';
|
|
@@ -271,7 +271,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
271
271
|
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
272
272
|
await toolCallback({ app: 'myapp' });
|
|
273
273
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
274
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_BACKUPS} --app=myapp`);
|
|
274
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_BACKUPS} --app='myapp'`);
|
|
275
275
|
});
|
|
276
276
|
it('should build correct command with all parameters', async () => {
|
|
277
277
|
const successResponse = 'Scheduling automatic daily backups at 00:00 America/New_York... done\n';
|
|
@@ -285,7 +285,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
285
285
|
quiet: true
|
|
286
286
|
});
|
|
287
287
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
288
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_BACKUPS} --app=myapp`);
|
|
288
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_BACKUPS} --app='myapp'`);
|
|
289
289
|
});
|
|
290
290
|
it('should handle error response', async () => {
|
|
291
291
|
const errorResponse = '<<<ERROR>>>\nError: No backups found\n<<<END ERROR>>>\n';
|
|
@@ -323,7 +323,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
323
323
|
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
324
324
|
await toolCallback({ app: 'myapp' });
|
|
325
325
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
326
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_UPGRADE} --app=myapp`);
|
|
326
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_UPGRADE} --app='myapp'`);
|
|
327
327
|
});
|
|
328
328
|
it('should build correct command with all parameters', async () => {
|
|
329
329
|
const successResponse = 'Starting upgrade of HEROKU_POSTGRESQL_RED to PostgreSQL 14... done\n';
|
|
@@ -335,7 +335,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
335
335
|
database: 'HEROKU_POSTGRESQL_RED'
|
|
336
336
|
});
|
|
337
337
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
338
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_UPGRADE} --app=myapp --version=14 --confirm=myapp -- HEROKU_POSTGRESQL_RED`);
|
|
338
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_UPGRADE} --app='myapp' --version='14' --confirm='myapp' -- 'HEROKU_POSTGRESQL_RED'`);
|
|
339
339
|
});
|
|
340
340
|
it('should handle error response', async () => {
|
|
341
341
|
const errorResponse = '<<<ERROR>>>\nError: Database is already at version 14\n<<<END ERROR>>>\n';
|
|
@@ -27,7 +27,7 @@ describe('Maintenance Tools', () => {
|
|
|
27
27
|
mocks.herokuRepl.executeCommand.resolves('Enabling maintenance mode for myapp... done\n');
|
|
28
28
|
await toolCallback({ app: 'myapp' });
|
|
29
29
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
30
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.MAINTENANCE_ON} --app=myapp`);
|
|
30
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.MAINTENANCE_ON} --app='myapp'`);
|
|
31
31
|
});
|
|
32
32
|
it('should handle successful response', async () => {
|
|
33
33
|
const successResponse = 'Enabling maintenance mode for myapp... done\n';
|
|
@@ -72,7 +72,7 @@ describe('Maintenance Tools', () => {
|
|
|
72
72
|
mocks.herokuRepl.executeCommand.resolves('Disabling maintenance mode for myapp... done\n');
|
|
73
73
|
await toolCallback({ app: 'myapp' });
|
|
74
74
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
75
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.MAINTENANCE_OFF} --app=myapp`);
|
|
75
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.MAINTENANCE_OFF} --app='myapp'`);
|
|
76
76
|
});
|
|
77
77
|
it('should handle successful response', async () => {
|
|
78
78
|
const successResponse = 'Disabling maintenance mode for myapp... done\n';
|
|
@@ -27,7 +27,7 @@ describe('Pipeline Tools', () => {
|
|
|
27
27
|
mocks.herokuRepl.executeCommand.resolves('Creating pipeline myapp-pipeline... done\n');
|
|
28
28
|
await toolCallback({ name: 'myapp-pipeline' });
|
|
29
29
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
30
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_CREATE} -- myapp-pipeline`);
|
|
30
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_CREATE} -- 'myapp-pipeline'`);
|
|
31
31
|
});
|
|
32
32
|
it('should build correct command with all parameters', async () => {
|
|
33
33
|
mocks.herokuRepl.executeCommand.resolves('Creating pipeline myapp-pipeline... done\n');
|
|
@@ -38,7 +38,7 @@ describe('Pipeline Tools', () => {
|
|
|
38
38
|
team: 'myteam'
|
|
39
39
|
});
|
|
40
40
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
41
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_CREATE} --stage=production --app=myapp --team=myteam -- myapp-pipeline`);
|
|
41
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_CREATE} --stage='production' --app='myapp' --team='myteam' -- 'myapp-pipeline'`);
|
|
42
42
|
});
|
|
43
43
|
it('should handle error response', async () => {
|
|
44
44
|
const errorResponse = '<<<ERROR>>>\nError: Pipeline already exists\n<<<END ERROR>>>\n';
|
|
@@ -75,7 +75,7 @@ describe('Pipeline Tools', () => {
|
|
|
75
75
|
mocks.herokuRepl.executeCommand.resolves('Promoting myapp to production... done\n');
|
|
76
76
|
await toolCallback({ app: 'myapp' });
|
|
77
77
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
78
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_PROMOTE} --app=myapp`);
|
|
78
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_PROMOTE} --app='myapp'`);
|
|
79
79
|
});
|
|
80
80
|
it('should build correct command with all parameters', async () => {
|
|
81
81
|
mocks.herokuRepl.executeCommand.resolves('Promoting myapp to production... done\n');
|
|
@@ -84,7 +84,7 @@ describe('Pipeline Tools', () => {
|
|
|
84
84
|
to: 'production'
|
|
85
85
|
});
|
|
86
86
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
87
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_PROMOTE} --app=myapp --to=production`);
|
|
87
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_PROMOTE} --app='myapp' --to='production'`);
|
|
88
88
|
});
|
|
89
89
|
});
|
|
90
90
|
describe('pipelines:list', () => {
|
|
@@ -139,7 +139,7 @@ describe('Pipeline Tools', () => {
|
|
|
139
139
|
mocks.herokuRepl.executeCommand.resolves('=== myapp-pipeline\nStaging: myapp-staging\nProduction: myapp-prod\n');
|
|
140
140
|
await toolCallback({ pipeline: 'myapp-pipeline' });
|
|
141
141
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
142
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_INFO} -- myapp-pipeline`);
|
|
142
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_INFO} -- 'myapp-pipeline'`);
|
|
143
143
|
});
|
|
144
144
|
it('should build correct command with all parameters', async () => {
|
|
145
145
|
mocks.herokuRepl.executeCommand.resolves('{"pipeline": "myapp-pipeline", "apps": {...}}\n');
|
|
@@ -148,7 +148,7 @@ describe('Pipeline Tools', () => {
|
|
|
148
148
|
json: true
|
|
149
149
|
});
|
|
150
150
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
151
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_INFO} --json -- myapp-pipeline`);
|
|
151
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_INFO} --json -- 'myapp-pipeline'`);
|
|
152
152
|
});
|
|
153
153
|
});
|
|
154
154
|
describe('pipelines', () => {
|
package/dist/tools/ps.spec.js
CHANGED
|
@@ -27,7 +27,7 @@ describe('Process Management Tools', () => {
|
|
|
27
27
|
mocks.herokuRepl.executeCommand.resolves('=== run: one-off processes\n=== web: web processes\nweb.1: up\n');
|
|
28
28
|
await toolCallback({ app: 'myapp' });
|
|
29
29
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
30
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS} --app=myapp`);
|
|
30
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS} --app='myapp'`);
|
|
31
31
|
});
|
|
32
32
|
it('should build correct command with all parameters', async () => {
|
|
33
33
|
mocks.herokuRepl.executeCommand.resolves('=== run: one-off processes\n=== web: web processes\nweb.1: up\n');
|
|
@@ -36,7 +36,7 @@ describe('Process Management Tools', () => {
|
|
|
36
36
|
json: true
|
|
37
37
|
});
|
|
38
38
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
39
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS} --app=myapp --json`);
|
|
39
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS} --app='myapp' --json`);
|
|
40
40
|
});
|
|
41
41
|
it('should handle error response', async () => {
|
|
42
42
|
const errorResponse = '<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n';
|
|
@@ -73,7 +73,7 @@ describe('Process Management Tools', () => {
|
|
|
73
73
|
mocks.herokuRepl.executeCommand.resolves('Scaling dynos... done, now running web at 2:Standard-1X\n');
|
|
74
74
|
await toolCallback({ app: 'myapp', dyno: 'web=2' });
|
|
75
75
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
76
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_SCALE} --app=myapp -- web=2`);
|
|
76
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_SCALE} --app='myapp' -- 'web=2'`);
|
|
77
77
|
});
|
|
78
78
|
it('should build correct command with remote parameter', async () => {
|
|
79
79
|
mocks.herokuRepl.executeCommand.resolves('Scaling dynos... done, now running web at 2:Standard-1X\n');
|
|
@@ -82,7 +82,7 @@ describe('Process Management Tools', () => {
|
|
|
82
82
|
dyno: 'web=2'
|
|
83
83
|
});
|
|
84
84
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
85
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_SCALE} --app=myapp -- web=2`);
|
|
85
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_SCALE} --app='myapp' -- 'web=2'`);
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
describe('ps:restart', () => {
|
|
@@ -105,7 +105,7 @@ describe('Process Management Tools', () => {
|
|
|
105
105
|
mocks.herokuRepl.executeCommand.resolves('Restarting all dynos... done\n');
|
|
106
106
|
await toolCallback({ app: 'myapp' });
|
|
107
107
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
108
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app=myapp`);
|
|
108
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app='myapp'`);
|
|
109
109
|
});
|
|
110
110
|
it('should build correct command with specific dyno', async () => {
|
|
111
111
|
mocks.herokuRepl.executeCommand.resolves('Restarting web.1 dyno... done\n');
|
|
@@ -114,7 +114,7 @@ describe('Process Management Tools', () => {
|
|
|
114
114
|
'dyno-name': 'web.1'
|
|
115
115
|
});
|
|
116
116
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
117
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app=myapp --dyno-name=web.1`);
|
|
117
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app='myapp' --dyno-name='web.1'`);
|
|
118
118
|
});
|
|
119
119
|
it('should build correct command with all parameters', async () => {
|
|
120
120
|
mocks.herokuRepl.executeCommand.resolves('Restarting web dynos... done\n');
|
|
@@ -124,7 +124,7 @@ describe('Process Management Tools', () => {
|
|
|
124
124
|
'process-type': 'web'
|
|
125
125
|
});
|
|
126
126
|
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
127
|
-
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app=myapp --dyno-name=web.1 --process-type=web`);
|
|
127
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app='myapp' --dyno-name='web.1' --process-type='web'`);
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
130
|
});
|
|
@@ -9,6 +9,20 @@
|
|
|
9
9
|
* input validation and reject them.
|
|
10
10
|
*/
|
|
11
11
|
const LINE_BREAK_PATTERN = /[\r\n]/;
|
|
12
|
+
/**
|
|
13
|
+
* Quotes a value so the Heroku CLI REPL treats it as a single, unexpanded token.
|
|
14
|
+
*
|
|
15
|
+
* The REPL re-tokenizes each stdin line with `shell-quote.parse` (then
|
|
16
|
+
* `yargs-parser`). POSIX single quotes are literal in that grammar: `$`,
|
|
17
|
+
* backticks, `|`, `;`, `#`, spaces, and backslashes are not expanded or split.
|
|
18
|
+
* An embedded apostrophe is encoded as `'\''` (end quote, escaped quote, restart).
|
|
19
|
+
*
|
|
20
|
+
* @param value - A single-line flag value or positional argument.
|
|
21
|
+
* @returns The value wrapped in single quotes, safe for `shell-quote.parse`.
|
|
22
|
+
*/
|
|
23
|
+
export function quoteForRepl(value) {
|
|
24
|
+
return `'${value.replaceAll("'", String.raw `'\''`)}'`;
|
|
25
|
+
}
|
|
12
26
|
/**
|
|
13
27
|
* A builder class for constructing Heroku CLI commands with flags and positional arguments.
|
|
14
28
|
* This class provides a fluent interface for building command-line arguments in a structured way.
|
|
@@ -52,7 +66,7 @@ export class CommandBuilder {
|
|
|
52
66
|
this.flags.push(`--${flag}`);
|
|
53
67
|
else {
|
|
54
68
|
CommandBuilder.assertNoLineBreaks('flag', flag, value);
|
|
55
|
-
this.flags.push(`--${flag}=${value}`);
|
|
69
|
+
this.flags.push(`--${flag}=${quoteForRepl(value)}`);
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
72
|
}
|
|
@@ -68,7 +82,7 @@ export class CommandBuilder {
|
|
|
68
82
|
for (const [name, value] of Object.entries(args)) {
|
|
69
83
|
if (value) {
|
|
70
84
|
CommandBuilder.assertNoLineBreaks('argument', name, value);
|
|
71
|
-
this.args.push(value);
|
|
85
|
+
this.args.push(quoteForRepl(value));
|
|
72
86
|
}
|
|
73
87
|
}
|
|
74
88
|
return this;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
+
import { parse } from 'shell-quote';
|
|
2
3
|
import { CommandBuilder } from './command-builder.js';
|
|
3
4
|
import { TOOL_COMMAND_MAP } from './tool-commands.js';
|
|
4
5
|
/**
|
|
@@ -21,12 +22,12 @@ describe('CommandBuilder', () => {
|
|
|
21
22
|
it('adds string flags with values correctly', () => {
|
|
22
23
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
23
24
|
builder.addFlags({ team: 'my-team', space: 'my-space' });
|
|
24
|
-
expect(builder.build()).to.equal(
|
|
25
|
+
expect(builder.build()).to.equal("apps --team='my-team' --space='my-space'");
|
|
25
26
|
});
|
|
26
27
|
it('handles mixed boolean and string flags', () => {
|
|
27
28
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
28
29
|
builder.addFlags({ all: true, team: 'my-team', json: true });
|
|
29
|
-
expect(builder.build()).to.equal(
|
|
30
|
+
expect(builder.build()).to.equal("apps --all --team='my-team' --json");
|
|
30
31
|
});
|
|
31
32
|
it('ignores undefined flag values', () => {
|
|
32
33
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
@@ -48,9 +49,15 @@ describe('CommandBuilder', () => {
|
|
|
48
49
|
expect(() => builder.addFlags({ team: 'my-team\nsecond-line' })).to.throw(/line breaks \(CR\/LF\) are not allowed/);
|
|
49
50
|
expect(() => builder.addFlags({ team: 'my-team\rother' })).to.throw(/line breaks/);
|
|
50
51
|
});
|
|
51
|
-
it('
|
|
52
|
+
it('quotes flag values that contain spaces (only line breaks are rejected)', () => {
|
|
52
53
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
53
54
|
expect(() => builder.addFlags({ team: 'my team' })).to.not.throw();
|
|
55
|
+
expect(builder.build()).to.equal("apps --team='my team'");
|
|
56
|
+
});
|
|
57
|
+
it('POSIX-quotes apostrophes inside flag values', () => {
|
|
58
|
+
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
59
|
+
builder.addFlags({ team: "it's" });
|
|
60
|
+
expect(builder.build()).to.equal("apps --team='it'\\''s'");
|
|
54
61
|
});
|
|
55
62
|
it('names the offending flag and the "flag" kind in the error message', () => {
|
|
56
63
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
@@ -61,17 +68,17 @@ describe('CommandBuilder', () => {
|
|
|
61
68
|
it('adds positional arguments correctly', () => {
|
|
62
69
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.RENAME_APP);
|
|
63
70
|
builder.addPositionalArguments({ new_name: 'new-app-name' });
|
|
64
|
-
expect(builder.build()).to.equal(
|
|
71
|
+
expect(builder.build()).to.equal("apps:rename -- 'new-app-name'");
|
|
65
72
|
});
|
|
66
73
|
it('adds multiple positional arguments in order', () => {
|
|
67
74
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.TRANSFER_APP);
|
|
68
75
|
builder.addPositionalArguments({ app: 'my-app', recipient: 'user@example.com' });
|
|
69
|
-
expect(builder.build()).to.equal(
|
|
76
|
+
expect(builder.build()).to.equal("apps:transfer -- 'my-app' 'user@example.com'");
|
|
70
77
|
});
|
|
71
78
|
it('ignores undefined argument values', () => {
|
|
72
79
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.RENAME_APP);
|
|
73
80
|
builder.addPositionalArguments({ app: undefined, new_name: 'new-app-name' });
|
|
74
|
-
expect(builder.build()).to.equal(
|
|
81
|
+
expect(builder.build()).to.equal("apps:rename -- 'new-app-name'");
|
|
75
82
|
});
|
|
76
83
|
it('supports method chaining', () => {
|
|
77
84
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.RENAME_APP);
|
|
@@ -91,7 +98,7 @@ describe('CommandBuilder', () => {
|
|
|
91
98
|
it('combines flags and positional arguments correctly', () => {
|
|
92
99
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.CREATE_APP);
|
|
93
100
|
builder.addFlags({ region: 'eu', team: 'my-team' }).addPositionalArguments({ app: 'my-new-app' });
|
|
94
|
-
expect(builder.build()).to.equal(
|
|
101
|
+
expect(builder.build()).to.equal("apps:create --region='eu' --team='my-team' -- 'my-new-app'");
|
|
95
102
|
});
|
|
96
103
|
it('handles commands with no flags or arguments', () => {
|
|
97
104
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
@@ -105,12 +112,12 @@ describe('CommandBuilder', () => {
|
|
|
105
112
|
it('handles commands with only positional arguments', () => {
|
|
106
113
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.RENAME_APP);
|
|
107
114
|
builder.addPositionalArguments({ new_name: 'new-app-name' });
|
|
108
|
-
expect(builder.build()).to.equal(
|
|
115
|
+
expect(builder.build()).to.equal("apps:rename -- 'new-app-name'");
|
|
109
116
|
});
|
|
110
117
|
it('maintains flag and argument order across multiple calls', () => {
|
|
111
118
|
const builder = new CommandBuilder(TOOL_COMMAND_MAP.CREATE_APP);
|
|
112
119
|
builder.addFlags({ region: 'eu' }).addPositionalArguments({ app: 'my-app' }).addFlags({ team: 'my-team' });
|
|
113
|
-
expect(builder.build()).to.equal(
|
|
120
|
+
expect(builder.build()).to.equal("apps:create --region='eu' --team='my-team' -- 'my-app'");
|
|
114
121
|
});
|
|
115
122
|
it('can never emit a command containing carriage returns or line feeds', () => {
|
|
116
123
|
// Validation rejects CR/LF at add-time, so a value with a line break is never
|
|
@@ -123,7 +130,33 @@ describe('CommandBuilder', () => {
|
|
|
123
130
|
expect(() => builder.addPositionalArguments({ app: 'my-app\rsecond-line' })).to.throw(/line breaks \(CR\/LF\) are not allowed/);
|
|
124
131
|
const command = builder.build();
|
|
125
132
|
expect(command).to.not.match(/[\r\n]/);
|
|
126
|
-
expect(command).to.equal(
|
|
133
|
+
expect(command).to.equal("apps:create --region='eu'");
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe('heroku repl tokenization (shell-quote.parse)', () => {
|
|
137
|
+
it('keeps a space-injected --confirm= in version as one flag token (W-23972762)', () => {
|
|
138
|
+
const command = new CommandBuilder('pg:upgrade')
|
|
139
|
+
.addFlags({ app: 'prod-db-app', version: '14 --confirm=prod-db-app' })
|
|
140
|
+
.build();
|
|
141
|
+
expect(command).to.equal("pg:upgrade --app='prod-db-app' --version='14 --confirm=prod-db-app'");
|
|
142
|
+
const tokens = parse(command).filter((token) => typeof token === 'string');
|
|
143
|
+
expect(tokens).to.deep.equal(['pg:upgrade', '--app=prod-db-app', '--version=14 --confirm=prod-db-app']);
|
|
144
|
+
expect(tokens.some((token) => token.startsWith('--confirm='))).to.equal(false);
|
|
145
|
+
});
|
|
146
|
+
it('does not expand or split $, backticks, |, ;, or # in flag values', () => {
|
|
147
|
+
const payload = '14 $HOME `id` | cat ; echo hi # comment';
|
|
148
|
+
const command = new CommandBuilder('pg:upgrade').addFlags({ version: payload }).build();
|
|
149
|
+
const tokens = parse(command).filter((token) => typeof token === 'string');
|
|
150
|
+
expect(tokens).to.deep.equal(['pg:upgrade', `--version=${payload}`]);
|
|
151
|
+
expect(tokens.some((token) => typeof token === 'object')).to.equal(false);
|
|
152
|
+
});
|
|
153
|
+
it('round-trips apostrophes and keeps a positional value as one token', () => {
|
|
154
|
+
const command = new CommandBuilder('apps:rename')
|
|
155
|
+
.addFlags({ app: 'prod-db-app' })
|
|
156
|
+
.addPositionalArguments({ new_name: "it's a name --confirm=prod-db-app" })
|
|
157
|
+
.build();
|
|
158
|
+
const tokens = parse(command).filter((token) => typeof token === 'string');
|
|
159
|
+
expect(tokens).to.deep.equal(['apps:rename', '--app=prod-db-app', '--', "it's a name --confirm=prod-db-app"]);
|
|
127
160
|
});
|
|
128
161
|
});
|
|
129
162
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heroku/mcp-server",
|
|
3
3
|
"description": "Heroku Platform MCP Server",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.9",
|
|
5
5
|
"author": "Heroku",
|
|
6
6
|
"bugs": "https://github.com/heroku/heroku-mcp-server/issues",
|
|
7
7
|
"bin": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@types/chai": "^5.2.1",
|
|
26
26
|
"@types/mocha": "^10.0.10",
|
|
27
27
|
"@types/node": "^22.x",
|
|
28
|
-
"@types/
|
|
29
|
-
"@types/
|
|
28
|
+
"@types/shell-quote": "^1.7.5",
|
|
29
|
+
"@types/sinon": "^22.0.0",
|
|
30
30
|
"chai": "^6.2.2",
|
|
31
31
|
"eslint": "^9",
|
|
32
32
|
"eslint-config-oclif": "^6.0.144",
|
|
@@ -35,8 +35,9 @@
|
|
|
35
35
|
"mocha": "^11.3.0",
|
|
36
36
|
"nyc": "^18.0.0",
|
|
37
37
|
"prettier": "^3.8.1",
|
|
38
|
+
"shell-quote": "^1.10.0",
|
|
38
39
|
"shx": "^0.4.0",
|
|
39
|
-
"sinon": "^
|
|
40
|
+
"sinon": "^22.1.0",
|
|
40
41
|
"tsx": "^4.21.0",
|
|
41
42
|
"typescript": "^5.9.3"
|
|
42
43
|
},
|