Commit Graph

19 Commits

Author SHA1 Message Date
Claude 1bef40ba2d test: Tighten misleading test names and pin packageManager guard
Address two review threads on PR #1518 that flagged tests whose titles
overstated what was being verified.

- fileProcess: the longBase64 string is one continuous line, so the
  truncateBase64 → removeEmptyLines ordering was never actually under
  test (truncateBase64Content's regex does not span newlines). Rename
  to describe the combined behavior the test really pins.
- skillTechStack: rename the per-directory case to reflect that root
  and subpackage land in separate buckets keyed by getDirPath, and
  add a second case with two package.json entries at the same path
  to genuinely exercise the parsed.packageManager && !result.packageManager
  guard at skillTechStack.ts:541.
2026-04-26 13:24:32 +00:00
Kazuki Yamada 402e4906d7 test: Pin v1.14.0 regression-prone invariants
Targeted regression tests for the high-risk areas identified in the
v1.13.1..main audit, focusing on silent-correctness bugs and parallel
error handling — places that wouldn't surface in CI but would in the
field.

- core/metrics/calculateMetrics: pin numeric equivalence between the
  fast path (Σ file tokens + wrapper tokens) and the slow path (full
  output tokenization). Cover wrapper-extraction fallback, split-output
  fallback, and worker pool cleanup when fileMetrics rejects.

- core/file/fileProcess: pin transform ordering invariants —
  removeComments → removeEmptyLines (blank lines from comment removal
  must be cleaned up; preserved when removeEmptyLines is off);
  truncateBase64 → removeEmptyLines (multi-line base64 squashed first);
  trim → showLineNumbers (no leading/trailing blanks numbered).
  Plus worker/lightweight path parity for inputs that don't need
  worker processing.

- core/packager: pin metrics worker pool cleanup on parallel branch
  failures (validateFileSafety, produceOutput, calculateMetrics, warmup
  rejection). Verify prefetchSortData failure is isolated and does not
  block sortOutputFiles.

- core/skill/skillTechStack: cover untested fix-commit invariants —
  root entry sorts first in monorepo output; configFiles deduplicated
  within a directory; first-seen packageManager wins per directory.
2026-04-26 19:43:53 +09:00
Kazuki Yamada 6fecdca6b3 test(core): Add combined worker + lightweight pipeline integration test
Add test that exercises all transforms together: removeComments (worker)
+ truncateBase64 + removeEmptyLines + showLineNumbers (lightweight) to
verify the full two-phase pipeline produces correct output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 18:27:55 +09:00
Kazuki Yamada f1067163ec refactor(core): Simplify into single applyLightweightTransforms and remove redundant trim
Merge applyPreCompressTransforms and applyPostCompressTransforms into
a single applyLightweightTransforms function. Move truncateBase64 to
post-worker phase since tree-sitter handles string literals as single
AST nodes regardless of content size.

Remove redundant trim from worker processContent — the main thread
applyLightweightTransforms already handles it.

Final pipeline:
  Worker: removeComments → compress
  Main:   truncateBase64 → removeEmptyLines → trim → showLineNumbers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 18:01:22 +09:00
Kazuki Yamada 47e4a65b61 fix(core): Move removeEmptyLines to post-compress to preserve ordering
Move removeEmptyLines from applyPreCompressTransforms to
applyPostCompressTransforms so it runs after removeComments.
This ensures empty lines created by comment removal are cleaned up.

Transform order: truncateBase64 (pre) → [removeComments → compress] (worker) → removeEmptyLines → trim → showLineNumbers (post)

Simplify applyPreCompressTransforms to only handle truncateBase64
with an early return when disabled.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 17:57:00 +09:00
Kazuki Yamada cac35d0465 fix(core): Preserve transform order by splitting into pre/post compress phases
Split applyLightweightTransforms into applyPreCompressTransforms and
applyPostCompressTransforms to preserve the original execution order:
truncateBase64 → removeComments → removeEmptyLines → trim → compress → showLineNumbers

Pre-compress transforms (truncateBase64, removeEmptyLines) must run
before tree-sitter parsing to avoid performance regression with large
base64 strings and to ensure empty line removal affects chunk merging.

Action: split lightweight transforms into pre-compress and post-compress phases
Why: previous refactor changed execution order, causing tree-sitter to receive
untreated base64 and content with empty lines, altering compress output

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 17:40:11 +09:00
Kazuki Yamada e978decb2b test(core): Add regression tests for base64 truncation and lastIndex safety
Add test for consecutive truncateBase64Content calls to verify global
regex lastIndex reset works correctly. Add test for truncateBase64
config branch in applyLightweightTransforms.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 17:33:54 +09:00
Kazuki Yamada 3e70628307 refactor(core): Separate lightweight transforms from worker processing
Extract lightweight file transforms (truncateBase64, removeEmptyLines,
trim, showLineNumbers) into applyLightweightTransforms() on the main
thread, keeping only heavy operations (removeComments, compress) in
worker processContent(). This eliminates dual management of the same
logic across worker and main thread paths.

Also pre-compile base64 regex patterns at module level to avoid
re-creation per file call.

Action: split processContent into heavy (worker) and lightweight (main thread) phases
Action: extract applyLightweightTransforms() as single source of truth for lightweight ops
Action: hoist regex patterns in truncateBase64.ts to module scope with lastIndex reset
Why: lightweight transforms were duplicated in both processFilesMainThread and processContent
Why: regex re-compilation per file added unnecessary overhead for large repos

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 17:24:32 +09:00
Kazuki Yamada ddd2814f84 fix(tests): Update test mocks to use new WorkerOptions interface 2025-08-31 16:32:49 +09:00
Kazuki Yamada 8f07b63a61 feat(core): Add runtime selection support for worker pools
Add WorkerRuntime type and configurable runtime parameter to createWorkerPool and initTaskRunner functions. This allows choosing between 'worker_threads' and 'child_process' runtimes based on performance requirements.

- Add WorkerRuntime type definition for type safety
- Add optional runtime parameter to createWorkerPool with child_process default
- Add optional runtime parameter to initTaskRunner with child_process default
- Configure fileCollectWorker to use worker_threads for better performance
- Update all test files to use WorkerRuntime type
- Add comprehensive tests for runtime parameter functionality
- Maintain backward compatibility with existing code

The fileCollectWorker now benefits from worker_threads faster startup and shared memory, while other workers continue using child_process for stability.
2025-08-31 16:18:12 +09:00
Kazuki Yamada b7fe6f25c5 fix(lint): resolve all oxlint warnings for code quality
- Remove unused imports across 67 files (RepomixConfigMerged, QueryCapture, etc.)
- Fix unused parameters by prefixing with underscore (_context, _index, etc.)
- Remove unused catch parameters using modern JavaScript syntax
- Fix require-yield warnings in generator functions
- Remove unused variables and interface declarations
- Add oxlint configuration to ignore integration test fixtures

Resolves 144 linting warnings while preserving all functionality.
All 743 tests continue to pass. Code quality significantly improved.
2025-08-24 18:25:08 +09:00
Kazuki Yamada 748ce7cead refactor(shared): Consolidate initTaskRunner implementations
Add generic initTaskRunner function to processConcurrency.ts to eliminate
duplicate initialization logic across multiple modules. This reduces code
duplication and provides consistent worker pool management with proper
type safety through generic parameters.

- Add TaskRunner<T, R> interface and initTaskRunner function
- Remove duplicate createTaskRunner wrappers from 5 modules
- Update all deps parameters to use shared initTaskRunner directly
- Maintain type safety with explicit generic type parameters
- Update corresponding test mocks to match new signature

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-24 23:47:07 +09:00
Kazuki Yamada 97d4171176 fix(core): Fix TokenCounter memory leak in worker threads
TokenCounter instances were not being properly freed when worker threads
were terminated by Tinypool's idle timeout. This caused memory leaks
when using runCli as a library.

Changes:
- Add SIGTERM/SIGINT handlers to fileMetricsWorker and outputMetricsWorker
- Add freeTokenCounters function with proper cleanup and debug logging
- Convert all worker usage to consistent taskRunner pattern with cleanup
- Add cleanupWorkerPool function for explicit worker pool termination
- Update all related tests to match new taskRunner interface

The fix ensures TokenCounter resources are properly freed when workers
terminate, preventing memory accumulation during library usage.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-24 23:25:23 +09:00
Kazuki Yamada d9595eeda2 test(core): Fix TokenCounter mock implementation and path 2025-04-20 17:33:57 +09:00
Kazuki Yamada 7da5973abe refactor(core): Extract file processing logic to separate modules
- Create fileRead.ts for file reading functionality

- Create fileProcessContent.ts for content processing

- Update worker files to use new modules
2025-04-20 16:00:14 +09:00
yamadashy 3f8dff6694 test: Increase coverage of some tests 2025-03-02 21:45:12 +09:00
Kazuki Yamada ebacdd967c feat(pack): Simplify the process and make it testable with DI 2025-01-25 12:43:38 +09:00
Kazuki Yamada 79df207866 feat(process): Prevent main thread blocking in file processing 2024-12-29 22:09:21 +09:00
Kazuki Yamada 487287c22c refactor: refine directory structure and files 2024-10-08 01:17:05 +09:00