Files
DanConwayDev e6c8db5a35 fix(ci): retain test failure details in diagnostic tails
CI combined the libtest stdout before Cargo stderr, leaving the final tail with only a generic test failure. Redirect test stdout into stderr so assertion failures and Cargo diagnostics share one stream.

Keep the command exit status and existing test selection unchanged. This improves diagnostic tails without changing provider capture or guaranteeing that arbitrary verbose failures fit a bounded tail.

Validation: Nix parsing, formatting and diff checks passed. A mock cargo invocation confirmed both streams are captured on stderr and exit status 101 is preserved.

Assisted-by: GPT-6
2026-10-27 10:27:25 +00:00

69 lines
2.7 KiB
Nix

{ pkgs, craneLib, rustToolchain, src, version }:
let
source = craneLib.cleanCargoSource src;
vendor = craneLib.vendorCargoDeps { src = source; };
objects = craneLib.buildDepsOnly {
pname = "ngit-grasp-ci-dependencies";
version = "0.0.0";
src = source;
strictDeps = true;
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl ];
CARGO_PROFILE = "dev";
CARGO_INCREMENTAL = "0";
CARGO_PROFILE_DEV_DEBUG = "0";
cargoExtraArgs = "--workspace --locked";
installCargoArtifactsMode = "use-zstd";
doCompressAndInstallFullArchive = true;
};
tools = with pkgs; [
rustToolchain stdenv.cc pkg-config git bash coreutils gnumake
gnused gnugrep gnutar gzip findutils
];
command = name: script: pkgs.writeShellApplication {
inherit name;
runtimeInputs = tools;
runtimeEnv = {
CC = if pkgs.stdenv.cc.isClang then "clang" else "gcc";
PKG_CONFIG = "pkg-config";
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
};
text = script;
};
rust = name: script: command name ''
export AR="ar" CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0
export NGIT_BUILD_REVISION="''${NGIT_CI_COMMIT_SHA:-$(git rev-parse HEAD)}"
export CARGO_TARGET_DIR="''${CARGO_TARGET_DIR:-$PWD/target}"
if [[ ! -e "$CARGO_TARGET_DIR/.rustc_info.json" ]]; then
mkdir -p "$CARGO_TARGET_DIR"
${pkgs.gnutar}/bin/tar --use-compress-program=${pkgs.zstd}/bin/zstd \
-xf ${objects}/target.tar.zst -C "$CARGO_TARGET_DIR"
fi
export CARGO_HOME="$CARGO_TARGET_DIR/ci-cargo-home"
mkdir -p "$CARGO_HOME"
cp --remove-destination ${vendor}/config.toml "$CARGO_HOME/config.toml"
${script}
'';
in {
dependencies = pkgs.linkFarm "ngit-grasp-ci-dependencies" ([
{ name = "objects"; path = objects; }
{ name = "sources"; path = vendor; }
{ name = "openssl"; path = pkgs.openssl.dev; }
] ++ map (tool: { name = tool.name; path = tool; }) tools);
commands = {
format = command "format" "cargo fmt --all -- --check";
compile = rust "compile" "cargo test --workspace --locked --offline --no-run";
lint = rust "lint" "cargo clippy --workspace --all-targets --locked --offline -- -D warnings";
tests = rust "tests" ''
# Keep intentionally hostile Git defaults private to this test step.
export HOME="$CARGO_TARGET_DIR/test-home"
mkdir -p "$HOME"
${builtins.readFile ./ci-hostile-git.sh}
# Keep libtest failure details with Cargo diagnostics in the CI log tail.
cargo test --workspace --locked --offline 1>&2
'';
};
container = import ./ci-container.nix { inherit pkgs version; };
}