diff --git a/docs/modules/ROOT/pages/development/ci.adoc b/docs/modules/ROOT/pages/development/ci.adoc index a5e529d..bcb1652 100644 --- a/docs/modules/ROOT/pages/development/ci.adoc +++ b/docs/modules/ROOT/pages/development/ci.adoc @@ -141,19 +141,23 @@ To close a release, close its milestone and open the next one with its due date: The workflow `engine-watch.yml` reports what changed in the upstream engine (ArcadeData/arcadedb) that may need a change in the bindings, in one issue titled "Engine changes to review". It runs `scripts/engine_watch.py`, a script that needs only the standard library, git and `gh api`, and no LLM API. * It runs on Monday at 05:23 UTC. On the other days it runs at the same time and does nothing unless upstream published a release in the last 48 hours (a release of another repository cannot start a workflow). It also runs by hand: with `dry_run` it writes nothing to GitHub and puts the full text into the job summary, and only such a run accepts `since` and `until` to choose the range. -* It reports public methods, constructors, enum constants and nested types that were added, removed, changed or deprecated in the classes the bindings wrap, `GlobalConfiguration` settings, index types, and SQL statements, keywords, functions and methods. Each line names the upstream pull request or commit and the file. Other merged pull requests that touched the same files are listed in a collapsed block and never open an issue on their own. +* It reports public methods, constructors, enum constants and nested types that were added, removed, changed or deprecated in the classes the bindings wrap, `GlobalConfiguration` settings, index types, and SQL statements, keywords, functions and methods. Each line names the upstream pull request or commit and the file. +* It also lists two sets of upstream commits of the range, each commit with its pull request (or the commit alone when it has none), newest first. The first holds every commit whose subject starts with `feat`, whatever it touched, so a feature in a new class or in a module the scan does not read still has a line. The second holds every commit whose subject starts with `fix` and that changed a watched file of a class the bindings use, because a fix can change behavior and keep every signature. Only the start of the subject decides: a commit that starts with another word, such as `perf`, `refactor` or `Merge pull request`, is in neither list. +* Other merged pull requests that touched watched files, without a finding and in neither list, are in a collapsed block. * A new method has a row of its own only when it is abstract and on an interface the bindings implement, or on a class they name. All other new methods are one count. * One section lists new and removed exception classes below a class that `exceptions.py` names, or below `NeedRetryException`. * It also reports an engine class that is gone and that the native image configuration (`reachability-metadata.json` and the `.properties` files) names. * The column "Used" means only that the sources of the bindings hold the name, so check it before you rely on it. For a method, the class (or a type below it) and the method name must both match. * The list of wrapped classes is derived from the sources on every run: `JClass`, `JImplements` and `JPackage` in `src/arcadedb`, the imports and full names in `src/java` and `native/src/main/java`, their supertypes, and the engine types returned by methods under names the bindings call. * The mark, the last reviewed engine commit, is a hidden comment in the issue, so nothing is committed to the repository. Only issues written by `github-actions[bot]` are read. Before the first issue the scan starts at `4a91847a1` (2026-11-06). -* When nothing relevant changed, nothing is written. -* It does not see a change of behavior inside a method, openCypher, a wire protocol, or a class that the bindings do not reach. +* When nothing relevant changed, nothing is written. Relevant means a finding or a `feat` commit, so a new feature is never silent: one `feat` commit is enough to open the issue. `fix` commits and the other pull requests alone are not relevant, because upstream merges fixes all the time. They are not lost: the mark stays where it is, and the next report that is written holds them. While the issue is open, new `fix` commits rewrite its text without a comment. +* The comparison of signatures does not see a change of behavior inside a method, openCypher, a wire protocol, or a class that the bindings do not reach. The two lists of commits are the only trace of such a change, as far as the commit subjects tell. * It holds `contents: read` and `issues: write` only, has no pull request trigger, and reads the engine without building or running it. Upstream links go through `redirect.github.com`, so the issue leaves no "mentioned this" line on upstream pull requests. -* An issue text that is too long for GitHub is cut. The full text is in the job summary and in the run artifact `engine-watch-report`, which is kept for 30 days. +* An issue text that is too long for GitHub is cut: first the other pull requests, then the list of `fix` commits, then the rows of the tables, and the list of `feat` commits last. Each cut says how many lines it left out. The full text is in the job summary and in the run artifact `engine-watch-report`, which is kept for 30 days. -To handle the issue, decide for each line whether the bindings need a change, open an issue for each one that does, then close the issue. Closing it marks its newest engine commit as reviewed, and the next run starts there. While it stays open, a run rewrites its text with everything since the mark and adds a comment when there is something new. Do not edit the hidden comment. +To handle the issue, decide for each line of the tables and of the two lists of commits whether the bindings need a change, open an issue for each one that does, then close the issue. Closing it marks its newest engine commit as reviewed, and the next run starts there. While it stays open, a run rewrites its text with everything since the mark and adds a comment when there is a new finding or `feat` commit. Do not edit the hidden comment. + +At each upstream release, a person or a session reads the two lists of commits and the https://github.com/ArcadeData/arcadedb/releases[release notes] of that release, and opens an issue for each feature or change of behavior that the bindings should follow. The lists cover only what came after the mark, so read the ones in the issues of this workflow that were closed since the previous release too. When a list was cut, read the full text in the run that the cut line links to. After 30 days a dry run over the same range (`since` and `until`) makes it again. == Native build diff --git a/scripts/engine_watch.py b/scripts/engine_watch.py index c86f76d..ff446bb 100644 --- a/scripts/engine_watch.py +++ b/scripts/engine_watch.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 """Report what changed in the upstream engine that may need a change in the bindings. -The scan compares two commits of ArcadeData/arcadedb, the last one that was reviewed (`base`) and the newest one (`head`), and -reports only differences of what the engine offers, never of how it is written: +The scan compares two commits of ArcadeData/arcadedb, the last one that was reviewed (`base`) and the newest one (`head`). Its +findings are only differences of what the engine offers, never of how it is written: - the public methods, constructors, enum constants and nested types of the Java classes the bindings wrap. The list of classes is derived on every run from the sources of this repository: each engine class that `src/arcadedb` names in `JClass`, `JImplements` @@ -16,14 +16,24 @@ - the index types (`Schema.INDEX_TYPE`); - the SQL statements and keywords (the ANTLR grammar) and the SQL functions and methods (the two default factories). -Every finding names the upstream commit (and its pull request) that introduced it and the file. The other merged pull requests that -touched the same files are listed for context; they do not count as findings and never open an issue on their own. +Every finding names the upstream commit (and its pull request) that introduced it and the file. + +A comparison of signatures does not show every change: a new feature may arrive in a new class or in a module the scan does not +read, and a behavior may change behind the same signature. So the report also lists, from the commit subjects alone, two sets of +upstream commits of the range, each commit with its pull request: + +- every commit whose subject starts with `feat`, whatever it touched; +- every commit whose subject starts with `fix` and that changed a watched file of a class the bindings use. + +The other merged pull requests that touched watched files, without a finding and in neither list, are listed for context. The result goes into one issue, "Engine changes to review". Its state is a hidden comment at the end of the issue text, so no file in the repository changes: while the issue is open, a run rewrites it with everything since its `base` and comments when there is -something new; when a person closes it, its `head` is reviewed, and the next run starts there. Only issues written by the workflow -token (`github-actions[bot]`) are read, so nobody else can move the mark. Without such an issue the scan starts at FIRST_MARK. -When nothing relevant changed, nothing is written. +a new finding or `feat` commit; when a person closes it, its `head` is reviewed, and the next run starts there. Only issues written +by the workflow token (`github-actions[bot]`) are read, so nobody else can move the mark. Without such an issue the scan starts at +FIRST_MARK. When nothing relevant changed, nothing is written. Relevant is a finding or a `feat` commit, so that a new feature is +never silent. `fix` commits and the other pull requests alone are not: nothing is written, the mark stays, and the next report that +is written holds them. Without --publish nothing is written to GitHub (a dry run). --since and --until pick a range to look at and are for dry runs only: a run that writes always starts at the mark, so that only a closed issue can move it. No model and no API key is used: git, @@ -575,6 +585,10 @@ def pull_request(self) -> int | None: ) return int(found.group(1) or found.group(2)) if found else None + def starts_with(self, word: str) -> bool: + """Whether the subject starts with `word`, in any case: `feat: x`, `feat(sql)!: x`, `Fix x`.""" + return self.subject.lower().startswith(word) + class GitRepo: """Read-only access to a bare clone.""" @@ -1019,15 +1033,27 @@ class Scan: base_date: str head_date: str findings: list[Finding] - others: list[tuple[Commit, list[str]]] # commits on watched files without a finding + # pull requests on watched files with no finding by their commit, and in neither list of commits below + others: list[tuple[Commit, list[str]]] watched: dict[str, str] commits: list[Commit] releases: list[dict] = dataclasses.field(default_factory=list) folded: int = 0 # new methods that have no row of their own + # The two lists of commits, newest first, each commit with the watched files it changed (a `feat` commit may have none). + features: list[tuple[Commit, list[str]]] = dataclasses.field(default_factory=list) + fixes: list[tuple[Commit, list[str]]] = dataclasses.field(default_factory=list) + + @property + def relevant(self) -> bool: + """Whether there is something to write. Fixes alone are not: they stay in the range until a report is written.""" + return bool(self.findings or self.features) @property def digest(self) -> str: - joined = "\n".join(sorted(f.key for f in self.findings)) + """Of everything the text lists as to be reviewed: a different one means the issue has to be rewritten.""" + keys = [f.key for f in self.findings] + keys += [commit.sha for commit, _ in self.features + self.fixes] + joined = "\n".join(sorted(keys)) return hashlib.sha256(joined.encode()).hexdigest()[:16] @@ -1564,10 +1590,23 @@ def run(self) -> Scan: ) cited = {f.commit.sha for f in self.findings if f.commit} paths = set(watched) | set(FIXED_FILES) + newest = list(reversed(self.commits)) + features = [ + (commit, [p for p in commit.files if p in paths]) + for commit in newest + if commit.starts_with("feat") + ] + fixes = [ + (commit, touched) + for commit in newest + if commit.starts_with("fix") + and (touched := [p for p in commit.files if p in watched]) + ] + listed = {commit.sha for commit, _ in features + fixes} others = [ (commit, touched) - for commit in reversed(self.commits) - if commit.sha not in cited + for commit in newest + if commit.sha not in cited | listed and commit.pull_request and (touched := [p for p in commit.files if p in paths]) ] @@ -1581,6 +1620,8 @@ def run(self) -> Scan: watched, self.commits, folded=self.folded, + features=features, + fixes=fixes, ) @@ -1640,24 +1681,50 @@ def state_marker(scan: Scan) -> str: return f"" +def plural(count: int, noun: str) -> str: + return f"{count} {noun}{'' if count == 1 else 's'}" + + +def commit_list( + commits: list[tuple[Commit, list[str]]], limit: int | None, scan: Scan, full: str +) -> list[str]: + """One line for each commit (its pull request, its subject as data, the watched files it changed), up to `limit`.""" + shown = commits if limit is None else commits[:limit] + lines = [] + for commit, touched in shown: + link = upstream_link(commit, scan.base, scan.head, short=True) + # not in a table, so a border needs no escape + line = f"- {link} {code(commit.subject, 140).replace(chr(92) + '|', '|')}" + names = sorted({Path(p).name for p in touched}) + if names: + more = f", and {len(names) - 4} more" if len(names) > 4 else "" + line += f" ({', '.join(names[:4])}{more})" + lines.append(line) + if len(commits) > len(shown): + lines += ["", f"{len(commits) - len(shown)} more are in {full}."] + return lines + + def render( scan: Scan, run_url: str = "", rows: int | None = None, other_rows: int | None = None, + fix_rows: int | None = None, + feature_rows: int | None = None, ) -> str: base, head = scan.base[:9], scan.head[:9] - count = len(scan.findings) full = f"the [run]({run_url})" if run_url else "a dry run of the script" + counted = f"{plural(len(scan.findings), 'finding')}, {plural(len(scan.features), '`feat` commit')}, and {plural(len(scan.fixes), '`fix` commit')} in classes the bindings use" lines = [ - f"The upstream engine changed in ways that may need a change in the Python bindings: {count} finding{'' if count == 1 else 's'} between `{base}` ({scan.base_date[:10]}) and `{head}` ({scan.head_date[:10]}), {len(scan.commits)} upstream commits ([compare]({UPSTREAM_WEB}/compare/{scan.base}...{scan.head})).", + f"The upstream engine changed in ways that may need a change in the Python bindings: {counted}, between `{base}` ({scan.base_date[:10]}) and `{head}` ({scan.head_date[:10]}), {len(scan.commits)} upstream commits ([compare]({UPSTREAM_WEB}/compare/{scan.base}...{scan.head})).", "", - f"To review: decide for each line whether the bindings need a change, open an issue for each one that does, then close this issue. Closing it marks `{head}` as reviewed, and the next run starts there. While it stays open, a run rewrites this text with everything since `{base}` and adds a comment when there is something new.", + f"To review: decide for each line of the tables and of the two lists of commits whether the bindings need a change, open an issue for each one that does, then close this issue. Closing it marks `{head}` as reviewed, and the next run starts there. While it stays open, a run rewrites this text with everything since `{base}` and adds a comment when there is a new finding or `feat` commit.", "", ] for release in scan.releases: lines += [ - f"Upstream published the release {code(release['tag_name'])} on {release['published_at'][:10]}.", + f"Upstream published the release {code(release['tag_name'])} on {release['published_at'][:10]}. Read its release notes together with the two lists of commits.", "", ] lines += ["| Section | Findings | Name used in the bindings |", "|---|---|---|"] @@ -1685,33 +1752,36 @@ def render( "", f"Not listed: {scan.folded} more new method names in watched classes (neither abstract on an interface the bindings implement, nor on a class they name).", ] + for title, note, commits, limit in ( + ( + "New features upstream (`feat` commits)", + "Every commit of the range whose subject starts with `feat`, newest first, with the watched files it changed, if any.", + scan.features, + feature_rows, + ), + ( + "Fixes in classes the bindings use (`fix` commits)", + "Commits whose subject starts with `fix` and that changed a watched file of a class the bindings use, newest first. A fix can change behavior and keep every signature.", + scan.fixes, + fix_rows, + ), + ): + if commits: + lines += ["", f"## {title}", "", note, ""] + lines += commit_list(commits, limit, scan, full) if scan.others: - shown_others = ( - scan.others if other_rows is None else scan.others[: other_rows or 0] - ) lines += [ "", - f"
{len(scan.others)} other merged pull requests touched the watched files without such a change (newest first)", + f"
{len(scan.others)} other merged pull requests touched the watched files without such a change and are in neither list of commits (newest first)", "", ] - for commit, touched in shown_others: - names = ", ".join(sorted({Path(p).name for p in touched})[:4]) - more = len({Path(p).name for p in touched}) - 4 - names += f", and {more} more" if more > 0 else "" - lines.append( - f"- [PR {commit.pull_request}]({UPSTREAM_WEB}/pull/{commit.pull_request}) {code(commit.subject, 140)} ({names})" - ) - if len(scan.others) > len(shown_others): - lines += [ - "", - f"{len(scan.others) - len(shown_others)} more are in {full}.", - ] + lines += commit_list(scan.others, other_rows, scan, full) lines += ["", "
"] lines += [ "", "
How this was made", "", - f'`scripts/engine_watch.py` (workflow `engine-watch.yml`) compared the two commits. It watches {len(scan.watched)} engine files that it derived from the sources of the bindings, plus the settings, index types, SQL grammar, and SQL function factories. It reports differences of signatures and registrations, not changes of behavior inside a method. "Used" means only that the sources of the bindings hold that name, so check it before relying on it. The comment below this block is the state of the job: do not edit it.', + f'`scripts/engine_watch.py` (workflow `engine-watch.yml`) compared the two commits. It watches {len(scan.watched)} engine files that it derived from the sources of the bindings, plus the settings, index types, SQL grammar, and SQL function factories. Its findings are differences of signatures and registrations, not changes of behavior inside a method. The two lists of commits are picked by how the subject starts and are not judged further. "Used" means only that the sources of the bindings hold that name, so check it before relying on it. The comment below this block is the state of the job: do not edit it.', "", "
", "", @@ -1721,37 +1791,53 @@ def render( def fit(scan: Scan, run_url: str = "", limit: int = BODY_LIMIT) -> str: - """The text of the issue, cut down until GitHub takes it: first the other pull requests, then the rows of each section.""" - for rows, others in ( - (None, None), - (None, 100), - (None, 30), - (None, 0), - (150, 0), - (80, 0), - (50, 0), - (30, 0), - (15, 0), - (5, 0), + """The text of the issue, cut down until GitHub takes it: first the other pull requests, then the `fix` commits, then the rows + of each section, and the `feat` commits last. Each cut says how many lines it left out. + """ + for rows, others, fixes, features in ( + (None, None, None, None), + (None, 100, None, None), + (None, 30, None, None), + (None, 0, None, None), + (None, 0, 100, None), + (None, 0, 50, None), + (None, 0, 20, None), + (150, 0, 20, None), + (80, 0, 20, None), + (50, 0, 20, None), + (30, 0, 20, 60), + (15, 0, 10, 30), + (5, 0, 5, 10), ): - body = render(scan, run_url, rows, others) + body = render(scan, run_url, rows, others, fixes, features) if len(body) <= limit: return body raise WatchError(f"the issue text is longer than {limit} characters") -def new_since(scan: Scan, previous_head: str) -> list[Finding]: - """The findings whose commit came after the head the issue showed before.""" +def new_since(scan: Scan, previous_head: str) -> tuple[list[Finding], list[Commit]]: + """The findings and the `feat` commits that came after the head the issue showed before.""" + features = [commit for commit, _ in scan.features] shas = [c.sha for c in scan.commits] if previous_head not in shas: - return list(scan.findings) if previous_head == scan.base else [] + if previous_head != scan.base: + return [], [] + return list(scan.findings), features later = set(shas[shas.index(previous_head) + 1 :]) - return [f for f in scan.findings if f.commit and f.commit.sha in later] + return ( + [f for f in scan.findings if f.commit and f.commit.sha in later], + [c for c in features if c.sha in later], + ) -def comment_text(scan: Scan, fresh: list[Finding], limit: int = 25) -> str: +def comment_text( + scan: Scan, fresh: list[Finding], features: list[Commit], limit: int = 25 +) -> str: + counted = [plural(len(fresh), "new finding")] if fresh else [] + if features: + counted.append(plural(len(features), "new `feat` commit")) lines = [ - f"{len(fresh)} new finding{'' if len(fresh) == 1 else 's'}, the engine is now at `{scan.head[:9]}`. The text above holds all of them.", + f"{' and '.join(counted)}, the engine is now at `{scan.head[:9]}`. The text above holds all of them.", "", ] for finding in fresh[:limit]: @@ -1760,7 +1846,14 @@ def comment_text(scan: Scan, fresh: list[Finding], limit: int = 25) -> str: f"- {finding.change} {what} ({upstream_link(finding.commit, scan.base, scan.head)})" ) if len(fresh) > limit: - lines.append(f"- and {len(fresh) - limit} more") + lines.append(f"- and {plural(len(fresh) - limit, 'more finding')}") + for commit in features[:limit]: + subject = code(commit.subject, 200).replace("\\|", "|") + lines.append( + f"- new `feat` commit {subject} ({upstream_link(commit, scan.base, scan.head)})" + ) + if len(features) > limit: + lines.append(f"- and {plural(len(features) - limit, 'more `feat` commit')}") return "\n".join(lines) + "\n" @@ -1843,7 +1936,7 @@ def choose_mark(issues: list[dict]) -> tuple[str, dict | None, str]: def publish(api, repo: str, scan: Scan, current: dict | None, run_url: str) -> str: """Write the result. Returns what was done.""" - if not scan.findings: + if not scan.relevant: return "nothing relevant changed: nothing written" if current is None: made = api( @@ -1862,15 +1955,15 @@ def publish(api, repo: str, scan: Scan, current: dict | None, run_url: str) -> s return f"nothing new: issue {current['number']} left as it is" number = current["number"] api("PATCH", f"repos/{repo}/issues/{number}", {"body": fit(scan, run_url)}) - fresh = new_since(scan, before.get("head", scan.base)) - if not fresh: - return f"updated issue {number}, no new finding" + fresh, features = new_since(scan, before.get("head", scan.base)) + if not fresh and not features: + return f"updated issue {number}, no new finding or feat commit" api( "POST", f"repos/{repo}/issues/{number}/comments", - {"body": comment_text(scan, fresh)}, + {"body": comment_text(scan, fresh, features)}, ) - return f"updated issue {number} and commented on {len(fresh)} new findings" + return f"updated issue {number} and commented on {len(fresh)} new findings and {len(features)} new feat commits" def releases(api) -> list[dict]: @@ -1970,20 +2063,20 @@ def main(argv: list[str] | None = None) -> int: key=lambda r: r["published_at"], ) full = render(scan, run_url) - if args.report and scan.findings: + if args.report and scan.relevant: Path(args.report).write_text(full[:SUMMARY_LIMIT], encoding="utf-8") counts = ", ".join( f"{name} {sum(f.section == name for f in scan.findings)}" for name, _ in SECTIONS ) print( - f"{len(scan.commits)} commits, {len(scan.watched)} watched files, {len(scan.findings)} findings ({counts}), {len(scan.others)} other pull requests" + f"{len(scan.commits)} commits, {len(scan.watched)} watched files, {len(scan.findings)} findings ({counts}), {len(scan.features)} feat commits, {len(scan.fixes)} fix commits on watched files, {len(scan.others)} other pull requests" ) if args.publish: print(publish(gh_api, args.repo, scan, current, run_url)) else: print("dry run: nothing is written to GitHub") - if scan.findings and not args.report: + if scan.relevant and not args.report: print(fit(scan, run_url)) except WatchError as error: print(f"error: {error}", file=sys.stderr) diff --git a/tests/test_engine_watch.py b/tests/test_engine_watch.py index 723b476..e0171db 100644 --- a/tests/test_engine_watch.py +++ b/tests/test_engine_watch.py @@ -650,9 +650,9 @@ def test_the_classes_of_the_table_of_codes_are_read_from_this_repository(): assert "com.arcadedb.exception.DuplicatedKeyException" in errors -def test_a_change_inside_a_method_body_is_no_finding_but_its_pull_request_is_listed(): +def test_a_change_inside_a_method_body_is_no_finding_but_its_fix_commit_is_listed(): scan = scan_of(changed_engine()) - assert 106 in [commit.pull_request for commit, _ in scan.others] + assert 106 in numbers(scan.fixes) assert 106 not in found(scan).values() @@ -690,14 +690,18 @@ def test_a_file_the_scan_reads_that_moved_is_an_error_not_silence(): # -- the text ------------------------------------------------------------------------------------------------------------------------- +def outside_code(text: str) -> str: + """The markdown that GitHub reads: without the code spans and the link targets.""" + return re.sub(r"\]\([^)]*\)", "]", re.sub(r"`[^`\n]*`", "", text)) + + def test_the_text_never_links_into_upstream_or_names_a_person_or_a_local_issue(): scan = scan_of(changed_engine()) body = ew.render(scan, "https://example.invalid/run") assert "https://github.com/ArcadeData/arcadedb/" not in body assert "https://redirect.github.com/ArcadeData/arcadedb/pull/104" in body - outside_code = re.sub(r"\]\([^)]*\)", "]", re.sub(r"`[^`\n]*`", "", body)) - assert not re.search(r"(?", 1) + assert "/pull/1)" in features and "/pull/4)" in features + assert "(LocalDatabase.java)" in features + assert "/pull/2)" in fixes and f"/commit/{scan.fixes[0][0].sha})" in fixes + assert "/pull/5)" in others and "/pull/2)" not in others + assert "/pull/3)" not in body + assert "@" not in outside_code(body) + assert not re.search(r"(? list: + """The calls of a run at the commit `now` on an issue that was written at the commit `shown`.""" + api = FakeApi() + before = scan_of(repo, head=repo.log[shown - 1].sha) + current = {"number": 4, "body": ew.render(before)} + ew.publish(api, "o/r", scan_of(repo, head=repo.log[now - 1].sha), current, "") + return api.calls + + patch, comment = update(3, 4) + assert patch[:2] == ("PATCH", "repos/o/r/issues/4") + assert comment[:2] == ("POST", "repos/o/r/issues/4/comments") + text = comment[2]["body"] + assert text.startswith("1 new `feat` commit, ") + assert "/pull/4)" in text and "/pull/1)" not in text + assert "@" not in outside_code(text) + # a `perf` and a `fix` commit: the list of fixes grew, so the text is rewritten, without a comment + assert [call[:2] for call in update(4, 6)] == [("PATCH", "repos/o/r/issues/4")] + # a `perf` commit alone is nothing new + assert update(4, 5) == [] + + +def many_commits(word: str, count: int) -> list: + path = f"{E}/database/Database.java" + return [ + (ew.Commit(f"{n:040x}", "d", f"{word}: {'x' * 200} (#{n})"), [path]) + for n in range(1, count + 1) + ] + + +def test_long_lists_of_commits_are_cut_with_a_count_and_the_full_text_keeps_them(): + url = "https://example.invalid/run" + scan = scan_of(changed_engine()) + scan.features, scan.fixes = many_commits("feat", 400), many_commits("fix", 400) + full = ew.render(scan, url) + assert full.count("`feat: x") == 400 and full.count("`fix: x") == 400 + body = ew.fit(scan, url) + assert len(body) <= ew.BODY_LIMIT < len(full) + for word in ("feat", "fix"): + shown = body.count(f"`{word}: x") + assert 0 < shown < 400 + assert f"{400 - shown} more are in the [run]({url})." in body + assert ew.read_marker(body)["head"] == scan.head + + +def test_the_list_of_fix_commits_is_cut_before_the_list_of_feat_commits(): + scan = scan_of(changed_engine()) + scan.features, scan.fixes = many_commits("feat", 40), many_commits("fix", 400) + body = ew.fit(scan, "https://example.invalid/run") + assert body.count("`feat: x") == 40 + assert 0 < body.count("`fix: x") < 400 + + +def test_the_shortest_cut_fits_when_every_part_is_long(): + scan = scan_of(changed_engine()) + scan.findings = [ + ew.Finding(section, "changed", "s" * 400, "d" * 400, f"{E}/{'F' * 80}.java") + for section, _ in ew.SECTIONS + for _ in range(200) + ] + scan.features, scan.fixes = many_commits("feat", 900), many_commits("fix", 900) + scan.others = many_commits("perf", 900) + assert len(ew.fit(scan, "https://example.invalid/run")) <= ew.BODY_LIMIT # -- when and how it runs -------------------------------------------------------------------------------------------------------------