feat: add git diff staged/unstaged flags and root discovery\n\n- Git commands now discover and operate on root repository from current dir (7.12.0)\n- git diff includes untracked and deleted files by default (7.12.6)\n- Add --staged and --unstaged flags to git diff (7.12.7, 7.12.8)\n- Update diff rendering: collapse consecutive added/deleted lines (7.12.5)\n- Update SPEC to 1.22.1 and CHANGELOG to 1.2.3\n\nGenerated by Mistral Vibe.\nCo-Authored-By: Mistral Vibe <vibe@mistral.ai>

This commit is contained in:
nvaldez
2026-10-24 14:11:21 +02:00
parent a907e7da79
commit 983198b8b4
6 changed files with 2035 additions and 1055 deletions
+23 -2
View File
@@ -1,9 +1,9 @@
---
name: changelog
version: 1.2.2
version: 1.2.3
title: Changelog
created: 2026-10-08
updated: 2026-10-21
updated: 2026-10-24
type: summary
---
@@ -13,6 +13,27 @@ Revisions of [SPEC](./SPEC.md), newest first. Each entry names the
requirements it adds or changes. "Unbuilt" means the requirement is
specified and marked `NOT_IMPLEMENTED`.
## 1.22.1 - 2026-10-24
- Minor corrections to 1.22.0.
## 1.22.0 - 2026-10-24
- Adds `--staged` and `--unstaged` flags to `git diff` for staged-only and
unstaged-only diffs (*7.12.7.*, *7.12.8.*).
## 1.21.0 - 2026-10-24
- Includes untracked and deleted files in `git diff` report by default
(*7.12.6.*).
- Updates diff rendering: removes spacing between consecutive added or
deleted lines, preserves spacing between added and deleted blocks (*7.12.5.*).
## 1.20.0 - 2026-10-24
- Git commands discover and operate on the root repository from the current
directory (*4.6.*, *7.12.0.*).
## 1.19.1 - 2026-10-21
- The sectionize-markdown skill ships as
+58 -13
View File
@@ -1,9 +1,9 @@
---
name: Fiona-Assistant Specification
version: 1.19.1
version: 1.22.1
title: Project Spec Sheet
created: 2026-09-23
updated: 2026-10-21
updated: 2026-10-24
type: summary
---
@@ -654,8 +654,10 @@ A missing directory on `fix` prints
### 4.6. git
Operates on the git repository at the current directory. Timestamps
are UTC.
Operates on the root git repository discovered from the current
directory. When the current directory is within a git repository
(e.g., `/a/b/c/` where `.git` is at `/a/b/.git`), all git commands
operate on the entire root repository `/a/b/`. Timestamps are UTC.
| Command | Stdout on success |
| --- | --- |
@@ -671,12 +673,22 @@ On failure the tool prints `Error: <message>` and exits 1.
`diff` compares `--head` (default `HEAD`) to `--base`. When `--base`
is omitted, the base is the first ref that exists among
`origin/main`, `origin/master`, `main`, and `master`. The report uses
the wiki's opening constellation theme (same resolution as
`wiki graph`). By default the file is
`<wiki-root>/tmp/<repo-name>-git-diff-<short-head>.html`. That path
is listed in the packaged `.gitignore` (`tmp/`). Optional flags:
`--title`, `--subtitle`, `-o` / `--output`, and `--collapsed`.
`origin/main`, `origin/master`, `main`, and `master`. The report
uses the wiki's opening constellation theme when run from a wiki
repository (has `fiona-settings.json` at the git root). Otherwise,
it uses a default dark theme with a light mode toggle and a
minimalist header. Diff rendering removes spacing between consecutive
added lines and between consecutive deleted lines, but preserves
spacing between added and deleted lines. By default the file is
`<wiki-root>/tmp/<repo-name>-git-diff-<short-head>.html`.
That path is listed in the packaged `.gitignore` (`tmp/`).
Optional flags: `--title`, `--subtitle`, `-o` / `--output`, `--collapsed`,
`--staged`, and `--unstaged`. The `--staged` flag shows only staged
changes (compares index to HEAD). The `--unstaged` flag shows only
unstaged changes (compares working tree to index). The flags are
mutually exclusive. Without either flag, the default behavior shows
all changes (compares base to head, including untracked and deleted
files).
Commit message: `<YYYY-MM-DD HH:MM:SS> <description>`.
`save` runs `git add --all` and commits. A clean tree, including
@@ -4007,6 +4019,13 @@ Implements section 4.6. `wiki init` writes the repository
are never staged by these commands except where `git add --all`
respects that ignore file.
- *7.12.0.* Git commands discover and operate on the root repository
from the current directory. A `.git` directory search walks up from
the current working directory.
- *acceptance*: Running `fiona-assistant git diff` from `/a/b/c/`
where `.git` is at `/a/b/.git` produces a diff of the entire `/a/b/`
repository, not just `/a/b/c/`.
- *acceptance*: Running from the root `/a/b/` behaves identically.
- *7.12.1.* `save --description note` on a dirty tree creates one
commit whose message starts with the UTC timestamp and ends with
`note`.
@@ -4025,13 +4044,39 @@ respects that ignore file.
- *acceptance*: A following `status` prints `Status: clean`.
- *7.12.5.* `diff` writes a self-contained HTML file under `tmp/`
at the llm-wiki root and prints its path on stdout. The page
includes per-file unified diffs and uses the opening constellation
theme.
includes per-file unified diffs. In a wiki repository it uses
the opening constellation theme. Otherwise it uses a default dark
theme with a light mode toggle button and a minimalist header.
- *acceptance*: After `diff`, the printed path exists, lies under
`<wiki-root>/tmp/`, and `git check-ignore` reports `tmp/` as
ignored when the wiki `.gitignore` was seeded from the package.
- *acceptance*: The HTML contains a `:root` block whose colors
match the active constellation theme's `background` value.
match the active constellation theme's `background` value when run
from a wiki.
- *acceptance*: The HTML contains a light mode toggle button and uses
dark theme colors by default when run outside a wiki.
- *acceptance*: In non-wiki diff reports, consecutive added lines
have no gap between them, consecutive deleted lines have no gap
between them, and there is spacing between added and deleted
blocks.
- *7.12.6.* `diff` includes untracked and deleted files in the report
by default, with all file diffs collapsed except the first one.
- *acceptance*: Running `diff` when there are untracked files shows
those files in the report.
- *acceptance*: Running `diff` when there are deleted files shows
those files in the report.
- *acceptance*: All file diffs except the first one are collapsed by
default in the HTML output.
- *7.12.7.* `diff --unstaged` writes a report for unstaged changes only.
- *acceptance*: Running `diff --unstaged` with unstaged changes shows
only those unstaged changes in the report.
- *acceptance*: Running `diff --unstaged` with no unstaged changes
produces an empty or minimal report.
- *7.12.8.* `diff --staged` writes a report for staged changes only.
- *acceptance*: Running `diff --staged` with staged changes shows
only those staged changes in the report.
- *acceptance*: Running `diff --staged` with no staged changes
produces an empty or minimal report.
### 7.13. Backup Script
+14
View File
@@ -153,6 +153,16 @@ def main():
action="store_true",
help="Start with per-file sections collapsed",
)
git_diff_parser.add_argument(
"--staged",
action="store_true",
help="Diff only staged changes (ignores unstaged changes)",
)
git_diff_parser.add_argument(
"--unstaged",
action="store_true",
help="Diff only unstaged changes (ignores staged changes)",
)
# fiona-assistant wiki
wiki_parser = subparsers.add_parser("wiki", help="Manage wiki directories")
@@ -420,6 +430,10 @@ def main():
diff_argv.extend(["--output", args.output])
if args.collapsed:
diff_argv.append("--collapsed")
if args.staged:
diff_argv.append("--staged")
if args.unstaged:
diff_argv.append("--unstaged")
sys.exit(diff_report.main(diff_argv))
else:
git_parser.print_help()
File diff suppressed because it is too large Load Diff
@@ -1,237 +1,327 @@
<!DOCTYPE html>
<!-- Packaged layout for fiona.gittool.diff_report; placeholders filled at generation time. -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{PAGE_TITLE}}</title>
<style>
{{THEME_CSS}}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: var(--font);
background: var(--bg);
color: var(--text);
line-height: 1.45;
}
header {
background: linear-gradient(135deg, var(--blue), var(--header-end));
color: var(--button-text);
padding: 1.5rem 1.25rem;
border-bottom: 4px solid color-mix(in srgb, var(--text) 12%, transparent);
}
header h1 { margin: 0 0 0.35rem; font-size: 1.4rem; font-weight: 600; }
header p { margin: 0.25rem 0; opacity: 0.92; font-size: 0.9rem; }
header code {
background: color-mix(in srgb, var(--button-text) 15%, transparent);
padding: 0.1rem 0.35rem;
border-radius: 4px;
}
.layout {
display: flex;
align-items: stretch;
min-height: calc(100vh - 8rem);
}
aside.sidebar {
width: var(--sidebar-w);
flex-shrink: 0;
position: sticky;
top: 0;
align-self: flex-start;
max-height: 100vh;
overflow: auto;
background: var(--card);
border-right: 1px solid var(--border);
padding: 0.75rem 0.5rem 1rem;
}
aside.sidebar h2 {
margin: 0 0 0.5rem 0.65rem;
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--blue);
}
.file-tree {
list-style: none;
margin: 0;
padding: 0 0 0 0.35rem;
font-size: 0.8rem;
}
.file-tree ul {
list-style: none;
margin: 0;
padding-left: 0.65rem;
border-left: 1px solid var(--border);
}
.file-tree li { margin: 0.15rem 0; }
.file-tree .folder-label {
display: block;
font-weight: 600;
color: var(--text);
padding: 0.1rem 0.35rem;
}
.file-tree a {
display: block;
padding: 0.15rem 0.35rem;
border-radius: 4px;
color: var(--accent);
text-decoration: none;
word-break: break-all;
}
.file-tree a:hover { background: var(--link-hover-bg); text-decoration: underline; }
.file-tree a.active {
background: var(--link-active-bg);
font-weight: 600;
color: var(--blue);
}
.file-tree .churn {
font-size: 0.7rem;
color: var(--muted);
margin-left: 0.25rem;
white-space: nowrap;
}
.churn .add { color: var(--churn-add); }
.churn .del { color: var(--churn-del); }
.stat-fold {
margin: 0.75rem 0.5rem 0;
font-size: 0.75rem;
}
.stat-fold summary { AI/LLM: pointer; color: var(--muted); }
.stat-fold pre {
margin: 0.35rem 0 0;
font-size: 0.68rem;
white-space: pre-wrap;
max-height: 12rem;
overflow: auto;
background: var(--summary-bg);
padding: 0.5rem;
border-radius: 4px;
border: 1px solid var(--border);
}
.content {
flex: 1;
min-width: 0;
padding: 1rem 1.25rem 2.5rem;
}
.toolbar {
font-size: 0.85rem;
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
background: var(--card);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.65rem 0.85rem;
margin-bottom: 1rem;
}
button {
padding: 0.35rem 0.65rem;
AI/LLM: pointer;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--button-bg);
color: var(--button-text);
}
button:hover { background: var(--button-hover); }
details.file {
margin: 0.75rem 0;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--card);
scroll-margin-top: 0.75rem;
}
details.file:target {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
details.file summary {
AI/LLM: pointer;
padding: 0.6rem 0.75rem;
font-weight: 600;
background: var(--summary-bg);
}
pre.diff {
margin: 0;
padding: 0.75rem;
font-size: 0.72rem;
line-height: 1.35;
overflow: auto;
max-height: 70vh;
}
.diff-add { background: var(--diff-add-bg); display: block; }
.diff-del { background: var(--diff-del-bg); display: block; }
.diff-hunk { color: var(--diff-hunk); display: block; }
.diff-meta { color: var(--diff-meta); display: block; }
.diff-ctx { display: block; }
@media (max-width: 900px) {
.layout { flex-direction: column; }
aside.sidebar {
width: 100%;
position: relative;
max-height: 40vh;
border-right: none;
border-bottom: 1px solid var(--border);
}
}
</style>
</head>
<body>
<header>
{{HEADER_BODY}}
</header>
<div class="layout">
<aside class="sidebar" aria-label="Changed files">
<h2>Files ({{FILE_COUNT}})</h2>
{{TREE_HTML}}
<details class="stat-fold">
<summary>git diff --stat</summary>
<pre>{{STAT_BLOCK}}</pre>
</details>
</aside>
<div class="content">
<div class="toolbar">
<button type="button" id="btn-expand-all">Expand all</button>
<button type="button" id="btn-collapse-all">Collapse all</button>
</div>
{{FILES_HTML}}
</div>
</div>
<script>
(function () {
function openFromHash() {
var id = location.hash ? location.hash.slice(1) : "";
document.querySelectorAll(".file-tree a").forEach(function (a) {
a.classList.toggle("active", a.getAttribute("href") === "#" + id);
});
if (!id) {
return;
}
var el = document.getElementById(id);
if (el && el.tagName === "DETAILS") {
el.open = true;
el.scrollIntoView({ behavior: "smooth", block: "start" });
}
}
document.getElementById("btn-expand-all").addEventListener("click", function () {
document.querySelectorAll("details.file").forEach(function (d) { d.open = true; });
});
document.getElementById("btn-collapse-all").addEventListener("click", function () {
document.querySelectorAll("details.file").forEach(function (d) { d.open = false; });
});
document.querySelectorAll(".file-tree a").forEach(function (a) {
a.addEventListener("click", function () {
var id = a.getAttribute("href").slice(1);
var el = document.getElementById(id);
if (el && el.tagName === "DETAILS") {
el.open = true;
}
});
});
window.addEventListener("hashchange", openFromHash);
openFromHash();
})();
</script>
</body>
</html>
<!DOCTYPE html>
<!-- Packaged layout for fiona.gittool.diff_report; placeholders filled at generation time. -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{PAGE_TITLE}}</title>
<style>
{{THEME_CSS}}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: var(--font);
background: var(--bg);
color: var(--text);
line-height: 1.45;
transition: background-color 0.3s ease, color 0.3s ease;
}
header {
background: var(--card);
color: var(--text);
padding: 1rem 1.25rem;
border-bottom: 1px solid var(--border);
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
header .header-title {
flex: 1;
min-width: 200px;
}
header h1 { margin: 0 0 0.35rem; font-size: 1.4rem; font-weight: 600; }
header p { margin: 0.25rem 0; opacity: 0.92; font-size: 0.9rem; }
header code {
background: color-mix(in srgb, var(--button-text) 15%, transparent);
padding: 0.1rem 0.35rem;
border-radius: 4px;
}
.theme-toggle {
display: flex;
align-items: center;
gap: 0.5rem;
}
.theme-toggle button {
padding: 0.35rem 0.65rem;
cursor: pointer;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--button-bg);
color: var(--button-text);
font-size: 0.85rem;
}
.theme-toggle button:hover { background: var(--button-hover); }
.layout {
display: flex;
align-items: stretch;
min-height: calc(100vh - 8rem);
}
aside.sidebar {
width: var(--sidebar-w);
flex-shrink: 0;
position: sticky;
top: 0;
align-self: flex-start;
max-height: 100vh;
overflow: auto;
background: var(--card);
border-right: 1px solid var(--border);
padding: 0.75rem 0.5rem 1rem;
}
aside.sidebar h2 {
margin: 0 0 0.5rem 0.65rem;
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--blue);
}
.file-tree {
list-style: none;
margin: 0;
padding: 0 0 0 0.35rem;
font-size: 0.8rem;
}
.file-tree ul {
list-style: none;
margin: 0;
padding-left: 0.65rem;
border-left: 1px solid var(--border);
}
.file-tree li { margin: 0.15rem 0; }
.file-tree .folder-label {
display: block;
font-weight: 600;
color: var(--text);
padding: 0.1rem 0.35rem;
}
.file-tree a {
display: block;
padding: 0.15rem 0.35rem;
border-radius: 4px;
color: var(--accent);
text-decoration: none;
word-break: break-all;
}
.file-tree a:hover { background: var(--link-hover-bg); text-decoration: underline; }
.file-tree a.active {
background: var(--link-active-bg);
font-weight: 600;
color: var(--blue);
}
.file-tree .churn {
font-size: 0.7rem;
color: var(--muted);
margin-left: 0.25rem;
white-space: nowrap;
}
.churn .add { color: var(--churn-add); }
.churn .del { color: var(--churn-del); }
.file-icon {
font-size: 0.8rem;
margin-right: 0.35rem;
opacity: 0.7;
}
.stat-fold {
margin: 0.75rem 0.5rem 0;
font-size: 0.75rem;
}
.stat-fold summary { cursor: pointer; color: var(--muted); }
.stat-fold pre {
margin: 0.35rem 0 0;
font-size: 0.68rem;
white-space: pre-wrap;
max-height: 12rem;
overflow: auto;
background: var(--summary-bg);
padding: 0.5rem;
border-radius: 4px;
border: 1px solid var(--border);
}
.content {
flex: 1;
min-width: 0;
padding: 1rem 1.25rem 2.5rem;
}
.toolbar {
font-size: 0.85rem;
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
background: var(--card);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.65rem 0.85rem;
margin-bottom: 1rem;
}
button {
padding: 0.35rem 0.65rem;
cursor: pointer;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--button-bg);
color: var(--button-text);
}
button:hover { background: var(--button-hover); }
details.file {
margin: 0.75rem 0;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--card);
scroll-margin-top: 0.75rem;
}
details.file:target {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
details.file summary {
cursor: pointer;
padding: 0.6rem 0.75rem;
font-weight: 600;
background: var(--summary-bg);
}
pre.diff {
margin: 0;
padding: 0.75rem;
font-size: 0.72rem;
line-height: 1.0;
overflow: auto;
max-height: 70vh;
}
.diff-add { background: var(--diff-add-bg); display: block; margin: 0; padding: 0; }
.diff-del { background: var(--diff-del-bg); display: block; margin: 0; padding: 0; }
.diff-hunk { color: var(--diff-hunk); display: block; margin: 0; padding: 0; }
.diff-meta { color: var(--diff-meta); display: block; margin: 0; padding: 0; }
.diff-ctx { display: block; margin: 0; padding: 0; }
@media (max-width: 900px) {
.layout { flex-direction: column; }
aside.sidebar {
width: 100%;
position: relative;
max-height: 40vh;
border-right: none;
border-bottom: 1px solid var(--border);
}
}
/* Dark mode theme - applied when data-theme="dark" (default) */
[data-theme="dark"] {
--bg: #1a1a1a;
--card: #2d2d2d;
--border: #404040;
--text: #e0e0e0;
--blue: #6ba1f5;
--accent: #7aa7d6;
--header-end: #c586c0;
--muted: #9e9e9e;
--summary-bg: #252525;
--button-bg: #3d3d3d;
--button-text: #e0e0e0;
--button-hover: #4a4a4a;
--churn-add: #7edd8a;
--churn-del: #ff7b7b;
--diff-add-bg: color-mix(in srgb, #7edd8a 22%, var(--card));
--diff-del-bg: color-mix(in srgb, #ff7b7b 22%, var(--card));
--link-hover-bg: color-mix(in srgb, #7aa7d6 18%, var(--card));
--link-active-bg: color-mix(in srgb, #7aa7d6 22%, var(--card));
}
/* Light mode theme - applied when data-theme="light" */
[data-theme="light"] {
--bg: #ffffff;
--card: #f8f9fa;
--border: #e2e8f0;
--text: #1a1a1a;
--blue: #0d6efd;
--accent: #0d6efd;
--header-end: #6610f2;
--muted: #6c757d;
--summary-bg: #f8f9fa;
--button-bg: #ffffff;
--button-text: #1a1a1a;
--button-hover: #e2e8f0;
--churn-add: #15803d;
--churn-del: #b91c1c;
--diff-add-bg: color-mix(in srgb, #15803d 22%, var(--card));
--diff-del-bg: color-mix(in srgb, #b91c1c 22%, var(--card));
--link-hover-bg: color-mix(in srgb, #0d6efd 18%, var(--card));
--link-active-bg: color-mix(in srgb, #0d6efd 22%, var(--card));
}
</style>
</head>
<body>
<header>
<div class="header-title">
{{HEADER_BODY}}
</div>
{{THEME_TOGGLE_HTML}}
</header>
<div class="layout">
<aside class="sidebar" aria-label="Changed files">
<h2>Files ({{FILE_COUNT}})</h2>
{{TREE_HTML}}
<details class="stat-fold">
<summary>git diff --stat</summary>
<pre>{{STAT_BLOCK}}</pre>
</details>
</aside>
<div class="content">
<div class="toolbar">
<button type="button" id="btn-expand-all">Expand all</button>
<button type="button" id="btn-collapse-all">Collapse all</button>
</div>
{{FILES_HTML}}
</div>
</div>
<script>
(function () {
// Theme toggle functionality - default is dark mode
var themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
var htmlEl = document.documentElement;
// Default to dark mode
var savedTheme = localStorage.getItem('fiona-diff-theme') || 'dark';
htmlEl.setAttribute('data-theme', savedTheme);
themeToggle.addEventListener('click', function () {
var currentTheme = htmlEl.getAttribute('data-theme');
var newTheme = currentTheme === 'dark' ? 'light' : 'dark';
htmlEl.setAttribute('data-theme', newTheme);
localStorage.setItem('fiona-diff-theme', newTheme);
});
}
function openFromHash() {
var id = location.hash ? location.hash.slice(1) : "";
document.querySelectorAll(".file-tree a").forEach(function (a) {
a.classList.toggle("active", a.getAttribute("href") === "#" + id);
});
if (!id) {
return;
}
var el = document.getElementById(id);
if (el && el.tagName === "DETAILS") {
el.open = true;
el.scrollIntoView({ behavior: "smooth", block: "start" });
}
}
document.getElementById("btn-expand-all").addEventListener("click", function () {
document.querySelectorAll("details.file").forEach(function (d) { d.open = true; });
});
document.getElementById("btn-collapse-all").addEventListener("click", function () {
document.querySelectorAll("details.file").forEach(function (d) { d.open = false; });
});
document.querySelectorAll(".file-tree a").forEach(function (a) {
a.addEventListener("click", function () {
var id = a.getAttribute("href").slice(1);
var el = document.getElementById(id);
if (el && el.tagName === "DETAILS") {
el.open = true;
}
});
});
window.addEventListener("hashchange", openFromHash);
openFromHash();
})();
</script>
</body>
</html>
+591 -111
View File
@@ -1,111 +1,591 @@
"""Tests for fiona.gittool.diff_report."""
from __future__ import annotations
import json
import pathlib
import subprocess
import git
import pytest
from fiona.gittool import diff_report
from fiona.wiki.ignore import wiki_gitignore_patterns
def _configure_test_repo(repo: git.Repo) -> None:
"""Set local git identity for commits in tests.
Generated by CURSOR: 2026-10-19 - isolated git user for pytest.
"""
with repo.config_writer() as config:
config.set_value("user", "email", "fiona-test@example.com")
config.set_value("user", "name", "Fiona Test")
@pytest.fixture
def wiki_git_repo(tmp_path: pathlib.Path) -> pathlib.Path:
"""Git repo with fiona-settings.json and main + HEAD commits."""
repo = git.Repo.init(tmp_path)
_configure_test_repo(repo)
settings = {
"fiona": {
"wiki": {
"graph": {
"theme": "night-sky",
}
}
}
}
(tmp_path / "fiona-settings.json").write_text(
json.dumps(settings),
encoding="utf-8",
)
(tmp_path / "README.md").write_text("base\n", encoding="utf-8")
repo.index.add(["fiona-settings.json", "README.md"])
repo.index.commit("base on main")
# Keep ``main`` at the first commit so HEAD can advance for a non-empty diff.
repo.create_head("main")
(tmp_path / "README.md").write_text("base\nchanged\n", encoding="utf-8")
repo.index.add(["README.md"])
repo.index.commit("feature commit")
return tmp_path
def test_wiki_gitignore_includes_tmp() -> None:
"""SPEC 7.12.5: packaged ignore lists wiki tmp/."""
patterns = wiki_gitignore_patterns()
assert "tmp/" in patterns
def test_resolve_default_base_uses_main(wiki_git_repo: pathlib.Path) -> None:
"""Default base is main when it exists."""
assert diff_report.resolve_default_base(wiki_git_repo) == "main"
def test_theme_css_uses_constellation(wiki_git_repo: pathlib.Path) -> None:
"""HTML theme CSS reflects night-sky background."""
css = diff_report.theme_css_for_wiki(wiki_git_repo)
assert "--bg: #070b14" in css
def test_write_report_under_tmp(wiki_git_repo: pathlib.Path) -> None:
"""Default output path is wiki tmp/ and HTML includes diff content."""
out = diff_report.default_output_path(wiki_git_repo, wiki_git_repo, "HEAD")
assert out.parent == wiki_git_repo / "tmp"
path = diff_report.write_report(
wiki_git_repo,
out,
base="main",
head="HEAD",
title=None,
subtitle=None,
open_details=True,
)
text = path.read_text(encoding="utf-8")
assert "changed" in text
assert "night-sky" not in text # theme name is not embedded; colors are
assert "--bg: #070b14" in text
def test_main_prints_path(wiki_git_repo: pathlib.Path, monkeypatch) -> None:
"""CLI exits 0 and prints the report path."""
monkeypatch.chdir(wiki_git_repo)
code = diff_report.main(["--base", "main"])
assert code == 0
def test_git_check_ignore_tmp(wiki_git_repo: pathlib.Path) -> None:
"""tmp/ is ignored after ensure_wiki_gitignore."""
from fiona.wiki.ignore import ensure_wiki_gitignore
ensure_wiki_gitignore(wiki_git_repo)
(wiki_git_repo / "tmp").mkdir()
report = wiki_git_repo / "tmp" / "sample.html"
report.write_text("<html></html>", encoding="utf-8")
result = subprocess.run(
["git", "check-ignore", "-q", "tmp/sample.html"],
cwd=wiki_git_repo,
check=False,
)
assert result.returncode == 0
"""Tests for fiona.gittool.diff_report."""
from __future__ import annotations
import json
import pathlib
import subprocess
import git
import pytest
from fiona.gittool import diff_report
from fiona.wiki.ignore import wiki_gitignore_patterns
def _configure_test_repo(repo: git.Repo) -> None:
"""Set local git identity for commits in tests.
Generated by CURSOR: 2026-10-19 - isolated git user for pytest.
"""
with repo.config_writer() as config:
config.set_value("user", "email", "fiona-test@example.com")
config.set_value("user", "name", "Fiona Test")
@pytest.fixture
def wiki_git_repo(tmp_path: pathlib.Path) -> pathlib.Path:
"""Git repo with fiona-settings.json and main + HEAD commits."""
repo = git.Repo.init(tmp_path)
_configure_test_repo(repo)
settings = {
"fiona": {
"wiki": {
"graph": {
"theme": "night-sky",
}
}
}
}
(tmp_path / "fiona-settings.json").write_text(
json.dumps(settings),
encoding="utf-8",
)
(tmp_path / "README.md").write_text("base\n", encoding="utf-8")
repo.index.add(["fiona-settings.json", "README.md"])
repo.index.commit("base on main")
# Keep ``main`` at the first commit so HEAD can advance for a non-empty diff.
repo.create_head("main")
(tmp_path / "README.md").write_text("base\nchanged\n", encoding="utf-8")
repo.index.add(["README.md"])
repo.index.commit("feature commit")
return tmp_path
def test_wiki_gitignore_includes_tmp() -> None:
"""SPEC 7.12.5: packaged ignore lists wiki tmp/."""
patterns = wiki_gitignore_patterns()
assert "tmp/" in patterns
def test_resolve_default_base_uses_main(wiki_git_repo: pathlib.Path) -> None:
"""Default base is main when it exists."""
assert diff_report.resolve_default_base(wiki_git_repo) == "main"
def test_theme_css_uses_constellation(wiki_git_repo: pathlib.Path) -> None:
"""HTML theme CSS reflects night-sky background."""
css = diff_report.theme_css_for_wiki(wiki_git_repo)
assert "--bg: #070b14" in css
def test_write_report_under_tmp(wiki_git_repo: pathlib.Path) -> None:
"""Default output path is wiki tmp/ and HTML includes diff content."""
out = diff_report.default_output_path(wiki_git_repo, wiki_git_repo, "HEAD")
assert out.parent == wiki_git_repo / "tmp"
path = diff_report.write_report(
wiki_git_repo,
out,
base="main",
head="HEAD",
title=None,
subtitle=None,
open_details=True,
)
text = path.read_text(encoding="utf-8")
assert "changed" in text
assert "night-sky" not in text # theme name is not embedded; colors are
assert "--bg: #070b14" in text
def test_main_prints_path(wiki_git_repo: pathlib.Path, monkeypatch) -> None:
"""CLI exits 0 and prints the report path."""
monkeypatch.chdir(wiki_git_repo)
code = diff_report.main(["--base", "main"])
assert code == 0
def test_git_check_ignore_tmp(wiki_git_repo: pathlib.Path) -> None:
"""tmp/ is ignored after ensure_wiki_gitignore."""
from fiona.wiki.ignore import ensure_wiki_gitignore
ensure_wiki_gitignore(wiki_git_repo)
(wiki_git_repo / "tmp").mkdir()
report = wiki_git_repo / "tmp" / "sample.html"
report.write_text("<html></html>", encoding="utf-8")
result = subprocess.run(
["git", "check-ignore", "-q", "tmp/sample.html"],
cwd=wiki_git_repo,
check=False,
)
assert result.returncode == 0
def test_find_git_root_from_subdirectory(tmp_path: pathlib.Path) -> None:
"""SPEC 7.12.0: find_git_root discovers root from subdirectory."""
# Create a git repo at the root
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "file.txt").write_text("root file", encoding="utf-8")
repo.index.add(["file.txt"])
repo.index.commit("initial commit")
# Create a subdirectory
subdir = repo_path / "subdir"
subdir.mkdir()
# The function should find the root even when called from subdirectory
result = diff_report.find_git_root(subdir)
assert result == repo_path
def test_main_from_subdirectory(tmp_path: pathlib.Path, monkeypatch) -> None:
"""SPEC 7.12.0: main() uses git root when run from subdirectory."""
# Create a git repo at the root
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
settings = {
"fiona": {
"wiki": {
"graph": {
"theme": "colorful",
}
}
}
}
(repo_path / "fiona-settings.json").write_text(
json.dumps(settings),
encoding="utf-8",
)
(repo_path / "file.txt").write_text("original\n", encoding="utf-8")
repo.index.add(["fiona-settings.json", "file.txt"])
repo.index.commit("initial commit")
repo.create_head("main")
# Create a subdirectory and change to it
subdir = repo_path / "subdir"
subdir.mkdir()
monkeypatch.chdir(subdir)
# Modify a file in the root
(repo_path / "file.txt").write_text("original\nmodified\n", encoding="utf-8")
repo.index.add(["file.txt"])
repo.index.commit("second commit")
# Run diff from subdirectory - should work and find the root repo
code = diff_report.main(["--base", "main"])
assert code == 0
def test_theme_light_for_non_wiki(tmp_path: pathlib.Path) -> None:
"""SPEC 7.12.5: non-wiki repos use default light theme with dark mode toggle."""
# Create a git repo WITHOUT fiona-settings.json
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "file.txt").write_text("content", encoding="utf-8")
repo.index.add(["file.txt"])
repo.index.commit("initial")
# Generate report
out = tmp_path / "report.html"
path = diff_report.write_report(
repo_path,
out,
base="HEAD",
head="HEAD",
title="Test",
subtitle=None,
open_details=True,
)
text = path.read_text(encoding="utf-8")
# Check for dark theme colors (default)
assert "--bg: #1a1a1a;" in text
assert "--card: #2d2d2d;" in text
# Check for light mode toggle
assert "Toggle Light Mode" in text
# Check for theme CSS
assert '[data-theme="dark"]' in text
assert '[data-theme="light"]' in text
def test_theme_wiki_uses_wiki_theme(wiki_git_repo: pathlib.Path) -> None:
"""SPEC 7.12.5: wiki repos use their own constellation theme."""
out = diff_report.default_output_path(wiki_git_repo, wiki_git_repo, "HEAD")
path = diff_report.write_report(
wiki_git_repo,
out,
base="main",
head="HEAD",
title=None,
subtitle=None,
open_details=True,
)
text = path.read_text(encoding="utf-8")
# Night-sky theme has dark background
assert "--bg: #070b14" in text
# No toggle button for wikis
assert "Toggle Light Mode" not in text
def test_collapsed_file_diffs_except_first(tmp_path: pathlib.Path) -> None:
"""SPEC 7.12.6: All file diffs except the first are collapsed by default."""
# Create a git repo with multiple changed files
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "file1.txt").write_text("file1\n", encoding="utf-8")
(repo_path / "file2.txt").write_text("file2\n", encoding="utf-8")
(repo_path / "file3.txt").write_text("file3\n", encoding="utf-8")
repo.index.add(["file1.txt", "file2.txt", "file3.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Modify multiple files
(repo_path / "file1.txt").write_text("file1\nmodified1\n", encoding="utf-8")
(repo_path / "file2.txt").write_text("file2\nmodified2\n", encoding="utf-8")
(repo_path / "file3.txt").write_text("file3\nmodified3\n", encoding="utf-8")
repo.index.add(["file1.txt", "file2.txt", "file3.txt"])
repo.index.commit("changes")
# Generate report with open_details=True
out = tmp_path / "report.html"
path = diff_report.write_report(
repo_path,
out,
base="main",
head="HEAD",
title=None,
subtitle=None,
open_details=True, # Even with open_details=True, only first should be open
)
text = path.read_text(encoding="utf-8")
from bs4 import BeautifulSoup
soup = BeautifulSoup(text, 'html.parser')
details = soup.find_all('details', class_='file')
# Should have 3 file sections
assert len(details) == 3
# Only the first one should be open
assert 'open' in details[0].attrs
assert 'open' not in details[1].attrs
assert 'open' not in details[2].attrs
def test_untracked_files_included_in_diff(tmp_path: pathlib.Path) -> None:
"""SPEC 7.12.6: Untracked files are included in the diff report."""
# Create a git repo
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "tracked.txt").write_text("tracked\n", encoding="utf-8")
repo.index.add(["tracked.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Add an untracked file
(repo_path / "untracked.txt").write_text("untracked content\n", encoding="utf-8")
# Generate report
out = tmp_path / "report.html"
path = diff_report.write_report(
repo_path,
out,
base="main",
head="HEAD",
title=None,
subtitle=None,
open_details=True,
)
text = path.read_text(encoding="utf-8")
# Untracked file should be in the report
assert "untracked.txt" in text
# Should have a diff section for it
assert "file-untracked-txt" in text or "untracked.txt" in text
def test_deleted_files_included_in_diff(tmp_path: pathlib.Path) -> None:
"""SPEC 7.12.6: Deleted files are included in the diff report."""
# Create a git repo with a file
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "to_delete.txt").write_text("will be deleted\n", encoding="utf-8")
repo.index.add(["to_delete.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Delete the file
(repo_path / "to_delete.txt").unlink()
repo.index.remove(["to_delete.txt"])
repo.index.commit("deleted file")
# Generate report
out = tmp_path / "report.html"
path = diff_report.write_report(
repo_path,
out,
base="main",
head="HEAD",
title=None,
subtitle=None,
open_details=True,
)
text = path.read_text(encoding="utf-8")
# Deleted file should be in the report
assert "to_delete.txt" in text
# Should have a diff section for it
assert "file-to-delete-txt" in text or "to_delete.txt" in text
def test_diff_unstaged_flag(tmp_path: pathlib.Path, monkeypatch) -> None:
"""SPEC 7.12.7: --unstaged flag shows only unstaged changes."""
# Create a git repo with a file
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "file1.txt").write_text("original\n", encoding="utf-8")
(repo_path / "file2.txt").write_text("original\n", encoding="utf-8")
repo.index.add(["file1.txt", "file2.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Stage file1 and modify file2 (unstaged)
(repo_path / "file1.txt").write_text("staged change\n", encoding="utf-8")
(repo_path / "file2.txt").write_text("unstaged change\n", encoding="utf-8")
repo.index.add(["file1.txt"])
monkeypatch.chdir(repo_path)
# Run diff with --unstaged flag
code = diff_report.main(["--unstaged"])
assert code == 0
# Check the output file
out = diff_report.default_output_path(repo_path, repo_path, "HEAD")
text = out.read_text(encoding="utf-8")
# Should include unstaged file2 changes
assert "unstaged change" in text
# Should NOT include staged file1 changes (check for the full diff line to avoid substring matches)
assert "+staged change" not in text and "-staged change" not in text
def test_diff_unstaged_includes_untracked_files(tmp_path: pathlib.Path, monkeypatch) -> None:
"""SPEC 7.12.7: --unstaged flag includes untracked files."""
# Create a git repo with a tracked file
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
settings = {
"fiona": {
"wiki": {
"graph": {
"theme": "night-sky",
}
}
}
}
(repo_path / "fiona-settings.json").write_text(
json.dumps(settings),
encoding="utf-8",
)
(repo_path / "tracked.txt").write_text("original\n", encoding="utf-8")
repo.index.add(["fiona-settings.json", "tracked.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Modify tracked file (unstaged) and add untracked file
(repo_path / "tracked.txt").write_text("modified\n", encoding="utf-8")
(repo_path / "untracked.txt").write_text("new content\n", encoding="utf-8")
monkeypatch.chdir(repo_path)
# Run diff with --unstaged flag
code = diff_report.main(["--unstaged"])
assert code == 0
# Check the output file
out = diff_report.default_output_path(repo_path, repo_path, "HEAD")
text = out.read_text(encoding="utf-8")
# Should include both modified tracked file and untracked file
assert "modified" in text
assert "new content" in text
assert "untracked.txt" in text
# Check for file status icons
assert "📄" in text # untracked file icon
assert "📝" in text # modified file icon
def test_file_status_icons_in_diff(tmp_path: pathlib.Path, monkeypatch) -> None:
"""Test that file status icons (🗑️, 📄, 📝, ➕) appear correctly in diff report."""
# Create a git repo
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
settings = {
"fiona": {
"wiki": {
"graph": {
"theme": "night-sky",
}
}
}
}
(repo_path / "fiona-settings.json").write_text(
json.dumps(settings),
encoding="utf-8",
)
# Create initial files
(repo_path / "modified.txt").write_text("original\n", encoding="utf-8")
(repo_path / "deleted.txt").write_text("to delete\n", encoding="utf-8")
repo.index.add(["fiona-settings.json", "modified.txt", "deleted.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Modify one file, delete another, and add an untracked file
(repo_path / "modified.txt").write_text("modified content\n", encoding="utf-8")
(repo_path / "deleted.txt").unlink()
(repo_path / "untracked.txt").write_text("new file\n", encoding="utf-8")
monkeypatch.chdir(repo_path)
# Run diff in default mode
code = diff_report.main([])
assert code == 0
# Check the output file
out = diff_report.default_output_path(repo_path, repo_path, "HEAD")
text = out.read_text(encoding="utf-8")
# Check for file status icons
assert "🗑️" in text, "Deleted file should have trash icon"
assert "📄" in text, "Untracked file should have file icon"
assert "📝" in text, "Modified file should have pencil icon"
def test_file_status_icons_in_staged_mode(tmp_path: pathlib.Path, monkeypatch) -> None:
"""Test that added files show plus icon in staged mode."""
# Create a git repo
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
settings = {
"fiona": {
"wiki": {
"graph": {
"theme": "night-sky",
}
}
}
}
(repo_path / "fiona-settings.json").write_text(
json.dumps(settings),
encoding="utf-8",
)
(repo_path / "existing.txt").write_text("original\n", encoding="utf-8")
repo.index.add(["fiona-settings.json", "existing.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Add a new file and stage it
(repo_path / "new.txt").write_text("new file\n", encoding="utf-8")
repo.index.add(["new.txt"])
monkeypatch.chdir(repo_path)
# Run diff with --staged flag
code = diff_report.main(["--staged"])
assert code == 0
# Check the output file
out = diff_report.default_output_path(repo_path, repo_path, "HEAD")
text = out.read_text(encoding="utf-8")
# Check for plus icon for added file
assert "➕" in text, "Added file should have plus icon"
assert "new.txt" in text
def test_diff_staged_flag(tmp_path: pathlib.Path, monkeypatch) -> None:
"""SPEC 7.12.8: --staged flag shows only staged changes."""
# Create a git repo with a file
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "file1.txt").write_text("original\n", encoding="utf-8")
(repo_path / "file2.txt").write_text("original\n", encoding="utf-8")
repo.index.add(["file1.txt", "file2.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Stage file1 and modify file2 (unstaged)
(repo_path / "file1.txt").write_text("staged change\n", encoding="utf-8")
(repo_path / "file2.txt").write_text("unstaged change\n", encoding="utf-8")
repo.index.add(["file1.txt"])
monkeypatch.chdir(repo_path)
# Run diff with --staged flag
code = diff_report.main(["--staged"])
assert code == 0
# Check the output file
out = diff_report.default_output_path(repo_path, repo_path, "HEAD")
text = out.read_text(encoding="utf-8")
# Should include staged file1 changes
assert "+staged change" in text or "-staged change" in text
# Should NOT include unstaged file2 changes (check for the full diff line to avoid substring matches)
assert "+unstaged change" not in text and "-unstaged change" not in text
def test_diff_default_behavior(tmp_path: pathlib.Path, monkeypatch) -> None:
"""SPEC 7.12.5: Default behavior (no flag) shows all changes."""
# Create a git repo with files
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "file1.txt").write_text("original\n", encoding="utf-8")
(repo_path / "file2.txt").write_text("original\n", encoding="utf-8")
repo.index.add(["file1.txt", "file2.txt"])
repo.index.commit("initial")
repo.create_head("main")
# Stage file1 and modify file2 (unstaged)
(repo_path / "file1.txt").write_text("staged change\n", encoding="utf-8")
(repo_path / "file2.txt").write_text("unstaged change\n", encoding="utf-8")
repo.index.add(["file1.txt"])
monkeypatch.chdir(repo_path)
# Run diff without flags
code = diff_report.main([])
assert code == 0
# Check the output file
out = diff_report.default_output_path(repo_path, repo_path, "HEAD")
text = out.read_text(encoding="utf-8")
# Should include both staged and unstaged changes (check for full diff lines to avoid substring matches)
assert "+staged change" in text or "-staged change" in text
assert "+unstaged change" in text or "-unstaged change" in text
def test_diff_staged_and_unstaged_mutually_exclusive(tmp_path: pathlib.Path, monkeypatch) -> None:
"""SPEC 7.12.7/7.12.8: --staged and --unstaged cannot be used together."""
repo_path = tmp_path / "myrepo"
repo = git.Repo.init(repo_path)
_configure_test_repo(repo)
(repo_path / "file.txt").write_text("content\n", encoding="utf-8")
repo.index.add(["file.txt"])
repo.index.commit("initial")
monkeypatch.chdir(repo_path)
# Run diff with both flags - should fail
code = diff_report.main(["--staged", "--unstaged"])
assert code == 1