import json import subprocess import tempfile import unittest from pathlib import Path import scripts.conventional_commits as conventional_commits import scripts.preview as preview class PreviewNotesTests(unittest.TestCase): def test_humanize_groups_conventional_subjects(self): self.assertEqual( preview.humanize_subject("feat(update): add preview channel"), ("Added", "Add preview channel"), ) self.assertEqual( preview.humanize_subject("fix: handle preview manifest"), ("Fixed", "Handle preview manifest"), ) self.assertEqual( preview.humanize_subject("not conventional"), ("Other", "Not conventional"), ) def test_build_manifest_archives_current_assets(self): with tempfile.TemporaryDirectory() as tmp: output = Path(tmp) / "preview.json" notes = "Preview notes\n" content = preview.build_manifest( output=output, repo="ogulcancelik/herdr", tag="preview-2026-06-02-abcdef123456", build_id="2026-06-02-abcdef123456", commit="abcdef1234567890", built_at="2026-06-02T03:00:00Z", base_version="0.6.6", protocol=12, notes=notes, shas={"linux-x86_64": "deadbeef"}, retain=30, ) data = json.loads(content) self.assertEqual(data["channel"], "preview") self.assertEqual(data["build_id"], "2026-06-02-abcdef123456") self.assertEqual( data["assets"]["linux-x86_64"]["sha256"], "deadbeef", ) self.assertIn("2026-06-02-abcdef123456", data["builds"]) def test_hidden_subjects_include_preview_manifest_commits(self): self.assertTrue(preview.hidden_subject("docs: update preview manifest")) self.assertFalse(preview.hidden_subject("fix: repair preview manifest")) def test_preview_docs_rewrite_links_to_preview_namespace(self): source = """--- title: Install Herdr --- [Install](/docs/install/) file: ../../../public/assets/logo.svg """ output = subprocess.check_output( ["node", "website/scripts/prepare-docs.mjs", "--rewrite-preview-doc-fixture"], input=source, text=True, ) self.assertIn("[Install](/docs/preview/install/)", output) self.assertIn("file: ../../../../public/assets/logo.svg", output) self.assertIn("Preview docs describe unreleased preview builds", output) class ConventionalCommitTests(unittest.TestCase): def test_valid_subjects_allow_scopes_and_bang(self): self.assertTrue(conventional_commits.valid_subject("fix(update): handle preview")) self.assertTrue(conventional_commits.valid_subject("feat!: change config")) self.assertFalse(conventional_commits.valid_subject("update preview channel")) def test_commit_message_subject_skips_comments(self): with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "COMMIT_EDITMSG" path.write_text( "\n# Please enter the commit message\n\nfix(update): switch channel\n", encoding="utf-8", ) self.assertEqual( conventional_commits.commit_message_subject(path), "fix(update): switch channel", ) if __name__ == "__main__": unittest.main()