Skip to content

Commit 13de6d5

Browse files
committed
test: build the post-bash rebase history in one fast-import and cover bare tg-hook
The post-bash git-mutation rebase test made its four-commit history with a git spawn per step, which timed out on a loaded host. It now writes the history with a single git fast-import; the rebase and the assertion are unchanged. native_hook_client gains a test for a host that drops the hook's args array: the client prints the no-op {} and exits 0, matching main() in native/tg-hook/src/main.rs, and runs nothing. text_commands stops the shared batch server before removing the note data directory and retries the removal while the database handle closes.
1 parent 6b6519d commit 13de6d5

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

‎tests/hooks_bash.test.ts‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,24 +4780,20 @@ describe('postBashHandler — git-mutation staleness enqueue', () => {
47804780
execFileSync('git', args, { cwd: dir, stdio: 'ignore' })
47814781
}
47824782
const gitEnv = ['-c', 'user.email=t@t.t', '-c', 'user.name=t', '-c', 'core.hooksPath=/dev/null']
4783-
writeFileSync(join(dir, 'base.txt'), 'base\n')
4783+
// One fast-import writes the whole history; a git spawn per step took over a minute on a loaded host.
4784+
const originalBranch = 'trunk'
4785+
let when = 1_700_000_000
4786+
const commit = (ref: string, message: string, file: string, body: string, from?: string): string =>
4787+
`commit refs/heads/${ref}\ncommitter t <t@t.t> ${when++} +0000\ndata ${message.length}\n${message}\n` +
4788+
(from === undefined ? '' : `from refs/heads/${from}\n`) +
4789+
`M 100644 inline ${file}\ndata ${body.length}\n${body}\n`
4790+
const history =
4791+
commit(originalBranch, 'init', 'base.txt', 'base\n') +
4792+
commit('feature', 'add first.txt', 'first.txt', 'first\n', originalBranch) +
4793+
commit('feature', 'add second.txt', 'second.txt', 'second\n') +
4794+
commit(originalBranch, 'unrelated mainline commit', 'mainline.txt', 'mainline\n')
47844795
git(['init'])
4785-
git([...gitEnv, 'add', '.'])
4786-
git([...gitEnv, 'commit', '-m', 'init'])
4787-
const originalBranch = execFileSync('git', ['symbolic-ref', '--short', 'HEAD'], { cwd: dir }).toString().trim()
4788-
4789-
git(['checkout', '-b', 'feature'])
4790-
writeFileSync(join(dir, 'first.txt'), 'first\n')
4791-
git([...gitEnv, 'add', 'first.txt'])
4792-
git([...gitEnv, 'commit', '-m', 'add first.txt'])
4793-
writeFileSync(join(dir, 'second.txt'), 'second\n')
4794-
git([...gitEnv, 'add', 'second.txt'])
4795-
git([...gitEnv, 'commit', '-m', 'add second.txt'])
4796-
4797-
git(['checkout', originalBranch])
4798-
writeFileSync(join(dir, 'mainline.txt'), 'mainline\n')
4799-
git([...gitEnv, 'add', 'mainline.txt'])
4800-
git([...gitEnv, 'commit', '-m', 'unrelated mainline commit'])
4796+
execFileSync('git', ['fast-import', '--quiet'], { cwd: dir, input: history, stdio: ['pipe', 'ignore', 'ignore'] })
48014797

48024798
git(['checkout', 'feature'])
48034799
execFileSync('git', [...gitEnv, 'rebase', originalBranch], { cwd: dir, stdio: 'ignore' })

‎tests/native_hook_client.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,17 @@ describe('process behaviour', () => {
829829
expect(fallbackRuns()).toBe(runs)
830830
})
831831

832+
// HAND-DERIVED: main() in native/tg-hook/src/main.rs (f590b0646): a host that drops the hook's args array
833+
// runs the bare command, and the client answers the valid no-op `{}` with exit 0, not a block.
834+
it('no arguments at all fail open with the no-op response, running nothing', () => {
835+
const runs = fallbackRuns()
836+
const res = spawnSync(bin, [], { cwd: sb.proj, env: sb.env, input: '{}', encoding: 'utf8' })
837+
expect(res.status).toBe(0)
838+
expect(res.stdout).toBe('{}\n')
839+
expect(res.stderr).toBe('')
840+
expect(fallbackRuns()).toBe(runs)
841+
})
842+
832843
it.skipIf(process.platform === 'darwin')('killing the client kills the wrapped command it started (Windows job object, Linux parent-death signal; macOS has neither)', async () => {
833844
const pidFile = path.join(sb.base, `hang-${Date.now()}.pid`)
834845
let grandchild = 0

‎tests/text_commands.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,9 @@ describe('note command', () => {
15861586
})
15871587

15881588
afterAll(async () => {
1589-
fs.rmSync(noteData, { recursive: true, force: true })
1589+
// The shared batch server holds this dir's database open: end it first, then retry while the handle closes.
1590+
stopBatchCli()
1591+
fs.rmSync(noteData, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 })
15901592
})
15911593

15921594
it('set then get round-trips a value', async () => {

0 commit comments

Comments
 (0)