Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.
Rust agent-skillsclaude-codeclicode-migrationcodexffigolangjavajavascriptmcpmigrationnapiperformanceportingpyo3pythonrewriterubyrusttypescript
Say no folder for a missing folder in app, spec, map and obligations (#1279)
jakalijeybc150d63e9d4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ea784b3e..eb044d51 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -96,6 +96,10 @@included (`:save!` names `save!`, not `save`; `:+` and `:[]=` stay listed); before,`:soundex_str` also matched `soundex` as a substring, so the export was listed twice (foundporting the `text` gem's `soundex.rb`, by @cfreyes7).+- Every `app` subcommand, `spec`, `map` and the `obligations` commands say `no folder <path>` for a+ folder that does not exist, with no operating system error after it, as `analyze` does. They+ check through `walk::resolve_root`, so a folder that exists but cannot be read is no longer+ called missing (#1248 by @jakalijey).- Java: the wrapper and shadow classes import `ArrayList`, `LinkedList`, `HashMap`, `LinkedHashMap`,`TreeMap`, `OptionalInt`, `OptionalLong` and `OptionalDouble` when a signature uses them. Before,`bridge` accepted those types and generated a wrapper `javac` refused (#1253 by @jakalijey).diff --git a/src/app.rs b/src/app.rsindex 2eb70adb..2ef09e33 100644--- a/src/app.rs+++ b/src/app.rs@@ -2713,10 +2713,7 @@ pub fn record(opts: &RecordOptions) -> Result<RecordOutcome> {for n in opts.normalize {custom_normalizer(n)?;}- let repo = opts- .repo- .canonical()- .with_context(|| format!("no folder {}", opts.repo.display()))?;+ let repo = crate::walk::resolve_root(opts.repo)?;let _record_lock = AppRecordLock::take(&repo)?;let existing = Config::load(&repo)?;let previous_skips = crate::lift::previous_cases_test_skips(&repo, existing.as_ref());@@ -4477,10 +4474,7 @@ pub(crate) fn replay_unwritten(opts: &ReplayOptions) -> Result<ReplayOutcome> {fn replay_cases(opts: &ReplayOptions) -> Result<ReplayOutcome> {check_timeout(opts.timeout_secs)?;- let repo = opts- .repo- .canonical()- .with_context(|| format!("no folder {}", opts.repo.display()))?;+ let repo = crate::walk::resolve_root(opts.repo)?;let dir = cases_dir(&repo);let config = Config::load(&repo)?;if config.is_none()diff --git a/src/app_shadow.rs b/src/app_shadow.rsindex 52dd163a..6f138124 100644--- a/src/app_shadow.rs+++ b/src/app_shadow.rs@@ -16,7 +16,6 @@ use crate::app::{self, Config, Failure, Normalizers, Problem};use crate::effects::EffectsConfig;use crate::http::{self, Launch, Req, Resp, Server};use crate::mismatch::{At, Group, text_at};-use crate::walk::Canonical;pub const SHADOW_DIR: &str = "shadow";pub const MISMATCHES_FILE: &str = "mismatches.jsonl";@@ -156,10 +155,7 @@ fn upstream_addr(text: &str) -> Result<SocketAddr> {pub fn shadow(opts: &ShadowOptions) -> Result<ShadowOutcome> {app::check_timeout(opts.timeout_secs)?;ensure!(opts.requests != Some(0), "--requests must be at least 1");- let repo = opts- .repo- .canonical()- .with_context(|| format!("no folder {}", opts.repo.display()))?;+ let repo = crate::walk::resolve_root(opts.repo)?;let dir = app::cases_dir(&repo);let Some(config) = Config::load(&repo)? else {bail!(diff --git a/src/drift.rs b/src/drift.rsindex 6b175b42..3e0013e1 100644--- a/src/drift.rs+++ b/src/drift.rs@@ -9,7 +9,6 @@ use anyhow::{Context, Result, bail};use serde::Serialize;use crate::app::{self, Config, Failure, ReplayOptions, ReplayOutcome};-use crate::walk::Canonical;pub const REPORT_FILE: &str = "drift-report.md";@@ -63,10 +62,7 @@ fn failed(outcome: &ReplayOutcome) -> BTreeSet<&str> {pub fn drift(opts: &DriftOptions) -> Result<DriftOutcome> {app::check_timeout(opts.timeout_secs)?;- let repo = opts- .repo- .canonical()- .with_context(|| format!("no folder {}", opts.repo.display()))?;+ let repo = crate::walk::resolve_root(opts.repo)?;let dir = app::cases_dir(&repo);let Some(config) = Config::load(&repo)? else {if let Ok(state) = crate::front_door::State::load(&repo)diff --git a/src/front_door.rs b/src/front_door.rsindex e92e754f..4d0656a5 100644--- a/src/front_door.rs+++ b/src/front_door.rs@@ -848,10 +848,7 @@ pub struct FrontDoorOutcome {}pub fn front_door(opts: &FrontDoorOptions) -> Result<FrontDoorOutcome> {- let repo = opts- .repo- .canonical()- .with_context(|| format!("no folder {}", opts.repo.display()))?;+ let repo = crate::walk::resolve_root(opts.repo)?;let dir = repo.join(APP_DIR);ensure!(!dir.exists(),@@ -1242,10 +1239,7 @@ pub fn wire(opts: &WireOptions) -> Result<WireOutcome> {}fn wire_unit(opts: &WireOptions) -> Result<WireOutcome> {- let repo = opts- .repo- .canonical()- .with_context(|| format!("no folder {}", opts.repo.display()))?;+ let repo = crate::walk::resolve_root(opts.repo)?;let mut state = State::load(&repo)?;ensure!(!state.lifted,diff --git a/src/lift.rs b/src/lift.rsindex 81b13cc8..b31e9925 100644--- a/src/lift.rs+++ b/src/lift.rs@@ -1589,10 +1589,7 @@ pub fn lift(opts: &LiftOptions) -> Result<LiftOutcome> {}fn lift_app_dir(opts: &LiftOptions) -> Result<LiftOutcome> {- let repo = opts- .repo- .canonical()- .with_context(|| format!("no folder {}", opts.repo.display()))?;+ let repo = crate::walk::resolve_root(opts.repo)?;let _lock = front_door::WireLock::take(&repo)?;if let Some(mut journal) = Journal::load(&repo)? {let binary = commit(&repo, &mut journal)?;diff --git a/src/obligations/mod.rs b/src/obligations/mod.rsindex bf7e6449..03b7175d 100644--- a/src/obligations/mod.rs+++ b/src/obligations/mod.rs@@ -338,9 +338,7 @@ pub fn ledger_with(root: &Path, lang: Option<Lang>, detector: Detector) -> Resul}fn build(root: &Path, lang: Option<Lang>, injected: Option<Detector>) -> Result<Ledger> {- let root = root- .canonical()- .with_context(|| format!("listing the obligations of {}", root.display()))?;+ let root = crate::walk::resolve_root(root)?;// `analyze` recurses into the files: on the calling thread, a file with a chain of tens of// thousands of links overflows the stack. So the analysis runs on a thread whose stack// follows the biggest file of the repository; nothing is written before the end.diff --git a/src/obligations/standing/act.rs b/src/obligations/standing/act.rsindex ebad4207..f920996f 100644--- a/src/obligations/standing/act.rs+++ b/src/obligations/standing/act.rs@@ -11,7 +11,7 @@ use std::path::{Path, PathBuf};use std::sync::atomic::{AtomicU64, Ordering};use std::time::{Duration, SystemTime, UNIX_EPOCH};-use anyhow::{Context, Result, bail};+use anyhow::{Result, bail};use toml_edit::{Array, ArrayOfTables, DocumentMut, Item, Table, value};use super::super::evidence::{Opened, open};@@ -19,14 +19,11 @@ use super::super::{Completeness, Family, stays_inside};use super::decisions::{self, DECISIONS_FILE};use super::fallbacks::Class;use super::{World, adr};-use crate::walk::Canonical;const LOCK_FILE: &str = "rust/.rust-anything/obligations.lock";pub(super) fn lock(repo: &Path) -> Result<fs::File> {- let root = repo- .canonical()- .with_context(|| format!("no folder {}", repo.display()))?;+ let root = crate::walk::resolve_root(repo)?;check_target(&root, LOCK_FILE)?;let path = root.join(LOCK_FILE);if let Some(dir) = path.parent() {diff --git a/src/obligations/standing/mod.rs b/src/obligations/standing/mod.rsindex c7170c27..ad591623 100644--- a/src/obligations/standing/mod.rs+++ b/src/obligations/standing/mod.rs@@ -18,13 +18,12 @@ use std::collections::{BTreeMap, BTreeSet};use std::fmt::Write as _;use std::path::{Path, PathBuf};-use anyhow::{Context, Result};+use anyhow::Result;use serde::Serialize;use super::evidence::{self, Evidence, Lens, Sources};use super::{Completeness, Family, Ledger};use crate::lang::Lang;-use crate::walk::Canonical;mod act;mod adr;@@ -188,9 +187,7 @@ impl World {/// computation), then the registry with the detected language, the evidence and the cases./// The language is never forced: `lift` does not force it either.pub(super) fn load(repo: &Path) -> Result<Self> {- let root = repo- .canonical()- .with_context(|| format!("no folder {}", repo.display()))?;+ let root = crate::walk::resolve_root(repo)?;let decisions = decisions::read(&root)?;let ledger = super::ledger(&root, None)?;let evidence = evidence::evidence(&root, &ledger)?;@@ -476,9 +473,7 @@ pub fn standing(repo: &Path) -> Result<Standing> {/// The ids waived by `rust/obligations-decisions.toml` of the repository `repo`, for `gate`. A/// missing file waives nothing; a bad file is an error.pub(crate) fn waived_ids(repo: &Path) -> Result<BTreeSet<String>> {- let root = repo- .canonical()- .with_context(|| format!("no folder {}", repo.display()))?;+ let root = crate::walk::resolve_root(repo)?;Ok(decisions::read(&root)?.waived().keys()@@ -487,9 +482,7 @@ pub(crate) fn waived_ids(repo: &Path) -> Result<BTreeSet<String>> {}pub(crate) fn size_allowance(repo: &Path, unit: &str) -> Result<Option<Size>> {- let root = repo- .canonical()- .with_context(|| format!("no folder {}", repo.display()))?;+ let root = crate::walk::resolve_root(repo)?;Ok(decisions::read(&root)?.size(unit).cloned())}diff --git a/src/port_map.rs b/src/port_map.rsindex 01f06c64..55a54b62 100644--- a/src/port_map.rs+++ b/src/port_map.rs@@ -146,6 +146,9 @@ impl PortMap {}pub fn map(root: &Path, extra: &[PathBuf]) -> Result<PortMap> {+ // `no folder <root>` for a missing folder, as `analyze` says it. The paths in the map keep+ // `std::fs::canonicalize`'s form, as the `--crates` folders below do.+ crate::walk::resolve_root(root)?;let root =std::fs::canonicalize(root).with_context(|| format!("mapping {}", root.display()))?;// A file is not a repository: `analyze` says so, and a map over a file used to come out emptydiff --git a/src/spec.rs b/src/spec.rsindex b320a756..31a82107 100644--- a/src/spec.rs+++ b/src/spec.rs@@ -8,7 +8,6 @@ use sha2::{Digest, Sha256};use crate::app::{self, Failure, ReplayOptions};use crate::gate::Check;use crate::recording::Trend;-use crate::walk::Canonical;pub const CASES: &str = "spec/cases";pub const SPEC: &str = "spec/SPEC.md";@@ -22,9 +21,7 @@ pub fn is_new_app(root: &Path) -> bool {}fn ensure_new_app(dir: &Path) -> Result<PathBuf> {- let dir = dir- .canonical()- .with_context(|| format!("no folder {}", dir.display()))?;+ let dir = crate::walk::resolve_root(dir)?;ensure!(is_new_app(&dir),"{} has no {CASES}/{}: start the app with `rust-anything new`",diff --git a/tests/missing_crate.rs b/tests/missing_crate.rsindex 5ea25102..7581bfe8 100644--- a/tests/missing_crate.rs+++ b/tests/missing_crate.rs@@ -1,6 +1,8 @@//! `disable`, `report` and `shadow` on a crate folder that does not exist name the folder and//! say to run `bridge` first, like the commands that read the manifest straight away.+mod common;+use std::path::PathBuf;use rust_anything::{card, enable, harness, shadow};@@ -141,3 +143,23 @@ fn bench_on_missing_resolve_from_names_the_folder() {"{msg}");}++#[test]+fn app_spec_map_and_obligations_name_a_missing_folder_once() {+ // The words `analyze` uses (#948): `no folder <path>`, with no operating system error after.+ let dir = missing("no-folder");+ let path = dir.display().to_string();+ for args in [+ vec!["app", "replay", &path],+ vec!["app", "lift", &path],+ vec!["spec", "check", &path],+ vec!["map", &path],+ vec!["obligations", &path],+ vec!["obligations", "--check", &path],+ ] {+ let out = common::cli().args(&args).output().unwrap();+ assert_eq!(out.status.code(), Some(2), "{args:?}");+ let err = String::from_utf8_lossy(&out.stderr);+ assert_eq!(err.trim(), format!("error: no folder {path}"), "{args:?}");+ }+}