mirror of
https://github.com/storytold/effectcraft.git
synced 2026-12-03 15:31:23 -05:00
13470ca161
* AG4: xtask ci --affected cargo xtask ci --affected [--base REV] [--dry-run] runs fmt, clippy, tests (nextest + doctests when available), layers, assets (only on asset changes) and wasm (only for affected L0-L4/web crates) for the packages a change can affect: changed files map to the owning package and to packages whose sources read them via ../ paths, expanded to reverse dependents. Workspace-wide inputs (root Cargo.toml, Cargo.lock, .cargo/, xtask/, toolchain, clippy.toml) fall back to full CI. Documented in docs/testing.md, AGENTS.md and CLAUDE.md. (cherry picked from commit f3ca84fc2ee3948582cbc94e4c99ee510e829540) (cherry picked from commit 8a2cdcadf447eafa57ab14016beae4420f002af0) (cherry picked from commitd8a4301bc1) (cherry picked from commit 36402c61ac2f7e29ecd76a6cfc89365cc2572e0a) * AO1: fast CI profile, looser timing tests - [profile.ci] (release without LTO, 16 codegen units); `xtask ci` runs clippy and tests with --profile ci instead of --release. - Wall-clock asserts in engine memory_tick, gpu OpenGL decline and script socket tests keep their intent with bounds that survive a loaded machine. - docs/testing.md and CONTRIBUTING.md mention the profile. (cherry picked from commit b45c8a379351ebdfda0d7076ad4b740baf6f2087) (cherry picked from commit fa1ea6a107c4c1936cde89b518a05adc73f2b4b0) (cherry picked from commite5d5ed80e9) (cherry picked from commit d2c67660c70764f9c56880a642ad7f0d004a7f92) * AG6: journal replay repros Bug reports become replay scripts and crash regression tests become data files: - engine::replay: a JSON-lines repro format (start line, command steps with expect_error, expect queries with JSON pointer + equals, expect_no_error), a never-panicking runner that reports per-step ok/error and the first failure, and journal export (from the last project open; saves left out; size-capped). - journal.export {path?} and help.exportRepro {path?} (not journaled). - Crash capture: when the last-resort guard catches a panic in the outermost command, the journal plus that command is saved to Repros/crash-*.jsonl in the settings store (newest 20 kept) and the error names the file. - Commands run by a journaled command (script steps) are no longer journaled twice. - effectcraft-cli replay SCRIPT.jsonl [--json] [--keep-going]: exits 1 on a failed step, unmet expectation or panic. - crates/host/tests/repros.rs replays every tests/repros/*.jsonl; three samples from past crash fixes (zero frame rate, Layer Settings with no selection, New Comp from Selection with hostile overlap). - Docs: docs/agents.md "Repro scripts"; AGENTS.md: crash fix regression test = a .jsonl in tests/repros. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit c38509d7dafe507856c48c78db65e00b94b0cebc) (cherry picked from commit e55b56dbf76716adfcbfe4cc773df19a74edc419) (cherry picked from commit96a63855a9) (cherry picked from commit c59351ab3bd697f0868e41230dd883960d94a540) * xtask: ci and ci --affected run cargo test and nextest with --no-fail-fast One run now lists every failing crate instead of stopping at the first. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019qXL3GPNnY9BSFF2XoU2Yu (cherry picked from commit e46c7debe738eca62b35bf7392ab77637f6a33ae) * Agents: confinement write-checks journal.export, help.exportRepro and file.exportTimeline Review on #859 (split into this PR): their output paths were only read-checked (relative ones not at all). Test: confinement_covers_every_command_that_writes_a_file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014d65YdNxQmjRkbXRtP2NwH * #1224: handle bin-only CI targets and BOM repros without weakening timing tests * #1224: run the full gate when nextest policy changes --------- Co-authored-by: Elias <hakifx91@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: FredApps <FredApps@users.noreply.github.com> Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
87 lines
4.2 KiB
Rust
87 lines
4.2 KiB
Rust
use super::{EngineError, Event, Result, Session, Value, commands, guard};
|
|
|
|
impl Session {
|
|
pub fn new() -> Session {
|
|
Session::default()
|
|
}
|
|
|
|
/// Run a command by id.
|
|
pub fn execute(&mut self, id: &str, params: Value) -> Result<Value> {
|
|
if self.script_ui.render_host.is_some() && !crate::scriptui::allowed_during_render(id) {
|
|
return Err(EngineError::Other(crate::scriptui::RENDER_WAIT_MESSAGE.into()));
|
|
}
|
|
let spec = commands::find(id).ok_or_else(|| EngineError::UnknownCommand(id.to_string()))?;
|
|
if let Err(why) = (spec.enabled)(self) {
|
|
// Explicit targets (agents, scripts) don't need a UI selection.
|
|
let explicit = (["layer", "layers", "prop", "keys"].iter().any(|k| params.get(k).is_some()) && commands::has_comp(self).is_ok())
|
|
|| ["item", "items"].iter().any(|k| params.get(k).is_some())
|
|
// An explicit composition (the enablement looks at the active one).
|
|
|| params.get("comp").is_some_and(|c| !c.is_null() && self.resolve_comp(Some(c)).is_ok());
|
|
if !explicit {
|
|
return Err(EngineError::Disabled(id.to_string(), why));
|
|
}
|
|
}
|
|
// Last-resort guard: a panicking command reports an error instead of crashing the app.
|
|
let nesting = crate::replay::Nesting::enter(spec.journal);
|
|
let caught = guard::caught();
|
|
let r = guard::guarded(&format!("command `{id}`"), || (spec.run)(self, ¶ms));
|
|
let r = crate::replay::after_command(self, id, ¶ms, &nesting, caught, r)?;
|
|
self.learn_observe(id, ¶ms);
|
|
if spec.journal && !nesting.inside_journaled() {
|
|
// Revert and Open Recent resolve a file the parameters may not name. Store
|
|
// the successful read as an explicit open boundary while its resolved path is known.
|
|
let entry = if matches!(id, "file.revert" | "file.openRecent") {
|
|
self.path.as_ref().map(|path| ("file.open".to_string(), serde_json::json!({"path": path})))
|
|
} else {
|
|
None
|
|
};
|
|
self.journal.push(entry.unwrap_or_else(|| (id.to_string(), params)));
|
|
if self.journal.len() > 10_000 {
|
|
self.journal.drain(..1000);
|
|
}
|
|
}
|
|
Ok(r)
|
|
}
|
|
|
|
/// [`Session::execute`] for agents and scripts (MCP, CLI, control channel): unknown top-level
|
|
/// parameters are rejected with the accepted keys instead of being silently ignored.
|
|
pub fn execute_checked(&mut self, id: &str, params: Value) -> Result<Value> {
|
|
let spec = commands::find(id).ok_or_else(|| EngineError::UnknownCommand(id.to_string()))?;
|
|
commands::check_params(spec, ¶ms)?;
|
|
self.execute(id, params)
|
|
}
|
|
|
|
/// [`Session::execute`] for a command a script asked for (the JavaScript engine's
|
|
/// `app.run`, ScriptUI callbacks…). The command and everything it runs count as the script's:
|
|
/// it may not change the settings that limit scripts (Settings ▸ Scripting & Expressions ▸
|
|
/// Application Scripting), which only the user can, from the UI, CLI or control channel.
|
|
pub fn execute_for_script(&mut self, id: &str, params: Value) -> Result<Value> {
|
|
self.script_calls.0 = self.script_calls.0.saturating_add(1);
|
|
let r = self.execute(id, params);
|
|
self.script_calls.0 = self.script_calls.0.saturating_sub(1);
|
|
r
|
|
}
|
|
|
|
/// Whether the command running was issued by a script ([`Session::execute_for_script`]).
|
|
pub fn running_for_script(&self) -> bool {
|
|
self.script_calls.0 > 0
|
|
}
|
|
|
|
/// Whether `id` names a known command whose `enabled` predicate returns `Ok` for this session;
|
|
/// an unknown id or a predicate error reads as disabled.
|
|
pub fn is_enabled(&self, id: &str) -> bool {
|
|
if self.script_ui.render_host.is_some() && !crate::scriptui::allowed_during_render(id) {
|
|
return false;
|
|
}
|
|
commands::find(id).is_some_and(|c| (c.enabled)(self).is_ok())
|
|
}
|
|
|
|
pub fn toast(&mut self, msg: impl Into<String>) {
|
|
self.events.push(Event::Toast { message: msg.into(), error: false });
|
|
}
|
|
|
|
pub fn drain_events(&mut self) -> Vec<Event> {
|
|
std::mem::take(&mut self.events)
|
|
}
|
|
}
|