feat(builtins): implement uptime builtin#562
Draft
san-jos wants to merge 5 commits into
Draft
Conversation
Adds the uptime builtin command with cross-platform support (Linux, macOS, Windows). Outputs current time, system uptime duration, and load averages (1/5/15 min). User count is intentionally omitted to avoid reading utmp session data. Flags: -p/--pretty (human-readable duration), -s/--since (boot time as YYYY-MM-DD HH:MM:SS), -h/--help. Data sources bypass AllowedPaths (fixed kernel paths, same precedent as ss, ip route, df): /proc/uptime + /proc/loadavg on Linux; sysctl kern.boottime + vm.loadavg on Darwin; GetTickCount64 on Windows. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Windows 32-bit: combine lo/hi uintptr from GetTickCount64.Call() into a uint64 to avoid the ~49.7-day rollover on windows/386 where the return value is split across the low and high words - macOS reliability: remove four happy-path scenario tests that call sysinfo.Get() directly and fail with EPERM in restricted environments; replace with deterministic unit tests for formatDuration, formatPretty, and formatDefault in builtins/uptime/uptime_test.go (pure functions, no OS calls) - README: add uptime to the AllowedPaths bypass note alongside ss, ip route, and df Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Remove unused fmt import (sysinfo_windows.go no longer calls fmt.Errorf).
Split the tick-count extraction into build-tagged helpers to fix 64-bit
corruption: on amd64/arm64 Proc.Call's second return (hi) is the XMM0
floating-point register, not guaranteed zero, so combining lo|hi<<32
would corrupt the result. The split:
sysinfo_windows_386.go (implicit GOOS=windows GOARCH=386):
ticksToMs combines lo and hi to reconstruct the full ULONGLONG from
the Win32 32-bit calling convention (EDX:EAX pair).
sysinfo_windows_64bit.go (build: windows && !386):
ticksToMs returns lo only; hi is XMM0 and must be ignored.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Add New(getInfo) constructor to uptime.go so tests can inject a deterministic sysinfo.Info without OS syscalls. builtins/tests/uptime/uptime_test.go covers the six handler-level behaviors not exercised by the existing unit tests or scenario tests: - default output wired end-to-end (provider -> formatDefault -> stdout) - -p routes to formatPretty - -s formats BootTime via time.Unix(...).Local() - -p takes precedence over -s when both flags are set - generic provider error -> stderr message, exit 1 - ErrNotSupported -> platform-specific message, exit 1 Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
san-jos
force-pushed
the
feat/uptime-builtin
branch
from
July 22, 2026 10:14
253947f to
c966c1a
Compare
Replace with neutral phrasing to avoid any licensing ambiguity. Co-Authored-By: Claude Sonnet 4.6 (1M context) <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.
Summary
Data sources
All bypass `AllowedPaths` (fixed kernel paths — same precedent as `ss`, `ip route`, `df`):
Windows 32-bit (386): `GetTickCount64` returns a 64-bit ULONGLONG split across lo (EAX) and hi (EDX) — combined in `sysinfo_windows_386.go`. On 64-bit targets hi is XMM0 (unspecified) and is ignored in `sysinfo_windows_64bit.go`.
Test plan
🤖 Generated with Claude Code