From de458ef3dbe3a38f46fed0683fa3c0e35f363505 Mon Sep 17 00:00:00 2001 From: dmitrii-f-t27 Date: Thu, 15 Oct 2026 11:23:49 -0300 Subject: [PATCH] spec(port): port specs/port/trios/crates/trios-cli/src/cmd/race.t27 (Closes #9489) Port gHashTag/trios:crates/trios-cli/src/cmd/race.rs (at 8b229e9489ee, 279 lines) as specs/port/trios/crates/trios-cli/src/cmd/race.t27 - Roadmap Stage 6, goal #4548, target t27c gen-rust. The decisions the command makes are ported as pure functions and tested (12 tests, 12 pass, 0 vacuous, 40 runtime asserts): the default RaceConfig (Neon fallback URL, igla-race study, reduction factor 3, rung bounds 3/27, target BPB 1.50 - including the original's own test), the schema shape (3 tables, 2 views, names), the status limit default of 10 with the take() cap, the 25-char params truncation with its ellipsis edge, the missing-agent ??? fallback, the mock leaderboard rows and race statistics, the ASHA step ladder 1000/3000/9000, the IGLA FOUND threshold BPB < 1.50, the 3-decimal BPB display and the agent-line presence gate. The init/status/report_trial transports keep their names with undefined; bodies no test calls; Rust's Option decisions are carried by presence-flag helpers (the language has no unwrap). Verified: parse OK, spec-status IMPLEMENTED, typecheck 0 errors, coverage 21/24 (only the 3 transports untested, by design), test-report 12/12 pass, 0 BLOCKED, gen 215 lines with 0 'not yet implemented', boundary exactly this one file, dupe_scan: all 21 new helper names unique across 2039 specs. Dmitrii Fedorov ([@dmitrii-f-t27](https://github.com/dmitrii-f-t27)) --- .../trios/crates/trios-cli/src/cmd/race.t27 | 332 ++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 specs/port/trios/crates/trios-cli/src/cmd/race.t27 diff --git a/specs/port/trios/crates/trios-cli/src/cmd/race.t27 b/specs/port/trios/crates/trios-cli/src/cmd/race.t27 new file mode 100644 index 0000000000..9021375f7c --- /dev/null +++ b/specs/port/trios/crates/trios-cli/src/cmd/race.t27 @@ -0,0 +1,332 @@ +// trios-cli `race` command — IGLA RACE study init, leaderboard and trial +// reporting. +// Port of gHashTag/trios:crates/trios-cli/src/cmd/race.rs +// (at 8b229e9489ee, 279 lines) — Roadmap Stage 6, goal #4548, target t27c +// gen-rust. +// +// The original is a CLI command over the IGLA RACE Optuna study: `init` +// creates the study in Neon PostgreSQL and prints its SQL schema, `status` +// renders the live leaderboard with the ASHA rung ladder, and `report_trial` +// logs a trial result back to the race. The environment read, the SQL +// round-trips and the prints are plumbing; the decisions the file makes — +// the default configuration (with the Neon fallback URL, study name, +// reduction factor, rung bounds and target BPB), the schema's shape (three +// tables, two views, the trials table and the leaderboard view by name), the +// status limit default of 10 with the take() cap, the 25-character parameter +// truncation with its ellipsis, the missing-agent "???" fallback, the mock +// leaderboard rows, the race statistics, the ASHA step ladder 1000 → 3000 → +// 9000 and the IGLA FOUND threshold of BPB < 1.50 — are ported here as pure +// functions and tested. The transports keep their names with `undefined;` +// bodies that no test calls (issue #9489, "Port the decision, not the +// plumbing"). +// +// Rust's `Option` / `Option` have no unwrap construct here: +// the decisions that read them (`unwrap_or(10)`, the `???` fallback, the +// agent line's presence gate) are ported as verdict functions taking the +// presence flag, the shape this series' table gives argv and optional +// inputs. + +module port::trios_cli_cmd_race; + +// --------------------------------------------------------------------------- +// Original lines 12-27: `pub struct RaceConfig { ... }`. Only the facts the +// logic reads; the doc-comments on the fields are the original's, kept in +// the decisions below. +// --------------------------------------------------------------------------- + +pub struct RaceConfig { + neon_url: str, + study_name: str, + reduction_factor: usize, + min_rungs: usize, + max_rungs: usize, + target_bpb: f64, +} + +// --------------------------------------------------------------------------- +// Original lines 29-41: `impl Default for RaceConfig { fn default() -> Self }`. +// The configuration every caller gets when it builds none: the Neon URL +// falls back to the placeholder connection string when the environment +// carries none (the env read is plumbing; the fallback constant is the +// decision), the study is "igla-race", the ASHA reduction factor is 3, the +// rung bounds are 3 (1000 steps) and 27 (9000 steps, 3^3), and the target +// BPB threshold is 1.50. +// --------------------------------------------------------------------------- + +pub fn RaceConfig_default() -> RaceConfig { + return RaceConfig { + neon_url: "postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/neondb", + study_name: "igla-race", + reduction_factor: 3, + min_rungs: 3, + max_rungs: 27, + target_bpb: 1.50, + }; +} + +pub fn neon_url_fallback() -> str { + return "postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/neondb"; +} + +// --------------------------------------------------------------------------- +// Original lines 70-162: `pub fn init(config: RaceConfig) -> Result<()>`. +// Creates the Optuna study in Neon and prints the SQL schema and the worker +// instructions. Pure transport. The schema it carries has a shape worth +// porting: three tables (trials, experience, competitors), two views +// (leaderboard, winning techniques), with the trials table and the +// leaderboard view under the names the schema declares. +// --------------------------------------------------------------------------- + +pub fn init(config: RaceConfig) -> ?str { + return undefined; // plumbing: creates the Optuna study and prints the schema (lines 70-162) +} + +pub fn schema_table_count() -> usize { + return 3; +} + +pub fn schema_view_count() -> usize { + return 2; +} + +pub fn trials_table_name() -> str { + return "igla_race_trials"; +} + +pub fn leaderboard_view_name() -> str { + return "igla_leaderboard"; +} + +// --------------------------------------------------------------------------- +// Original lines 165-238: `pub fn status(limit: Option) -> +// Result<()>`. Fetches and prints the live leaderboard. Pure transport; +// its decisions are ported below. +// --------------------------------------------------------------------------- + +pub fn status(limit_present: bool, limit: usize) -> ?str { + return undefined; // plumbing: queries the leaderboard view and prints it (lines 165-238) +} + +// Original line 168: `let limit = limit.unwrap_or(10);` — the status limit +// defaults to 10 when the caller passed none. +pub fn status_limit(limit_present: bool, limit: usize) -> usize { + if (!limit_present) { + return 10; + } + return limit; +} + +// Original line 207: `for entry in mock_entries.iter().take(limit)` — the +// shown rows are capped by the limit and by how many entries exist. +pub fn take_count(limit: usize, total: usize) -> usize { + if (limit > total) { + return total; + } + return limit; +} + +// Original lines 209-213: the parameters column truncates to 25 characters +// and marks the cut with an ellipsis, exactly when the string is longer +// than 25 (a 25-character string stays whole). +pub fn params_truncated_len(params_len: usize) -> usize { + if (params_len > 25) { + return 25; + } + return params_len; +} + +pub fn params_needs_ellipsis(params_len: usize) -> bool { + if (params_len > 25) { + return true; + } + return false; +} + +// Original line 208: `entry.agent.as_deref().unwrap_or("???")` — an entry +// without an agent shows the ??? marker. +pub fn agent_label(agent_present: bool, agent: str) -> str { + if (!agent_present) { + return "???"; + } + return agent; +} + +// Original lines 171-199: the three mock leaderboard rows the status +// command renders, by rank: BPB, agent name, and the entry count. +pub fn mock_entry_count() -> usize { + return 3; +} + +pub fn mock_bpb(rank: usize) -> f64 { + if (rank == 1) { + return 2.716; + } + if (rank == 2) { + return 2.743; + } + if (rank == 3) { + return 2.780; + } + return 0; +} + +pub fn mock_agent(rank: usize) -> str { + if (rank == 1) { + return "ALFA"; + } + if (rank == 2) { + return "BRAVO"; + } + if (rank == 3) { + return "CHARLIE"; + } + return ""; +} + +// Original lines 222-230: the race statistics block the status command +// prints: 12 active trials, 42 completed, a 23.5% promoted rate, and the +// 1.500 target BPB line. +pub fn active_trials_count() -> usize { + return 12; +} + +pub fn completed_trials_count() -> usize { + return 42; +} + +pub fn promoted_rate_percent() -> f64 { + return 23.5; +} + +// Original lines 232-235: the ASHA rung ladder — 1000 steps, then 3000, +// then 9000 — and the IGLA FOUND threshold on the last rung: BPB < 1.50. +pub fn asha_step_ladder(rung_index: usize) -> usize { + if (rung_index == 0) { + return 1000; + } + if (rung_index == 1) { + return 3000; + } + if (rung_index == 2) { + return 9000; + } + return 0; +} + +pub fn igla_found(bpb: f64) -> bool { + if (bpb < 1.50) { + return true; + } + return false; +} + +// --------------------------------------------------------------------------- +// Original lines 241-260: `pub fn report_trial(...) -> Result<()>`. Reports +// a trial result to the race. Pure transport; its decisions are ported +// below. +// --------------------------------------------------------------------------- + +pub fn report_trial( + trial_id: u32, + rung: usize, + bpb: f64, + params_len: usize, + agent_present: bool, +) -> ?str { + return undefined; // plumbing: reports the trial to the race (lines 241-260) +} + +// Original line 253: `println!(" BPB: {:.3}", bpb)` — the reported BPB is +// shown with three decimals. +pub fn bpb_display_decimals() -> usize { + return 3; +} + +// Original lines 255-257: the Agent line is printed only when a Some agent +// was passed. +pub fn report_includes_agent(agent_present: bool) -> bool { + return agent_present; +} + +// --------------------------------------------------------------------------- +// Tests: every decision above asserted against values read from the +// original (including the original's own test_race_config_default, lines +// 267-271). No test calls a transport. +// --------------------------------------------------------------------------- + +test raceconfig_default_matches_original { + const c = RaceConfig_default(); + assert(c.neon_url == "postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/neondb"); + assert(c.study_name == "igla-race"); + assert(c.reduction_factor == 3); + assert(c.min_rungs == 3); + assert(c.max_rungs == 27); + assert(c.target_bpb == 1.50); +} + +test neon_url_fallback_literal { + assert(neon_url_fallback() == "postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/neondb"); +} + +test schema_shape { + assert(schema_table_count() == 3); + assert(schema_view_count() == 2); + assert(trials_table_name() == "igla_race_trials"); + assert(leaderboard_view_name() == "igla_leaderboard"); +} + +test status_limit_defaults_to_ten { + assert(status_limit(false, 0) == 10); + assert(status_limit(true, 5) == 5); +} + +test params_truncated_at_25_chars { + assert(params_truncated_len(24) == 24); + assert(params_truncated_len(25) == 25); + assert(params_truncated_len(26) == 25); + assert(!params_needs_ellipsis(25)); + assert(params_needs_ellipsis(26)); +} + +test agent_label_fallback_marker { + assert(agent_label(false, "") == "???"); + assert(agent_label(true, "ALFA") == "ALFA"); +} + +test take_limit_capped_by_entries { + assert(take_count(5, 3) == 3); + assert(take_count(2, 3) == 2); + assert(take_count(10, mock_entry_count()) == 3); +} + +test mock_leaderboard_rows { + assert(mock_bpb(1) == 2.716); + assert(mock_bpb(2) == 2.743); + assert(mock_bpb(3) == 2.780); + assert(mock_agent(2) == "BRAVO"); +} + +test race_statistics_constants { + assert(active_trials_count() == 12); + assert(completed_trials_count() == 42); + assert(promoted_rate_percent() == 23.5); +} + +test asha_step_ladder_triples { + assert(asha_step_ladder(0) == 1000); + assert(asha_step_ladder(1) == 3000); + assert(asha_step_ladder(2) == 9000); + assert(asha_step_ladder(3) == 0); +} + +test igla_found_below_target_only { + assert(igla_found(1.49)); + assert(!igla_found(1.50)); + assert(!igla_found(2.716)); +} + +test report_line_shape { + assert(bpb_display_decimals() == 3); + assert(report_includes_agent(true)); + assert(!report_includes_agent(false)); +}