afterhours-shift-manager/tests/scripts/test_package_lambdas.py
Adam Moussa 13350b72d0
Some checks are pending
Deploy / Deploy to prod (push) Waiting to run
feat(infra): migrate afterhours to HCP Terraform (PLAT-74) (#252)
* fix(cutover): write Slack secrets into empty Terraform shells

DescribeSecret succeeds on HCP-created shells with no version, so skip-if-exists left roster and Slack tokens unset.

* feat(infra): migrate afterhours to HCP Terraform (PLAT-74)

Replace the mgmt SAM stack with a prod-only HCP workspace, in-repo hcptf IAM, stub Lambdas, and zip CD on push to main.

* fix(cutover): retry DDB unprocessed items and skip past at() holidays

Unprocessed BatchWriteItem rows and leftover past at() schedules would drop roster data or abort holiday recreation during prod cutover.
2026-09-15 23:31:59 +00:00

54 lines
1.6 KiB
Python

"""package_lambdas.py zip layout without a full pip install."""
import importlib.util
import sys
import zipfile
from pathlib import Path
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[2]
def _load():
spec = importlib.util.spec_from_file_location(
"package_lambdas", ROOT / "scripts" / "package_lambdas.py"
)
mod = importlib.util.module_from_spec(spec)
sys.modules["package_lambdas"] = mod
spec.loader.exec_module(mod)
return mod
pkg = _load()
def test_function_keys_match_terraform_locals():
locals_tf = (ROOT / "terraform" / "locals.tf").read_text()
for key in pkg.FUNCTIONS:
assert f" {key} =" in locals_tf
for src in pkg.FUNCTIONS.values():
assert src.is_dir()
assert (src / "requirements.txt").is_file()
def test_build_function_bundles_shared_and_git_sha(tmp_path, monkeypatch):
monkeypatch.setattr(pkg, "_req_lines", lambda path: [])
def fake_run(cmd, check):
raise AssertionError(f"pip should not run when reqs are empty: {cmd}")
with patch.object(pkg.subprocess, "run", fake_run):
zip_path = pkg.build_function(
"weekly_post",
pkg.FUNCTIONS["weekly_post"],
"deadbeef",
tmp_path,
)
assert zip_path.is_file()
with zipfile.ZipFile(zip_path) as zf:
names = zf.namelist()
assert "app.py" in names
assert "shared/sentry_init.py" in names
assert "shared/build_info.py" in names
assert 'GIT_SHA = "deadbeef"' in zf.read("shared/build_info.py").decode()
assert "requirements.txt" not in names