diff --git a/docs/tooling/addon-ci.md b/docs/tooling/addon-ci.md index dc68eca..fa1ad2c 100644 --- a/docs/tooling/addon-ci.md +++ b/docs/tooling/addon-ci.md @@ -46,9 +46,13 @@ skipping the Odoo runner. They also run The default remains full addon validation. The runner installs all installable owned addons, including ones without tests, -and selects tests by the owned module names. Shared addons are installed as -tenant dependencies without selecting their tests again. Test discovery remains -Odoo's responsibility. Browser suites use the image's Chromium plus the locked +and selects tests by the owned module names. Full tenant runs also install +the required platform addons and the product's artifact install list, including +modules the owned addons do not depend on directly. A focused tenant run with +a selected addon directory adds only the declared modules from its shared +support checkout. Odoo can resolve dependencies using the entire shared +checkout. Shared-addon CI installs and tests its own full addon set +independently. Browser suites use the image's Chromium plus the locked CI-only `websocket-client` dependency catalog in `docker/addon-tests`. Its Python range covers the 3.13 and 3.14 image families; the base image supplies the interpreter that executes Odoo and its addon tests. @@ -85,10 +89,11 @@ layers, under its existing host cache policy. The runner removes only its own na hosted runner supplies an additional cleanup boundary for job cancellation. `odoo.log` and `result.json` are written to the output directory. The result -records selected modules, external source commits, requested image, the actual -built test image's immutable ID, test count and elapsed +records the test selection, requested and installed modules, external source +commits, requested image, the actual built test image's immutable ID, test count and elapsed seconds; the elapsed time is also reported in the Actions job summary. A missing -summary, zero tests, reported failures/errors, or nonzero Odoo exit fails the job. +summary, zero tests, reported failures/errors, nonzero Odoo exit, or any requested +module missing from the installed set fails the job. Callers upload evidence even when the run fails. Legacy callers may filter addon and test-input changes. Callers adopting `qualityGate.test.local` and `qualityGate.test.ci` run the complete suite for every source PR head and merge diff --git a/odoo_devkit/addon_ci.py b/odoo_devkit/addon_ci.py index 749693d..549a1fd 100644 --- a/odoo_devkit/addon_ci.py +++ b/odoo_devkit/addon_ci.py @@ -21,10 +21,11 @@ from .artifact_inputs import effective_artifact_input_sources, load_artifact_inputs_definition from .base_python import BASE_PYTHON_PLATFORMS, read_base_python_catalogs from .dependency_workspace import derive_base_python_lock, stage_publishable_dependency_workspace -from .manifest import load_workspace_manifest +from .manifest import WorkspaceManifest, load_workspace_manifest ROOT = Path(__file__).resolve().parents[1] SUMMARY = re.compile(r"(\d+) failed, (\d+) error[(]s[)] of (\d+) tests") +TEST_DATABASE = "addon_ci" class TestCounts(TypedDict): @@ -35,6 +36,8 @@ class TestCounts(TypedDict): class AddonResult(TypedDict, total=False): addons: list[str] + install_addons: list[str] + installed_addons: list[str] external_sources: list[dict[str, str]] image: str test_image_id: str @@ -67,6 +70,25 @@ def discover_addons(root: Path) -> list[str]: return addons +def product_addons_to_install(manifest: WorkspaceManifest) -> set[str]: + from .local_runtime import ( + LAUNCHPLANE_REQUIRED_ODOO_MODULES, + load_stack, + resolve_manifest_runtime_stack_selection, + resolve_stack_file_path, + ) + + artifact = replace(manifest, runtime=replace(manifest.runtime, instance="artifact")) + _, selection = resolve_manifest_runtime_stack_selection( + manifest=artifact, + stack_definition=load_stack(resolve_stack_file_path(ROOT)).stack_definition, + artifact_inputs_definition=None, + runtime_repo_path=ROOT, + allow_runtime_payload_context=True, + ) + return {*LAUNCHPLANE_REQUIRED_ODOO_MODULES, *selection.effective_install_modules} + + def test_result(log: str, exit_code: int) -> TestCounts: matches = SUMMARY.findall(log) if not matches: @@ -78,6 +100,30 @@ def test_result(log: str, exit_code: int) -> TestCounts: return counts +def read_installed_addons(database_container: str) -> list[str]: + query = "SELECT name FROM ir_module_module WHERE state = 'installed' ORDER BY name" + return command( + [ + "docker", + "exec", + database_container, + "psql", + "-h", + "127.0.0.1", + "-U", + "odoo", + "-d", + TEST_DATABASE, + "-XAt", + "-v", + "ON_ERROR_STOP=1", + "-c", + query, + ], + capture=True, + ).stdout.splitlines() + + def execution_environment() -> dict[str, str]: return {key: value for key, value in os.environ.items() if key != "ADDON_CI_SOURCE_TOKEN"} @@ -217,9 +263,7 @@ def run_tests( devkit_checks: bool = False, ) -> None: owned_addons = discover_addons(addons_root) - install_addons = list(owned_addons) - if support_root is not None: - install_addons = sorted(set(install_addons + discover_addons(support_root))) + install_addons = set(owned_addons) token = f"odoo-addon-ci-{uuid.uuid4().hex[:12]}" database_container = f"{token}-db" test_container = f"{token}-tests" @@ -231,12 +275,22 @@ def run_tests( external_paths: list[str] = [] result["external_sources"] = external_sources try: + manifest = None + if tenant is not None: + manifest = load_workspace_manifest(tenant / "workspace.toml") + product_addons = product_addons_to_install(manifest) + if addons_root != tenant / "addons": + available_support = discover_addons(support_root) if support_root is not None else () + product_addons.intersection_update(available_support) + install_addons.update(product_addons) + elif support_root is not None: + install_addons.update(discover_addons(support_root)) + result["install_addons"] = sorted(install_addons) with tempfile.TemporaryDirectory(prefix=token, dir=output.parent) as temporary: context = Path(temporary) external_root = context / "external" external_root.mkdir() - if tenant is not None: - manifest = load_workspace_manifest(tenant / "workspace.toml") + if manifest is not None: inputs = load_artifact_inputs_definition(manifest=manifest) if inputs: sources = effective_artifact_input_sources( @@ -385,7 +439,7 @@ def run_tests( "--db_user", "odoo", "--database", - "addon_ci", + TEST_DATABASE, "--addons-path", ",".join(paths), "--data-dir", @@ -393,7 +447,7 @@ def run_tests( "--without-demo", "all", "--init", - ",".join(install_addons), + ",".join(result["install_addons"]), "--test-enable", "--test-tags", ",".join(f"/{name}" for name in owned_addons), @@ -419,6 +473,10 @@ def run_tests( log = (output / "odoo.log").read_text(encoding="utf-8") print(log) result.update(test_result(log, completed.returncode)) + result["installed_addons"] = read_installed_addons(database_container) + missing = sorted(install_addons.difference(result["installed_addons"])) + if missing: + raise ValueError(f"Odoo did not install required addons: {', '.join(missing)}") result["state"] = "passed" except TestRunError as error: result.update(error.counts) diff --git a/odoo_devkit/local_runtime.py b/odoo_devkit/local_runtime.py index cddb1e4..7ee30c9 100644 --- a/odoo_devkit/local_runtime.py +++ b/odoo_devkit/local_runtime.py @@ -1288,24 +1288,17 @@ def load_runtime_context( artifact_inputs_definition = load_artifact_inputs_definition(manifest=manifest) except ArtifactInputsError as error: raise RuntimeCommandError(str(error)) from error - effective_stack_definition = resolve_manifest_runtime_stack_definition( + effective_stack_definition, runtime_selection = resolve_manifest_runtime_stack_selection( manifest=manifest, stack_definition=loaded_stack.stack_definition, + artifact_inputs_definition=artifact_inputs_definition, + runtime_repo_path=runtime_repo_path, allow_runtime_payload_context=( not require_local_instance and manifest.runtime.instance.strip().lower() != "local" and explicit_runtime_environment_payload_is_configured() ), ) - website_bootstrap = load_website_bootstrap_definition(manifest=manifest) - runtime_selection = resolve_runtime_selection( - stack_definition=effective_stack_definition, - artifact_inputs_definition=artifact_inputs_definition, - context_name=manifest.runtime.context, - instance_name=manifest.runtime.instance, - repo_root=runtime_repo_path, - website_bootstrap=website_bootstrap, - ) if enforce_required_environment: ensure_required_runtime_selection_values( stack_definition=effective_stack_definition, @@ -1328,6 +1321,28 @@ def load_runtime_context( ) +def resolve_manifest_runtime_stack_selection( + *, + manifest: WorkspaceManifest, + stack_definition: StackDefinition, + artifact_inputs_definition: ArtifactInputsDefinition | None, + runtime_repo_path: Path, + allow_runtime_payload_context: bool, +) -> tuple[StackDefinition, RuntimeSelection]: + stack = resolve_manifest_runtime_stack_definition( + manifest=manifest, stack_definition=stack_definition, allow_runtime_payload_context=allow_runtime_payload_context + ) + selection = resolve_runtime_selection( + stack_definition=stack, + artifact_inputs_definition=artifact_inputs_definition, + context_name=manifest.runtime.context, + instance_name=manifest.runtime.instance, + repo_root=runtime_repo_path, + website_bootstrap=load_website_bootstrap_definition(manifest=manifest), + ) + return stack, selection + + def resolve_manifest_runtime_stack_definition( *, manifest: WorkspaceManifest, diff --git a/tests/test_addon_ci.py b/tests/test_addon_ci.py index 511bf0c..f01898a 100644 --- a/tests/test_addon_ci.py +++ b/tests/test_addon_ci.py @@ -1,4 +1,5 @@ import base64 +import json import os import shutil import subprocess @@ -203,6 +204,72 @@ def test_install_selection_includes_addons_without_tests_and_excludes_uninstalla (addon / "__manifest__.py").write_text(repr({"installable": installable})) self.assertEqual(discover_addons(root), ["no_tests", "tested"]) + def test_full_tenant_validation_installs_startup_addons_and_leaves_optional_support_available(self) -> None: + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + tenant = root / "tenant" + owned = tenant / "addons" + support = root / "support" + platform = root / "platform" + platform.mkdir() + for parent, names in ( + (owned, ("owned_one", "owned_two")), + (support, ("declared", "optional", "launchplane_settings", "disable_odoo_online")), + ): + for name in names: + addon = parent / name + addon.mkdir(parents=True) + (addon / "__manifest__.py").write_text("{}\n") + (tenant / "workspace.toml").write_text("""schema_version=1 +tenant="fixture" +workspace={name="fixture",python="3.13"} +repos={tenant={name="fixture",path="."}} +runtime={context="fixture",instance="local",database="fixture",addons_paths=[]} +ide={mode="tenant_repo",focus_paths=[],attached_paths=[]} +""") + (platform / "stack.toml").write_text("""schema_version=1 +odoo_version="20.0" +addons_path=[] +contexts.fixture={install_modules=["declared", "native_startup"],instances={local={install_modules_add=["optional"]}}} +""") + requested = {"owned_one", "owned_two", "declared", "native_startup", "launchplane_settings", "disable_odoo_online"} + installed = requested | {"transitive_support"} + + def docker_command(args: list[str], *, capture: bool = False) -> subprocess.CompletedProcess[str]: + if args[:2] == ["docker", "exec"] and args[3] == "psql": + return subprocess.CompletedProcess(args, 0, "\n".join(sorted(installed)), "") + return subprocess.CompletedProcess(args, 0, "20.0" if capture else "", "") + + def run_fixture() -> None: + addon_ci.run_tests( + image="fixture", + version="20.0", + addons_root=owned, + support_root=support, + tenant=tenant, + output=root / "results", + timeout=60, + ) + + with ( + patch.object(addon_ci, "ROOT", root), + patch.object(addon_ci, "build_test_image"), + patch.object(addon_ci, "command", side_effect=docker_command) as command_mock, + patch.object(addon_ci, "copy_test_inputs") as copy, + patch.object(subprocess, "run", return_value=subprocess.CompletedProcess([], 0)), + patch.object(addon_ci, "test_result", return_value={"tests": 1, "errors": 0, "failed": 0}), + ): + run_fixture() + invocation = next(call.args[0] for call in command_mock.call_args_list if call.args[0][:2] == ["docker", "create"]) + self.assertEqual(set(invocation[invocation.index("--init") + 1].split(",")), requested) + self.assertEqual(set(invocation[invocation.index("--test-tags") + 1].split(",")), {"/owned_one", "/owned_two"}) + self.assertIn((support, "/opt/extra_addons"), copy.call_args.args[0]) + evidence = json.loads((root / "results/result.json").read_text()) + self.assertEqual(set(evidence["installed_addons"]), installed) + installed.remove("native_startup") + with self.assertRaisesRegex(ValueError, "Odoo did not install required addons: native_startup"): + run_fixture() + def test_no_addons_fails(self) -> None: with tempfile.TemporaryDirectory() as temporary, self.assertRaises(ValueError): discover_addons(Path(temporary))