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
29 changes: 28 additions & 1 deletion .github/workflows/bc-test-from-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,20 @@ on:
required: false
type: string
default: "auto"
test_runner_codeunit_id:
description: >-
Run the test suite through this test runner codeunit, for example
130451 "Test Runner - Isol. Disabled" or a test app's own codeunit
with Subtype = TestRunner (BcContainerHelper's -testRunnerCodeunitId).
Blank (default) uses 130450 "Test Runner - Isol. Codeunit",
BcContainerHelper's default. Only the websocket runner
runs tests through a runner codeunit, so when this is set every
codeunit goes to it: test_runner=auto uses websocket for the whole
run, and test_runner=altool fails. Results come back in the same JUnit
format (issue #193).
required: false
type: string
default: ""
altool_transport:
description: >-
How the altool leg of test_runner=auto reaches the TestRunnerHub.
Expand Down Expand Up @@ -833,7 +847,7 @@ jobs:
# - test_runner=auto on an older version → skip the install; the
# run step's live probe will route to the websocket runner
- name: Install AL dotnet tool (altool test runner)
if: inputs.test_runner != 'websocket'
if: inputs.test_runner != 'websocket' && inputs.test_runner_codeunit_id == ''
run: |
set -e
BC_MAJOR=$(echo "${{ inputs.bc_version }}" | cut -d. -f1)
Expand Down Expand Up @@ -1322,6 +1336,18 @@ jobs:
# "altool" without server support fails inside the script with
# a clear error instead of silently degrading.
EFFECTIVE_RUNNER="${{ inputs.test_runner }}"
# A runner codeunit only exists on the websocket path; the hub runs
# tests without one (issue #193).
RUNNER_CODEUNIT_ARGS=()
if [ -n "${{ inputs.test_runner_codeunit_id }}" ]; then
RUNNER_CODEUNIT_ARGS=(--test-runner-codeunit "${{ inputs.test_runner_codeunit_id }}")
if [ "$EFFECTIVE_RUNNER" = "altool" ]; then
echo "ERROR: test_runner_codeunit_id needs the websocket runner; test_runner=altool runs tests without a runner codeunit"
exit 1
fi
EFFECTIVE_RUNNER="websocket"
echo "test_runner_codeunit_id=${{ inputs.test_runner_codeunit_id }}: using the websocket runner for every codeunit"
fi
if [ "$EFFECTIVE_RUNNER" = "auto" ]; then
if [ -x "$HOME/.dotnet/tools/al" ] \
&& python3 scripts/run-tests-altool.py --probe --port "$BC_DEV_PORT"; then
Expand Down Expand Up @@ -1406,6 +1432,7 @@ jobs:
--base-url "http://localhost:${BC_ODATA_PORT}/BC" \
--dev-url "http://localhost:${BC_DEV_PORT}/BC/dev" \
"${COMPANY_ARGS[@]}" \
"${RUNNER_CODEUNIT_ARGS[@]}" \
--timeout ${{ inputs.test_timeout_minutes }} 2>&1 | tee "$tmplog"
fi
RUN_TESTS_RC=${PIPESTATUS[0]}
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/bc-test-prebuilt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ on:
"50000..50100,130450,200000..210000" mixed
required: true
type: string
test_runner_codeunit_id:
description: >-
Run the test suite through this test runner codeunit, for example
130451 "Test Runner - Isol. Disabled" or a test app's own codeunit
with Subtype = TestRunner (BcContainerHelper's -testRunnerCodeunitId).
Blank (default) uses 130450 "Test Runner - Isol. Codeunit",
BcContainerHelper's default. Results come back in the same JUnit
format (issue #193).
required: false
type: string
default: ""
extra_apps:
description: >-
Newline-separated names of Microsoft apps from the BC artifact to
Expand Down Expand Up @@ -479,6 +490,10 @@ jobs:
if [ -n "${TEST_COMPANY:-}" ]; then
COMPANY_ARGS=(--company "$TEST_COMPANY")
fi
RUNNER_CODEUNIT_ARGS=()
if [ -n "${{ inputs.test_runner_codeunit_id }}" ]; then
RUNNER_CODEUNIT_ARGS=(--test-runner-codeunit "${{ inputs.test_runner_codeunit_id }}")
fi
# Per-app JUnit XML — see bc-test-from-source.yml for the rationale.
mkdir -p ../build
for app in $TEST_APP_FILES; do
Expand All @@ -494,6 +509,7 @@ jobs:
--base-url "http://localhost:${BC_ODATA_PORT}/BC" \
--dev-url "http://localhost:${BC_DEV_PORT}/BC/dev" \
"${COMPANY_ARGS[@]}" \
"${RUNNER_CODEUNIT_ARGS[@]}" \
--timeout 30 2>&1 | tee "$tmplog"
# `tee` always exits 0; capture run-tests.sh's real exit code.
RUN_TESTS_RC=${PIPESTATUS[0]}
Expand Down
13 changes: 13 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ moved.
part safe to re-post. `--timeout` is scaled by the number of parts, because it
used to be a per-part budget and is now a whole-run one.

**The runner codeunit can be chosen** (issue #193). The suite runs through page
130455 with runner 130450 "Test Runner - Isol. Codeunit", BcContainerHelper's
default. `--test-runner-codeunit <id>` on `run-tests.sh`, and the
`test_runner_codeunit_id` input on both reusable workflows, set the suite's
"Test Runner Id" instead (field `TestRunnerId` on table 99903, Test Runner
Extension 3.3.0.0). That covers 130451 and a test app's own `Subtype =
TestRunner` codeunit (BcContainerHelper's `-testRunnerCodeunitId`). The hub has
no runner codeunit, so with the input set `bc-test-from-source.yml` sends every
codeunit to the websocket runner, and `test_runner=altool` fails. A runner id
that does not exist fails the run with BC's "An object with that ID does not
exist". The extension cannot check it earlier: it has no platform dependency,
so `AllObj` is not visible to it.

**EXPERIMENTAL altool runner (BC 28+ only):** `scripts/run-tests-altool.py` runs tests through the AL dotnet tool's native `al runtests` command (Microsoft.Dynamics.BusinessCentral.Development.Tools, 18.x prerelease — stable 17.x has no `runtests`), which drives the NST's built-in SignalR hub at `/dev/TestRunnerHub`. No TestRunnerExtension, no OData suite, no WebSocket emulation — the server pushes per-method results (status, output, duration) over the hub. Requires the server to advertise Dev API 7.0 (`GET /BC/dev/metadata`), which only exists in BC 28.0+. Caveats: tests do NOT run under an AL test runner codeunit (no AI tests, no test-runner setup/teardown events, isolation from `RequiredTestIsolation`, default Codeunit) — so Microsoft BCApps suites may behave differently than under `run-tests.sh`; the test app must already be published+installed (the script doesn't publish). The reusable workflow's `test_runner` input defaults to `auto`: after BC is healthy it probes `GET /dev/metadata` (via `run-tests-altool.py --probe`, exit 0 = Dev API ≥ 7.0) and uses the altool runner when supported, falling back to the websocket runner otherwise — so 27.x legs and consumers on older versions keep working unchanged. `websocket` forces the legacy flow; `altool` forces the hub and fails hard when unsupported (the regression-detection mode). `altool_version` pins the dotnet tool. Auth comes from `BC_SERVER_USERNAME`/`BC_SERVER_PASSWORD` env vars, which the script sets from `--auth`. The script's stdout deliberately prints the same `N total, P passed, F failed` and `Test codeunits: ...` lines the workflow parser greps — keep that contract if you touch either side.

### Editing the startup hook
Expand Down
Binary file modified extensions/TestRunnerExtension/TestRunnerExtension.app
Binary file not shown.
2 changes: 1 addition & 1 deletion extensions/TestRunnerExtension/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"name": "Test Runner Extension",
"publisher": "ALDirectCompile",
"version": "3.2.0.0",
"version": "3.3.0.0",
"runtime": "16.0",
"target": "OnPrem",
"dependencies": [
Expand Down
25 changes: 23 additions & 2 deletions extensions/TestRunnerExtension/src/RunnerTable.al
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ table 99903 "Codeunit Run Request"
Caption = 'Last Execution (UTC)';
DataClassification = SystemMetadata;
}

/// <summary>
/// The test runner codeunit SetupSuite and SetupSuiteAppend give the DEFAULT suite
/// (issue #193). 0 means 130450 "Test Runner - Isol. Codeunit", BcContainerHelper's
/// default. Set it to run the suite through another runner, such as a test app's own
/// codeunit with Subtype = TestRunner (BcContainerHelper's -testRunnerCodeunitId).
/// </summary>
field(7; TestRunnerId; Integer)
{
Caption = 'Test Runner Id';
DataClassification = SystemMetadata;
}
}

keys
Expand Down Expand Up @@ -179,6 +191,7 @@ page 99902 "Codeunit Run Requests"
field(Id; Rec.Id) { Editable = false; }
field(CodeunitId; Rec.CodeunitId) { }
field(CodeunitIds; Rec.CodeunitIds) { }
field(TestRunnerId; Rec.TestRunnerId) { }
field(Status; Rec.Status) { Editable = false; }
field(LastResult; Rec.LastResult) { Editable = false; }
field(LastExecutionUTC; Rec.LastExecutionUTC) { Editable = false; }
Expand Down Expand Up @@ -222,7 +235,7 @@ page 99902 "Codeunit Run Requests"
// 130450 = TestIsolation=Codeunit (fresh session per codeunit) ← CORRECT
// 130451 = TestIsolation=Disabled (no isolation) ← WRONG, causes cascading failures
SuiteRunner.InitSuite('DEFAULT');
OverrideSuiteRunner('DEFAULT', 130450);
OverrideSuiteRunner('DEFAULT', SuiteRunnerId());
exit(AddRequestedCodeunits(SuiteRunner, 'Suite ready') > 0);
end;

Expand All @@ -249,7 +262,7 @@ page 99902 "Codeunit Run Requests"
exit(false);

SuiteRunner.InitSuiteKeep('DEFAULT');
OverrideSuiteRunner('DEFAULT', 130450);
OverrideSuiteRunner('DEFAULT', SuiteRunnerId());
exit(AddRequestedCodeunits(SuiteRunner, 'Suite extended') > 0);
end;

Expand Down Expand Up @@ -334,6 +347,14 @@ page 99902 "Codeunit Run Requests"
exit(true);
end;

/// <summary>TestRunnerId, or 130450 when it is 0.</summary>
local procedure SuiteRunnerId(): Integer
begin
if Rec.TestRunnerId = 0 then
exit(130450);
exit(Rec.TestRunnerId);
end;

local procedure OverrideSuiteRunner(SuiteName: Code[10]; RunnerId: Integer)
var
ALTestSuite: Record "AL Test Suite";
Expand Down
30 changes: 27 additions & 3 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
TEST_RUNNER_APP=""
JUNIT_OUTPUT=""
RENEW_CLIENT_CONTEXT=0
TEST_RUNNER_CODEUNIT=""

show_help() {
cat <<'HELPEOF'
Expand Down Expand Up @@ -87,6 +88,12 @@ Options:
the whole suite, so SingleInstance codeunit state carries
across test codeunits the way it does on a real tier.
Turn this on only to reproduce the pre-#65 behaviour.
--test-runner-codeunit <id>
Run the suite through this test runner codeunit, for
example 130451 or a test app's own codeunit with
Subtype = TestRunner (BcContainerHelper's
-testRunnerCodeunitId). Default: 130450 "Test Runner -
Isol. Codeunit", BcContainerHelper's default.
-h, --help Show this help

Examples:
Expand Down Expand Up @@ -115,12 +122,19 @@ while [[ $# -gt 0 ]]; do
--disabled-tests) DISABLED_TESTS_DIR="$2"; shift 2;;
--junit-output) JUNIT_OUTPUT="$2"; shift 2;;
--renew-client-context) RENEW_CLIENT_CONTEXT=1; shift;;
--test-runner-codeunit) TEST_RUNNER_CODEUNIT="$2"; shift 2;;
--host|--test-runner|--suite-name|--codeunit-timeout|--extension-id|--sql-password) shift 2;;
*) echo "Unknown option: $1 (try --help)"; exit 1;;
esac
done

if [ -n "$TEST_RUNNER_CODEUNIT" ] && ! [[ "$TEST_RUNNER_CODEUNIT" =~ ^[1-9][0-9]*$ ]]; then
echo "ERROR: --test-runner-codeunit must be a codeunit id, got '$TEST_RUNNER_CODEUNIT'"
exit 1
fi

echo "=== BC Test Runner ==="
[ -n "$TEST_RUNNER_CODEUNIT" ] && echo "Test runner codeunit: $TEST_RUNNER_CODEUNIT"

# --- Helper ---
py3() { env -u PYTHONHOME -u PYTHONPATH python3 "$@"; }
Expand Down Expand Up @@ -440,11 +454,17 @@ REQUEST_ID=""
setup_suite_chunk() {
local chunk="$1" label="$2" action="${3:-setupSuite}"
echo -n "Setting up test suite${label}... "
local create_body create_http
local create_body create_http request_json
# TestRunnerId arrived in Test Runner Extension 3.3.0.0 (issue #193). Only send it when
# asked for, so the default run still works against an older image.
request_json="{\"CodeunitIds\": \"$chunk\"}"
if [ -n "$TEST_RUNNER_CODEUNIT" ]; then
request_json="{\"CodeunitIds\": \"$chunk\", \"TestRunnerId\": $TEST_RUNNER_CODEUNIT}"
fi
create_body=$(mktemp)
create_http=$(curl -s -o "$create_body" -w "%{http_code}" --max-time 15 -u "$AUTH" -X POST \
-H "Content-Type: application/json" \
-d "{\"CodeunitIds\": \"$chunk\"}" \
-d "$request_json" \
"${API_BASE}/codeunitRunRequests" 2>/dev/null)
REQUEST_ID=$(py3 -c "import sys,json; print(json.load(sys.stdin)['Id'])" < "$create_body" 2>/dev/null || true)

Expand All @@ -453,7 +473,7 @@ setup_suite_chunk() {
echo ""
echo "ERROR: POST ${API_BASE}/codeunitRunRequests"
echo " HTTP code: $create_http"
echo " Request body: {\"CodeunitIds\": \"$chunk\"}"
echo " Request body: $request_json"
echo " CodeunitIds length: ${#chunk} chars (BC's field limit is 2048)"
echo " Response body:"
sed 's/^/ /' "$create_body"
Expand All @@ -466,6 +486,10 @@ setup_suite_chunk() {
echo " POST in this BC version (the auto-detection picked an endpoint that"
echo " accepts GET on this path but not POST)."
echo " - The request body schema doesn't match the page's bound action."
if [ -n "$TEST_RUNNER_CODEUNIT" ]; then
echo " - The bc-runner image is older than this script: TestRunnerId"
echo " (--test-runner-codeunit) needs Test Runner Extension 3.3.0.0."
fi
echo " - Application_StringExceededLength above means the part is still"
echo " too long — lower BC_CODEUNIT_IDS_MAX_CHARS (currently"
echo " ${CODEUNIT_IDS_MAX_CHARS})."
Expand Down
Loading