Skip to content

Enhance weekly financial reports workflow to include Slack reporting #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 8, 2025

Conversation

anatolyshipitz
Copy link
Collaborator

  • Updated the weeklyFinancialReportsWorkflow to integrate the sendReportToSlack function, allowing for the sending of financial reports directly to Slack.
  • Modified the workflow to return the Slack link instead of the financial data file link, improving the reporting process.
  • Added necessary mocks for sendReportToSlack in the corresponding test file to ensure proper testing of the new functionality.

These changes enhance the application's reporting capabilities by facilitating direct communication of financial reports via Slack, streamlining the workflow process.

anatolyshipitz and others added 9 commits June 11, 2025 18:29
- Introduced `formatCurrency` function to format numbers as USD currency, ensuring proper localization and rounding.
- Added `getRateByDate` function to retrieve rates from a historical dataset based on a specified date, with handling for undefined inputs and edge cases.
- Created unit tests for both functions to validate their functionality and accuracy, covering various scenarios for currency formatting and rate retrieval.

These additions enhance the utility functions for financial calculations and improve test coverage for the application.
- Updated the `getRateByDate` function to sort the rate history dates chronologically using a custom sorting function. This ensures that the dates are processed in the correct order, improving the accuracy of rate retrieval based on date.

These changes enhance the functionality of the rate retrieval process, ensuring more reliable data handling.
- Introduced `WeeklyFinancialReportRepository` class implementing `IWeeklyFinancialReportRepository` for generating weekly financial reports based on target units, employees, and projects.
- Added `IWeeklyFinancialReportRepository` interface and `GenerateReportInput` type for structured input handling.
- Created unit tests for the repository to validate report generation, ensuring correct summary and details output for various input scenarios, including handling of empty input arrays.

These changes enhance the financial reporting capabilities of the application, providing structured and detailed insights into weekly performance.
- Introduced `sendReportToSlack` function to handle sending financial reports to Slack, integrating data retrieval and message posting.
- Created unit tests for `sendReportToSlack` to validate successful report sending and error handling scenarios, ensuring robustness.
- Updated `weeklyFinancialReports/index.ts` to export the new function.

These changes enhance the application's ability to communicate financial reports via Slack, improving reporting capabilities and error management.
- Introduced a new method `processTargetUnit` to encapsulate the logic for processing each target unit, enhancing code readability and maintainability.
- Added `pushGroupByMarginality` method to categorize groups based on their marginality level, streamlining the report generation process.
- Refactored the report title generation into a private method `composeWeeklyReportTitle` for better organization.
- Updated the report details and summary formatting using `WeeklyFinancialReportFormatter`, ensuring consistent output structure.

These changes enhance the clarity and efficiency of the weekly financial report generation process, making it easier to manage and extend in the future.
- Updated the `weeklyFinancialReportsWorkflow` to integrate the `sendReportToSlack` function, allowing for the sending of financial reports directly to Slack.
- Modified the workflow to return the Slack link instead of the financial data file link, improving the reporting process.
- Added necessary mocks for `sendReportToSlack` in the corresponding test file to ensure proper testing of the new functionality.

These changes enhance the application's reporting capabilities by facilitating direct communication of financial reports via Slack, streamlining the workflow process.
@anatolyshipitz anatolyshipitz requested a review from killev as a code owner July 2, 2025 11:17
Copy link

coderabbitai bot commented Jul 2, 2025

📝 Walkthrough

Walkthrough

The workflow for weekly financial reports was updated to call a new activity, sendReportToSlack, after fetching financial data. The workflow now returns the result from this new activity. Corresponding tests were updated to mock and verify the new activity and its interactions.

Changes

Files/Paths Change Summary
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts Added sendReportToSlack activity call; workflow now returns its result instead of previous output.
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts Added mocks and assertions for sendReportToSlack; updated expected results and verifications.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Workflow
    participant getTargetUnits
    participant fetchFinancialAppData
    participant sendReportToSlack

    Caller->>Workflow: weeklyFinancialReportsWorkflow(groupName)
    Workflow->>getTargetUnits: getTargetUnits(groupName)
    getTargetUnits-->>Workflow: fileLink
    Workflow->>fetchFinancialAppData: fetchFinancialAppData(fileLink)
    fetchFinancialAppData-->>Workflow: resultLink
    Workflow->>sendReportToSlack: sendReportToSlack(fileLink, resultLink)
    sendReportToSlack-->>Workflow: slackLink
    Workflow-->>Caller: slackLink
Loading

Possibly related PRs

Suggested reviewers

  • killev
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@anatolyshipitz anatolyshipitz requested review from killev and removed request for killev July 2, 2025 11:17
@anatolyshipitz anatolyshipitz self-assigned this Jul 2, 2025
Copy link

github-actions bot commented Jul 2, 2025

🔍 Vulnerabilities of temporal-test:latest

📦 Image Reference temporal-test:latest
digestsha256:da30eca7154c7c4cb2616e31f7411021ea9146d5b15c68adf2a57df4c52b164c
vulnerabilitiescritical: 2 high: 7 medium: 0 low: 0
platformlinux/amd64
size218 MB
packages358
📦 Base Image alpine:3
also known as
  • 3.21
  • 3.21.3
  • latest
digestsha256:1c4eef651f65e2f7daee7ee785882ac164b02b78fb74503052a26dc061c90474
vulnerabilitiescritical: 0 high: 0 medium: 0 low: 0
critical: 1 high: 0 medium: 0 low: 0 stdlib 1.23.6 (golang)

pkg:golang/[email protected]

critical : CVE--2025--22871

Affected range<1.23.8
Fixed version1.23.8
EPSS Score0.023%
EPSS Percentile4th percentile
Description

The net/http package improperly accepts a bare LF as a line terminator in chunked data chunk-size lines. This can permit request smuggling if a net/http server is used in conjunction with a server that incorrectly accepts a bare LF as part of a chunk-ext.

critical: 1 high: 0 medium: 0 low: 0 stdlib 1.23.2 (golang)

pkg:golang/[email protected]

critical : CVE--2025--22871

Affected range<1.23.8
Fixed version1.23.8
EPSS Score0.023%
EPSS Percentile4th percentile
Description

The net/http package improperly accepts a bare LF as a line terminator in chunked data chunk-size lines. This can permit request smuggling if a net/http server is used in conjunction with a server that incorrectly accepts a bare LF as part of a chunk-ext.

critical: 0 high: 1 medium: 0 low: 0 golang.org/x/crypto 0.32.0 (golang)

pkg:golang/golang.org/x/[email protected]

high : CVE--2025--22869

Affected range<0.35.0
Fixed version0.35.0
EPSS Score0.135%
EPSS Percentile34th percentile
Description

SSH servers which implement file transfer protocols are vulnerable to a denial of service attack from clients which complete the key exchange slowly, or not at all, causing pending content to be read into memory, but never transmitted.

critical: 0 high: 1 medium: 0 low: 0 github.com/golang-jwt/jwt/v4 4.5.1 (golang)

pkg:golang/github.com/golang-jwt/[email protected]#v4

high 8.7: CVE--2025--30204 Asymmetric Resource Consumption (Amplification)

Affected range<4.5.2
Fixed version4.5.2
CVSS Score8.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
EPSS Score0.025%
EPSS Percentile5th percentile
Description

Summary

Function parse.ParseUnverified currently splits (via a call to strings.Split) its argument (which is untrusted data) on periods.

As a result, in the face of a malicious request whose Authorization header consists of Bearer followed by many period characters, a call to that function incurs allocations to the tune of O(n) bytes (where n stands for the length of the function's argument), with a constant factor of about 16. Relevant weakness: CWE-405: Asymmetric Resource Consumption (Amplification)

Details

See parse.ParseUnverified

Impact

Excessive memory allocation

critical: 0 high: 1 medium: 0 low: 0 github.com/golang-jwt/jwt 3.2.2+incompatible (golang)

pkg:golang/github.com/golang-jwt/[email protected]%2Bincompatible

high 8.7: CVE--2025--30204 Asymmetric Resource Consumption (Amplification)

Affected range>=3.2.0
<=3.2.2
Fixed versionNot Fixed
CVSS Score8.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
EPSS Score0.025%
EPSS Percentile5th percentile
Description

Summary

Function parse.ParseUnverified currently splits (via a call to strings.Split) its argument (which is untrusted data) on periods.

As a result, in the face of a malicious request whose Authorization header consists of Bearer followed by many period characters, a call to that function incurs allocations to the tune of O(n) bytes (where n stands for the length of the function's argument), with a constant factor of about 16. Relevant weakness: CWE-405: Asymmetric Resource Consumption (Amplification)

Details

See parse.ParseUnverified

Impact

Excessive memory allocation

critical: 0 high: 1 medium: 0 low: 0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc 0.36.4 (golang)

pkg:golang/go.opentelemetry.io/contrib/[email protected]#google.golang.org/grpc/otelgrpc

high 7.5: CVE--2023--47108 Allocation of Resources Without Limits or Throttling

Affected range<0.46.0
Fixed version0.46.0
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score2.678%
EPSS Percentile85th percentile
Description

Summary

The grpc Unary Server Interceptor opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go

// UnaryServerInterceptor returns a grpc.UnaryServerInterceptor suitable
// for use in a grpc.NewServer call.
func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {

out of the box adds labels

  • net.peer.sock.addr
  • net.peer.sock.port

that have unbound cardinality. It leads to the server's potential memory exhaustion when many malicious requests are sent.

Details

An attacker can easily flood the peer address and port for requests.

PoC

Apply the attached patch to the example and run the client multiple times. Observe how each request will create a unique histogram and how the memory consumption increases during it.

Impact

In order to be affected, the program has to configure a metrics pipeline, use UnaryServerInterceptor, and does not filter any client IP address and ports via middleware or proxies, etc.

Others

It is similar to already reported vulnerabilities.

Workaround for affected versions

As a workaround to stop being affected, a view removing the attributes can be used.

The other possibility is to disable grpc metrics instrumentation by passing otelgrpc.WithMeterProvider option with noop.NewMeterProvider.

Solution provided by upgrading

In PR #4322, to be released with v0.46.0, the attributes were removed.

References

critical: 0 high: 1 medium: 0 low: 0 golang.org/x/oauth2 0.7.0 (golang)

pkg:golang/golang.org/x/[email protected]

high : CVE--2025--22868

Affected range<0.27.0
Fixed version0.27.0
EPSS Score0.069%
EPSS Percentile22nd percentile
Description

An attacker can pass a malicious malformed token which causes unexpected memory to be consumed during parsing.

critical: 0 high: 1 medium: 0 low: 0 c-ares 1.34.3-r0 (apk)

pkg:apk/alpine/[email protected]?os_name=alpine&os_version=3.21

high : CVE--2025--31498

Affected range<1.34.5-r0
Fixed version1.34.5-r0
EPSS Score0.154%
EPSS Percentile37th percentile
Description
critical: 0 high: 1 medium: 0 low: 0 golang.org/x/oauth2 0.26.0 (golang)

pkg:golang/golang.org/x/[email protected]

high : CVE--2025--22868

Affected range<0.27.0
Fixed version0.27.0
EPSS Score0.069%
EPSS Percentile22nd percentile
Description

An attacker can pass a malicious malformed token which causes unexpected memory to be consumed during parsing.

Base automatically changed from feature/add-sendReportToSlack-activity to main July 3, 2025 07:28
@anatolyshipitz anatolyshipitz enabled auto-merge (squash) July 3, 2025 08:44
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (2)

78-78: Update test description to reflect the new return value.

The test description "returns fileLink on success" is now outdated since the workflow returns a Slack confirmation message instead of a file link.

-  it('returns fileLink on success', async () => {
+  it('returns Slack confirmation on success', async () => {

96-96: Consider adding error handling test for the new activity.

The test suite covers error propagation from getTargetUnits and fetchFinancialAppData, but there's no corresponding test for error propagation from sendReportToSlack. This would ensure comprehensive error handling coverage.

Add this test after the existing error handling tests:

it('propagates error from sendReportToSlack', async () => {
  getTargetUnitsMock.mockResolvedValueOnce({ fileLink: 'file.json' });
  fetchFinancialAppDataMock.mockResolvedValueOnce({
    fileLink: 'result.json',
  });
  sendReportToSlackMock.mockRejectedValueOnce(new Error('slack error'));
  await expect(
    weeklyFinancialReportsWorkflow(GroupNameEnum.SD_REPORT),
  ).rejects.toThrow('slack error');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1b5b38 and a0affa5.

📒 Files selected for processing (2)
  • workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (2 hunks)
  • workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: speedandfunction/automatization#0
File: .cursor/rules/temporal-project-structure.mdc:0-0
Timestamp: 2025-06-24T12:29:48.641Z
Learning: Workflow and activity logic in Temporal projects should be kept modular and well-tested, and all naming (workflows, activities, task queues) should be clear and descriptive to enhance code quality and maintainability.
Learnt from: anatolyshipitz
PR: speedandfunction/automatization#34
File: workers/main/src/workflows/financial/FinancialReportFormatter.ts:3-7
Timestamp: 2025-05-30T17:57:21.010Z
Learning: User anatolyshipitz prefers to keep code implementations simple during early development stages rather than adding comprehensive error handling and validation. They consider extensive type annotations and error handling "redundant" when focusing on core functionality and testing.
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (2)
Learnt from: CR
PR: speedandfunction/automatization#0
File: .cursor/rules/temporal-project-structure.mdc:0-0
Timestamp: 2025-06-24T12:29:48.641Z
Learning: When introducing new Temporal workers or workflows, it is essential to avoid duplicating logic already present in shared modules and to update documentation with every significant change to workflows or activities.
Learnt from: CR
PR: speedandfunction/automatization#0
File: .cursor/rules/temporal-project-structure.mdc:0-0
Timestamp: 2025-06-24T12:29:48.641Z
Learning: Workflow and activity logic in Temporal projects should be kept modular and well-tested, and all naming (workflows, activities, task queues) should be clear and descriptive to enhance code quality and maintainability.
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (2)
Learnt from: CR
PR: speedandfunction/automatization#0
File: .cursor/rules/temporal-project-structure.mdc:0-0
Timestamp: 2025-06-24T12:29:48.641Z
Learning: Workflow and activity logic in Temporal projects should be kept modular and well-tested, and all naming (workflows, activities, task queues) should be clear and descriptive to enhance code quality and maintainability.
Learnt from: CR
PR: speedandfunction/automatization#0
File: .cursor/rules/temporal-project-structure.mdc:0-0
Timestamp: 2025-06-24T12:29:48.641Z
Learning: When introducing new Temporal workers or workflows, it is essential to avoid duplicating logic already present in shared modules and to update documentation with every significant change to workflows or activities.
🧬 Code Graph Analysis (2)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (1)
workers/main/src/activities/weeklyFinancialReports/sendReportToSlack.ts (1)
  • sendReportToSlack (8-36)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (1)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (1)
  • weeklyFinancialReportsWorkflow (13-26)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Docker Security Scanning (temporal, Dockerfile.temporal, temporal-test:latest)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: Service Availability Check
  • GitHub Check: SonarQube
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.ts (2)

8-11: LGTM: Clean integration of the new Slack reporting activity.

The sendReportToSlack activity is properly integrated into the proxied activities with consistent timeout configuration. The implementation maintains the modular structure as recommended in the project guidelines.


25-25: LGTM: Correct parameter passing to the new activity.

The workflow correctly passes both file links (targetUnits.fileLink and finData.fileLink) to the sendReportToSlack activity, matching the expected parameters from the activity implementation in workers/main/src/activities/weeklyFinancialReports/sendReportToSlack.ts.

workers/main/src/workflows/weeklyFinancialReports/weeklyFinancialReports.workflow.test.ts (2)

11-11: LGTM: Comprehensive mock setup for the new activity.

The mock setup for sendReportToSlack follows the existing patterns and includes proper reset in beforeEach. The integration is consistent with the existing test structure.

Also applies to: 17-17, 21-21, 29-29, 37-39, 44-44


83-83: LGTM: Correct test updates for the new activity.

The test properly verifies that:

  • sendReportToSlack is called with the correct parameters ('file.json' and 'result.json')
  • The workflow returns the result from sendReportToSlack ('slack-link.json')

Also applies to: 88-88, 91-94

Copy link

sonarqubecloud bot commented Jul 4, 2025

Copy link
Contributor

@killev killev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@anatolyshipitz anatolyshipitz merged commit b9b27b8 into main Jul 8, 2025
17 of 18 checks passed
@anatolyshipitz anatolyshipitz deleted the feature/add-slack-reporting branch July 8, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants