Skip to content

test: add 121 unit tests for highest-impact coverage gaps#514

Merged
zbigniewsobiecki merged 2 commits intodevfrom
feature/test-coverage-improvements
Feb 23, 2026
Merged

test: add 121 unit tests for highest-impact coverage gaps#514
zbigniewsobiecki merged 2 commits intodevfrom
feature/test-coverage-improvements

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Feb 23, 2026

Summary

Implements 8 new test files targeting the highest-impact coverage gaps in the codebase, adding 121 new unit tests across core agent pipeline, gadgets, PM webhooks, and utilities.

  • tests/unit/agents/utils/agentLoop.test.ts (NEW) — 28 tests for runAgentLoop and truncateContent: event processing (text, gadget_call, gadget_result, stream_complete), loop detection/hard-stop, interactive mode, session completion injection, gadget-specific log context
  • tests/unit/agents/utils/logging.test.ts (NEW) — 7 tests for createAgentLogger: dual-write to console + file logger, null file logger support, all log levels
  • tests/unit/agents/utils/setup.test.ts (NEW) — 25 tests for getLogLevel, readContextFiles, installDependencies, warmTypeScriptCache: env var precedence, package manager detection, missing files, TypeScript error tolerance
  • tests/unit/agents/shared/syntheticCalls.test.ts (NEW) — 15 tests for injectSyntheticCall, injectDirectoryListing, injectContextFiles, injectSquintContext: invocation ID tracking, sequential IDs, squint fallback
  • tests/unit/agents/shared/builderFactory.test.ts (NEW) — 18 tests for isSquintEnabled and createConfiguredBuilder: budget enforcement, BudgetPricingUnavailableError handling, skipSessionState, postConfigure callback
  • tests/unit/pm/webhook-handler.test.ts (NEW) — 14 tests for processPMWebhook: invalid payload, queuing when busy, no project found, duplicate card skipping, pre-resolved triggers, ackCommentId passthrough, error recovery
  • tests/unit/triggers/builtins.test.ts (NEW) — 8 tests for registerBuiltInTriggers: total count, registration order (comment-mention before card-moved, JIRA comment before transition), all trigger categories present
  • tests/unit/utils/llmEnv.test.ts (NEW) — 6 tests for injectLlmApiKeys: env injection from DB, restore function removes injected key, restores original value, null credential handling

Test plan

  • All 121 new tests pass
  • Full test suite: 3,006 tests across 180 files, all passing
  • Lint: npm run lint passes cleanly (zero errors)
  • Typecheck: npm run typecheck passes cleanly (zero errors)

Card: https://trello.com/c/699c9f643c77d7c420a98233

🤖 Generated with Claude Code

@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 23, 2026

👍 Just a sec, looking into the unit tests for highest-impact coverage gaps

@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 23, 2026

Hi! I'm ready to address review feedback on this PR.

However, I don't see any review comments or requested changes yet. The PR appears to be freshly opened with CI checks still running.

Once reviewers provide feedback (review comments, requested changes, or suggestions), I'll be happy to:

  • Make the necessary code changes
  • Run tests and linting to verify
  • Commit and push the fixes
  • Reply to each comment explaining what was addressed

For now, let's wait for the CI checks to complete and for reviewers to provide their feedback. 🚀

@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 23, 2026

🔍 Reviewing code — Examining the PR changes for quality and correctness...

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

Summary

LGTM — well-structured test suite covering high-impact code paths across the agent pipeline, PM webhooks, triggers, and utilities. CI passes cleanly.

Minor Observations

Should Fix (non-blocking)

  • tests/unit/agents/utils/setup.test.ts:8-10 — Dead mock at ../../src/utils/repo.js does nothing. The comment on line 12 explains the correct mock is on line 13 (../../../../src/utils/repo.js), which matches how vitest resolves the relative import ../../utils/repo.js from the source module. The dead mock on line 8 should be removed to avoid confusion — it looks like a leftover from initial trial-and-error.

The tests are well-scoped, use appropriate mock granularity, correctly verify both happy and error paths, and the assertions match the actual source implementations I checked (llmEnv.ts, setup.ts, webhook-handler.ts). The helper factory functions (createBaseOptions, createMockAgent, createMockIntegration, etc.) keep the tests DRY without sacrificing readability.

Comment thread tests/unit/agents/utils/setup.test.ts Outdated

vi.mock('../../src/utils/repo.js', () => ({
runCommand: vi.fn(),
}));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: This mock at ../../src/utils/repo.js is dead code — it doesn't match any actual module resolution path from the test file. The real mock on line 13 (../../../../src/utils/repo.js) is the one that works. Consider removing lines 8-10 to avoid confusion.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed — removed the dead mock at ../../src/utils/repo.js (lines 8-10) and the now-unnecessary comment on line 12. The correct mock at ../../../../src/utils/repo.js remains. All 25 tests in the file still pass. Pushed in fbc309d.

@zbigniewsobiecki
Copy link
Copy Markdown
Member

@aaight address code review concerns

@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 23, 2026

Request Addressed

What was asked

Address code review concerns from @nhopeatall's review.

Changes Made

  • Removed dead mock at incorrect path ../../src/utils/repo.js (lines 8-10) in tests/unit/agents/utils/setup.test.ts
  • Removed the now-unnecessary explanatory comment on line 12
  • The correct mock at ../../../../src/utils/repo.js remains untouched

Verification

  • All 25 tests in setup.test.ts passing ✅
  • Lint (biome) passes cleanly ✅
  • Typecheck passes cleanly ✅
  • Pre-commit hooks (lint + typecheck) pass ✅
  • Pre-push hooks (full test suite) pass ✅

Remove unused vi.mock at incorrect path '../../src/utils/repo.js' that
doesn't match any actual module resolution path. The correct mock at
'../../../../src/utils/repo.js' on the next line is the one that works.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 23, 2026

🔍 Reviewing code — Examining the PR changes for quality and correctness...

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

LGTM — well-targeted test coverage addition.

All 8 test files accurately reflect their source implementations. I verified the test assertions against the actual source code for agentLoop.ts, logging.ts, setup.ts, syntheticCalls.ts, builderFactory.ts, webhook-handler.ts, builtins.ts, and llmEnv.ts. Highlights:

  • Mocking strategy is sound: Each file mocks only its direct dependencies, not transitive ones. The as never casts are a pragmatic approach for avoiding full type construction of complex internal types.
  • Edge cases covered well: truncateContent boundary at exact maxLen, warmTypeScriptCache treating tsc errors as success (matching the intentional design), injectLlmApiKeys restore function preserving original vs undefined values, processPMWebhook error recovery clearing the processing flag.
  • Assertions match actual behavior: Verified registerBuiltInTriggers count (16) and ordering against the source, budget withBudget conditional (> 0, not just truthy) matches the source's !== undefined && > 0 check, and webhook-handler tests correctly model the handleMatchedTrigger → resolveTriggerResult flow including pre-resolved result bypass.

CI passes (lint, typecheck, all 3,006 tests). No issues found.

@zbigniewsobiecki zbigniewsobiecki merged commit 6c69498 into dev Feb 23, 2026
5 checks passed
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.

3 participants