Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

1.6 KB
Raw Blame
import { describe, expect, it } from 'bun:test';
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

import { isExecutableFile } from '../src/services/smart-file-read/tree-sitter-bin-path.js';

/**
 * The predicate the tree-sitter CLI resolution gates on. The platform is an
 * argument, so the Windows branch is tested on every host.
 */
describe('isExecutableFile', () => {
  const withFile = (name: string, run: (file: string, dir: string) => void) => {
    const dir = mkdtempSync(join(tmpdir(), 'tree-sitter-executable-'));
    try {
      const file = join(dir, name);
      writeFileSync(file, '');
      run(file, dir);
    } finally {
      rmSync(dir, { recursive: true, force: true });
    }
  };

  it('asks for existence on Windows, where there is no exec bit to read', () => {
    withFile('tree-sitter.exe', (file, dir) => {
      expect(isExecutableFile(file, 'win32')).toBe(true);
      // CreateProcess reports the real failure, but a path that is not there
      // is not executable there either.
      expect(isExecutableFile(join(dir, 'missing.exe'), 'win32')).toBe(false);
    });
  });

  it('asks for the exec bit on POSIX, where existence alone is not enough', () => {
    withFile('tree-sitter', (file) => {
      chmodSync(file, 0o644);
      expect(isExecutableFile(file, 'linux')).toBe(false);
      chmodSync(file, 0o755);
      expect(isExecutableFile(file, 'linux')).toBe(true);
      expect(isExecutableFile(`${file}-missing`, 'linux')).toBe(false);
    });
  });
});