Skip to content
45 changes: 45 additions & 0 deletions test/general/test_world_manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Check world sources' manifest files"""

import json
import unittest
from pathlib import Path
from typing import ClassVar

from worlds.AutoWorld import AutoWorldRegister
from ..param import classvar_matrix


# Only check source folders for now. Zip validation should probably be in the loader and/or installer.
source_world_names = [k for k, v in AutoWorldRegister.world_types.items() if not v.zip_path]


def get_source_world_manifest_path(game: str) -> Path | None:
world_type = AutoWorldRegister.world_types[game]
manifest_path = Path(world_type.__file__).parent / "archipelago.json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are worlds meant to always define the world class in a file that's directly inside the root directory instead of a subfolder? Otherwise this will fail to find an archipelago.json in the root directory, although it doesn't seem to be the first place to use this.

Copy link
Member Author

@black-sliver black-sliver Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it only has to be imported from the __init__.py. (But maybe even that can be relaxed in the future once the manifest is mandatory - the manifest could say what exactly to import.)

I added some code to find the worlds' root folder now. I do think this should be solved in AutoWorldRegister, so it can be shared between setup, LauncherComponents and tests, but I am honestly not sure what the best approach is gonna be, so I'd rather leave it just in the test for now (and we'll fix other places in the future).

if manifest_path.exists():
return manifest_path
return None


# TODO: remove the filter once manifests are mandatory.
@classvar_matrix(game=filter(get_source_world_manifest_path, source_world_names))
class TestWorldManifest(unittest.TestCase):
game: ClassVar[str]

def test_game(self) -> None:
"""Test that 'game' will be correctly defined when generating APWorld manifest from source."""
world_type = AutoWorldRegister.world_types[self.game]
manifest_path = get_source_world_manifest_path(self.game)
assert manifest_path # make mypy happy
with manifest_path.open("r", encoding="utf-8") as f:
manifest = json.load(f)
self.assertIn(
"game",
manifest,
f"archipelago.json manifest exists for {self.game} but does not contain 'game'",
)
self.assertIn(
manifest["game"],
world_type.game,
f"archipelago.json manifest for {self.game} specifies wrong game '{manifest['game']}'",
)