Skip to content

test(daemon): expand abbenay-service and consumer-auth unit coverage - #111

Merged
sudhirverma merged 3 commits into
mainfrom
improve-daemon-server-coverage
Aug 12, 2026
Merged

test(daemon): expand abbenay-service and consumer-auth unit coverage#111
sudhirverma merged 3 commits into
mainfrom
improve-daemon-server-coverage

Conversation

@sudhirverma

@sudhirverma sudhirverma commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Expand abbenay-service.test.ts with gRPC handler coverage (auth, streaming, MCP, config, sessions, providers)
  • Add consumer-auth edge-case tests (env variants, token matching, missing env values)
  • Remove tautological SessionChat simulations and authorizeConsumer spies; use real auth paths and withEnv cleanup
  • Address CodeRabbit review: deterministic env in consumer-auth tests, shared withEnv helper, fake-timer try/finally, handler assertion coverage

Commits

  • test(daemon): expand abbenay-service and consumer-auth unit coverage — comprehensive handler tests and consumer-auth edge cases
  • test(daemon): address CodeRabbit review on daemon server tests — explicit env maps, shared withEnv, timer cleanup, camelCase handler assertions

Coverage

File Lines Statements Branches Functions
abbenay-service.ts 99.4% 96.7% 83% 100%
consumer-auth.ts 100% 100% 98% 100%

Test plan

  • npx eslint src/daemon/server/abbenay-service.test.ts src/daemon/server/consumer-auth.test.ts src/daemon/server/test-env.ts
  • npx vitest run src/daemon/server/abbenay-service.test.ts src/daemon/server/consumer-auth.test.ts
  • npm test (full monorepo)
  • npm run ci:build

Add comprehensive gRPC handler tests for abbenay-service and edge-case
coverage for consumer-auth. Use real auth paths and withEnv cleanup instead
of tautological simulations and authorizeConsumer spies.
@github-actions github-actions Bot added the chore label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@sudhirverma, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 36 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 15e7e343-5263-4b53-acab-421592ffe160

📥 Commits

Reviewing files that changed from the base of the PR and between d57d173 and 0f5ea0c.

📒 Files selected for processing (3)
  • packages/daemon/src/daemon/server/abbenay-service.test.ts
  • packages/daemon/src/daemon/server/consumer-auth.test.ts
  • packages/daemon/src/daemon/server/test-env.ts
📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Expanded coverage for service handlers, policy conversion, authorization, sessions, streaming, configuration, MCP, web server, and status workflows.
    • Added validation for consumer authentication defaults, authentication bypass settings, missing tokens, and matching consumer selection.
    • Added round-trip coverage for consumer credentials and handling of empty policy collections.

Walkthrough

The PR expands daemon server test coverage for conversions, authorization, consumer authentication, unary handlers, streaming handlers, validation, persistence, and gRPC error mapping.

Changes

Daemon server test coverage

Layer / File(s) Summary
Test contracts and service harness
packages/daemon/src/daemon/server/abbenay-service.test.ts
Adds conversion and authorization tests, invocation helpers, stream fixtures, and mocked daemon state.
Consumer authentication behavior
packages/daemon/src/daemon/server/consumer-auth.test.ts
Tests loopback defaults, open-auth values, missing token variables, and configuration-order matching.
Unary handler coverage
packages/daemon/src/daemon/server/abbenay-service.test.ts
Covers registration, status, workspace, provider, secret, configuration, policy, web server, session, summarization, MCP, and validation handlers.
Chat and streaming handlers
packages/daemon/src/daemon/server/abbenay-service.test.ts
Covers Chat, SessionChat, VS Code streams, tool events, inline policies, authentication, persistence, and stream failures.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: cidrblock

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the expanded unit test coverage for both daemon server test files.
Description check ✅ Passed The description directly explains the added handler and consumer-auth tests, coverage, and validation steps.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.02%. Comparing base (6a3db8a) to head (0f5ea0c).

❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
+ Coverage   68.57%   78.02%   +9.45%     
==========================================
  Files          37       38       +1     
  Lines        4973     4979       +6     
  Branches     1568     1569       +1     
==========================================
+ Hits         3410     3885     +475     
+ Misses       1023      542     -481     
- Partials      540      552      +12     
Flag Coverage Δ
daemon 78.02% <66.66%> (+9.45%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/daemon/src/daemon/server/abbenay-service.test.ts (3)

871-884: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Restore fake timers and global spies in a finally block.

Shutdown installs fake timers and spies on process.emit. If any assertion between the setup and the teardown fails, vi.useRealTimers() and emitSpy.mockRestore() never run. Fake timers then leak into later tests in the same file and cause unrelated failures. The same pattern exists at lines 1382-1414 (VSCodeStream) and 2288-2322.

Use try { ... } finally { ... }, or move the timer setup and teardown into beforeEach/afterEach hooks in a nested describe.

♻️ Proposed change for the `Shutdown` test
   it('Shutdown acknowledges and schedules SIGTERM', async () => {
     vi.useFakeTimers();
     const emitSpy = vi.spyOn(process, 'emit').mockReturnValue(true as never);
-    const state = createMockState();
-    const service = createServiceHandlers(state);
-
-    const { error } = await invokeUnary(service.Shutdown, {});
-    expect(error).toBeNull();
-    vi.advanceTimersByTime(150);
-    expect(emitSpy).toHaveBeenCalledWith('SIGTERM', 'SIGTERM');
-
-    emitSpy.mockRestore();
-    vi.useRealTimers();
+    try {
+      const state = createMockState();
+      const service = createServiceHandlers(state);
+
+      const { error } = await invokeUnary(service.Shutdown, {});
+      expect(error).toBeNull();
+      vi.advanceTimersByTime(150);
+      expect(emitSpy).toHaveBeenCalledWith('SIGTERM', 'SIGTERM');
+    } finally {
+      emitSpy.mockRestore();
+      vi.useRealTimers();
+    }
   });

Also applies to: 1382-1414, 2288-2322

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/daemon/src/daemon/server/abbenay-service.test.ts` around lines 871 -
884, Update the Shutdown, VSCodeStream, and corresponding test around the later
referenced range so fake timers and process.emit spies are always cleaned up in
a finally block, even when setup or assertions fail; preserve the existing test
assertions and restore emitSpy before calling vi.useRealTimers().

121-130: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract withEnv into a shared test helper.

consumer-auth.test.ts defines the same withEnv function at lines 121-130 of that file. Move it to a shared test utility module and import it in both files.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/daemon/src/daemon/server/abbenay-service.test.ts` around lines 121 -
130, Move the duplicated withEnv helper from abbenay-service.test.ts and
consumer-auth.test.ts into a shared test utility module, preserving its
environment restoration behavior, then import and use the shared withEnv in both
test files and remove their local definitions.

2168-2213: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add assertions to the coverage-only invocations.

Lines 2168-2170 and 2195-2212 call handlers without checking any result. These calls raise line coverage but do not verify behavior. A regression in SummarizeSession, GetSession, ListSessions, DeleteSession, ReconnectMcpServer, ConfigureProvider, or RemoveProvider camelCase field handling would still pass.

Assert at minimum that each call returns no error, and that the camelCase field reached the mock. Example: expect(state.mcpClientPool.reconnect).toHaveBeenCalledWith('dyn-ok').

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/daemon/src/daemon/server/abbenay-service.test.ts` around lines 2168
- 2213, Add assertions to the coverage-only invocations in the test: verify
Register, ListModels, SummarizeSession, GetSession, ListSessions, DeleteSession,
ReconnectMcpServer, ConfigureProvider, and RemoveProvider return without errors,
and assert relevant mocks receive the expected camelCase-derived values,
including state.mcpClientPool.reconnect called with 'dyn-ok'.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/daemon/src/daemon/server/consumer-auth.test.ts`:
- Around line 111-115: Update the test for buildConsumerAuthContext to pass an
explicit environment map when invoking it, and apply the same deterministic
environment setup to matchConsumerByToken tests. Ensure ABBENAY_ALLOW_OPEN_AUTH
and NOT_SET_ENV cannot leak from process.env by explicitly setting or clearing
them and restoring any modified values after each test.

---

Nitpick comments:
In `@packages/daemon/src/daemon/server/abbenay-service.test.ts`:
- Around line 871-884: Update the Shutdown, VSCodeStream, and corresponding test
around the later referenced range so fake timers and process.emit spies are
always cleaned up in a finally block, even when setup or assertions fail;
preserve the existing test assertions and restore emitSpy before calling
vi.useRealTimers().
- Around line 121-130: Move the duplicated withEnv helper from
abbenay-service.test.ts and consumer-auth.test.ts into a shared test utility
module, preserving its environment restoration behavior, then import and use the
shared withEnv in both test files and remove their local definitions.
- Around line 2168-2213: Add assertions to the coverage-only invocations in the
test: verify Register, ListModels, SummarizeSession, GetSession, ListSessions,
DeleteSession, ReconnectMcpServer, ConfigureProvider, and RemoveProvider return
without errors, and assert relevant mocks receive the expected camelCase-derived
values, including state.mcpClientPool.reconnect called with 'dyn-ok'.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e28f6c12-4f6b-4267-82db-26bf142a1679

📥 Commits

Reviewing files that changed from the base of the PR and between b13b7b9 and d57d173.

📒 Files selected for processing (2)
  • packages/daemon/src/daemon/server/abbenay-service.test.ts
  • packages/daemon/src/daemon/server/consumer-auth.test.ts

Comment thread packages/daemon/src/daemon/server/consumer-auth.test.ts
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

Pass explicit env maps in consumer-auth tests, extract shared withEnv
helper, wrap fake-timer tests in try/finally, and assert camelCase handler
invocations instead of coverage-only calls.
@sudhirverma

Copy link
Copy Markdown
Contributor Author

Addressed CodeRabbit review feedback in a1d4e66:

  • Environment isolation (consumer-auth.test.ts): explicit env maps for buildConsumerAuthContext and matchConsumerByToken; afterEach clears NOT_SET_ENV and ABBENAY_ALLOW_OPEN_AUTH.
  • Fake timer cleanup (abbenay-service.test.ts): Shutdown and both VSCodeStream tests use try/finally so timers and spies always restore.
  • Shared withEnv: extracted to packages/daemon/src/daemon/server/test-env.ts.
  • Coverage-only handler calls: added error and mock assertions for camelCase Register/ListModels/SummarizeSession/GetSession/ListSessions/DeleteSession/ReconnectMcpServer/ConfigureProvider/RemoveProvider invocations.

@sathyapramod sathyapramod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!!

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
75.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sudhirverma
sudhirverma merged commit b265a2f into main Aug 12, 2026
12 of 14 checks passed
@sudhirverma
sudhirverma deleted the improve-daemon-server-coverage branch August 12, 2026 05:33
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.

4 participants