Repository navigation
test(cli): cover app id derivation from project names - #79
Merged
owenthcarey merged 1 commit intoSep 8, 2026
Merged
owenthcarey merged 1 commit into
owenthcarey merged 1 commit into
Conversation
_app_id_from_name had no direct tests and no docstring, and the two behaviors that matter were pinned by nothing: mutating it to keep hyphens or to use a different prefix broke zero tests, because every existing fixture used my_app, widgets, or MyProject. What the six downstream assertions pinned was underscore preservation and lowercasing, incidentally. The tests are split by reachability. _NAME_RE guarantees a leading letter, so the "app" prefix branch is unreachable from pn init <name>; it is live only via the derived directory name when pn init is given none. Each group asserts its own premise against _NAME_RE so the split can't silently rot, and one end-to-end test drives the prefix branch through the no-name path. The docstring records why hyphens are deleted rather than mapped, that the derivation is therefore non-injective, and that the result satisfies _APP_ID_SEGMENT without being guaranteed to pass _validate_app_id -- reserved words like "class" pass through here. No behavior change; the function body's AST is identical to main. Closes pythonnative#62
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.
What
A Google-style docstring on
_app_id_from_nameand direct unit tests. No behavior change — thefunction body's AST is identical to
main.Closes #62.
The reachability split, which corrects the issue
_NAME_RE(^[a-z][a-z0-9_-]*$) guarantees a leading letter, soslugis never empty andslug[0].isalpha()is always true for a typed name. Theapp-prefix branch is unreachablefrom
pn init <name>.The issue names
3d_viewer→com.example.app3d_vieweras the headline untested case, butpn init 3d_viewerexits 1 on the name guard and never calls this function. A test written thatway would pass for the wrong reason. Same for the empty-string and uppercase cases.
So the tests are split into typed-reachable and derived-only groups, each asserting its own
premise against
_NAME_REso the split can't silently rot, and the prefix branch is covered endto end through the no-name path from a
3d_viewer/directory. Hyphen removal is the onlysubstitution a typed name can trigger, since
-is the one_NAME_REcharacter outside[a-z0-9_].The suggested invariant can't fail, and I kept it anyway
^com\.example\.[a-z][a-z0-9_]*$holds for every possible input — fuzzed over 2,173,777 duringorientation (exhaustive ASCII to length 3, every Unicode character whose
.lower()changeslength, 60k random control characters and non-ASCII), and structurally guaranteed since the
substitution leaves only
[a-z0-9_]and the prefix supplies a leading letter.It earns its place for a narrower reason, recorded in a comment: it catches a change that admits
a character outside the segment grammar — under a keep-hyphens mutation it kills 4 nodes, since
com.example.my-appdoesn't match — but not a changed prefix. The exact-value cases carry thereal weight.
What the mutation checks establish
Before this PR, the two behaviors the issue exists to cover were pinned by nothing:
[^a-z0-9_-]"x"not"app"[^a-z0-9].lower()Every existing fixture used
my_app,widgets, orMyProject— no hyphens, nothing digit- orunderscore-leading. What the six downstream assertions pinned was underscore preservation and
lowercasing, incidentally, and nothing the issue was about.
Two claims in the docstring took correcting during review
Recording them because they're the kind of thing that survives into documentation otherwise.
Hyphens and the platform grammars. I first wrote that neither a Java package segment nor an
iOS bundle identifier admits a hyphen. The second half is wrong here:
config.py:444calls_validate_app_id(self.ios.bundle_id, allow_hyphen=True), and:613normalizes-to_beforematching, so an explicit
[ios].bundle_idmay contain one. The real constraint is stronger andsimpler —
_app_id_from_namefillsapp.id, which is the default for both the Androidapplication id and the iOS bundle id, so it has to satisfy the stricter of the two grammars.
Non-injectivity. I first wrote that mapping
-to_would be "valid and injective." Itwouldn't.
_NAME_REpermits both characters, somy-appwould collide withmy_appinstead ofwith
myapp. Across every typed-legal name up to length 4, both schemes lose the same 423 namesto collision — deletion produces 129 multi-source ids, the mapping produces 309. Same information
loss, redistributed. Injectivity would need an escaping scheme, not a substitution.
A test now pins
my-appandmy_appas distinct, so the alternative can't be introduced silentlyand the comment can't go stale.
Flagged, not fixed
pn init classexits 0 and writesid = "com.example.class", which_validate_app_idthenrejects — all 53 entries in
config._JAVA_KEYWORDSpass_NAME_RE. The scaffold is dead onarrival. Opened as #78; out of scope here since this issue forbids behavior changes and the fix
is a product decision. The docstring records that the result satisfies
_APP_ID_SEGMENTwithoutbeing guaranteed to pass
_validate_app_id.Testing
32 new test nodes, 111 in
tests/test_cli.py../scripts/check.shpasses.Behavior identity was verified two ways: the function body's AST compared against
mainwith thedocstring stripped, and 10,011 fuzz inputs run through both versions with outputs compared. Every
parameterized expected value was computed independently from
main's source rather than from theimplementation under test.
_app_id_from_nameis private, somkdocstrings'filters: ["!^_"]excludes it — the docstringdoesn't render anywhere and
mkdocs build --strictis unaffected.