A tiny, local-first CLI that finds the files your AI coding agent actually needs — and packs them into a focused context.
| 1 | """Shared fixtures for agent-context tests.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | |
| 10 | @pytest.fixture |
| 11 | def sample_repo(tmp_path: Path) -> Path: |
| 12 | """A small multi-language-ish repo with auth code, tests, docs, secrets, binaries.""" |
| 13 | root = tmp_path / "repo" |
| 14 | (root / "src" / "auth").mkdir(parents=True) |
| 15 | (root / "src" / "api").mkdir(parents=True) |
| 16 | (root / "src" / "payment").mkdir(parents=True) |
| 17 | (root / "tests").mkdir(parents=True) |
| 18 | (root / "docs").mkdir(parents=True) |
| 19 | (root / "node_modules" / "lodash").mkdir(parents=True) |
| 20 | (root / "dist").mkdir(parents=True) |
| 21 | (root / ".git").mkdir(parents=True) |
| 22 | |
| 23 | (root / "src" / "auth" / "middleware.ts").write_text( |
| 24 | "export function authMiddleware(req, res, next) {\n" |
| 25 | " const token = req.cookies.session;\n" |
| 26 | " if (!token) return res.status(401).end();\n" |
| 27 | " next();\n" |
| 28 | "}\n", |
| 29 | encoding="utf-8", |
| 30 | ) |
| 31 | (root / "src" / "auth" / "session.ts").write_text( |
| 32 | "export class Session {\n" |
| 33 | " constructor(public userId: string) {}\n" |
| 34 | " static create(userId: string) { return new Session(userId); }\n" |
| 35 | "}\n", |
| 36 | encoding="utf-8", |
| 37 | ) |
| 38 | (root / "src" / "api" / "auth.ts").write_text( |
| 39 | "import { authMiddleware } from '../auth/middleware';\n" |
| 40 | "export function login() { return { ok: true }; }\n", |
| 41 | encoding="utf-8", |
| 42 | ) |
| 43 | (root / "src" / "payment" / "payment.ts").write_text( |
| 44 | "export function charge(amount: number) { return amount; }\n", |
| 45 | encoding="utf-8", |
| 46 | ) |
| 47 | (root / "tests" / "auth.test.ts").write_text( |
| 48 | "import { authMiddleware } from '../src/auth/middleware';\n" |
| 49 | "test('rejects missing token', () => { expect(true).toBe(true); });\n", |
| 50 | encoding="utf-8", |
| 51 | ) |
| 52 | (root / "docs" / "auth.md").write_text( |
| 53 | "# Authentication\n\nCookie-based authentication middleware lives in src/auth.\n", |
| 54 | encoding="utf-8", |
| 55 | ) |
| 56 | (root / "README.md").write_text( |
| 57 | "# Sample App\n\nUses Next.js and MongoDB.\n", |
| 58 | encoding="utf-8", |
| 59 | ) |
| 60 | (root / "package.json").write_text( |
| 61 | '{\n "name": "sample",\n "dependencies": {\n' |
| 62 | ' "next": "14.0.0",\n "react": "18.0.0",\n' |
| 63 | ' "mongodb": "6.0.0",\n "redis": "4.0.0"\n }\n}\n', |
| 64 | encoding="utf-8", |
| 65 | ) |
| 66 | (root / "tsconfig.json").write_text('{ "compilerOptions": {} }\n', encoding="utf-8") |
| 67 | |
| 68 | # Secrets — must never appear in packed context content. |
| 69 | (root / ".env").write_text( |
| 70 | "API_KEY=super-secret-key-12345\nPASSWORD=hunter2\n", |
| 71 | encoding="utf-8", |
| 72 | ) |
| 73 | (root / "credentials.json").write_text( |
| 74 | '{"token": "abc", "password": "x"}\n', |
| 75 | encoding="utf-8", |
| 76 | ) |
| 77 | |
| 78 | # Ignored / generated / binary |
| 79 | (root / "node_modules" / "lodash" / "index.js").write_text( |
| 80 | "module.exports = {};\n", encoding="utf-8" |
| 81 | ) |
| 82 | (root / "dist" / "bundle.js").write_text("console.log(1);\n", encoding="utf-8") |
| 83 | (root / "logo.png").write_bytes(b"\x89PNG\r\n\x1a\n" + b"\x00" * 64) |
| 84 | |
| 85 | (root / ".gitignore").write_text( |
| 86 | "node_modules/\ndist/\n.env\n*.png\n", |
| 87 | encoding="utf-8", |
| 88 | ) |
| 89 | |
| 90 | # File with inline secret that is NOT a sensitive filename |
| 91 | (root / "src" / "config" ).mkdir(parents=True, exist_ok=True) |
| 92 | (root / "src" / "config" / "settings.ts").write_text( |
| 93 | 'export const config = {\n API_KEY: "should-be-redacted",\n port: 3000,\n};\n', |
| 94 | encoding="utf-8", |
| 95 | ) |
| 96 | |
| 97 | return root |