Files
ruvnet__ruflo/v3/@claude-flow/cli/__tests__/validate-input-path-2352.test.ts
rUv 0bb7c4e3d7 fix: community bug batch — Windows path validation (#2352), trajectory-end feedback (#2351), init hooks settings (#2350) (#2355)
Three reproducible bugs reported by @grym3s, batched in the style of #2346.

#2352 — hooks post-edit: Windows paths rejected, failure printed as [OK]
  - validatePath used the general SHELL_META set which includes `\`, so
    every absolute Windows path (E:\Repos\...) failed with "shell
    metacharacters". Claude Code hook events deliver absolute paths in
    tool_input.file_path, so all Windows users had silent learning loss.
    Path-specific PATH_SHELL_META drops `\` (still rejects ; & | ` $ etc.)
    and the sanitized output normalizes to forward slashes.
  - CLI post-edit action printed `Outcome recorded for ...` whenever the
    MCP call returned at all, ignoring `{success:false}`. Now checks
    result.success, surfaces the error, and exits non-zero.

#2351 — trajectory-end: step-less feedback never distilled
  - When `trajectory-end` is called with `feedback` but no recorded steps,
    the feedback was persisted with the trajectory but never embedded as a
    searchable pattern — patternsExtracted always reported 0 and
    pattern-search never surfaced it. Step-less trajectories are the
    common case for LLM agents. Now routes feedback through the same
    bridge.bridgeStorePattern / store-fallback path that pattern-store
    uses, with modest default confidence (0.6 success / 0.4 failure)
    since step-less feedback hasn't been validated by execution evidence.
    Best-effort: distillation failures do not fail the trajectory-end call.

#2350 — init hooks: subcommand writes no hooks block
  - settings-generator (#1744 fix) only emits the `hooks` block when
    `components.helpers` is true, because hooks point at the helper
    handler script. The `init hooks` subcommand was setting helpers:false,
    so the one subcommand whose purpose is "Initialize only hooks
    configuration" produced settings.json with no `hooks` key while
    reporting "N hooks enabled". Helpers must ship with hooks.

Tests
- v3/@claude-flow/cli/__tests__/validate-input-path-2352.test.ts (22 tests):
  pins Windows-path acceptance, POSIX-path acceptance, and rejection of
  shell metacharacters, traversal, empty/non-string/oversized input.
- All existing validate-input, init-wizard-bugs, hooks-intelligence, and
  hooks-post-task tests still pass.
2026-06-11 10:59:04 -04:00

96 lines
3.4 KiB
TypeScript

/**
* Regression test for #2352 (Bug A): validatePath used to reject every
* absolute Windows path because backslash was in the general SHELL_META set.
* Claude Code hook events deliver absolute paths in `tool_input.file_path`,
* so every forwarded `hooks post-edit` call failed on Windows — and Bug B
* hid the failure behind a "[OK]" log.
*
* Pin the contract: Windows-shaped paths are accepted, dangerous shell
* metacharacters and path traversal are still rejected.
*/
import { describe, it, expect } from 'vitest';
import { validatePath } from '../src/mcp-tools/validate-input.js';
describe('validatePath (#2352)', () => {
describe('Windows paths (the regression)', () => {
it('accepts an absolute Windows path with a drive letter', () => {
const r = validatePath('E:\\Repos\\my-app\\middleware.ts', 'filePath');
expect(r.valid).toBe(true);
// Sanitized form normalizes backslashes to forward slashes
expect(r.sanitized).toBe('E:/Repos/my-app/middleware.ts');
});
it('accepts a UNC-style Windows path', () => {
const r = validatePath('\\\\server\\share\\file.txt', 'filePath');
expect(r.valid).toBe(true);
});
it('accepts mixed separators', () => {
const r = validatePath('C:\\Users\\ruv/Projects\\ruflo/file.ts', 'filePath');
expect(r.valid).toBe(true);
});
});
describe('POSIX paths (must keep working)', () => {
it('accepts a relative forward-slash path', () => {
const r = validatePath('app/page.tsx', 'filePath');
expect(r.valid).toBe(true);
expect(r.sanitized).toBe('app/page.tsx');
});
it('accepts an absolute POSIX path', () => {
const r = validatePath('/home/ruv/repo/src/file.ts', 'filePath');
expect(r.valid).toBe(true);
});
});
describe('still rejects dangerous input', () => {
it('rejects path traversal with forward slashes', () => {
const r = validatePath('../etc/passwd', 'filePath');
expect(r.valid).toBe(false);
expect(r.error).toMatch(/path traversal/);
});
it('rejects path traversal with backslashes (Windows form)', () => {
const r = validatePath('..\\windows\\system32\\config', 'filePath');
expect(r.valid).toBe(false);
expect(r.error).toMatch(/path traversal/);
});
it.each([
['semicolon', 'foo;rm -rf /'],
['pipe', 'foo|cat /etc/passwd'],
['ampersand', 'foo&calc.exe'],
['backtick', 'foo`whoami`'],
['dollar', 'foo$BAR'],
['parens', 'foo$(echo bar)'],
['braces', 'foo{a,b}.txt'],
['brackets', 'foo[1].txt'],
['redirect', 'foo>out.txt'],
['append', 'foo<in.txt'],
['bang', 'foo!bar'],
['hash', 'foo#bar'],
])('rejects %s in path', (_label, value) => {
const r = validatePath(value, 'filePath');
expect(r.valid).toBe(false);
expect(r.error).toMatch(/shell metacharacters/);
});
it('rejects an empty string', () => {
expect(validatePath('', 'filePath').valid).toBe(false);
});
it('rejects non-string input', () => {
expect(validatePath(null, 'filePath').valid).toBe(false);
expect(validatePath(undefined, 'filePath').valid).toBe(false);
expect(validatePath(42, 'filePath').valid).toBe(false);
});
it('rejects an over-long path', () => {
const long = 'a/'.repeat(2500) + 'file.ts';
expect(validatePath(long, 'filePath').valid).toBe(false);
});
});
});