From b13195550fdef45d3e74f3bcc801bd268d7d0059 Mon Sep 17 00:00:00 2001 From: yktsnet Date: Wed, 11 Nov 2026 19:39:26 +0900 Subject: [PATCH 1/2] Add tests for guarantee ledger gaps --- docs/guarantees/README.md | 8 ----- docs/guarantees/build.md | 1 + docs/guarantees/incremental.md | 5 ++++ docs/guarantees/plugins.md | 1 + docs/guarantees/publish.md | 2 +- tests/test_build.py | 53 +++++++++++++++++++++++++++++++++- tests/test_plugins.py | 5 ++++ tests/test_publish.py | 29 +++++++++++++++++++ 8 files changed, 94 insertions(+), 10 deletions(-) diff --git a/docs/guarantees/README.md b/docs/guarantees/README.md index 7297c5d..bff06da 100644 --- a/docs/guarantees/README.md +++ b/docs/guarantees/README.md @@ -23,11 +23,3 @@ codeview が外へ約束している振る舞いと、それを守るテスト | [plugins](plugins.md) | | [publish](publish.md) | | [sessions](sessions.md) | - -## Gaps - -- 生成物が 20,000 ファイルを超えたとき、`publish` が push せずに非0で終わること。見本に 2 万件のファイルを作るとテストが重くなりすぎるため見送った -- 直下にファイルが無いディレクトリのページに案内文を出すこと。`test_readme_on_directory_page` は、ファイルのあるディレクトリに案内文が出ないことしか確かめていない -- `build --incremental` が、リポの置き場所・アカウント・本体のコード・`[scan.repos]` 以外の設定・Issue の一覧が変わったときにも作り直すこと。テストは HEAD・GitHub の URL で指す他のリポ・`[scan.repos]`・拡張の Issue の `targets` の変化しか確かめていない -- `check_every_hours` の確認で、起動のずれを見込む分が5分であること。`test_publish_checks_account_at_its_interval` は、間隔より1分短い時に見ることと、直後には見ないことしか確かめていない -- 拡張が返した Issue の `waits` の表示が、待っている Issue のページへのリンクであること。`test_issue_source_next_to_config` は `waits on <リポ> #<番号>` の文字が出ることしか確かめていない diff --git a/docs/guarantees/build.md b/docs/guarantees/build.md index c5bbad1..309b87c 100644 --- a/docs/guarantees/build.md +++ b/docs/guarantees/build.md @@ -33,6 +33,7 @@ | 保証 | 対応テスト | |---|---| | README のあるディレクトリのページには、一覧の下に README を描く | `test_readme_on_directory_page` | +| 直下にファイルが無いディレクトリのページには、案内文を出す | `test_guide_on_directory_page_without_files` | | README の無いディレクトリのページには、一覧の先頭のファイルを README と同じ位置に描く | `test_readme_on_directory_page` | | 左の一覧で、中身がディレクトリ1つだけのディレクトリは、その子のディレクトリと連ねて `a/b/c` の1行にまとめる | `test_dir_only_chains_collapse_into_one_row` | | 左の一覧のディレクトリの連なりは、中身がディレクトリ1つだけでなくなるところで止まる | `test_dir_only_chains_collapse_into_one_row` | diff --git a/docs/guarantees/incremental.md b/docs/guarantees/incremental.md index 5634c15..ba54e69 100644 --- a/docs/guarantees/incremental.md +++ b/docs/guarantees/incremental.md @@ -8,6 +8,11 @@ | `build --incremental` は、Markdown が GitHub の URL で指す他のリポが変わったとき、指している側のリポも作り直す | `test_incremental_build_matches_full_build` | | `build --incremental` は、リポ単位の設定(`[scan.repos]`)が変わったリポを作り直す | `test_repo_scan_change_rebuilds_incrementally` | | `build --incremental` は、拡張が返した Issue の `targets` が変われば、リポの HEAD が同じでも、そのリポのページを作り直す | `test_incremental_build_follows_issue_targets` | +| `build --incremental` は、リポの置き場所が変わったリポを作り直す | `test_incremental_build_follows_repo_location` | +| `build --incremental` は、リポの属するアカウントが変わったリポを作り直す | `test_incremental_build_follows_account` | +| `build --incremental` は、本体のコードが変わったとき、すべてのリポを作り直す | `test_incremental_build_follows_code` | +| `build --incremental` は、`[scan.repos]` 以外の設定が変わったとき、すべてのリポを作り直す | `test_incremental_build_follows_other_config` | +| `build --incremental` は、Issue の一覧が変わったとき、何も書かずには終わらない | `test_incremental_build_follows_issue_list` | ## `build --incremental` の出力 diff --git a/docs/guarantees/plugins.md b/docs/guarantees/plugins.md index 5a63376..d7a8fa0 100644 --- a/docs/guarantees/plugins.md +++ b/docs/guarantees/plugins.md @@ -5,6 +5,7 @@ | 設定ファイルの隣に置いた拡張モジュールをアカウントの `issues` に挙げると、その `issues(ctx, account, repos)` が返す Issue を一覧とページに出す | `test_issue_source_next_to_config` | | 拡張は `[plugins.<名前>]` の表を `ctx.options` で読める | `test_issue_source_next_to_config` | | 拡張が返した Issue の `waits` のうち一覧にある Issue への依存は、Issue のページに `waits on <リポ> #<番号>` として出る | `test_issue_source_next_to_config` | +| 拡張が返した Issue の `waits` の表示は、待っている Issue のページへのリンクである | `test_issue_source_next_to_config` | | 拡張が返した Issue の `waits` のうち一覧に無い Issue への依存は、出さない | `test_issue_source_next_to_config` | | 拡張が `trusted` を立てなければ、Issue の本文の HTML はエスケープする | `test_issue_source_next_to_config` | | 拡張が返した Issue の `targets` に挙げたファイルのページには、その Issue へのリンクを出す | `test_issue_source_next_to_config` | diff --git a/docs/guarantees/publish.md b/docs/guarantees/publish.md index e5dc995..7bc2003 100644 --- a/docs/guarantees/publish.md +++ b/docs/guarantees/publish.md @@ -26,6 +26,6 @@ | `publish --if-changed` は、前回の配信から変更が無ければ push せずに終わる | `test_publish_if_changed_skips_without_changes` | | `publish --if-changed` は Issue だけの更新では push しない | `test_publish_if_changed_skips_issue_only_change` | | `check_every_hours` を持つアカウントのリポの変化は、前回そのアカウントを見てから間隔が経つまで見ない | `test_publish_checks_account_at_its_interval` | -| `check_every_hours` を持つアカウントは、定期実行の起動のずれを見込み、間隔より5分短い時間が経っていれば見て、変化があれば配信する | `test_publish_checks_account_at_its_interval` | +| `check_every_hours` を持つアカウントは、定期実行の起動のずれを見込み、間隔より5分短い時間が経っていれば見て、変化があれば配信する | `test_publish_checks_account_at_its_interval`, `test_publish_check_allows_five_minutes_of_startup_drift` | | 間隔の無いアカウントの変化は、次の実行で配信する | `test_publish_checks_account_at_its_interval` | | 旧形式の状態ファイルは無いものとして扱い、配信する | `test_publish_if_changed_republishes_over_old_state` | diff --git a/tests/test_build.py b/tests/test_build.py index 6b3e5f2..9b31c0f 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -13,7 +13,7 @@ from pathlib import Path from urllib.parse import unquote -from conftest import commit, git +from conftest import commit, gh_row, git def test_scans_children_and_skips(site): @@ -144,6 +144,13 @@ def test_readme_on_directory_page(site): assert "Select a file" not in docs +def test_guide_on_directory_page_without_files(site): + commit(site.home / "own" / "alpha", {"pkg/sub/x.py": "x = 1\n"}) + public, _ = site.build() + page = (public / "alpha" / "pkg" / "index.html").read_text() + assert "Select a file" in page + + def test_no_plugins_means_plain_top(site): public, _ = site.build() out = public.parent @@ -818,3 +825,47 @@ def test_incremental_build_follows_plugin_fingerprint(site): public, err = _build_incremental(site) assert "build skipped" not in err and "beta: unchanged" in err assert (public / "fp.html").read_text() == "2" + + +def test_incremental_build_follows_repo_location(site, tmp_path): + site.write_config(site.config.read_text().replace(f'children = "{site.home}/own"', 'children = "~/own"')) + _build_incremental(site) + moved = tmp_path / "moved" + moved.mkdir() + shutil.copytree(site.home / "own", moved / "own", symlinks=True) + site.env["HOME"] = str(moved) + _, err = _build_incremental(site) + assert "alpha: unchanged" not in err and "beta: unchanged" in err + + +def test_incremental_build_follows_account(site): + _build_incremental(site) + git(site.home / "own" / "alpha", "remote", "set-url", "origin", "github-work:org/alpha.git") + _, err = _build_incremental(site) + assert "alpha: unchanged" not in err and "beta: unchanged" in err + + +def test_incremental_build_follows_code(site, tmp_path): + root = tmp_path / "code" + shutil.copytree(Path(site.env["PYTHONPATH"]) / "codeview", root / "codeview", + ignore=shutil.ignore_patterns("__pycache__")) + site.env["PYTHONPATH"] = str(root) + _build_incremental(site) + with open(root / "codeview" / "layout.py", "a") as f: + f.write("\n# changed\n") + _, err = _build_incremental(site) + assert "build skipped" not in err + + +def test_incremental_build_follows_other_config(site): + _build_incremental(site) + site.write_config(site.config.read_text().replace('skip_exts = [".png"]', 'skip_exts = [".png", ".txt"]')) + _, err = _build_incremental(site) + assert "alpha: unchanged" not in err and "beta: unchanged" not in err + + +def test_incremental_build_follows_issue_list(site): + _build_incremental(site) + site.set_gh("beta", [gh_row(8, "beta の新しい問い", "2026-04-01T00:00:00Z")]) + _, err = _build_incremental(site) + assert "build skipped" not in err diff --git a/tests/test_plugins.py b/tests/test_plugins.py index b471952..8150f80 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -2,6 +2,7 @@ from __future__ import annotations +import re import textwrap from pathlib import Path @@ -43,6 +44,10 @@ def test_issue_source_next_to_config(site): assert "ext first ok" in listing and "ext second" in listing second = (public / "issues" / "me" / "alpha" / "2.html").read_text() assert "waits on alpha #1" in second + m = re.search(r'waits on alpha #1', second) + assert m and (public / "issues" / "me" / "alpha" / m.group(1)).resolve() == ( + public / "issues" / "me" / "alpha" / "1.html" + ).resolve() # 一覧に無い先への依存は落とす assert "#99" not in second # 取り込み元が trusted を立てなければ、本文の HTML はエスケープされる diff --git a/tests/test_publish.py b/tests/test_publish.py index 6afba7f..9d34fbc 100644 --- a/tests/test_publish.py +++ b/tests/test_publish.py @@ -112,6 +112,35 @@ def test_publish_checks_account_at_its_interval(site, tmp_path): assert git(remote, "rev-parse", "deploy") != second +def test_publish_check_allows_five_minutes_of_startup_drift(site, tmp_path): + site.write_config( + site.config.read_text().replace( + 'gh_config_dir = "', 'check_every_hours = 2\ngh_config_dir = "', 1 + ) + ) + remote = _with_remote(site, tmp_path) + site.run("-m", "codeview", "publish", "--if-changed") + first = git(remote, "rev-parse", "deploy") + commit(site.home / "work" / "beta", {"new.py": "n = 1\n"}) + path = _state(site, tmp_path) + + # 間隔より5分を超えて短ければ、まだ見ない + state = json.loads(path.read_text()) + state["accounts"]["work"]["checked"] = int(time.time()) - 2 * 3600 + 5 * 60 + 30 + path.write_text(json.dumps(state)) + proc = site.run("-m", "codeview", "publish", "--if-changed") + assert "skipped" in proc.stdout + assert git(remote, "rev-parse", "deploy") == first + + # 間隔より5分以内の短さなら見る + state = json.loads(path.read_text()) + state["accounts"]["work"]["checked"] = int(time.time()) - 2 * 3600 + 5 * 60 - 30 + path.write_text(json.dumps(state)) + proc = site.run("-m", "codeview", "publish", "--if-changed") + assert "pushed" in proc.stdout + assert git(remote, "rev-parse", "deploy") != first + + def test_publish_if_changed_republishes_over_old_state(site, tmp_path): # ハッシュだけを書いていた旧形式の状態は、無いものとして配信する remote = _with_remote(site, tmp_path) From 0c045ec6eeb2c6666333f8b1f740ea2115b8637b Mon Sep 17 00:00:00 2001 From: yktsnet Date: Wed, 11 Nov 2026 19:42:34 +0900 Subject: [PATCH 2/2] test: drop the weakened issue-list guarantee and file it as an issue --- docs/guarantees/incremental.md | 1 - tests/test_build.py | 6 ------ 2 files changed, 7 deletions(-) diff --git a/docs/guarantees/incremental.md b/docs/guarantees/incremental.md index ba54e69..f09a458 100644 --- a/docs/guarantees/incremental.md +++ b/docs/guarantees/incremental.md @@ -12,7 +12,6 @@ | `build --incremental` は、リポの属するアカウントが変わったリポを作り直す | `test_incremental_build_follows_account` | | `build --incremental` は、本体のコードが変わったとき、すべてのリポを作り直す | `test_incremental_build_follows_code` | | `build --incremental` は、`[scan.repos]` 以外の設定が変わったとき、すべてのリポを作り直す | `test_incremental_build_follows_other_config` | -| `build --incremental` は、Issue の一覧が変わったとき、何も書かずには終わらない | `test_incremental_build_follows_issue_list` | ## `build --incremental` の出力 diff --git a/tests/test_build.py b/tests/test_build.py index 9b31c0f..22b82b4 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -863,9 +863,3 @@ def test_incremental_build_follows_other_config(site): _, err = _build_incremental(site) assert "alpha: unchanged" not in err and "beta: unchanged" not in err - -def test_incremental_build_follows_issue_list(site): - _build_incremental(site) - site.set_gh("beta", [gh_row(8, "beta の新しい問い", "2026-04-01T00:00:00Z")]) - _, err = _build_incremental(site) - assert "build skipped" not in err