diff --git a/.github/ISSUE_TEMPLATE/alpha-feedback.md b/.github/ISSUE_TEMPLATE/alpha-feedback.md index b05cacdb0..d437d803c 100644 --- a/.github/ISSUE_TEMPLATE/alpha-feedback.md +++ b/.github/ISSUE_TEMPLATE/alpha-feedback.md @@ -1,20 +1,20 @@ --- name: Alpha feedback -about: Report a wrong result, a crash or a surprise from an alrunner alpha or edge build +about: Report a wrong result, a crash or a surprise from an al-runner alpha or edge build title: "" labels: alpha-feedback --- A wrong result is the most useful report: a test that passes or fails in -alrunner but behaves differently on real Business Central. +al-runner but behaves differently on real Business Central. -**alrunner version** (output of `alrunner --version`) +**al-runner version** (output of `al-runner --version`) **Operating system** (for example Windows 11 x64, macOS 15 arm64, Ubuntu 24.04) **Command** (the full command line) -**What alrunner did** (outcome: passed, failed, not run with its reason, crash, or wrong output; paste the lines that matter) +**What al-runner did** (outcome: passed, failed, not run with its reason, crash, or wrong output; paste the lines that matter) **What you expected** diff --git a/.github/workflows/build-packages.yml b/.github/workflows/build-packages.yml index 9e3e6cd4f..361421276 100644 --- a/.github/workflows/build-packages.yml +++ b/.github/workflows/build-packages.yml @@ -1,6 +1,6 @@ name: Build packages -# Builds alrunner for the three alpha targets, smoke tests each binary, packages it and attests it. +# Builds al-runner for the three alpha targets, smoke tests each binary, packages it and attests it. # Used by release-tag.yml (numbered alphas, and the dry run) and edge.yml (the rolling edge build). # Output: the artifact "packages" holding the archives and one SHA256SUMS. Nothing of Microsoft's # is built in or downloaded here: the smoke test runs a fixture project of this repository. @@ -85,18 +85,18 @@ jobs: - name: Smoke test shell: bash run: | - exe=target/${{ matrix.target }}/release/alrunner + exe=target/${{ matrix.target }}/release/al-runner [ "${{ matrix.ext }}" = zip ] && exe="$exe.exe" release/smoke.sh "$exe" - name: Package shell: bash run: | - name="alrunner-${{ inputs.label }}-${{ matrix.target }}" + name="al-runner-${{ inputs.label }}-${{ matrix.target }}" mkdir -p stage dist if [ "${{ matrix.ext }}" = zip ]; then - cp "target/${{ matrix.target }}/release/alrunner.exe" stage/ + cp "target/${{ matrix.target }}/release/al-runner.exe" stage/ else - cp "target/${{ matrix.target }}/release/alrunner" stage/ + cp "target/${{ matrix.target }}/release/al-runner" stage/ fi cp LICENSE stage/LICENSE cp release/README.txt stage/README.txt @@ -133,7 +133,7 @@ jobs: - name: SHA256SUMS and install scripts run: | cp release/install.sh release/install.ps1 dist/ - (cd dist && sha256sum alrunner-*.tar.xz alrunner-*.zip > SHA256SUMS && cat SHA256SUMS) + (cd dist && sha256sum al-runner-*.tar.xz al-runner-*.zip > SHA256SUMS && cat SHA256SUMS) - uses: actions/upload-artifact@v4 with: name: packages diff --git a/.github/workflows/edge.yml b/.github/workflows/edge.yml index 65e8e9864..6ba4343d5 100644 --- a/.github/workflows/edge.yml +++ b/.github/workflows/edge.yml @@ -48,7 +48,7 @@ jobs: # caller's event (schedule or workflow_dispatch), so this input is checked first. CALL_SHA: ${{ inputs.sha }} run: | - # The UTC date of this build, shown in `alrunner --version` as +edge.YYYYMMDD. + # The UTC date of this build, shown in `al-runner --version` as +edge.YYYYMMDD. echo "version_suffix=+edge.$(date -u +%Y%m%d)" >> "$GITHUB_OUTPUT" if [ -n "$CALL_SHA" ]; then echo "Nightly build of $CALL_SHA." @@ -135,8 +135,8 @@ jobs: done gh release upload edge dist/* --clobber gh release edit edge --prerelease --latest=false --draft=false \ - --title "alrunner edge ($(echo "$SHA" | cut -c1-9))" --notes-file notes.md + --title "al-runner edge ($(echo "$SHA" | cut -c1-9))" --notes-file notes.md else gh release create edge dist/* --prerelease --latest=false --verify-tag \ - --title "alrunner edge ($(echo "$SHA" | cut -c1-9))" --notes-file notes.md + --title "al-runner edge ($(echo "$SHA" | cut -c1-9))" --notes-file notes.md fi diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index 11608a5c3..d286f7a4a 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -4,7 +4,7 @@ name: Release # The workflow checks the tag, runs the CI checks, builds and smoke tests the three targets and # creates a normal GitHub release (not a draft, not a pre-release) marked "latest", so that # `mise use github:aldevtools/BusinessCentral.AL.Runner` and `mise up` find it (owner decision 2026-10-20). -# Assets: alrunner--.tar.xz or .zip, SHA256SUMS, install.sh, install.ps1. +# Assets: al-runner--.tar.xz or .zip, SHA256SUMS, install.sh, install.ps1. # workflow_dispatch is a dry run: it builds and packages but creates no release. on: @@ -84,12 +84,12 @@ jobs: VERSION: ${{ needs.plan.outputs.version }} run: | mkdir bin - tar -C bin -xJf "dist/alrunner-$VERSION-x86_64-unknown-linux-musl.tar.xz" - printed="$(./bin/alrunner --version)" + tar -C bin -xJf "dist/al-runner-$VERSION-x86_64-unknown-linux-musl.tar.xz" + printed="$(./bin/al-runner --version)" echo "$printed" case "$printed" in - "alrunner $VERSION "*|"alrunner $VERSION") ;; - *) echo "::error::alrunner --version prints '$printed', not version $VERSION of tag $GITHUB_REF_NAME"; exit 1 ;; + "al-runner $VERSION "*|"al-runner $VERSION") ;; + *) echo "::error::al-runner --version prints '$printed', not version $VERSION of tag $GITHUB_REF_NAME"; exit 1 ;; esac - name: Create the release env: @@ -98,7 +98,7 @@ jobs: VERSION: ${{ needs.plan.outputs.version }} run: | cat > notes.md < ureq::Agent { let config = ureq::Agent::config_builder() .timeout_global(Some(std::time::Duration::from_secs(300))) .timeout_connect(Some(std::time::Duration::from_secs(20))) - .user_agent(concat!("al-runtime-rs/", env!("CARGO_PKG_VERSION"))) + .user_agent(concat!("al-runner/", env!("CARGO_PKG_VERSION"))) .http_status_as_error(false) .build(); ureq::Agent::new_with_config(config) diff --git a/crates/al-host/src/testdata.rs b/crates/al-host/src/testdata.rs index 6cc1591e6..5eee28bb0 100644 --- a/crates/al-host/src/testdata.rs +++ b/crates/al-host/src/testdata.rs @@ -1,7 +1,7 @@ //! Test data from a database file (ADR-020 point 3): the capability a host gives the runtime to //! read the rows of one table of a restored company, and the counts of what a run took from it. //! -//! The core never sees a file. A host (`alrunner`) implements [`TableProvider`] over a BC database +//! The core never sees a file. A host (`al-runner`) implements [`TableProvider`] over a BC database //! backup; the runtime asks it for a table the first time a session touches that table. The //! provider answers in plain typed cells under the table's SQL column names. Mapping those names //! to the fields of the compiled program is the runtime's job (the program is the schema, never a diff --git a/crates/al-test-cli/src/main.rs b/crates/al-test-cli/src/main.rs index e4b60e038..dd7c6016a 100644 --- a/crates/al-test-cli/src/main.rs +++ b/crates/al-test-cli/src/main.rs @@ -76,7 +76,7 @@ fn run() -> Result { } // The corpus pins that real BC's web address in its CI is http, has a port and the path /BC, and that its host is // not `localhost` (session/lt-geturl-shape/GetUrlShape.al:283); the host name itself is masked there and stays the - // host setting of ADR-042. So the corpus tool runs with an address of that shape instead of alrunner's default. + // host setting of ADR-042. So the corpus tool runs with an address of that shape instead of al-runner's default. al_test_cli::host::set_server_url(Some(CORPUS_SERVER_URL.into())); if let Some(dir) = &args.files_dir { al_test_cli::host::set_files_dir(dir.clone()); @@ -516,7 +516,7 @@ fn run_version( source_root: Some(root.to_path_buf()), // Only the user's folders. ADR-014 section 3, step 2 (the service folder of the platform package the run // selected) is skipped: the artifact cache holds no service folder, and BcContainerHelper's - // `~/.bcartifacts.cache/sandbox`, which `alrunner` reads, is a machine's own folder, often of another build + // `~/.bcartifacts.cache/sandbox`, which `al-runner` reads, is a machine's own folder, often of another build // of the major. Read here, it made a corpus case pass or be refused by what HOME held (99100 // AL_JsonTextWriter_SimpleObject needs Newtonsoft.Json from it), so one build gave two results // (corpus_harness.rs `outcomes_do_not_depend_on_threads_or_home`). A missing assembly is refused, as on CI. diff --git a/crates/al-testkit/Cargo.toml b/crates/al-testkit/Cargo.toml index bf77f1353..be0f20671 100644 --- a/crates/al-testkit/Cargo.toml +++ b/crates/al-testkit/Cargo.toml @@ -15,5 +15,5 @@ al-ir.workspace = true al-testrun = { workspace = true, optional = true } [features] -# `outcomes_in`: run the tests of a codeunit the way `alrunner test` does (al-testrun). +# `outcomes_in`: run the tests of a codeunit the way `al-runner test` does (al-testrun). runner = ["dep:al-testrun"] diff --git a/crates/al-testkit/src/lib.rs b/crates/al-testkit/src/lib.rs index a38cdde53..0b934fe9e 100644 --- a/crates/al-testkit/src/lib.rs +++ b/crates/al-testkit/src/lib.rs @@ -148,7 +148,7 @@ pub fn run_with(src: &str, object: &str, routine: &str, args: Vec) -> Res b.call(oi, ri, args) } -/// With the `runner` feature: compiles `src` and runs the tests of the codeunit named `codeunit` the way `alrunner test` does +/// With the `runner` feature: compiles `src` and runs the tests of the codeunit named `codeunit` the way `al-runner test` does /// (one session per codeunit, the install code first), giving each test's name and outcome. #[cfg(feature = "runner")] pub fn outcomes_in(src: &str, codeunit: &str) -> Vec<(String, al_testrun::Outcome)> { diff --git a/crates/al-testrun/src/baseline_cache.rs b/crates/al-testrun/src/baseline_cache.rs index 9989a140c..8bbdabe6e 100644 --- a/crates/al-testrun/src/baseline_cache.rs +++ b/crates/al-testrun/src/baseline_cache.rs @@ -2,7 +2,7 @@ //! apps and `Company-Initialize` takes longer than reading what they leave, and it is the same for the same program //! and the same world around it. The entry lives in the compile cache's folder (`/compile/`, file extension //! `albr`), is tied to the same build of the runtime, is pruned with the other entries, and goes with -//! `alrunner cache clear` and is replaced by `--rebuild-compile-cache`. There is no second cache. +//! `al-runner cache clear` and is replaced by `--rebuild-compile-cache`. There is no second cache. //! //! The file is the [`BaselineRun`]: the data the install code left, the notes about roots that did not run to their //! end, and the instant the run began. The file is written to a name of its own and renamed, so a reader never sees diff --git a/crates/al-testrun/src/cache_gc.rs b/crates/al-testrun/src/cache_gc.rs index 7ed839a17..ac1f8cd03 100644 --- a/crates/al-testrun/src/cache_gc.rs +++ b/crates/al-testrun/src/cache_gc.rs @@ -1,6 +1,6 @@ //! Cleanup of the compile cache folder (ADR-022, "Cleanup of old builds"). //! -//! Every entry file name starts with the tag of the alrunner build that wrote it (`al_cache::build_tag`), and a +//! Every entry file name starts with the tag of the al-runner build that wrote it (`al_cache::build_tag`), and a //! cache hit sets the file's modification time to now. So the cleanup needs `stat` only, never a file read: //! //! - an entry of another build (or from before the tag existed) goes after 7 days unused: several builds run on one diff --git a/crates/al-testrun/src/coverage.rs b/crates/al-testrun/src/coverage.rs index 72cfa840b..1429d0f3b 100644 --- a/crates/al-testrun/src/coverage.rs +++ b/crates/al-testrun/src/coverage.rs @@ -1,4 +1,4 @@ -//! Statement coverage for `alrunner test --coverage`: the statements of the workspace's apps, and a per-thread sink in +//! Statement coverage for `al-runner test --coverage`: the statements of the workspace's apps, and a per-thread sink in //! which a test codeunit's run leaves what each of its tests executed. //! //! A statement is a `Stmt::Pos` marker of the lowered program (`ir::Program::positions`); the VM counts how often each diff --git a/crates/al-testrun/src/dotnet.rs b/crates/al-testrun/src/dotnet.rs index 82778bd94..da8d1bfa4 100644 --- a/crates/al-testrun/src/dotnet.rs +++ b/crates/al-testrun/src/dotnet.rs @@ -467,7 +467,7 @@ fn resolve(cfg: &SidecarConfig) -> Result { Ok(Resolved { dotnet, sidecar }) } -/// The sidecar's source files, built into this binary, so a copied or installed `alrunner` can +/// The sidecar's source files, built into this binary, so a copied or installed `al-runner` can /// find or build its helper without the repository (the cache is keyed by the same hash as the /// repository's own build). A test keeps the list equal to the folder. const EMBEDDED: &[(&str, &str)] = &[ diff --git a/crates/al-testrun/src/events.rs b/crates/al-testrun/src/events.rs index 36dc67542..328395757 100644 --- a/crates/al-testrun/src/events.rs +++ b/crates/al-testrun/src/events.rs @@ -1,5 +1,5 @@ //! What a run tells while it runs: one event per test as it finishes, and a flag that stops the run after the current -//! test (`alrunner serve`, ADR-028). Installed per thread by the code that runs a test codeunit, so the signatures of +//! test (`al-runner serve`, ADR-028). Installed per thread by the code that runs a test codeunit, so the signatures of //! the run functions did not change. use crate::Outcome; diff --git a/crates/al-testrun/src/explain.rs b/crates/al-testrun/src/explain.rs index 1d9879de7..b28793d74 100644 --- a/crates/al-testrun/src/explain.rs +++ b/crates/al-testrun/src/explain.rs @@ -91,7 +91,7 @@ pub fn render(head: &str, outcome: &Outcome, oracle: &str, detail: Option<&TestD render_with(head, Some(oracle), outcome, detail) } -/// The same for a run that has no oracle (`alrunner test --explain`). +/// The same for a run that has no oracle (`al-runner test --explain`). pub fn render_without_oracle(head: &str, outcome: &Outcome, detail: Option<&TestDetail>) -> String { render_with(head, None, outcome, detail) } diff --git a/crates/al-testrun/src/junit.rs b/crates/al-testrun/src/junit.rs index 2534a5f99..fb89b3344 100644 --- a/crates/al-testrun/src/junit.rs +++ b/crates/al-testrun/src/junit.rs @@ -1,6 +1,6 @@ //! The JUnit XML of a run, written in one place (ADR-037 item 6). The two command lines write two dialects of it, //! and both stay byte for byte what they were: `Dialect::Oracle` is the file `al-test-cli --junit` writes and the -//! oracle parser reads back; `Dialect::Runner` is the v2-shaped file `alrunner test --junit` writes. Each caller +//! oracle parser reads back; `Dialect::Runner` is the v2-shaped file `al-runner test --junit` writes. Each caller //! builds the suites (how tests are grouped differs) and this module writes them. use crate::Outcome; diff --git a/crates/al-testrun/src/runtime/compiled.rs b/crates/al-testrun/src/runtime/compiled.rs index 9837ca3ee..158063cea 100644 --- a/crates/al-testrun/src/runtime/compiled.rs +++ b/crates/al-testrun/src/runtime/compiled.rs @@ -21,29 +21,29 @@ pub struct RunOptions { /// to read them (`deps::load_project_with`). The run reads what it needs; a missing entry means /// the app has its text. pub lazy: Vec>, - /// `alrunner test --isolation`: the isolation of every test codeunit, instead of the runner's property (`None`: the runner's, + /// `al-runner test --isolation`: the isolation of every test codeunit, instead of the runner's property (`None`: the runner's, /// else Codeunit). pub isolation: Option, - /// Count how often each statement of the workspace's apps runs, per test (`alrunner test --coverage`). + /// Count how often each statement of the workspace's apps runs, per test (`al-runner test --coverage`). /// Off, a run pays one branch per statement. pub coverage: bool, - /// A scratch run (`alrunner serve`'s `execute`): the `OnRun` trigger of one codeunit per `SuiteRun`'s app runs + /// A scratch run (`al-runner serve`'s `execute`): the `OnRun` trigger of one codeunit per `SuiteRun`'s app runs /// instead of the tests, and the text of its `Message` calls is kept in `TestResult::messages`. pub execute: bool, - /// Capture the values of the locals and the loops of the apps' code, per test (`alrunner serve`, ADR-030). Off, + /// Capture the values of the locals and the loops of the apps' code, per test (`al-runner serve`, ADR-030). Off, /// a run pays nothing for it. pub capture: al_vm::CaptureConfig, /// Callbacks while the run goes on: a line per test as it finishes, and a flag that stops the run after the - /// current test (`alrunner serve`). + /// current test (`al-runner serve`). pub hooks: crate::events::Hooks, /// Where the run clock of a test codeunit starts (codeunit id to Unix milliseconds), instead of now: the corpus /// oracle recorded values derived from `Today` on the day real BC ran, so the harness starts each codeunit at the /// time of that codeunit's suite in the oracle. pub clock_starts: Option>>, - /// Do not print the `baseline:` detail lines to stderr (`alrunner test` prints them only with `--verbose`). The counts + /// Do not print the `baseline:` detail lines to stderr (`al-runner test` prints them only with `--verbose`). The counts /// stay in `Phases::baseline_roots`. Default `false`: print, as the corpus job does. pub quiet_baseline: bool, - /// `alrunner impact-index build` (ADR-043 step 2): note per test what it raised and touched + /// `al-runner impact-index build` (ADR-043 step 2): note per test what it raised and touched /// (`TestResult::impact`), and what the install baseline raised and touched (`CorpusRuntime::impact_baseline`). /// The baseline then runs instead of being read from the compile cache. Off, a run pays one branch per raise and /// record operation. diff --git a/crates/al-testrun/src/runtime/run.rs b/crates/al-testrun/src/runtime/run.rs index b7808b1bd..1087a1555 100644 --- a/crates/al-testrun/src/runtime/run.rs +++ b/crates/al-testrun/src/runtime/run.rs @@ -403,7 +403,7 @@ pub(crate) fn run_codeunit_core( Err(why) => Ok(Err(Signal::Unsupported(why))), Ok(()) => std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { // A debugging aid: the named test panics here, to show that a panic ends one codeunit and not the - // process (tests of `alrunner serve`). Not documented for users. + // process (tests of `al-runner serve`). Not documented for users. if std::env::var("ALRUNNER_DEBUG_PANIC_IN").is_ok_and(|n| n == routine.name) { panic!("requested by ALRUNNER_DEBUG_PANIC_IN"); } diff --git a/crates/al-testrun/tests/execute.rs b/crates/al-testrun/tests/execute.rs index eed6f29b1..b2ce3cc28 100644 --- a/crates/al-testrun/tests/execute.rs +++ b/crates/al-testrun/tests/execute.rs @@ -1,4 +1,4 @@ -//! A scratch run (`alrunner serve`'s `execute`): the `OnRun` trigger of one codeunit per app runs, and the +//! A scratch run (`al-runner serve`'s `execute`): the `OnRun` trigger of one codeunit per app runs, and the //! text of its `Message` calls comes back with the result. use al_sema::workspace::AppSource; diff --git a/crates/al-vm/src/callstack.rs b/crates/al-vm/src/callstack.rs index fc7d7d49d..2e32ecfe6 100644 --- a/crates/al-vm/src/callstack.rs +++ b/crates/al-vm/src/callstack.rs @@ -34,7 +34,7 @@ impl Session { } /// Sets the frames of the test runner that stand below a test's frames (the corpus job and - /// `alrunner` set them; a session without a runner has none). + /// `al-runner` set them; a session without a runner has none). pub fn set_runner_frames(&mut self, frames: String) { self.runner_frames = frames; } diff --git a/crates/al-vm/src/impact.rs b/crates/al-vm/src/impact.rs index 41c44dc67..d24b352bb 100644 --- a/crates/al-vm/src/impact.rs +++ b/crates/al-vm/src/impact.rs @@ -1,4 +1,4 @@ -//! The per-test record of what the code raised and touched, for the impact index of `alrunner impact-index build` +//! The per-test record of what the code raised and touched, for the impact index of `al-runner impact-index build` //! (ADR-043 section 2.2). Off unless asked for (`Session::enable_impact_trace`): then each note costs one branch. //! //! What is noted, and where: @@ -46,7 +46,7 @@ impl Touches { } impl crate::Session { - /// Starts noting what the code raises and touches (`alrunner impact-index build`). + /// Starts noting what the code raises and touches (`al-runner impact-index build`). pub fn enable_impact_trace(&mut self) { *self.coverage.impact.borrow_mut() = Some(Touches::default()); self.coverage.impact_on = true; diff --git a/crates/al-vm/src/lib.rs b/crates/al-vm/src/lib.rs index 920b89dd4..25a520705 100644 --- a/crates/al-vm/src/lib.rs +++ b/crates/al-vm/src/lib.rs @@ -529,7 +529,7 @@ pub struct Session { pub test_object: Option, /// The `TestHttpRequestPolicy` of the running test codeunit (`None`: the property is absent). pub(crate) http_policy: Option<&'static str>, - /// A scratch run (`alrunner serve`'s `execute`): the text of every `Message` raised outside a test + /// A scratch run (`al-runner serve`'s `execute`): the text of every `Message` raised outside a test /// method, in order. `None`: such a call is refused, as BC's behaviour then is not pinned. pub(crate) scratch_messages: Option>, /// Value capture and loop tracking (`capture.rs`); `None`: off, and the statements run as they always did. @@ -1574,7 +1574,7 @@ impl Session { self.stop.clone() } - /// Starts counting how often each statement runs (`alrunner test --coverage`). + /// Starts counting how often each statement runs (`al-runner test --coverage`). pub fn enable_coverage(&mut self) { self.coverage.coverage_counts = Some((Vec::new(), Vec::new())); } diff --git a/crates/al-vm/src/state.rs b/crates/al-vm/src/state.rs index 2255af33e..5d06afd70 100644 --- a/crates/al-vm/src/state.rs +++ b/crates/al-vm/src/state.rs @@ -126,12 +126,12 @@ pub(crate) type ViewFilterKey = (usize, i32, String); pub(crate) struct CoverageState { /// `CodeCoverageLog` is recording. pub(crate) code_coverage: bool, - /// `alrunner test --coverage`: runs per statement position (`Program::positions`) since the last + /// `al-runner test --coverage`: runs per statement position (`Program::positions`) since the last /// [`Session::take_coverage`]. `None` when coverage is off, which costs one branch per statement. pub(crate) coverage_counts: Option<(Vec, Vec)>, /// What recording noted (`platform/coverage.rs`). pub(crate) recorder: platform::coverage::Recorder, - /// `alrunner impact-index build`: what the code raised and touched (`impact.rs`). `None` when off. A cell, so + /// `al-runner impact-index build`: what the code raised and touched (`impact.rs`). `None` when off. A cell, so /// that the readers that take `&self` (a report's schema) can note too. pub(crate) impact: std::cell::RefCell>, /// `impact` is on: the one branch a note costs when it is off. diff --git a/crates/alrunner-cli/Cargo.toml b/crates/alrunner-cli/Cargo.toml index 54f768e4b..011ca3260 100644 --- a/crates/alrunner-cli/Cargo.toml +++ b/crates/alrunner-cli/Cargo.toml @@ -5,10 +5,10 @@ edition.workspace = true license.workspace = true rust-version.workspace = true build = "build.rs" -description = "alrunner: the user command line of AL Runner v3 (ADR-016)" +description = "al-runner: the user command line of AL Runner v3 (ADR-016)" [[bin]] -name = "alrunner" +name = "al-runner" path = "src/main.rs" [features] diff --git a/crates/alrunner-cli/build.rs b/crates/alrunner-cli/build.rs index f39733a3d..30ea84803 100644 --- a/crates/alrunner-cli/build.rs +++ b/crates/alrunner-cli/build.rs @@ -1,4 +1,4 @@ -//! Puts the commit into `alrunner --version`: `ALRUNNER_COMMIT` is the short hash, or "unknown" +//! Puts the commit into `al-runner --version`: `ALRUNNER_COMMIT` is the short hash, or "unknown" //! when the source has no git history (a source archive). CI may set `ALRUNNER_COMMIT` itself. //! `ALRUNNER_VERSION` is the Cargo version plus the optional `ALRUNNER_VERSION_SUFFIX` (an edge //! build sets `+edge.YYYYMMDD`). A suffix that is not empty and does not start with `+` is ignored. diff --git a/crates/alrunner-cli/src/args.rs b/crates/alrunner-cli/src/args.rs index 66f78a26a..385eb2042 100644 --- a/crates/alrunner-cli/src/args.rs +++ b/crates/alrunner-cli/src/args.rs @@ -1,4 +1,4 @@ -//! The command line of `alrunner` (ADR-016 section 2): parsing and the help text. +//! The command line of `al-runner` (ADR-016 section 2): parsing and the help text. use std::path::PathBuf; @@ -7,33 +7,33 @@ use std::path::PathBuf; pub enum Command { Help, Version, - /// `alrunner --list-assumptions`: the registry of unprobed assumptions with the counts of the last run. + /// `al-runner --list-assumptions`: the registry of unprobed assumptions with the counts of the last run. ListAssumptions(Option), Test(Box), - /// `alrunner serve`: the options every request's `alrunner test` run gets (ADR-028). + /// `al-runner serve`: the options every request's `al-runner test` run gets (ADR-028). Serve(Vec), - /// `alrunner warm`: find (or download) the demo backup and build its index. + /// `al-runner warm`: find (or download) the demo backup and build its index. Warm(Box), - /// `alrunner cache clear [--cache-dir DIR]`: remove every entry of the compile cache. + /// `al-runner cache clear [--cache-dir DIR]`: remove every entry of the compile cache. CacheClear(Option), - /// `alrunner cache prune [--dry-run] [--all-other-builds] [--cache-dir DIR]`. + /// `al-runner cache prune [--dry-run] [--all-other-builds] [--cache-dir DIR]`. CachePrune { dir: Option, dry_run: bool, all_other_builds: bool, }, - /// `alrunner cache info [--cache-dir DIR]`. + /// `al-runner cache info [--cache-dir DIR]`. CacheInfo(Option), - /// `alrunner impact-index build APP... [OPTIONS]` (ADR-043 step 2): run the tests of the APPs once and keep, per + /// `al-runner impact-index build APP... [OPTIONS]` (ADR-043 step 2): run the tests of the APPs once and keep, per /// test, what it raised and touched, for the impact runs that follow. ImpactIndexBuild(Box), - /// `alrunner impact-index check-static APP... [OPTIONS]` (ADR-043 step 5): check that static reach covers every key + /// `al-runner impact-index check-static APP... [OPTIONS]` (ADR-043 step 5): check that static reach covers every key /// each test recorded in the cached index (a key it misses is a bug in static reach), and say how much more static /// reach selects. ImpactIndexCheckStatic(Box), } -/// `alrunner test`. +/// `al-runner test`. #[derive(Debug, Default, Clone, PartialEq)] pub struct TestArgs { /// The apps whose tests run: an app folder (with `app.json`), a `*.Source.zip` or an `.app`. @@ -87,7 +87,7 @@ pub struct TestArgs { /// `--refusal-detail TEXT`: the reasons that contain TEXT, grouped finer than `--top-refusals`. pub refusal_detail: Option, pub allow_not_run: bool, - /// Not a command line option: `alrunner serve`'s `execute` runs the `OnRun` trigger of one codeunit per app + /// Not a command line option: `al-runner serve`'s `execute` runs the `OnRun` trigger of one codeunit per app /// instead of the tests. pub execute: bool, /// Not a command line option: `captureValues` and `iterationTracking` of a server request. @@ -175,14 +175,14 @@ fn is_backup(v: &str) -> bool { pub const DEFAULT_TOP: usize = 10; pub const HELP: &str = "\ -alrunner: run AL tests without a service tier (AL Runner v3, preview) +al-runner: run AL tests without a service tier (AL Runner v3, preview) USAGE - alrunner test [OPTIONS] APP... - alrunner serve [--protocol 2] [OPTIONS] - alrunner impact-index build|check-static [OPTIONS] APP... - alrunner cache clear|prune|info [--cache-dir DIR] - alrunner --version | --help + al-runner test [OPTIONS] APP... + al-runner serve [--protocol 2] [OPTIONS] + al-runner impact-index build|check-static [OPTIONS] APP... + al-runner cache clear|prune|info [--cache-dir DIR] + al-runner --version | --help APP is an app folder (with app.json), a source archive (`Tests-SMB.Source.zip`) or an `.app` that carries its source. Every `Subtype = Test` codeunit of every APP runs, each in its own @@ -214,7 +214,7 @@ DEPENDENCIES COMPILE CACHE The Microsoft apps and the other dependency apps are compiled completely once, and the result is kept in /compile/ (about 20 MB per set of apps). Later runs with the same apps, - versions, sources, target and the same alrunner build load it instead of compiling them. + versions, sources, target and the same al-runner build load it instead of compiling them. The first run of a new set pays for the build (about 10 s for Business Central). --no-compile-cache Compile the dependency apps on every run, only what the tests reach. Same as ALRUNNER_NO_COMPILE_CACHE=1. @@ -224,20 +224,20 @@ COMPILE CACHE sources, the install baseline). Entries of other app sets stay. The cache also holds the install baseline: what the install code of the dependency apps and Company-Initialize leave in the database, with the demo data if the run has it. It is kept - under a key of the alrunner build, the dependency apps, the app's sources, the BC target, the + under a key of the al-runner build, the dependency apps, the app's sources, the BC target, the environment, the demo backup and the day, and a run that finds it starts its clock at the instant the run that made it began. - Old entries go by themselves: at the end of `alrunner test`, at most once a day and for at most - 200 ms, the folder is cleaned of entries of other alrunner builds unused for 7 days, entries of + Old entries go by themselves: at the end of `al-runner test`, at most once a day and for at most + 200 ms, the folder is cleaned of entries of other al-runner builds unused for 7 days, entries of any build unused for 30 days, and leftover temporary files older than a day. A cache hit renews the entry. ALRUNNER_NO_CACHE_PRUNE=1 turns this off. - alrunner cache prune [--dry-run] [--all-other-builds] [--cache-dir DIR] + al-runner cache prune [--dry-run] [--all-other-builds] [--cache-dir DIR] Run that cleanup now and print how many files and bytes went (--dry-run: only print). --all-other-builds also removes entries of other builds that are younger than 7 days. - alrunner cache info [--cache-dir DIR] - Print the entries, their size, and the split by alrunner build. - alrunner cache clear [--cache-dir DIR] + al-runner cache info [--cache-dir DIR] + Print the entries, their size, and the split by al-runner build. + al-runner cache clear [--cache-dir DIR] Remove every entry of the compile cache (/compile/): use it when a cached result is in doubt. The next run builds what it needs. @@ -333,12 +333,12 @@ IMPACT (ADR-043) or is a selection miss and not accepted; 2 for bad options or an unreadable accept file; 6 when a side selected no test. Tests not run on a side do not give 7 or 8: they are the class not verified. - alrunner impact-index build [OPTIONS] APP... + al-runner impact-index build [OPTIONS] APP... Run the tests of the APPs once (the same options as `test`, without --impact-of) and keep in the cache, per test, the events it raised and the tables, pages and reports it used. An impact run with the same APPs and options reads it. Never built implicitly. - alrunner impact-index check-static [OPTIONS] APP... + al-runner impact-index check-static [OPTIONS] APP... Check that static reach covers everything each test recorded in the cached index of the same APPs and options (exit 1 on a miss), and how much more static reach selects. @@ -361,18 +361,18 @@ EXIT CODES Order when several apply: 2, 6, 1, 8, 7. SERVE - alrunner serve AL Runner v2's server protocol (ALchemist, LethAL): one JSON object per line on + al-runner serve AL Runner v2's server protocol (ALchemist, LethAL): one JSON object per line on stdin, answers on stdout (a ready line first), logs on stderr. Commands: runTests, cancel, shutdown (execute: later). Each runTests request runs - `alrunner test` as a child process, so nothing is kept between requests. + `al-runner test` as a child process, so nothing is kept between requests. The options are those of `test` that do not depend on a request (--package-cache, --define, --test-timeout, --bc-version, --cache-dir, --no-download, --dep, ...); the request carries sourcePaths, packagePaths, coverage, perTestCoverage, test, excludeTests, testIsolation. See docs/adr/028-alrunner-serve.md. WARM - alrunner cache clear [--cache-dir DIR] - alrunner warm [PATH.bak] [--bc-version BUILD] [--country CODE] [--cache-dir DIR] [--no-download] + al-runner cache clear [--cache-dir DIR] + al-runner warm [PATH.bak] [--bc-version BUILD] [--country CODE] [--cache-dir DIR] [--no-download] [--test-data-company NAME] Finds the demo backup the way `test` does (downloading it if need be), opens it and keeps its page map and catalog in the cache. The first open of a backup verifies the @@ -457,16 +457,16 @@ fn number(flag: &str, v: &str) -> Result { v.parse().map_err(|_| format!("{flag} needs a number, got `{v}`")) } -/// `alrunner cache clear|prune|info`. +/// `al-runner cache clear|prune|info`. fn parse_cache(mut it: impl Iterator) -> Result { let sub = match it.next().as_deref() { Some(s @ ("clear" | "prune" | "info")) => s.to_string(), Some(other) => { return Err(format!( - "unknown cache command `{other}` (use `alrunner cache clear`, `prune` or `info`)" + "unknown cache command `{other}` (use `al-runner cache clear`, `prune` or `info`)" )); } - None => return Err("alrunner cache needs a command: `clear`, `prune` or `info`".into()), + None => return Err("al-runner cache needs a command: `clear`, `prune` or `info`".into()), }; let (mut dir, mut dry_run, mut all_other_builds) = (None, false, false); while let Some(f) = it.next() { @@ -476,7 +476,7 @@ fn parse_cache(mut it: impl Iterator) -> Result "--all-other-builds" if sub == "prune" => all_other_builds = true, other => { return Err(format!( - "unknown option `{other}` for `alrunner cache {sub}` (see --help)" + "unknown option `{other}` for `al-runner cache {sub}` (see --help)" )); } } @@ -492,7 +492,7 @@ fn parse_cache(mut it: impl Iterator) -> Result }) } -/// `alrunner warm [PATH.bak] [--bc-version V] [--country CODE] [--cache-dir DIR] [--no-download] [--test-data-company NAME]`. +/// `al-runner warm [PATH.bak] [--bc-version V] [--country CODE] [--cache-dir DIR] [--no-download] [--test-data-company NAME]`. fn parse_warm(mut it: impl Iterator) -> Result { let mut a = TestArgs { test_data: true, @@ -510,18 +510,18 @@ fn parse_warm(mut it: impl Iterator) -> Result { f if !f.starts_with("--") && is_backup(f) => a.test_data_path = Some(PathBuf::from(f)), f => { return Err(format!( - "unknown option or argument `{f}` for `alrunner warm` (see --help)" + "unknown option or argument `{f}` for `al-runner warm` (see --help)" )); } } } if a.test_data_path.is_none() && a.bc_version.is_none() { - return Err("alrunner warm needs a backup (PATH.bak) or a build (--bc-version BUILD)".into()); + return Err("al-runner warm needs a backup (PATH.bak) or a build (--bc-version BUILD)".into()); } Ok(Command::Warm(Box::new(a))) } -/// `alrunner serve [--protocol 2] [OPTIONS]`: the options are those of `alrunner test` that do not depend on a request; +/// `al-runner serve [--protocol 2] [OPTIONS]`: the options are those of `al-runner test` that do not depend on a request; /// they are checked with its parser and handed to every run. fn parse_serve(args: Vec) -> Result { let mut daemon = Vec::new(); @@ -545,7 +545,7 @@ fn parse_serve(args: Vec) -> Result { let mut probe = vec!["test".to_string(), "APP".to_string()]; probe.extend(daemon.iter().cloned()); let Command::Test(t) = parse(probe)? else { - return Err("alrunner serve: options of `alrunner test` only".into()); + return Err("al-runner serve: options of `al-runner test` only".into()); }; let t = *t; if t.apps.len() != 1 @@ -559,7 +559,7 @@ fn parse_serve(args: Vec) -> Result { || t.explain.is_some() || t.isolation.is_some() { - return Err("alrunner serve takes only the options that do not depend on a request: --package-cache, --dep, --define, --preprocessor-symbols, --test-timeout, --bc-version, --cache-dir, --no-download, --test-data and the like; the rest comes in each `runTests` request".into()); + return Err("al-runner serve takes only the options that do not depend on a request: --package-cache, --dep, --define, --preprocessor-symbols, --test-timeout, --bc-version, --cache-dir, --no-download, --test-data and the like; the rest comes in each `runTests` request".into()); } Ok(Command::Serve(daemon)) } @@ -594,7 +594,7 @@ pub fn parse(args: impl IntoIterator) -> Result } other => { return Err(format!( - "`alrunner impact-index` needs `build` or `check-static`, got `{}`", + "`al-runner impact-index` needs `build` or `check-static`, got `{}`", other.unwrap_or_default() )); } @@ -604,7 +604,7 @@ pub fn parse(args: impl IntoIterator) -> Result "serve" => return parse_serve(it.collect()), "run" | "debug" | "deps" | "package" | "helper" | "doctor" | "migrate" | "guide" => { return Err(format!( - "`alrunner {first}` is not implemented yet (ADR-016 lists it for a later step); only `alrunner test` exists" + "`al-runner {first}` is not implemented yet (ADR-016 lists it for a later step); only `al-runner test` exists" )); } other => return Err(format!("unknown command `{other}` (see --help)")), @@ -810,7 +810,7 @@ pub fn parse(args: impl IntoIterator) -> Result } } if a.apps.is_empty() { - return Err("alrunner test needs at least one APP (an app folder or a *.Source.zip)".into()); + return Err("al-runner test needs at least one APP (an app folder or a *.Source.zip)".into()); } if a.rebuild_compile_cache && a.no_compile_cache { return Err("--rebuild-compile-cache and --no-compile-cache cannot be combined".into()); @@ -863,10 +863,10 @@ pub fn parse(args: impl IntoIterator) -> Result } if index_build { if !a.impact_of.is_empty() || a.impact.is_some() || a.impact_accept.is_some() || a.impact_json.is_some() { - return Err("alrunner impact-index build runs the tests without any extension: --impact-of, --impact, --impact-accept and --impact-json do not apply".into()); + return Err("al-runner impact-index build runs the tests without any extension: --impact-of, --impact, --impact-accept and --impact-json do not apply".into()); } if a.no_compile_cache { - return Err("alrunner impact-index build cannot be combined with --no-compile-cache: impact runs compile the dependency apps completely from the compile cache, and so must the index's run (ADR-043 section 2.2)".into()); + return Err("al-runner impact-index build cannot be combined with --no-compile-cache: impact runs compile the dependency apps completely from the compile cache, and so must the index's run (ADR-043 section 2.2)".into()); } for (set, flag) in [ (a.explain.is_some(), "--explain"), @@ -875,7 +875,7 @@ pub fn parse(args: impl IntoIterator) -> Result (a.recipe, "--recipe microsoft"), ] { if set { - return Err(format!("alrunner impact-index build cannot be combined with {flag}")); + return Err(format!("al-runner impact-index build cannot be combined with {flag}")); } } return Ok(if check_static { @@ -1049,7 +1049,7 @@ mod tests { #[test] fn the_help_documents_the_flush_and_the_rebuild_and_the_baseline_entry() { - for needle in ["alrunner cache clear", "--rebuild-compile-cache", "install baseline"] { + for needle in ["al-runner cache clear", "--rebuild-compile-cache", "install baseline"] { assert!(HELP.contains(needle), "{needle}"); } } diff --git a/crates/alrunner-cli/src/coverage.rs b/crates/alrunner-cli/src/coverage.rs index 82e59cc71..9e88c1e91 100644 --- a/crates/alrunner-cli/src/coverage.rs +++ b/crates/alrunner-cli/src/coverage.rs @@ -98,7 +98,7 @@ pub fn cobertura( )); } format!( - "\n\n \n {}\n \n \n{body} \n\n", + "\n\n \n {}\n \n \n{body} \n\n", rate(covered, valid), esc(cwd) ) diff --git a/crates/alrunner-cli/src/impact.rs b/crates/alrunner-cli/src/impact.rs index d5991c4bd..5298693cf 100644 --- a/crates/alrunner-cli/src/impact.rs +++ b/crates/alrunner-cli/src/impact.rs @@ -1,4 +1,4 @@ -//! `alrunner test --impact-of APP` (ADR-043 steps 1 to 3: two runs or dynamic selection, the diff, the accept file, +//! `al-runner test --impact-of APP` (ADR-043 steps 1 to 3: two runs or dynamic selection, the diff, the accept file, //! the JSON diff and the JUnit of the run with the extension). //! //! Runs the selected tests of the APPs without the extensions, then with them (the extensions given as further @@ -755,7 +755,7 @@ fn side_args(a: &TestArgs) -> TestArgs { /// The command that builds the index this run lacks: the run's own arguments, as `impact-index build`, without the /// extension (ADR-043 section 2.3: it repeats the test apps and flags exactly). fn build_command(args: &[String]) -> String { - let mut out = vec!["alrunner".to_string(), "impact-index".into(), "build".into()]; + let mut out = vec!["al-runner".to_string(), "impact-index".into(), "build".into()]; let mut it = args.iter().skip_while(|a| *a != "test").skip(1); while let Some(a) = it.next() { if a == "--impact-of" || a == "--impact" { @@ -794,7 +794,7 @@ fn no_index_warning(a: &TestArgs, cannot_rule_out: Option) -> String { ) } -/// `alrunner test --impact-of ...`: `--impact all` runs everything on both sides; `--impact static`, or no cached +/// `al-runner test --impact-of ...`: `--impact all` runs everything on both sides; `--impact static`, or no cached /// index, selects by static reach; else dynamic selection with the index. Exit 1 when a test newly fails, fails /// differently, is newly not run or is a selection miss; a run that selected nothing or stopped exits as that run did. pub fn run(a: &TestArgs) -> Result { diff --git a/crates/alrunner-cli/src/impact_index.rs b/crates/alrunner-cli/src/impact_index.rs index d8b636121..717fb8947 100644 --- a/crates/alrunner-cli/src/impact_index.rs +++ b/crates/alrunner-cli/src/impact_index.rs @@ -39,7 +39,7 @@ pub struct IndexedTest { pub keys: Vec, } -/// What `alrunner impact-index build` keeps. +/// What `al-runner impact-index build` keeps. #[derive(Debug, Clone, PartialEq, Default)] pub struct Index { /// The apps of the index run's compile: (id, name, version). @@ -316,11 +316,11 @@ pub fn of_run(c: &Collected) -> Index { } } -/// `alrunner impact-index build APP...`: runs the tests of the APPs with the trace on and writes the index. +/// `al-runner impact-index build APP...`: runs the tests of the APPs with the trace on and writes the index. pub fn build(a: &TestArgs) -> Result { // The index must hold every test codeunit an impact run of these APPs can run. if !a.codeunits.is_empty() || !a.filters.is_empty() || !a.exact.is_empty() || !a.excludes.is_empty() { - return Err("alrunner impact-index build runs every test of the APPs: --codeunit, --test, --exact and --exclude do not apply (an impact run selects from the whole index)".into()); + return Err("al-runner impact-index build runs every test of the APPs: --codeunit, --test, --exact and --exclude do not apply (an impact run selects from the whole index)".into()); } let started = Instant::now(); let path = path(a)?; @@ -356,7 +356,7 @@ pub fn build(a: &TestArgs) -> Result { Ok(0) } -/// `alrunner impact-index check-static APP... [OPTIONS]` (ADR-043 step 5, the cross-check): compiles the APPs as the +/// `al-runner impact-index check-static APP... [OPTIONS]` (ADR-043 step 5, the cross-check): compiles the APPs as the /// index's run did, runs nothing, and checks that every key each test recorded in the cached index is in the test's /// static reach (with "cannot rule out" sites). A key outside it is a bug in static reach: exit 1. Also prints how /// much more static reach selects than the index, per test and per codeunit. @@ -367,7 +367,7 @@ pub fn check_static(a: &TestArgs) -> Result { side.parity = a.disabled_tests_dir.is_some(); side.test_apps = Some(a.apps.len()); let Some((index, path)) = lookup(&side)? else { - return Err("no impact index for these test apps and options: build it first with alrunner impact-index build and the same APPs and options".into()); + return Err("no impact index for these test apps and options: build it first with al-runner impact-index build and the same APPs and options".into()); }; println!("checking static reach against the impact index {}", path.display()); let (index, verbose, tests) = (Arc::new(index), a.verbose, a.apps.len()); diff --git a/crates/alrunner-cli/src/main.rs b/crates/alrunner-cli/src/main.rs index 922b34950..2e14cd838 100644 --- a/crates/alrunner-cli/src/main.rs +++ b/crates/alrunner-cli/src/main.rs @@ -1,4 +1,4 @@ -//! `alrunner`: the user command line of AL Runner v3 (ADR-016). Today: `alrunner test`. +//! `al-runner`: the user command line of AL Runner v3 (ADR-016). Today: `al-runner test`. mod apps; mod args; @@ -8,6 +8,7 @@ mod coverage; mod impact; mod impact_index; mod output; +mod path_note; mod recipe; mod recipe_run; mod run; @@ -52,6 +53,11 @@ fn real_main() -> ExitCode { return ExitCode::from(2); } }; + // Another `al-runner` on PATH (AL Runner v2's dotnet tool): one line on stderr, at most once a day. `--version` + // lists the copies instead; `serve` talks a protocol on stdout and stderr and gets no note. + if !matches!(command, Command::Help | Command::Version | Command::Serve(_)) { + path_note::maybe_note(); + } match command { Command::Help => { print!("{}", args::HELP); @@ -59,6 +65,14 @@ fn real_main() -> ExitCode { } Command::Version => { println!("{}", version::line()); + // A tool that reads only the first line may close the pipe before the list: not an error. + use std::io::Write; + let mut out = std::io::stdout(); + for l in path_note::version_lines() { + if writeln!(out, "{l}").is_err() { + break; + } + } ExitCode::SUCCESS } Command::ListAssumptions(dir) => { diff --git a/crates/alrunner-cli/src/output.rs b/crates/alrunner-cli/src/output.rs index 17bb642d3..098dd3a2d 100644 --- a/crates/alrunner-cli/src/output.rs +++ b/crates/alrunner-cli/src/output.rs @@ -224,7 +224,7 @@ pub fn json(results: &[&TestResult], exit_code: u8, wall_s: f64) -> String { serde_json::to_string_pretty(&doc).expect("a JSON value serializes") } -/// One row of `tests[]` of the `--output-json` document, also the body of a `test` line of `alrunner serve`. +/// One row of `tests[]` of the `--output-json` document, also the body of a `test` line of `al-runner serve`. pub fn json_row( codeunit: u32, codeunit_name: &str, diff --git a/crates/alrunner-cli/src/path_note.rs b/crates/alrunner-cli/src/path_note.rs new file mode 100644 index 000000000..3a9742188 --- /dev/null +++ b/crates/alrunner-cli/src/path_note.rs @@ -0,0 +1,210 @@ +//! The note about another `al-runner` on PATH (ADR-016, amendment of 2026-10-21). +//! +//! AL Runner v2's dotnet tool installs a command of the same name into `~/.dotnet/tools`. Whichever comes +//! first on PATH runs. This binary can only notice the clash when it runs itself, so: +//! - each command except `serve`, `--help` and `--version` prints one line to stderr when it finds another +//! copy, at most once a day (a stamp file in the cache folder); +//! - `--version` lists every other copy with the first line of its own `--version` output. +//! +//! `ALRUNNER_NO_PATH_NOTE=1` turns both off. Nothing here writes to stdout except the `--version` list, so +//! JUnit, JSON and `serve` output do not change. Tooling only: nothing AL code can see (ADR-009). + +use std::ffi::OsString; +use std::io::Read; +use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; +use std::time::{Duration, Instant, SystemTime}; + +/// Turns the note and the `--version` list off. +pub const OFF_VAR: &str = "ALRUNNER_NO_PATH_NOTE"; +const NAMES: [&str; 2] = ["al-runner", "al-runner.exe"]; +const ONCE_PER: Duration = Duration::from_secs(24 * 60 * 60); +const VERSION_WAIT: Duration = Duration::from_secs(2); + +fn off() -> bool { + std::env::var(OFF_VAR).is_ok_and(|v| !v.trim().is_empty() && v.trim() != "0") +} + +fn home() -> Option { + ["HOME", "USERPROFILE"] + .iter() + .filter_map(std::env::var_os) + .find(|v| !v.is_empty()) + .map(PathBuf::from) +} + +/// The other `al-runner` executables: the folders of `path` in order, then `/.dotnet/tools`. Leaves out +/// `me` (compared by canonical path) and links to a program of another name (a version manager's shim), and +/// names each file once. +pub fn others(path: Option, home: Option, me: Option<&Path>) -> Vec { + let me = me.and_then(|m| m.canonicalize().ok()); + let mut dirs: Vec = path.map(|p| std::env::split_paths(&p).collect()).unwrap_or_default(); + dirs.extend(home.map(|h| h.join(".dotnet").join("tools"))); + let mut seen: Vec = Vec::new(); + let mut out = Vec::new(); + for dir in dirs.iter().filter(|d| !d.as_os_str().is_empty()) { + for name in NAMES { + let p = dir.join(name); + if !p.is_file() { + continue; + } + let Ok(real) = p.canonicalize() else { continue }; + let real_name = real.file_name().and_then(|f| f.to_str()).map(str::to_ascii_lowercase); + if me.as_ref() == Some(&real) + || seen.contains(&real) + || !NAMES.contains(&real_name.as_deref().unwrap_or("")) + { + continue; + } + seen.push(real); + out.push(p); + } + } + out +} + +fn others_from_env() -> Vec { + let me = std::env::current_exe().ok(); + others(std::env::var_os("PATH"), home(), me.as_deref()) +} + +/// True when the stamp is missing, unreadable, or older than a day (or dated in the future). +pub fn due(stamp: &Path, now: SystemTime) -> bool { + match std::fs::metadata(stamp).and_then(|m| m.modified()) { + Ok(t) => now.duration_since(t).map_or(true, |age| age >= ONCE_PER), + Err(_) => true, + } +} + +fn in_dotnet_tools(p: &Path) -> bool { + let mut parts = p.parent().into_iter().flat_map(|d| d.iter().rev().take(2)); + parts.next().is_some_and(|t| t == "tools") && parts.next().is_some_and(|d| d == ".dotnet") +} + +/// The note's one line. +pub fn note(other: &Path, more: usize, version: &str, me: Option<&Path>) -> String { + let (what, remove) = if in_dotnet_tools(other) { + ( + " (AL Runner v2, a dotnet tool)", + "Remove v2 with \"dotnet tool uninstall -g MSDyn365BC.AL.Runner\"", + ) + } else { + ("", "If it is AL Runner v2, remove it") + }; + let first = match me.and_then(Path::parent) { + Some(d) => format!("put {} first on PATH", d.display()), + None => "put this al-runner first on PATH".into(), + }; + let more = match more { + 0 => String::new(), + n => format!(" ({n} more: see al-runner --version)"), + }; + format!( + "note: another al-runner is on PATH at {}{what}{more}. This is AL Runner v3 {version}. {remove}, or \ + {first}. ALRUNNER_NO_PATH_NOTE=1 turns this note off.", + other.display() + ) +} + +/// Prints the note to stderr when another copy is on PATH and the last note is a day old. +pub fn maybe_note() { + if off() { + return; + } + let others = others_from_env(); + let Some(first) = others.first() else { return }; + let stamp = al_deps::cache::cache_root_from_env(None).join("path-note.stamp"); + if !due(&stamp, SystemTime::now()) { + return; + } + let me = std::env::current_exe().ok(); + eprintln!( + "{}", + note(first, others.len() - 1, env!("ALRUNNER_VERSION"), me.as_deref()) + ); + if let Some(dir) = stamp.parent() { + let _ = std::fs::create_dir_all(dir); + } + let _ = std::fs::write(&stamp, b"the note about another al-runner on PATH was printed\n"); +} + +/// The first line of `p --version`, waiting at most two seconds. +fn version_of(p: &Path) -> String { + let child = Command::new(p) + .arg("--version") + // A v3 copy would list the others again, and so on. + .env(OFF_VAR, "1") + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .spawn(); + let mut child = match child { + Ok(c) => c, + Err(e) => return format!("(could not start it: {e})"), + }; + let start = Instant::now(); + loop { + match child.try_wait() { + Ok(Some(_)) => break, + Ok(None) if start.elapsed() < VERSION_WAIT => std::thread::sleep(Duration::from_millis(20)), + _ => { + let _ = child.kill(); + let _ = child.wait(); + return "(no answer within 2 s)".into(); + } + } + } + let mut out = String::new(); + if let Some(mut s) = child.stdout.take() { + let _ = s.read_to_string(&mut out); + } + out.lines() + .map(str::trim) + .find(|l| !l.is_empty()) + .unwrap_or("(no version line)") + .to_string() +} + +/// The lines `--version` prints after its own: one per other copy. +pub fn version_lines() -> Vec { + if off() { + return Vec::new(); + } + others_from_env() + .iter() + .map(|p| format!("also on PATH: {}: {}", p.display(), version_of(p))) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_note_is_due_without_a_stamp_and_a_day_after_the_last_one() { + let d = tempfile::tempdir().unwrap(); + let stamp = d.path().join("path-note.stamp"); + let now = SystemTime::now(); + assert!(due(&stamp, now)); + std::fs::write(&stamp, b"x").unwrap(); + assert!(!due(&stamp, now)); + assert!(!due(&stamp, now + Duration::from_secs(23 * 3600))); + assert!(due(&stamp, now + Duration::from_secs(25 * 3600))); + let f = std::fs::File::options().write(true).open(&stamp).unwrap(); + f.set_modified(now - Duration::from_secs(25 * 3600)).unwrap(); + assert!(due(&stamp, now)); + } + + #[test] + fn the_note_names_v2_only_for_the_dotnet_tools_folder() { + let v2 = Path::new("/h/.dotnet/tools/al-runner"); + let other = Path::new("/opt/x/al-runner"); + let me = Path::new("/home/u/.local/bin/al-runner"); + assert!(note(v2, 0, "3.0.0", Some(me)).contains("(AL Runner v2, a dotnet tool)")); + let n = note(other, 2, "3.0.0", Some(me)); + assert!(!n.contains("AL Runner v2, a dotnet tool"), "{n}"); + assert!(n.contains("If it is AL Runner v2, remove it, or put"), "{n}"); + assert!(n.contains("(2 more: see al-runner --version)"), "{n}"); + assert!(n.contains("put /home/u/.local/bin first on PATH"), "{n}"); + } +} diff --git a/crates/alrunner-cli/src/recipe_run.rs b/crates/alrunner-cli/src/recipe_run.rs index f2a62fb98..f3a3df193 100644 --- a/crates/alrunner-cli/src/recipe_run.rs +++ b/crates/alrunner-cli/src/recipe_run.rs @@ -1,4 +1,4 @@ -//! `alrunner test --recipe microsoft`: one run per lane, with the company and the disabled tests Microsoft's CI uses. +//! `al-runner test --recipe microsoft`: one run per lane, with the company and the disabled tests Microsoft's CI uses. //! //! The planning (which codeunit gets which company) is `recipe.rs`; the files come from `bcapps.rs`. This file turns a //! plan into runs of the ordinary test command and adds the lines that put the lanes together. diff --git a/crates/alrunner-cli/src/run.rs b/crates/alrunner-cli/src/run.rs index 190b92a48..372de2a82 100644 --- a/crates/alrunner-cli/src/run.rs +++ b/crates/alrunner-cli/src/run.rs @@ -1,4 +1,4 @@ -//! `alrunner test`: load the APPs and their dependencies, compile, run, report. +//! `al-runner test`: load the APPs and their dependencies, compile, run, report. use crate::apps::{self, AppInput}; use crate::args::{DEFAULT_TOP, TestArgs}; @@ -214,12 +214,12 @@ pub fn write_file(path: &Path, text: &str) -> Result<(), String> { std::fs::write(path, text).map_err(|e| format!("{}: {e}", path.display())) } -/// With `alrunner serve`: the backup opened last, kept with the tables read from it, for the next request. +/// With `al-runner serve`: the backup opened last, kept with the tables read from it, for the next request. type KeptBackup = ((PathBuf, Option), TestData); static KEPT_BACKUP: std::sync::Mutex> = std::sync::Mutex::new(None); static KEEP_BACKUPS: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); -/// `alrunner serve` keeps the opened backup (and so the tables read from it) between requests. +/// `al-runner serve` keeps the opened backup (and so the tables read from it) between requests. pub fn keep_backups() { KEEP_BACKUPS.store(true, std::sync::atomic::Ordering::Relaxed); } @@ -406,7 +406,7 @@ fn should_choose_test_data(a: &TestArgs, already_open: bool, microsoft: bool) -> a.wants_test_data() && !already_open && (microsoft || a.test_data_asked_for()) } -/// `alrunner warm`: finds the backup, opens it, and so builds the index kept next to the compile cache. +/// `al-runner warm`: finds the backup, opens it, and so builds the index kept next to the compile cache. pub fn warm(a: &TestArgs) -> Result<(), String> { if a.country.is_some() && !a.no_download { al_deps::artifact::check_country(&al_deps::artifact::HttpCdn::from_env(), a.country())?; @@ -461,7 +461,7 @@ pub fn test(a: &TestArgs) -> Result { /// What one side of an impact run (ADR-043), or the run that builds its index, asks for and keeps of its run. #[derive(Default)] pub struct Collected { - /// Asked for: note what each test raised and touched (`alrunner impact-index build`). + /// Asked for: note what each test raised and touched (`al-runner impact-index build`). pub impact_trace: bool, /// Asked for: narrow the test codeunits once the compile is done (dynamic selection). pub narrow: Option, @@ -490,7 +490,7 @@ pub fn test_collect(a: &TestArgs, into: &mut Collected) -> Result { /// What the server hears for each test as it finishes: the event, and its capture as JSON. pub type OnTest = Arc) + Send + Sync>; -/// What `alrunner serve` keeps between requests, and how it hears about a request's run (ADR-028). +/// What `al-runner serve` keeps between requests, and how it hears about a request's run (ADR-028). #[derive(Default)] pub struct WarmCtx { pub runtime: al_testrun::runtime::Warm, diff --git a/crates/alrunner-cli/src/serve.rs b/crates/alrunner-cli/src/serve.rs index b0354f864..2b2c6c928 100644 --- a/crates/alrunner-cli/src/serve.rs +++ b/crates/alrunner-cli/src/serve.rs @@ -1,4 +1,4 @@ -//! `alrunner serve` (ADR-028): the v2 server protocol on stdin and stdout, in this process. The compile of the +//! `al-runner serve` (ADR-028): the v2 server protocol on stdin and stdout, in this process. The compile of the //! last request is kept (`WarmCtx`), a test line is written as each test finishes, and `cancel` stops the run after the //! current test. @@ -171,13 +171,13 @@ pub fn serve(daemon: &[String]) -> Result<(), String> { Ok(()) } -/// The `alrunner test` options of the daemon, as the template of every request's. +/// The `al-runner test` options of the daemon, as the template of every request's. fn daemon_args(daemon: &[String]) -> Result { let mut probe = vec!["test".to_string(), "APP".to_string()]; probe.extend(daemon.iter().cloned()); match crate::args::parse(probe)? { Command::Test(t) => Ok(*t), - _ => Err("alrunner serve: options of `alrunner test` only".into()), + _ => Err("al-runner serve: options of `al-runner test` only".into()), } } @@ -204,7 +204,7 @@ fn flag(fields: &Map, name: &str) -> Result { } } -/// The `alrunner test` arguments for a request, and the warnings the request earns. +/// The `al-runner test` arguments for a request, and the warnings the request earns. fn request_args(base: &TestArgs, fields: &Map) -> Result<(TestArgs, Vec), String> { let mut warnings = Vec::new(); for key in fields.keys() { @@ -370,7 +370,7 @@ fn is_object_declaration(code: &str) -> bool { /// Microsoft's apps in sight the app has no dependencies (it runs at once); with `--bc-version`, `--dep`, /// `--package-cache` or `packagePaths` it is built for that BC version and sees the Base Application. fn inline_app(code: &str, with_microsoft: bool, bc_version: Option<&str>) -> Result { - let dir = std::env::temp_dir().join(format!("alrunner-execute-{}", std::process::id())); + let dir = std::env::temp_dir().join(format!("al-runner-execute-{}", std::process::id())); std::fs::create_dir_all(&dir).map_err(|e| format!("{}: {e}", dir.display()))?; let mut app = json!({ "id": "6f3f1a4e-3d52-4c1e-9d4b-0a1c2e3f4a5b", diff --git a/crates/alrunner-cli/src/style.rs b/crates/alrunner-cli/src/style.rs index a0eab403c..c8eb156d6 100644 --- a/crates/alrunner-cli/src/style.rs +++ b/crates/alrunner-cli/src/style.rs @@ -1,4 +1,4 @@ -//! Plain ANSI colors for the human report of `alrunner test` (no dependency). `--color auto|always|never`: +//! Plain ANSI colors for the human report of `al-runner test` (no dependency). `--color auto|always|never`: //! auto colors only when the report goes to a terminal and `NO_COLOR` is not set. JUnit and JSON output are never colored. use std::sync::atomic::{AtomicBool, Ordering}; diff --git a/crates/alrunner-cli/src/testdata.rs b/crates/alrunner-cli/src/testdata.rs index 2f947ec46..4e551d031 100644 --- a/crates/alrunner-cli/src/testdata.rs +++ b/crates/alrunner-cli/src/testdata.rs @@ -13,7 +13,7 @@ use std::path::{Path, PathBuf}; pub struct Where<'a, D: FnMut(&BuildId) -> Result> { /// `~/.bcartifacts.cache/sandbox`, when it exists. pub local_root: Option<&'a Path>, - /// The alrunner artifact cache root (`--cache-dir`, `$ALRUNNER_CACHE`, the default). + /// The al-runner artifact cache root (`--cache-dir`, `$ALRUNNER_CACHE`, the default). pub cache_root: &'a Path, /// Downloads the backup of a build into the cache. `None` for `--no-download`. pub download: Option, diff --git a/crates/alrunner-cli/src/version.rs b/crates/alrunner-cli/src/version.rs index a64530c83..01b77e284 100644 --- a/crates/alrunner-cli/src/version.rs +++ b/crates/alrunner-cli/src/version.rs @@ -1,9 +1,9 @@ //! The one version line, shared by `--version` and the run header. -/// `alrunner ()`. The version is the Cargo version, plus the build suffix +/// `al-runner ()`. The version is the Cargo version, plus the build suffix /// (`+edge.YYYYMMDD`) on an edge build. pub fn line() -> String { - format!("alrunner {} ({})", env!("ALRUNNER_VERSION"), env!("ALRUNNER_COMMIT")) + format!("al-runner {} ({})", env!("ALRUNNER_VERSION"), env!("ALRUNNER_COMMIT")) } #[cfg(test)] @@ -13,7 +13,10 @@ mod tests { #[test] fn line_starts_with_the_cargo_version_and_has_the_commit() { let l = line(); - assert!(l.starts_with(&format!("alrunner {}", env!("CARGO_PKG_VERSION"))), "{l}"); + assert!( + l.starts_with(&format!("al-runner {}", env!("CARGO_PKG_VERSION"))), + "{l}" + ); assert!(l.ends_with(&format!(" ({})", env!("ALRUNNER_COMMIT"))), "{l}"); } diff --git a/crates/alrunner-cli/tests/cli.rs b/crates/alrunner-cli/tests/cli.rs index 5bc41c2f5..d2e06d71b 100644 --- a/crates/alrunner-cli/tests/cli.rs +++ b/crates/alrunner-cli/tests/cli.rs @@ -1,17 +1,19 @@ -//! `alrunner test` end to end on small fixture apps. Nothing here is Microsoft's code. +//! `al-runner test` end to end on small fixture apps. Nothing here is Microsoft's code. use std::path::{Path, PathBuf}; use std::process::{Command, Output}; fn alrunner(args: &[&str]) -> Output { - Command::new(env!("CARGO_BIN_EXE_alrunner")) + Command::new(env!("CARGO_BIN_EXE_al-runner")) // Few threads: the machine is shared, and the fixtures are tiny. .env("AL_CHECK_THREADS", "2") .env("AL_LOWER_THREADS", "2") .env("AL_TEST_THREADS", "2") + // The note about another al-runner on PATH (the machine may have AL Runner v2) stays out of these outputs. + .env("ALRUNNER_NO_PATH_NOTE", "1") .args(args) .output() - .expect("run alrunner") + .expect("run al-runner") } fn text(o: &Output) -> String { @@ -143,7 +145,7 @@ fn help_and_version_exit_0_and_say_what_the_command_does() { let o = alrunner(&["--help"]); assert_eq!(code(&o), 0); let t = text(&o); - assert!(t.contains("alrunner test [OPTIONS] APP..."), "{t}"); + assert!(t.contains("al-runner test [OPTIONS] APP..."), "{t}"); assert!(t.contains("--dep PATH") && t.contains("--package-cache DIR"), "{t}"); assert!(t.contains("7 some tests were not run"), "{t}"); assert_eq!(code(&alrunner(&["--version"])), 0); @@ -153,7 +155,7 @@ fn help_and_version_exit_0_and_say_what_the_command_does() { fn version_prints_the_crate_version_and_the_commit() { let o = alrunner(&["--version"]); let t = text(&o); - let want = format!("alrunner {} (", env!("CARGO_PKG_VERSION")); + let want = format!("al-runner {} (", env!("CARGO_PKG_VERSION")); assert!(t.starts_with(&want) && t.trim_end().ends_with(')'), "{t}"); assert!(env!("CARGO_PKG_VERSION").starts_with("3.0.0-alpha."), "{t}"); } @@ -219,7 +221,7 @@ fn the_default_output_leaves_setup_details_to_verbose() { let o = alrunner(&["test", app.to_str().unwrap(), "--no-download"]); let t = text(&o); assert_eq!(code(&o), 1, "{t}"); - assert!(t.starts_with("alrunner "), "the version line comes first: {t}"); + assert!(t.starts_with("al-runner "), "the version line comes first: {t}"); for kept in [ "FAIL 50100 Mixed Tests.Fails: boom 5", "Top refusals", @@ -1088,7 +1090,8 @@ fn define_adds_a_preprocessor_symbol_and_the_v2_flags_are_accepted() { assert_eq!(code(&o), 1, "{}", text(&o)); assert!(text(&o).contains("mutant"), "{}", text(&o)); // The v2 variable is read; a value that is no number is an error. - let o = Command::new(env!("CARGO_BIN_EXE_alrunner")) + let o = Command::new(env!("CARGO_BIN_EXE_al-runner")) + .env("ALRUNNER_NO_PATH_NOTE", "1") .env("AL_RUNNER_TEST_TIMEOUT_SEC", "soon") .args(["test", a, "--no-download", "--no-test-data"]) .output() @@ -1251,7 +1254,8 @@ fn server_url_is_checked_printed_and_taken_from_the_variable() { "{}", text(&o) ); - let o = std::process::Command::new(env!("CARGO_BIN_EXE_alrunner")) + let o = std::process::Command::new(env!("CARGO_BIN_EXE_al-runner")) + .env("ALRUNNER_NO_PATH_NOTE", "1") .env("ALRUNNER_SERVER_URL", "http://env.example/BC/") .args(["test", a, "--no-download", "--verbose"]) .output() @@ -1282,7 +1286,8 @@ fn color_always_paints_the_labels_and_never_or_no_color_keeps_them_plain() { assert!(t.contains("\x1b[1m"), "headings are bold: {t}"); let t = text(&alrunner(&["test", a, "--no-download", "--color", "never"])); assert!(!t.contains('\x1b'), "{t}"); - let o = std::process::Command::new(env!("CARGO_BIN_EXE_alrunner")) + let o = std::process::Command::new(env!("CARGO_BIN_EXE_al-runner")) + .env("ALRUNNER_NO_PATH_NOTE", "1") .env("NO_COLOR", "1") .args(["test", a, "--no-download"]) .output() @@ -1301,3 +1306,198 @@ fn color_always_paints_the_labels_and_never_or_no_color_keeps_them_plain() { ]); assert!(!std::fs::read_to_string(&xml).unwrap().contains('\x1b')); } + +// The note about another `al-runner` on PATH (ADR-016, amendment of 2026-10-21). AL Runner v2's dotnet +// tool installs a command of the same name; whichever comes first on PATH runs. + +/// A fake other `al-runner`: a shell script that runs `body`. +#[cfg(unix)] +fn fake_al_runner(dir: &Path, body: &str) -> PathBuf { + use std::os::unix::fs::PermissionsExt; + std::fs::create_dir_all(dir).unwrap(); + let p = dir.join("al-runner"); + std::fs::write(&p, format!("#!/bin/sh\n{body}\n")).unwrap(); + std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap(); + p +} + +/// Runs this al-runner with a PATH, a home folder and a cache folder of the test's own, the note switched on. +#[cfg(unix)] +fn alrunner_env(path: &Path, home: &Path, args: &[&str]) -> Output { + Command::new(env!("CARGO_BIN_EXE_al-runner")) + .env_remove("ALRUNNER_NO_PATH_NOTE") + .env("PATH", path) + .env("HOME", home) + .env("USERPROFILE", home) + .env("ALRUNNER_CACHE", home.join("cache")) + .args(args) + .output() + .expect("run al-runner") +} + +#[cfg(unix)] +const NOTE: &str = "note: another al-runner is on PATH at "; + +#[cfg(unix)] +#[test] +fn another_al_runner_on_path_gets_one_note_on_stderr_at_most_once_a_day() { + let d = tempfile::tempdir().unwrap(); + let bin = d.path().join("v2bin"); + let other = fake_al_runner(&bin, "echo 'AL Runner 1.0.99'"); + let home = d.path().join("home"); + let cache_dir = d.path().join("c"); + let args = ["cache", "info", "--cache-dir", cache_dir.to_str().unwrap()]; + let first = alrunner_env(&bin, &home, &args); + assert_eq!(code(&first), 0, "{}", text(&first)); + let err = String::from_utf8_lossy(&first.stderr); + assert!(err.contains(&format!("{NOTE}{}", other.display())), "{err}"); + assert!( + err.contains("ALRUNNER_NO_PATH_NOTE=1"), + "the note says how to turn it off: {err}" + ); + assert_eq!(err.matches(NOTE).count(), 1, "one line: {err}"); + assert!( + !String::from_utf8_lossy(&first.stdout).contains("al-runner is on PATH"), + "never on stdout" + ); + let second = alrunner_env(&bin, &home, &args); + assert!(!text(&second).contains(NOTE), "once a day: {}", text(&second)); + assert_eq!(first.stdout, second.stdout, "the note does not change stdout"); +} + +#[cfg(unix)] +#[test] +fn the_path_note_is_off_with_alrunner_no_path_note() { + let d = tempfile::tempdir().unwrap(); + let bin = d.path().join("v2bin"); + fake_al_runner(&bin, "echo 'AL Runner 1.0.99'"); + let home = d.path().join("home"); + let o = Command::new(env!("CARGO_BIN_EXE_al-runner")) + .env("ALRUNNER_NO_PATH_NOTE", "1") + .env("PATH", &bin) + .env("HOME", &home) + .env("ALRUNNER_CACHE", home.join("cache")) + .args(["cache", "info", "--cache-dir", d.path().join("c").to_str().unwrap()]) + .output() + .unwrap(); + assert_eq!(code(&o), 0, "{}", text(&o)); + assert!(!text(&o).contains(NOTE), "{}", text(&o)); +} + +#[cfg(unix)] +#[test] +fn the_dotnet_tools_folder_is_checked_even_when_it_is_not_on_path() { + let d = tempfile::tempdir().unwrap(); + let home = d.path().join("home"); + let other = fake_al_runner(&home.join(".dotnet").join("tools"), "echo 'AL Runner 1.0.99'"); + let empty = d.path().join("empty"); + std::fs::create_dir_all(&empty).unwrap(); + let o = alrunner_env( + &empty, + &home, + &["cache", "info", "--cache-dir", d.path().join("c").to_str().unwrap()], + ); + let err = String::from_utf8_lossy(&o.stderr); + assert!(err.contains(&format!("{NOTE}{}", other.display())), "{err}"); + assert!(err.contains("AL Runner v2, a dotnet tool"), "{err}"); + assert!(err.contains("dotnet tool uninstall -g MSDyn365BC.AL.Runner"), "{err}"); +} + +#[cfg(unix)] +#[test] +fn this_binary_itself_and_a_shim_of_another_tool_are_not_another_al_runner() { + let d = tempfile::tempdir().unwrap(); + let home = d.path().join("home"); + // A link to this very binary. + let me = d.path().join("me"); + std::fs::create_dir_all(&me).unwrap(); + std::os::unix::fs::symlink(env!("CARGO_BIN_EXE_al-runner"), me.join("al-runner")).unwrap(); + // A version manager's shim: `al-runner` is a link to a program of another name. + let shims = d.path().join("shims"); + std::fs::create_dir_all(&shims).unwrap(); + let mgr = fake_al_runner(&d.path().join("mgr"), "echo manager"); + let mise = mgr.with_file_name("mise"); + std::fs::rename(&mgr, &mise).unwrap(); + std::os::unix::fs::symlink(&mise, shims.join("al-runner")).unwrap(); + let path = std::env::join_paths([&me, &shims]).unwrap(); + let o = alrunner_env( + Path::new(&path), + &home, + &["cache", "info", "--cache-dir", d.path().join("c").to_str().unwrap()], + ); + assert_eq!(code(&o), 0, "{}", text(&o)); + assert!(!text(&o).contains(NOTE), "{}", text(&o)); +} + +#[cfg(unix)] +#[test] +fn version_lists_each_other_al_runner_with_the_first_line_of_its_version() { + let d = tempfile::tempdir().unwrap(); + let bin = d.path().join("v2bin"); + let other = fake_al_runner(&bin, "echo 'AL Runner 1.0.99'; echo 'second line'"); + let home = d.path().join("home"); + let o = alrunner_env(&bin, &home, &["--version"]); + assert_eq!(code(&o), 0, "{}", text(&o)); + let out = String::from_utf8_lossy(&o.stdout); + let lines: Vec<&str> = out.lines().collect(); + assert!( + lines[0].starts_with(&format!("al-runner {} (", env!("CARGO_PKG_VERSION"))), + "{out}" + ); + assert_eq!(lines.len(), 2, "{out}"); + assert!( + lines[1].contains(&other.display().to_string()) && lines[1].contains("AL Runner 1.0.99"), + "{out}" + ); + assert!(!lines[1].contains("second line"), "{out}"); + assert!( + !String::from_utf8_lossy(&o.stderr).contains(NOTE), + "--version lists instead of the note" + ); +} + +#[cfg(unix)] +#[test] +fn version_waits_at_most_2_seconds_for_another_al_runner() { + let d = tempfile::tempdir().unwrap(); + let bin = d.path().join("v2bin"); + fake_al_runner(&bin, "exec /bin/sleep 20"); + let home = d.path().join("home"); + let start = std::time::Instant::now(); + let o = alrunner_env(&bin, &home, &["--version"]); + assert!( + start.elapsed() < std::time::Duration::from_secs(10), + "{:?}", + start.elapsed() + ); + let out = String::from_utf8_lossy(&o.stdout); + assert!(out.contains("no answer within 2 s"), "{out}"); +} + +#[cfg(unix)] +#[test] +fn version_read_by_a_tool_that_takes_only_the_first_line_still_exits_0() { + use std::io::BufRead; + let d = tempfile::tempdir().unwrap(); + let bin = d.path().join("v2bin"); + // The other copy answers after the reader has gone (`al-runner --version | head -1`). + fake_al_runner(&bin, "/bin/sleep 1; echo 'AL Runner 1.0.99'"); + let home = d.path().join("home"); + let mut child = Command::new(env!("CARGO_BIN_EXE_al-runner")) + .env_remove("ALRUNNER_NO_PATH_NOTE") + .env("PATH", &bin) + .env("HOME", &home) + .env("ALRUNNER_CACHE", home.join("cache")) + .arg("--version") + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap(); + let mut first = String::new(); + std::io::BufReader::new(child.stdout.take().unwrap()) + .read_line(&mut first) + .unwrap(); + assert!(first.starts_with("al-runner "), "{first}"); + let o = child.wait_with_output().unwrap(); + assert_eq!(code(&o), 0, "{}", String::from_utf8_lossy(&o.stderr)); +} diff --git a/crates/alrunner-cli/tests/fixtures/impact/baseapp-ext/ResLedgerQty.Codeunit.al b/crates/alrunner-cli/tests/fixtures/impact/baseapp-ext/ResLedgerQty.Codeunit.al index 30588c6a5..7504f90fa 100644 --- a/crates/alrunner-cli/tests/fixtures/impact/baseapp-ext/ResLedgerQty.Codeunit.al +++ b/crates/alrunner-cli/tests/fixtures/impact/baseapp-ext/ResLedgerQty.Codeunit.al @@ -1,6 +1,6 @@ // An example extension for a manual impact run against Microsoft's resource tests (not run by `cargo test`: it needs // the Base App). It doubles the quantity of every resource ledger entry that a resource journal line posts. -// alrunner test "/Applications/BaseApp/Test/Tests-Resource.Source.zip" --codeunit 136403 \ +// al-runner test "/Applications/BaseApp/Test/Tests-Resource.Source.zip" --codeunit 136403 \ // --impact-of crates/alrunner-cli/tests/fixtures/impact/baseapp-ext --impact all codeunit 50540 "Impact Example Res. Qty" { diff --git a/crates/alrunner-cli/tests/impact.rs b/crates/alrunner-cli/tests/impact.rs index 6362f16ef..58c860c2d 100644 --- a/crates/alrunner-cli/tests/impact.rs +++ b/crates/alrunner-cli/tests/impact.rs @@ -1,4 +1,4 @@ -//! `alrunner test --impact-of` (ADR-043 step 1: two runs and a diff) end to end on the small fixture apps in +//! `al-runner test --impact-of` (ADR-043 step 1: two runs and a diff) end to end on the small fixture apps in //! `tests/fixtures/impact`. Nothing here is Microsoft's code: `lib` stands in for the Base App (a publisher), //! `tests` for a Microsoft test app, `ext` for a partner extension (a subscriber), `unrelated` for an app that //! touches nothing the tests reach. @@ -16,14 +16,16 @@ fn fixture(name: &str) -> String { fn alrunner(args: &[&str]) -> Output { let cache = tempfile::tempdir().unwrap(); - Command::new(env!("CARGO_BIN_EXE_alrunner")) + Command::new(env!("CARGO_BIN_EXE_al-runner")) .env("AL_CHECK_THREADS", "2") .env("AL_LOWER_THREADS", "2") .env("AL_TEST_THREADS", "2") + // The note about another al-runner on PATH (the machine may have AL Runner v2) stays out of these outputs. + .env("ALRUNNER_NO_PATH_NOTE", "1") .args(args) .args(["--no-download", "--cache-dir", cache.path().to_str().unwrap()]) .output() - .expect("run alrunner") + .expect("run al-runner") } fn text(o: &Output) -> String { @@ -172,7 +174,7 @@ fn without_an_index_the_run_selects_by_static_reach_and_says_what_that_misses() "{t}" ); assert!( - t.contains("Build the index once with: alrunner impact-index build"), + t.contains("Build the index once with: al-runner impact-index build"), "{t}" ); // Only codeunit 50510 calls the publisher the extension subscribes to; both sides run it. @@ -225,14 +227,16 @@ fn without_an_index_the_run_selects_by_static_reach_and_says_what_that_misses() } fn alrunner_in(cache: &std::path::Path, args: &[&str]) -> Output { - Command::new(env!("CARGO_BIN_EXE_alrunner")) + Command::new(env!("CARGO_BIN_EXE_al-runner")) .env("AL_CHECK_THREADS", "2") .env("AL_LOWER_THREADS", "2") .env("AL_TEST_THREADS", "2") + // The note about another al-runner on PATH (the machine may have AL Runner v2) stays out of these outputs. + .env("ALRUNNER_NO_PATH_NOTE", "1") .args(args) .args(["--no-download", "--cache-dir", cache.to_str().unwrap()]) .output() - .expect("run alrunner") + .expect("run al-runner") } #[test] diff --git a/crates/alrunner-cli/tests/install_script.rs b/crates/alrunner-cli/tests/install_script.rs new file mode 100644 index 000000000..932c82d90 --- /dev/null +++ b/crates/alrunner-cli/tests/install_script.rs @@ -0,0 +1,132 @@ +//! `release/install.sh` against a local folder that looks like a release (ALRUNNER_DOWNLOAD_BASE). The binary +//! is a fake shell script; nothing is downloaded. Linux x64 and macOS arm64 only, as the script. + +#![cfg(unix)] + +use std::os::unix::fs::PermissionsExt; +use std::path::{Path, PathBuf}; +use std::process::{Command, Output}; + +fn target() -> Option<&'static str> { + match (std::env::consts::OS, std::env::consts::ARCH) { + ("linux", "x86_64") => Some("x86_64-unknown-linux-musl"), + ("macos", "aarch64") => Some("aarch64-apple-darwin"), + _ => None, + } +} + +fn script(p: &Path, body: &str) { + std::fs::create_dir_all(p.parent().unwrap()).unwrap(); + std::fs::write(p, format!("#!/bin/sh\n{body}\n")).unwrap(); + std::fs::set_permissions(p, std::fs::Permissions::from_mode(0o755)).unwrap(); +} + +/// A release folder with one archive `-