Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions docs/guarantees/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <リポ> #<番号>` の文字が出ることしか確かめていない
1 change: 1 addition & 0 deletions docs/guarantees/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
4 changes: 4 additions & 0 deletions docs/guarantees/incremental.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
| `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` の出力

Expand Down
1 change: 1 addition & 0 deletions docs/guarantees/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
2 changes: 1 addition & 1 deletion docs/guarantees/publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
47 changes: 46 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -818,3 +825,41 @@ 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

5 changes: 5 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import re
import textwrap
from pathlib import Path

Expand Down Expand Up @@ -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'<a class="wait" href="([^"]+)">waits on alpha #1</a>', 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 はエスケープされる
Expand Down
29 changes: 29 additions & 0 deletions tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading