fix: generate readable ASCII names by default - #45
Open
blaipr wants to merge 1 commit into
Open
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
cigamit
previously approved these changes
Sep 13, 2026
Closes ctrliq#43. `random_title()` supplies the default name for a resource created through the `HasCreate` API without one. It had three branches and only one of them produced a name anybody would want, and that one was unreachable without knowing an environment variable nothing documents. ```python def random_title(num_words=2, non_ascii=True): base = ''.join([random.choice(words) for word in range(num_words)]) if os.getenv('ASCENDERKIT_FORCE_ONLY_ASCII', False): title = ''.join([base, ''.join(str(random_int(99)))]) else: if non_ascii: title = ''.join([base, random_utf8(1)]) else: title = ''.join([base, ''.join([str(random_int()) for _ in range(3)])]) return title ``` The default appended one random BMP character. `random_utf8` scrubs anything outside the BMP and substitutes U+FFFD, so a good share of the output ended in a replacement character: `Inventory - MorningSample<?>`, rendered as a black diamond or an empty box depending on the font. `non_ascii=False` was worse. It appended three `random_int()` calls, each `random.randint(0, sys.maxsize)`, concatenated: `Inventory - ArtIllegal646628978901380143791055131131464064421635873256955087439`. `ASCENDERKIT_FORCE_ONLY_ASCII` gave the sensible two-digit suffix, and appears exactly once in the repository, in the line above. **The call sites had already worked this out, one failure at a time.** Six of the forty-three passed `non_ascii=False`, and they are precisely the places where a stray character breaks something rather than merely looking wrong: a username and an email address in `users.py`, the `/tmp/inventory<char>.ini` path in `ascender/inventory.py`, and the Ansible group and host names in `api/pages/inventory.py`. Everywhere it was merely ugly, it stayed on. So this keeps the branch that works and deletes the two that do not: ``` Inventory - SquarePen56 Inventory - PrivatePeople0 Inventory - FootResolution44 Inventory - ExplanationGrand57 ``` `non_ascii` survives as an opt-in parameter defaulting to `False`, because deliberately exercising the API's Unicode handling is a legitimate thing to want, it is just a poor default. `ASCENDERKIT_FORCE_ONLY_ASCII` goes, since what it produced is now the normal output. The six explicit `non_ascii=False` arguments go with it, being the default now. `random_title` gains the docstring it never had. `words.py` is untouched. 1525 nouns with no duplicates is a lot of file, and it is also what makes these names readable and greppable in an activity stream when you are looking at what a test run left behind. The word list was never the problem. **Scope.** The CLI cannot reach any of this: `ascender <resource> create` posts the kwargs it was given through `self.page.post(kwargs)`, and nothing under `cli/` calls `create()` or `payload()`. Every `random_title` call sits inside `payload()`, `add_survey()`, `copy()`, `add_schedule()` or `make_approval_node()`, the fixture API inherited from `awxkit`. It is still a behaviour change for library callers, so it is in the changelog as one. **Tests.** The two existing tests still pass unchanged and still cover both branches. Two more pin the shape the old code had no assertion for: that the default is ASCII over 50 draws, and that the result is words followed by at most two digits, for one, two and five words. Both would have failed before this change, on either branch. The `skipif(sys.version_info < (3, 6))` markers on the existing pair are also gone, the floor being 3.11. Verified with `black --check`, `flake8` and the unit suite, 359 passing.
blaipr
force-pushed
the
fix/random-title-suffix
branch
from
September 13, 2026 09:03
953393e to
f80dcc2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #43.
random_title()supplies the default name for a resource created through theHasCreateAPI without one. It had three branches and only one of them produced a name anybody would want, and that one was unreachable without knowing an environment variable nothing documents.The default appended one random BMP character.
random_utf8scrubs anything outside the BMP and substitutes U+FFFD, so a good share of the output ended in a replacement character:Inventory - MorningSample<?>, rendered as a black diamond or an empty box depending on the font.non_ascii=Falsewas worse. It appended threerandom_int()calls, eachrandom.randint(0, sys.maxsize), concatenated:Inventory - ArtIllegal646628978901380143791055131131464064421635873256955087439.ASCENDERKIT_FORCE_ONLY_ASCIIgave the sensible two-digit suffix, and appears exactly once in the repository, in the line above.The call sites had already worked this out, one failure at a time. Six of the forty-three passed
non_ascii=False, and they are precisely the places where a stray character breaks something rather than merely looking wrong: a username and an email address inusers.py, the/tmp/inventory<char>.inipath inascender/inventory.py, and the Ansible group and host names inapi/pages/inventory.py. Everywhere it was merely ugly, it stayed on.So this keeps the branch that works and deletes the two that do not:
non_asciisurvives as an opt-in parameter defaulting toFalse, because deliberately exercising the API's Unicode handling is a legitimate thing to want, it is just a poor default.ASCENDERKIT_FORCE_ONLY_ASCIIgoes, since what it produced is now the normal output. The six explicitnon_ascii=Falsearguments go with it, being the default now.random_titlegains the docstring it never had.words.pyis untouched. 1525 nouns with no duplicates is a lot of file, and it is also what makes these names readable and greppable in an activity stream when you are looking at what a test run left behind. The word list was never the problem.Scope. The CLI cannot reach any of this:
ascender <resource> createposts the kwargs it was given throughself.page.post(kwargs), and nothing undercli/callscreate()orpayload(). Everyrandom_titlecall sits insidepayload(),add_survey(),copy(),add_schedule()ormake_approval_node(), the fixture API inherited fromawxkit. It is still a behaviour change for library callers, so it is in the changelog as one.Tests. The two existing tests still pass unchanged and still cover both branches. Two more pin the shape the old code had no assertion for: that the default is ASCII over 50 draws, and that the result is words followed by at most two digits, for one, two and five words. Both would have failed before this change, on either branch. The
skipif(sys.version_info < (3, 6))markers on the existing pair are also gone, the floor being 3.11.Verified with
black --check,flake8and the unit suite, 359 passing.