Repository navigation
feat(whoami): add whoami - #273
Conversation
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. whoami behaves the way the PR says, both WASM command lists are updated, and I found nothing blocking. The notes below are optional.
- ⚪
"lash"is now hard-coded in two places, and #288 adds a third.whoami.rs:7hasconst DEFAULT_USER: &str = "lash";, the same literal is atvfs_kernel.rs:291(env.insert("USER".into(), "lash".into())), andid.rs:11in #288 copies the constant again. Apub const LASH_USERnext toLASH_UIDinsrc/vfs.rs:14would keep them in sync. This is cleanup, not a bug. - ⚪ Tests: the empty-
USERbranch has no test (expect!(whoami_empty_user, "USER= whoami", "lash")). The two error tests only check that stderr containswhoami, and thestrands-shell: whoami:prefix always does.
What I verified
- Head
63309f2. CI is green on every target. Locally,cargo test --test shell_integration whoamipassed 7/7 andcargo test --workspace --all-targetspassed 2577 with 0 failures. Clippy shows nothing new inwhoami.rs. I didn't runcargo fmt(rustfmt isn't installed here) or a WASM build. - Behaviour through the CLI:
whoami→lash;USER= whoami→lash;unset USER; whoami→lash.export USER=bob; whoami→bob;Shell::builder().env("USER", …)is respected;/bin/whoamiworks;whoami --→lash.whoami x→unexpected argument "x"(exit 1), the same asenv x.whoami -x→invalid option '-x'(exit 1).
--help/--version: GNUwhoamiaccepts both. Here--versionis rejected (exit 1), which is consistent with the rest of the repo: no command implements--version(basename --versionexits 1,pwd --versionexits 2, andtrue --versionexits 0 only becausetrueignores its arguments).-his rejected, which matches GNU and the 17 other commands that only take--help(basename,cp,mv, …). About 15 commands do accept-h, so the repo is split, and this PR doesn't make that worse.- It never reads the host user. The env comes only from
VfsKernel::new_process(vfs_kernel.rs:285-293), and nothing readsstd::env. - Command lists: native builds register commands through
inventory, so they need no change. The WASM lookup (mod.rs:109) and the WASM/binlist (vfs.rs:831) are both updated. The README count 33→34 matches the WASM lookup.
Appendix (non-blocking)
- Pre-existing, not from this PR: the WASM
/binlist (vfs.rs:829-832) is missingcurlandsleep, even though both are in the WASM lookup. That's a one-line fix if someone touches that list. I didn't file an issue for it. - The command reference on strandsagents.com lives in a different repo and may need a
whoamientry.
|
Thanks. Pushed 87f1e67: there is now a test for an empty On the shared The missing |
# Conflicts: # README.md # src/vfs.rs
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Still approve, now at 66d0485. Since my last review the only changes are the test commit and the merge of main; whoami.rs is byte-identical. No new findings. CI on the merge commit was still running when I posted, with no failures so far.
Previous notes:
- Tests: fixed in
87f1e67.whoami_empty_useris a real check: when I removed the!user.is_empty()guard locally, that test failed and the other 7 passed. The two error tests now match the actual message. - Shared
"lash"constant: still open, by agreement. #288 has merged, so the literal is now in three places (vfs_kernel.rs:282,id.rs:11,whoami.rs:7). Your follow-up plan is fine and doesn't block this.
What I verified
- Merge resolution (
66d0485, base1e0dbfb): the WASM lookup inmod.rs:115and the WASM/binlist invfs.rs:848both carrywhoaminext to the newly mergedbase64,idanduname. The README count 36→37 matches the 37 entries in the WASM lookup. - Tests:
cargo test --workspace --all-targetspassed 2687 with 0 failures; the 8whoamitests pass.cargo fmt --checkis clean and clippy reports nothing inwhoami.rs. I didn't run a WASM build or the Python and Node suites. - Behaviour through the CLI:
whoami,USER= whoamiandunset USER; whoami→lash;USER=agent whoami→agent, and the nextwhoamiis back tolash.whoamiand the mergedid -unagree for the default, a setUSERand an unsetUSER.which whoami,command -v whoamiand/bin/whoamiall resolve.whoami x,whoami -x,whoami -handwhoami --versionexit 1 with a message on stderr;whoami >&-exits 1.
Appendix (non-blocking)
Description
There's no
whoami, so an agent that checks who it's running as gets command not found.This adds
whoami. It prints the shell's own user, which is$USER(lashby default, or whatever the embedder sets), and falls back tolashifUSERis unset or empty. It never looks at the real host's user. It takes no arguments, and an extra operand or unknown option is an error, like GNU. I also added it to the WASM command list and bumped the command count in the README.Related Issues
Part of #207
Documentation PR
Type of Change
New feature
Testing
I compared the output and the error cases with GNU
whoami. The new tests cover the default user, a user set in the shell or by the embedder, an unsetUSER, help, and the error cases. The full Rust suite passes and clippy has the same warnings as main. I didn't run the Python or Node suites because the bindings are unchanged. This is one of four small PRs addingwhoami,hostname,uname, andid; each stands on its own, but they touch the same command lists, so whichever lands later will need a trivial rebase.cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.