Skip to content

Conversation

@bhearsum
Copy link
Contributor

@bhearsum bhearsum commented Dec 3, 2024

This is inspired by recent frustrations of surprise behaviour by signingscript, and feeling like the current test-every-tiny-little-function-independently tests wouldn't allow for any sort of confident refactoring. These new tests that I'm adding use the same entry point that scriptworker calls into: async_main, and they mock out as little as they possible can. Currently, this is calls to Autograph, and verify_mar_signature, but there will probably be other things mocked out (eg: anything that depends on a signature from a real certificate will need to be mocked).

Running just these new tests alone already achieves 35% coverage overall, and 27% coverage of sign.py:

tests/test_script.py::test_gpg_signing[autograph_gpg] PASSED                                                                                                                                [ 25%]
tests/test_script.py::test_gpg_signing[stage_autograph_gpg] PASSED                                                                                                                          [ 50%]
tests/test_script.py::test_mar_signing[autograph_hash_only_mar384] cPASSED                                                                                                                   [ 75%]
tests/test_script.py::test_mar_signing[stage_autograph_hash_only_mar384] PASSED                                                                                                             [100%]

---------- coverage: platform linux, python 3.11.6-final-0 -----------
Name                              Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------------------------------
src/signingscript/__init__.py         0      0      0      0   100%
src/signingscript/exceptions.py      11      3      0      0    73%   17, 30, 43
src/signingscript/rcodesign.py       71     58     28      0    13%   25-51, 62-69, 82-90, 99-112, 121-132, 143-152
src/signingscript/script.py          72     29     34      7    55%   32, 34, 37-38, 41-43, 55, 57, 71-74, 112-130, 135-137
src/signingscript/sign.py           863    594    222     14    27%   159-161, 182-184, 202-207, 225-235, 255-269, 294-316, 341-373, 393-407, 430-444, 465-488, 495-500, 508-524, 530-539, 545-562, 568-577, 583-596, 602, 623-630, 637-655, 661-663, 669-687, 693-703, 708-712, 718-721, 727-741, 747-751, 756-763, 769-783, 823-857, 867, 919, 934, 936, 938, 946-948, 952->956, 958-963, 966-969, 975-988, 1014, 1027, 1029, 1054-1063, 1135-1145, 1164-1176, 1192-1200, 1245, 1285-1301, 1324-1332, 1354-1367, 1373-1374, 1393-1468, 1493-1515, 1526-1551, 1558-1559, 1564-1582, 1593-1606, 1611-1619, 1628-1650, 1661-1668, 1677-1681, 1690-1768
src/signingscript/task.py            82     11     36     10    82%   83, 131->130, 134, 157-158, 171, 177, 239, 243, 247, 250, 253
src/signingscript/utils.py           95     33     18      3    59%   63-67, 80-81, 101-104, 132, 143-148, 174-177, 192-203, 229, 243
-----------------------------------------------------------------------------
TOTAL                              1194    728    338     34    35%

This number will obviously go up as I add tests for other signing types.

Copy link
Contributor

@ahal ahal left a comment

Choose a reason for hiding this comment

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

Overall this stack looks great to me!

if fmt in ("privileged_webextension", "system_addon", "stage_privileged_webextension", "stage_system_addon"):
return True
if fmt.startswith("autograph_xpi"):
if fmt.startswith(("autograph_xpi", "stage_autograph_xpi")):
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, how did I not know that startswith could take a tuple?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neither did I until a few days ago 😆

@bhearsum
Copy link
Contributor Author

bhearsum commented Dec 3, 2024

augh, sorry, I just realized this has a whole bunch of stuff from #1085. I'm going to rebase.

@bhearsum bhearsum force-pushed the api-level-tests branch 2 times, most recently from c9037fe to 66116bd Compare December 27, 2024 16:48
@bhearsum bhearsum mentioned this pull request Apr 15, 2025
@bhearsum
Copy link
Contributor Author

As much as I'd like to have these, I kindof doubt I'm ever going to be able to prioritize doing this, so I'm just going to close this...

The newly written landoscript is using this style of testing, and can serve as a model for future scripts, or if anyone wants to try to hack it in to an existing one (which is much more difficult to do after the fact vs. when you're writing something new...)

@bhearsum bhearsum closed this May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants