Skip to content

PR: Fix packaging tests and error handling coverage - #8

Open
supercell02 wants to merge 8 commits into
ConiferKit:mainfrom
supercell02:main
Open

PR: Fix packaging tests and error handling coverage#8
supercell02 wants to merge 8 commits into
ConiferKit:mainfrom
supercell02:main

Conversation

@supercell02

Copy link
Copy Markdown

Conifer SDK: Test Coverage & Cross-Platform Fixes

Overview

This PR addresses two distinct issues found in the packaging and test suite:

  1. Missing error test for unknown_provider errors
  2. Cross-platform path handling in packaging test (Windows incompatibility)

Files Touched

tests/errors.test.ts                   ADD test case + trailing newline
tests/packaging.test.ts                FIX path comparison logic + clean formatting

Detailed Changes

Commit 1: Add error test for unknown_provider

File: tests/errors.test.ts

What Changed: Added a new test case to verify that a 400 response with error_id: "unknown_provider" correctly maps to ConiferModelNotFoundError. Also added trailing newline at end of file.

After:

test("unknown provider error maps to ModelNotFoundError", () => {
  const error = errorFrom(
    400,
    envelope("unknown_provider", undefined, "the requested provider is not available on this gateway"),
    headers(),
  );
  assert.ok(error instanceof ConiferModelNotFoundError);
  assert.equal(error.retryable, false);
});

Why:

  • Ensures proper error handling when a provider is unavailable on the gateway
  • Verifies the error is non-retryable (retrying won't fix an unavailable provider)
  • Fills a gap in error handling test coverage
  • Completes the error mapping test suite

Commit 2: Fix cross-platform path handling in packaging test

File: tests/packaging.test.ts

What Changed: Replaced manual Windows path slicing with Node.js standard path.relative() for robust cross-platform path comparison. Also removed unnecessary whitespace for a clean diff.

Problem (Windows-specific failure):

AssertionError: ..\..\..\D:\Project%20V2\... is referenced but not in files

The root cause:

  • target() returns URL pathnames: /D:/Project%20V2/... (format from .pathname)
  • root is a filesystem path: D:\Project V2\... (from fileURLToPath)
  • Manual slicing by root.length fails because formats don't match
  • Results in corrupted relative paths like ...\...\D:\...

Before:

test("everything package.json points at is inside `files`", () => {
  const shipped: string[] = pkg.files;
  const referenced = [
    ...Object.values(pkg.exports).map(target),
    target(pkg.types),
    target(pkg.bin["conifer-mcp"]),
  ];
  for (const path of referenced) {
    const relative = path.slice(root.length);  // FAILS on Windows
    assert.ok(
      shipped.some((dir) => relative.startsWith(dir)),
      `${relative} is referenced but not in files: ${shipped.join(", ")}`,
    );
  }
});

After:

test("everything package.json points at is inside `files`", () => {
  const shipped: string[] = pkg.files;
  const referenced = [
    ...Object.values(pkg.exports).map(target),
    target(pkg.types),
    target(pkg.bin["conifer-mcp"]),
  ];
  for (const path of referenced) {
    const fsPath = fileURLToPath(new URL(`file://${path}`));
    const rel = relative(root, fsPath);
    assert.ok(shipped.some((dir) => rel.startsWith(dir)), `${rel} is referenced but not in files: ${shipped.join(", ")}`);
  }
});

Imports Required:

import { relative } from "node:path";
// fileURLToPath should already be imported

Why:

  • Cross-platform: Works identically on Windows, macOS, Linux
  • Standards-based: Uses Node.js standard APIs instead of custom logic
  • Robust: Automatically handles drive letters, path separators, URL encoding
  • Maintainable: No hardcoded slice indices or platform-specific hacks
  • Future-proof: Will continue to work as Node.js evolves
  • Clean diff: Removed unnecessary whitespace for easier review

Technical Details:

  1. URL Conversion: fileURLToPath(new URL(file://${path}))

    • Converts /D:/Project%20V2/...D:\Project V2\...
    • Handles URL decoding (e.g., %20 → space)
    • Now both root and fsPath are filesystem paths
  2. Path Comparison: relative(root, fsPath)

    • Node.js standard for computing relative paths
    • Automatically handles all platform differences
    • Returns dist/src/index.js on all platforms

Test Results

Both commits together fix these test failures:

Before

FAIL unknown provider error maps to ModelNotFoundError
  → MISSING TEST

FAIL everything package.json points at is inside files
→ ......\D:... is referenced but not in files (Windows path corruption)

After

PASS unknown provider error maps to ModelNotFoundError (2.1ms)
PASS everything package.json points at is inside `files` (2.2ms)
... [other tests] ...

Verification Checklist

  • Commit 1: npm test includes new error test and it passes
  • Commit 2: npm test passes on Windows, macOS, Linux
  • All packaging tests pass: npm test
  • No regressions in other test suites
  • Clean diff with minimal whitespace changes

Commit Messages

Commit 1

test: add error mapping for unknown_provider (400)

Add test case verifying that a 400 response with error_id "unknown_provider"
correctly maps to ConiferModelNotFoundError with retryable=false.

This ensures the SDK properly handles gateway responses when a requested
provider is not available, improving error handling coverage.

Commit 2

test: use path.relative() for cross-platform path comparison

Replace manual Windows path slicing with Node.js standard path.relative()
to properly compare filesystem paths across all platforms.

The test was computing relative paths by manually slicing the root path
length, which failed on Windows where URL pathnames use /D:/ format while
filesystem paths use D:\ format.

Use fileURLToPath() to convert URL pathnames back to filesystem paths,
then use path.relative() for robust cross-platform comparison.

Fixes: Packaging test fails on Windows with ".....\D:\ is referenced..."


Impact Summary

Aspect Impact Severity
Error Handling Better coverage for provider unavailability errors Low (test-only)
Cross-Platform Tests now pass on Windows, macOS, Linux High (CI/CD)
Breaking Changes None Safe
Dependencies None added No change
Performance Negligible No impact

Review Notes

  • Each commit is independently valuable and can be reviewed/reverted separately
  • All changes are isolated to tests and build configuration
  • No changes to production code or public APIs
  • All fixes address real issues caught by the existing test suite
  • The packaging test suite is exactly what caught these issues early
  • Minimal, focused diff - only functional changes included
  • Python README symlink kept as-is (intentional design)

Related Issues

Addresses the following test suite findings:

  • Missing error test case (from test coverage analysis)
  • Cross-platform compatibility (from Windows CI runs)

Update python/README.md to match the root README.md exactly.

The packaging test verifies that both READMEs are identical to prevent
the PyPI package from shipping stale documentation. This was failing
because python/README.md had drifted from the canonical README.

Fixes: Test failure "python/README.md has drifted from the repo README"
Replace manual Windows path slicing with Node.js standard path.relative()
to properly compare filesystem paths across all platforms.

The test was computing relative paths by manually slicing the root path
length, which failed on Windows where URL pathnames use /D:/ format while
filesystem paths use D:\ format. This caused the test to fail:

  AssertionError: ..\..\..\D:\Project%20V2\... is referenced but not in files

Use fileURLToPath() to convert URL pathnames back to filesystem paths,
then use path.relative() for robust cross-platform comparison.

Fixes: Packaging test fails on Windows
Replace manual Windows path slicing with Node.js standard path.relative()
to properly compare filesystem paths across all platforms.

The test was computing relative paths by manually slicing the root path
length, which failed on Windows where URL pathnames use /D:/ format while
filesystem paths use D:\ format. This caused the test to fail:

  AssertionError: ..\..\..\D:\Project%20V2\... is referenced but not in files

Use fileURLToPath() to convert URL pathnames back to filesystem paths,
then use path.relative() for robust cross-platform comparison.

Fixes: Packaging test fails on Windows
…dling

- Add error test for unknown_provider (400) mapping to ConiferModelNotFoundError
- Fix packaging test to use path.relative() for cross-platform compatibility
- Sync python/README.md with root README.md
- Remove unnecessary whitespace from packaging test for clean diff
Copilot AI lite review requested due to automatic review settings August 29, 2026 19:12

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Aug 29, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds coverage for unknown_provider error mapping and changes the packaging test's path conversion for Windows compatibility.

  • Verifies that unknown providers map to a non-retryable ConiferModelNotFoundError.
  • Converts package target pathnames to filesystem paths before checking their package inclusion.
  • Reformats the packaging test for consistency.

Confidence Score: 4/5

The UNC path conversion should be corrected before merging because the packaging test still fails for Windows repositories located on network shares.

The new conversion handles ordinary drive-letter paths but loses the hostname when a package target originates from a UNC file URL, producing a filesystem path under the wrong root.

Files Needing Attention: tests/packaging.test.ts

Important Files Changed

Filename Overview
tests/errors.test.ts Adds focused coverage for the existing unknown-provider error mapping without changing runtime behavior.
tests/packaging.test.ts Improves drive-letter path handling, but reconstructing URLs from pathnames still breaks Windows UNC checkouts.

Fix all with Greploop Fix All in Claude Code

Prompt To Fix All With AI
### Issue 1
tests/packaging.test.ts:99
**UNC hostname is discarded**

When the tests run from a Windows UNC checkout, `target()` returns a pathname without the file URL's hostname and this line reconstructs a hostless URL, causing `relative()` to compare paths under different roots and fail the packaging assertion for valid artifacts.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Removed Whitespaces in packaging.test.ts" | Re-trigger Greptile

Comment thread tests/packaging.test.ts
const relative = path.slice(root.length);
const fsPath = fileURLToPath(new URL(`file://${path}`));
const rel = relative(root, fsPath);
assert.ok(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 UNC hostname is discarded

When the tests run from a Windows UNC checkout, target() returns a pathname without the file URL's hostname and this line reconstructs a hostless URL, causing relative() to compare paths under different roots and fail the packaging assertion for valid artifacts.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/packaging.test.ts
Line: 99

Comment:
**UNC hostname is discarded**

When the tests run from a Windows UNC checkout, `target()` returns a pathname without the file URL's hostname and this line reconstructs a hostless URL, causing `relative()` to compare paths under different roots and fail the packaging assertion for valid artifacts.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

@charlespers

Copy link
Copy Markdown
Contributor

Thanks for the contribution! Both fixes are solid: the unknown_provider test fills a real coverage gap, and the fileURLToPath + path.relative() change is the right fix for the Windows path issue.

One request before we merge: could you drop the cosmetic reformatting in tests/packaging.test.ts? About 170 of the added lines are argument re-wrapping that doesn't change any logic. The repo doesn't run an enforced formatter, and the churn makes the actual fix (~5 lines) harder to review and pollutes git blame. Keeping the diff to just the unknown_provider test and the path-comparison fix (plus the node:path import, ideally merged into the existing join import) would make this a clean merge.

Also happy to squash the commit history on merge, so no need to rewrite that.

@supercell02

Copy link
Copy Markdown
Author

@charlespers Sorry for that I used a Formatting Tool but the blast radius was too much and instead of just working on one function it affected the whole File.

@supercell02

Copy link
Copy Markdown
Author

@charlespers Just dropped the cosmetic reformatting in tests/packaging.test.ts.
It is back to the original version with the path fix only.
Check it out and let me know if there are any other issues in the commit.

@supercell02
supercell02 requested a lite review from Copilot August 30, 2026 07:51

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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