Skip to content

Commit 055fd36

Browse files
authored
Merge pull request #151 from athkulk/1.7-changes
Add custom QCLI PostStartUp Notification
2 parents 204a475 + a24d64a commit 055fd36

File tree

2 files changed

+108
-5
lines changed

2 files changed

+108
-5
lines changed

patched-vscode/extensions/post-startup-notifications/src/extension.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import { POST_START_UP_STATUS_FILE, SERVICE_NAME_ENV_KEY, SERVICE_NAME_ENV_VALUE
44
import { StatusFile } from './types';
55
import * as chokidar from 'chokidar';
66

7+
// Simple method to check if user has seen a notification
8+
function hasUserSeen(context: vscode.ExtensionContext, notificationId: string): boolean {
9+
return context.globalState.get(`notification_seen_${notificationId}`) === true;
10+
}
11+
12+
// Simple method to mark notification as seen
13+
function markAsSeen(context: vscode.ExtensionContext, notificationId: string): void {
14+
context.globalState.update(`notification_seen_${notificationId}`, true);
15+
}
716

817
let previousStatus: string | undefined;
918
let watcher: chokidar.FSWatcher;
@@ -18,6 +27,9 @@ export function activate(context: vscode.ExtensionContext) {
1827
}
1928

2029
outputChannel = vscode.window.createOutputChannel('SageMaker Unified Studio Post Startup Notifications');
30+
31+
// Show Q CLI notification if user hasn't seen it before
32+
showQCliNotification(context);
2133

2234
try {
2335
watcher = chokidar.watch(POST_START_UP_STATUS_FILE, {
@@ -69,6 +81,31 @@ function processStatusFile() {
6981
}
7082
};
7183

84+
// Show Q CLI notification if user hasn't seen it before
85+
function showQCliNotification(context: vscode.ExtensionContext): void {
86+
const notificationId = 'smus_q_cli_notification';
87+
const message = 'The Amazon Q Command Line Interface (CLI) is installed. You can now access AI-powered assistance in your terminal.';
88+
const link = 'https://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/q-actions.html';
89+
const linkLabel = 'Learn More';
90+
91+
if (!hasUserSeen(context, notificationId)) {
92+
outputChannel.appendLine("User has not seen the notification")
93+
// Show notification with Learn More button
94+
vscode.window.showInformationMessage(
95+
message,
96+
{ modal: false },
97+
{ title: linkLabel, isCloseAffordance: false }
98+
).then((selection) => {
99+
if (selection && selection.title === linkLabel) {
100+
vscode.env.openExternal(vscode.Uri.parse(link));
101+
}
102+
103+
// Mark as seen regardless of which button was clicked
104+
markAsSeen(context, notificationId);
105+
});
106+
}
107+
}
108+
72109
export function deactivate() {
73110
if (watcher) {
74111
watcher.close();
@@ -77,4 +114,4 @@ export function deactivate() {
77114
if (outputChannel) {
78115
outputChannel.dispose();
79116
}
80-
}
117+
}

patched-vscode/extensions/post-startup-notifications/src/test/extension.test.ts

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ interface MockFSWatcher extends chokidar.FSWatcher {
1515
jest.mock('vscode', () => ({
1616
window: {
1717
showErrorMessage: jest.fn(),
18-
showInformationMessage: jest.fn(),
18+
showInformationMessage: jest.fn().mockReturnValue(Promise.resolve()),
1919
createOutputChannel: jest.fn()
20+
},
21+
env: {
22+
openExternal: jest.fn()
23+
},
24+
Uri: {
25+
parse: jest.fn(url => ({ toString: () => url }))
2026
}
2127
}));
2228

@@ -32,8 +38,15 @@ describe('SageMaker Unified Studio Extension Tests', () => {
3238
// Reset mocks
3339
jest.resetAllMocks();
3440

35-
// Setup context
36-
mockContext = { subscriptions: [] } as any;
41+
// Setup context with globalState for storage
42+
mockContext = {
43+
subscriptions: [],
44+
globalState: {
45+
get: jest.fn(),
46+
update: jest.fn(),
47+
keys: jest.fn().mockReturnValue([])
48+
}
49+
} as any;
3750

3851
// Setup watcher
3952
mockWatcher = {
@@ -189,6 +202,59 @@ describe('SageMaker Unified Studio Extension Tests', () => {
189202
});
190203
});
191204

205+
describe('Q CLI Notification Tests', () => {
206+
test('should show Q CLI notification with Learn More button', () => {
207+
// Set up globalState to simulate first-time user
208+
(mockContext.globalState.get as jest.Mock).mockReturnValue(undefined);
209+
210+
activate(mockContext);
211+
212+
// Verify notification is shown with correct message and button
213+
expect(vscode.window.showInformationMessage).toHaveBeenCalledWith(
214+
'The Amazon Q Command Line Interface (CLI) is installed. You can now access AI-powered assistance in your terminal.',
215+
{ modal: false },
216+
{ title: 'Learn More', isCloseAffordance: false }
217+
);
218+
});
219+
220+
test('should open documentation when Learn More is clicked', async () => {
221+
// Set up globalState to simulate first-time user
222+
(mockContext.globalState.get as jest.Mock).mockReturnValue(undefined);
223+
224+
// Mock the user clicking "Learn More"
225+
const mockSelection = { title: 'Learn More' };
226+
(vscode.window.showInformationMessage as jest.Mock).mockReturnValue(Promise.resolve(mockSelection));
227+
228+
activate(mockContext);
229+
230+
// Wait for the promise to resolve
231+
await new Promise(process.nextTick);
232+
233+
// Verify the documentation link is opened
234+
expect(vscode.env.openExternal).toHaveBeenCalledWith(
235+
expect.objectContaining({
236+
toString: expect.any(Function)
237+
})
238+
);
239+
240+
// Verify notification is marked as seen
241+
expect(mockContext.globalState.update).toHaveBeenCalledWith(
242+
'notification_seen_smus_q_cli_notification',
243+
true
244+
);
245+
});
246+
247+
test('should not show notification if already seen', () => {
248+
// Set up globalState to simulate returning user who has seen notification
249+
(mockContext.globalState.get as jest.Mock).mockReturnValue(true);
250+
251+
activate(mockContext);
252+
253+
// Verify notification is not shown again
254+
expect(vscode.window.showInformationMessage).not.toHaveBeenCalled();
255+
});
256+
});
257+
192258
describe('Deactivation Tests', () => {
193259
test('should cleanup resources properly', () => {
194260
activate(mockContext);
@@ -198,4 +264,4 @@ describe('SageMaker Unified Studio Extension Tests', () => {
198264
expect(mockOutputChannel.dispose).toHaveBeenCalled();
199265
});
200266
});
201-
});
267+
});

0 commit comments

Comments
 (0)