Skip to content

Enforce builtin command structure and import allowlist#11

Merged
thieman merged 2 commits intomainfrom
thieman/builtins-interface
Mar 9, 2026
Merged

Enforce builtin command structure and import allowlist#11
thieman merged 2 commits intomainfrom
thieman/builtins-interface

Conversation

@thieman
Copy link
Copy Markdown
Collaborator

@thieman thieman commented Mar 9, 2026

  • Introduced self-registration via init() and a Register() function, replacing the manually maintained central registry in builtins.go; each command implementation now owns its own registration

  • Moved all command implementations (cat, echo, exit, true/false, break/continue) from interp/builtins/ into a new interp/builtins/cmds/ package, keeping the framework (CallContext, Result, Register, Lookup) isolated in interp/builtins/

  • Changed CallContext.Stdin from *os.File to io.Reader to eliminate the dangerous *os.File method surface from command implementations; guarded the assignment in runner_exec.go to avoid typed-nil interface issues

  • Added tests/import_allowlist_test.go with a symbol-level import allowlist for interp/builtins/cmds/; every package and pkg.Symbol used by a command implementation must be explicitly listed, including internal packages; reflect and unsafe are permanently banned

- Introduced self-registration via init() and a Register() function,
  replacing the manually maintained central registry in builtins.go;
  each command implementation now owns its own registration

- Moved all command implementations (cat, echo, exit, true/false,
  break/continue) from interp/builtins/ into a new interp/builtins/cmds/
  package, keeping the framework (CallContext, Result, Register, Lookup)
  isolated in interp/builtins/

- Changed CallContext.Stdin from *os.File to io.Reader to eliminate the
  dangerous *os.File method surface from command implementations; guarded
  the assignment in runner_exec.go to avoid typed-nil interface issues

- Added tests/import_allowlist_test.go with a symbol-level import
  allowlist for interp/builtins/cmds/; every package and pkg.Symbol
  used by a command implementation must be explicitly listed, including
  internal packages; reflect and unsafe are permanently banned

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thieman thieman marked this pull request as ready for review March 9, 2026 18:22
- Renamed Register → register (unexported); the Go compiler now enforces
  that only files within package builtins can call it, making the
  AST-based TestBuiltinRegisterOnlyFromCmds test redundant — removed it

- Moved command implementations back from interp/builtins/cmds/ into
  interp/builtins/ (same package), removing the need for the blank import
  in runner_exec.go and the internal-package allowlist entries

- Restored the builtins.go exclusion in TestBuiltinImportAllowlist; this
  is safe because Go's per-file import system ensures that imports in
  builtins.go do not bleed into command implementation files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thieman thieman merged commit b17eb9e into main Mar 9, 2026
8 checks passed
@thieman thieman deleted the thieman/builtins-interface branch March 9, 2026 18:47
This was referenced Mar 12, 2026
@matt-dz matt-dz mentioned this pull request Mar 12, 2026
4 tasks
@AlexandreYang AlexandreYang mentioned this pull request Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants