Part IV — Expert Production Engineering · Chapter 25 · Lesson 4 of 7 · 2 min read
Lesson 4: Adding Standard-Library Capabilities Safely
Lesson level: Expert
Purpose: A capability extension is an authority change. Make permissions, resource bounds, and host-value boundaries explicit and test their enforcement.
Learning Objectives
- Specify an additive change and its compatibility contract.
- Trace implementation and authority impacts.
- Test both accepted behavior and rejection boundaries.
4.1 Concepts
A standard-library extension belongs in the registry, host implementation, permission model, type contract, tests, and documentation. Separate pure helpers from environment operations. The RC2 registry attaches permissions at module level; when any required permission is absent, _guard replaces callable members with a denial function. For std.file and std.csv, this means the declared file.read and file.write set gates the module as a whole. Do not describe this as per-operation least privilege without an adapted implementation.
4.2 Annotated Example
Illustrative contributor task: add a pure normalization helper to an appropriate existing namespace. It needs deterministic fixtures and no new authority. A network helper instead requires approved endpoint policy, bounded body size, timeout handling, and a permission contract. Annotation: declaring a permission string in a registry does not by itself restrict destinations or enforce a response-size limit.
4.3 Guided Practice
Compare a pure string helper with a file reader. Locate where required permissions are checked and identify the minimum data and authority each operation needs.
4.4 Common Mistakes
Do not expose raw host objects, hide environment access in a pure-looking helper, assume module guards enforce path/origin policy, or use permissive defaults merely to simplify tests.
4.5 Hands-On Lab
- Document inputs, outputs, errors, resource costs, and authority for the proposed helper.
- Add registry and implementation changes in a disposable checkout.
- Test normal behavior, denied authority, malformed inputs, and exceeded bounds.
- Verify the stdlib manifest, public API, and host contract remain accurate.
Deliverable: Proposed contract, disposable implementation, compatibility fixtures, and permission-denial evidence.
4.6 Review Questions
Where are registry permissions enforced? Why can module-level gating require more authority than one operation needs? What must the host add for path and endpoint policy?
4.7 Applied Challenge
Propose finer-grained guarded wrappers without widening the existing public namespace. Include denial-first migration and compatibility tests.
Lesson Summary
A capability extension is an authority change. Make permissions, resource bounds, and host-value boundaries explicit and test their enforcement.
Lesson status: Draft complete; ready for review.