Skip to content

Conversation

@Blankll
Copy link
Member

@Blankll Blankll commented Apr 7, 2024

This pull request enhances the cross-platform download and extraction logic for search engine binaries, with a focus on supporting Windows systems and zip file handling. The main improvements include robust detection and extraction of zip files, dynamic URL generation based on platform, and better error handling during downloads.

Platform and archive handling improvements:

  • Added detection for zip files and extraction logic using the yauzl library, enabling proper handling of Windows zip binaries and fallback to gzip extraction if mislabelled. (src/utils.ts, package.json, [1] [2] [3] [4]
  • Refactored the engine binary URL generator to produce platform-specific URLs (zip for Windows, tar.gz for Unix), including correct architecture and system naming for Elasticsearch, OpenSearch, and ZincSearch. (src/utils.ts, src/utils.tsR154-R255)

File and directory utilities:

  • Improved file existence checks to use synchronous methods for reliability, and added a utility for recursive directory creation with proper permissions. (src/utils.ts, [1] [2]

Download and extraction robustness:

  • Enhanced error handling for HTTP responses and extraction failures, including logging and process termination on critical errors. (src/utils.ts, src/utils.tsL65-R139)
  • Updated test cases to cover Windows platforms and verify correct URL generation for all supported engines and platforms. (tests/utils.test.ts, tests/utils.test.tsR84-R104)

@Blankll
Copy link
Member Author

Blankll commented Dec 26, 2025

@copilot finish the implementation

Copy link

Copilot AI commented Dec 26, 2025

@Blankll I've opened a new pull request, #25, to work on those changes. Once the pull request is ready, I'll request review from you.

Completes Windows platform support by fixing zip file extraction and
cross-platform path handling. The initial implementation had incomplete
zip extraction logic with incorrect parameter passing and path
concatenation that would fail on Windows.

## Changes

- **Fixed `downloadZip` function**: Added missing `extractPath`
parameter, proper directory creation per file, and error handling for
read/write streams
- **Cross-platform paths**: Replaced string concatenation
(`${path}/${file}`) with `path.join()` and `path.dirname()` for Windows
compatibility
- **Corrected function call**: Pass both zip file path and extraction
directory to `downloadZip()`
- **Standardized permissions**: Use 0o755 consistently (Windows ignores
Unix modes without error)

## Example

The zip extraction now properly handles nested paths on both Unix and
Windows:

```typescript
// Before: Failed on Windows with hardcoded forward slashes
const filePath = `${extractPath}/${entry.fileName}`;
const fileDir = filePath.substring(0, filePath.lastIndexOf('/'));

// After: Cross-platform path handling
const filePath = path.join(extractPath, entry.fileName);
const fileDir = path.dirname(filePath);
```

This enables Windows users to run jest-search with Elasticsearch,
OpenSearch, and ZincSearch, which all distribute Windows binaries as zip
files.

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Blankll <[email protected]>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Windows platform support to the project by implementing ZIP file handling capabilities alongside the existing tar.gz extraction. The main changes include adding the yauzl library for ZIP extraction, updating platform detection logic to recognize Windows (win32), and modifying URL generation for all supported search engines.

Key changes:

  • Implemented ZIP file detection and extraction using the yauzl library
  • Updated isFileExists from async to sync implementation
  • Modified platform-specific URL generation for Elasticsearch, OpenSearch, and ZincSearch to support Windows

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 9 comments.

File Description
src/utils.ts Core implementation of Windows support including ZIP handling functions, platform detection updates, and binary URL generation for win32
package.json Added yauzl dependency for ZIP extraction and @types/yauzl dev dependency for TypeScript support
package-lock.json Lock file updates for new dependencies including yauzl, buffer-crc32, and pend packages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Blankll Blankll linked an issue Dec 26, 2025 that may be closed by this pull request
@Blankll
Copy link
Member Author

Blankll commented Dec 26, 2025

@copilot fix the test failure issues

Copy link

Copilot AI commented Dec 26, 2025

@Blankll I've opened a new pull request, #26, to work on those changes. Once the pull request is ready, I'll request review from you.

…ities (#26)

CI failures were caused by incorrect OpenSearch URL generation for macOS
and critical npm audit security vulnerabilities.

## Changes

- **OpenSearch URL generation**: Fixed to use `linux` for non-Windows
platforms. OpenSearch only provides Windows and Linux builds; the Linux
build works on macOS and other Unix-like systems.

- **Windows test coverage**: Added test cases for win32 platform across
all three engines (Elasticsearch, OpenSearch, ZincSearch).

- **Resource management**: 
- Fixed file descriptor leak in `isZipFile` - now properly closes FDs in
all code paths
  - Added cleanup handler for zip extraction errors
  - Added file renaming when `.zip` download is actually gzipped

- **Error handling**: Enhanced download errors to include HTTP status
codes and response text.

- **Security**: Resolved npm audit vulnerabilities including critical
form-data issue.

```typescript
// Before: darwin would generate opensearch-2.9.0-darwin-x64.tar.gz (doesn't exist)
const systemName = sysName === 'win32' ? 'windows' : sysName;

// After: darwin uses linux build which works on macOS
const systemName = sysName === 'win32' ? 'windows' : 'linux';
```

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Blankll <[email protected]>
@codecov
Copy link

codecov bot commented Dec 26, 2025

Codecov Report

❌ Patch coverage is 69.44444% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.17%. Comparing base (f00257b) to head (367867a).

Files with missing lines Patch % Lines
src/utils.ts 73.03% 20 Missing and 4 partials ⚠️
src/engineClient.ts 52.63% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
- Coverage   85.21%   79.17%   -6.04%     
==========================================
  Files           9        9              
  Lines         230      317      +87     
  Branches       38       56      +18     
==========================================
+ Hits          196      251      +55     
- Misses         26       51      +25     
- Partials        8       15       +7     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI commented Dec 26, 2025

@Blankll I've opened a new pull request, #27, to work on those changes. Once the pull request is ready, I'll request review from you.

Addresses three critical issues in the Windows ZIP extraction
implementation: missing test coverage, promise settling race condition,
and path traversal vulnerability.

## Changes

- **Security**: Fixed path traversal vulnerability in `downloadZip` by
validating extracted paths with `path.resolve()` before file creation
  ```typescript
  const resolvedExtractPath = path.resolve(extractPath);
  const resolvedFilePath = path.resolve(extractPath, entry.fileName);
  if (!resolvedFilePath.startsWith(resolvedExtractPath + path.sep)) {
return cleanup(new Error(`Path traversal attempt detected:
${entry.fileName}`));
  }
  ```

- **Promise handling**: Added `settled` flag in `downloadZip` cleanup to
prevent double resolution/rejection when zipfile events fire after
errors

- **Test coverage**: Added 11 unit tests for `isZipFile` and
`downloadZip` covering normal operation, edge cases (empty files,
non-existent files, subdirectories), and security scenarios (path
traversal attempts with `../` and `../../`)

- **Exports**: Made `isZipFile` and `downloadZip` publicly exported for
testing

Defense in depth: Both yauzl library validation and custom path checking
reject malicious ZIP entries.

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/geek-fun/jest-search/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Blankll <[email protected]>
@Blankll
Copy link
Member Author

Blankll commented Dec 26, 2025

@copilot add Windows Runtime in GitHub action pipeline

Copy link

Copilot AI commented Dec 26, 2025

@Blankll I've opened a new pull request, #28, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 3 commits December 26, 2025 17:23
The PR introduced Windows platform support with ZIP file handling, but
the CI pipeline only tested on macOS and Linux.

**CI coverage:**
- Added `windows-latest` to the GitHub Actions OS matrix to validate
Windows-specific code paths (ZIP extraction, platform detection, binary
URL generation)

This ensures all three target platforms are tested in CI, catching
platform-specific issues before merge.

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/geek-fun/jest-search/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Blankll <[email protected]>
@Blankll
Copy link
Member Author

Blankll commented Dec 29, 2025

@copilot
To set up your repository to handle line endings correctly across macOS, Windows, and Linux, implement these solutions:

1. Git Configuration (.gitattributes)

Create or update .gitattributes in your repository root:

# Auto detect text files and normalize line endings to LF in the repository
* text=auto eol=lf

# Explicitly declare text files you want to always be normalized and converted to LF
*.js text eol=lf
*.ts text eol=lf
*. jsx text eol=lf
*. tsx text eol=lf
*.json text eol=lf
*.md text eol=lf
*.yml text eol=lf
*. yaml text eol=lf

# Denote all files that are truly binary and should not be modified
*.png binary
*.jpg binary
*.ico binary

This ensures:

  • All text files are stored with LF in the repository
  • Git automatically converts to the appropriate line ending on checkout (LF on macOS/Linux, can be configured for Windows)

2. EditorConfig (.editorconfig)

Create .editorconfig in your repository root:

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,jsx,ts,tsx,json,yml,yaml}]
indent_style = space
indent_size = 2

This ensures all team members' editors use consistent formatting.

3. Prettier Configuration

Ensure your Prettier config includes:

{
  "endOfLine": "lf"
}

4. Git Configuration for Team Members

Each developer should run:

# Configure Git to always use LF
git config --global core.autocrlf false
git config --global core.eol lf

For Windows users specifically:

git config --global core.autocrlf input

5. Fix Existing Files

After adding .gitattributes:

# Fix all files with Prettier
npx prettier --write . 

# Or with ESLint
npx eslint . --fix

# Renormalize the repository
git add --renormalize .
git commit -m "chore: normalize line endings"

6. Pre-commit Hook (Optional but Recommended)

Install and configure Husky with lint-staged:

npm install --save-dev husky lint-staged
npx husky init

Add to package.json:

{
  "lint-staged": {
    "*. {js,jsx,ts,tsx,json,md,yml,yaml}": [
      "prettier --write",
      "eslint --fix"
    ]
  }
}

Update .husky/pre-commit:

npx lint-staged

This automatically formats files before commit, preventing line ending issues from being committed.

These configurations work together to ensure consistent line endings across all platforms while maintaining compatibility with each OS's conventions.

Copy link

Copilot AI commented Dec 29, 2025

@Blankll I've opened a new pull request, #30, to work on those changes. Once the pull request is ready, I'll request review from you.

Implements standardized line ending handling across macOS, Windows, and
Linux to prevent CRLF/LF inconsistencies in the codebase.

**Configuration files added:**

* `.gitattributes` - Minimal configuration with auto-detection to
normalize text files to LF, excludes README.md from normalization
* `.editorconfig` - Minimal configuration enforcing LF endings and
2-space indentation

**Normalization:**

* Applied Prettier formatting to workflow files with the
already-configured `endOfLine: "lf"` setting
* README.md is preserved in its original state and excluded from line
ending normalization
* Renormalized repository with Git to apply new attributes

This ensures consistent line endings for code files regardless of
developer platform, preventing spurious diffs and merge conflicts from
line ending variations, while preserving documentation files as-is. The
configuration files use minimal rules, relying on Git's auto-detection
and Prettier for formatting.

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Blankll <[email protected]>
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.

enable support for windows

2 participants