use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, TryLockError};
use airsl::description::{Function, LuaType, ModuleDescription};
use airsl::mlua::{self, Lua, Table, Value};
use airsl::{HostModule, InstallContext, ModuleName};
use buildl_core::{
EvaluationFailure, EvaluationLimit, IgnoreRules, Origin, PluginName, StagedItem, TargetRole,
};
use crate::decode_all;
use crate::plugin::Plugins;
use crate::primitives;
use crate::refusal::{CallSite, Refusal};
use crate::results::Results;
use crate::snapshot::copy_tables;
use crate::sources::Sources;
use crate::stable_text;
use crate::staging::{Exceeded, Staging};
#[derive(Debug)]
pub(crate) struct BuildlModule<I> {
name: ModuleName,
staging: Arc<Mutex<Staging>>,
sources: Sources<I>,
results: Results,
plugins: Plugins<I>,
}
impl<I: IgnoreRules + Clone + Send + 'static> BuildlModule<I> {
pub(crate) fn new(
staging: Arc<Mutex<Staging>>,
sources: Sources<I>,
results: Results,
root: &Path,
plugins: BTreeMap<PluginName, PathBuf>,
) -> airsl::Result<Self> {
let plugins = Plugins::new(root, plugins, &staging, &sources, &results);
Ok(Self {
name: ModuleName::new("buildl")?,
staging,
sources,
results,
plugins,
})
}
}
impl<I: IgnoreRules + Clone + Send + 'static> HostModule for BuildlModule<I> {
fn name(&self) -> &ModuleName {
&self.name
}
fn describe(&self) -> airsl::Result<ModuleDescription> {
ModuleDescription::builder("Declares the build file's targets, rules and settings.")
.function(
Function::new("target", "Declares a build target.")
.param("name", LuaType::STRING, "The target's label.")
.param("options", LuaType::TABLE, "The target's rule and inputs.")
.returns(LuaType::NIL),
)
.function(
Function::new("test", "Declares a test target.")
.param("name", LuaType::STRING, "The target's label.")
.param("options", LuaType::TABLE, "The target's rule and inputs.")
.returns(LuaType::NIL),
)
.function(
Function::new("discover", "Declares a discovery target.")
.param("name", LuaType::STRING, "The target's label.")
.param("options", LuaType::TABLE, "The target's rule and inputs.")
.returns(LuaType::NIL),
)
.function(
Function::new("rule", "Declares a rule.")
.param("name", LuaType::STRING, "The rule's name.")
.param("options", LuaType::TABLE, "The rule's command.")
.returns(LuaType::NIL),
)
.function(
Function::new("alias", "Declares an alias for a target.")
.param("name", LuaType::STRING, "The alias.")
.param("target", LuaType::STRING, "The target it names.")
.returns(LuaType::NIL),
)
.function(
Function::new("option", "Declares a setting.")
.param("name", LuaType::STRING, "The setting's name.")
.param("options", LuaType::TABLE, "The setting's default.")
.returns(LuaType::NIL),
)
.function(
Function::new("subdir", "Declares a subdirectory with its own build file.")
.param(
"path",
LuaType::STRING,
"The directory, relative to this file.",
)
.returns(LuaType::NIL),
)
.function(
Function::new("sources", "Lists the files matching a glob.")
.param(
"pattern",
LuaType::STRING,
"The glob, relative to this file.",
)
.returns(LuaType::array(LuaType::STRING)),
)
.function(
Function::new("folder", "Reports this build file's directory.")
.returns(LuaType::STRING),
)
.function(
Function::new("discovered", "Reads a discovery target's output.")
.param("label", LuaType::STRING, "The discovery target's label.")
.returns(LuaType::optional(LuaType::STRING)),
)
.function(
Function::new("decode_all", "Decodes a stream of JSON values.")
.param("text", LuaType::STRING, "The JSON text to decode.")
.returns(LuaType::TABLE),
)
.function(
Function::new("use", "Loads a plugin's module.")
.param("name", LuaType::STRING, "The plugin's name.")
.returns(LuaType::TABLE),
)
.build()
}
fn install(
&self,
lua: &Lua,
table: &Table,
_context: &InstallContext<'_>,
) -> airsl::Result<()> {
let fail = |error| airsl::Error::lua("buildl", error);
let primitives = primitives_table(
lua,
&self.staging,
&self.sources,
&self.results,
&Origin::BuildFile,
)
.map_err(fail)?;
for pair in primitives.pairs::<String, Value>() {
let (name, function) = pair.map_err(fail)?;
table.set(name, function).map_err(fail)?;
}
self.plugins.bind_use(lua, table, &[]).map_err(fail)?;
let globals = lua.globals();
globals.set("buildl", table.clone()).map_err(fail)?;
let math: Table = globals.get("math").map_err(fail)?;
math.set("random", Value::Nil).map_err(fail)?;
math.set("randomseed", Value::Nil).map_err(fail)?;
globals.set("print", Value::Nil).map_err(fail)?;
stable_text::install(lua).map_err(fail)?;
record_language(lua).map_err(fail)?;
Ok(())
}
}
pub(crate) const LANGUAGE_REGISTRY_KEY: &str = "buildl.language";
const NOT_LANGUAGE: [&str; 4] = ["buildl", "airsstack", "_G", "require"];
pub(crate) fn primitives_table<I: IgnoreRules + Clone + Send + 'static>(
lua: &Lua,
staging: &Arc<Mutex<Staging>>,
sources: &Sources<I>,
results: &Results,
origin: &Origin,
) -> mlua::Result<Table> {
let table = lua.create_table()?;
let origin = Arc::new(origin.clone());
for (primitive, role) in [
("target", TargetRole::Build),
("test", TargetRole::Test),
("discover", TargetRole::Discovery),
] {
let staging = Arc::clone(staging);
let origin = Arc::clone(&origin);
let function = lua.create_function(move |lua, (name, options): (Value, Value)| {
declare(lua, &staging, &origin, primitive, || {
primitives::target(&name, &options, role).map(StagedItem::Target)
})
})?;
table.set(primitive, function)?;
}
let staging_ref = Arc::clone(staging);
let origin_ref = Arc::clone(&origin);
let rule = lua.create_function(move |lua, (name, options): (Value, Value)| {
declare(lua, &staging_ref, &origin_ref, "rule", || {
primitives::rule(&name, &options).map(StagedItem::Rule)
})
})?;
table.set("rule", rule)?;
let staging_ref = Arc::clone(staging);
let origin_ref = Arc::clone(&origin);
let alias = lua.create_function(move |lua, (name, target): (Value, Value)| {
declare(lua, &staging_ref, &origin_ref, "alias", || {
primitives::alias(&name, &target).map(StagedItem::Alias)
})
})?;
table.set("alias", alias)?;
let staging_ref = Arc::clone(staging);
let origin_ref = Arc::clone(&origin);
let option = lua.create_function(move |lua, (name, options): (Value, Value)| {
declare(lua, &staging_ref, &origin_ref, "option", || {
primitives::option(&name, &options).map(StagedItem::Setting)
})
})?;
table.set("option", option)?;
let staging_ref = Arc::clone(staging);
let subdir = lua.create_function(move |lua, path: Value| {
guarded(lua, &staging_ref, "subdir", |staging| {
let path = primitives::subdir(&path)?;
staging.stage_subdir(path).map_err(exceeded)
})
})?;
table.set("subdir", subdir)?;
let staging_ref = Arc::clone(staging);
let walk = sources.clone();
let found = lua.create_function(move |lua, pattern: Value| {
let found = guarded(lua, &staging_ref, "sources", |_| {
walk.find(&primitives::pattern(&pattern)?)
})?;
lua.create_sequence_from(found)
})?;
table.set("sources", found)?;
let results = results.clone();
let directory = results.directory().as_str().to_owned();
let folder = lua.create_function(move |_, ()| Ok(directory.clone()))?;
table.set("folder", folder)?;
let staging_ref = Arc::clone(staging);
let discovered = lua.create_function(move |lua, label: Value| {
let label = guarded(lua, &staging_ref, "discovered", |_| {
primitives::discovered(&label, results.directory())
})?;
results
.get(&label)
.map(|bytes| lua.create_string(bytes))
.transpose()
})?;
table.set("discovered", discovered)?;
let decode_all = lua.create_function(|lua, text: Value| decode_all::decode_all(lua, &text))?;
table.set("decode_all", decode_all)?;
Ok(table)
}
pub(crate) fn record_language(lua: &Lua) -> mlua::Result<()> {
let snapshot = lua.create_table()?;
copy_tables(lua, &lua.globals(), &snapshot)?;
for name in NOT_LANGUAGE {
snapshot.set(name, Value::Nil)?;
}
lua.set_named_registry_value(LANGUAGE_REGISTRY_KEY, snapshot)
}
fn declare(
lua: &Lua,
staging: &Mutex<Staging>,
origin: &Origin,
primitive: &'static str,
read: impl FnOnce() -> Result<StagedItem, Refusal>,
) -> mlua::Result<()> {
guarded(lua, staging, primitive, |staging| {
staging.stage(read()?, origin).map_err(exceeded)
})
}
pub(crate) fn guarded<T>(
lua: &Lua,
staging: &Mutex<Staging>,
primitive: &'static str,
work: impl FnOnce(&mut Staging) -> Result<T, Refusal>,
) -> mlua::Result<T> {
let site = call_site(lua);
let mut staging = match staging.try_lock() {
Ok(staging) => staging,
Err(TryLockError::Poisoned(poisoned)) => poisoned.into_inner(),
Err(TryLockError::WouldBlock) => {
return Err(mlua::Error::RuntimeError(format!(
"buildl.{primitive}: buildl primitives cannot be called while another buildl call is in progress"
)));
}
};
let recorded = staging.recorded().map(ToString::to_string);
let outcome = recorded.map_or_else(
|| {
work(&mut staging).map_err(|refusal| {
let diagnostic = refusal.diagnostic(primitive, site.as_ref());
let message = diagnostic.to_string();
staging.record(refusal.failure().clone(), diagnostic);
message
})
},
Err,
);
drop(staging);
outcome.map_err(mlua::Error::RuntimeError)
}
const PLUGIN_CHUNK_MARK: char = '=';
const CHUNK_NAME_SHOWN: usize = 59;
const ELLIPSIS: &str = "...";
pub(crate) fn plugin_chunk_name(chunk: &str) -> String {
if chunk.len() <= CHUNK_NAME_SHOWN {
return format!("{PLUGIN_CHUNK_MARK}{chunk}");
}
let mut from = chunk.len() - (CHUNK_NAME_SHOWN - ELLIPSIS.len());
while !chunk.is_char_boundary(from) {
from += 1;
}
format!("{PLUGIN_CHUNK_MARK}{ELLIPSIS}{}", &chunk[from..])
}
fn call_site(lua: &Lua) -> Option<CallSite> {
(1..)
.map_while(|level| {
lua.inspect_stack(level, |debug| {
let line = debug.current_line()?;
let source = debug.source().source;
let plugin_chunk = source
.as_deref()
.and_then(|name| name.strip_prefix(PLUGIN_CHUNK_MARK));
Some(
plugin_chunk.map_or(CallSite::BuildFile { line }, |chunk| CallSite::Plugin {
chunk: chunk.to_owned(),
line,
}),
)
})
})
.flatten()
.next()
}
fn exceeded(exceeded: Exceeded) -> Refusal {
Refusal::new(
EvaluationFailure::LimitReached {
limit: EvaluationLimit::Staging,
},
exceeded.to_string(),
)
}
#[cfg(test)]
mod tests {
#![expect(
clippy::unwrap_used,
reason = "tests unwrap known-valid fixtures; a panic is the intended failure signal"
)]
use std::collections::{BTreeMap, BTreeSet};
use std::fs;
use std::sync::{Arc, Mutex};
use airsl::{Engine, LanguageSurface, ModuleSet, Policy, Script};
use buildl_core::{
DeclarationOrder, Diagnostic, Directory, EvaluationFailure, EvaluationLimit, Freshness,
NetworkAccess, NothingIgnored, Origin, OutputSource, StagedAlias, StagedDeclaration,
StagedFile, StagedItem, StagedRule, StagedSetting, StagedSubdir, StagedTarget, TargetRole,
Written,
};
use airsl::mlua::{Lua, Table, Value};
use buildl_core::{PluginName, PluginRef, PluginVersion};
use super::{
BuildlModule, CHUNK_NAME_SHOWN, LANGUAGE_REGISTRY_KEY, plugin_chunk_name, primitives_table,
record_language,
};
use crate::limits::DeclarationLimits;
use crate::results::Results;
use crate::sources::Sources;
use crate::staging::Staging;
#[test]
fn a_chunk_name_that_fits_is_marked_and_left_whole() {
let chunk = "x".repeat(CHUNK_NAME_SHOWN);
assert_eq!(plugin_chunk_name(&chunk), format!("={chunk}"));
assert_eq!(
plugin_chunk_name("plugins/p/main.lua"),
"=plugins/p/main.lua"
);
}
#[test]
fn a_chunk_name_that_is_too_long_keeps_its_end() {
let chunk = format!(".buildl/plugins/c/{}/lib/api.lua", "ab".repeat(20));
let name = plugin_chunk_name(&chunk);
assert_eq!(name.len(), 1 + CHUNK_NAME_SHOWN);
assert!(name.starts_with("=..."), "{name}");
assert!(name.ends_with("/lib/api.lua"), "{name}");
assert!(chunk.ends_with(&name[4..]), "{name}");
}
#[test]
fn a_cut_chunk_name_does_not_split_a_character() {
let chunk = format!("{}/é.lua", "é".repeat(40));
let name = plugin_chunk_name(&chunk);
assert!(name.len() <= 1 + CHUNK_NAME_SHOWN, "{name}");
assert!(name.ends_with("/é.lua"), "{name}");
}
fn evaluate(source: &str, staging: &Arc<Mutex<Staging>>) -> airsl::Result<String> {
let dir = tempfile::tempdir().unwrap();
let root = fs::canonicalize(dir.path()).unwrap();
fs::write(root.join("a.c"), "").unwrap();
fs::write(root.join("b.c"), "").unwrap();
let mut modules = ModuleSet::new();
modules
.insert(Box::new(
BuildlModule::new(
Arc::clone(staging),
Sources::new(
&root,
&Directory::root(),
DeclarationLimits::default().walk_entries(),
&[],
NothingIgnored,
),
Results::none(),
&root,
BTreeMap::new(),
)
.unwrap(),
))
.unwrap();
let engine = Engine::builder()
.policy(Policy::confined().with_language(LanguageSurface::Minimal))
.stdlib(modules)
.build()
.unwrap();
engine.eval_to::<String>(&Script::from_source(source, "build.lua").unwrap())
}
fn run(
source: &str,
budget: u64,
) -> (
airsl::Result<String>,
Result<StagedFile, (EvaluationFailure, Diagnostic)>,
) {
let staging = Arc::new(Mutex::new(Staging::new(budget)));
let result = evaluate(source, &staging);
let staged = std::mem::replace(&mut *staging.lock().unwrap(), Staging::new(0)).finish();
(result, staged)
}
fn strings<T>(texts: &[&str]) -> Vec<Written<T>> {
texts.iter().map(|text| Written::new(*text)).collect()
}
#[test]
fn the_description_matches_what_install_sets() {
let dir = tempfile::tempdir().unwrap();
let root = fs::canonicalize(dir.path()).unwrap();
let module = BuildlModule::new(
Arc::new(Mutex::new(Staging::new(u64::MAX))),
Sources::new(
&root,
&Directory::root(),
DeclarationLimits::default().walk_entries(),
&[],
NothingIgnored,
),
Results::none(),
&root,
BTreeMap::new(),
)
.unwrap();
airsl::luals::verify(&module, &airsl::RootTable::default()).unwrap();
}
#[test]
fn binds_one_table_under_two_names_without_inheritance() {
let (result, _) = run(
"return tostring(buildl == airsstack.buildl) .. ' ' .. tostring(buildl.json)",
u64::MAX,
);
assert_eq!(result.unwrap(), "true nil");
}
#[test]
fn withholds_random_and_print() {
let (result, _) = run(
"return type(math.random) .. type(math.randomseed) .. type(print) .. type(math.floor)",
u64::MAX,
);
assert_eq!(result.unwrap(), "nilnilnilfunction");
}
#[test]
fn replaces_tostring_and_format_with_address_free_versions() {
let (result, _) = run(
"local a = pcall(tostring, {})\n\
local b = pcall(string.format, '%p', 1)\n\
return tostring(a) .. tostring(b) .. string.format('%s', 'x')",
u64::MAX,
);
assert_eq!(result.unwrap(), "falsefalsex");
}
#[test]
fn stages_every_primitive_in_call_order() {
let (result, staged) = run(
"buildl.subdir('lib')\n\
buildl.rule('cc', { run = { 'cc' } })\n\
buildl.target('app', { rule = 'cc' })\n\
buildl.test('app_test', { run = { 'app' } })\n\
buildl.alias('default', 'app')\n\
buildl.option('mode', { default = 'debug' })\n\
return 'ok'",
u64::MAX,
);
assert_eq!(result.unwrap(), "ok");
let target = |name: &str, role, rule: Option<&str>, run: Option<&[&str]>| StagedTarget {
name: Written::new(name),
role,
rule: rule.map(Written::new),
run: run.map(strings),
inputs: Vec::new(),
deps: Vec::new(),
outputs: None,
env: Vec::new(),
network: NetworkAccess::Sealed,
output_source: OutputSource::Command,
freshness: Freshness::Cached,
};
let declared = |order, item| StagedDeclaration {
order: DeclarationOrder::new(order),
origin: Origin::BuildFile,
item,
};
assert_eq!(
staged.unwrap(),
StagedFile {
declarations: vec![
declared(
1,
StagedItem::Rule(StagedRule {
name: Written::new("cc"),
run: strings(&["cc"]),
description: None,
})
),
declared(
2,
StagedItem::Target(target("app", TargetRole::Build, Some("cc"), None))
),
declared(
3,
StagedItem::Target(target(
"app_test",
TargetRole::Test,
None,
Some(&["app"])
))
),
declared(
4,
StagedItem::Alias(StagedAlias {
name: Written::new("default"),
target: Written::new("app"),
})
),
declared(
5,
StagedItem::Setting(StagedSetting {
name: Written::new("mode"),
default: Written::new("debug"),
})
),
],
subdirs: vec![StagedSubdir {
path: Written::new("lib"),
order: DeclarationOrder::new(0),
}],
}
);
}
#[test]
fn folder_is_empty_at_the_root() {
let (result, staged) = run(
"buildl.target('x' .. buildl.folder(), { run = { 'x' } })\n\
return 'ok'",
u64::MAX,
);
assert_eq!(result.unwrap(), "ok");
let staged = staged.unwrap();
assert!(
matches!(
&staged.declarations[0].item,
StagedItem::Target(target) if target.name == Written::new("x")
),
"{staged:?}"
);
}
#[test]
fn a_refusal_names_the_line_and_fails_the_file() {
let (result, staged) = run("\n\nbuildl.target('app', { run = 1 })", u64::MAX);
let message = result.unwrap_err().to_string();
assert!(
message.contains(
"line 3: buildl.target 'app': field 'run' must be a list of strings, found integer"
),
"{message}"
);
assert_eq!(
staged.unwrap_err(),
(
EvaluationFailure::WrongFieldType {
field: Written::new("run"),
},
Diagnostic::new(
"line 3: buildl.target 'app': field 'run' must be a list of strings, found integer"
),
)
);
}
#[test]
fn a_swallowed_refusal_still_fails_the_file_and_stops_later_calls() {
let (result, staged) = run(
"local ok = pcall(buildl.target, 'app', { srcs = {} })\n\
local again = pcall(buildl.alias, 'default', 'app')\n\
return tostring(ok) .. ' ' .. tostring(again)",
u64::MAX,
);
assert_eq!(result.unwrap(), "false false");
let (failure, diagnostic) = staged.unwrap_err();
assert_eq!(
failure,
EvaluationFailure::UnknownField {
field: Written::new("srcs"),
}
);
assert_eq!(
diagnostic.as_str(),
"line 1: buildl.target 'app': unknown field 'srcs'"
);
}
#[test]
fn a_swallowed_sources_refusal_still_fails_the_file_and_stops_later_calls() {
let (result, staged) = run(
"local ok = pcall(buildl.sources, 'a[')\n\
local again = pcall(buildl.alias, 'default', 'app')\n\
return tostring(ok) .. ' ' .. tostring(again)",
u64::MAX,
);
assert_eq!(result.unwrap(), "false false");
let (failure, diagnostic) = staged.unwrap_err();
assert_eq!(failure, EvaluationFailure::Runtime);
assert!(
diagnostic.as_str().starts_with("line 1: buildl.sources"),
"{diagnostic:?}"
);
}
#[test]
fn a_call_while_the_staging_buffer_is_in_use_fails_instead_of_waiting() {
let staging = Arc::new(Mutex::new(Staging::new(u64::MAX)));
let held = staging.lock().unwrap();
let result = evaluate(
"local ok, message = pcall(buildl.subdir, 'lib')\n\
return tostring(ok) .. ' ' .. tostring(message)",
&staging,
);
drop(held);
let output = result.unwrap();
assert!(
output.starts_with("false ")
&& output.contains("cannot be called while another buildl call is in progress"),
"{output}"
);
assert!(staging.lock().unwrap().recorded().is_none());
}
#[test]
fn a_call_past_the_budget_is_a_staging_limit() {
let (result, staged) = run("buildl.subdir('lib')", 1);
assert!(result.is_err());
let (failure, diagnostic) = staged.unwrap_err();
assert_eq!(
failure,
EvaluationFailure::LimitReached {
limit: EvaluationLimit::Staging,
}
);
assert_eq!(
diagnostic.as_str(),
"line 1: buildl.subdir: staging budget of 1 bytes exceeded"
);
}
#[test]
fn sources_returns_a_sorted_lua_list() {
let (result, staged) = run("return table.concat(buildl.sources('*.c'), ',')", u64::MAX);
assert_eq!(result.unwrap(), "a.c,b.c");
assert_eq!(
staged.unwrap(),
StagedFile {
declarations: Vec::new(),
subdirs: Vec::new(),
}
);
}
fn plugin(name: &str) -> PluginRef {
PluginRef {
unkeyed: BTreeSet::new(),
name: PluginName::parse(name).unwrap(),
version: PluginVersion::parse("1.0.0").unwrap(),
run: BTreeSet::new(),
env: BTreeSet::new(),
}
}
#[test]
fn a_table_built_for_an_origin_stamps_its_declarations() {
let lua = Lua::new();
let staging = Arc::new(Mutex::new(Staging::new(u64::MAX)));
let sources = Sources::new(
std::path::Path::new("."),
&Directory::root(),
DeclarationLimits::default().walk_entries(),
&[],
NothingIgnored,
);
let outer = Origin::plugins(vec![plugin("outer")]).unwrap();
let nested = Origin::plugins(vec![plugin("outer"), plugin("inner")]).unwrap();
for (name, origin) in [("outer", &outer), ("nested", &nested)] {
let table =
primitives_table(&lua, &staging, &sources, &Results::none(), origin).unwrap();
lua.globals().set(name, table).unwrap();
}
lua.load(
"outer.alias('a', 'x')\n\
nested.alias('b', 'x')\n\
outer.option('mode', { default = 'debug' })",
)
.exec()
.unwrap();
let staged = std::mem::replace(&mut *staging.lock().unwrap(), Staging::new(0))
.finish()
.unwrap();
let origins: Vec<&Origin> = staged.declarations.iter().map(|d| &d.origin).collect();
assert_eq!(origins, [&outer, &nested, &outer]);
}
#[test]
fn the_file_table_still_stamps_build_file() {
let (result, staged) = run(
"buildl.alias('a', 'x')\n\
airsstack.buildl.target('t', { run = { 'x' } })\n\
return 'ok'",
u64::MAX,
);
assert_eq!(result.unwrap(), "ok");
let staged = staged.unwrap();
assert_eq!(staged.declarations.len(), 2);
assert!(
staged
.declarations
.iter()
.all(|declaration| declaration.origin == Origin::BuildFile)
);
}
#[test]
fn the_language_snapshot_excludes_buildl_airsstack_and_g() {
let lua = Lua::new();
let globals = lua.globals();
for name in ["buildl", "airsstack"] {
globals.set(name, lua.create_table().unwrap()).unwrap();
}
globals.set("answer", 42).unwrap();
record_language(&lua).unwrap();
let snapshot: Table = lua.named_registry_value(LANGUAGE_REGISTRY_KEY).unwrap();
let mut names: Vec<String> = snapshot
.pairs::<String, Value>()
.map(|pair| pair.unwrap().0)
.collect();
names.sort();
assert!(names.contains(&"answer".to_owned()), "{names:?}");
assert!(names.contains(&"math".to_owned()), "{names:?}");
for excluded in ["buildl", "airsstack", "_G", "require"] {
assert!(!names.contains(&excluded.to_owned()), "{excluded}");
}
globals.set("answer", "changed").unwrap();
assert_eq!(snapshot.get::<i64>("answer").unwrap(), 42);
let math: Table = globals.get("math").unwrap();
math.set("floor", Value::Nil).unwrap();
let recorded: Table = snapshot.get("math").unwrap();
assert!(matches!(
recorded.get::<Value>("floor").unwrap(),
Value::Function(_)
));
}
}