Skip to content

Commit 96aac5e

Browse files
committed
Merge remote-tracking branch 'upstream/master' into custom
2 parents 6b41c8a + 3f45c37 commit 96aac5e

File tree

6 files changed

+77
-9
lines changed

6 files changed

+77
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q /test: Truncating user input to 4096 characters for unit test generation."
4+
}

packages/amazonq/.vscode/tasks.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"problemMatcher": "$ts-webpack-watch",
4545
"options": {
4646
"cwd": "${workspaceFolder}/../../packages/core"
47-
}
47+
},
48+
"presentation": { "panel": "dedicated" }
4849
},
4950
{
5051
"label": "terminate",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424
"compileOnly": "tsc -p ./",
425425
"compileDev": "npm run compile -- --mode development",
426426
"webpackDev": "webpack --mode development",
427-
"serveVue": "webpack serve --config-name vue --mode development",
427+
"serveVue": "ts-node ./scripts/build/checkServerPort.ts && webpack serve --port 8080 --config-name vue --mode development",
428428
"watch": "npm run clean && npm run buildScripts && npm run compileOnly -- --watch",
429429
"lint": "ts-node ./scripts/lint/testLint.ts",
430430
"generateClients": "ts-node ./scripts/build/generateServiceClient.ts ",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* Validate that the required port used by webviews during development is not being used.
8+
*/
9+
10+
import * as net from 'net'
11+
12+
/** This must be kept up to date with the port that is being used to serve the vue files. */
13+
const portNumber = 8080
14+
15+
function checkPort(port: number): Promise<boolean> {
16+
return new Promise((resolve) => {
17+
const server = net.createServer()
18+
19+
server.once('error', (err) => {
20+
if ((err as NodeJS.ErrnoException).code === 'EADDRINUSE') {
21+
resolve(true)
22+
}
23+
})
24+
25+
server.once('listening', () => {
26+
server.close()
27+
resolve(false)
28+
})
29+
30+
server.listen(port)
31+
})
32+
}
33+
34+
async function main() {
35+
try {
36+
const isPortInUse = await checkPort(portNumber)
37+
38+
if (isPortInUse) {
39+
console.error(`
40+
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
41+
42+
ERROR: Webviews will not load as expected, meaning Q may not work.
43+
REASON: Port ${portNumber} is already in use, preventing the latest webview files from being served.
44+
SOLUTION: Kill the current process using port ${portNumber}.
45+
- Unix: "kill -9 $(lsof -t -i :${portNumber})"
46+
47+
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
48+
`)
49+
process.exit(1)
50+
}
51+
} catch (error) {
52+
console.error('Error checking port:', error)
53+
process.exit(1)
54+
}
55+
}
56+
57+
void main()

packages/core/src/amazonqTest/chat/controller/controller.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
testGenCompletedField,
2222
testGenProgressField,
2323
testGenSummaryMessage,
24+
maxUserPromptLength,
2425
} from '../../models/constants'
2526
import MessengerUtils, { ButtonActions } from './messenger/messengerUtils'
2627
import { getTelemetryReasonDesc, isAwsError } from '../../../shared/errors'
@@ -365,7 +366,8 @@ export class TestController {
365366
getLogger().debug('startTestGen tabId: %O', message.tabID)
366367
let fileName = ''
367368
let filePath = ''
368-
let userMessage = ''
369+
let userFacingMessage = ''
370+
let userPrompt = ''
369371
session.testGenerationStartTime = performance.now()
370372

371373
try {
@@ -381,6 +383,8 @@ export class TestController {
381383
)
382384
return
383385
}
386+
// Truncating the user prompt if the prompt is more than 4096.
387+
userPrompt = message.prompt.slice(0, maxUserPromptLength)
384388

385389
// check that the session is authenticated
386390
const authState = await AuthUtil.instance.getChatAuthState()
@@ -425,16 +429,16 @@ export class TestController {
425429
getLogger().debug(`File path: ${fileEditorToTest.document.uri.fsPath}`)
426430
filePath = fileEditorToTest.document.uri.fsPath
427431
fileName = path.basename(filePath)
428-
userMessage = message.prompt
432+
userFacingMessage = userPrompt
429433
? regenerateTests
430-
? `${message.prompt}`
431-
: `/test ${message.prompt}`
434+
? `${userPrompt}`
435+
: `/test ${userPrompt}`
432436
: `/test Generate unit tests for \`${fileName}\``
433437

434-
session.hasUserPromptSupplied = message.prompt.length > 0
438+
session.hasUserPromptSupplied = userPrompt.length > 0
435439

436440
// displaying user message prompt in Test tab
437-
this.messenger.sendMessage(userMessage, tabID, 'prompt')
441+
this.messenger.sendMessage(userFacingMessage, tabID, 'prompt')
438442
this.messenger.sendChatInputEnabled(tabID, false)
439443
this.sessionStorage.getSession().conversationState = ConversationState.IN_PROGRESS
440444
this.messenger.sendUpdatePromptProgress(message.tabID, testGenProgressField)
@@ -460,7 +464,7 @@ export class TestController {
460464
this.messenger.sendMessage(unsupportedMessage, tabID, 'answer')
461465
await this.onCodeGeneration(
462466
session,
463-
message.prompt,
467+
userPrompt,
464468
tabID,
465469
fileName,
466470
filePath,

packages/core/src/amazonqTest/models/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { BuildStatus } from '../chat/session/session'
1111
// For uniquely identifiying which chat messages should be routed to Test
1212
export const testChat = 'testChat'
1313

14+
export const maxUserPromptLength = 4096 // user prompt character limit from MPS and API model.
15+
1416
export const cancelTestGenButton: ChatItemButton = {
1517
id: ButtonActions.STOP_TEST_GEN,
1618
text: 'Cancel',

0 commit comments

Comments
 (0)