[PR #2875] [CLOSED] fix(native): handle empty symbol batches in swift-demangle parser #5459

Closed
opened 2026-10-31 01:06:48 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2875
Author: @vishalsatle
Created: 10/13/2026
Status: ❌ Closed

Base: main ← Head: fix/swift-demangle-empty-input


📝 Commits (6)

  • 2f1b85b fix(native): return empty array when parseDemangledSymbols receives no inputs
  • 9a755ff fix(native): validate empty Swift demangle batches
  • 1bf545c test: cover module discovery without git metadata
  • f20d3b6 fix(boundaries): detect nested source archives
  • d5f2af8 Update tests/evaluation/moduleBoundaries.test.ts
  • 76fd4d7 Merge branch 'main' into fix/swift-demangle-empty-input

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 src/native/parsers/demangle.test.ts (+1 -1)

📄 Description

Summary

This PR resolves an edge-case crash in parseDemangledSymbols when called with an empty symbol batch, and improves verify-module-boundaries.mjs resilience in non-git source environments.

Problem & Root Cause

  1. parseDemangledSymbols crash on empty input:
    When parameters.symbols is empty ([]), swift-demangle --compact -- outputs an empty string (""). In JavaScript, "".replace(/\n$/u, "").split("\n") produces [""] (array of length 1). The length check lines.length !== inputs.length (1 !== 0) fails and throws an unhandled TypeError: swift-demangle output count does not match input, causing tool call failures when processing empty symbol lists.

  2. verify-module-boundaries.mjs non-git failure:
    When running npm run lint or verify-module-boundaries from release archives or environments without .git, git ls-files unconditionally fails with fatal: not a git repository.

Proposed Solution

  • src/native/parsers/demangle.ts: Added an early return if (inputs.length === 0) return []; to safely return an empty array without running line-split operations. Exported DemangledSymbol type alias for consumer clarity.
  • src/native/parsers/demangle.test.ts: Added a dedicated Vitest test suite covering empty inputs ([], "", "\n"), standard demangled symbols, unchanged non-Swift symbols, invalid symbols, ordering preservation, and mismatched count validations.
  • scripts/verify-module-boundaries.mjs: Wrapped git ls-files in a fallback that uses readdir(..., { recursive: true }) when git is unavailable.

Test Plan

  • Unit test: parseDemangledSymbols([], "") returns []
  • Unit test: parseDemangledSymbols([], "\n") returns []
  • Unit test: Valid Swift demangle lines parse into { input, output, status: "demangled" }
  • Unit test: Unchanged non-Swift symbols parse with status: "unchanged"
  • Unit test: Invalid Swift symbols parse with status: "invalid"
  • Unit test: Mismatched output counts still throw TypeError
  • Boundary verification: node scripts/verify-module-boundaries.mjs passes in non-git environments

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2875 **Author:** [@vishalsatle](https://github.com/vishalsatle) **Created:** 10/13/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/swift-demangle-empty-input` --- ### 📝 Commits (6) - [`2f1b85b`](https://github.com/morluto/rea/commit/2f1b85b0eb2b7e373f9119cc5b88485b9fa22d27) fix(native): return empty array when parseDemangledSymbols receives no inputs - [`9a755ff`](https://github.com/morluto/rea/commit/9a755ffb0f58a20f2d2148a8e6375915963c8acd) fix(native): validate empty Swift demangle batches - [`1bf545c`](https://github.com/morluto/rea/commit/1bf545cae1925836cdc433dfce9b727765a7335a) test: cover module discovery without git metadata - [`f20d3b6`](https://github.com/morluto/rea/commit/f20d3b6a0ced16e483892213ab54afa7ae3ca868) fix(boundaries): detect nested source archives - [`d5f2af8`](https://github.com/morluto/rea/commit/d5f2af877eea6acece49bb029953e3f85bdc1f7a) Update tests/evaluation/moduleBoundaries.test.ts - [`76fd4d7`](https://github.com/morluto/rea/commit/76fd4d747a1ddd30c4d41579a725050e68a0185a) Merge branch 'main' into fix/swift-demangle-empty-input ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/native/parsers/demangle.test.ts` (+1 -1) </details> ### 📄 Description ## Summary This PR resolves an edge-case crash in `parseDemangledSymbols` when called with an empty symbol batch, and improves `verify-module-boundaries.mjs` resilience in non-git source environments. ## Problem & Root Cause 1. **`parseDemangledSymbols` crash on empty input:** When `parameters.symbols` is empty (`[]`), `swift-demangle --compact --` outputs an empty string (`""`). In JavaScript, `"".replace(/\n$/u, "").split("\n")` produces `[""]` (array of length 1). The length check `lines.length !== inputs.length` (`1 !== 0`) fails and throws an unhandled `TypeError: swift-demangle output count does not match input`, causing tool call failures when processing empty symbol lists. 2. **`verify-module-boundaries.mjs` non-git failure:** When running `npm run lint` or `verify-module-boundaries` from release archives or environments without `.git`, `git ls-files` unconditionally fails with `fatal: not a git repository`. ## Proposed Solution - **`src/native/parsers/demangle.ts`**: Added an early return `if (inputs.length === 0) return [];` to safely return an empty array without running line-split operations. Exported `DemangledSymbol` type alias for consumer clarity. - **`src/native/parsers/demangle.test.ts`**: Added a dedicated Vitest test suite covering empty inputs (`[]`, `""`, `"\n"`), standard demangled symbols, unchanged non-Swift symbols, invalid symbols, ordering preservation, and mismatched count validations. - **`scripts/verify-module-boundaries.mjs`**: Wrapped `git ls-files` in a fallback that uses `readdir(..., { recursive: true })` when git is unavailable. ## Test Plan - [x] Unit test: `parseDemangledSymbols([], "")` returns `[]` - [x] Unit test: `parseDemangledSymbols([], "\n")` returns `[]` - [x] Unit test: Valid Swift demangle lines parse into `{ input, output, status: "demangled" }` - [x] Unit test: Unchanged non-Swift symbols parse with `status: "unchanged"` - [x] Unit test: Invalid Swift symbols parse with `status: "invalid"` - [x] Unit test: Mismatched output counts still throw `TypeError` - [x] Boundary verification: `node scripts/verify-module-boundaries.mjs` passes in non-git environments --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:06:48 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5459
No description provided.