Expand description
Temporary copies of a project where Forge builds and runs generated tests.
Re-exportsΒ§
use crate::result::TestResult;πuse crate::workspace;πuse eyre::Context;πuse eyre::Result;πuse eyre::eyre;πuse foundry_common::fs::canonicalize_path;πuse foundry_compilers::cache::SOLIDITY_FILES_CACHE_FILENAME;πuse foundry_compilers::solc::Solc;πuse foundry_config::Config;πuse foundry_config::DenyLevel;πuse serde::Deserialize;πuse serde::Deserialize;πuse std::fs;πuse std::path::Path;πuse std::path::PathBuf;πuse std::process::Command;πuse std::process::ExitStatus;πuse std::process::Output;πuse std::process::Stdio;πuse std::thread;πuse std::time::Duration;πuse std::time::Instant;πuse tempfile::TempDir;πuse toml_edit::DocumentMut;πuse rustix::process::Pid;πUnix use rustix::process::Signal;πUnix use rustix::process::kill_process_group;πUnix use std::os::unix::process::CommandExt;πUnix use std::sync::Mutex;πUnix
StructsΒ§
- Sandbox π
- Builds and runs generated code in temporary copies of the project. Generated code runs outside
the sandbox of whatever wrote it, so a copy leaves out hidden root entries such as
.envand agent settings, and Forge runs in it with only a few environment variables. - Test
File π - A Solidity file that an agent wrote, by its path relative to the project root.
ConstantsΒ§
- AGENT_
CONFIG π - Agent settings and instruction files that a workspace leaves out at every level. Settings can
hold hooks that run commands on the host.
CLAUDE.mdandAGENTS.mdare project docs, but they steer the agents that work in the copy, so a user who wants them passes them with--context. Entries of dependency directories are links, so they keep their own files. - PASSED_
ENV π - The environment variables that builds and test runs of generated code see, besides
HOME,FOUNDRY_PROFILE, and the seed settings. Generated tests run outside the agentβs sandbox, so they must not read the secrets of Forgeβs environment with the env cheatcodes. - RUN_
TIMEOUT π - How long one Forge build or test run in a workspace can take.
- SELECT_
ALL_ πTESTS - Overrides configured test filters, so they cannot hide generated tests.
$^matches no contract or test name, and no project file is under/forge-properties-none. - SESSION_
POLL π - How often Forge checks whether an agent session with a timeout has exited. Sessions take minutes, so this adds no noticeable delay.
StaticsΒ§
- SESSIONS π
Unix - The process groups of the running agent sessions, which Forge ends if it is interrupted.
FunctionsΒ§
- copy_
build_ πoutput - Copies the build output and the compiler cache of a built workspace into another workspace. The copy clones files where the file system can (APFS, Btrfs, XFS).
- copy_
project_ πtree - Copies a project directory into a workspace, without Git data, the
skippedpaths, agent settings and instructions (AGENT_CONFIG), and, at the project root, hidden entries such as.env. - ensure_
inside π - Fails if the nearest existing ancestor of
pathresolves outsideroot, for example through a linked directory. - restrict_
config π - Turns off
ffiunlessallow_ffi, and removes the RPC and Etherscan settings unlessallow_network. Every workspace of aSandboxwrites its config through this, so no generated test can callvm.ffior reach an endpoint that the config names. Config ignoresFFIenvironment variables. - run_
session π - Runs a session command in its own process group until it exits or reaches the timeout in
seconds, then ends the process group, so no process that the session started keeps running.
Returns
Noneif the session reached the timeout. - shorten π
- Keeps both ends of a long tool output. Many tools print the decisive error last.
- stderr π
- Returns stderr without compiler warning blocks and keeps both ends when it is still long.
Warnings can fill the limit before the decisive error, and many tools print the error last.
Without a compiler error, as with
deny = "warnings", the warnings are the errors and stay. - suite_
results π - Returns every test result in Forgeβs JSON output with its contract and test name.