with tempfile.TemporaryDirectory() as directory:
    tmp = Path(directory)
    subprocess.run(['git', 'init', '-q', directory], check=True, capture_output=True)
    (tmp / 'discount.py').write_text('return round(price * 0.9, 2)\n')
    subprocess.run(['git', '-C', directory, 'add', 'discount.py'], check=True, capture_output=True)
    (tmp / 'private-notes.txt').write_text('not staged\n')
    staged = subprocess.check_output(['git', '-C', directory, 'diff', '--cached', '--name-only'], text=True).splitlines()
    check('在隔离仓库读取暂存文件清单', staged == output['files'])
    check('未暂存文件未进入模型提交清单', 'private-notes.txt' not in output['files'])
check('标题满足Conventional Commits前缀', bool(re.match(r'^(feat|fix|docs|style|refactor|perf|test|build|ci|chore)(\([^\n)]+\))?!?:\s+\S', output['subject'])))
(folder / 'commit-preview.txt').write_text(output['subject'] + '\n\n' + output.get('body', ''))
