fix: keep status complete and name generation read-only

This commit is contained in:
Dandaedre 2026-09-20 20:56:21 +02:00
parent a3708a843f
commit b6f74e6e83
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
5 changed files with 44 additions and 74 deletions

View File

@ -52,7 +52,7 @@ work belongs here before implementation.
- [x] Make `efo show` inspect actual world state or replace it with a coherent
command surface; remove its current generated demonstration output.
- [ ] Make `efo status` clearly show current epoch, timeline divergence/future
- [x] Make `efo status` clearly show current epoch, timeline divergence/future
snapshots, entity totals, and a clean/modified indicator if detectable.
- [x] Implement and test truthful `epoch diff` output.
- [x] Implement `epoch fsck` with read-only checks for config, directories,
@ -118,7 +118,8 @@ These require user approval and are not part of the current implementation:
- `epoch switch --force` is parsed but ignored.
- Entity rendering emits ANSI escapes when stdout is redirected and relies on
several optional Nerd Font glyphs for labels.
- Name generation creates `naming.json` in the process working directory.
- Name generation used to create `naming.json` in the working directory; this
was removed in favor of read-only embedded defaults.
- The binary crate currently has no tests; most coverage is parsing/model-level.
- Existing library tests passed on 2026-09-20. Tarpaulin was intentionally not
run because badges are release-only by project policy.

View File

@ -1,73 +1,46 @@
//! A very succint status display
//! Concise repository and current-epoch status.
use clap::Args;
use colored::Colorize;
use lib_efo::epoch::{EpochConfig, EpochId};
/// Arguments for the `status` subcommand.
#[derive(Args, Debug)]
pub struct StatusCmd {
/// An optionnal EpochId showing another epoch
/// Show a numeric epoch instead of the currently checked-out epoch.
custom_id: Option<EpochId>,
}
/// Print a short status
/// Print the selected epoch's annotations, timeline state, and entity totals.
pub(crate) fn status(cmd: &StatusCmd) -> Result<(), crate::error::AppError> {
let mut main_epoch = EpochConfig::new_from_path(None)?;
let mut config = EpochConfig::new_from_path(None)?;
let selected_id = cmd.custom_id.unwrap_or(config.epoch_id);
let is_current = selected_id == config.epoch_id;
let future_count = config
.list_existing_epochs
.keys()
.filter(|id| **id > config.epoch_id)
.count();
let epoch = config.load_epoch(selected_id)?;
let current_epoch = if let Some(epoch_id) = cmd.custom_id {
main_epoch.load_epoch(epoch_id)?
} else {
main_epoch.try_load_current()?
};
let mut out = String::new();
out.push_str(
&format!(
"[{}{} {}]\n",
"󰬌 ".bright_blue(),
"Epoch".blue(),
current_epoch.epoch_id
)
.blue(),
println!(
"Epoch {}{}",
epoch.epoch_id,
if is_current { " (current)" } else { "" }
);
if !current_epoch.summary.is_empty() {
out.push_str(&format!(
" ├─ {:12} {}\n",
"Summary".green(),
current_epoch.summary
));
if !epoch.summary.is_empty() {
println!("├─ Summary {}", epoch.summary);
}
if !current_epoch.tags.is_empty() {
out.push_str(&format!(
" ├─ {:12} {}\n",
"Tags".green(),
current_epoch.tags.join(",")
));
if !epoch.tags.is_empty() {
println!("├─ Tags {}", epoch.tags.join(", "));
}
out.push_str(&format!(" └─ {}\n", "Stats".green()));
out.push_str(&format!(
" ├ {:11} {}\n",
"Events".bright_green(),
current_epoch.events.len()
));
out.push_str(&format!(
" ├ {:11} {}\n",
"Characters".bright_green(),
current_epoch.characters.len()
));
out.push_str(&format!(
" ├ {:11} {}\n",
"Towns".bright_green(),
current_epoch.towns.len()
));
out.push_str(&format!(
" └ {:11} {}",
"Blockers".bright_green(),
current_epoch.blockers.len()
));
println!("{}", out);
if is_current && future_count > 0 {
println!("├─ Future {future_count} epoch(s); `epoch next` is blocked");
}
println!("└─ Entities");
println!(" ├─ Characters {}", epoch.characters.len());
println!(" ├─ Towns {}", epoch.towns.len());
println!(" ├─ Events {}", epoch.events.len());
println!(" ├─ Calamities {}", epoch.calamities.len());
println!(" └─ Blockers {}", epoch.blockers.len());
Ok(())
}

View File

@ -70,7 +70,9 @@ fn init_status_diff_and_fsck_workflow() {
let status = efo(&repo, &["status"]);
assert_success(&status);
assert!(stdout(&status).contains("Epoch 0"));
let status_text = stdout(&status);
assert!(status_text.contains("Epoch 0 (current)"));
assert!(status_text.contains("Calamities 0"));
assert_success(&efo(&repo, &["chr", "add", "Aria"]));
let show = efo(&repo, &["show", "all"]);
@ -81,6 +83,7 @@ fn init_status_diff_and_fsck_workflow() {
assert!(show_text.contains("Towns (0)"));
assert_success(&efo(&repo, &["epoch", "next"]));
assert_success(&efo(&repo, &["chr", "edit", "Aria", "--prestige-add", "2"]));
assert!(!repo.path().join("naming.json").exists());
let diff = efo(&repo, &["epoch", "diff", "0", "1"]);
assert_success(&diff);

View File

@ -49,9 +49,8 @@ collection. Use `<noun> show IDENTIFIER` for full details of one entity.
## Generation and output
`efo gen character|town|event|exotic|calamity|blocker` prints generated content.
The first naming operation may unexpectedly create `naming.json` in the current
directory; removal of this side effect is planned.
`efo gen character|town|event|exotic|calamity|blocker` prints generated content
without creating or changing repository files.
Output is human-readable Unicode. Some 0.1.0 renderers emit ANSI colour when
redirected and use optional Nerd Font glyphs; these are known accessibility

View File

@ -3,10 +3,7 @@
use once_cell::sync::Lazy;
use rand::prelude::*;
use serde::{Deserialize, Serialize};
use std::{
fs, io,
path::{Path, PathBuf},
};
use std::{fs, io, path::Path};
use crate::Displayable;
use crate::entity::{EffectApplication, EffectBounds, EntityDuration};
@ -305,15 +302,12 @@ impl NamingData {
/// `include_str!` pulls the file at compile time.
const DEFAULT_JSON_STR: &str = include_str!("../naming.json");
/// Helper that determines the *runtime* location of the `naming.json` file.
fn naming_file_path() -> PathBuf {
PathBuf::from("naming.json")
}
/// Global instance that is lazily initialised on first use.
/// Global naming data loaded from the JSON embedded in the binary.
///
/// Generating a name is deliberately read-only and never creates files in the
/// user's world repository.
pub static NAMING: Lazy<NamingData> = Lazy::new(|| {
let path = naming_file_path();
NamingData::load_or_create(path).expect("Failed to load naming data")
serde_json::from_str(DEFAULT_JSON_STR).expect("embedded naming data must be valid")
});
#[cfg(test)]