From 0453d8bf7444744806b6d7936ec09f8dae167e15 Mon Sep 17 00:00:00 2001 From: nawaaaaaAaar <198336470+nawaaaaaAaar@users.noreply.github.com> Date: Mon, 5 Oct 2026 05:41:17 +0000 Subject: [PATCH] feat: add offline beginner Git phrases with work-preservation tests --- seed_kb.json | 17 ++++++++++++- tests/test_git_seed_phrases.py | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/test_git_seed_phrases.py diff --git a/seed_kb.json b/seed_kb.json index 6da6407..5b798f5 100644 --- a/seed_kb.json +++ b/seed_kb.json @@ -83,5 +83,20 @@ "show running services": "systemctl list-units --type=service --state=running", "show recent system logs": "journalctl -n 50 --no-pager", "show folder tree": "find . -maxdepth 2 -not -path '*/.*'", - "go back": "cd -" + "go back": "cd -", + "show git status": "git status", + "what did i change": "git diff", + "show staged changes": "git diff --staged", + "which branch am i on": "git branch --show-current", + "list local branches": "git branch", + "show recent commits": "git log --oneline -n 10", + "show the last commit": "git show HEAD", + "stage a file": "git add ", + "save my work": "git add -A && git commit -m ", + "create a git branch": "git switch -c ", + "switch git branch": "git switch ", + "stash my changes": "git stash push -m ", + "list saved stashes": "git stash list", + "restore my stashed work": "git stash pop", + "undo my last commit": "git reset --soft HEAD~1" } diff --git a/tests/test_git_seed_phrases.py b/tests/test_git_seed_phrases.py new file mode 100644 index 0000000..74411b4 --- /dev/null +++ b/tests/test_git_seed_phrases.py @@ -0,0 +1,45 @@ +"""Exercise new offline Git suggestions in an isolated repository.""" + +import json +import shlex +import subprocess +from pathlib import Path + + +SEED = json.loads((Path(__file__).parents[1] / "seed_kb.json").read_text()) + + +def test_offline_git_suggestions_preserve_work(tmp_path): + def git(*args): + return subprocess.run( + ["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True + ).stdout + + def suggestion(phrase, **values): + command = SEED[phrase] + for name, value in values.items(): + command = command.replace(f"<{name}>", shlex.quote(value)) + assert "<" not in command + return subprocess.run( + command, shell=True, cwd=tmp_path, check=True, capture_output=True, text=True + ).stdout + + git("init", "-b", "main") + git("config", "user.name", "Fixture") + git("config", "user.email", "fixture@example.invalid") + (tmp_path / "notes.txt").write_text("first\n") + suggestion("save my work", message="Initial fixture") + assert suggestion("which branch am i on").strip() == "main" + suggestion("create a git branch", branch="feature") + assert suggestion("which branch am i on").strip() == "feature" + (tmp_path / "notes.txt").write_text("second\n") + assert "+second" in suggestion("what did i change") + suggestion("stage a file", file="notes.txt") + assert "+second" in suggestion("show staged changes") + suggestion("save my work", message="Second fixture") + assert "Second fixture" in suggestion("show recent commits") + assert "Second fixture" in suggestion("show the last commit") + suggestion("undo my last commit") + assert (tmp_path / "notes.txt").read_text() == "second\n" + assert "+second" in suggestion("show staged changes") + assert "Initial fixture" in git("log", "-1", "--format=%s")