Skip to content

Commit eae3652

Browse files
committed
fix tests
1 parent 5a4ca89 commit eae3652

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

exercises/05.changes/02.problem.resources-list-changed/src/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,11 +676,11 @@ test('ListChanged notification: tools', async () => {
676676
const initialTools = await client.listTools()
677677
const initialToolNames = initialTools.tools.map((t) => t.name)
678678

679-
// Should not have advanced tools initially
679+
// Should not have tools requiring exisitng entries
680680
expect(
681681
initialToolNames,
682-
'🚨 Advanced tools like create_wrapped_video should not be available initially',
683-
).not.toContain('create_wrapped_video')
682+
'🚨 Tools requiring entries like get_entry should not be available initially',
683+
).not.toContain('get_entry')
684684

685685
// Trigger a DB change that should enable additional tools
686686
await client.callTool({
@@ -722,8 +722,8 @@ test('ListChanged notification: tools', async () => {
722722
const enabledToolNames = enabledTools.tools.map((t) => t.name)
723723
expect(
724724
enabledToolNames,
725-
'🚨 Advanced tools like create_wrapped_video should be enabled after creating entries/tags. The server must dynamically enable/disable tools based on content.',
726-
).toContain('create_wrapped_video')
725+
'🚨 Tools requiring entries like get_entry should be enabled after creating entries/tags. The server must dynamically enable/disable tools based on content.',
726+
).toContain('get_entry')
727727

728728
// Verify that tools are properly enabled with correct count
729729
expect(

exercises/05.changes/02.solution.resources-list-changed/src/index.test.ts

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ test('ListChanged notification: resources', async () => {
599599
},
600600
)
601601

602+
// Initially resources should be disabled/empty
603+
const initialResources = await client.listResources()
604+
expect(
605+
initialResources.resources,
606+
'🚨 Resources should initially be empty when no entries/tags exist',
607+
).toHaveLength(0)
608+
602609
// Trigger a DB change that should enable resources
603610
await client.callTool({
604611
name: 'create_tag',
@@ -615,6 +622,7 @@ test('ListChanged notification: resources', async () => {
615622
},
616623
})
617624

625+
// Should receive resource listChanged notification
618626
let resourceNotif
619627
try {
620628
resourceNotif = await Promise.race([
@@ -625,13 +633,31 @@ test('ListChanged notification: resources', async () => {
625633
])
626634
} catch {
627635
throw new Error(
628-
'🚨 Did not receive resources/listChanged notification when expected. Make sure your server calls sendResourceListChanged when resources change.',
636+
'🚨 Did not receive resources/listChanged notification when expected. Make sure your server calls sendResourceListChanged when resources are enabled/disabled.',
629637
)
630638
}
631639
expect(
632640
resourceNotif,
633-
'🚨 Did not receive resources/listChanged notification when expected. Make sure your server calls sendResourceListChanged when resources change.',
641+
'🚨 Did not receive resources/listChanged notification when expected. Make sure your server calls sendResourceListChanged when resources are enabled/disabled.',
634642
).toBeDefined()
643+
644+
// After notification, resources should now be available
645+
const enabledResources = await client.listResources()
646+
expect(
647+
enabledResources.resources.length,
648+
'🚨 Resources should be enabled after creating entries/tags. The server must dynamically enable/disable resources based on content.',
649+
).toBeGreaterThan(0)
650+
651+
// Verify that resources are properly available
652+
const resourceUris = enabledResources.resources.map((r) => r.uri)
653+
expect(
654+
resourceUris.some((uri) => uri.includes('entries')),
655+
'🚨 Should have entry resources available after creating entries',
656+
).toBe(true)
657+
expect(
658+
resourceUris.some((uri) => uri.includes('tags')),
659+
'🚨 Should have tag resources available after creating tags',
660+
).toBe(true)
635661
})
636662

637663
test('ListChanged notification: tools', async () => {
@@ -646,7 +672,17 @@ test('ListChanged notification: tools', async () => {
646672
},
647673
)
648674

649-
// Trigger a DB change that should enable tools
675+
// Get initial tool list
676+
const initialTools = await client.listTools()
677+
const initialToolNames = initialTools.tools.map((t) => t.name)
678+
679+
// Should not have tools requiring exisitng entries
680+
expect(
681+
initialToolNames,
682+
'🚨 Tools requiring entries like get_entry should not be available initially',
683+
).not.toContain('get_entry')
684+
685+
// Trigger a DB change that should enable additional tools
650686
await client.callTool({
651687
name: 'create_tag',
652688
arguments: {
@@ -662,6 +698,7 @@ test('ListChanged notification: tools', async () => {
662698
},
663699
})
664700

701+
// Should receive tool listChanged notification
665702
let toolNotif
666703
try {
667704
toolNotif = await Promise.race([
@@ -679,4 +716,18 @@ test('ListChanged notification: tools', async () => {
679716
toolNotif,
680717
'🚨 Did not receive tools/listChanged notification when expected. Make sure your server notifies clients when tools are enabled/disabled.',
681718
).toBeDefined()
719+
720+
// After notification, additional tools should be available
721+
const enabledTools = await client.listTools()
722+
const enabledToolNames = enabledTools.tools.map((t) => t.name)
723+
expect(
724+
enabledToolNames,
725+
'🚨 Tools requiring entries like get_entry should be enabled after creating entries/tags. The server must dynamically enable/disable tools based on content.',
726+
).toContain('get_entry')
727+
728+
// Verify that tools are properly enabled with correct count
729+
expect(
730+
enabledTools.tools.length,
731+
'🚨 Should have more tools available after creating content',
732+
).toBeGreaterThan(initialTools.tools.length)
682733
})

0 commit comments

Comments
 (0)