Skip to content

Agent skill that turns natural language, code, Terraform/K8s, SQL, OpenAPI, AsyncAPI, Protobuf and GraphQL sources into editable, tested draw.io architecture diagrams: incremental sync, multi-view projection, drift diff, CI architecture tests, whiteboard derasterize, interactive HTML/PPTX/Mermaid exports.

feat: architecture time-lapse from git history (v1.22.0) (#70)

Agents365.ai9973d2ea71e0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a948bcc..128206f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,23 @@ All notable changes to **drawio-skill** are documented here. The format is based
on [Keep a Changelog](https://keepachangelog.com/), and the project follows
semantic-ish versioning (the `version:` field in `skills/drawio-skill/SKILL.md`).
+## [1.22.0] — 2026-07-03
+### Added
+- **Architecture time-lapse** (`scripts/timelapse.py`) — animate how a codebase's
+ structure grew across git history. Walks a directory's commits, re-runs a
+ bundled importer at each sampled commit (tree pulled with `git archive`; the
+ working copy is never touched), lays out + exports a PNG per commit, and
+ assembles **one self-contained HTML player** (frames embedded as base64,
+ play / step / scrub controls, no external files or CDNs).
+ - `timelapse.py <dir> --importer pyimports` → `architecture-evolution.html`.
+ - Works with any bundled extractor (`pyimports`/`jsimports`/`goimports`/
+ `rustimports`/`pyclasses`/`tfimports`/`k8simports`/`composeimports`/`sqlerd`);
+ `--importer-args` passes extra flags. Commits are sampled evenly to
+ `--max-frames` (first + last always kept); commits where the path did not
+ exist yet are skipped.
+ - Documented in `references/autolayout.md`; SKILL.md router + READMEs updated.
+ Suite now 54.
+
## [1.21.0] — 2026-07-03
### Added
- **Diagram diff** (`scripts/drawiodiff.py`) — compare two `.drawio` files into a
diff --git a/README.md b/README.md
index 96e520f..c10bdee 100644
--- a/README.md
+++ b/README.md
@@ -173,6 +173,9 @@ python3 scripts/c4.py c4.json -o c4.drawio # C4 model, multi-pa
# Diff two diagrams / snapshots → colour-coded "what changed"
python3 scripts/drawiodiff.py old.drawio new.drawio -o graph.json # +added -removed ~changed
+# Architecture time-lapse → self-contained HTML player of how a codebase grew
+python3 scripts/timelapse.py src --importer pyimports # → architecture-evolution.html
+
# any extractor → auto-layout → editable .drawio
python3 scripts/autolayout.py graph.json -o diagram.drawio
```
@@ -181,6 +184,7 @@ python3 scripts/autolayout.py graph.json -o diagram.drawio
|---|---|
| **11 extractors** | import graphs for **Python · JS/TS · Go · Rust**, **Python class inheritance**, **Terraform / Kubernetes / docker-compose** resource graphs (official cloud icons), **SQL DDL → ERD**, and **live** infra from `terraform show -json` / `docker inspect` / `kubectl get -o json` (draw what's actually deployed) |
| **Diagram diff** | `drawiodiff.py` compares two `.drawio` (or two live snapshots) into one colour-coded graph — added=green, removed=red, changed=orange — so you can see architecture / infra **drift** at a glance |
+| **Architecture time-lapse** | `timelapse.py` re-runs an importer across a repo's git history and assembles a self-contained HTML player — watch modules & edges appear over time (▶ play / ‹ › step) |
| **Sequence engine** | `seqlayout.py` computes lifeline / activation-bar / arrow geometry from a message list — no Graphviz, no hand placement |
| **Auto-layout** | Graphviz places nodes and routes orthogonal edges *around* them — removes the manual-coordinate ceiling for large graphs. `--tune` tries both directions and keeps the more readable one |
| **Transitive reduction** | drops edges implied by a longer path, turning a dense hairball into a traceable graph (asyncio: 149 → 46 edges) |
diff --git a/README_CN.md b/README_CN.md
index fc5a770..83ba3e8 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -171,6 +171,9 @@ python3 scripts/c4.py c4.json -o c4.drawio # C4 模型,多页
# 对比两张图 / 两个快照 → 高亮「改了什么」
python3 scripts/drawiodiff.py old.drawio new.drawio -o graph.json # +新增 -删除 ~变更
+# 架构时间轴 → 从 git 历史生成「代码怎么长出来的」自包含 HTML 播放器
+python3 scripts/timelapse.py src --importer pyimports # → architecture-evolution.html
+
# 任一提取器 → 自动布局 → 可编辑的 .drawio
python3 scripts/autolayout.py graph.json -o diagram.drawio
```
@@ -179,6 +182,7 @@ python3 scripts/autolayout.py graph.json -o diagram.drawio
|---|---|
| **11 个提取器** | **Python · JS/TS · Go · Rust** 的导入关系图、**Python 类继承**、**Terraform / Kubernetes / docker-compose** 资源图(自动配官方云图标)、**SQL DDL → ER 图**,以及从 `terraform show -json` / `docker inspect` / `kubectl get -o json` 提取的**实时**基础设施(画出真正已部署的样子) |
| **图对比 (diff)** | `drawiodiff.py` 把两张 `.drawio`(或两个实时快照)对比成一张彩色图 —— 新增=绿、删除=红、变更=橙 —— 一眼看出架构 / 基础设施**漂移** |
+| **架构时间轴** | `timelapse.py` 沿 git 历史逐个提交重跑提取器,拼成一个自包含 HTML 播放器 —— 看着模块和依赖边随时间长出来(▶ 播放 / ‹ › 单步) |
| **时序图引擎** | `seqlayout.py` 从消息列表直接算出 lifeline / 激活条 / 箭头几何 —— 不需要 Graphviz,不需要手摆 |
| **自动布局** | Graphviz 自动布点,正交连线**绕开**节点 —— 大图不再需要手动摆坐标。`--tune` 双向各排一次取更可读的 |
| **传递约简** | 删掉被更长路径蕴含的边,把密集的"毛线团"变成可读图(asyncio:149 → 46 条边) |
diff --git a/skills/drawio-skill/SKILL.md b/skills/drawio-skill/SKILL.md
index e5f2b32..7877f3e 100644
--- a/skills/drawio-skill/SKILL.md
+++ b/skills/drawio-skill/SKILL.md
@@ -1,6 +1,6 @@
---
name: drawio-skill
-version: 1.21.0
+version: 1.22.0
description: Use when the user requests diagrams, flowcharts, architecture diagrams, ER diagrams, UML / sequence / class diagrams, network topology, cloud architecture from Terraform or Kubernetes manifests, ML/DL model figures (Transformer/CNN/LSTM), mind maps, or any visualization. Also use proactively when explaining systems with 3+ components, complex data flows, or relationships that benefit from visual representation. Best suited when the diagram needs custom styling, rich shape vocabulary, swimlanes, or exportable images (PNG/SVG/PDF/JPG). Generates .drawio XML and exports locally via the native draw.io desktop CLI.
license: MIT
homepage: https://github.com/Agents365-ai/drawio-skill
@@ -50,6 +50,7 @@ When the workflow references one of these, read it on demand — none of them ne
| `scripts/tfimports.py` · `k8simports.py` · `composeimports.py` | The user wants to visualize **declared** infrastructure (**Terraform** `.tf`, **Kubernetes** manifests, or **docker-compose**) — extracts the resource/service reference graph (official AWS/Azure/GCP/K8s icons for tf/k8s; service boxes + volume cylinders for compose) for autolayout |
| `scripts/tfstate.py` · `dockerimports.py` (+ `k8simports.py`) | The user wants to draw **what is ACTUALLY running / deployed** — pipe `terraform show -json` (deployed state), `docker inspect $(docker ps -q)` (live containers), or `kubectl get all,ing,cm,secret,pvc -o json` (live cluster, via k8simports) and get the real topology with the same official icons. See `references/live-infra.md` |
| `scripts/drawiodiff.py` | The user wants to **compare / diff two diagrams or two snapshots** ("what changed", infra drift) — `drawiodiff.py old.drawio new.drawio -o diff.json` emits a colour-coded graph (added=green, removed=red, changed=orange, same=grey) for autolayout. Matches by cell id (importer/live-snapshot output) or `--by-label` (hand-drawn) |
+| `scripts/timelapse.py` | The user wants an **architecture time-lapse / to see how a codebase's structure evolved over git history** — `timelapse.py <dir> --importer pyimports` re-runs an importer at each sampled commit and assembles a self-contained HTML player (embedded frames, play/step controls). Best on a package with real import edges (point `<dir>` at the module root) |
| `scripts/sqlerd.py` | The user wants an **ER diagram from SQL DDL** — parses `CREATE TABLE` statements into per-table nodes (columns with PK/FK markers) and crow's-foot FK edges for autolayout |
| `scripts/seqlayout.py` | The user wants a **sequence diagram** — describe participants + messages as JSON and the script computes all lifeline/activation/arrow geometry deterministically (no hand-placed coordinates, no Graphviz needed) |
| `scripts/c4.py` | The user wants a **C4 model** (System Context / Container / Component) — levels JSON in, one multi-page `.drawio` out with official C4 shapes/colors and **click-to-drill-down** links between levels |
diff --git a/skills/drawio-skill/references/autolayout.md b/skills/drawio-skill/references/autolayout.md
index 5c9c771..d66bdaf 100644
--- a/skills/drawio-skill/references/autolayout.md
+++ b/skills/drawio-skill/references/autolayout.md
@@ -134,6 +134,17 @@ python3 <this-skill-dir>/scripts/autolayout.py diff.json -o diff.drawio
Nodes match by cell **id** by default — ideal for anything the importers or live-infra snapshots produce (their ids are stable semantic keys), so *snapshot → change → snapshot → diff* shows drift directly (e.g. two `tfstate.py` or `k8simports.py` snapshots). Pass `--by-label` to match on the visible label instead, for hand-drawn diagrams whose ids are random. Only leaf vertices and their edges are compared (containers/group cells and edge labels are skipped); the diff is a flat colour-coded view, so original icons are replaced by status colours (labels are kept). Multi-page files are flattened; compressed pages are skipped with a warning (this skill always writes uncompressed XML).
+## Architecture time-lapse over git history (`timelapse.py`)
+
+`timelapse.py <dir> --importer pyimports` shows how a codebase's structure grew: it walks the git history of `<dir>`, re-runs the importer at each sampled commit (pulling the tree with `git archive` — the working copy is never touched), lays each out and exports a PNG frame, then assembles **one self-contained HTML player** (frames embedded as base64, play / step / scrub controls, no external files or CDNs).
+
+```bash
+python3 <this-skill-dir>/scripts/timelapse.py src --importer pyimports --max-frames 12
+# -> architecture-evolution.html (open in any browser)
+```
+
+`--importer` is any bundled graph extractor (`pyimports`/`jsimports`/`goimports`/`rustimports`/`pyclasses`/`tfimports`/`k8simports`/`composeimports`/`sqlerd`), run with the same positional `<dir>` it expects, so **point `<dir>` at the module / project / infra root** — extra flags pass through via `--importer-args "--group"`. Commits touching the dir are sampled evenly down to `--max-frames` (always keeping the first and last); a commit where the importer finds nothing (the path did not exist yet) is skipped. It renders one draw.io frame per commit, so it needs git + Graphviz + the draw.io CLI and takes a few seconds per frame. The story is strongest on a package with real **import edges** (they accumulate over time); a flat directory still shows the node count grow.
+
The tf/k8s importers emit `ranksep`/`nodesep` in the graph JSON automatically (icon labels render *below* the shape, so rows need extra separation).
**`--tune` (autolayout flag)**: lays the graph out in both directions (TB and LR), scores each (through-vertex routes ×20 + edge crossings ×10 + total edge length as tiebreak), and keeps the better one — report on stderr. `validate.py --score` prints the same style of readability score for a finished `.drawio`, for comparing variants.
diff --git a/skills/drawio-skill/scripts/timelapse.py b/skills/drawio-skill/scripts/timelapse.py
new file mode 100644
index 0000000..a4bbc02
--- /dev/null
+++ b/skills/drawio-skill/scripts/timelapse.py
@@ -0,0 +1,251 @@
+#!/usr/bin/env python3
+"""Animate how a codebase's architecture grew, across its git history.
+
+Walks the git history of a directory, re-runs one of the bundled importers at
+each sampled commit (the tree is pulled with ``git archive`` — the working copy
+is never touched), lays each out and exports a PNG frame, then assembles a
+single self-contained HTML player (frames embedded as base64, play / step
+controls, no external files or CDNs). Open it in any browser to watch the
+modules and edges appear over time.
+
+ python3 timelapse.py skills/drawio-skill/scripts --importer pyimports
+ # -> architecture-evolution.html
+
+The importer is any of the bundled graph extractors (pyimports, jsimports,
+goimports, rustimports, pyclasses, tfimports, k8simports, composeimports,
+sqlerd); it is run against the archived directory with the same positional
+"path" argument they all take, so point the path at the project/package/infra
+root the importer expects. Extra importer flags pass through via
+``--importer-args`` (e.g. ``--importer-args "--group"``).
+
+Commits that touched the directory are sampled evenly (always keeping the first
+and last) down to ``--max-frames``; a commit where the importer finds nothing
+(the path did not exist yet) is skipped. Needs git, the importer's requirements,
+Graphviz (autolayout) and the draw.io CLI — the same tools the importers use.
+
+Usage: python3 timelapse.py <dir> [--importer NAME] [--importer-args STR]
+ [--max-frames N] [-o out.html] [--direction TB|LR] [--keep-frames]
+"""
+import argparse
+import base64
+import io
+import json
+import os
+import subprocess
+import sys
+import tarfile
+import tempfile
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+IMPORTERS = {"pyimports", "jsimports", "goimports", "rustimports", "pyclasses",
+ "tfimports", "k8simports", "composeimports", "sqlerd"}
+
+
+def git(root, *args):
+ """Run a git command in `root`; return (returncode, stdout_bytes)."""
+ p = subprocess.run(["git", "-C", root, *args], capture_output=True)
+ return p.returncode, p.stdout
+
+
+def sample_indices(total, n):
+ """Evenly-spaced indices across range(total), always incl. first and last.
+
+ For total <= n every index is kept; otherwise n indices are picked so the
+ first (0) and last (total-1) are always present and the rest are spread
+ uniformly between them.
+ """
+ if total <= 0:
+ return []
+ if total <= n or n <= 1:
+ return list(range(total))
+ return sorted({round(i * (total - 1) / (n - 1)) for i in range(n)})
+
+
+def history(root, subpath):
+ """Chronological [(hash, iso_date, subject), ...] of commits touching subpath."""
+ code, out = git(root, "log", "--format=%H%x09%aI%x09%s", "--", subpath or ".")
+ if code != 0:
+ return []
+ rows = []
+ for line in out.decode("utf-8", "replace").splitlines():
+ parts = line.split("\t", 2)
+ if len(parts) == 3:
+ rows.append(tuple(parts))
+ return list(reversed(rows)) # oldest first
+
+
+def extract_tree(root, commit, subpath, dest):
+ """Extract subpath of `commit` into dest via git archive. False if absent."""
+ code, tar_bytes = git(root, "archive", commit, subpath or ".")
+ if code != 0 or not tar_bytes:
+ return False
+ with tarfile.open(fileobj=io.BytesIO(tar_bytes)) as tf:
+ tf.extractall(dest) # git-authored tar; trusted
+ return True
+
+
+def build_frame(importer, importer_args, work_path, direction, tmp):
+ """Importer -> autolayout -> PNG for one commit. Returns (png_bytes, n, e) or None."""
+ graph_json = os.path.join(tmp, "graph.json")
+ imp = subprocess.run(
+ [sys.executable, os.path.join(HERE, importer + ".py"), work_path,
+ "-o", graph_json, *importer_args],
+ capture_output=True)
+ if imp.returncode != 0 or not os.path.exists(graph_json):
+ return None
+ graph = json.loads(open(graph_json, encoding="utf-8").read())
+ if not graph.get("nodes"):
+ return None
+ graph["direction"] = direction
+ open(graph_json, "w", encoding="utf-8").write(json.dumps(graph))
+ drawio = os.path.join(tmp, "frame.drawio")
+ lay = subprocess.run(
+ [sys.executable, os.path.join(HERE, "autolayout.py"), graph_json, "-o", drawio],
+ capture_output=True)
+ if lay.returncode != 0 or not os.path.exists(drawio):
+ return None
+ png = os.path.join(tmp, "frame.png")
+ exp = subprocess.run(["drawio", "-x", "-f", "png", "--width", "1600",
+ "-o", png, drawio], capture_output=True)
+ if exp.returncode != 0 or not os.path.exists(png):
+ return None
+ return open(png, "rb").read(), len(graph["nodes"]), len(graph["edges"])
+
+
+def build_html(frames, title):
+ """Self-contained HTML player for the frame list."""
+ data = [{"img": "data:image/png;base64," + base64.b64encode(png).decode(),
+ "hash": h[:9], "date": d[:10], "subj": s, "n": n, "e": e}
+ for png, h, d, s, n, e in frames]
+ peak = max((f["n"] for f in data), default=1) or 1
+ payload = json.dumps(data).replace("</", "<\\/")
+ return f"""<!doctype html><html lang="en"><head><meta charset="utf-8">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+<title>{title}</title><style>
+:root{{color-scheme:light dark}}
+*{{box-sizing:border-box}}
+body{{margin:0;font:14px/1.5 system-ui,-apple-system,Segoe UI,sans-serif;
+background:#f6f7f9;color:#1a1a1a}}
+@media(prefers-color-scheme:dark){{body{{background:#15171a;color:#e8e8e8}}}}
+header{{padding:16px 20px 4px}}h1{{margin:0;font-size:17px;font-weight:600}}
+main{{max-width:1100px;margin:0 auto;padding:8px 16px 28px}}
+#stage{{background:#fff;border:1px solid #0001;border-radius:10px;
+min-height:60vh;display:flex;align-items:center;justify-content:center;padding:12px}}
+@media(prefers-color-scheme:dark){{#stage{{background:#1e2226;border-color:#fff2}}}}
+#stage img{{max-width:100%;max-height:74vh;object-fit:contain}}
+.cap{{display:flex;gap:14px;flex-wrap:wrap;align-items:baseline;
+padding:12px 4px 6px;color:#556;font-size:13px}}
+@media(prefers-color-scheme:dark){{.cap{{color:#9aa}}}}
+.cap b{{color:inherit;font-weight:600}}.cap .subj{{color:#1a1a1a}}
+@media(prefers-color-scheme:dark){{.cap .subj{{color:#e8e8e8}}}}
+.bar{{height:6px;border-radius:3px;background:#0d99ff;transition:width .3s}}
+.barwrap{{height:6px;background:#0001;border-radius:3px;margin:2px 4px 12px}}
+.ctl{{display:flex;gap:10px;align-items:center;padding:4px}}
+button{{font:inherit;padding:6px 12px;border:1px solid #0002;border-radius:8px;
+background:#fff;cursor:pointer;color:inherit}}
+@media(prefers-color-scheme:dark){{button{{background:#262b31;border-color:#fff2}}}}
+button:hover{{border-color:#0d99ff}}
+input[type=range]{{flex:1;accent-color:#0d99ff}}
+</style></head><body>
+<header><h1>{title}</h1></header>
+<main>
+<div id="stage"><img id="img" alt="architecture frame"></div>
+<div class="cap">
+ <span><b id="idx"></b></span>
+ <span><b id="hash"></b> · <span id="date"></span></span>
+ <span class="subj" id="subj"></span>
+ <span id="counts"></span>
+</div>
+<div class="barwrap"><div class="bar" id="bar"></div></div>
+<div class="ctl">
+ <button id="prev">‹ Prev</button>
+ <button id="play">▶ Play</button>
+ <button id="next">Next ›</button>
+ <input type="range" id="scrub" min="0" value="0">
+</div>
+</main>
+<script>
+const F={payload},PEAK={peak};
+let i=0,timer=null;
+const $=id=>document.getElementById(id);
+$("scrub").max=F.length-1;
+function show(k){{
+ i=(k+F.length)%F.length;const f=F[i];
+ $("img").src=f.img;$("idx").textContent=`Frame ${{i+1}} / ${{F.length}}`;
+ $("hash").textContent=f.hash;$("date").textContent=f.date;$("subj").textContent=f.subj;
+ $("counts").textContent=`${{f.n}} nodes · ${{f.e}} edges`;
+ $("bar").style.width=(6+94*f.n/PEAK)+"%";$("scrub").value=i;
+}}
+function stop(){{clearInterval(timer);timer=null;$("play").textContent="▶ Play";}}
+$("prev").onclick=()=>{{stop();show(i-1);}};
+$("next").onclick=()=>{{stop();show(i+1);}};
+$("scrub").oninput=e=>{{stop();show(+e.target.value);}};
+$("play").onclick=()=>{{
+ if(timer){{stop();return;}}
+ $("play").textContent="⏸ Pause";
+ timer=setInterval(()=>{{if(i>=F.length-1){{show(0);}}else{{show(i+1);}}}},900);
+}};
+show(0);
+</script></body></html>"""
+
+
+def main():
+ ap = argparse.ArgumentParser(description="Git-history architecture time-lapse -> HTML player.")
+ ap.add_argument("path", help="directory to visualize (inside a git repo)")
+ ap.add_argument("--importer", default="pyimports",
+ help="bundled importer to run at each commit (default pyimports)")
+ ap.add_argument("--importer-args", default="",
+ help="extra args passed to the importer, e.g. \"--group\"")
+ ap.add_argument("--max-frames", type=int, default=10, help="sample down to N commits")
+ ap.add_argument("--direction", default="TB", choices=["TB", "LR"])
+ ap.add_argument("-o", "--output", default="architecture-evolution.html")
+ ap.add_argument("--keep-frames", action="store_true",
+ help="also write the PNG frames next to the HTML")
+ args = ap.parse_args()
+
+ importer = args.importer[:-3] if args.importer.endswith(".py") else args.importer
+ if importer not in IMPORTERS:
+ sys.exit(f"error: unknown importer {importer!r} (choose one of: "
+ + ", ".join(sorted(IMPORTERS)) + ")")
+ if not os.path.isdir(args.path):
+ sys.exit(f"error: {args.path} is not a directory")
+ code, top = git(args.path, "rev-parse", "--show-toplevel")
+ if code != 0:
+ sys.exit(f"error: {args.path} is not inside a git repository")
+ root = top.decode().strip()
+ subpath = os.path.relpath(os.path.abspath(args.path), root)
+ if subpath == ".":
+ subpath = ""
+
+ commits = history(root, subpath)
+ if not commits:
+ sys.exit(f"error: no commits touch {args.path}")
+ picked = [commits[i] for i in sample_indices(len(commits), args.max_frames)]
+ imp_args = args.importer_args.split()
+
+ frames = []
+ for n, (h, date, subj) in enumerate(picked, 1):
+ sys.stderr.write(f"[{n}/{len(picked)}] {h[:9]} {subj[:50]}\n")
+ with tempfile.TemporaryDirectory() as tmp:
+ if not extract_tree(root, h, subpath, tmp):
+ continue
+ work = os.path.join(tmp, subpath) if subpath else tmp
+ frame = build_frame(importer, imp_args, work, args.direction, tmp)
+ if frame is None:
+ sys.stderr.write(" (importer found nothing — skipped)\n")
+ continue
+ png, nn, ee = frame
+ frames.append((png, h, date, subj, nn, ee))
+ if args.keep_frames:
+ fp = f"{os.path.splitext(args.output)[0]}-frame{len(frames):02d}.png"
+ open(fp, "wb").write(png)
+
+ if not frames:
+ sys.exit("error: no frames produced (importer found nothing in any commit)")
+ title = f"Architecture evolution — {os.path.basename(os.path.abspath(args.path))}"
+ open(args.output, "w", encoding="utf-8").write(build_html(frames, title))
+ sys.stderr.write(f"wrote {args.output} ({len(frames)} frames)\n")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/test_scripts.py b/tests/test_scripts.py
index 685177d..9cf8a59 100644
--- a/tests/test_scripts.py
+++ b/tests/test_scripts.py
@@ -710,6 +710,30 @@ class TestImportersCli(unittest.TestCase):
status = {n["id"]: self._status(n["style"]) for n in graph["nodes"]}
self.assertEqual(status, {"API": "same", "DB": "removed", "Cache": "added"})
+ def test_timelapse_sample_indices(self):
+ tl = load("timelapse")
+ self.assertEqual(tl.sample_indices(3, 10), [0, 1, 2]) # fewer than n -> all
+ self.assertEqual(tl.sample_indices(0, 5), [])
+ picked = tl.sample_indices(20, 5)
+ self.assertEqual(picked[0], 0) # always first
+ self.assertEqual(picked[-1], 19) # always last
+ self.assertEqual(len(picked), 5)
+ self.assertEqual(picked, sorted(set(picked))) # unique + ordered
+
+ def test_timelapse_build_html_self_contained(self):
+ tl = load("timelapse")
+ frames = [(b"\x89PNG-old", "abc1234567", "2026-01-01", "init", 2, 1),
+ (b"\x89PNG-new", "def7654321", "2026-02-02", "grow", 9, 12)]
+ html = tl.build_html(frames, "Evo")
+ self.assertEqual(html.count("data:image/png;base64,"), 2)
+ self.assertNotIn("http://", html)
+ self.assertNotIn("https://", html) # no CDN/external refs
+ for ctl in ('id="play"', 'id="scrub"', 'id="bar"'):
+ self.assertIn(ctl, html)
+ # the embedded frame payload carries per-commit counts
+ self.assertIn('"n": 9', html)
+ self.assertIn('"e": 12', html)
+
SQL = ("CREATE TABLE users (id INT PRIMARY KEY, email VARCHAR(255));\n"
"CREATE TABLE orders (\n"
" id INT,\n"