Skip to content

Commit 1d9afd4

Browse files
aseemxslaileni-aws
andauthored
fix(amazonq): Fix mock fs clean; Node version upgrade (aws#2324)
* fix: update the node version to 24 * Fix mock-fs Windows compatibility by using relative cache paths * style: fix code formatting for mock-fs test files * fix: use fake timers in chat-client tests for Node.js 24 compatibility Node.js 24 has stricter timer handling that caused setTimeout calls in production code to hang tests. Using fake timers ensures proper test isolation and prevents timeouts. * style: fix prettier formatting for chat-client test * fix: stub handleChatPrompt in mynahUi test to prevent timeout * fix: update test assertion to match stubbed behavior * fix: use proper module reference for handleChatPrompt stub * fix: make test async and wait for setTimeout calls to complete * fix: stub setTimeout to execute immediately and increase test timeout * fix: add setTimeout stubs to all sendGenericCommand tests --------- Co-authored-by: laileni <[email protected]>
1 parent 45b86be commit 1d9afd4

File tree

10 files changed

+45
-20
lines changed

10 files changed

+45
-20
lines changed

.github/workflows/create-agent-standalone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup Node.js
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: '20'
22+
node-version: '24'
2323
cache: 'npm'
2424

2525
- name: Install dependencies

.github/workflows/create-agentic-github-prerelease.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
- name: Setup Node.js
102102
uses: actions/setup-node@v4
103103
with:
104-
node-version: '20'
104+
node-version: '24'
105105
cache: 'npm'
106106

107107
# To run a ts script to create the manifest

.github/workflows/create-release-candidate-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Setup Node.js
4343
uses: actions/setup-node@v4
4444
with:
45-
node-version: '20'
45+
node-version: '24'
4646
cache: 'npm'
4747

4848
# Needed to format the json file being checked in

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Set up Node
3838
uses: actions/setup-node@v4
3939
with:
40-
node-version: 18
40+
node-version: 24
4141
- name: Download build artifacts
4242
uses: actions/download-artifact@v4
4343
with:

.github/workflows/lsp-ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Node
1616
uses: actions/setup-node@v3
1717
with:
18-
node-version: 18
18+
node-version: 24
1919
- name: Build
2020
run: |
2121
npm ci
@@ -38,7 +38,7 @@ jobs:
3838
- name: Set up Node
3939
uses: actions/setup-node@v3
4040
with:
41-
node-version: 18
41+
node-version: 24
4242
- name: Build
4343
run: |
4444
npm ci
@@ -63,7 +63,7 @@ jobs:
6363
- name: Set up Node
6464
uses: actions/setup-node@v3
6565
with:
66-
node-version: 18
66+
node-version: 24
6767
- name: Build
6868
run: |
6969
npm ci
@@ -79,7 +79,7 @@ jobs:
7979
- name: Set up Node
8080
uses: actions/setup-node@v3
8181
with:
82-
node-version: 18
82+
node-version: 24
8383
- name: Build
8484
run: |
8585
npm ci

.github/workflows/npm-packaging.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Node
1616
uses: actions/setup-node@v3
1717
with:
18-
node-version: 18
18+
node-version: 24
1919
- name: Install dependencies
2020
run: npm ci
2121
- name: Build all monorepo packages

.github/workflows/release-please.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- name: Setup Nodejs
5151
uses: actions/setup-node@v4
5252
with:
53-
node-version: '20.x'
53+
node-version: '24.x'
5454
registry-url: 'https://registry.npmjs.org'
5555
scope: '@aws'
5656
if: ${{ fromJson(steps.release.outputs.releases_created) }}

chat-client/src/client/mynahUi.test.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,16 @@ describe('MynahUI', () => {
246246
})
247247

248248
describe('sendGenericCommand', () => {
249-
it('should create a new tab if none exits', () => {
249+
it('should create a new tab if none exits', function () {
250+
this.timeout(10000) // Increase timeout to 10 seconds
250251
// clear create tab stub since set up process calls it twice
251252
createTabStub.resetHistory()
253+
// Stub setTimeout to execute immediately
254+
const setTimeoutStub = sinon.stub(global, 'setTimeout').callsFake((fn: Function) => {
255+
fn()
256+
return {} as any
257+
})
258+
252259
const genericCommand = 'Explain'
253260
const selection = 'const x = 5;'
254261
const tabId = ''
@@ -258,12 +265,18 @@ describe('MynahUI', () => {
258265

259266
sinon.assert.calledOnceWithExactly(createTabStub, false)
260267
sinon.assert.calledThrice(updateStoreSpy)
268+
setTimeoutStub.restore()
261269
})
262270

263-
it('should create a new tab if current tab is loading', function (done) {
264-
this.timeout(8000)
271+
it('should create a new tab if current tab is loading', function () {
272+
this.timeout(10000)
265273
// clear create tab stub since set up process calls it twice
266274
createTabStub.resetHistory()
275+
// Stub setTimeout to execute immediately
276+
const setTimeoutStub = sinon.stub(global, 'setTimeout').callsFake((fn: Function) => {
277+
fn()
278+
return {} as any
279+
})
267280
getAllTabsStub.returns({ 'tab-1': { store: { loadingChat: true } } })
268281

269282
const genericCommand = 'Explain'
@@ -275,11 +288,16 @@ describe('MynahUI', () => {
275288

276289
sinon.assert.calledOnceWithExactly(createTabStub, false)
277290
sinon.assert.calledThrice(updateStoreSpy)
278-
done()
291+
setTimeoutStub.restore()
279292
})
280293

281294
it('should not create a new tab if one exists already', () => {
282295
createTabStub.resetHistory()
296+
// Stub setTimeout to execute immediately
297+
const setTimeoutStub = sinon.stub(global, 'setTimeout').callsFake((fn: Function) => {
298+
fn()
299+
return {} as any
300+
})
283301
const genericCommand = 'Explain'
284302
const selection = 'const x = 5;'
285303
const tabId = 'tab-1'
@@ -289,9 +307,15 @@ describe('MynahUI', () => {
289307

290308
sinon.assert.notCalled(createTabStub)
291309
sinon.assert.calledOnce(updateStoreSpy)
310+
setTimeoutStub.restore()
292311
})
293312

294313
it('should call handleChatPrompt when sendGenericCommand is called', () => {
314+
// Stub setTimeout to execute immediately
315+
const setTimeoutStub = sinon.stub(global, 'setTimeout').callsFake((fn: Function) => {
316+
fn()
317+
return {} as any
318+
})
295319
const genericCommand = 'Explain'
296320
const selection = 'const x = 5;'
297321
const tabId = 'tab-1'
@@ -321,6 +345,7 @@ describe('MynahUI', () => {
321345
loadingChat: true,
322346
promptInputDisabledState: false,
323347
})
348+
setTimeoutStub.restore()
324349
})
325350
})
326351

core/aws-lsp-core/src/content/cache/uriCacheRepository.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import path = require('path')
1212
describe('Test UriCacheRepository', async () => {
1313
const sampleUri = URI.parse('https://aws.amazon.com/')
1414
const currentTimeMs = 1234
15-
const metadataPath = '//cache/cachedUris/metadata'
15+
const metadataPath = 'cache/cachedUris/metadata'
1616

1717
let timeProviderStub: SinonStubbedInstance<TimeProvider>
1818

1919
let sut: UriCacheRepository
2020

2121
beforeEach(async () => {
2222
mockfs({
23-
'//cache': {
23+
cache: {
2424
cachedUris: {
2525
metadata: '{}',
2626
},
@@ -30,7 +30,7 @@ describe('Test UriCacheRepository', async () => {
3030
timeProviderStub = stub(new TimeProvider())
3131
timeProviderStub.currentMilliseconds.returns(currentTimeMs)
3232

33-
sut = new UriCacheRepository('//cache', timeProviderStub)
33+
sut = new UriCacheRepository('cache', timeProviderStub)
3434
})
3535

3636
afterEach(async () => {
@@ -89,7 +89,7 @@ describe('Test UriCacheRepository', async () => {
8989
})
9090

9191
function getCachePath(uri: URI): string {
92-
return path.join('//cache/cachedUris', getHash(uri))
92+
return path.join('cache/cachedUris', getHash(uri))
9393
}
9494

9595
function getHash(uri: URI): string {

core/aws-lsp-core/src/content/handlers/cachedContentHandler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('Test CachedContentHandler', async () => {
4343

4444
beforeEach(async () => {
4545
mockfs({
46-
'//cache': {
46+
cache: {
4747
cachedUris: {
4848
metadata: '{}',
4949
},
@@ -54,7 +54,7 @@ describe('Test CachedContentHandler', async () => {
5454
timeProviderStub = stub(new TimeProvider())
5555
timeProviderStub.currentMilliseconds.returns(currentTimeMs)
5656

57-
cacheRepository = new UriCacheRepository('//cache', timeProviderStub)
57+
cacheRepository = new UriCacheRepository('cache', timeProviderStub)
5858
sut = new CachedContentHandler({
5959
cacheRepository,
6060
timeProvider: timeProviderStub,

0 commit comments

Comments
 (0)