Skip to content

Commit 64b8b23

Browse files
committed
set stuff up for sync
1 parent 219e7ad commit 64b8b23

File tree

6 files changed

+66
-62
lines changed

6 files changed

+66
-62
lines changed

.github/scripts/fix_cdk_json.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ fix_boolean_number_key() {
3636
}
3737

3838
CFN_DRIFT_DETECTION_GROUP="epsam"
39+
IS_PULL_REQUEST="false"
3940
if [[ "$STACK_NAME" =~ -pr-[0-9]+$ ]]; then
4041
CFN_DRIFT_DETECTION_GROUP="epsam-pull-request"
42+
IS_PULL_REQUEST="true"
4143
fi
4244

4345
# go through all the key values we need to set
@@ -50,3 +52,4 @@ fix_string_key logLevel "${LOG_LEVEL}"
5052
fix_string_key slackBotToken "${SLACK_BOT_TOKEN}"
5153
fix_string_key slackSigningSecret "${SLACK_SIGNING_SECRET}"
5254
fix_string_key cfnDriftDetectionGroup "${CFN_DRIFT_DETECTION_GROUP}"
55+
fix_boolean_number_key isPullRequest "${IS_PULL_REQUEST}"

packages/cdk/stacks/EpsAssistMeStack.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class EpsAssistMeStack extends Stack {
3535
const account = Stack.of(this).account
3636
const logRetentionInDays = Number(this.node.tryGetContext("logRetentionInDays"))
3737
const logLevel: string = this.node.tryGetContext("logLevel")
38+
const isPullRequest: boolean = this.node.tryGetContext("isPullRequest")
3839

3940
// Get secrets from context or fail if not provided
4041
const slackBotToken: string = this.node.tryGetContext("slackBotToken")
@@ -179,7 +180,24 @@ export class EpsAssistMeStack extends Stack {
179180
value: storage.kbDocsBucket.bucket.bucketName,
180181
exportName: `${props.stackName}:kbDocsBucket:Name`
181182
})
182-
183+
if (isPullRequest) {
184+
new CfnOutput(this, "VERSION_NUMBER", {
185+
value: props.version,
186+
exportName: `${props.stackName}:local:VERSION-NUMBER`
187+
})
188+
new CfnOutput(this, "COMMIT_ID", {
189+
value: props.commitId,
190+
exportName: `${props.stackName}:local:COMMIT-ID`
191+
})
192+
new CfnOutput(this, "slackBotToken", {
193+
value: slackBotToken,
194+
exportName: `${props.stackName}:local:slackBotToken`
195+
})
196+
new CfnOutput(this, "slackSigningSecret", {
197+
value: slackSigningSecret,
198+
exportName: `${props.stackName}:local:slackSigningSecret`
199+
})
200+
}
183201
// Final CDK Nag Suppressions
184202
nagSuppressions(this)
185203
}

packages/slackBotFunction/app/handler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ def handler(event: dict, context: LambdaContext) -> dict:
2929
# register event handlers with the app
3030
app = get_app()
3131

32-
logger.info("Lambda invoked", extra={"is_async": event.get("async_processing", False)})
33-
3432
# handle async processing requests
3533
if event.get("async_processing"):
3634
slack_event_data = event.get("slack_event")

packages/slackBotFunction/app/slack/slack_handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def mention_handler(event, ack, body, client):
8888
- If text after the mention starts with 'feedback:', store it as additional feedback.
8989
- Otherwise, forward to the async processing pipeline (Q&A).
9090
"""
91+
logger.debug("Sending ack response")
9192
ack()
9293
event_id = _gate_common(event, body)
9394
if not event_id:
@@ -237,7 +238,10 @@ def thread_message_handler(event, event_id, client):
237238

238239
def unified_message_handler(event, ack, body, client):
239240
"""Handle all message events - DMs and channel messages"""
241+
logger.debug("Sending ack response")
240242
ack()
243+
bot_token = get_bot_token()
244+
respond_with_eyes(bot_token, event)
241245
event_id = _gate_common(event, body)
242246
if not event_id:
243247
return
@@ -253,6 +257,7 @@ def unified_message_handler(event, ack, body, client):
253257

254258
def feedback_handler(ack, body, client):
255259
"""Handle feedback button clicks (both positive and negative)."""
260+
logger.debug("Sending ack response")
256261
ack()
257262
try:
258263
action_id = body["actions"][0]["action_id"]
Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22

33

4-
def test_app_mention_handler_registered(
4+
def test_correct_handlers_registered(
55
mock_slack_app,
66
mock_env,
77
mock_get_parameter,
@@ -10,48 +10,25 @@ def test_app_mention_handler_registered(
1010
"""Test app mention handler execution by simulating the handler registration process"""
1111
# set up mocks
1212
# Create a mock app that captures the registered handlers
13-
registered_handlers = {}
13+
registered_action_handlers = {}
14+
registered_event_handlers = {}
1415

1516
def mock_event_decorator(event_type):
1617
def decorator(func):
17-
registered_handlers[event_type] = func
18+
registered_event_handlers[event_type] = func
1819
return func
1920

2021
return decorator
2122

22-
mock_slack_app.event = mock_event_decorator
23-
24-
# delete and import module to test
25-
if "app.slack.slack_handlers" in sys.modules:
26-
del sys.modules["app.slack.slack_handlers"]
27-
from app.slack.slack_handlers import setup_handlers
28-
29-
# perform operation
30-
setup_handlers(mock_slack_app)
31-
32-
# assertions
33-
assert "app_mention" in registered_handlers
34-
35-
36-
def test_message_handler_registered(
37-
mock_slack_app,
38-
mock_env,
39-
mock_get_parameter,
40-
lambda_context,
41-
):
42-
"""Test direct message handler execution by simulating the handler registration process"""
43-
# set up mocks
44-
# Create a mock app that captures the registered handlers
45-
registered_handlers = {}
46-
47-
def mock_event_decorator(event_type):
23+
def mock_action_decorator(event_type):
4824
def decorator(func):
49-
registered_handlers[event_type] = func
25+
registered_action_handlers[event_type] = func
5026
return func
5127

5228
return decorator
5329

5430
mock_slack_app.event = mock_event_decorator
31+
mock_slack_app.action = mock_action_decorator
5532

5633
# delete and import module to test
5734
if "app.slack.slack_handlers" in sys.modules:
@@ -62,4 +39,7 @@ def decorator(func):
6239
setup_handlers(mock_slack_app)
6340

6441
# assertions
65-
assert "message" in registered_handlers
42+
assert "app_mention" in registered_event_handlers
43+
assert "message" in registered_event_handlers
44+
assert "feedback_yes" in registered_action_handlers
45+
assert "feedback_no" in registered_action_handlers

packages/slackBotFunction/tests/test_slack_handlers.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,15 @@
33
from botocore.exceptions import ClientError
44

55

6-
def test_setup_handlers_registers_correctly(mock_env):
7-
"""Test that setup_handlers registers all handlers correctly"""
8-
# set up mocks
9-
mock_app = Mock()
10-
11-
# delete and import module to test
12-
if "app.slack.slack_handlers" in sys.modules:
13-
del sys.modules["app.slack.slack_handlers"]
14-
from app.slack.slack_handlers import setup_handlers
15-
16-
# perform operation
17-
setup_handlers(mock_app)
18-
19-
# assertions
20-
# Verify all handlers are registered
21-
assert mock_app.event.call_count == 2 # app_mention and unified message handler
22-
23-
246
@patch("app.utils.handler_utils.is_duplicate_event")
257
@patch("app.utils.handler_utils.trigger_async_processing")
268
@patch("app.utils.handler_utils.respond_with_eyes")
279
def test_app_mention_handler(
28-
mock_respond_with_eyes, mock_trigger_async_processing, mock_is_duplicate_event, mock_get_parameter, mock_env
10+
mock_respond_with_eyes: Mock,
11+
mock_trigger_async_processing: Mock,
12+
mock_is_duplicate_event: Mock,
13+
mock_get_parameter: Mock,
14+
mock_env: Mock,
2915
):
3016
"""Test app mention handler execution"""
3117
# set up mocks
@@ -45,7 +31,13 @@ def decorator(func):
4531
mock_app.event = capture_event
4632
mock_app.action = Mock()
4733
mock_ack = Mock()
48-
mock_event = {"user": "U123", "text": "<@U456> test", "channel": "C123"}
34+
mock_event = {
35+
"user": "U123",
36+
"text": "<@U456> test",
37+
"channel": "C123",
38+
"thread_ts": "123",
39+
"channel_type": "channel",
40+
}
4941
mock_body = {"event_id": "evt123"}
5042
mock_client = Mock()
5143
mock_is_duplicate_event.return_value = False
@@ -61,19 +53,26 @@ def decorator(func):
6153

6254
# assertions
6355
mock_ack.assert_called_once()
64-
mock_trigger_async_processing.assert_called_once()
56+
mock_trigger_async_processing.assert_called_once_with(
57+
{"event": mock_event, "event_id": "evt123", "bot_token": "test-token"}
58+
)
6559
mock_respond_with_eyes.assert_called_once()
6660

6761

6862
@patch("app.utils.handler_utils.is_duplicate_event")
6963
@patch("app.utils.handler_utils.trigger_async_processing")
7064
@patch("app.utils.handler_utils.respond_with_eyes")
7165
def test_message_handler_non_dm_skip(
72-
mock_respond_with_eyes, mock_trigger_async_processing, mock_is_duplicate_event, mock_get_parameter, mock_env
66+
mock_respond_with_eyes: Mock,
67+
mock_trigger_async_processing: Mock,
68+
mock_is_duplicate_event: Mock,
69+
mock_get_parameter: Mock,
70+
mock_env: Mock,
7371
):
7472
"""Test message handler skips non-DM messages"""
7573
# set up mocks
7674
mock_app = Mock()
75+
mock_is_duplicate_event.return_value = False
7776

7877
# Capture the message handler
7978
message_handler = None
@@ -107,19 +106,20 @@ def decorator(func):
107106
# assertions
108107
mock_ack.assert_called_once()
109108
mock_trigger_async_processing.assert_not_called() # Should not trigger for non-DM
109+
mock_respond_with_eyes.assert_called_once()
110110

111111

112112
@patch("app.utils.handler_utils.is_duplicate_event")
113113
@patch("app.utils.handler_utils.trigger_async_processing")
114114
@patch("app.utils.handler_utils.respond_with_eyes")
115115
@patch("app.slack.slack_events.store_feedback")
116116
def test_feedback_yes_action_handler(
117-
mock_store_feedback,
118-
mock_respond_with_eyes,
119-
mock_trigger_async_processing,
120-
mock_is_duplicate_event,
121-
mock_get_parameter,
122-
mock_env,
117+
mock_store_feedback: Mock,
118+
mock_respond_with_eyes: Mock,
119+
mock_trigger_async_processing: Mock,
120+
mock_is_duplicate_event: Mock,
121+
mock_get_parameter: Mock,
122+
mock_env: Mock,
123123
):
124124
"""Test feedback_yes action handler"""
125125
if "app.slack.slack_handlers" in sys.modules:

0 commit comments

Comments
 (0)