feat(licensing): declare the deployed software's licence per role

The project licence governs this repository's code and says nothing about the application a role installs, which is where a restriction on commercial use usually sits: a deployment cleared to use Infinito.Nexus commercially is still barred from NLLB-200's CC BY-NC weights.

Each invokable role names its licence in meta/<role>/license.yml with the url it was read from. The rights of a named licence live once in meta/licenses.yml, fifteen fields following the taxonomy choosealicense publishes. AND folds to the strictest combination, OR keeps the most favourable whole licence, and the seven contexts are derived from the rights rather than declared, so a heading cannot contradict the matrix under it.

The generated page renders one matrix per context, a lint refuses a role that declares nothing, and a Playwright spec asserts the page against the deployed docs. 21 of 22 deprecated SPDX ids were resolved against the upstream text; EPSON's remains unread because its AUR page blocks automated access.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-10-20 23:35:00 +02:00
1 parent fbd4b3a18d
commit ff734fe728
210 files changed
+2376 -5

No files matched your search

@@ -0,0 +1,125 @@
from __future__ import annotations
import importlib
import sys
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from utils.cache.files import read_text
from utils.roles.mapping import ROLE_FILE_META_LICENSE
from . import PROJECT_ROOT
_TOOLING = str(PROJECT_ROOT / "roles" / "web-app-docs" / "files" / "python")
if _TOOLING not in sys.path:
sys.path.insert(0, _TOOLING)
licensing = importlib.import_module("infinito_docs.generators.licensing")
_AGPL = "---\nspdx: AGPL-3.0-or-later\nurl: https://example.invalid/COPYING\n"
_MIT = "---\nspdx: MIT\nurl: https://example.invalid/LICENSE\n"
_NOTHING = "# nocheck: license-declared installs nothing of its own\n---\n"
_INLINE = (
"---\nspdx: LicenseRef-Probe-EULA\nurl: https://example.invalid/eula\nrights:\n"
+ "\n".join(
f" {field}: {'true' if field in ('private_use', 'self_host', 'commercial_use') else 'false'}"
for field in (
"commercial_use",
"modifications",
"distribution",
"private_use",
"patent_use",
"self_host",
"include_copyright",
"document_changes",
"disclose_source",
"network_use_disclose",
"same_license",
"liability",
"warranty",
"trademark_use",
"open_source",
)
)
)
def _render(roles: dict[str, str]) -> str:
"""Render the page for *roles* and return it.
Args:
roles: ``{role name: body of its meta/license.yml}``; an empty body
declares no licence file at all.
"""
with TemporaryDirectory() as tmp:
roles_dir = Path(tmp) / "roles"
for name, body in roles.items():
path = roles_dir / name / ROLE_FILE_META_LICENSE
path.parent.mkdir(parents=True)
if body:
path.write_text(body, encoding="utf-8")
output = Path(tmp) / "out" / "licensing.rst"
licensing.generate(roles_dir, output)
return read_text(str(output))
class TestLicensingGenerator(unittest.TestCase):
def test_a_role_is_grouped_by_the_context_its_rights_derive(self):
page = _render({"web-app-alpha": _AGPL, "web-app-beta": _MIT})
self.assertIn("Network copyleft", page)
self.assertIn("Permissive", page)
self.assertIn("AGPL-3.0-or-later", page)
self.assertIn("MIT", page)
def test_the_matrix_carries_one_column_per_right(self):
page = _render({"web-app-alpha": _MIT})
header = page[page.index("* - Role") : page.index("* - ``web-app-alpha``")]
self.assertEqual(len(licensing.COLUMNS) + 1, header.count(" - "))
def test_an_agpl_role_is_marked_as_owing_network_disclosure(self):
page = _render({"web-app-alpha": _AGPL})
row = page[page.index("* - ``web-app-alpha``") :]
cells = [
line.strip()[2:]
for line in row.splitlines()[1:]
if line.startswith(" - ")
]
index = [field for field, _ in licensing.COLUMNS].index("network_use_disclose")
self.assertEqual("yes", cells[index + 1])
def test_a_right_the_licence_withholds_renders_as_a_word(self):
page = _render({"web-app-alpha": _MIT})
row = page[page.index("* - ``web-app-alpha``") :]
cells = [
line.strip()[2:]
for line in row.splitlines()[1:]
if line.startswith(" - ")
]
index = [field for field, _ in licensing.COLUMNS].index("patent_use")
self.assertEqual("no", cells[index + 1])
def test_inline_rights_resolve_without_a_table_entry(self):
page = _render({"web-app-alpha": _INLINE})
self.assertIn("web-app-alpha", page)
self.assertNotIn("Not yet determined", page)
def test_a_role_without_a_licence_file_is_listed_as_undetermined(self):
page = _render({"web-app-alpha": ""})
self.assertIn("Not yet determined", page)
self.assertIn("web-app-alpha", page)
def test_a_role_that_deploys_nothing_is_not_reported_as_a_gap(self):
page = _render({"web-app-alpha": _NOTHING})
self.assertIn("Deploying no third-party software", page)
self.assertNotIn("Not yet determined", page)
def test_a_non_invokable_role_is_left_off_the_page(self):
page = _render({"web-app-alpha": _MIT, "sys-ctl-cln-gamma": _MIT})
self.assertIn("web-app-alpha", page)
self.assertNotIn("sys-ctl-cln-gamma", page)
if __name__ == "__main__":
unittest.main()
@@ -62,6 +62,7 @@ class TestProgress(unittest.TestCase):
"infinito_docs.generators.aliases",
"infinito_docs.generators.cli_commands",
"infinito_docs.generators.integrations",
"infinito_docs.generators.licensing",
"infinito_docs.generators.readmes",
"cli.build.docs.readme",
"cli.build.docs.readme.overview",
Whitespace-only changes.
@@ -0,0 +1,98 @@
from __future__ import annotations
import unittest
from utils.licensing.rights import FIELDS, context_of, resolve, table
EXPECTED_CONTEXT = {
"MIT": "permissive",
"Apache-2.0": "permissive",
"BSD-3-Clause": "permissive",
"CC0-1.0": "permissive",
"PostgreSQL": "permissive",
"GPL-2.0-only": "copyleft",
"GPL-3.0-only": "copyleft",
"LGPL-3.0-or-later": "copyleft",
"MPL-2.0": "copyleft",
"EPL-1.0": "copyleft",
"AGPL-3.0-only": "copyleft-network",
"AGPL-3.0-or-later": "copyleft-network",
"EUPL-1.2": "copyleft-network",
"OSL-3.0": "copyleft-network",
"Elastic-2.0": "source-available",
"BUSL-1.1": "source-available",
"SSPL-1.0": "source-available",
"CC-BY-NC-4.0": "non-commercial",
"LicenseRef-Infinito-Nexus-Community": "non-commercial",
"LicenseRef-Baserow-Premium": "proprietary",
}
EXPECTED_EXPRESSION = {
"MIT AND BSD-3-Clause": "permissive",
"MPL-2.0 AND LGPL-3.0-or-later": "copyleft",
"EUPL-1.2 AND CC-BY-NC-ND-4.0": "non-commercial",
"MIT AND LicenseRef-Baserow-Premium": "proprietary",
"MIT OR Apache-2.0": "permissive",
"GPL-2.0-only OR GPL-3.0-only": "copyleft",
"AGPL-3.0-only OR LicenseRef-RSALv2 OR SSPL-1.0": "copyleft-network",
"Elastic-2.0 OR SSPL-1.0 OR AGPL-3.0-only": "copyleft-network",
}
class TestLicenceTable(unittest.TestCase):
def test_every_entry_declares_every_field(self):
incomplete = {
name: sorted({*FIELDS, "open_source"} - set(row))
for name, row in table().items()
if {*FIELDS, "open_source"} - set(row)
}
self.assertEqual({}, incomplete)
def test_every_value_is_a_bool(self):
wrong = [
f"{name}.{field}"
for name, row in table().items()
for field in (*FIELDS, "open_source")
if not isinstance(row.get(field), bool)
]
self.assertEqual([], wrong)
class TestContextDerivation(unittest.TestCase):
def test_each_licence_derives_its_expected_context(self):
for spdx, expected in EXPECTED_CONTEXT.items():
with self.subTest(spdx=spdx):
self.assertEqual(expected, context_of(resolve(spdx, None)).key)
def test_an_unknown_id_without_inline_rights_is_unknown(self):
self.assertIsNone(resolve("Not-A-Real-Licence-9.9", None))
self.assertEqual("unknown", context_of(None).key)
class TestExpressions(unittest.TestCase):
def test_each_expression_derives_its_expected_context(self):
for expression, expected in EXPECTED_EXPRESSION.items():
with self.subTest(expression=expression):
self.assertEqual(expected, context_of(resolve(expression, None)).key)
def test_and_takes_the_strictest_duty_of_either_side(self):
folded = resolve("MIT AND AGPL-3.0-only", None)
self.assertTrue(folded["network_use_disclose"])
self.assertTrue(folded["include_copyright"])
def test_or_keeps_one_whole_licence_rather_than_mixing_fields(self):
chosen = resolve("AGPL-3.0-only OR LicenseRef-RSALv2 OR SSPL-1.0", None)
self.assertEqual(chosen, table()["AGPL-3.0-only"])
def test_an_expression_naming_one_unknown_id_falls_back_to_inline_rights(self):
inline = dict.fromkeys((*FIELDS, "open_source"), False)
inline["commercial_use"] = True
inline["modifications"] = True
self.assertEqual(
"source-available",
context_of(resolve("LicenseRef-Probe-EULA", inline)).key,
)
if __name__ == "__main__":
unittest.main()