Skip to content

Add test server modes to improve testing client library edge cases#68

Closed
DRMacIver wants to merge 3 commits intomainfrom
add-test-modes-for-sdk-coverage
Closed

Add test server modes to improve testing client library edge cases#68
DRMacIver wants to merge 3 commits intomainfrom
add-test-modes-for-sdk-coverage

Conversation

@DRMacIver
Copy link
Copy Markdown
Member

@DRMacIver DRMacIver commented Mar 26, 2026

New test server modes for SDK error handling coverage:

  • stop_test_on_start_span: StopTest during span operations
  • server_crash: Process exit mid-test
  • health_check_failure: Health check failure in test_done
  • server_error_in_results: Server error in test_done
  • flaky_replay: FlakyReplay error on generate

This is as part of the ongoing work to get rust coverage to 100% - there are a lot of paths that are hard to test without getting specific errors from the server, and this just gets the server to trigger them directly.

DRMacIver added a commit to hegeldev/hegel-rust that referenced this pull request Mar 26, 2026
Tests server error paths using the test server's error simulation modes:
- stop_test_on_start_span: covers StopTest during span operations
- health_check_failure: covers health check failure panic
- server_error_in_results: covers server error panic
- flaky_replay: covers FlakyReplay error handling

Requires hegel-core with new test modes (hegeldev/hegel-core#68).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DRMacIver DRMacIver force-pushed the add-test-modes-for-sdk-coverage branch from a529f8c to 100e02f Compare March 26, 2026 16:11
DRMacIver added a commit to hegeldev/hegel-rust that referenced this pull request Mar 26, 2026
Tests use HEGEL_PROTOCOL_TEST_MODE to exercise server error paths.
Currently hang due to server process lifecycle issue in TempRustProject
subprocesses — the HegelSession static doesn't clean up on panic.

Depends on hegeldev/hegel-core#68 for new test modes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DRMacIver DRMacIver force-pushed the add-test-modes-for-sdk-coverage branch 8 times, most recently from 2674796 to 991f01c Compare March 26, 2026 22:29
DRMacIver added a commit to hegeldev/hegel-rust that referenced this pull request Mar 26, 2026
Tests that use new test modes from hegeldev/hegel-core#68 (not yet
released) are skipped in CI where only the released hegel-core is
available. The requires_new_modes!() macro checks if the mode exists
before running the test.

Also: fall back to system hegel if local venv doesn't exist.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DRMacIver DRMacIver force-pushed the add-test-modes-for-sdk-coverage branch from 991f01c to 636cbd0 Compare March 27, 2026 06:22
@DRMacIver DRMacIver changed the title Add test server modes for SDK coverage testing Add test server modes to improve testing client library edge cases Mar 27, 2026
@DRMacIver DRMacIver force-pushed the add-test-modes-for-sdk-coverage branch 2 times, most recently from 193c85a to ff0c44f Compare March 27, 2026 06:27
New modes: stop_test_on_start_span, server_crash, health_check_failure,
server_error_in_results, flaky_replay. Plus conformance test classes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DRMacIver DRMacIver force-pushed the add-test-modes-for-sdk-coverage branch from ff0c44f to 935832b Compare March 27, 2026 06:28
DRMacIver and others added 2 commits March 27, 2026 06:32
- Add test_pool_commands_handled_before_start_span to exercise the
  new_pool/pool_add/generate branches in _handle_commands_until
- Split flaky_replay test into two: one that sends mark_complete
  (exercises the try success path) and one that doesn't (exercises
  the except timeout path)
- Fix TestServerCrash to expect ConnectionError with pytest.raises

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
These modules are already imported at the top of the file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread src/hegel/test_server.py
_send_test_done(test_channel)


def _mode_failed_no_reason(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Registering that I find this mode a little suss and maybe we should just assume this failure doesn't happen, but decided on balance that it's not a bad policy to have clients be a bit postel's law about servers, especially as we want to open up the protocol later.

@DRMacIver DRMacIver marked this pull request as ready for review March 27, 2026 06:39
@DRMacIver DRMacIver requested a review from Liam-DeVoe March 27, 2026 06:39
Comment thread src/hegel/conformance.py
Comment on lines +222 to +226
assert (
"health check" in result.stderr.lower()
or "Health check" in result.stderr
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand why we need two cases here. If we do then we should just check health check in s.lower(), because that subsumes Health check in s

Comment thread src/hegel/conformance.py
Comment on lines +202 to +220
class HealthCheckFailureConformance(ErrorHandlingConformance):
"""Conformance test for health check failure reported in test_done."""

test_mode = "health_check_failure"

def run(self, params: dict[str, Any]) -> None:
with tempfile.NamedTemporaryFile(mode="w", suffix=".jsonl") as f:
input_json = json.dumps(params)
result = subprocess.run(
[str(self.binary), input_json],
env={
**os.environ,
"CONFORMANCE_METRICS_FILE": f.name,
"CONFORMANCE_TEST_CASES": str(self.test_cases),
**self.extra_env(),
},
capture_output=True,
text=True,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can't be reimplementing ConformanceTest.run in subclasses. Why was this necessary? What hooks do we need to provide on ConformanceTest to make this not necesary?

@DRMacIver DRMacIver closed this Mar 31, 2026
@DRMacIver
Copy link
Copy Markdown
Member Author

Closing this as part of the general ditching the slop that came out of the previous iteration of 100% coverage work for rust.

@DRMacIver DRMacIver reopened this Mar 31, 2026
@DRMacIver DRMacIver closed this Mar 31, 2026
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