Skip to content

Commit 772c494

Browse files
GehockOverkillGuy
andauthored
Add an optional flag to activate a mission config during upload (zeusops#20)
* Describe and test for new auto-activate functionality Adds a feature description and an xfail test for a flag that lets an uploaded config be activated immediately without a separate command. * Make it possible to directly activate an uploaded mission * Add activate flag to `/zeus-upload` -------- Co-authored-by: Jb DOYON <[email protected]>
1 parent 47cd27c commit 772c494

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ The project uses semantic versioning (see [semver](https://semver.org)).
55

66
## [Unreleased]
77

8+
### Added
9+
10+
- New optional argument `activate` to `/zeus-upload`. If set to true, the
11+
uploaded mission is automatically set as the active config.
12+
813
## v0.5.0 - 2025-03-26
914

1015
### Added

features/reforger_upload.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Scenario: Upload next mission
1414
Then a new server config file is created
1515
And the config file is patched with <modlist.json> and <scenarioId>
1616

17+
Scenario: Upload next mission and activate
18+
Given a Zeusops mission locally ready
19+
When Zeus calls "/zeus-upload" with the activate flag
20+
Then the server config file is set as the active mission
21+
1722
Scenario: Upload next mission without modlist
1823
Given a Zeusops mission locally ready
1924
When Zeus calls "/zeus-upload"

src/zeusops_bot/cogs/zeus_upload.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ def __init__(self, bot: "ZeusopsBot", reforger_confgen: ReforgerConfigGenerator)
4646
input_type=discord.SlashCommandOptionType.attachment,
4747
required=False,
4848
)
49+
@discord.option(
50+
"activate",
51+
description="Immediately use this uploaded mission as the active mission",
52+
required=False,
53+
)
4954
async def zeus_upload(
5055
self,
5156
ctx: discord.ApplicationContext,
5257
scenario_id: str,
5358
filename: str,
5459
modlist: discord.Attachment | None = None,
60+
activate: bool = False,
5561
):
5662
"""Upload a mission as a Zeus"""
5763
extracted_mods = None
@@ -78,7 +84,7 @@ async def zeus_upload(
7884
return
7985
try:
8086
path = self.reforger_confgen.zeus_upload(
81-
scenario_id, filename, modlist=extracted_mods
87+
scenario_id, filename, modlist=extracted_mods, activate=activate
8288
)
8389
except ConfigFileNotFound:
8490
await ctx.respond(

src/zeusops_bot/reforger_config_gen.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ def zeus_upload(
3838
scenario_id: str,
3939
filename: str,
4040
modlist: list[ModDetail] | None,
41+
activate: bool = False,
4142
) -> Path:
4243
"""Convert a modlist+scenario into a file on server at given path
4344
4445
Args:
4546
scenario_id: The scenarioID to load within the modlist (selects mission)
4647
filename: The filename to store the resulting file under
4748
modlist: The exhaustive list of mods to load, or None to mean no change needed
49+
activate: If set to true, the added config is immediately set as the
50+
currently active config
4851
4952
Returns:
5053
Path: Path to the file generated on filesystem, under {py:attr}`target_folder`
@@ -68,6 +71,8 @@ def zeus_upload(
6871
target_filepath = as_config_file(self.target_dest, filename)
6972
# Create the file itself
7073
target_filepath.write_text(json.dumps(modded_config_dict, indent=4))
74+
if activate:
75+
self.zeus_set_mission(target_filepath)
7176
return target_filepath
7277

7378
def zeus_set_mission(self, filename):

tests/test_upload_mission.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
import json
1010
from pathlib import Path
1111

12+
import pytest
13+
1214
from tests.fixtures import BASE_CONFIG, MODLIST_DICT, MODLIST_JSON
1315
from zeusops_bot.reforger_config_gen import ReforgerConfigGenerator, extract_mods
1416

1517

16-
def test_upload_edits_files(base_config: Path, mission_dir: Path):
18+
@pytest.mark.parametrize("activate", (False, True))
19+
def test_upload_edits_files(base_config: Path, mission_dir: Path, activate: bool):
1720
"""Scenario: Upload next mission creates file"""
1821
# Given a Zeusops mission locally ready
1922
# And Zeus specifies <modlist.json>, <scenarioId>, <filename>
@@ -24,7 +27,7 @@ def test_upload_edits_files(base_config: Path, mission_dir: Path):
2427
)
2528
# When Zeus calls "/zeus-upload"
2629
modlist = extract_mods(MODLIST_JSON)
27-
out_path = config_gen.zeus_upload(scenario_id, filename, modlist)
30+
out_path = config_gen.zeus_upload(scenario_id, filename, modlist, activate)
2831
# Then a new server config file is created
2932
assert out_path.is_file(), "Should have generated a file on disk"
3033
# And the config file is patched with <modlist.json> and <scenarioId>
@@ -34,6 +37,24 @@ def test_upload_edits_files(base_config: Path, mission_dir: Path):
3437
assert config["game"]["mods"][0] == MODLIST_DICT[0]
3538

3639

40+
def test_upload_activate_mission(base_config: Path, mission_dir: Path):
41+
"""Scenario: Upload next mission and activate"""
42+
# Given a Zeusops mission locally ready
43+
# When Zeus calls "/zeus-upload" with the activate flag
44+
config_gen = ReforgerConfigGenerator(
45+
base_config_file=base_config, target_folder=mission_dir
46+
)
47+
modlist = extract_mods(MODLIST_JSON)
48+
out_path = config_gen.zeus_upload(
49+
"cool-scenario-1", "Jib_20250228", modlist, activate=True
50+
)
51+
# Then the server config file is set as the active mission
52+
target = mission_dir / "current-config.json"
53+
assert target.readlink() == out_path.relative_to(
54+
mission_dir
55+
), "Target should point to uploaded file"
56+
57+
3758
def test_upload_edits_files_without_modlist(base_config: Path, mission_dir: Path):
3859
"""Scenario: Upload next mission without modlist"""
3960
# Given a Zeusops mission locally ready

0 commit comments

Comments
 (0)