Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/check-agent-trailers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
with:
base-sha: ${{ github.event.pull_request.base.sha }}
head-sha: ${{ github.event.pull_request.head.sha }}

tests:
name: tests
runs-on: ubuntu-latest
Expand All @@ -41,5 +40,18 @@ jobs:
with:
node-version: 20

- name: Run tests
run: node --test tests/*.test.mjs
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Run Rust formatting, clippy, and tests
shell: bash
run: |
set -euo pipefail
NODE20="$(command -v node)"
export ROSTER_NODE20="$NODE20"
export ROSTER_TEST_NODE="$NODE20"
export GITHUB_AGENT_CONTRACTS="$GITHUB_WORKSPACE/vendor/github-agent-contracts"
cargo fmt --all -- --check
cargo clippy --all-targets --locked -- -D warnings
cargo test --locked
87 changes: 69 additions & 18 deletions rust/execution/counterfactual.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
use std::fs;
use std::path::Path;

use super::*;
Expand Down Expand Up @@ -199,16 +200,25 @@ pub(crate) async fn run_one(
} else {
approval.timeout()
};
let mut args = Vec::new();
if target.file.ends_with(".ts")
|| target.file.ends_with(".mts")
|| target.file.ends_with(".cts")
{
args.push("--import".to_owned());
args.push(tools::TS_IMPORT_HOOK.to_owned());
}
args.extend([
"--test".to_owned(),
"--test-reporter=tap".to_owned(),
format!("--test-timeout={per_test_timeout}"),
target.file.clone(),
]);
return owner
.run(
directory,
node,
&[
"--test".to_owned(),
"--test-reporter=tap".to_owned(),
format!("--test-timeout={per_test_timeout}"),
target.file.clone(),
],
&args,
&env,
approval.timeout(),
evidence::MAX_DIFF_BYTES,
Expand Down Expand Up @@ -247,24 +257,33 @@ pub(crate) async fn run_one(
.ok_or_else(|| {
unsupported("Rust integration counterfactual requires a direct tests/*.rs target")
})?;
owner
let had_lock = directory.join("Cargo.lock").is_file();
let mut args = vec!["test".to_owned()];
if had_lock {
args.push("--locked".to_owned());
}
args.push("--offline".to_owned());
args.push("--test".to_owned());
args.push(stem.to_owned());
args.push("--".to_owned());
for name in &target.names {
args.push(name.to_utf8()?);
}
args.push("--format=pretty".to_owned());
let run = owner
.run(
directory,
&cargo.executable,
&[
"test".to_owned(),
"--locked".to_owned(),
"--offline".to_owned(),
"--test".to_owned(),
stem.to_owned(),
"--".to_owned(),
"--format=pretty".to_owned(),
],
&args,
&env,
approval.timeout(),
evidence::MAX_DIFF_BYTES,
)
.await
.await;
if !had_lock {
let _ = fs::remove_file(directory.join("Cargo.lock"));
}
run
}

fn value(status: &str, reasons: &[Text], tests: Vec<Value>, runs: Vec<Value>) -> Value {
Expand Down Expand Up @@ -335,8 +354,10 @@ pub async fn run(
|| crate::planning::forbidden_read(file)
|| (file.ends_with(".rs")
&& (!owner.root().join("Cargo.toml").is_file()
|| file.starts_with("src/")
|| file
.split_once("/src/")
.or_else(|| file.split_once("/tests/"))
.is_some_and(|(sc, _)| owner.root().join(sc).join("Cargo.toml").is_file()))
&& !file.starts_with("tests/"))
{
Expand Down Expand Up @@ -441,6 +462,16 @@ pub async fn run(
let head = text(required(&changes.validation, "head")?, "Captured base revision is missing")?;
let base = scratch.base(&head, approval).await?;
scratch.overlay_tests(&base, files)?;
if targets.iter().any(|target| target.engine == Engine::Cargo)
&& !base.join("Cargo.lock").is_file()
{
let source_lock = owner.root().join("Cargo.lock");
if let Ok(meta) = fs::symlink_metadata(&source_lock)
&& meta.is_file()
{
let _ = fs::copy(&source_lock, base.join("Cargo.lock"));
}
}
let mut tests = Vec::new();
let mut runs = Vec::new();
let mut unavailable = false;
Expand All @@ -456,10 +487,30 @@ pub async fn run(
let at_candidate = run_one(owner, approval, &scratch, owner.root(), target, false).await?;
runs.push(observed(&at_base, "base", owner)?);
runs.push(observed(&at_candidate, "candidate", owner)?);
let base_output = at_base.text()?.to_utf8()?;
let base_missing_api = target.engine == Engine::Cargo
&& !at_base.timed_out
&& !at_base.overflow
&& at_base.exit.is_some_and(|code| code != 0)
&& base_output.contains(&target.file)
&& [
"error[E0599]",
"error[E0425]",
"error[E0412]",
"error[E0432]",
"error[E0433]",
"error[E0369]",
"error[E0277]",
]
.iter()
.any(|code| base_output.contains(code));
let mut target_red_count = 0_usize;
for name in &target.names {
let base = verdict(&at_base, name, target.engine)?;
let candidate = verdict(&at_candidate, name, target.engine)?;
let mut base = verdict(&at_base, name, target.engine)?;
if base == Verdict::Missing && candidate == Verdict::Pass && base_missing_api {
base = Verdict::Fail;
}
unavailable |= base == Verdict::Missing || candidate == Verdict::Missing;
if base == Verdict::Fail && candidate == Verdict::Pass {
target_red_count += 1;
Expand Down
27 changes: 27 additions & 0 deletions rust/execution/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,24 @@ pub fn capture(
) -> Result<Snapshot, Error> {
let root = paths::absolute(root)?;
secure::check_components(&root)?;
let is_dotnet_tree = fs::read_dir(&root)
.ok()
.into_iter()
.flatten()
.flatten()
.any(|entry| {
let s = entry.file_name().to_string_lossy().into_owned();
s.ends_with(".sln") || s.ends_with(".csproj")
})
|| fs::read_dir(root.join("src"))
.ok()
.into_iter()
.flatten()
.flatten()
.any(|entry| entry.path().is_dir() && entry.path().join("bin").is_dir());
let is_maven_tree = root.join("pom.xml").is_file();
let is_gradle_tree =
root.join("build.gradle").is_file() || root.join("build.gradle.kts").is_file();
let root_identity = paths::file_information(&root)?.identity;
let mut queue = vec![PathBuf::new()];
let mut entries = BTreeMap::new();
Expand All @@ -265,6 +283,15 @@ pub fn capture(
if name == ".git"
|| ["RESULT.md", "REVIEW.md"].contains(&name.as_str())
|| ignored_notebook(&name, memory)
|| name
.split('/')
.any(|part| matches!(part, "obj" | "__pycache__" | ".pytest_cache"))
|| (is_dotnet_tree && name.split('/').any(|part| part == "bin"))
|| (is_maven_tree && name.split('/').any(|part| part == "target"))
|| (is_gradle_tree
&& name
.split('/')
.any(|part| matches!(part, "build" | ".gradle")))
{
continue;
}
Expand Down
36 changes: 30 additions & 6 deletions rust/execution/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ pub fn consumer_requires_modern_node(root: &std::path::Path) -> bool {
if domain::is_text(pkg.get("name"), "github-agent-roster") {
return false;
}
if root.join("tsconfig.json").is_file() {
return true;
}
let Some(engine_str) = pkg
.get("engines")
.and_then(|e| e.get("node"))
Expand All @@ -132,9 +135,10 @@ pub fn relevant_tests(files: &[String]) -> Result<Vec<String>, Error> {
if docs_only(files)? {
return Ok(Vec::new());
}
let pattern =
regex(r"(?:^tests?/.+\.[cm]?js$|(?:^|/)(?:test(?:[._-][^/]+)?|[^/]+[._-]test)\.[cm]?js$)")?;
let extension = regex(r"\.[cm]?js$")?;
let pattern = regex(
r"(?:^tests?/.+\.[cm]?[jt]s$|(?:^|/)(?:test(?:[._-][^/]+)?|[^/]+[._-](?:test|spec))\.[cm]?[jt]s$)",
)?;
let extension = regex(r"\.[cm]?[jt]s$")?;
let mut tests = Vec::new();
for file in files {
let file = file.replace('\\', "/");
Expand All @@ -143,9 +147,29 @@ pub fn relevant_tests(files: &[String]) -> Result<Vec<String>, Error> {
}
let base = file.rsplit('/').next().unwrap_or("");
let base = extension.replace(base, "");
let candidate = format!("tests/{base}.test.mjs");
if !base.is_empty() && file.starts_with("src/") && !tests.contains(&candidate) {
tests.push(candidate);
if !base.is_empty() && file.starts_with("src/") {
if file.ends_with(".ts") || file.ends_with(".mts") || file.ends_with(".cts") {
let mut candidates = vec![
format!("src/test/{base}.test.ts"),
format!("src/test/{base}.spec.ts"),
format!("test/{base}.test.ts"),
format!("tests/{base}.test.ts"),
];
if let Some((dir, _)) = file.rsplit_once('/') {
candidates.push(format!("{dir}/{base}.test.ts"));
candidates.push(format!("{dir}/{base}.spec.ts"));
}
for candidate in candidates {
if !tests.contains(&candidate) {
tests.push(candidate);
}
}
} else {
let candidate = format!("tests/{base}.test.mjs");
if !tests.contains(&candidate) {
tests.push(candidate);
}
}
}
}
Ok(tests)
Expand Down
32 changes: 29 additions & 3 deletions rust/execution/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ pub fn declared_test_names(source: &Text) -> Vec<Text> {
names
}

fn bounded_output(units: &[u16], limit: usize) -> Vec<u16> {
if units.len() <= limit {
return units.to_vec();
}
let marker = Text::from("\n...[truncated]...\n").0;
if limit <= marker.len() {
return units.iter().copied().take(limit).collect();
}
let budget = limit - marker.len();
let head = budget / 3;
let tail = budget - head;
let mut out = Vec::with_capacity(limit);
out.extend(units.iter().copied().take(head));
out.extend_from_slice(&marker);
out.extend(units.iter().copied().skip(units.len().saturating_sub(tail)));
out
}

pub fn test_evidence(tests: &Value, changed: &[(String, Vec<Text>)]) -> Result<Text, Error> {
let output = ["stdout", "stderr"]
.iter()
Expand Down Expand Up @@ -190,8 +208,15 @@ pub fn test_evidence(tests: &Value, changed: &[(String, Vec<Text>)]) -> Result<T
}
changed_text.0.truncate(4000);
let exit = field_text(tests, "exit_code", "undefined")?;
let observed_cmd = list(tests, "commands")
.last()
.and_then(Value::as_string)
.and_then(|t| t.to_utf8().ok())
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "node --test".to_owned());
let mut evidence = Text::from(
format!("node --test exited {exit}\nCommand: node --test\nExit code: {exit}\n").as_str(),
format!("{observed_cmd} exited {exit}\nCommand: {observed_cmd}\nExit code: {exit}\n")
.as_str(),
);
if !totals.is_empty() {
evidence.push_str("Totals:\n");
Expand All @@ -210,7 +235,8 @@ pub fn test_evidence(tests: &Value, changed: &[(String, Vec<Text>)]) -> Result<T
evidence.0.extend(if output.is_empty() {
Text::from("(no output)").0
} else {
output.encode_utf16().take(1200).collect()
let units: Vec<u16> = output.encode_utf16().collect();
bounded_output(&units, 1200)
});
Ok(evidence)
}
Expand Down Expand Up @@ -330,7 +356,7 @@ pub fn render(
body.push_str("Output:\n");
for name in ["stdout", "stderr"] {
if let Some(source) = tests.get(name).and_then(Value::as_string) {
body.0.extend(source.0.iter().take(1200));
body.0.extend(bounded_output(&source.0, 1200));
body.0.push(10);
}
}
Expand Down
12 changes: 11 additions & 1 deletion rust/execution/self_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,17 @@ impl Request {
.and_then(Value::as_string)
.and_then(|t| t.to_utf8().ok())
{
let trimmed: String = out_str.trim().chars().take(1200).collect();
let clean = out_str.trim();
let chars: Vec<char> = clean.chars().collect();
let trimmed: String = if chars.len() <= 1200 {
clean.to_owned()
} else {
let marker = "\n...[truncated]...\n";
let head: String = chars.iter().take(400).collect();
let tail: String =
chars.iter().skip(chars.len().saturating_sub(780)).collect();
format!("{head}{marker}{tail}")
};
if !trimmed.is_empty() {
stdout_snip = format!("Observed test output:\n{trimmed}\n\n");
}
Expand Down
Loading
Loading