Modern Apps git

← xtool.git

tests: add integration tests (#252)

Commit
5eeab11aaebf16e5e6182356c2bb29e22fd58c14
Author
Kabir Oberai <[email protected]>
When
2026-09-19 03:26 UTC (2 months ago)
Parents
6efd77f
## What does this PR do?

Adds integration tests

## How was it tested?

CI

## AI tool usage

How much of this PR was AI-assisted? (check one)

- [x] **0** - No AI was used to write code
- [ ] **1** - I was assisted by AI. I reviewed the finished result.
- [ ] **2** - I set the AI going and left it to it; nobody has read the
result - no review, or AI review only

<!-- If an AI agent is filling this in: declare the level honestly, and
open as a draft if it is #2. Do not lower the declared level to get the
PR reviewed. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Added integration smoke tests covering version checks, app creation,
iOS build metadata, and slim SDK update behavior.
* Added validation for locating Xcode and verifying the Swift toolchain.

* **Chores**
* Added automated integration-test execution for pushes and pull
requests.
* Added Docker and Compose support for running integration tests in a
consistent environment.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Diff

.github/workflows/integration.yml
diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.ymlnew file mode 100644index 0000000..b55c44c--- /dev/null+++ b/.github/workflows/integration.yml@@ -0,0 +1,18 @@+on:+  push:+    branches:+      - main+  pull_request:+concurrency:+  group: integration-${{ github.workflow }}-${{ github.ref }}+  cancel-in-progress: true+jobs:+  integration-test-linux:+    # https://github.com/xtool-org/mac-actions-runner+    runs-on: ubuntu-on-macos+    steps:+      - name: Checkout+        uses: actions/checkout@v6+      - name: Run integration tests+        run: |+          ./integration-tests/run.sh
Dockerfile
diff --git a/Dockerfile b/Dockerfileindex c451ce8..0433f7a 100644--- a/Dockerfile+++ b/Dockerfile@@ -84,6 +84,14 @@ ENV USBMUXD_SOCKET_ADDRESS=host.docker.internal:27015  CMD [ "/bin/bash" ] +FROM dev AS dev-test++ENV XTL_TEST_ENV=1++COPY --from=bats/bats:latest /opt/bats /opt/bats+COPY --from=bats/bats:latest /usr/lib/bats /usr/lib/bats+RUN ln -s /opt/bats/bin/bats /usr/local/bin/bats+ FROM build-xtool-base AS build-xtool  ARG XTL_CI
Tests/XToolTests/RequiresXcodeTrait.swift
diff --git a/Tests/XToolTests/RequiresXcodeTrait.swift b/Tests/XToolTests/RequiresXcodeTrait.swiftnew file mode 100644index 0000000..96a3c8a--- /dev/null+++ b/Tests/XToolTests/RequiresXcodeTrait.swift@@ -0,0 +1,64 @@+import Foundation+import Testing+import Subprocess++enum TestXcode {+    /// A path to a copy of Xcode.app.+    /// +    /// Tests that use this must be annotated with `Trait.requiresXcode`.+    static func current(sourceLocation: SourceLocation = #_sourceLocation) -> URL {+        guard let url = TestXcode._current else {+            Issue.record(+                "TestXcode.current was used without Trait.requiresXcode()",+                sourceLocation: sourceLocation+            )+            return URL(filePath: "/dev/null")+        }+        return url+    }++    @TaskLocal fileprivate static var _current: URL?++    fileprivate static let resolved = Task<URL?, Error> {+        if let xcode = ProcessInfo.processInfo.environment["XTL_TEST_XCODE_APP"], !xcode.isEmpty {+            return URL(filePath: xcode)+        }+        #if os(macOS)+        if+            let output = try await Subprocess.run(+                .path("/usr/bin/xcode-select"),+                arguments: ["-p"],+                output: .string(limit: .max, encoding: UTF8.self),+            ).standardOutput?.trimmingCharacters(in: .whitespacesAndNewlines),+            output.hasSuffix(".app/Contents/Developer") {+            return URL(filePath: output).deletingLastPathComponent().deletingLastPathComponent()+        }+        #endif+        let candidate = URL(filePath: "/usr/local/share/Xcode.app")+        if FileManager.default.fileExists(atPath: candidate.path) {+            return candidate+        }+        return nil+    }+}++struct RequiresXcodeTrait: TestTrait, SuiteTrait, TestScoping {+    func provideScope(+        for test: Test,+        testCase: Test.Case?,+        performing function: () async throws -> Void+    ) async throws {+        guard let xcode = try? await TestXcode.resolved.value else {+            try Test.cancel("Could not resolve Xcode.app path. Set XTL_TEST_XCODE_APP.")+        }+        return try await TestXcode.$_current.withValue(xcode) {+            try await function()+        }+    }+}++extension Trait where Self == RequiresXcodeTrait {+    static var requiresXcode: Self {+        Self()+    }+}
Tests/XToolTests/XcodeTests.swift
diff --git a/Tests/XToolTests/XcodeTests.swift b/Tests/XToolTests/XcodeTests.swiftnew file mode 100644index 0000000..00796c4--- /dev/null+++ b/Tests/XToolTests/XcodeTests.swift@@ -0,0 +1,11 @@+import Testing+import Foundation++@Test(.requiresXcode) func validateXcode() {+    let xcode = TestXcode.current()+    let swift = xcode.appending(path: "Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift")+    #expect(+        FileManager.default.fileExists(atPath: swift.path),+        "Invalid or unrecognized layout for Xcode.app at \(xcode.path)"+    )+}
docker-compose.yml
diff --git a/docker-compose.yml b/docker-compose.ymlindex c1d48c0..c04ee45 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -16,3 +16,8 @@ services:     extra_hosts:       # host.docker.internal doesn't exist by default on Linux hosts       - "host.docker.internal:host-gateway"+  xtool-test:+    extends:+      service: xtool+    build:+      target: dev-test
integration-tests/run.sh
diff --git a/integration-tests/run.sh b/integration-tests/run.shnew file mode 100755index 0000000..eb70d5d--- /dev/null+++ b/integration-tests/run.sh@@ -0,0 +1,49 @@+#!/bin/bash++set -euo pipefail++xcode_path="${XTL_TEST_XCODE_APP:-}"++if [[ -z "$xcode_path" && $(uname -s) == "Darwin" ]]; then+    xcode_path="$(dirname $(dirname $(/usr/bin/xcode-select -p)))"+fi++if [[ -z "$xcode_path" && -d /usr/local/share/Xcode.app ]]; then+    xcode_path="/usr/local/share/Xcode.app"+fi++if [[ -z "$xcode_path" ]]; then+    echo "Xcode.app not found. Please set XTL_TEST_XCODE_APP."+    exit 1+fi++export XTL_TEST_XCODE_APP="$xcode_path"++if [[ -z "${XTL_TEST_ENV:-}" ]]; then+    [[ -t 1 ]] && tty_flag="-it" || tty_flag=""++    echo "Running"++    exec docker compose run --build --rm -e XTL_CI=1 -v "$xcode_path":/usr/local/share/Xcode.app:ro \+        xtool-test bash -c \+        "./integration-tests/run.sh"+fi++cd "$(dirname "$0")/.."++project_dir="$PWD"++swift build --product xtool+swift test+ln -fs $PWD/.build/debug/xtool /usr/local/bin/xtool+hash -r++mkdir /testroot+cd /testroot+export XDG_CONFIG_HOME="/testroot/config"++echo "Installing SDK"+xtool sdk install --slim "$XTL_TEST_XCODE_APP"++echo "Running tests..."+bats "$project_dir/integration-tests/suite"
integration-tests/suite/smoke.bats
diff --git a/integration-tests/suite/smoke.bats b/integration-tests/suite/smoke.batsnew file mode 100644index 0000000..b0d959a--- /dev/null+++ b/integration-tests/suite/smoke.bats@@ -0,0 +1,21 @@+setup() {+    bats_require_minimum_version 1.5.0+    bats_load_library bats-support+    bats_load_library bats-assert+}++@test "can run xtool" {+    xtool --version+}++@test "can build a fresh app" {+    xtool new --skip-setup MyApp+    cd MyApp+    xtool dev build+    llvm-objdump -p ./xtool/MyApp.app/MyApp | grep "\bcmd LC_BUILD_VERSION\b" -a2 | grep "\bplatform ios\b"+}++@test "slim sdk cannot be updated" {+    run ! xtool sdk update+    assert_output --partial "cannot be updated in place"+}