Skip to content

test(ssh): improve SSH proxy test coverage#1628

Open
fabiovincenzi wants to merge 10 commits into
finos:mainfrom
fabiovincenzi:ssh-test-coverage
Open

test(ssh): improve SSH proxy test coverage#1628
fabiovincenzi wants to merge 10 commits into
finos:mainfrom
fabiovincenzi:ssh-test-coverage

Conversation

@fabiovincenzi

Copy link
Copy Markdown
Contributor

Description

Add tests to improve SSH proxy coverage, focusing on the four modules with the most gaps:

  • server.ts: push flow (no-op detection, security chain integration, pack size/chunk limits, timeout), path validation, auth edge cases, debug mode
  • GitProtocol.ts: happy paths for all 4 exported functions
  • sshInternals.ts: all exported functions with failure modes and error messages
  • AgentForwarding.ts : CHANNEL_OPEN_CONFIRMATION handler, lock recovery

Related Issue

Resolves #1586

Checklist

General

Documentation

  • Documentation has been added/updated for any new features (N/A — test-only changes)

Configuration

  • If configuration schema (config.schema.json) was modified (N/A — no config changes)

Tests

  • Tests have been added/updated for new functionality
  • Unit tests pass (npm test)
  • Linting and formatting pass (npm run lint and npm run format:check)
  • Type checks pass (npm run check-types)

@netlify

netlify Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploy Preview for endearing-brigadeiros-63f9d0 canceled.

Name Link
🔨 Latest commit 944ed4d
🔍 Latest deploy log https://app.netlify.com/projects/endearing-brigadeiros-63f9d0/deploys/6a54de7685fdd30008b1a0bc

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.30%. Comparing base (15c4495) to head (944ed4d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1628      +/-   ##
==========================================
+ Coverage   85.75%   90.30%   +4.55%     
==========================================
  Files          84       84              
  Lines        8109     8109              
  Branches     1376     1466      +90     
==========================================
+ Hits         6954     7323     +369     
+ Misses       1126      757     -369     
  Partials       29       29              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

@fabiovincenzi fabiovincenzi changed the title Ssh test coverage test(ssh): improve SSH proxy test coverage Jul 1, 2026
@fabiovincenzi fabiovincenzi marked this pull request as ready for review July 3, 2026 09:31
@fabiovincenzi fabiovincenzi requested a review from a team as a code owner July 3, 2026 09:31

@jescalada jescalada 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.

Excellent work on getting our coverage back to standard! 🎉

Just a few minor comments/suggestions from me. I'd like to merge this ASAP for the coverage increase, despite conflicts with the Vitest 4 upgrade PR #1564. I'm happy to deal with failing tests later 🙂

// Both call validateSSHPrerequisites
vi.mocked(validateSSHPrerequisites).mockClear();

await fetchGitHubCapabilities(

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.

If fetchGitHubCapabilities defaults to true and then we assert that validateSSHPrerequisites was called, isn't that incompatible with the test's description?


function mockChannelModule(channelImpl?: (...args: unknown[]) => unknown) {
const mockChannel = { on: vi.fn(), write: vi.fn(), end: vi.fn() };
getChannelModuleSpy = vi.spyOn(sshInternals, 'getChannelModule').mockReturnValue({

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.

These mockReturnValue usages will likely fail after upgrading to Vitest 4 (underway in #1564).

If we merge this in first, and I can fix up any failing tests in that PR, otherwise you can fix those by passing in a function that returns an object, rather than the object itself.

Comment thread test/ssh/server.test.ts
} as any);

const debugServer = new SSHServer();
expect(debugServer).toBeDefined();

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.

We may want to check some other properties to make sure the server actually did start in debug mode 👍🏼

const ssh2 = await import('ssh2');
const Client = ssh2.Client as any;

const chunk1 = Buffer.from('0010chunk one\n');

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.

I think these pkt-line definitions might be wrong - though it's not clear why the test passes regardless:

0010 means the payload has 16 bytes, but the actual bytes in the payload is 14 (4 + 9 + 1):

"0010" = 4 bytes
"chunk one" = 9 bytes
"\n" = 1 byte

Same for the other chunk which excludes the flush.

Suggested change
const chunk1 = Buffer.from('0010chunk one\n');
const chunk1 = Buffer.from('000echunk one\n');

const Client = ssh2.Client as any;

const chunk1 = Buffer.from('0010chunk one\n');
const chunk2 = Buffer.from('0010chunk two\n0000');

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.

Suggested change
const chunk2 = Buffer.from('0010chunk two\n0000');
const chunk2 = Buffer.from('000echunk two\n0000');

const Client = ssh2.Client as any;

// Build a valid pkt-line payload with flush packet
// "0012hello world\n0000"

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.

This comment may also be inaccurate since "hello world\n" has 12 bytes + 2 + 2 = 16 bytes, or 0010 in hexadecimal

Suggested change
// "0012hello world\n0000"
// "0010hello world\n0000"

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.

Improve SSH Test Coverage

2 participants