mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-21 16:18:55 +00:00
65 lines
2 KiB
TypeScript
65 lines
2 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { execFileSync } from 'node:child_process'
|
|
import fs from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
|
|
import { afterEach, test } from 'vitest'
|
|
|
|
import { repoStatus, resolveRenamePath } from './git-review-ops'
|
|
|
|
const tempDirs: string[] = []
|
|
|
|
afterEach(() => {
|
|
for (const dir of tempDirs.splice(0)) {
|
|
fs.rmSync(dir, { force: true, recursive: true })
|
|
}
|
|
})
|
|
|
|
function makeRepo() {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-desktop-git-status-'))
|
|
|
|
tempDirs.push(dir)
|
|
execFileSync('git', ['init', '-q'], { cwd: dir })
|
|
execFileSync('git', ['config', 'user.email', 'hermes-test@example.com'], { cwd: dir })
|
|
execFileSync('git', ['config', 'user.name', 'Hermes Test'], { cwd: dir })
|
|
fs.writeFileSync(path.join(dir, 'tracked.txt'), 'tracked\n')
|
|
execFileSync('git', ['add', 'tracked.txt'], { cwd: dir })
|
|
execFileSync('git', ['commit', '-qm', 'initial'], { cwd: dir })
|
|
|
|
return dir
|
|
}
|
|
|
|
test('resolveRenamePath: plain path is unchanged', () => {
|
|
assert.equal(resolveRenamePath('src/a.ts'), 'src/a.ts')
|
|
})
|
|
|
|
test('resolveRenamePath: simple rename resolves to the new path', () => {
|
|
assert.equal(resolveRenamePath('old.ts => new.ts'), 'new.ts')
|
|
})
|
|
|
|
test('resolveRenamePath: brace rename resolves to the new path', () => {
|
|
assert.equal(resolveRenamePath('src/{old => new}/file.ts'), 'src/new/file.ts')
|
|
})
|
|
|
|
test('resolveRenamePath: brace rename collapsing a segment', () => {
|
|
assert.equal(resolveRenamePath('src/{lib => }/file.ts'), 'src/file.ts')
|
|
})
|
|
|
|
test('repoStatus reports an untracked directory without recursively listing its contents', async () => {
|
|
const dir = makeRepo()
|
|
const nested = path.join(dir, 'generated', 'deep')
|
|
|
|
fs.mkdirSync(nested, { recursive: true })
|
|
fs.writeFileSync(path.join(nested, 'large-output.txt'), 'generated\n')
|
|
|
|
const status = await repoStatus(dir, 'git')
|
|
|
|
assert.ok(status)
|
|
assert.equal(status.untracked, 1)
|
|
assert.equal(status.changed, 1)
|
|
assert.deepEqual(
|
|
status.files.map(file => file.path),
|
|
['generated/']
|
|
)
|
|
})
|