"""Test Release Notes.
The release list is checked against the git history as it is built, so the history here is written to match the releases rather than
taken from anywhere."""
####################################################################################################################################
import json
import os
import tempfile
from harness.test import *
from common.error import *
from common.exec import exec_one
from common.storage import file_read, file_write
from common.xml import xml_node_attribute, xml_node_child, xml_node_child_list, xml_node_content, xml_parse
from command.render.release import release_current_stable, release_history_update, release_last, release_list, release_render
from command.render.render import DocRender
# The history a release is checked against, newest first, which is the order git writes it in
HISTORY = [
("h1", "Improve a thing."),
("h2", "v2.02: Second."),
("h3", "Fix a bug."),
("h4", "Begin v2.02 development."),
("h5", "v2.01: First."),
("h6", "Add a feature."),
("h7", "v1.00: Initial."),
]
CONTRIBUTOR = """
David Steele
Other Person
Third Person
"""
RELEASE_LIST = """
Improve a thing.
Rework the internals.
A note about this release.
Fix a bug.
Add a feature.
And say more about it.
Fix an old bug.
Start the test suite.
Try things out.
Try other things out.
"""
# Releases with details and the history they are checked against
DETAIL_HISTORY = [
("dB", "Merge v2.10.1 release."),
("dA", "Fix a bug on a branch."),
("d8", "Rework the internals."),
("d0", "Improve speed."),
("d1", "Add a feature."),
("d2", "Fix a bug."),
("d3", 'Fix a "quoted" .'),
("d4", "Begin v2.60.0 development."),
("d5", "v2.10.0: Prior."),
("d6", "Improve a thing."),
("d7", "v1.00: Initial."),
]
DETAIL_RELEASE_LIST = """
Add a feature.
Say more about it.
And more.
Fix bugs.
Speed things up.
Rework the internals.
Fix a bug on a branch.
Improve a thing.
Say more.
"""
# Html of the details up to the first paragraph or line of links
DETAIL_HTML = '\n
'
# Version header with the patch part given
VERSION_H = """#define PROJECT_VERSION_MAJOR 2
#define PROJECT_VERSION_MINOR 60
#define PROJECT_VERSION_PATCH %d
#define PROJECT_VERSION_SUFFIX ""
"""
####################################################################################################################################
def _doc(release_list=RELEASE_LIST, contributor=CONTRIBUTOR):
"""The release document, which is the list of releases and who worked on them."""
return (
'What changed.'
"About the releases.
"
"%s%s" % (release_list, contributor)
)
####################################################################################################################################
def _history(history):
"""The cached form of a history."""
return [{"commit": commit, "date": "2026-07-30 00:00:00 +0000", "subject": subject} for commit, subject in history]
####################################################################################################################################
def _render(content=None, dev=False, history=HISTORY, claim=True, history_tag=None):
"""Build the release document from a release list."""
with tempfile.TemporaryDirectory() as path:
file_write(
os.path.join(path, "resource/git-history.cache"),
json.dumps(
{
"head": _history(history),
"tag": {} if history_tag is None else {version: _history(tag) for version, tag in history_tag.items()},
}
),
)
return release_render(xml_parse(_doc() if content is None else content, "test.xml"), path, dev, claim)
####################################################################################################################################
def _commit(path, subject, body=None):
"""Commit to a repository with nothing changed."""
exec_one(
"git -C %s -c user.name=test -c user.email=test@pgbackrest.org -c commit.gpgsign=false commit -q --allow-empty -m '%s'%s"
% (path, subject, "" if body is None else " -m '%s'" % body)
)
####################################################################################################################################
def _section_list(root):
"""The sections of the release document, which is how the releases are grouped."""
return [xml_node_attribute(section, "id") for section in xml_node_child_list(root, "section")]
####################################################################################################################################
def _item_html(release):
"""The html of each item of a release."""
render = DocRender("html")
return [
render.process_text(item)
for list_node in xml_node_child_list(release, "list")
for item in xml_node_child_list(list_node, "list-item")
]
####################################################################################################################################
def test_release_list():
"""The releases are listed newest first, which is the order they are read in."""
root = xml_parse(_doc(), "test.xml")
assert_equal([xml_node_attribute(node, "version") for node in release_list(root)][:2], ["2.03dev", "2.02"])
assert_equal(xml_node_attribute(release_last(root), "version"), "2.03dev")
# The most recent release that is out is what a reader who is not tracking development would install
assert_equal(xml_node_attribute(release_current_stable(root), "version"), "2.02")
with assert_raises(ToolError) as raised:
release_current_stable(xml_parse(_doc(''), "test.xml"))
assert_equal(str(raised.exception), "unable to find a released version")
####################################################################################################################################
def test_release_render():
"""Releases are grouped by how interesting they still are rather than by when they happened."""
root = _render()
assert_equal(_section_list(root), ["introduction", "development", "current", "supported", "unsupported"])
# The introduction says what the page is, which the title of the page already says, so it has no header of its own
assert_equal(xml_node_attribute(xml_node_child_list(root, "section")[0], "header"), "n")
# The document says what it is and what a search engine should show for it, and leaves out the contents since the releases are
# listed at the top of the page anyway
assert_equal(xml_node_attribute(root, "title"), "Releases")
assert_equal(xml_node_attribute(root, "subtitle"), "What Changed")
assert_equal(xml_node_attribute(root, "toc"), "n")
assert_equal(xml_node_content(xml_node_child(root, "description")), "What changed.")
assert_in("About the releases.", xml_node_content(xml_node_child_list(root, "section")[0]))
# A release keeps its own anchor whichever group it ends up in, so a link to it does not break when it moves
development = xml_node_child_list(root, "section")[1]
release = xml_node_child_list(development, "section")[0]
assert_equal(xml_node_attribute(release, "id"), "2.03dev")
assert_equal(xml_node_attribute(release, "anchor"), "no-inherit")
assert_equal(xml_node_content(xml_node_child(release, "title")), "v2.03dev Notes")
assert_equal(xml_node_content(xml_node_child(release, "subsubtitle")), "No Release Date Set")
# A release that is out says when it came out
supported = xml_node_child_list(root, "section")[3]
assert_equal(
xml_node_content(xml_node_child(xml_node_child_list(supported, "section")[0], "subsubtitle")), "Released January 2, 2026"
)
####################################################################################################################################
def test_release_render_item():
"""An item says what changed, who did it, and which part of the project it was in."""
root = _render()
current = xml_node_child_list(root, "section")[2]
release = xml_node_child_list(current, "section")[0]
text = "".join(xml_node_content(node) for node in xml_node_child_list(release, "p"))
# A note about the release as a whole goes before the first list, and a bug fix is named as a bug fix
assert_in("A note about this release.", text)
assert_in(" Bug Fixes:", text)
item = xml_node_child(xml_node_child(release, "list"), "list-item")
# The default contributor is dropped where they are the only one, so their name is not on every line of the page
assert_equal(xml_node_content(item), "Fix a bug. (Tested by Third Person. Reported by Other Person.)")
# A release of the documentation says so, and an item written as more than one paragraph reads as one line
supported = xml_node_child_list(root, "section")[3]
release = xml_node_child_list(supported, "section")[0]
assert_in("Documentation Features:", "".join(xml_node_content(node) for node in xml_node_child_list(release, "p")))
assert_equal(
xml_node_content(xml_node_child(xml_node_child(release, "list"), "list-item")),
"Add a feature. And say more about it. (Contributed by Other Person. Reviewed by Third Person.)",
)
####################################################################################################################################
def test_release_render_dev():
"""Development items are of no interest to a reader, so they are only listed on a development build."""
development = xml_node_child_list(_render(), "section")[1]
assert_not_in("Rework the internals.", xml_node_content(development))
development = xml_node_child_list(_render(dev=True), "section")[1]
assert_in("Rework the internals.", xml_node_content(development))
assert_in("Development:", xml_node_content(development))
####################################################################################################################################
def test_release_render_error():
"""A release list that does not describe what happened is reported rather than rendered."""
# Only one release can be in development at a time
with assert_raises(ToolError) as raised:
_render(
_doc(
''
''
)
)
assert_equal(str(raised.exception), "only one development release is allowed")
# A date that is not a date
with assert_raises(ToolError) as raised:
_render(_doc(RELEASE_LIST.replace('date="2026-07-30"', 'date="2026-13"')))
assert_equal(str(raised.exception), "invalid date 2026-13 for release 2.02")
# A release that has no release before it in the list has no commits to take
with assert_raises(ToolError) as raised:
_render(_doc(''))
assert_equal(str(raised.exception), "release 2.02 has no release before it to take its commits from")
####################################################################################################################################
def test_release_render_commit():
"""A release item is tied to the commit that did the work, so an item with nothing behind it is reported."""
# An item with no commit named uses what it says as the subject to look for
with assert_raises(ToolError) as raised:
_render(_doc(RELEASE_LIST.replace("Fix a bug.
", "Fix a different bug.
")))
assert_in("unable to find commit or no subject match for release 2.02 item 'Fix a different bug.'", str(raised.exception))
# The commits of the release that nothing has claimed are listed, so the one that was meant is easy to find
assert_in("h3: Fix a bug.", str(raised.exception))
# An item that names a commit is held to it
with assert_raises(ToolError) as raised:
_render(_doc(RELEASE_LIST.replace('subject="Add a feature."', 'subject="Add another feature."')))
assert_in("unable to find release 2.01 commit subject 'Add another feature.' in list", str(raised.exception))
# A release that is out must have a commit that closed it and at least one commit in it
with assert_raises(ToolError) as raised:
_render(history=[entry for entry in HISTORY if entry[1] != "v2.01: First."])
assert_equal(str(raised.exception), "release 2.01 must have an end commit")
with assert_raises(ToolError) as raised:
_render(history=[entry for entry in HISTORY if entry[1] != "Fix a bug."])
assert_equal(str(raised.exception), "no commits found for release 2.02")
####################################################################################################################################
def test_release_render_contributor():
"""Who did the work is said once, and a contributor list that contradicts itself is reported."""
# A reviewer cannot also be a contributor, since a reviewer is someone other than whoever did the work
with assert_raises(ToolError) as raised:
_render(
_doc(RELEASE_LIST.replace('', ''))
)
assert_equal(str(raised.exception), "other.person cannot be both a contributor and a reviewer")
# An item whose ideator is also the only contributor says the same thing twice
with assert_raises(ToolError) as raised:
_render(
_doc(
RELEASE_LIST.replace(
'\n'
' ',
'\n'
' ',
)
)
)
assert_equal(str(raised.exception), "cannot have same contributor and ideator list: other.person")
# A contributor who is not in the list has no name to render
with assert_raises(ToolError) as raised:
_render(
_doc(
RELEASE_LIST.replace(
'id="third.person"/>\n \n\n'
" Fix a bug.",
'id="nobody"/>\n \n\n'
"
Fix a bug.",
)
)
)
assert_equal(str(raised.exception), "contributor nobody does not exist")
####################################################################################################################################
def test_release_render_contributor_default():
"""An item the default contributor did not work on was reviewed by them, and one they did needs no reviewer."""
root = _render()
# The item of 2.01 was contributed by someone else, so the default contributor is named as the reviewer of it
supported = xml_node_child_list(root, "section")[3]
item = xml_node_child(xml_node_child(xml_node_child_list(supported, "section")[0], "list"), "list-item")
assert_in("Reviewed by Third Person.", xml_node_content(item))
# The item of 1.00 has no contributor list at all, so it was done by the default contributor and needs no reviewer
release = xml_node_child_list(supported, "section")[2]
item = xml_node_child(xml_node_child(release, "list"), "list-item")
assert_equal(xml_node_content(item), "Start the test suite.")
assert_in("Test Suite Improvements:", "".join(xml_node_content(node) for node in xml_node_child_list(release, "p")))
####################################################################################################################################
def test_release_render_commit_share():
"""Two items that name the same commit both find it, since a commit can do more than one thing."""
root = _render(
_doc(
RELEASE_LIST.replace(
"
Add a feature.
\n\n And say more about it.
",
"Add a feature.
",
).replace(
"",
"""
Add a feature as well.
""",
)
)
)
supported = xml_node_child_list(root, "section")[3]
item_list = xml_node_child_list(xml_node_child(xml_node_child_list(supported, "section")[0], "list"), "list-item")
assert_equal(len(item_list), 2)
####################################################################################################################################
def test_release_render_commit_ambiguous():
"""A subject that more than one commit begins with does not say which commit an item was, so it is reported."""
with assert_raises(ToolError) as raised:
_render(history=HISTORY[:3] + [("h8", "Fix a bug. Again.")] + HISTORY[3:])
assert_in("subject prefix 'Fix a bug.' already found in commit", str(raised.exception))
####################################################################################################################################
def test_release_render_detail():
"""Releases with version >= _DETAIL_VERSION_MIN have the paragraphs after the first and the links of an item in details."""
root = _render(_doc(DETAIL_RELEASE_LIST), history=DETAIL_HISTORY)
assert_equal(_section_list(root), ["introduction", "current", "supported"])
release = xml_node_child_list(xml_node_child_list(root, "section")[1], "section")[0]
assert_equal(
_item_html(release),
[
"Add a feature."
+ DETAIL_HTML
+ '\nSay more about it.
'
+ '\nAnd more.
'
+ '\n'
+ '
Issue #1'
+ '
Pull request #2'
+ '
Commit '
+ 'd1'
+ "
",
# An item with more than one commit has a line for each commit
"Fix bugs."
+ DETAIL_HTML
+ '\n'
+ '
d2'
+ " Fix a bug."
+ '
Pull request #3 '
+ '\n'
+ '
d3'
+ " Fix a "quoted" <bug>. ",
# An item with one commit has the commit after the issues and pull requests the commit element names
"Speed things up."
+ DETAIL_HTML
+ '\n'
+ '
Issue #5'
+ '
Pull request #6'
+ '
Commit '
+ 'd0'
+ "
",
],
)
# Releases with version < _DETAIL_VERSION_MIN have no details
supported = xml_node_child_list(root, "section")[2]
assert_equal(_item_html(xml_node_child_list(supported, "section")[1]), ["Improve a thing. Say more."])
####################################################################################################################################
def test_release_render_detail_dev():
"""A development release has links for the commits that are found and no error for the commits that are not."""
root = _render(
_doc(
DETAIL_RELEASE_LIST.replace('date="2026-10-01" version="2.60.0"', 'date="XXXX-XX-XX" version="2.60.0dev"').replace(
"",
"""
Do a thing.
Do another thing.
Do a third thing.
""",
1,
)
),
history=DETAIL_HISTORY,
)
development = xml_node_child_list(xml_node_child_list(root, "section")[1], "section")[0]
item_list = _item_html(development)
assert_equal(len(item_list), 6)
assert_equal(item_list[3], "Do a thing.")
assert_equal(
item_list[4],
"Do another thing."
+ DETAIL_HTML
+ '\n',
)
# A line for a commit that is not found has only the links the commit element names
assert_equal(
item_list[5],
"Do a third thing."
+ DETAIL_HTML
+ '\n'
+ '\n'
+ '
d0'
+ " Improve speed. ",
)
####################################################################################################################################
def test_release_render_commit_id():
"""A commit can be named by id when more than one commit has the same subject."""
history = DETAIL_HISTORY[:3] + [("e1", "Fix lines."), ("e2", "Fix lines.")] + DETAIL_HISTORY[3:]
release_list = DETAIL_RELEASE_LIST.replace(
"",
"""
Fix lines.
""",
1,
)
root = _render(_doc(release_list), history=history)
release = xml_node_child_list(xml_node_child_list(root, "section")[1], "section")[0]
assert_equal(
_item_html(release)[3],
"Fix lines."
+ DETAIL_HTML
+ '\n"
+ '\n",
)
# An id that is not in the release
with assert_raises(ToolError) as raised:
_render(_doc(release_list.replace('', '')), history=history)
assert_equal(str(raised.exception), "unable to find attribute 'subject' in node 'commit'")
with assert_raises(ToolError) as raised:
_render(
_doc(release_list.replace('', '')),
history=history,
)
assert_equal(str(raised.exception), "release 2.60.0 commit id 'e2' subject 'Fix lines.' does not begin with 'Fix more lines.'")
####################################################################################################################################
def test_release_render_backpatch():
"""Commits back-patched to a patch release are listed on a development build, grouped by the version of the patch release."""
root = _render(_doc(DETAIL_RELEASE_LIST), dev=True, history=DETAIL_HISTORY)
release = xml_node_child_list(xml_node_child_list(root, "section")[1], "section")[0]
assert_in("Back-Patched:", "".join(xml_node_content(node) for node in xml_node_child_list(release, "p")))
assert_equal(
_item_html(release)[-1],
'Back-patched to v2.10.1.'
+ DETAIL_HTML
+ '\n'
+ '
dA'
+ " Fix a bug on a branch. "
+ '\n'
+ '
dB'
+ " Merge v2.10.1 release. ",
)
# The commits are claimed but not listed on a release build
root = _render(_doc(DETAIL_RELEASE_LIST), history=DETAIL_HISTORY)
assert_not_in("Back-Patched:", xml_node_content(xml_node_child_list(xml_node_child_list(root, "section")[1], "section")[0]))
# The version must be a patch release in the list
for backpatch_version in ("2.10.0", "2.09.1"):
with assert_raises(ToolError) as raised:
_render(
_doc(
DETAIL_RELEASE_LIST.replace(
'', '' % backpatch_version
)
),
history=DETAIL_HISTORY,
)
assert_equal(str(raised.exception), "release 2.60.0 back-patch version %s is not a patch release" % backpatch_version)
# A back-patch has commits
with assert_raises(ToolError) as raised:
_render(
_doc(
DETAIL_RELEASE_LIST.replace(
'',
'\n ',
)
),
history=DETAIL_HISTORY,
)
assert_equal(str(raised.exception), "release 2.60.0 back-patch version 2.10.1 has no commits")
# Development items that name the release note of a later release
NOTE_RELEASE_LIST = """
Finish the thing.
Add the thing.
Add the thing to the docs.
Polish the thing.
Improve a thing.
Prepare for the thing.
Start the thing.
Tidy the thing.
"""
NOTE_HISTORY = [
("p3", "v2.62.0: Final."),
("p1", "Finish the thing."),
("n4", "v2.61.0: Beta."),
("n3", "Add the thing to the docs."),
("n2", "Polish the thing."),
("n1", "Add the thing."),
("m5", "v2.60.0: Start."),
("m6", "Tidy the thing."),
("m4", "Refactor for the thing."),
("m3", "Prepare the thing."),
("m2", "Start the thing."),
("m1", "Improve a thing."),
("m0", "v1.00: Initial."),
]
####################################################################################################################################
def test_release_render_release_note():
"""A development item may name the release note of a later release, which lists the development item in its details."""
root = _render(_doc(NOTE_RELEASE_LIST), history=NOTE_HISTORY)
current = xml_node_child_list(xml_node_child_list(root, "section")[1], "section")[0]
supported = xml_node_child_list(xml_node_child_list(root, "section")[2], "section")
assert_equal(
_item_html(current),
[
"Finish the thing."
+ DETAIL_HTML
+ '\n'
+ '\n'
+ '\n'
+ '
n2'
+ " Polish the thing. "
],
)
# Development items of the same release are listed under one line and the links of a development item with one commit are on the
# line of the commit
assert_equal(
_item_html(supported[0])[0],
"Add the thing."
+ DETAIL_HTML
+ '\n'
+ '\n'
+ '\n'
+ '
m3'
+ " Prepare the thing. "
+ '\n'
+ '
m4'
+ " Refactor for the thing. "
+ '\n'
+ '
m2'
+ " Start the thing."
+ '
Pull request #8 '
+ '\n'
+ '
m6'
+ " Tidy the thing. ",
)
# A development build links a development item to the release of its release note
root = _render(_doc(NOTE_RELEASE_LIST), dev=True, history=NOTE_HISTORY)
supported = xml_node_child_list(xml_node_child_list(root, "section")[2], "section")
assert_equal(
_item_html(supported[1])[1],
"Prepare for the thing."
+ DETAIL_HTML
+ '\n'
+ '
Development for Add the thing
in v2.61.0: '
+ '\n'
+ '
m3'
+ " Prepare the thing. "
+ '\n'
+ '
m4'
+ " Refactor for the thing. ",
)
assert_equal(
_item_html(supported[1])[2],
"Start the thing."
+ DETAIL_HTML
+ '\n'
+ '
Development for Add the thing
in v2.61.0: '
+ '\n'
+ '
Pull request #8'
+ '
Commit '
+ 'm2 ',
)
# A release in development is named by the version it will have when it is released
root = _render(
_doc(NOTE_RELEASE_LIST.replace('date="2026-12-01" version="2.62.0"', 'date="XXXX-XX-XX" version="2.62.0dev"')),
dev=True,
history=NOTE_HISTORY[1:],
)
current = xml_node_child_list(xml_node_child_list(root, "section")[2], "section")[0]
assert_equal(
_item_html(current)[2],
"Polish the thing."
+ DETAIL_HTML
+ '\n'
+ '
Development for Finish the thing
in '
+ 'v2.62.0dev: '
+ '\n',
)
# The release note must be in a later release
for version in ("2.60.0", "2.70.0"):
with assert_raises(ToolError) as raised:
_render(
_doc(
NOTE_RELEASE_LIST.replace(
'version="2.61.0" subject="Add the thing."', 'version="%s" subject="Add"' % version, 1
)
),
history=NOTE_HISTORY,
)
assert_equal(str(raised.exception), "release 2.60.0 release note version %s is not a later release" % version)
# The release note must be found once
with assert_raises(ToolError) as raised:
_render(
_doc(NOTE_RELEASE_LIST.replace('subject="Add the thing."', 'subject="Add another thing."', 1)), history=NOTE_HISTORY
)
assert_equal(str(raised.exception), "release 2.60.0 release note 'Add another thing.' not found in release 2.61.0")
with assert_raises(ToolError) as raised:
_render(_doc(NOTE_RELEASE_LIST.replace('subject="Add the thing."', 'subject="Add the thing"', 1)), history=NOTE_HISTORY)
assert_equal(str(raised.exception), "release 2.60.0 release note 'Add the thing' found more than once in release 2.61.0")
# Only a development item may name a release note
with assert_raises(ToolError) as raised:
_render(
_doc(
NOTE_RELEASE_LIST.replace(
"Finish the thing.
", '\nFinish the thing.
'
)
),
history=NOTE_HISTORY,
)
assert_equal(
str(raised.exception), "release 2.62.0 item 'Finish the thing.' is not a development item and cannot name a release note"
)
# A patch release built on a branch of its own
PATCH_RELEASE_LIST = """
Improve more.
Fix a bug on a branch.
Say more.
Fix the build on a branch.
Improve a thing.
"""
PATCH_HISTORY = [
("n2", "v2.61.0: Next."),
("n1", "Improve more."),
("n0", "Begin v2.61.0 development."),
("m2", "v2.60.0: Detail."),
("m1", "Improve a thing."),
("m0", "v1.00: Initial."),
]
PATCH_HISTORY_TAG = {
"2.60.1": [
("t3", "v2.60.1: Patch."),
("t2", "Fix the build on a branch."),
("t1", "Fix a bug on a branch."),
("t0", "Begin v2.60.1 development."),
]
}
####################################################################################################################################
def test_release_render_patch():
"""A patch release that is not the most recent is checked against the history of its tag."""
root = _render(_doc(PATCH_RELEASE_LIST), dev=True, history=PATCH_HISTORY, history_tag=PATCH_HISTORY_TAG)
release = xml_node_child_list(xml_node_child_list(root, "section")[2], "section")[0]
assert_equal(xml_node_attribute(release, "id"), "2.60.1")
assert_equal(
_item_html(release),
[
"Fix a bug on a branch."
+ DETAIL_HTML
+ '\nSay more.
'
+ '\n',
"Fix the build on a branch."
+ DETAIL_HTML
+ '\n',
],
)
# Every commit of the patch release is claimed by an item
with assert_raises(ToolError) as raised:
_render(
_doc(PATCH_RELEASE_LIST.replace("Fix the build on a branch.
", "Fix the build elsewhere.
")),
history=PATCH_HISTORY,
history_tag=PATCH_HISTORY_TAG,
)
assert_in("unable to find commit or no subject match for release 2.60.1 item 'Fix the build elsewhere.'", str(raised.exception))
with assert_raises(ToolError) as raised:
_render(
_doc(PATCH_RELEASE_LIST),
history=PATCH_HISTORY,
history_tag={"2.60.1": [("t4", "Do something unclaimed.")] + PATCH_HISTORY_TAG["2.60.1"]},
)
assert_in("release 2.60.1 has commits that no item claims:\n2026-07-30 t4: Do something unclaimed.", str(raised.exception))
# A patch release after another patch release ends at the commit that closed the one before it
release_before = """
Fix an earlier bug.
"""
release_list = PATCH_RELEASE_LIST.replace('version="2.60.1" title="Patch"', 'version="2.60.2" title="Patch"').replace(
'Fix the build on a branch.
", "Fix the build elsewhere.
")),
history=PATCH_HISTORY,
)
####################################################################################################################################
def test_release_render_bug_fix():
"""A bug fix release x.y.z with z > 0 is skipped when it is not the most recent and a release x.y.0 is checked."""
# The commits of 2.60.0 end at the commit that closed 2.10.0
with assert_raises(ToolError) as raised:
_render(_doc(DETAIL_RELEASE_LIST.replace("Add a feature.
", "Improve a thing.
")), history=DETAIL_HISTORY)
assert_in("unable to find commit or no subject match for release 2.60.0 item 'Improve a thing.'", str(raised.exception))
# Development on 2.60.0 may have been opened as 2.60
_render(
_doc(DETAIL_RELEASE_LIST),
history=[("d4", "Begin v2.60 development.") if commit == "d4" else (commit, subject) for commit, subject in DETAIL_HISTORY],
)
# Every commit of 2.60.0 is claimed by an item
with assert_raises(ToolError) as raised:
_render(_doc(DETAIL_RELEASE_LIST), history=[("d9", "Do something unclaimed.")] + DETAIL_HISTORY)
assert_in("release 2.60.0 has commits that no item claims:\n2026-07-30 d9: Do something unclaimed.", str(raised.exception))
# Commits that no item claims are allowed when claim is false
_render(_doc(DETAIL_RELEASE_LIST), history=[("d9", "Do something unclaimed.")] + DETAIL_HISTORY, claim=False)
# 2.10.0 is checked
with assert_raises(ToolError) as raised:
_render(_doc(DETAIL_RELEASE_LIST.replace("Improve a thing.
", "Improve two things.
")), history=DETAIL_HISTORY)
assert_in("unable to find commit or no subject match for release 2.10.0 item 'Improve two things.'", str(raised.exception))
####################################################################################################################################
def test_release_history_update():
"""The history is written from git when the newest commit in it or in the tag of a patch release has changed."""
with tempfile.TemporaryDirectory() as path:
path_doc = os.path.join(path, "doc")
path_history = os.path.join(path_doc, "resource/git-history.cache")
exec_one("git -C %s init -q" % path)
file_write(os.path.join(path, "src/version.h"), VERSION_H % 0)
_commit(path, "Add a feature.", "What the feature does.")
_commit(path, "v2.01: First.", "The release notes.")
# With no integration branch the history ends at HEAD
assert_false(release_history_update(path, path_doc))
history = json.loads(file_read(path_history))
assert_equal(history["head"][0]["commit"], exec_one("git -C %s rev-parse HEAD" % path).strip())
assert_equal(sorted(history["head"][1]), ["body", "commit", "date", "subject"])
assert_equal(history["tag"], {})
# The body of a commit that closed a release is left out
assert_equal(
[(commit["subject"], commit.get("body")) for commit in history["head"]],
[("v2.01: First.", None), ("Add a feature.", "What the feature does.")],
)
# The history is not written while HEAD is the newest commit in it
file_write(path_history, json.dumps({"head": history["head"][:1], "tag": {}}))
release_history_update(path, path_doc)
assert_equal(len(json.loads(file_read(path_history))["head"]), 1)
# A history written in the format before patch releases were read from their tags is written again
file_write(path_history, json.dumps(history["head"][:1]))
release_history_update(path, path_doc)
assert_equal(len(json.loads(file_read(path_history))["head"]), 2)
# A new commit is first in the history
_commit(path, "Fix a bug.")
release_history_update(path, path_doc)
assert_equal(
[commit["subject"] for commit in json.loads(file_read(path_history))["head"]],
["Fix a bug.", "v2.01: First.", "Add a feature."],
)
# The history of a patch release with version >= _DETAIL_VERSION_MIN is the commits of its tag that are not in the history
# of HEAD. Other release tags are left out.
branch = exec_one("git -C %s branch --show-current" % path).strip()
exec_one("git -C %s tag release/2.60.0" % path)
exec_one("git -C %s tag release/2.10.1" % path)
exec_one("git -C %s checkout -q -b patch" % path)
_commit(path, "Fix a bug on a branch.")
exec_one("git -C %s tag release/2.60.1" % path)
exec_one("git -C %s checkout -q %s" % (path, branch))
release_history_update(path, path_doc)
history = json.loads(file_read(path_history))
assert_equal(list(history["tag"]), ["2.60.1"])
assert_equal([commit["subject"] for commit in history["tag"]["2.60.1"]], ["Fix a bug on a branch."])
# The history is written again when the tag of a patch release moves
exec_one("git -C %s checkout -q patch" % path)
_commit(path, "v2.60.1: Patch.")
exec_one("git -C %s tag -f release/2.60.1" % path)
exec_one("git -C %s checkout -q %s" % (path, branch))
release_history_update(path, path_doc)
assert_equal(
[commit["subject"] for commit in json.loads(file_read(path_history))["tag"]["2.60.1"]],
["v2.60.1: Patch.", "Fix a bug on a branch."],
)
# With an integration branch related to HEAD the history ends at the newest commit of HEAD that is also in integration
exec_one("git -C %s branch integration" % path)
_commit(path, "RELEASE: Add release notes.")
assert_true(release_history_update(path, path_doc))
assert_equal(json.loads(file_read(path_history))["head"][0]["subject"], "Fix a bug.")
# With an integration branch that is not related to HEAD the history ends at HEAD
tree = exec_one("git -C %s hash-object -t tree /dev/null" % path).strip()
commit = exec_one(
"git -C %s -c user.name=test -c user.email=test@pgbackrest.org commit-tree %s -m 'Unrelated.'" % (path, tree)
).strip()
exec_one("git -C %s update-ref refs/heads/integration %s" % (path, commit))
assert_false(release_history_update(path, path_doc))
assert_equal(json.loads(file_read(path_history))["head"][0]["subject"], "RELEASE: Add release notes.")
# With an upstream integration branch related to HEAD the history ends at the newest commit of HEAD that is also in the
# upstream branch, and the result is false
exec_one("git -C %s update-ref refs/remotes/upstream/integration HEAD~1" % path)
assert_false(release_history_update(path, path_doc))
assert_equal(json.loads(file_read(path_history))["head"][0]["subject"], "Fix a bug.")
# With PROJECT_VERSION_PATCH != 0 the integration branches are not tried and the history ends at HEAD
file_write(os.path.join(path, "src/version.h"), VERSION_H % 1)
exec_one("git -C %s update-ref refs/heads/integration HEAD~1" % path)
assert_false(release_history_update(path, path_doc))
assert_equal(json.loads(file_read(path_history))["head"][0]["subject"], "RELEASE: Add release notes.")
# With PROJECT_VERSION_PATCH != 0 and an integration-x.y.z-ci branch related to HEAD the history ends at the newest commit
# of HEAD that is also in that branch, and the result is true
exec_one("git -C %s branch integration-2.60.1-ci HEAD~1" % path)
assert_true(release_history_update(path, path_doc))
assert_equal(json.loads(file_read(path_history))["head"][0]["subject"], "Fix a bug.")