Skip to content

Commit e6c4617

Browse files
committed
feat: add test for Portkey Gateway port and image verification; update RunCommandParser logic
1 parent e5f4ed0 commit e6c4617

File tree

6 files changed

+534
-7
lines changed

6 files changed

+534
-7
lines changed

src/sources/run/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export class RunCommandParser implements SourceParser {
3737
while (i < parts.length) {
3838
const arg = parts[i];
3939

40-
if (arg.startsWith('-')) {
40+
// If we haven't found the image yet and the argument starts with a dash,
41+
// it's an option
42+
if (!imageFound && arg.startsWith('-')) {
4143
switch (arg) {
4244
case '-p':
4345
case '--publish':
@@ -66,9 +68,12 @@ export class RunCommandParser implements SourceParser {
6668
break;
6769

6870
default:
69-
// Skip other options
70-
if (arg.startsWith('--')) {
71-
i++; // Skip the value of the option if it exists
71+
// Some flags take arguments, some don't
72+
if (arg === '--rm' || arg === '-d' || arg === '--detach') {
73+
// These are standalone flags - don't skip anything
74+
} else if (i + 1 < parts.length && !parts[i + 1].startsWith('-')) {
75+
// This option likely has a value - skip it
76+
i++;
7277
}
7378
}
7479
} else if (!imageFound) {
@@ -153,12 +158,15 @@ export class RunCommandParser implements SourceParser {
153158
const parts: string[] = [];
154159
let current = '';
155160
let inQuotes = false;
161+
let quoteChar = '';
156162

157163
for (let i = 0; i < command.length; i++) {
158164
const char = command[i];
159165

160-
if (char === '\'' || char === '"') {
166+
if ((char === '\'' || char === '"') && (inQuotes === false || quoteChar === char)) {
161167
inQuotes = !inQuotes;
168+
if (inQuotes) quoteChar = char;
169+
else quoteChar = '';
162170
continue;
163171
}
164172

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: '3'
2+
services:
3+
portkey:
4+
image: portkeyai/gateway:latest
5+
ports:
6+
- "8787:8787"

test/e2e/docker-run-files/test5.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker run --rm -p 8787:8787 portkeyai/gateway:latest

test/e2e/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { runTest1 } from './test1';
44
import { runTest2 } from './test2';
55
import { runTest3 } from './test3';
66
import { runTest4 } from './test4';
7+
import { runTest5 } from './test5';
78

89
// Constants for directories
910
const OUTPUT_DIR = join(__dirname, 'output');
@@ -39,10 +40,14 @@ async function runAllTests() {
3940
const test3Passed = await runTest3();
4041
testResults.push({ testName: 'Test 3: Environment Variable Substitution', passed: test3Passed });
4142

42-
// Run Test 4: Render Translation Only (Schema validation removed)
43+
// Run Test 4: Render Translation Only (Schema validation)
4344
const test4Passed = await runTest4();
4445
testResults.push({ testName: 'Test 4: Render Translation Only', passed: test4Passed });
4546

47+
// Run Test 5: Portkey Gateway Port and Image Verification
48+
const test5Passed = await runTest5();
49+
testResults.push({ testName: 'Test 5: Portkey Gateway Port and Image Verification', passed: test5Passed });
50+
4651
// Print summary
4752
console.log('\n=== Test Summary ===');
4853
const passedTests = testResults.filter(r => r.passed);

0 commit comments

Comments
 (0)