* docs: add investigation reports for 5 open GitHub issues Comprehensive analysis of issues #543, #544, #545, #555, and #557: - #557: settings.json not generated, module loader error (node/bun mismatch) - #555: Windows hooks not executing, hasIpc always false - #545: formatTool crashes on non-JSON tool_input strings - #544: mem-search skill hint shown incorrectly to Claude Code users - #543: /claude-mem slash command unavailable despite installation Each report includes root cause analysis, affected files, and proposed fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(logger): handle non-JSON tool_input in formatTool (#545) Wrap JSON.parse in try-catch to handle raw string inputs (e.g., Bash commands) that aren't valid JSON. Falls back to using the string as-is. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(context): update mem-search hint to reference MCP tools (#544) Update hint messages to reference MCP tools (search, get_observations) instead of the deprecated "mem-search skill" terminology. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(settings): auto-create settings.json on first load (#557, #543) When settings.json doesn't exist, create it with defaults instead of returning in-memory defaults. Creates parent directory if needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(hooks): use bun runtime for hooks except smart-install (#557) Change hook commands from node to bun since hooks use bun:sqlite. Keep smart-install.js on node since it bootstraps bun installation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: rebuild plugin scripts * docs: clarify that build artifacts must be committed * fix(docs): update build artifacts directory reference in CLAUDE.md * test: add test coverage for PR #558 fixes - Fix 2 failing tests: update "mem-search skill" → "MCP tools" expectations - Add 56 tests for formatTool() JSON.parse crash fix (Issue #545) - Add 27 tests for settings.json auto-creation (Issue #543) Test coverage includes: - formatTool: JSON parsing, raw strings, objects, null/undefined, all tool types - Settings: file creation, directory creation, schema migration, edge cases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(tests): clean up flaky tests and fix circular dependency Phase 1 of test quality improvements: - Delete 6 harmful/worthless test files that used problematic mock.module() patterns or tested implementation details rather than behavior: - context-builder.test.ts (tested internal implementation) - export-types.test.ts (fragile mock patterns) - smart-install.test.ts (shell script testing antipattern) - session_id_refactor.test.ts (outdated, tested refactoring itself) - validate_sql_update.test.ts (one-time migration validation) - observation-broadcaster.test.ts (excessive mocking) - Fix circular dependency between logger.ts and SettingsDefaultsManager.ts by using late binding pattern - logger now lazily loads settings - Refactor mock.module() to spyOn() in several test files for more maintainable and less brittle tests: - observation-compiler.test.ts - gemini_agent.test.ts - error-handler.test.ts - server.test.ts - response-processor.test.ts All 649 tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(tests): phase 2 - reduce mock-heavy tests and improve focus - Remove mock-heavy query tests from observation-compiler.test.ts, keep real buildTimeline tests - Convert session_id_usage_validation.test.ts from 477 to 178 lines of focused smoke tests - Remove tests for language built-ins from worker-spawn.test.ts (JSON.parse, array indexing) - Rename logger-coverage.test.ts to logger-usage-standards.test.ts for clarity 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs(tests): phase 3 - add JSDoc mock justification to test files Document mock usage rationale in 5 test files to improve maintainability: - error-handler.test.ts: Express req/res mocks, logger spies (~11%) - fallback-error-handler.test.ts: Zero mocks, pure function tests - session-cleanup-helper.test.ts: Session fixtures, worker mocks (~19%) - hook-constants.test.ts: process.platform mock for Windows tests (~12%) - session_store.test.ts: Zero mocks, real SQLite :memory: database Part of ongoing effort to document mock justifications per TESTING.md guidelines. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(integration): phase 5 - add 72 tests for critical coverage gaps Add comprehensive test coverage for previously untested areas: - tests/integration/hook-execution-e2e.test.ts (10 tests) Tests lifecycle hooks execution flow and context propagation - tests/integration/worker-api-endpoints.test.ts (19 tests) Tests all worker service HTTP endpoints without heavy mocking - tests/integration/chroma-vector-sync.test.ts (16 tests) Tests vector embedding synchronization with ChromaDB - tests/utils/tag-stripping.test.ts (27 tests) Tests privacy tag stripping utilities for both <private> and <meta-observation> tags All tests use real implementations where feasible, following the project's testing philosophy of preferring integration-style tests over unit tests with extensive mocking. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * context update * docs: add comment linking DEFAULT_DATA_DIR locations Added NOTE comment in logger.ts pointing to the canonical DEFAULT_DATA_DIR in SettingsDefaultsManager.ts. This addresses PR reviewer feedback about the fragility of having the default defined in two places to avoid circular dependencies. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<claude-mem-context>
|
||||
# Recent Activity
|
||||
|
||||
<!-- This section is auto-generated by claude-mem. Edit content outside the tags. -->
|
||||
|
||||
### Jan 5, 2026
|
||||
|
||||
| ID | Time | T | Title | Read |
|
||||
|----|------|---|-------|------|
|
||||
| #36888 | 1:58 AM | 🟣 | Phase 4 Implementation Completed via Subagent | ~533 |
|
||||
| #36885 | 1:57 AM | 🟣 | Export Types Tests Created | ~602 |
|
||||
| #36882 | 1:56 AM | 🟣 | Phase 3 Implementation Completed via Subagent | ~552 |
|
||||
| #36879 | " | 🟣 | Smart-Install Path Detection Tests Created | ~510 |
|
||||
</claude-mem-context>
|
||||
@@ -1,349 +0,0 @@
|
||||
import { describe, it, expect } from 'bun:test';
|
||||
import type {
|
||||
ObservationRecord,
|
||||
SdkSessionRecord,
|
||||
SessionSummaryRecord,
|
||||
UserPromptRecord,
|
||||
ExportData
|
||||
} from '../../scripts/types/export.js';
|
||||
|
||||
describe('Export Types', () => {
|
||||
describe('ObservationRecord', () => {
|
||||
it('should have all required fields', () => {
|
||||
const observation: ObservationRecord = {
|
||||
id: 1,
|
||||
memory_session_id: 'session-123',
|
||||
project: 'test-project',
|
||||
text: null,
|
||||
type: 'discovery',
|
||||
title: 'Test Title',
|
||||
subtitle: null,
|
||||
facts: null,
|
||||
narrative: null,
|
||||
concepts: null,
|
||||
files_read: null,
|
||||
files_modified: null,
|
||||
prompt_number: 1,
|
||||
discovery_tokens: null,
|
||||
created_at: '2025-01-01T00:00:00Z',
|
||||
created_at_epoch: 1704067200
|
||||
};
|
||||
|
||||
expect(observation.id).toBe(1);
|
||||
expect(observation.memory_session_id).toBe('session-123');
|
||||
expect(observation.project).toBe('test-project');
|
||||
expect(observation.type).toBe('discovery');
|
||||
expect(observation.title).toBe('Test Title');
|
||||
expect(observation.prompt_number).toBe(1);
|
||||
expect(observation.created_at).toBe('2025-01-01T00:00:00Z');
|
||||
expect(observation.created_at_epoch).toBe(1704067200);
|
||||
});
|
||||
|
||||
it('should accept string values for nullable text fields', () => {
|
||||
const observation: ObservationRecord = {
|
||||
id: 2,
|
||||
memory_session_id: 'session-456',
|
||||
project: 'another-project',
|
||||
text: 'Full observation text content',
|
||||
type: 'session-summary',
|
||||
title: 'Summary Title',
|
||||
subtitle: 'A subtitle',
|
||||
facts: 'Fact 1, Fact 2',
|
||||
narrative: 'The narrative of what happened',
|
||||
concepts: 'concept1, concept2',
|
||||
files_read: 'file1.ts, file2.ts',
|
||||
files_modified: 'file3.ts',
|
||||
prompt_number: 5,
|
||||
discovery_tokens: 1500,
|
||||
created_at: '2025-06-15T12:30:00Z',
|
||||
created_at_epoch: 1718451000
|
||||
};
|
||||
|
||||
expect(observation.text).toBe('Full observation text content');
|
||||
expect(observation.subtitle).toBe('A subtitle');
|
||||
expect(observation.facts).toBe('Fact 1, Fact 2');
|
||||
expect(observation.narrative).toBe('The narrative of what happened');
|
||||
expect(observation.concepts).toBe('concept1, concept2');
|
||||
expect(observation.files_read).toBe('file1.ts, file2.ts');
|
||||
expect(observation.files_modified).toBe('file3.ts');
|
||||
expect(observation.discovery_tokens).toBe(1500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SdkSessionRecord', () => {
|
||||
it('should have all required fields', () => {
|
||||
const session: SdkSessionRecord = {
|
||||
id: 1,
|
||||
content_session_id: 'content-abc',
|
||||
memory_session_id: 'memory-xyz',
|
||||
project: 'test-project',
|
||||
user_prompt: 'User asked a question',
|
||||
started_at: '2025-01-01T10:00:00Z',
|
||||
started_at_epoch: 1704103200,
|
||||
completed_at: null,
|
||||
completed_at_epoch: null,
|
||||
status: 'in_progress'
|
||||
};
|
||||
|
||||
expect(session.id).toBe(1);
|
||||
expect(session.content_session_id).toBe('content-abc');
|
||||
expect(session.memory_session_id).toBe('memory-xyz');
|
||||
expect(session.project).toBe('test-project');
|
||||
expect(session.user_prompt).toBe('User asked a question');
|
||||
expect(session.started_at).toBe('2025-01-01T10:00:00Z');
|
||||
expect(session.started_at_epoch).toBe(1704103200);
|
||||
expect(session.status).toBe('in_progress');
|
||||
});
|
||||
|
||||
it('should accept completion values for nullable fields', () => {
|
||||
const session: SdkSessionRecord = {
|
||||
id: 2,
|
||||
content_session_id: 'content-def',
|
||||
memory_session_id: 'memory-uvw',
|
||||
project: 'completed-project',
|
||||
user_prompt: 'Complete this task',
|
||||
started_at: '2025-01-01T10:00:00Z',
|
||||
started_at_epoch: 1704103200,
|
||||
completed_at: '2025-01-01T10:30:00Z',
|
||||
completed_at_epoch: 1704105000,
|
||||
status: 'completed'
|
||||
};
|
||||
|
||||
expect(session.completed_at).toBe('2025-01-01T10:30:00Z');
|
||||
expect(session.completed_at_epoch).toBe(1704105000);
|
||||
expect(session.status).toBe('completed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('SessionSummaryRecord', () => {
|
||||
it('should have all required fields', () => {
|
||||
const summary: SessionSummaryRecord = {
|
||||
id: 1,
|
||||
memory_session_id: 'session-summary-123',
|
||||
project: 'summary-project',
|
||||
request: null,
|
||||
investigated: null,
|
||||
learned: null,
|
||||
completed: null,
|
||||
next_steps: null,
|
||||
files_read: null,
|
||||
files_edited: null,
|
||||
notes: null,
|
||||
prompt_number: 1,
|
||||
discovery_tokens: null,
|
||||
created_at: '2025-01-01T14:00:00Z',
|
||||
created_at_epoch: 1704117600
|
||||
};
|
||||
|
||||
expect(summary.id).toBe(1);
|
||||
expect(summary.memory_session_id).toBe('session-summary-123');
|
||||
expect(summary.project).toBe('summary-project');
|
||||
expect(summary.prompt_number).toBe(1);
|
||||
expect(summary.created_at).toBe('2025-01-01T14:00:00Z');
|
||||
expect(summary.created_at_epoch).toBe(1704117600);
|
||||
});
|
||||
|
||||
it('should accept string values for all nullable summary fields', () => {
|
||||
const summary: SessionSummaryRecord = {
|
||||
id: 2,
|
||||
memory_session_id: 'session-full-summary',
|
||||
project: 'detailed-project',
|
||||
request: 'User requested feature X',
|
||||
investigated: 'Checked files A, B, C',
|
||||
learned: 'Discovered pattern D',
|
||||
completed: 'Implemented feature X',
|
||||
next_steps: 'Test and deploy',
|
||||
files_read: 'src/a.ts, src/b.ts',
|
||||
files_edited: 'src/c.ts',
|
||||
notes: 'Additional context here',
|
||||
prompt_number: 10,
|
||||
discovery_tokens: 2500,
|
||||
created_at: '2025-06-20T16:45:00Z',
|
||||
created_at_epoch: 1718901900
|
||||
};
|
||||
|
||||
expect(summary.request).toBe('User requested feature X');
|
||||
expect(summary.investigated).toBe('Checked files A, B, C');
|
||||
expect(summary.learned).toBe('Discovered pattern D');
|
||||
expect(summary.completed).toBe('Implemented feature X');
|
||||
expect(summary.next_steps).toBe('Test and deploy');
|
||||
expect(summary.files_read).toBe('src/a.ts, src/b.ts');
|
||||
expect(summary.files_edited).toBe('src/c.ts');
|
||||
expect(summary.notes).toBe('Additional context here');
|
||||
expect(summary.discovery_tokens).toBe(2500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('UserPromptRecord', () => {
|
||||
it('should have all required fields', () => {
|
||||
const prompt: UserPromptRecord = {
|
||||
id: 1,
|
||||
content_session_id: 'content-prompt-123',
|
||||
prompt_number: 1,
|
||||
prompt_text: 'What is the meaning of life?',
|
||||
created_at: '2025-01-01T08:00:00Z',
|
||||
created_at_epoch: 1704096000
|
||||
};
|
||||
|
||||
expect(prompt.id).toBe(1);
|
||||
expect(prompt.content_session_id).toBe('content-prompt-123');
|
||||
expect(prompt.prompt_number).toBe(1);
|
||||
expect(prompt.prompt_text).toBe('What is the meaning of life?');
|
||||
expect(prompt.created_at).toBe('2025-01-01T08:00:00Z');
|
||||
expect(prompt.created_at_epoch).toBe(1704096000);
|
||||
});
|
||||
|
||||
it('should handle multi-line prompt text', () => {
|
||||
const prompt: UserPromptRecord = {
|
||||
id: 2,
|
||||
content_session_id: 'content-multiline',
|
||||
prompt_number: 3,
|
||||
prompt_text: 'Line 1\nLine 2\nLine 3',
|
||||
created_at: '2025-03-15T09:30:00Z',
|
||||
created_at_epoch: 1710495000
|
||||
};
|
||||
|
||||
expect(prompt.prompt_text).toContain('\n');
|
||||
expect(prompt.prompt_number).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ExportData', () => {
|
||||
it('should compose all record types correctly', () => {
|
||||
const exportData: ExportData = {
|
||||
exportedAt: '2025-01-02T00:00:00Z',
|
||||
exportedAtEpoch: 1704153600,
|
||||
query: 'test query',
|
||||
totalObservations: 1,
|
||||
totalSessions: 1,
|
||||
totalSummaries: 1,
|
||||
totalPrompts: 1,
|
||||
observations: [{
|
||||
id: 1,
|
||||
memory_session_id: 'session-123',
|
||||
project: 'test-project',
|
||||
text: null,
|
||||
type: 'discovery',
|
||||
title: 'Test',
|
||||
subtitle: null,
|
||||
facts: null,
|
||||
narrative: null,
|
||||
concepts: null,
|
||||
files_read: null,
|
||||
files_modified: null,
|
||||
prompt_number: 1,
|
||||
discovery_tokens: null,
|
||||
created_at: '2025-01-01T00:00:00Z',
|
||||
created_at_epoch: 1704067200
|
||||
}],
|
||||
sessions: [{
|
||||
id: 1,
|
||||
content_session_id: 'content-abc',
|
||||
memory_session_id: 'memory-xyz',
|
||||
project: 'test-project',
|
||||
user_prompt: 'Question',
|
||||
started_at: '2025-01-01T10:00:00Z',
|
||||
started_at_epoch: 1704103200,
|
||||
completed_at: null,
|
||||
completed_at_epoch: null,
|
||||
status: 'in_progress'
|
||||
}],
|
||||
summaries: [{
|
||||
id: 1,
|
||||
memory_session_id: 'session-summary-123',
|
||||
project: 'summary-project',
|
||||
request: null,
|
||||
investigated: null,
|
||||
learned: null,
|
||||
completed: null,
|
||||
next_steps: null,
|
||||
files_read: null,
|
||||
files_edited: null,
|
||||
notes: null,
|
||||
prompt_number: 1,
|
||||
discovery_tokens: null,
|
||||
created_at: '2025-01-01T14:00:00Z',
|
||||
created_at_epoch: 1704117600
|
||||
}],
|
||||
prompts: [{
|
||||
id: 1,
|
||||
content_session_id: 'content-prompt-123',
|
||||
prompt_number: 1,
|
||||
prompt_text: 'Prompt text',
|
||||
created_at: '2025-01-01T08:00:00Z',
|
||||
created_at_epoch: 1704096000
|
||||
}]
|
||||
};
|
||||
|
||||
expect(exportData.exportedAt).toBe('2025-01-02T00:00:00Z');
|
||||
expect(exportData.exportedAtEpoch).toBe(1704153600);
|
||||
expect(exportData.query).toBe('test query');
|
||||
expect(exportData.totalObservations).toBe(1);
|
||||
expect(exportData.totalSessions).toBe(1);
|
||||
expect(exportData.totalSummaries).toBe(1);
|
||||
expect(exportData.totalPrompts).toBe(1);
|
||||
expect(exportData.observations).toHaveLength(1);
|
||||
expect(exportData.sessions).toHaveLength(1);
|
||||
expect(exportData.summaries).toHaveLength(1);
|
||||
expect(exportData.prompts).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should accept optional project field', () => {
|
||||
const exportWithProject: ExportData = {
|
||||
exportedAt: '2025-01-02T00:00:00Z',
|
||||
exportedAtEpoch: 1704153600,
|
||||
query: '*',
|
||||
project: 'specific-project',
|
||||
totalObservations: 0,
|
||||
totalSessions: 0,
|
||||
totalSummaries: 0,
|
||||
totalPrompts: 0,
|
||||
observations: [],
|
||||
sessions: [],
|
||||
summaries: [],
|
||||
prompts: []
|
||||
};
|
||||
|
||||
expect(exportWithProject.project).toBe('specific-project');
|
||||
});
|
||||
|
||||
it('should work without project field', () => {
|
||||
const exportWithoutProject: ExportData = {
|
||||
exportedAt: '2025-01-02T00:00:00Z',
|
||||
exportedAtEpoch: 1704153600,
|
||||
query: '*',
|
||||
totalObservations: 0,
|
||||
totalSessions: 0,
|
||||
totalSummaries: 0,
|
||||
totalPrompts: 0,
|
||||
observations: [],
|
||||
sessions: [],
|
||||
summaries: [],
|
||||
prompts: []
|
||||
};
|
||||
|
||||
expect(exportWithoutProject.project).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should handle empty arrays', () => {
|
||||
const emptyExport: ExportData = {
|
||||
exportedAt: '2025-01-02T00:00:00Z',
|
||||
exportedAtEpoch: 1704153600,
|
||||
query: 'no results',
|
||||
totalObservations: 0,
|
||||
totalSessions: 0,
|
||||
totalSummaries: 0,
|
||||
totalPrompts: 0,
|
||||
observations: [],
|
||||
sessions: [],
|
||||
summaries: [],
|
||||
prompts: []
|
||||
};
|
||||
|
||||
expect(emptyExport.observations).toHaveLength(0);
|
||||
expect(emptyExport.sessions).toHaveLength(0);
|
||||
expect(emptyExport.summaries).toHaveLength(0);
|
||||
expect(emptyExport.prompts).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,231 +0,0 @@
|
||||
import { describe, it, expect } from 'bun:test';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
|
||||
/**
|
||||
* Tests for smart-install.js path detection logic
|
||||
*
|
||||
* These tests verify that the path arrays used for detecting Bun and uv
|
||||
* installations include the correct platform-specific paths, particularly
|
||||
* for Apple Silicon Macs which use /opt/homebrew instead of /usr/local.
|
||||
*
|
||||
* The path arrays are defined inline in smart-install.js. These tests
|
||||
* replicate that logic to verify correctness without mocking the module.
|
||||
*/
|
||||
|
||||
describe('smart-install path detection', () => {
|
||||
describe('BUN_COMMON_PATHS', () => {
|
||||
/**
|
||||
* Helper function that replicates the path array logic from smart-install.js
|
||||
* This allows us to test the logic without importing/mocking the actual module.
|
||||
*/
|
||||
function getBunPaths(isWindows: boolean): string[] {
|
||||
return isWindows
|
||||
? [join(homedir(), '.bun', 'bin', 'bun.exe')]
|
||||
: [
|
||||
join(homedir(), '.bun', 'bin', 'bun'),
|
||||
'/usr/local/bin/bun',
|
||||
'/opt/homebrew/bin/bun',
|
||||
];
|
||||
}
|
||||
|
||||
it('should include Apple Silicon Homebrew path on macOS', () => {
|
||||
const bunPaths = getBunPaths(false);
|
||||
|
||||
expect(bunPaths).toContain('/opt/homebrew/bin/bun');
|
||||
});
|
||||
|
||||
it('should include Intel Homebrew path on macOS', () => {
|
||||
const bunPaths = getBunPaths(false);
|
||||
|
||||
expect(bunPaths).toContain('/usr/local/bin/bun');
|
||||
});
|
||||
|
||||
it('should include user-local ~/.bun path on macOS', () => {
|
||||
const bunPaths = getBunPaths(false);
|
||||
const expectedUserPath = join(homedir(), '.bun', 'bin', 'bun');
|
||||
|
||||
expect(bunPaths).toContain(expectedUserPath);
|
||||
});
|
||||
|
||||
it('should NOT include Apple Silicon Homebrew path on Windows', () => {
|
||||
const bunPaths = getBunPaths(true);
|
||||
|
||||
expect(bunPaths).not.toContain('/opt/homebrew/bin/bun');
|
||||
expect(bunPaths).not.toContain('/usr/local/bin/bun');
|
||||
});
|
||||
|
||||
it('should use .exe extension on Windows', () => {
|
||||
const bunPaths = getBunPaths(true);
|
||||
|
||||
expect(bunPaths.length).toBe(1);
|
||||
expect(bunPaths[0]).toEndWith('bun.exe');
|
||||
});
|
||||
|
||||
it('should check user-local paths before system paths', () => {
|
||||
const bunPaths = getBunPaths(false);
|
||||
const userLocalPath = join(homedir(), '.bun', 'bin', 'bun');
|
||||
const homebrewPath = '/opt/homebrew/bin/bun';
|
||||
|
||||
const userLocalIndex = bunPaths.indexOf(userLocalPath);
|
||||
const homebrewIndex = bunPaths.indexOf(homebrewPath);
|
||||
|
||||
expect(userLocalIndex).toBeLessThan(homebrewIndex);
|
||||
expect(userLocalIndex).toBe(0); // User local should be first
|
||||
});
|
||||
});
|
||||
|
||||
describe('UV_COMMON_PATHS', () => {
|
||||
/**
|
||||
* Helper function that replicates the UV path array logic from smart-install.js
|
||||
*/
|
||||
function getUvPaths(isWindows: boolean): string[] {
|
||||
return isWindows
|
||||
? [
|
||||
join(homedir(), '.local', 'bin', 'uv.exe'),
|
||||
join(homedir(), '.cargo', 'bin', 'uv.exe'),
|
||||
]
|
||||
: [
|
||||
join(homedir(), '.local', 'bin', 'uv'),
|
||||
join(homedir(), '.cargo', 'bin', 'uv'),
|
||||
'/usr/local/bin/uv',
|
||||
'/opt/homebrew/bin/uv',
|
||||
];
|
||||
}
|
||||
|
||||
it('should include Apple Silicon Homebrew path on macOS', () => {
|
||||
const uvPaths = getUvPaths(false);
|
||||
|
||||
expect(uvPaths).toContain('/opt/homebrew/bin/uv');
|
||||
});
|
||||
|
||||
it('should include Intel Homebrew path on macOS', () => {
|
||||
const uvPaths = getUvPaths(false);
|
||||
|
||||
expect(uvPaths).toContain('/usr/local/bin/uv');
|
||||
});
|
||||
|
||||
it('should include user-local paths on macOS', () => {
|
||||
const uvPaths = getUvPaths(false);
|
||||
const expectedLocalPath = join(homedir(), '.local', 'bin', 'uv');
|
||||
const expectedCargoPath = join(homedir(), '.cargo', 'bin', 'uv');
|
||||
|
||||
expect(uvPaths).toContain(expectedLocalPath);
|
||||
expect(uvPaths).toContain(expectedCargoPath);
|
||||
});
|
||||
|
||||
it('should NOT include Apple Silicon Homebrew path on Windows', () => {
|
||||
const uvPaths = getUvPaths(true);
|
||||
|
||||
expect(uvPaths).not.toContain('/opt/homebrew/bin/uv');
|
||||
expect(uvPaths).not.toContain('/usr/local/bin/uv');
|
||||
});
|
||||
|
||||
it('should use .exe extension on Windows', () => {
|
||||
const uvPaths = getUvPaths(true);
|
||||
|
||||
expect(uvPaths.every((p) => p.endsWith('.exe'))).toBe(true);
|
||||
});
|
||||
|
||||
it('should check user-local paths before system Homebrew paths', () => {
|
||||
const uvPaths = getUvPaths(false);
|
||||
const userLocalPath = join(homedir(), '.local', 'bin', 'uv');
|
||||
const cargoPath = join(homedir(), '.cargo', 'bin', 'uv');
|
||||
const homebrewPath = '/opt/homebrew/bin/uv';
|
||||
|
||||
const userLocalIndex = uvPaths.indexOf(userLocalPath);
|
||||
const cargoIndex = uvPaths.indexOf(cargoPath);
|
||||
const homebrewIndex = uvPaths.indexOf(homebrewPath);
|
||||
|
||||
// User paths should come before Homebrew paths
|
||||
expect(userLocalIndex).toBeLessThan(homebrewIndex);
|
||||
expect(cargoIndex).toBeLessThan(homebrewIndex);
|
||||
|
||||
// User local should be first, then cargo
|
||||
expect(userLocalIndex).toBe(0);
|
||||
expect(cargoIndex).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('path priority', () => {
|
||||
it('should prioritize user-installed binaries over system binaries', () => {
|
||||
// This is the expected order of preference:
|
||||
// 1. User's home directory (e.g., ~/.bun/bin/bun)
|
||||
// 2. Intel Homebrew (/usr/local/bin)
|
||||
// 3. Apple Silicon Homebrew (/opt/homebrew/bin)
|
||||
//
|
||||
// The rationale: User-local installs are most likely intentional
|
||||
// and should take precedence over system-wide installations.
|
||||
|
||||
const isWindows = false;
|
||||
const bunPaths = isWindows
|
||||
? [join(homedir(), '.bun', 'bin', 'bun.exe')]
|
||||
: [
|
||||
join(homedir(), '.bun', 'bin', 'bun'),
|
||||
'/usr/local/bin/bun',
|
||||
'/opt/homebrew/bin/bun',
|
||||
];
|
||||
|
||||
// Verify the first path is user-local
|
||||
expect(bunPaths[0]).toContain(homedir());
|
||||
expect(bunPaths[0]).not.toStartWith('/usr');
|
||||
expect(bunPaths[0]).not.toStartWith('/opt');
|
||||
});
|
||||
|
||||
it('should have Homebrew paths last in the array', () => {
|
||||
const isWindows = false;
|
||||
const uvPaths = isWindows
|
||||
? []
|
||||
: [
|
||||
join(homedir(), '.local', 'bin', 'uv'),
|
||||
join(homedir(), '.cargo', 'bin', 'uv'),
|
||||
'/usr/local/bin/uv',
|
||||
'/opt/homebrew/bin/uv',
|
||||
];
|
||||
|
||||
if (!isWindows) {
|
||||
// Last two should be the Homebrew paths
|
||||
expect(uvPaths[uvPaths.length - 1]).toBe('/opt/homebrew/bin/uv');
|
||||
expect(uvPaths[uvPaths.length - 2]).toBe('/usr/local/bin/uv');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('cross-platform consistency', () => {
|
||||
it('should have exactly 3 Bun paths on macOS/Linux', () => {
|
||||
const bunPaths = [
|
||||
join(homedir(), '.bun', 'bin', 'bun'),
|
||||
'/usr/local/bin/bun',
|
||||
'/opt/homebrew/bin/bun',
|
||||
];
|
||||
|
||||
expect(bunPaths.length).toBe(3);
|
||||
});
|
||||
|
||||
it('should have exactly 1 Bun path on Windows', () => {
|
||||
const bunPaths = [join(homedir(), '.bun', 'bin', 'bun.exe')];
|
||||
|
||||
expect(bunPaths.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should have exactly 4 UV paths on macOS/Linux', () => {
|
||||
const uvPaths = [
|
||||
join(homedir(), '.local', 'bin', 'uv'),
|
||||
join(homedir(), '.cargo', 'bin', 'uv'),
|
||||
'/usr/local/bin/uv',
|
||||
'/opt/homebrew/bin/uv',
|
||||
];
|
||||
|
||||
expect(uvPaths.length).toBe(4);
|
||||
});
|
||||
|
||||
it('should have exactly 2 UV paths on Windows', () => {
|
||||
const uvPaths = [
|
||||
join(homedir(), '.local', 'bin', 'uv.exe'),
|
||||
join(homedir(), '.cargo', 'bin', 'uv.exe'),
|
||||
];
|
||||
|
||||
expect(uvPaths.length).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user