Skip to content

test(slack): add 40 tests for Slack approval integration — 0% to full coverage#565

Merged
agents-squads[bot] merged 1 commit intodevelopfrom
solve/issue-555
Mar 9, 2026
Merged

test(slack): add 40 tests for Slack approval integration — 0% to full coverage#565
agents-squads[bot] merged 1 commit intodevelopfrom
solve/issue-555

Conversation

@kokevidaurre
Copy link
Contributor

Summary

  • Add comprehensive test suite for src/lib/slack.ts (previously 0% coverage)
  • 40 tests covering all 10 exported functions
  • All tests use mocked fetch and fs — no external API calls

Changes

  • test/slack.test.ts — new test file

Test Coverage

Function Tests
slackApi Auth header, POST body, error handling
isSlackConfigured Env var presence/absence
getApprovalTier YAML parsing for all 4 tiers + defaults
getSquadChannelId Found, not found, API error
postNotification With blocks, unconfigured, channel missing, post failure
postApprovalRequest Approve buttons, notify (no buttons)
waitForApproval Reactions, context text, timeout
requestApprovalAndWait Auto/notify/approve tier routing, fallback
createSquadChannel Create, topic, name_taken fallback
notifyTonightStart/Complete Dedup squads, emoji selection

Testing

  • npx vitest run test/slack.test.ts — 40/40 pass
  • npm run build — passes

Closes #555


🤖 Generated with Agents Squads

Attribution Value
Agent engineering/issue-solver
Squad engineering
Model claude-opus-4-6
Target develop

Closes #555

Add 40 tests covering all exported functions in src/lib/slack.ts (previously 0% coverage):
- slackApi: auth header, POST body, error handling
- isSlackConfigured: env var check
- getApprovalTier: YAML parsing for auto/notify/approve/confirm tiers
- getSquadChannelId: channel lookup and error cases
- postNotification: message posting with blocks
- postApprovalRequest: approval buttons and notify tier
- waitForApproval: reaction polling, context parsing, timeout
- requestApprovalAndWait: tier routing and fallback behavior
- createSquadChannel: creation, topic setting, name_taken handling
- notifyTonightStart/Complete: session notification formatting

Co-Authored-By: engineering/issue-solver <engineering-issue-solver@agents-squads.com>

Agent: engineering/issue-solver
Squad: engineering
Model: claude-opus-4-6
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness and reliability of the Slack integration by introducing a thorough suite of unit tests. By covering all key functions and mocking external dependencies, it ensures that the Slack module behaves correctly under various conditions, from API interactions to approval workflows, without relying on live external services. This foundational testing effort will prevent regressions and facilitate future development with greater confidence.

Highlights

  • Comprehensive Test Suite: Added a comprehensive test suite for the src/lib/slack.ts module, which previously had 0% test coverage.
  • Extensive Coverage: The new test suite includes 40 tests covering all 10 exported functions within the Slack integration module.
  • Mocked Dependencies: All tests utilize mocked fetch and fs to ensure no external API calls or file system operations are performed during testing, promoting isolated and fast execution.
Changelog
  • test/slack.test.ts
    • Added a new test file for Slack integration.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive test suite for the src/lib/slack.ts module, significantly improving code coverage and reliability. The tests are well-structured and cover a wide range of scenarios for all exported functions. My review includes a couple of suggestions to enhance the robustness and efficiency of the tests, primarily by avoiding brittle assertions and using fake timers for timeout tests.

Comment on lines +308 to +314
const postCall = mockFetch.mock.calls[1];
expect(postCall[0]).toBe('https://slack.com/api/chat.postMessage');
const body = JSON.parse(postCall[1].body);
expect(body.channel).toBe('C123');
expect(body.blocks).toHaveLength(2); // section + context
expect(body.blocks[0].text.text).toContain(':rocket:');
expect(body.blocks[1].elements[0].text).toBe('v1.0.0');

Choose a reason for hiding this comment

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

medium

Accessing mock calls by index (e.g., mockFetch.mock.calls[1]) can make tests brittle. If the number or order of preceding API calls changes in the function under test (or its dependencies), this test will break even if the chat.postMessage call itself is correct. A more robust approach is to find the specific call you want to inspect by its endpoint.

This pattern of accessing calls by index is also present in other tests within this file (e.g., for postApprovalRequest and notifyTonightComplete). Consider applying a similar fix there for improved test robustness.

      const postCall = mockFetch.mock.calls.find(
        (call) => call[0] === 'https://slack.com/api/chat.postMessage'
      );
      expect(postCall).toBeDefined();
      const body = JSON.parse(postCall![1].body);
      expect(body.channel).toBe('C123');
      expect(body.blocks).toHaveLength(2); // section + context
      expect(body.blocks[0].text.text).toContain(':rocket:');
      expect(body.blocks[1].elements[0].text).toBe('v1.0.0');

Comment on lines +503 to +525
it('throws on timeout', async () => {
process.env.SLACK_BOT_TOKEN = 'xoxb-test-token';
// Return pending state (actions still present, no reactions)
mockFetch.mockResolvedValue({
json: async () => ({
ok: true,
messages: [
{
ts: '1234.5678',
text: 'Approval',
blocks: [{ type: 'actions' }],
reactions: [],
},
],
}),
});

const { waitForApproval } = await import('../src/lib/slack');
// Use very short timeout (100ms) to avoid long test
await expect(waitForApproval('C123', '1234.5678', 100)).rejects.toThrow(
'Approval timeout'
);
});

Choose a reason for hiding this comment

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

medium

This timeout test will take approximately 3 seconds to run due to the hardcoded pollInterval of 3000ms in the waitForApproval function, despite the test's timeout being set to 100ms. This makes the test unnecessarily slow and the comment // Use very short timeout (100ms) to avoid long test misleading.

You can use vi.useFakeTimers() to control the passage of time and make the test execute instantly while still correctly testing the timeout logic.

    it('throws on timeout', async () => {
      vi.useFakeTimers();
      process.env.SLACK_BOT_TOKEN = 'xoxb-test-token';
      // Return pending state (actions still present, no reactions)
      mockFetch.mockResolvedValue({
        json: async () => ({
          ok: true,
          messages: [
            {
              ts: '1234.5678',
              text: 'Approval',
              blocks: [{ type: 'actions' }],
              reactions: [],
            },
          ],
        }),
      });

      const { waitForApproval } = await import('../src/lib/slack');
      const promise = waitForApproval('C123', '1234.5678', 100);

      // Advance timers to trigger the timeout logic in the polling loop
      await vi.advanceTimersByTimeAsync(3000);

      await expect(promise).rejects.toThrow('Approval timeout');
      vi.useRealTimers();
    });

@agents-squads agents-squads bot merged commit d00b6e1 into develop Mar 9, 2026
11 checks passed
@agents-squads agents-squads bot deleted the solve/issue-555 branch March 9, 2026 22:58
kokevidaurre pushed a commit that referenced this pull request Mar 9, 2026
Merged PR #565, closed 5 issues (init UX + slack tests), closed stale PR #533.
Open issues down from 20 to 15. PR #492 still awaiting founder merge.

Co-Authored-By: Claude <noreply@anthropic.com>
kokevidaurre pushed a commit that referenced this pull request Mar 9, 2026
Merged PR #565, closed 5 issues (init UX + slack tests), closed stale PR #533.
Open issues down from 20 to 15. PR #492 still awaiting founder merge.

Co-authored-by: Jorge Vidaurre <jorge@agents-squads.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant