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 name: changelog
version: 1.2.2 version: 1.2.3
title: Changelog title: Changelog
created: 2026-10-08 created: 2026-10-08
updated: 2026-10-21 updated: 2026-10-24
type: summary 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 requirements it adds or changes. "Unbuilt" means the requirement is
specified and marked `NOT_IMPLEMENTED`. 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 ## 1.19.1 - 2026-10-21
- The sectionize-markdown skill ships as - The sectionize-markdown skill ships as
+58 -13
View File
@@ -1,9 +1,9 @@
--- ---
name: Fiona-Assistant Specification name: Fiona-Assistant Specification
version: 1.19.1 version: 1.22.1
title: Project Spec Sheet title: Project Spec Sheet
created: 2026-09-23 created: 2026-09-23
updated: 2026-10-21 updated: 2026-10-24
type: summary type: summary
--- ---
@@ -654,8 +654,10 @@ A missing directory on `fix` prints
### 4.6. git ### 4.6. git
Operates on the git repository at the current directory. Timestamps Operates on the root git repository discovered from the current
are UTC. 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 | | 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` `diff` compares `--head` (default `HEAD`) to `--base`. When `--base`
is omitted, the base is the first ref that exists among is omitted, the base is the first ref that exists among
`origin/main`, `origin/master`, `main`, and `master`. The report uses `origin/main`, `origin/master`, `main`, and `master`. The report
the wiki's opening constellation theme (same resolution as uses the wiki's opening constellation theme when run from a wiki
`wiki graph`). By default the file is repository (has `fiona-settings.json` at the git root). Otherwise,
`<wiki-root>/tmp/<repo-name>-git-diff-<short-head>.html`. That path it uses a default dark theme with a light mode toggle and a
is listed in the packaged `.gitignore` (`tmp/`). Optional flags: minimalist header. Diff rendering removes spacing between consecutive
`--title`, `--subtitle`, `-o` / `--output`, and `--collapsed`. 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>`. Commit message: `<YYYY-MM-DD HH:MM:SS> <description>`.
`save` runs `git add --all` and commits. A clean tree, including `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` are never staged by these commands except where `git add --all`
respects that ignore file. 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 - *7.12.1.* `save --description note` on a dirty tree creates one
commit whose message starts with the UTC timestamp and ends with commit whose message starts with the UTC timestamp and ends with
`note`. `note`.
@@ -4025,13 +4044,39 @@ respects that ignore file.
- *acceptance*: A following `status` prints `Status: clean`. - *acceptance*: A following `status` prints `Status: clean`.
- *7.12.5.* `diff` writes a self-contained HTML file under `tmp/` - *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 at the llm-wiki root and prints its path on stdout. The page
includes per-file unified diffs and uses the opening constellation includes per-file unified diffs. In a wiki repository it uses
theme. 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 - *acceptance*: After `diff`, the printed path exists, lies under
`<wiki-root>/tmp/`, and `git check-ignore` reports `tmp/` as `<wiki-root>/tmp/`, and `git check-ignore` reports `tmp/` as
ignored when the wiki `.gitignore` was seeded from the package. ignored when the wiki `.gitignore` was seeded from the package.
- *acceptance*: The HTML contains a `:root` block whose colors - *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 ### 7.13. Backup Script
+14
View File
@@ -153,6 +153,16 @@ def main():
action="store_true", action="store_true",
help="Start with per-file sections collapsed", 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 # fiona-assistant wiki
wiki_parser = subparsers.add_parser("wiki", help="Manage wiki directories") wiki_parser = subparsers.add_parser("wiki", help="Manage wiki directories")
@@ -420,6 +430,10 @@ def main():
diff_argv.extend(["--output", args.output]) diff_argv.extend(["--output", args.output])
if args.collapsed: if args.collapsed:
diff_argv.append("--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)) sys.exit(diff_report.main(diff_argv))
else: else:
git_parser.print_help() git_parser.print_help()
File diff suppressed because it is too large Load Diff
@@ -1,237 +1,327 @@
<!DOCTYPE html> <!DOCTYPE html>
<!-- Packaged layout for fiona.gittool.diff_report; placeholders filled at generation time. --> <!-- Packaged layout for fiona.gittool.diff_report; placeholders filled at generation time. -->
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{PAGE_TITLE}}</title> <title>{{PAGE_TITLE}}</title>
<style> <style>
{{THEME_CSS}} {{THEME_CSS}}
* { box-sizing: border-box; } * { box-sizing: border-box; }
body { body {
margin: 0; margin: 0;
font-family: var(--font); font-family: var(--font);
background: var(--bg); background: var(--bg);
color: var(--text); color: var(--text);
line-height: 1.45; line-height: 1.45;
} transition: background-color 0.3s ease, color 0.3s ease;
header { }
background: linear-gradient(135deg, var(--blue), var(--header-end)); header {
color: var(--button-text); background: var(--card);
padding: 1.5rem 1.25rem; color: var(--text);
border-bottom: 4px solid color-mix(in srgb, var(--text) 12%, transparent); padding: 1rem 1.25rem;
} border-bottom: 1px solid var(--border);
header h1 { margin: 0 0 0.35rem; font-size: 1.4rem; font-weight: 600; } display: flex;
header p { margin: 0.25rem 0; opacity: 0.92; font-size: 0.9rem; } justify-content: space-between;
header code { align-items: center;
background: color-mix(in srgb, var(--button-text) 15%, transparent); flex-wrap: wrap;
padding: 0.1rem 0.35rem; gap: 1rem;
border-radius: 4px; }
} header .header-title {
.layout { flex: 1;
display: flex; min-width: 200px;
align-items: stretch; }
min-height: calc(100vh - 8rem); 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; }
aside.sidebar { header code {
width: var(--sidebar-w); background: color-mix(in srgb, var(--button-text) 15%, transparent);
flex-shrink: 0; padding: 0.1rem 0.35rem;
position: sticky; border-radius: 4px;
top: 0; }
align-self: flex-start; .theme-toggle {
max-height: 100vh; display: flex;
overflow: auto; align-items: center;
background: var(--card); gap: 0.5rem;
border-right: 1px solid var(--border); }
padding: 0.75rem 0.5rem 1rem; .theme-toggle button {
} padding: 0.35rem 0.65rem;
aside.sidebar h2 { cursor: pointer;
margin: 0 0 0.5rem 0.65rem; border: 1px solid var(--border);
font-size: 0.75rem; border-radius: 6px;
text-transform: uppercase; background: var(--button-bg);
letter-spacing: 0.05em; color: var(--button-text);
color: var(--blue); font-size: 0.85rem;
} }
.file-tree { .theme-toggle button:hover { background: var(--button-hover); }
list-style: none; .layout {
margin: 0; display: flex;
padding: 0 0 0 0.35rem; align-items: stretch;
font-size: 0.8rem; min-height: calc(100vh - 8rem);
} }
.file-tree ul { aside.sidebar {
list-style: none; width: var(--sidebar-w);
margin: 0; flex-shrink: 0;
padding-left: 0.65rem; position: sticky;
border-left: 1px solid var(--border); top: 0;
} align-self: flex-start;
.file-tree li { margin: 0.15rem 0; } max-height: 100vh;
.file-tree .folder-label { overflow: auto;
display: block; background: var(--card);
font-weight: 600; border-right: 1px solid var(--border);
color: var(--text); padding: 0.75rem 0.5rem 1rem;
padding: 0.1rem 0.35rem; }
} aside.sidebar h2 {
.file-tree a { margin: 0 0 0.5rem 0.65rem;
display: block; font-size: 0.75rem;
padding: 0.15rem 0.35rem; text-transform: uppercase;
border-radius: 4px; letter-spacing: 0.05em;
color: var(--accent); color: var(--blue);
text-decoration: none; }
word-break: break-all; .file-tree {
} list-style: none;
.file-tree a:hover { background: var(--link-hover-bg); text-decoration: underline; } margin: 0;
.file-tree a.active { padding: 0 0 0 0.35rem;
background: var(--link-active-bg); font-size: 0.8rem;
font-weight: 600; }
color: var(--blue); .file-tree ul {
} list-style: none;
.file-tree .churn { margin: 0;
font-size: 0.7rem; padding-left: 0.65rem;
color: var(--muted); border-left: 1px solid var(--border);
margin-left: 0.25rem; }
white-space: nowrap; .file-tree li { margin: 0.15rem 0; }
} .file-tree .folder-label {
.churn .add { color: var(--churn-add); } display: block;
.churn .del { color: var(--churn-del); } font-weight: 600;
.stat-fold { color: var(--text);
margin: 0.75rem 0.5rem 0; padding: 0.1rem 0.35rem;
font-size: 0.75rem; }
} .file-tree a {
.stat-fold summary { AI/LLM: pointer; color: var(--muted); } display: block;
.stat-fold pre { padding: 0.15rem 0.35rem;
margin: 0.35rem 0 0; border-radius: 4px;
font-size: 0.68rem; color: var(--accent);
white-space: pre-wrap; text-decoration: none;
max-height: 12rem; word-break: break-all;
overflow: auto; }
background: var(--summary-bg); .file-tree a:hover { background: var(--link-hover-bg); text-decoration: underline; }
padding: 0.5rem; .file-tree a.active {
border-radius: 4px; background: var(--link-active-bg);
border: 1px solid var(--border); font-weight: 600;
} color: var(--blue);
.content { }
flex: 1; .file-tree .churn {
min-width: 0; font-size: 0.7rem;
padding: 1rem 1.25rem 2.5rem; color: var(--muted);
} margin-left: 0.25rem;
.toolbar { white-space: nowrap;
font-size: 0.85rem; }
display: flex; .churn .add { color: var(--churn-add); }
align-items: center; .churn .del { color: var(--churn-del); }
gap: 0.5rem; .file-icon {
flex-wrap: wrap; font-size: 0.8rem;
background: var(--card); margin-right: 0.35rem;
border: 1px solid var(--border); opacity: 0.7;
border-radius: 8px; }
padding: 0.65rem 0.85rem; .stat-fold {
margin-bottom: 1rem; margin: 0.75rem 0.5rem 0;
} font-size: 0.75rem;
button { }
padding: 0.35rem 0.65rem; .stat-fold summary { cursor: pointer; color: var(--muted); }
AI/LLM: pointer; .stat-fold pre {
border: 1px solid var(--border); margin: 0.35rem 0 0;
border-radius: 6px; font-size: 0.68rem;
background: var(--button-bg); white-space: pre-wrap;
color: var(--button-text); max-height: 12rem;
} overflow: auto;
button:hover { background: var(--button-hover); } background: var(--summary-bg);
details.file { padding: 0.5rem;
margin: 0.75rem 0; border-radius: 4px;
border: 1px solid var(--border); border: 1px solid var(--border);
border-radius: 6px; }
background: var(--card); .content {
scroll-margin-top: 0.75rem; flex: 1;
} min-width: 0;
details.file:target { padding: 1rem 1.25rem 2.5rem;
outline: 2px solid var(--accent); }
outline-offset: 2px; .toolbar {
} font-size: 0.85rem;
details.file summary { display: flex;
AI/LLM: pointer; align-items: center;
padding: 0.6rem 0.75rem; gap: 0.5rem;
font-weight: 600; flex-wrap: wrap;
background: var(--summary-bg); background: var(--card);
} border: 1px solid var(--border);
pre.diff { border-radius: 8px;
margin: 0; padding: 0.65rem 0.85rem;
padding: 0.75rem; margin-bottom: 1rem;
font-size: 0.72rem; }
line-height: 1.35; button {
overflow: auto; padding: 0.35rem 0.65rem;
max-height: 70vh; cursor: pointer;
} border: 1px solid var(--border);
.diff-add { background: var(--diff-add-bg); display: block; } border-radius: 6px;
.diff-del { background: var(--diff-del-bg); display: block; } background: var(--button-bg);
.diff-hunk { color: var(--diff-hunk); display: block; } color: var(--button-text);
.diff-meta { color: var(--diff-meta); display: block; } }
.diff-ctx { display: block; } button:hover { background: var(--button-hover); }
@media (max-width: 900px) { details.file {
.layout { flex-direction: column; } margin: 0.75rem 0;
aside.sidebar { border: 1px solid var(--border);
width: 100%; border-radius: 6px;
position: relative; background: var(--card);
max-height: 40vh; scroll-margin-top: 0.75rem;
border-right: none; }
border-bottom: 1px solid var(--border); details.file:target {
} outline: 2px solid var(--accent);
} outline-offset: 2px;
</style> }
</head> details.file summary {
<body> cursor: pointer;
<header> padding: 0.6rem 0.75rem;
{{HEADER_BODY}} font-weight: 600;
</header> background: var(--summary-bg);
<div class="layout"> }
<aside class="sidebar" aria-label="Changed files"> pre.diff {
<h2>Files ({{FILE_COUNT}})</h2> margin: 0;
{{TREE_HTML}} padding: 0.75rem;
<details class="stat-fold"> font-size: 0.72rem;
<summary>git diff --stat</summary> line-height: 1.0;
<pre>{{STAT_BLOCK}}</pre> overflow: auto;
</details> max-height: 70vh;
</aside> }
<div class="content"> .diff-add { background: var(--diff-add-bg); display: block; margin: 0; padding: 0; }
<div class="toolbar"> .diff-del { background: var(--diff-del-bg); display: block; margin: 0; padding: 0; }
<button type="button" id="btn-expand-all">Expand all</button> .diff-hunk { color: var(--diff-hunk); display: block; margin: 0; padding: 0; }
<button type="button" id="btn-collapse-all">Collapse all</button> .diff-meta { color: var(--diff-meta); display: block; margin: 0; padding: 0; }
</div> .diff-ctx { display: block; margin: 0; padding: 0; }
{{FILES_HTML}} @media (max-width: 900px) {
</div> .layout { flex-direction: column; }
</div> aside.sidebar {
<script> width: 100%;
(function () { position: relative;
function openFromHash() { max-height: 40vh;
var id = location.hash ? location.hash.slice(1) : ""; border-right: none;
document.querySelectorAll(".file-tree a").forEach(function (a) { border-bottom: 1px solid var(--border);
a.classList.toggle("active", a.getAttribute("href") === "#" + id); }
}); }
if (!id) { /* Dark mode theme - applied when data-theme="dark" (default) */
return; [data-theme="dark"] {
} --bg: #1a1a1a;
var el = document.getElementById(id); --card: #2d2d2d;
if (el && el.tagName === "DETAILS") { --border: #404040;
el.open = true; --text: #e0e0e0;
el.scrollIntoView({ behavior: "smooth", block: "start" }); --blue: #6ba1f5;
} --accent: #7aa7d6;
} --header-end: #c586c0;
document.getElementById("btn-expand-all").addEventListener("click", function () { --muted: #9e9e9e;
document.querySelectorAll("details.file").forEach(function (d) { d.open = true; }); --summary-bg: #252525;
}); --button-bg: #3d3d3d;
document.getElementById("btn-collapse-all").addEventListener("click", function () { --button-text: #e0e0e0;
document.querySelectorAll("details.file").forEach(function (d) { d.open = false; }); --button-hover: #4a4a4a;
}); --churn-add: #7edd8a;
document.querySelectorAll(".file-tree a").forEach(function (a) { --churn-del: #ff7b7b;
a.addEventListener("click", function () { --diff-add-bg: color-mix(in srgb, #7edd8a 22%, var(--card));
var id = a.getAttribute("href").slice(1); --diff-del-bg: color-mix(in srgb, #ff7b7b 22%, var(--card));
var el = document.getElementById(id); --link-hover-bg: color-mix(in srgb, #7aa7d6 18%, var(--card));
if (el && el.tagName === "DETAILS") { --link-active-bg: color-mix(in srgb, #7aa7d6 22%, var(--card));
el.open = true; }
} /* Light mode theme - applied when data-theme="light" */
}); [data-theme="light"] {
}); --bg: #ffffff;
window.addEventListener("hashchange", openFromHash); --card: #f8f9fa;
openFromHash(); --border: #e2e8f0;
})(); --text: #1a1a1a;
</script> --blue: #0d6efd;
</body> --accent: #0d6efd;
</html> --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.""" """Tests for fiona.gittool.diff_report."""
from __future__ import annotations from __future__ import annotations
import json import json
import pathlib import pathlib
import subprocess import subprocess
import git import git
import pytest import pytest
from fiona.gittool import diff_report from fiona.gittool import diff_report
from fiona.wiki.ignore import wiki_gitignore_patterns from fiona.wiki.ignore import wiki_gitignore_patterns
def _configure_test_repo(repo: git.Repo) -> None: def _configure_test_repo(repo: git.Repo) -> None:
"""Set local git identity for commits in tests. """Set local git identity for commits in tests.
Generated by CURSOR: 2026-10-19 - isolated git user for pytest. Generated by CURSOR: 2026-10-19 - isolated git user for pytest.
""" """
with repo.config_writer() as config: with repo.config_writer() as config:
config.set_value("user", "email", "fiona-test@example.com") config.set_value("user", "email", "fiona-test@example.com")
config.set_value("user", "name", "Fiona Test") config.set_value("user", "name", "Fiona Test")
@pytest.fixture @pytest.fixture
def wiki_git_repo(tmp_path: pathlib.Path) -> pathlib.Path: def wiki_git_repo(tmp_path: pathlib.Path) -> pathlib.Path:
"""Git repo with fiona-settings.json and main + HEAD commits.""" """Git repo with fiona-settings.json and main + HEAD commits."""
repo = git.Repo.init(tmp_path) repo = git.Repo.init(tmp_path)
_configure_test_repo(repo) _configure_test_repo(repo)
settings = { settings = {
"fiona": { "fiona": {
"wiki": { "wiki": {
"graph": { "graph": {
"theme": "night-sky", "theme": "night-sky",
} }
} }
} }
} }
(tmp_path / "fiona-settings.json").write_text( (tmp_path / "fiona-settings.json").write_text(
json.dumps(settings), json.dumps(settings),
encoding="utf-8", encoding="utf-8",
) )
(tmp_path / "README.md").write_text("base\n", encoding="utf-8") (tmp_path / "README.md").write_text("base\n", encoding="utf-8")
repo.index.add(["fiona-settings.json", "README.md"]) repo.index.add(["fiona-settings.json", "README.md"])
repo.index.commit("base on main") repo.index.commit("base on main")
# Keep ``main`` at the first commit so HEAD can advance for a non-empty diff. # Keep ``main`` at the first commit so HEAD can advance for a non-empty diff.
repo.create_head("main") repo.create_head("main")
(tmp_path / "README.md").write_text("base\nchanged\n", encoding="utf-8") (tmp_path / "README.md").write_text("base\nchanged\n", encoding="utf-8")
repo.index.add(["README.md"]) repo.index.add(["README.md"])
repo.index.commit("feature commit") repo.index.commit("feature commit")
return tmp_path return tmp_path
def test_wiki_gitignore_includes_tmp() -> None: def test_wiki_gitignore_includes_tmp() -> None:
"""SPEC 7.12.5: packaged ignore lists wiki tmp/.""" """SPEC 7.12.5: packaged ignore lists wiki tmp/."""
patterns = wiki_gitignore_patterns() patterns = wiki_gitignore_patterns()
assert "tmp/" in patterns assert "tmp/" in patterns
def test_resolve_default_base_uses_main(wiki_git_repo: pathlib.Path) -> None: def test_resolve_default_base_uses_main(wiki_git_repo: pathlib.Path) -> None:
"""Default base is main when it exists.""" """Default base is main when it exists."""
assert diff_report.resolve_default_base(wiki_git_repo) == "main" assert diff_report.resolve_default_base(wiki_git_repo) == "main"
def test_theme_css_uses_constellation(wiki_git_repo: pathlib.Path) -> None: def test_theme_css_uses_constellation(wiki_git_repo: pathlib.Path) -> None:
"""HTML theme CSS reflects night-sky background.""" """HTML theme CSS reflects night-sky background."""
css = diff_report.theme_css_for_wiki(wiki_git_repo) css = diff_report.theme_css_for_wiki(wiki_git_repo)
assert "--bg: #070b14" in css assert "--bg: #070b14" in css
def test_write_report_under_tmp(wiki_git_repo: pathlib.Path) -> None: def test_write_report_under_tmp(wiki_git_repo: pathlib.Path) -> None:
"""Default output path is wiki tmp/ and HTML includes diff content.""" """Default output path is wiki tmp/ and HTML includes diff content."""
out = diff_report.default_output_path(wiki_git_repo, wiki_git_repo, "HEAD") out = diff_report.default_output_path(wiki_git_repo, wiki_git_repo, "HEAD")
assert out.parent == wiki_git_repo / "tmp" assert out.parent == wiki_git_repo / "tmp"
path = diff_report.write_report( path = diff_report.write_report(
wiki_git_repo, wiki_git_repo,
out, out,
base="main", base="main",
head="HEAD", head="HEAD",
title=None, title=None,
subtitle=None, subtitle=None,
open_details=True, open_details=True,
) )
text = path.read_text(encoding="utf-8") text = path.read_text(encoding="utf-8")
assert "changed" in text assert "changed" in text
assert "night-sky" not in text # theme name is not embedded; colors are assert "night-sky" not in text # theme name is not embedded; colors are
assert "--bg: #070b14" in text assert "--bg: #070b14" in text
def test_main_prints_path(wiki_git_repo: pathlib.Path, monkeypatch) -> None: def test_main_prints_path(wiki_git_repo: pathlib.Path, monkeypatch) -> None:
"""CLI exits 0 and prints the report path.""" """CLI exits 0 and prints the report path."""
monkeypatch.chdir(wiki_git_repo) monkeypatch.chdir(wiki_git_repo)
code = diff_report.main(["--base", "main"]) code = diff_report.main(["--base", "main"])
assert code == 0 assert code == 0
def test_git_check_ignore_tmp(wiki_git_repo: pathlib.Path) -> None: def test_git_check_ignore_tmp(wiki_git_repo: pathlib.Path) -> None:
"""tmp/ is ignored after ensure_wiki_gitignore.""" """tmp/ is ignored after ensure_wiki_gitignore."""
from fiona.wiki.ignore import ensure_wiki_gitignore from fiona.wiki.ignore import ensure_wiki_gitignore
ensure_wiki_gitignore(wiki_git_repo) ensure_wiki_gitignore(wiki_git_repo)
(wiki_git_repo / "tmp").mkdir() (wiki_git_repo / "tmp").mkdir()
report = wiki_git_repo / "tmp" / "sample.html" report = wiki_git_repo / "tmp" / "sample.html"
report.write_text("<html></html>", encoding="utf-8") report.write_text("<html></html>", encoding="utf-8")
result = subprocess.run( result = subprocess.run(
["git", "check-ignore", "-q", "tmp/sample.html"], ["git", "check-ignore", "-q", "tmp/sample.html"],
cwd=wiki_git_repo, cwd=wiki_git_repo,
check=False, check=False,
) )
assert result.returncode == 0 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