Repository navigation
rust-cli-template: fix the audit's seven defects and nine weak spots - #19
Merged
Merged
Conversation
rust-cli-template: fix the audit's seven defects and nine weak spots Fixed all 7 defects and all 9 weak spots from the audit at base commit `b75b6a1`. Orbit-Task: ORB-26727 Orchestrated-By: Orchestrated-By: opus
Candidate b76845a (tree 2b186cd) against base b75b6a1 (ancestor of HEAD; required_validation_commands is an empty list). I checked all 16 items and their acceptance criteria against the diff, the callers, and the tests. Two concrete defects were repaired in the worktree, uncommitted: F1, Title::try_from ran the control-character check on the untrimmed value, so a trailing newline or tab that the base trimmed and accepted was refused; it now checks the trimmed value, and the title test asserts both trailing cases (failed with the fix reverted, passes with it). F2, docs/design/tmpl-cli/4_decisions.md named `run` as the chokepoint; it now says `run_with`. Checks on the repaired tree: make ci-fast passed; make clippy passed; make goldens passed (2/2); the scripts tests passed (3/3); the full workspace suite passed as a diagnostic (129/129 nextest, 1/1 doctest). make deny was refused by the sandbox: the advisory-db lock sits on a read-only path, and this cargo-deny build has no --db-path flag, so the advisories check did not run; licenses, bans and sources pass. I did not work around the refusal. Items 1 to 16 are implemented as the execution summary describes; I traced the audit-lock split, the JSON error ordering, the bad-record policy, the duplicate and exhausted ids, the actor contract, the holder liveness check, the help defaults and the three script fixes. I did not re-run the pre-fix red runs for every item; only the title test I added was checked red. Repaired findings: F1, F2. Changed paths: crates/tmpl-cli-core/src/note.rs, crates/tmpl-cli-core/src/tests/note.rs, docs/design/tmpl-cli/4_decisions.md. Orbit-Task: ORB-26727 Orbit-Review-Attempt: rvw-49a20ff28968-1 Orbit-Review-Crew: haiku
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.
Task
ORB-26727 — rust-cli-template: fix the audit's seven defects and nine weak spots
Description
Filed by const-0-capt (ORB-26697) from the scope amendment afb2915 (Shape 5, "Fix what the audit found"; Daniel approved the audit's findings 2026-11-21). Design: docs/design/rust-cli-template/1_scope.md in the constellation umbrella. This is the first task of the audit: every copy made before it lands inherits these. It depends on no phase. Paths below are at b75b6a1 and under crates/tmpl-cli-core/ or crates/tmpl-cli/ unless they start with scripts/.
Rule for every item: reproduce the defect with a failing test (or, for the scripts, a failing run against a scratch fixture) first, commit that as the first step, then fix. The chief confirmed defects 2 to 7 in the source; items 1 and the weak spots are the reviewers' reports, most reproduced in a scratch copy, so re-check each against the code before fixing and say in the execution summary which ones did not reproduce.
Problem
Defects:
find -depthwith the prune list, and -depth disables -prune, so the rename walks into .git/, target/ and docs/standards/. A branch named with the placeholder is renamed.note list. The body path lets a carriage return through (tmpl-cli/src/output/render.rs:81-91 only indents after '\n').nextsaturates); store/format.rs decode does not check ids for uniqueness on load.mod tests;, so a whole test directory can stop running with the gate green.std::fsbut not the grouped importuse std::{fmt, fs}.Weak spots (same task unless one grows; if one grows, split it out and say so):
8. Title and Tag validate inside serde (tmpl-cli-core/src/note.rs:128-130 and 211-213, try_from = "String"), so one hand-edited title or tag makes the whole store unreadable.
9. A serialization failure is reported as an I/O error naming a path never touched (store/format.rs:91, store/mod.rs:135).
10. Table widths count characters, not display columns (tmpl-cli/src/output/table.rs:71-73, char_len).
11. A stored note missing a field is read with a default and the next write persists it (note.rs:313-320, serde(default) on body, tags, priority).
Bad-record policy (items 8 and 11 share it). A bad record is a note whose title or tag fails validation, or which lacks a required field. Decoding the store yields the valid notes plus one typed error per bad record, naming its id (or its line, when the id itself is unreadable) and the reason; nothing is defaulted or dropped silently. Read commands (
note list,note showof a good id) succeed with the valid notes and write one warning per bad record to stderr. That holds under--jsontoo: stdout keeps the documented payload, and the laterwarningsenvelope field (Shape 4) moves these warnings into it.note showof a bad id fails with that record's typed error. Every write command refuses while the store holds a bad record, with a typed error naming it and the data-error exit code, so a rewrite can never drop or default it. The file is never modified on read.12. The audit record names no actor (tmpl-cli-core/src/store/audit.rs:36-53; STD-08 R11).
Actor contract:
AuditEventgainsactor: Option<String>, the OS user name.AppEnv(crates/tmpl-cli/src/app.rs) reads it once, fromUSER, elseUSERNAME, besideHOME, so tests inject it. The audit guard records it. It serializes as"actor": "<name>", ornullwhen neither variable is set. No sentinel string. A line written before this change has noactorfield and reads asnull: the field is optional by contract, so item 11's refusal of missing required fields does not apply to it. Bump the audit line format, add the UPGRADES step, and list the field in docs/design/tmpl-cli/specs/store.md and in the audit section of docs/design/tmpl-cli/2_design.md.13. A lock timeout can name a process that has already finished as the holder (tmpl-cli-core/src/store/fsio.rs:235-253, record_holder/read_holder).
14.
note add --tagand--jsonstate no default in help (tmpl-cli/src/commands/note.rs:70 and tmpl-cli/src/cli.rs:54; STD-01 R22).15. DEFAULT_LOCK_WAIT and AUDIT_FILE are re-exported and unused (tmpl-cli-core/src/lib.rs:31).
16. The doc comment at tmpl-cli-core/src/store/mod.rs:19-20 says a load refuses any state that is not owner-only; fsio.rs:157-158 refuses only group- or world-writable state.
Owned work
mod tests;. Item 6: the gate catches grouped imports. Item 7: help goldens are generated from every_command(), and a command without a golden fails the test.Left out
warningsenvelope field and an audit-log reader are Shape 4 additions, not here: item 8 reports the bad record in the error, nothing more.Acceptance Criteria
make cipasses.note listandnote showoutput piped to a file contains no byte below 0x20 other than newline and tab, including for a body containing a carriage return.mod tests;exits non-zero and names the directory; on this repository it exits 0.use std::{fmt, fs};exits non-zero; on this repository it exits 0.cargo test -p tmpl-cli --test goldensfail.note listexits 0, lists only the good note, and writes one stderr warning per bad record naming its id and reason (also with --json, whose stdout stays the documented payload);note show <bad id>fails with a typed error naming the record;note addrefuses with a typed error naming a bad record and the data-error exit code, and the store file is byte-identical afterwards; no code path writes a defaulted field."actor": "<that name>"; with USER and USERNAME both unset it carries"actor": null; an audit line from the previous format, which has no actor, still reads; the audit line format version is bumped with an UPGRADES step, and a test shows an old line upgrades.tmpl-cli note add --helpandtmpl-cli --helpshow the default for --tag and --json, and the help goldens match.cargo buildandcargo clippy --workspace --all-targets -- -D warningspass with DEFAULT_LOCK_WAIT and AUDIT_FILE no longer re-exported from lib.rs.grep -n 'not owner-only' crates/tmpl-cli-core/src/store/mod.rsmatches nothing contradicting fsio.rs's check, and the comment states the check the code makes.Execution Summary
Click to expand
Summary
Fixed all 7 defects and all 9 weak spots from the audit at base commit
b75b6a1.Reproduction at base commit (
b75b6a1)All 16 items reproduced at
b75b6a1(none failed to reproduce). Before implementing the fixes, failing tests for defects 1–6 (and items 9, 10, 13) were added and run (cargo nextest run --workspace --all-targets --locked --no-fail-fast, captured in.orbit/tmp/repro-failures.txt): 12 tests failed as expected before fixes and all pass after. For defect 7, after migratingtests/goldens.rsto iterateevery_command(), adding a temporaryScratchsubcommand without a golden file causedcargo test -p tmpl-cli --test goldens --lockedto fail (exit 101, reportingmissing golden help/note-scratch.txt), after which the scratch variant was reverted.Acceptance criteria mapping
make ci): Defects 1–7 were reproduced failing before fixes and pass after. Deviation on commit structure: Orbit's Handoff procedure requires leaving all changes uncommitted so the delivery pipeline creates the commit; failing-before-fix evidence was captured in.orbit/tmp/repro-failures.txtrather than a separate git commit.Store::record_auditnow acquires its own.audit.lock(separate from.lock), andcommands::run_withdropsAuditGuardafteroutput::finishflushes stdout/stderr. Verified byrecord_audit_succeeds_while_the_store_lock_is_held,lock_timeout_audited_command_waits_one_deadline_and_records_one_failure_line, andjson_error_object_precedes_audit_failure_warning_on_stderr.-depthfromfindinscripts/rename-template.shso-pruneprotects.git/,target/, anddocs/standards/, sorting matches deepest-first viaperl. Verified byrename_template_leaves_git_target_and_standards_untouched.Title::try_fromrejects all Unicode control characters (char::is_control) withNoteError::TitleNotSingleLine;output::render::note_detailnormalizes CRLF and escapes control characters other than\nand\t. Verified bytitle_is_trimmed_and_must_be_one_non_empty_line,detail_view_sanitizes_body_control_characters_and_normalizes_crlf, andtitle_rejects_control_characters_and_piped_output_strips_body_control_bytes.NoteId::next_afteruses checked addition and returnsNoneatu64::MAX, mapped toError::IdExhausted(note_id_exhausted);store/format.rs::decoderejects duplicate note ids withError::DuplicateId(store_duplicate_id). Verified byduplicate_note_ids_fail_to_load_with_a_stable_codeandadd_refuses_when_max_id_is_already_in_use.scripts/check-test-modules.shverifies everysrc/**/tests/directory is declared (mod tests;) by its parent module (lib.rs/main.rsormod.rs/<parent>.rs), naming the directory on failure. Verified bycheck_test_modules_fails_when_parent_lacks_mod_testsand exit 0 on this repo.scripts/check-dependency-direction.shaddsban_import(awk) detecting single- and multi-line groupeduseimports (use std::{fmt, fs};,use crate::{...};,use super::{...};). Verified bycheck_dependency_direction_catches_grouped_std_fs_importand exit 0 on this repo.crates/tmpl-cli/src/lib.rsexportingevery_command()(shared withsrc/tests/cli.rs) and migratedtests/goldens.rsto iteratetmpl_cli::every_command(), failing on missing goldens. Verified bymake goldensand the scratch-subcommand failure check.Deserialize/try_from = "String"fromTitleandTagand#[serde(default)]fromNote.store/format.rs::decodevalidates every required field per record at construction boundaries, isolating bad records asBadRecord(RecordLocator::Idor 1-basedRecordLocator::Line+BadRecordReason).Store::listandStore::showreturnLoaded<T>carryingbad_records; read commands exit 0 with valid notes and 1 stderr warning per bad record (preserving--jsonstdout payload);note show <bad id>fails exit 1 withstore_bad_record;note addrefuses exit 1 withstore_bad_recordleavingnotes.jsonbyte-identical. Verified bybad_records_are_isolated_with_id_or_line_and_reason,bad_records_are_isolated_on_read_fail_on_show_and_refuse_writes, andbad_records_warn_on_reads_fail_on_show_and_refuse_writes_without_touching_store.Error::Encode(encode_error) with no invented path for bothstore/format.rs::encodeandstore/audit.rs::encode_line. Verified byencode_failure_is_not_io_and_names_no_pathandrecord_audit_encode_failure_is_not_io_and_names_no_path.display_width/char_widthcovering East Asian Wide/Fullwidth and zero-width combining/control characters) inoutput/table.rsfor column sizing, padding, and truncation. Verified bycjk_cells_align_by_display_width.actor: Option<String>toAuditEvent, bumpedAUDIT_FORMATto 2 with append-onlyUPGRADES(upgrade_v1_to_v2) anddecode_lineinstore/audit.rs, capturedUSERelseUSERNAMEinAppEnv/Context, passed intoAuditGuard, and documented inspecs/store.mdand2_design.md. Verified byactor_prefers_user_then_username_then_none,a_format_one_audit_line_without_actor_upgrades_to_null_actor,the_audit_format_is_one_more_than_the_number_of_upgrade_steps, andaudit_line_records_actor_from_user_or_username_else_null.store/fsio.rs::read_holderparses the recorded PID and checks liveness on Unix viarustix::process::test_kill_process, reporting"an unknown process"when dead. Verified bya_lock_timeout_does_not_report_a_finished_pid_as_holder.[default: none]tonote add --tagand[default: false]to--json, updatedevery_command_and_flag_has_help_textto enforce flag defaults, and regenerated all 5 help goldens. Verified byhelp_states_defaults_for_tag_and_jsonandmake goldens.DEFAULT_LOCK_WAITandAUDIT_FILEfromtmpl-cli-core/src/lib.rsre-exports and narrowed their visibility insidestore. Verified bycargo build --workspace --lockedandmake clippy.crates/tmpl-cli-core/src/store/mod.rsdoc comment to accurately state STD-05 R8 (0700/0600on creation) and R9 (load refuses symlinks, foreign owners, or group-/world-writable modes matchingfsio.rs). Verified by! grep -n 'not owner-only' crates/tmpl-cli-core/src/store/mod.rs.Validation commands & outcomes
make ci-fast(cargo fmt --all -- --check,check-dependency-direction.sh,check-test-modules.sh,check-terminal-guard.sh,docs/standards/check.sh): passedmake clippy(cargo clippy --workspace --all-targets --locked -- -D warnings): passedcargo deny check licenses bans sources: passed (bans ok, licenses ok, sources ok;Cargo.lockunchanged)make deny(cargo deny checkincluding advisories): failed (sandbox read-only path) —failed to obtain lock file '~/.cargo/advisory-dbs/db.lock': attempted to take an exclusive lock on a read-only path. No dependencies orCargo.lockwere modified; pipeline final validation runs outside the sandbox.make test(cargo nextest run --workspace --all-targets --locked --no-tests=fail+cargo test --workspace --doc --locked): passed (129/129 tests passed, 0 skipped; 1/1 doctest passed)make goldens: passed (2/2 golden test suites passed after regenerating help goldens withmake goldens UPDATE=1)cargo build --workspace --locked: passedgit diff --check: passed (no whitespace errors; no newORB-IDs in diff)Reconciliation & scope
HEAD = b75b6a102b6e12357ad0c4031be08c6e99bcbe65, cleangit status --short.crates/tmpl-cli/src/lib.rs,crates/tmpl-cli/tests/scripts.rs), all uncommitted for pipeline delivery.context_filesselectors (necessary companions):crates/tmpl-cli/Cargo.toml,crates/tmpl-cli/src/lib.rs,crates/tmpl-cli/src/main.rs(exposeevery_command()totests/goldens.rsfor Item 7);crates/tmpl-cli/src/output/mod.rs,crates/tmpl-cli/src/output/payload.rs(stderr bad-record warnings onOutputfor Items 8 & 11);crates/tmpl-cli/tests/support/mod.rs(complete note fixtures without removed defaults for Item 11);crates/tmpl-cli/tests/scripts.rs(regression tests for Items 2, 5, 6)..orbit/tmp/; zero unintended leftovers.Validation
Branch Freshness
refs/remotes/origin/agent-mainorbit/ORB-26727-6c5a7adeOrchestrated-By: opus