Skip to content

rust-cli-template: lock tests count waits instead of timing them; escape record text on stderr - #21

Open
orbit-agent-01 wants to merge 1 commit into
agent-mainfrom
orbit/ORB-26751-4b1f5bd1
Open

orbit-agent-01 wants to merge 1 commit into
agent-mainfrom
orbit/ORB-26751-4b1f5bd1

Conversation

@orbit-agent-01

Copy link
Copy Markdown
Contributor

Task

ORB-26751 — rust-cli-template: lock tests count waits instead of timing them; escape record text on stderr

Description

Problem

Two leftovers from the audit's defect fix (landed as c7d24df).

  1. Timing-bound lock tests. Two tests assert a wall-clock window around the 80 ms lock deadline, with elapsed < deadline * 2 (and elapsed >= deadline in the second). On a loaded runner that leaves about 80 ms of slack:

    • record_audit_succeeds_while_the_store_lock_is_held in crates/tmpl-cli-core/src/store/tests/store.rs;
    • the lock-timeout test in crates/tmpl-cli/src/commands/tests/note.rs.

    The same kind of check already failed once on hosted macOS before the review repair (GitHub Actions run 44999038272). The behaviour under test is that the failing command waits on the store lock once, not twice. Measure that by counting contended lock acquisitions (or waits) through a test seam, not with elapsed time. Keep the assertions that the timeout error comes back and that exactly one failure line is audited.

  2. Unescaped text on stderr. Bad-record warnings are written raw (crates/tmpl-cli/src/output/mod.rs, emit: warning: {warning}). NoteError::InvalidTag displays the tag as '{0}' (crates/tmpl-cli-core/src/note.rs). A hand-edited tag or title holding ESC therefore reaches the terminal raw, through a warning or an error message. That goes against the third defect's rule that control characters cannot reach the terminal raw. Escape control characters in any record-derived text written to stderr, with the same sanitiser the body output uses, or {:?}.

Nit, same change: #[allow(dead_code)] on decode_line in crates/tmpl-cli-core/src/store/audit.rs has no reason =.

Filed by the constellation captain ORB-26697 from the review of the earlier defect fix. No task ids in any file of this public repository.

Acceptance Criteria

  • No test under crates/ asserts an upper bound on elapsed wall-clock time around the lock deadline (grep -rn "deadline * 2" crates matches nothing), and a test asserts the failing audited command waits on the store lock exactly once and audits exactly one failure line.
  • A test stores a tag or title containing ESC (0x1b) by hand, runs note list and note add, and asserts stderr contains no byte below 0x20 other than newline and tab.
  • The allow on decode_line carries a reason, and make ci passes.

Execution Summary

Click to expand

Completed all three items:

  1. Lock-wait counting instead of wall-clock timing:
  • Added LockGuard::acquire_observing in crates/tmpl-cli-core/src/store/fsio.rs (invoking on_contended once on the first WouldBlock, with LockGuard::acquire delegating to it).
  • Added an internal Arc<AtomicUsize> counter and Store::contended_lock_waits(&self) -> usize in crates/tmpl-cli-core/src/store/mod.rs, wired into Store::lock and Store::audit_lock.
  • Replaced Instant::now() / elapsed < deadline * 2 wall-clock assertions in crates/tmpl-cli-core/src/store/tests/store.rs#record_audit_succeeds_while_the_store_lock_is_held and crates/tmpl-cli/src/commands/tests/note.rs#lock_timeout_audited_command_waits_one_deadline_and_records_one_failure_line with contended_lock_waits() == 1 assertions, keeping the store_locked and single-failure-audit-line checks. Verified grep -rn "deadline \* 2" crates matches nothing (exit 1).
  1. Escaping control characters on stderr:
  • Changed NoteError::{InvalidId, InvalidTag, InvalidPriority} in crates/tmpl-cli-core/src/note.rs to format values with {0:?}.
  • Made render::sanitize_for_display pub(super) in crates/tmpl-cli/src/output/render.rs and applied it in crates/tmpl-cli/src/output/mod.rs (emit warnings/notices, report_error human errors, finish_parse_error human usage errors).
  • Added regression integration test bad_record_control_characters_are_escaped_on_stderr in crates/tmpl-cli/tests/cli.rs (seen failing on unfixed code with raw ESC 0x1b on stderr, passing after fix).
  1. decode_line attribute:
  • Verified crates/tmpl-cli-core/src/store/audit.rs#decode_line already carries #[cfg_attr(not(test), expect(dead_code, reason = "template mechanism for an audit reader"))] (landed in b3d2772).

Validation:

  • cargo test -p tmpl-cli --locked --test cli bad_record_control_characters_are_escaped_on_stderr (before fix): failed as expected (left: Some(27) on stderr).
  • cargo fmt --all && make ci: passed (exit 0: fmt-check, structure, standards-check, docs-check, clippy -D warnings, cargo deny check, cargo nextest run --workspace --all-targets --locked --no-tests=fail, cargo test --workspace --doc --locked 1 passed, make goldens).
  • grep -rn "deadline \* 2" crates: no matches (exit 1).
  • cargo test --workspace --all-targets --locked: passed (42 tmpl-cli lib tests, 32 cli integration tests, 45 tmpl-cli-core lib tests, 13 store integration tests, plus scripts/goldens/rename_template binaries).
  • Reconciliation: 8 modified tracked files (crates/tmpl-cli-core/src/note.rs, crates/tmpl-cli-core/src/store/fsio.rs, crates/tmpl-cli-core/src/store/mod.rs, crates/tmpl-cli-core/src/store/tests/store.rs, crates/tmpl-cli/src/commands/tests/note.rs, crates/tmpl-cli/src/output/mod.rs, crates/tmpl-cli/src/output/render.rs, crates/tmpl-cli/tests/cli.rs), all within task scope; git diff --check clean; no untracked leftovers.

Validation

  • Not reported

Branch Freshness

  • Base ref: refs/remotes/origin/agent-main
  • Head ref: orbit/ORB-26751-4b1f5bd1
  • Behind base: 0
  • Ahead of base: 1

Orchestrated-By: opus

rust-cli-template: lock tests count waits instead of timing them; escape record text on stderr

Completed all three items:

Orbit-Task: ORB-26751
Orchestrated-By: Orchestrated-By: opus
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.

1 participant