feat: discover shell login options from /etc/shells#97
Conversation
- Introduce `ShellsFile` package variable in `session/discovery.go`. - Add `discoverShellSessions()` to parse `/etc/shells` and extract executables. - Append extracted shells to the session menu as Type 'C' (Console). - Update unit tests and mock `ShellsFile` to cover the new functionality. Co-authored-by: arran4 <111667+arran4@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request introduces shell session discovery by reading the /etc/shells file, allowing console logins to be listed as available sessions. The implementation includes a new discoverShellSessions method in the session package and updates to the test suite to mock and verify this behavior. Feedback was provided regarding the need to check for errors after the bufio.Scanner loop to ensure that no I/O issues occurred during the file reading process.
| for scanner.Scan() { | ||
| line := strings.TrimSpace(scanner.Text()) | ||
| if line == "" || strings.HasPrefix(line, "#") { | ||
| continue | ||
| } | ||
|
|
||
| if _, err := d.ExecLookPath(line); err == nil { | ||
| name := filepath.Base(line) + " shell" | ||
| sessions = append(sessions, Session{ | ||
| Name: name, | ||
| Exec: line, | ||
| Type: "C", | ||
| Path: ShellsFile, | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
The bufio.Scanner loop finishes without checking for errors. It is a best practice to check scanner.Err() after the loop to ensure that the file was read completely and no I/O errors occurred during scanning.
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if line == "" || strings.HasPrefix(line, "#") {
continue
}
if _, err := d.ExecLookPath(line); err == nil {
name := filepath.Base(line) + " shell"
sessions = append(sessions, Session{
Name: name,
Exec: line,
Type: "C",
Path: ShellsFile,
})
}
}
if err := scanner.Err(); err != nil {
return nil, err
}There was a problem hiding this comment.
The
bufio.Scannerloop finishes without checking for errors. It is a best practice to checkscanner.Err()after the loop to ensure that the file was read completely and no I/O errors occurred during scanning.for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) if line == "" || strings.HasPrefix(line, "#") { continue } if _, err := d.ExecLookPath(line); err == nil { name := filepath.Base(line) + " shell" sessions = append(sessions, Session{ Name: name, Exec: line, Type: "C", Path: ShellsFile, }) } } if err := scanner.Err(); err != nil { return nil, err }
There was a problem hiding this comment.
Good point. I've added the error check using scanner.Err() after the bufio.Scanner loop in discoverShellSessions to catch any I/O errors that might occur during the file reading.
|
@jules test failures please run and fix all tests: |
I have fixed the failing test |
|
This PR introduces the feature to parse
/etc/shellsand present them as shell login options with Type 'C' (Console). It dynamically maps and validates the executables from the file, providing users with traditional shell fallback choices.PR created automatically by Jules for task 12346225625501892072 started by @arran4