Repository navigation
feat(user): confirm creation of unknown user profiles - #127
Merged
Merged
Conversation
Starting a user session for a name that does not exist silently created a new user profile, so a typo in the name left an unwanted profile behind. NansenUserSession.instance now asks the user to confirm before a profile is created for an unknown name, and lists the profiles that already exist so a misspelled name is easy to spot. Declining throws NANSEN:UserSession:UserProfileCreationAborted and creates nothing. The check runs before an active session is closed, so declining leaves the current session untouched. It is skipped for the default profile, for the nocreate and reset modes, and in non-interactive sessions, where input is unavailable. Programmatic callers opt out with the new ConfirmNewUser name-value argument, which ProjectFixture uses for the throwaway profiles it creates. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Test Results444 tests 444 ✅ 54s ⏱️ Results for commit 7b069a5. ♻️ This comment has been updated with latest results. |
Address review findings on the confirmation guard. A declined prompt is a user decision, but neither entry point treated it as one. nansen printed an extended error report with a stack trace, because the new identifier fell through to the catch-all branch. nansen.setup downgraded the error to a warning and then ran the setup wizard anyway, so declining had no effect. Both now report the message and stop. isExistingUser tested for the preference directory with isfolder, which matches names case insensitively on macOS and Windows. A capitalisation typo was accepted as the existing profile and the session then ran under a name that did not match its own directory. Profile names are now compared directly, and a name that differs from an existing profile only by capitalisation is called out in the prompt. The yes/no prompt asking whether to close an active session is replaced by the shared askYesNo helper, so both questions in this class accept the same answers and report unexpected input with an identifier. Its commented out dead code is dropped. getPrefdir and listUserNames now share getUserRootDirectory instead of each spelling out the directory layout. Tests: cover the case sensitive lookup, assert names are present before comparing their positions, and tolerate a missing directory during teardown so a failing test does not report a second, unrelated failure. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Resolves the conflict on the generated badge files by taking the versions from dev. No code files conflicted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
confirmNewUserProfile asked whether to create a profile for a name that differs from an existing profile only by capitalisation. On macOS and Windows the answer yes created nothing: the session ran under the new name on the existing profile's directory, and listUserNames kept returning the old name, so the question came back on every call. Such a name now throws NANSEN:UserSession:UserNameCaseMismatch, which names the existing profile. The check runs before the -batch exemption, so scripts get the error too, and nansen and nansen.setup print it without a stack trace. askYesNo counts an empty answer as no and shows (y/N), so pressing Enter declines instead of raising UnexpectedInput. The ConfirmNewUser help lists when no question is asked. The tests build profile names from a uuid, because test processes that start together share prefdir and the same random number seed; two tests cover the case refusal and its exemption in 'nocreate' mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
ReviewVerdict: ready to merge once CI passes on 020a29e. The guard sits in the right place: it runs before the singleton is inspected, so declining leaves an active session untouched. Fixed on the branch:
All 10 tests in Not changed:
Out of scope (exists on
Merge notes:
🤖 Generated with Claude Code |
ehennestad
added a commit
that referenced
this pull request
Nov 6, 2026
Conflicts: - .github/badges/tests.svg: dev's version. - Preferences.m: dev's fromStruct (#172). It skips saved preferences the class does not declare, as this branch's version did. NansenUserSession.m merges without a conflict, but the merge puts getUserDataDirectory and getDefaultUserDataDirectory after #127's confirmNewUserProfile, inside its methods (Static, Access = private) block. They are moved back to the public static block, because nansen.userdatadir, clear_tutorial_data, ProjectFixture and UserDataDirectoryTest call them from outside the class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ehennestad
added a commit
that referenced
this pull request
Nov 6, 2026
listUserNames, from #127, listed the folders in prefdir/Nansen, which belongs to one MATLAB release. A profile created in another release has only its user data directory, <userpath>/Nansen/profiles/<name>, in this one. The confirmation prompt then called it unknown, and the capitalisation check could not see it: nansen("John") could create a profile next to an existing "john" from another release, and on macOS and Windows the two used the same user data directory. listUserNames now also lists the default user data root. The path of that root moves into getDefaultUserDataRoot, which getDefaultUserDataDirectory also uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ehennestad
added a commit
that referenced
this pull request
Nov 8, 2026
listUserNames, from #127, listed the folders in prefdir/Nansen, which belongs to one MATLAB release. A profile created in another release has only its user data directory, <userpath>/Nansen/profiles/<name>, in this one. The confirmation prompt then called it unknown, and the capitalisation check could not see it: nansen("John") could create a profile next to an existing "john" from another release, and on macOS and Windows the two used the same user data directory. listUserNames now also lists the default user data root. The path of that root moves into getDefaultUserDataRoot, which getDefaultUserDataDirectory also uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ehennestad
added a commit
that referenced
this pull request
Nov 9, 2026
listUserNames, from #127, listed the folders in prefdir/Nansen, which belongs to one MATLAB release. A profile created in another release has only its user data directory, <userpath>/Nansen/profiles/<name>, in this one. The confirmation prompt then called it unknown, and the capitalisation check could not see it: nansen("John") could create a profile next to an existing "john" from another release, and on macOS and Windows the two used the same user data directory. listUserNames now also lists the default user data root. The path of that root moves into getDefaultUserDataRoot, which getDefaultUserDataDirectory also uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
NansenUserSession.instance(userName)creates a user profile for any name it is given. A name that does not exist yet is indistinguishable from a name that does, so a typo silently produces a new profile and its preference directory. Repeated typos accumulate profiles that nobody asked for.Change
instancenow asks the user to confirm before a profile is created for a name that does not exist, and lists the profiles that already exist so a misspelled name sits next to the name it was meant to be:Declining, or pressing Enter, throws
NANSEN:UserSession:UserProfileCreationAbortedand creates nothing.The check runs before the singleton is inspected or torn down. Placing it later would mean an active session is closed by the
mode == "check"branch first, so declining the typo would cost the user the session they already had.It is skipped in four cases: the
defaultprofile, which is created implicitly on first run; a name whose profile already exists; thenocreateandresetmodes, which never construct a session; and non-interactive sessions, whereinputerrors rather than blocks. In a non-interactive session the profile is created without a question.Name matching is case sensitive
isExistingUsercompares against the profile names returned bylistUserNamesrather than testing the preference directory withisfolder. The file system matches names case insensitively on macOS and Windows, soisfolderacceptsJohnas the existing profilejohn, and the session then runs under a name that does not match the directory it reads and writes. A name that differs from an existing profile only by case is refused withNANSEN:UserSession:UserNameCaseMismatch, which names the existing profile, also undermatlab -batch. On macOS and Windows a profile for such a name would share the existing profile's directory.Declining stops the caller
nansenprinted an extended error report with a stack trace for a declined prompt, because the new identifier fell through to the catch-all branch of itsswitch.nansen.setupdowngraded the error to a warning and then ran the setup wizard anyway, so declining had no effect on what setup did. Both now report the message and stop.Shared yes/no prompt
The prompt asking whether to close an active session was a second hand-rolled
inputblock accepting only exact lowercasey/nand erroring without an identifier. Both questions now go through oneaskYesNohelper, so they accept the same answers (y, yes, n, no in any case; an empty answer counts as no) and report unexpected input the same way. Its commented out dead code is dropped.getPrefdirandlistUserNamessharegetUserRootDirectoryinstead of each spelling out the directory layout.Opting out
Programmatic callers pass
ConfirmNewUser=false.nansen.fixture.ProjectFixtureuses this for the throwaway test profiles it creates, which must not block on input.batchStartupOptionUsedcoversmatlab -batch. It does not covermatlab -nodisplay -r, whereinputreads from stdin; automation using that form needsConfirmNewUser=falseexplicitly. Gating on~usejava('desktop')instead was rejected because it would remove the prompt for legitimate-nodesktopterminal use.Tests
tests/+nansen/+unittest/+user/NansenUserSessionTest.mcoverslistUserNames(membership, sort order, exclusion of the.and..entriesdirreturns),isExistingUserincluding the case sensitive lookup, the refusal of a name that differs from a profile only by case, and theinstancepaths that must not prompt:ConfirmNewUser=falsecreates the profile, andnocreatereturns empty without leaving a directory behind or checking the name.The interactive branches are not covered.
inputcannot be substituted from a test without moving the read behind an injectable handle, which is a design change worth making separately if that coverage is wanted.Profile directories in the tests are created under MATLAB's real preference directory, because
getPrefdirderives its path fromprefdir, which cannot be redirected from a running session. Names end with a uuid, so test processes that start at the same time do not share a profile, and teardown tolerates a missing directory so a test that fails early does not report a second, unrelated failure.Documentation
The class header and the
instancehelp both stated that user profiles were not supported yet. Theinstancehelp said so three lines above the paragraph describing the new name-value argument. Both now describe what the user name does.🤖 Generated with Claude Code