Repository navigation
feat(hostname): add hostname - #277
ferdingler wants to merge 3 commits into
Conversation
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. I found no defects. hostname matches the other commands, the localhost default is what users actually get, and the tests check real behaviour.
🟡 Watch the merge order: #273 and #286 make the same 33 → 34 edit at README.md:118 and README.md:252. Identical edits merge without a conflict. I tried it: merging this PR and then #273 conflicts only in src/vfs.rs, and the README stays at 34 while mod.rs has 35 commands. Whichever of these PRs lands second needs to bump the count by hand.
@ferdingler, two non-blocking questions:
hostname -sandhostname -fshow up a lot in scripts, and right now they fail withinvalid option. In a sandbox that has no domain, both could just print the name. Is rejecting them a deliberate choice?- The help text doesn't mention
$HOSTNAMEor thelocalhostfallback, so an agent reading--helpcan't tell how the name is set. Could you add a line?
What I verified (head 5cd7643)
cargo test --test shell_integration hostname: 7/7 pass.cargo fmt --checkis clean, andcargo clippy --all-targetshas no warnings in the changed lines.- Built CLI:
hostname→localhost.HOSTNAME=box hostname→box.hostname newname→hostname: unexpected argument "newname"with exit 1.hostname -sand-f→invalid option, exit 1.-hprints the usage./bin/hostnameexists. VfsKernel::new_process(src/vfs_kernel.rs:286-291) sets only HOME, PWD, PATH and USER, and nothing setsHOSTNAME. So the default is reachable, and the code never looks at the real host name.hostname.rsfollowspwd.rsline for line: same lexopt parsing,-h/--help, andarg.unexpected().- Native
/binlinks and the command lists come from the registry. Only the WASM list insrc/vfs.rsis maintained by hand, and the PR updates it. - #286
uname -nuses the same$HOSTNAME-or-localhostrule. It copiesDEFAULT_HOSTNAMErather than sharing it, so whichever PR lands second could import the other's constant to keep them from drifting. - #285 (only exported variables reach commands) keeps builder env and
VAR=x cmdprefixes exported, so the tests still hold after it merges.
Passes run: correctness/tests (fresh reviewer). I skipped the API bar-raiser and adversarial passes: there's no library API change and the parsing is trivial.
|
Thanks. Pushed 0ca9f3a:
On merge order: agreed. Whichever of #273, #277, #286, #288 lands later will get rebased, with the README count bumped to match and the WASM list conflict in |
# Conflicts: # README.md # src/commands/mod.rs # src/vfs.rs # tests/shell_integration.rs
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve at d2324a8, with one 🟡 that the merge with main brought in.
Points from my last review:
- README count: fixed. The README says 38 and
src/commands/mod.rshas 38 commands. - Help text: fixed in
0ca9f3a. -s/-f: left out on purpose, which is fine as a follow-up.- Duplicated
DEFAULT_HOSTNAME: replaced by the inline finding below.
🟡 src/commands/hostname.rs:22: since #331, uname -n falls back to the kernel's node name, but hostname still falls back to the constant localhost. Under a kernel that overrides Kernel::uname, uname -n; hostname prints studio then localhost. The standalone shell is unaffected. The fix is two lines and is inline; neither command is released yet, so it's cheap to line them up now.
CI on this head was still running when I posted (several Rust and Node jobs queued).
What I verified (head d2324a8, base c28e1fb)
Linux aarch64, cargo 1.100.0.
cargo test --workspace --all-targets: 2697 passed, 0 failed, 0 ignored across 20 test binaries.cargo fmt --checkis clean.cargo clippy --workspace --all-targetsexits 0 with no warnings inhostname.rs.- Merge resolution:
README.md:118and:252say 38, matching the 38 arms inlookup. The WASM list insrc/vfs.rshashostnamenext toid,unameandwhoami; it lacks onlycurlandsleep, as on main. - Built CLI:
hostname→localhost;HOSTNAME=box hostname→box;HOSTNAME= hostname→localhost.export HOSTNAME=web1; hostname; sh -c hostname; uname -n→web1three times.hostname newname,hostname -- newname,hostname ''andhostname -seach exit 1 with the message the tests now check.--helpand-hprint the new$HOSTNAMEline./bin/hostnamelinks tolash, andx=$(hostname)andhostname > fileboth capture the name.
- The inline finding: reproduced with the
tests/custom_kernel.rskernel, then re-run with the suggested fix applied (studiofrom both commands; the 9hostname-named tests inshell_integrationstill pass).
Not run: pytest tests/python, npm test, a WASM build, anything on macOS or Windows.
Appendix (1)
hostname ""prints the name and exits 0 because the shell drops a literal""word before the command sees it. That is #299, not this PR.
| let host = io::with_process(|p| match p.get_env("HOSTNAME") { | ||
| Some(host) if !host.is_empty() => host.to_string(), | ||
| _ => DEFAULT_HOSTNAME.to_string(), | ||
| }); |
There was a problem hiding this comment.
hostname and uname -n print different names when the kernel reports its own node name
Since #331 (merged into this branch), uname -n falls back to Kernel::uname().node_name. hostname still falls back to the constant localhost. An embedder that overrides Kernel::uname and leaves $HOSTNAME unset (Box plans to, per #331) gets studio from uname -n and localhost from hostname. The standalone shell is unaffected, because its kernel's node name is localhost.
Suggestion: use the same fallback as uname. This also needs _os renamed to os on line 10, DEFAULT_HOSTNAME removed, and the help line reworded, since it names localhost.
| let host = io::with_process(|p| match p.get_env("HOSTNAME") { | |
| Some(host) if !host.is_empty() => host.to_string(), | |
| _ => DEFAULT_HOSTNAME.to_string(), | |
| }); | |
| let host = io::with_process(|p| match p.get_env("HOSTNAME") { | |
| Some(host) if !host.is_empty() => host.to_string(), | |
| _ => os.uname().node_name, | |
| }); |
Reproduction details
Reviewed and tested at d2324a8 (base c28e1fb), Linux aarch64, cargo 1.100.0.
Setup: a copy of tests/custom_kernel.rs saved as a scratch test file, with this test appended. Its MemKernel already overrides uname() with node_name: "studio" and does not set HOSTNAME.
#[test]
fn rev277_hostname_vs_uname_n_under_custom_kernel() {
let kernel = MemKernel::new();
let mut shell = shell_over(&kernel);
block_on(async {
let out = shell.run("echo \"[$HOSTNAME]\"; uname -n; hostname").await;
eprintln!("REV277 unset: {:?} status={}", out.stdout, out.status);
let out = shell.run("HOSTNAME=box uname -n; HOSTNAME=box hostname").await;
eprintln!("REV277 set: {:?} status={}", out.stdout, out.status);
});
}Command: cargo test --test zz_rev277_hostname rev277 -- --nocapture
$HOSTNAME unset |
HOSTNAME=box |
|
|---|---|---|
| Expected | [], studio, studio |
box, box |
Observed at d2324a8 |
[], studio, localhost |
box, box |
| Observed with the suggestion applied | [], studio, studio |
box, box |
Exit status was 0 in every run. With the suggestion applied, cargo test --test shell_integration hostname passed 9 of 9. I removed the scratch file and reverted the edit afterwards.
A regression test could add hostname to uname_describes_the_kernel_system in tests/custom_kernel.rs and assert studio. I did not run it in that form.
Description
There's no
hostname, so a script that prints or logs the machine name gets command not found.This adds
hostname. It prints the shell's own host name:$HOSTNAMEif the embedder or script sets it, otherwiselocalhost. It never looks at the real host's name. It only prints; it doesn't set the name and doesn't take the formatting flags, so any argument is an error. 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 checked the output and the help flag against the
hostnametool on Linux. The new tests cover the default name, a name set in the shell or by the embedder, an empty variable, help, and rejecting an attempt to set the name. 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.uname -nin its own PR uses the same rule for the name.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.