ktx/packages/cli/test/context/test/make-local-git-repo.ts
Andrey Avtomonov 00cdf2de90
refactor: enforce ktx naming and AGENTS.md compliance sweep (#289)
Align the tree with AGENTS.md/CLAUDE.md conventions:

- Rewrite user-facing strings, docs, and tests to lowercase `ktx`
  (no bare uppercase `KTX` tokens remain outside literal identifiers).
- Drop the legacy `historicSql` migration path and its now-unused
  helpers, per the no-backward-compat rule.
- Remove `as unknown as` / `any` casts: narrow `BaseTool` generics to
  `z.ZodObject`, add a typed `createLookerClient`, and delete the dead
  `getParametersSchema`/`toAnthropicFormat` pre-AI-SDK helpers.
- Use `InvalidArgumentError` for Commander parse failures.
- Finish the adapter→connector prose conversion in the `ktx.yaml` docs
  while keeping the literal `adapters` config key.
2026-06-11 13:49:45 +02:00

45 lines
1.5 KiB
TypeScript

import { cp, mkdir, rm, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import type { SimpleGit } from 'simple-git';
import { createSimpleGit } from '../../../src/context/ingest/git-env.js';
export interface LocalGitRepo {
repoDir: string;
repoUrl: string;
git: SimpleGit;
commit: (message: string) => Promise<string>;
writeFile: (relPath: string, content: string) => Promise<void>;
deleteFile: (relPath: string) => Promise<void>;
}
export async function makeLocalGitRepo(fixtureDir: string, destRoot: string): Promise<LocalGitRepo> {
const repoDir = join(destRoot, 'repo');
await mkdir(repoDir, { recursive: true });
await cp(fixtureDir, repoDir, { recursive: true });
const git = createSimpleGit(repoDir);
await git.init();
await git.raw(['checkout', '-B', 'main']);
await git.addConfig('user.email', 'test@ktx.local');
await git.addConfig('user.name', 'ktx Test');
await git.add('.');
await git.commit('initial');
const commit = async (message: string): Promise<string> => {
await git.add('.');
await git.commit(message);
return (await git.log({ maxCount: 1 })).latest?.hash ?? '';
};
return {
repoDir,
repoUrl: `file://${repoDir}`,
git,
commit,
writeFile: async (relPath: string, content: string) => {
const dest = join(repoDir, relPath);
await mkdir(join(dest, '..'), { recursive: true });
await writeFile(dest, content, 'utf-8');
},
deleteFile: async (relPath: string) => {
await rm(join(repoDir, relPath), { force: true });
},
};
}