diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2b851e9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,264 @@ +name: Build + +# The binaries the StackQL installers take: the Windows executable for each +# processor the MSI comes for, and the Mac app. CI calls this on every run +# and the release workflow calls it for a tag, so what a release ships is +# built, checked and named the way every commit is. +# +# Nothing here is signed for release. The StackQL release signs what it +# ships. + +on: + workflow_call: + inputs: + ref: + description: The commit, branch or tag to build. Empty builds what the caller runs on. + type: string + required: false + default: '' + +permissions: + contents: read + +jobs: + # The Mac app, and a test build of it as a disk image. The signature is ad + # hoc, with no Developer ID, and nothing is notarised. + macos: + name: Bundle (macOS, universal) + runs-on: macos-latest + timeout-minutes: 60 + + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ inputs.ref }} + + - uses: actions/setup-node@v7 + with: + node-version: 24 + cache: npm + + # A universal build needs the standard library for both architectures. + - uses: dtolnay/rust-toolchain@stable + with: + targets: aarch64-apple-darwin,x86_64-apple-darwin + + - uses: Swatinem/rust-cache@v2 + with: + workspaces: src-tauri + + - name: Install webview dependencies + run: npm ci + + # An Apple Silicon Mac runs no code without a signature. "-" asks for an + # ad hoc one, which needs no certificate. + - name: Build the app and the disk image + env: + APPLE_SIGNING_IDENTITY: '-' + run: npm run tauri build -- --target universal-apple-darwin --bundles app,dmg + + - name: Check the bundle + shell: bash + run: | + bundle=src-tauri/target/universal-apple-darwin/release/bundle + app=$(ls -d "$bundle"/macos/*.app) + archs=$(lipo -archs "$app/Contents/MacOS/stackql-workbench") + echo "Architectures: $archs" + [[ "$archs" == *arm64* && "$archs" == *x86_64* ]] + codesign --verify --deep --strict --verbose=2 "$app" + codesign --display --verbose=2 "$app" + ls -l "$bundle"/dmg + + # The app must stand on its own too. Everything it links to has to be + # part of macOS: a system framework, or a library under /usr/lib. The + # page renderer is one of those frameworks, so there is nothing to ship + # with the app as there is on Windows. + - name: Check what the app asks the system for + shell: bash + run: | + bundle=src-tauri/target/universal-apple-darwin/release/bundle + app=$(ls -d "$bundle"/macos/*.app) + needed=$(otool -L "$app/Contents/MacOS/stackql-workbench" \ + | grep -E '^[[:space:]]' | awk '{print $1}' | sort -u) + echo "$needed" + foreign=$(echo "$needed" | grep -v -E '^(/System/Library/|/usr/lib/)' || true) + if [ -n "$foreign" ]; then + echo "Not part of macOS:" + echo "$foreign" + exit 1 + fi + # Nothing else is carried in the bundle that would have to be signed. + find "$app/Contents" -type f \( -name '*.dylib' -o -name '*.so' \) -print + + # The pages need a renderer of a certain age, and on a Mac the renderer + # is the one that macOS has. The bundle names the oldest macOS it runs + # on, so an older one refuses to open it. Both halves of the executable + # must be built for that version as well. + - name: Check the oldest macOS the app runs on + shell: bash + run: | + bundle=src-tauri/target/universal-apple-darwin/release/bundle + app=$(ls -d "$bundle"/macos/*.app) + want=$(node -p "require('./src-tauri/tauri.conf.json').bundle.macOS.minimumSystemVersion") + declared=$(/usr/libexec/PlistBuddy -c 'Print :LSMinimumSystemVersion' "$app/Contents/Info.plist") + echo "Wanted: $want" + echo "Declared in Info.plist: $declared" + [ "$declared" = "$want" ] + built=$(otool -l "$app/Contents/MacOS/stackql-workbench" \ + | awk '$1 == "minos" {print $2}' | sort -u) + echo "Built for: $built" + [ "$built" = "$want" ] + + - uses: actions/upload-artifact@v7 + with: + name: stackql-workbench-macos-universal + path: src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg + if-no-files-found: error + + # The app on its own, for the StackQL PKG, which installs it beside the + # stackql command and signs what it ships. It is packed with tar because + # a bundle holds links and permissions that a zip of loose files loses. + - name: Pack the app for the installer + shell: bash + run: | + bundle=src-tauri/target/universal-apple-darwin/release/bundle + app=$(ls -d "$bundle"/macos/*.app) + mkdir -p installer-input + tar -czf installer-input/stackql-workbench-macos-universal.app.tar.gz \ + -C "$(dirname "$app")" "$(basename "$app")" + cd installer-input + shasum -a 256 stackql-workbench-macos-universal.app.tar.gz \ + > stackql-workbench-macos-universal.app.tar.gz.sha256 + cat stackql-workbench-macos-universal.app.tar.gz.sha256 + tar -tzf stackql-workbench-macos-universal.app.tar.gz | head -n 12 + + - uses: actions/upload-artifact@v7 + with: + name: stackql-workbench-macos-universal-app + path: installer-input/* + if-no-files-found: error + + # The executable the StackQL MSI installs beside stackql.exe. It is the + # optimised build, with no installer of its own. + # + # The MSI comes for x64 and for arm64, so there is one build for each, made + # on a runner of that processor. Nothing is built across. + windows: + name: Build (Windows, ${{ matrix.arch }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + include: + - arch: x64 + os: windows-latest + - arch: arm64 + os: windows-11-arm + + steps: + - uses: actions/checkout@v7 + with: + ref: ${{ inputs.ref }} + + - uses: actions/setup-node@v7 + with: + node-version: 24 + cache: npm + + - uses: dtolnay/rust-toolchain@stable + + # Kept apart from the cache of the checks, which hold a debug build. + - uses: Swatinem/rust-cache@v2 + with: + workspaces: src-tauri + key: release + + - name: Install webview dependencies + run: npm ci + + - name: Build the executable + run: npm run tauri build -- --no-bundle + + # The executable must stand on its own in the installer's folder. It + # carries its C runtime inside it, so what it asks the system for is + # Windows itself. This reads its import tables and fails on a runtime. + # It also fails when the executable is not built for this processor. + - name: Check what the executable asks the system for + run: node scripts/check-exe-imports.js src-tauri/target/release/stackql-workbench.exe ${{ matrix.arch }} + + - name: Pack the executable for the installer + shell: pwsh + run: | + $exe = 'src-tauri/target/release/stackql-workbench.exe' + New-Item -ItemType Directory -Force installer-input | Out-Null + Copy-Item $exe installer-input/ + $hash = (Get-FileHash installer-input/stackql-workbench.exe -Algorithm SHA256).Hash.ToLower() + "$hash stackql-workbench.exe" | Set-Content installer-input/stackql-workbench.exe.sha256 + Get-Item installer-input/stackql-workbench.exe | Format-List Name, Length + Get-Content installer-input/stackql-workbench.exe.sha256 + + - uses: actions/upload-artifact@v7 + with: + name: stackql-workbench-windows-${{ matrix.arch }} + path: installer-input/* + if-no-files-found: error + + # The three files as a release names them, in one artifact, each with its + # SHA-256. The names follow the StackQL release: amd64 and arm64 for + # Windows, multiarch for the Mac. The release workflow attaches exactly + # these files, so what it attaches has been put together on every run + # before it. + assets: + name: Release assets + needs: [macos, windows] + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/download-artifact@v8 + with: + pattern: stackql-workbench-* + path: built + + - name: Name the files as a release names them + shell: bash + run: | + set -euo pipefail + mkdir release-assets + + # Copies one built file under its release name, after checking it + # against the SHA-256 the job that built it wrote down. + take() { + local folder="built/$1" file="$2" name="$3" + local want have + want=$(awk '{print $1}' "$folder/$file.sha256" | tr -d '\r') + have=$(sha256sum "$folder/$file" | awk '{print $1}') + if [ "$want" != "$have" ]; then + echo "$folder/$file is not the file that was built: $have, expected $want" + exit 1 + fi + cp "$folder/$file" "release-assets/$name" + } + + take stackql-workbench-windows-x64 stackql-workbench.exe \ + stackql-workbench_windows_amd64.exe + take stackql-workbench-windows-arm64 stackql-workbench.exe \ + stackql-workbench_windows_arm64.exe + take stackql-workbench-macos-universal-app stackql-workbench-macos-universal.app.tar.gz \ + stackql-workbench_darwin_multiarch.app.tar.gz + + cd release-assets + for file in *; do + sha256sum "$file" > "$file.sha256" + done + ls -l + cat ./*.sha256 + + - uses: actions/upload-artifact@v7 + with: + name: stackql-workbench-release-assets + path: release-assets/* + if-no-files-found: error + # A job that is run again replaces what its first attempt left. + overwrite: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3d07da..78c1b12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,184 +115,10 @@ jobs: - name: Debug build run: npm run tauri build -- --debug --no-bundle - # A test build for a Mac, kept as a workflow artifact. It is not a release: - # the signature is ad hoc, with no Developer ID, and nothing is notarised. - # It does not wait for the checks, so a failing test still leaves a build. - bundle-macos: - name: Bundle (macOS, universal) - runs-on: macos-latest - timeout-minutes: 60 - - steps: - - uses: actions/checkout@v7 - - - uses: actions/setup-node@v7 - with: - node-version: 24 - cache: npm - - # A universal build needs the standard library for both architectures. - - uses: dtolnay/rust-toolchain@stable - with: - targets: aarch64-apple-darwin,x86_64-apple-darwin - - - uses: Swatinem/rust-cache@v2 - with: - workspaces: src-tauri - - - name: Install webview dependencies - run: npm ci - - # An Apple Silicon Mac runs no code without a signature. "-" asks for an - # ad hoc one, which needs no certificate. - - name: Build the app and the disk image - env: - APPLE_SIGNING_IDENTITY: '-' - run: npm run tauri build -- --target universal-apple-darwin --bundles app,dmg - - - name: Check the bundle - shell: bash - run: | - bundle=src-tauri/target/universal-apple-darwin/release/bundle - app=$(ls -d "$bundle"/macos/*.app) - archs=$(lipo -archs "$app/Contents/MacOS/stackql-workbench") - echo "Architectures: $archs" - [[ "$archs" == *arm64* && "$archs" == *x86_64* ]] - codesign --verify --deep --strict --verbose=2 "$app" - codesign --display --verbose=2 "$app" - ls -l "$bundle"/dmg - - # The app must stand on its own too. Everything it links to has to be - # part of macOS: a system framework, or a library under /usr/lib. The - # page renderer is one of those frameworks, so there is nothing to ship - # with the app as there is on Windows. - - name: Check what the app asks the system for - shell: bash - run: | - bundle=src-tauri/target/universal-apple-darwin/release/bundle - app=$(ls -d "$bundle"/macos/*.app) - needed=$(otool -L "$app/Contents/MacOS/stackql-workbench" \ - | grep -E '^[[:space:]]' | awk '{print $1}' | sort -u) - echo "$needed" - foreign=$(echo "$needed" | grep -v -E '^(/System/Library/|/usr/lib/)' || true) - if [ -n "$foreign" ]; then - echo "Not part of macOS:" - echo "$foreign" - exit 1 - fi - # Nothing else is carried in the bundle that would have to be signed. - find "$app/Contents" -type f \( -name '*.dylib' -o -name '*.so' \) -print - - # The pages need a renderer of a certain age, and on a Mac the renderer - # is the one that macOS has. The bundle names the oldest macOS it runs - # on, so an older one refuses to open it. Both halves of the executable - # must be built for that version as well. - - name: Check the oldest macOS the app runs on - shell: bash - run: | - bundle=src-tauri/target/universal-apple-darwin/release/bundle - app=$(ls -d "$bundle"/macos/*.app) - want=$(node -p "require('./src-tauri/tauri.conf.json').bundle.macOS.minimumSystemVersion") - declared=$(/usr/libexec/PlistBuddy -c 'Print :LSMinimumSystemVersion' "$app/Contents/Info.plist") - echo "Wanted: $want" - echo "Declared in Info.plist: $declared" - [ "$declared" = "$want" ] - built=$(otool -l "$app/Contents/MacOS/stackql-workbench" \ - | awk '$1 == "minos" {print $2}' | sort -u) - echo "Built for: $built" - [ "$built" = "$want" ] - - - uses: actions/upload-artifact@v7 - with: - name: stackql-workbench-macos-universal - path: src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg - if-no-files-found: error - - # The app on its own, for the StackQL PKG, which installs it beside the - # stackql command and signs what it ships. It is packed with tar because - # a bundle holds links and permissions that a zip of loose files loses. - - name: Pack the app for the installer - shell: bash - run: | - bundle=src-tauri/target/universal-apple-darwin/release/bundle - app=$(ls -d "$bundle"/macos/*.app) - mkdir -p installer-input - tar -czf installer-input/stackql-workbench-macos-universal.app.tar.gz \ - -C "$(dirname "$app")" "$(basename "$app")" - cd installer-input - shasum -a 256 stackql-workbench-macos-universal.app.tar.gz \ - > stackql-workbench-macos-universal.app.tar.gz.sha256 - cat stackql-workbench-macos-universal.app.tar.gz.sha256 - tar -tzf stackql-workbench-macos-universal.app.tar.gz | head -n 12 - - - uses: actions/upload-artifact@v7 - with: - name: stackql-workbench-macos-universal-app - path: installer-input/* - if-no-files-found: error - - # The executable the StackQL MSI installs beside stackql.exe. It is the - # optimised build, with no installer of its own, and it is not signed here: - # the StackQL release signs what it ships. Like the Mac build it does not - # wait for the checks. - # - # The MSI comes for x64 and for arm64, so there is one build for each, made - # on a runner of that processor. Nothing is built across. - build-windows: - name: Build (Windows, ${{ matrix.arch }}) - runs-on: ${{ matrix.os }} - timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - include: - - arch: x64 - os: windows-latest - - arch: arm64 - os: windows-11-arm - - steps: - - uses: actions/checkout@v7 - - - uses: actions/setup-node@v7 - with: - node-version: 24 - cache: npm - - - uses: dtolnay/rust-toolchain@stable - - # Kept apart from the cache of the checks, which hold a debug build. - - uses: Swatinem/rust-cache@v2 - with: - workspaces: src-tauri - key: release - - - name: Install webview dependencies - run: npm ci - - - name: Build the executable - run: npm run tauri build -- --no-bundle - - # The executable must stand on its own in the installer's folder. It - # carries its C runtime inside it, so what it asks the system for is - # Windows itself. This reads its import tables and fails on a runtime. - # It also fails when the executable is not built for this processor. - - name: Check what the executable asks the system for - run: node scripts/check-exe-imports.js src-tauri/target/release/stackql-workbench.exe ${{ matrix.arch }} - - - name: Pack the executable for the installer - shell: pwsh - run: | - $exe = 'src-tauri/target/release/stackql-workbench.exe' - New-Item -ItemType Directory -Force installer-input | Out-Null - Copy-Item $exe installer-input/ - $hash = (Get-FileHash installer-input/stackql-workbench.exe -Algorithm SHA256).Hash.ToLower() - "$hash stackql-workbench.exe" | Set-Content installer-input/stackql-workbench.exe.sha256 - Get-Item installer-input/stackql-workbench.exe | Format-List Name, Length - Get-Content installer-input/stackql-workbench.exe.sha256 - - - uses: actions/upload-artifact@v7 - with: - name: stackql-workbench-windows-${{ matrix.arch }} - path: installer-input/* - if-no-files-found: error + # The binaries the StackQL installers take, built on every run by the + # workflow a release uses: the Windows executable for each processor, the + # Mac app, and the three of them under the names a release gives them. It + # does not wait for the checks, so a failing test still leaves a build. + build: + name: Build + uses: ./.github/workflows/build.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8a1a899 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,88 @@ +name: Release + +# Attaches the files the StackQL installers take to a release: the Windows +# executable for x64 and for arm64, and the Mac app, each with its SHA-256. +# +# It runs when a release is published from a tag. The files are built from +# the commit the tag names, by the workflow CI runs on every commit. It can +# also be started by hand for a release that already exists, to attach the +# files again after a run that did not finish. +# +# Nothing here is signed for release. The StackQL release signs what it +# ships. + +on: + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: The tag of a release that exists, to build and attach the files to + type: string + required: true + +permissions: + contents: read + +concurrency: + group: release-${{ github.event.release.tag_name || inputs.tag }} + cancel-in-progress: false + +jobs: + # The tag for version 1.2.3 is v1.2.3. A release under any other tag would + # hold an app that calls itself by another version. + version: + name: Check the tag + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + tag: ${{ steps.tag.outputs.tag }} + + steps: + - id: tag + env: + TAG: ${{ github.event.release.tag_name || inputs.tag }} + run: echo "tag=$TAG" >> "$GITHUB_OUTPUT" + + - uses: actions/checkout@v7 + with: + ref: ${{ steps.tag.outputs.tag }} + + - name: The tag is the version the app carries + env: + TAG: ${{ steps.tag.outputs.tag }} + run: node scripts/check-release-tag.js "$TAG" + + build: + name: Build + needs: version + uses: ./.github/workflows/build.yml + with: + ref: ${{ needs.version.outputs.tag }} + + # A file that is already on the release is not replaced: the upload fails + # and says so. To replace one, delete it from the release and start this + # workflow by hand with the tag. + attach: + name: Attach the files to the release + needs: [version, build] + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + + steps: + - uses: actions/download-artifact@v8 + with: + name: stackql-workbench-release-assets + path: release-assets + + - name: Attach + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ needs.version.outputs.tag }} + run: | + ls -l release-assets + gh release upload "$TAG" release-assets/* --repo "$GITHUB_REPOSITORY" + gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets \ + --jq '.assets[] | "\(.name) \(.size) bytes \(.digest)"' diff --git a/CLAUDE.md b/CLAUDE.md index dba5314..cf26d3b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -22,7 +22,9 @@ Not started: the rest of M1 (saved `.iql` files, cancel, a streaming grid), M2 ( CI has a job that builds a universal macOS disk image and keeps it as a workflow artifact, so the app can be tried on a Mac. The signature is ad hoc and nothing is notarised. It is a test build, not M2. -CI also keeps what the StackQL MSI and PKG are built from: the optimised Windows executable for each processor the MSI comes for, as `stackql-workbench-windows-x64` and `stackql-workbench-windows-arm64`, and the Mac app bundle, packed with tar, as `stackql-workbench-macos-universal-app`. Each comes with its SHA-256. Neither is signed for release. The maintainer said on 19 November 2026 that the StackQL release signs what it ships, so this repository holds no signing identity and signs nothing but the ad hoc signature a Mac needs to run the app at all. Workflow artifacts last 90 days and are not a release. There is no tagged release yet, which is how a shipped build should be pinned. +CI also keeps what the StackQL MSI and PKG are built from: the optimised Windows executable for each processor the MSI comes for, as `stackql-workbench-windows-x64` and `stackql-workbench-windows-arm64`, and the Mac app bundle, packed with tar, as `stackql-workbench-macos-universal-app`. Each comes with its SHA-256. Neither is signed for release. The maintainer said on 19 November 2026 that the StackQL release signs what it ships, so this repository holds no signing identity and signs nothing but the ad hoc signature a Mac needs to run the app at all. Workflow artifacts last 90 days and are not a release. + +A build that ships comes from a release of this repository. The maintainer decided that on 20 November 2026. Publishing a release from the tag `v` runs the Release workflow, which builds the three files from the commit the tag names and attaches them: `stackql-workbench_windows_amd64.exe`, `stackql-workbench_windows_arm64.exe` and `stackql-workbench_darwin_multiarch.app.tar.gz`, each with a `.sha256` beside it. The build scripts of the two installers fetch the files of the newest release. `.github/workflows/build.yml` builds, checks and names the files, and both CI and the Release workflow call it, so what a release attaches has been put together on every run before it. `scripts/check-release-tag.js` stops a release whose tag is not the version the app carries. No release has been made yet, so the step that attaches the files has not run. What has and has not been run: @@ -43,6 +45,7 @@ What has and has not been run: - The page renderer was checked on Windows 11 with a build of the app in a folder of its own. With nothing beside it, the renderer process ran from the system's WebView2. With a copy of that runtime in a `WebView2Runtime` folder beside it, the renderer process ran from that folder and the app came up with its engine. With a `WebView2Runtime` folder that held no runtime, the system's was used. The copy was of the runtime Windows had installed, version 157, not of Microsoft's Fixed Version package, which has the same layout and was not downloaded. - No machine without a WebView2 runtime was tried, and no freshly installed Windows 11. A machine without one was imitated on Windows 11 by pointing the loader's variable at an empty folder. The optimised build from CI showed the app's own dialog, the heading and the one sentence each on one line, and no terminal: the process had no console host, where a debug build has one. It exited with code 1 when the dialog was closed. A click on the link, sent to the dialog of a debug build, brought Microsoft's page up in the browser and left the dialog open. Nothing is written to the app's log, which starts after the window is made. Before the check was added, the optimised build showed Tauri's own dialog and then ended in a panic. - The data folder of an installed app was checked on Windows with the app and a copy of `stackql.exe` in a folder the account could read and run from but not write to, which is what `Program Files` is to an ordinary account. The app was started with that folder as its working folder. It started the engine beside it, the engine's data folder was `/engine`, and nothing was added to the folder of the app. The real `Program Files` was not used, since that needs an administrator, and the note in the settings pane was not looked at in that run. +- That run was before an installed app used the home folder. After the change the same layout was run again: the engine beside the app was started on `.stackql` in the home folder, the app listed the providers the operator's own `stackql` command had pulled there, and nothing was added to the folder of the app. The app alone in a folder it could write to, which is what a build is, kept a `.stackql` folder beside itself and listed no providers. The fallback to the local app data directory has run only in tests, and the macOS rule only as unit tests. - The token counts were seen in the built app with a scripted model, and for real through the Copilot CLI: one prompt to a probe to see what the CLI sends, and one turn through the app, which showed the count on the steps line and in the log. The counts of Gemini, Anthropic and an OpenAI-compatible server are read as their documentation describes and tested against stubs, not against the real services. - The supervisor's tests see a child end by waiting on a handle to it on Windows, and with `kill -0` on Unix. They used to ask `tasklist`, which on a busy machine could use up the time a test allowed. They passed 30 runs in a row with every core busy. With twice as many busy loops as cores a different test, `an_unexpected_exit_is_reported_with_its_code`, missed its 10 second limit twice in 30 runs. @@ -134,7 +137,7 @@ stackql-workbench/ .cargo/ build flags: the C runtime linked in on Windows examples/ pgwire_spike and mcp_spike, the probes behind the spike reports tests/ integration tests against a real stackql - scripts/ test launcher, the check of what a Windows executable asks the system for + scripts/ test launcher, the check of what a Windows executable asks the system for, the check of a release tag against the app's version docs/ design notes and spike reports ``` @@ -174,7 +177,7 @@ Things to know about them: - `npm test` goes through `scripts/test.js`. Vitest fails on Windows when the working directory is spelled with a lower-case drive letter, which an editor terminal can do. The launcher corrects that. - `cargo test` includes integration tests that start a real `stackql`. They are skipped, with a note on stderr, when no binary is found. They need no credentials and no network. - The release executable is `src-tauri/target/release/stackql-workbench.exe` on Windows. -- The engine's `--approot` is `.stackql` beside the Workbench executable. For a build from this repository that is `src-tauri/target/release/.stackql`, or `target/debug/.stackql` under `npm run tauri dev`. Where that folder cannot be written to, the fallback is `/engine`, which on Windows is `%APPDATA%\io.stackql.workbench\engine`. The operator can name another folder in Settings. +- The engine's `--approot` depends on how the app got there. An installed app uses `.stackql` in the home folder, the one the `stackql` command uses. A build from this repository uses `.stackql` beside its executable: `src-tauri/target/release/.stackql`, or `target/debug/.stackql` under `npm run tauri dev`. Where the folder cannot be written to, the fallback is `/engine`, which on Windows is `%LOCALAPPDATA%\io.stackql.workbench\engine`. The operator can name another folder in Settings. - Settings are in `/settings.json`. The agent audit log is in `/audit` and the operator's statement history in `/history.jsonl`. Those two do not move with the engine's data folder. - The app's own log is in `/logs`, one file for each run, named `stackql_workbench_.log`. The host writes it and nothing reads it back. It is apart from the engine's audit log, which the engine writes. The 20 newest files are kept. - The binaries are built to need nothing from the system that has to be installed. The maintainer asked for that on 19 November 2026. @@ -238,9 +241,13 @@ Flags the host passes: - `--pgsrv.port` with a free port chosen by the host. The default is 5466 and may be taken. - `--approot` with the engine's data folder, always. The engine's own default is `.stackql` in the working directory, so the provider cache would otherwise follow wherever the app was started from. The host resolves the folder in this order and stops at the first hit. 1. Explicit folder in settings. This source is strict: a folder that is not a full path, or cannot be created or written to, is an error and the engine does not start. - 2. `.stackql` beside the Workbench executable. Skipped inside a macOS app bundle, because adding a file to a signed bundle breaks its signature. - 3. `/engine`. Used when the folder beside the executable cannot be written to, which is the normal case for an app installed under `Program Files`. The settings pane says so. -- The Workbench does not share the operator's own `.stackql` folder unless they point it there. + 2. For an installed app, `.stackql` in the home folder. For a build that was not installed, `.stackql` beside the Workbench executable. + 3. `/engine`. Used when the second cannot be written to. The settings pane says so. +- An installed app shares the home folder's `.stackql` with the `stackql` command. The maintainer decided that on 20 November 2026. The installers put the command and the app down together, the command shell the MSI installs starts the command in the home folder, and a provider pulled in one should be there in the other. +- An app counts as installed when the engine sits beside its executable, which is how the MSI lays them out, or when it runs from a macOS bundle. It is the reading discovery makes of "the engine installed with the app". +- An installed app writes nothing to the folder it was installed in. The MSI installs for the whole machine under `Program Files`, where an ordinary account cannot write, and a macOS bundle is signed. Its state is kept for each user. +- A build from this repository does not share the operator's `.stackql` folder unless they point it there. It keeps its own beside the executable, so development and tests stay apart from the operator's providers. +- The fallback is in the local app data directory because it is a cache that can be pulled again. It used to be in the app data directory, which on Windows follows a user from machine to machine, and a cache of two providers measured 95 MB. - `--pgsrv.debug.enable`. Without it an upstream API failure is an empty, successful result with the reason only on stderr. With it the reason arrives as a pg notice on the connection that ran the statement. - `--env.file` when the operator has set a credentials file. @@ -453,9 +460,6 @@ This applies to docs, comments, commit messages and UI copy. Raise these with the maintainer when the work reaches them. Do not decide them alone. - How Workbench versions are pinned to engine releases, and the minimum engine version check at startup. -- How a build that ships is released from this repository: a tag and a release whose files the StackQL release fetches, in place of workflow artifacts that expire. -- Where an installed app keeps the engine's provider cache. The MSI installs for the whole machine under `Program Files`, which an ordinary account cannot write to, so the cache goes to `/engine`. On Windows that is in the roaming profile, and a cache of two providers measured 95 MB. The local app data directory is the usual place for a cache. -- Whether an installed app shares the provider cache of the `stackql` command shell the MSI installs, which is `.stackql` in the home folder. Today each has its own, so a provider installed in one is not seen in the other. - Whether `srv` should later co-host the MCP server so the IDE and the agent share one engine session. - Whether loopback pg wire needs TLS with a per-launch client certificate. diff --git a/README.md b/README.md index fb1a0bf..d783516 100644 --- a/README.md +++ b/README.md @@ -214,17 +214,29 @@ The same build on a Mac is `npm run tauri build -- --target universal-apple-darw ### What the installers take -CI also keeps what the StackQL MSI and PKG are built from, on every run, as three more workflow artifacts. Each holds one file and its SHA-256. +The StackQL MSI and PKG are built from three files. A release of this repository carries them as assets, each with its SHA-256 beside it as `.sha256`. -| Artifact | Holds | For | +| Release asset | Holds | For | |---|---|---| -| `stackql-workbench-windows-x64` | `stackql-workbench.exe`, the optimised build for x64 | The x64 MSI, which installs it beside `stackql.exe` | -| `stackql-workbench-windows-arm64` | `stackql-workbench.exe`, the optimised build for Arm | The arm64 MSI, which does the same | -| `stackql-workbench-macos-universal-app` | `stackql-workbench-macos-universal.app.tar.gz`, the app bundle for Apple Silicon and Intel | The PKG, which installs it to `/Applications` | +| `stackql-workbench_windows_amd64.exe` | The optimised build for x64 | The x64 MSI, which installs it beside `stackql.exe` as `stackql-workbench.exe` | +| `stackql-workbench_windows_arm64.exe` | The optimised build for Arm | The arm64 MSI, which does the same | +| `stackql-workbench_darwin_multiarch.app.tar.gz` | The app bundle for Apple Silicon and Intel | The PKG, which installs it to `/Applications` | + +The names follow the StackQL release: `amd64` and `arm64` for Windows, `multiarch` for the Mac. The files of the newest release are at `https://github.com/stackql/stackql-workbench/releases/latest/download/`. The build scripts of the two installers fetch them from there and check each against its SHA-256. + +To make a release: + +- Set the version in `src-tauri/tauri.conf.json`, `src-tauri/Cargo.toml` and `package.json`, and merge that. +- Publish a release from the tag `v`, for example `v0.1.0`. +- The Release workflow builds the three files from the commit the tag names and attaches them. It stops at once when the tag is not the version the app carries. + +A file that is already on a release is not replaced. To replace one, delete it from the release and start the Release workflow by hand with the tag. + +CI builds the same three files on every run, with the workflow a release uses, and keeps them as workflow artifacts. `stackql-workbench-release-assets` holds the three under their release names. `stackql-workbench-windows-x64`, `stackql-workbench-windows-arm64` and `stackql-workbench-macos-universal-app` hold each as it was built. They are on the summary page of a run that has finished, they last 90 days, and they are for trying a build, not for shipping one. Neither is signed for release. The Windows executable has no signature and the Mac app has an ad hoc one, so the StackQL release signs both, and notarises the Mac app, before it ships them. Unpack the Mac app with `tar -xzf`, which keeps the links and permissions inside the bundle. -The StackQL MSI is built for x64 and for arm64, so there is a Windows executable for each. The two files have the same name, and the artifact says which is which. Each is built on a runner of that processor, and CI checks which processor the executable names. The maintainer asked for the arm64 build on 20 November 2026, in place of shipping the x64 executable to run under emulation: Windows emulates x64 only from Windows 11, it could not be tried here, and the arm64 MSI ships an engine built for Arm. +The StackQL MSI is built for x64 and for arm64, so there is a Windows executable for each. Each is built on a runner of that processor, and CI checks which processor the executable names. The maintainer asked for the arm64 build on 20 November 2026, in place of shipping the x64 executable to run under emulation: Windows emulates x64 only from Windows 11, it could not be tried here, and the arm64 MSI ships an engine built for Arm. Both are built to stand on their own, and CI checks that they do. @@ -242,12 +254,9 @@ Shipping the runtime was ruled out the same day: the binaries stay small and run - Install the unpacked folder beside `stackql-workbench.exe`, renamed to `WebView2Runtime`. When that folder is there the app uses it and does not look at what the system has. When it is not, the app uses the system's runtime. Nothing else is configured, so the same executable serves both. The folder is large: the runtime installed on the machine this was measured on is 878 MB in 918 files. It is also a browser engine at one fixed version, so a security update to it means a new installer, where the system's runtime is kept up to date by Windows. The app only ever loads its own pages from inside the executable, which limits what an out-of-date renderer is exposed to. macOS has nothing of the kind to ship, because its renderer is part of the system. That renderer is as old as the macOS it is on, so the app needs macOS 13 or later. The maintainer decided that on 20 November 2026. The bundle declares it as its minimum, and an older macOS refuses to open the app. The reason is the styling library the pages use, which needs the WebKit of Safari 16.4, from March 2023. Safari 16.4 came to macOS 13 in an update, so a Mac that is still on the first releases of macOS 13 opens the app with a renderer older than that. - -To fetch them from the latest run on `main`: `gh run download --repo stackql/stackql-workbench --branch main --name stackql-workbench-windows-x64`, and the same with the other names. GitHub keeps a workflow artifact for 90 days. A build to be shipped should come from a tagged release, which this repository does not make yet. - ### Using the app -The engine keeps its provider cache in a folder of the app's own: `.stackql` beside the executable, or the app data directory when that place cannot be written to, as under `Program Files`. A first run therefore lists no providers. Run `REGISTRY PULL github;` in the editor to install one. To use another folder, for example the `.stackql` folder you already use with the `stackql` CLI, set it under Settings. +An installed app keeps the engine's provider cache in `.stackql` in your home folder. That is where the `stackql` command keeps it when it is started there, as the command shell the MSI installs does, so providers you pulled with the command are there in the app, and the other way round. A build from this repository keeps a `.stackql` folder beside its executable instead, so a first run of one lists no providers. Run `REGISTRY PULL github;` in the editor to install one. To use another folder, set it under Settings. Provider credentials are environment variables the engine reads. On Windows the engine sees the variables of your user account. To use a dotenv file, set it under Settings. @@ -320,7 +329,7 @@ StackQL Workbench has no installer of its own. It ships inside the StackQL insta - Windows: the StackQL MSI installs `stackql-workbench.exe` next to `stackql.exe` and adds a Start Menu entry. The executable needs no runtime installed. The page is drawn by the Microsoft WebView2 runtime that Windows has, which is part of Windows 11 and already on most Windows 10 machines. The MSI neither ships it nor installs it. Where it is missing the app says so when it starts, with a link to Microsoft's page. See "What the installers take". - The app uses the `stackql` it was installed with: on Windows the one that sits beside it, and on macOS the command the PKG puts in `/usr/local/bin`, or an engine inside the app bundle if the PKG ever puts one there. That is the pair that was built and tested together, so nothing on the machine replaces it except a path the operator sets under Settings after the install. A `STACKQL_BIN` variable does not, and when one is set the status bar says it is not used. Neither installer has anything to configure for this. -- Under `Program Files` the folder beside the app cannot be written to, so the engine keeps its provider cache in the app data directory. A first run lists no providers. +- The app writes nothing to the folder it is installed in, which under `Program Files` an ordinary account cannot write to. Its state is kept for each user: settings, history and logs under the user's app data, and the engine's provider cache in `.stackql` in the home folder, shared with the `stackql` command. The installers have nothing to create for it. - macOS: the StackQL PKG installs `StackQL Workbench.app` to `/Applications` alongside the `stackql` CLI. - Bundle identifier: `io.stackql.workbench`. - This repository builds the per-platform artefacts. The StackQL release workflow consumes a pinned Workbench version. diff --git a/scripts/check-release-tag.js b/scripts/check-release-tag.js new file mode 100644 index 0000000..15325c9 --- /dev/null +++ b/scripts/check-release-tag.js @@ -0,0 +1,95 @@ +// Checks that a release tag is the version the app carries. +// +// node scripts/check-release-tag.js +// +// A release is made from a tag, and its files are built from the commit the +// tag names. The app's own version is in src-tauri/tauri.conf.json, with a +// copy in src-tauri/Cargo.toml and one in package.json. The tag for version +// 1.2.3 is v1.2.3. This fails when the tag is anything else, or when the +// three files disagree, so a release never holds an app that calls itself by +// another version. + +import fs from 'node:fs'; +import process from 'node:process'; + +/** + * The tag a version is released under. + * + * @param {string} version + * @returns {string} + */ +export function tagFor(version) { + return `v${version}`; +} + +/** + * The version in a Cargo.toml: the first `version = "..."` line, which is + * the one of the package. + * + * @param {string} toml + * @returns {string | null} + */ +export function cargoVersion(toml) { + const match = /^version\s*=\s*"([^"]+)"/m.exec(toml); + return match ? match[1] : null; +} + +/** + * What is wrong with a tag, given the versions the three files hold. An + * empty list means nothing is. + * + * @param {string} tag + * @param {{ tauri: string | null, cargo: string | null, npm: string | null }} versions + * @returns {string[]} + */ +export function problems(tag, versions) { + /** @type {string[]} */ + const found = []; + if (!versions.tauri) { + return ['src-tauri/tauri.conf.json holds no version.']; + } + if (versions.cargo !== versions.tauri) { + found.push( + `src-tauri/Cargo.toml says ${versions.cargo ?? 'nothing'} and src-tauri/tauri.conf.json says ${versions.tauri}.`, + ); + } + if (versions.npm !== versions.tauri) { + found.push( + `package.json says ${versions.npm ?? 'nothing'} and src-tauri/tauri.conf.json says ${versions.tauri}.`, + ); + } + if (tag !== tagFor(versions.tauri)) { + found.push( + `The tag is ${tag} and the app is version ${versions.tauri}. Release it as ${tagFor(versions.tauri)}, or set the version first.`, + ); + } + return found; +} + +/** + * @param {string} path + * @returns {string | null} + */ +function jsonVersion(path) { + /** @type {unknown} */ + const parsed = JSON.parse(fs.readFileSync(path, 'utf8')); + if (typeof parsed === 'object' && parsed !== null && 'version' in parsed) { + return typeof parsed.version === 'string' ? parsed.version : null; + } + return null; +} + +const tag = process.argv[2]; +if (tag) { + const versions = { + tauri: jsonVersion('src-tauri/tauri.conf.json'), + cargo: cargoVersion(fs.readFileSync('src-tauri/Cargo.toml', 'utf8')), + npm: jsonVersion('package.json'), + }; + const found = problems(tag, versions); + if (found.length > 0) { + process.stderr.write(`${found.join('\n')}\n`); + process.exit(1); + } + process.stdout.write(`${tag} is the version the app carries, ${versions.tauri ?? ''}.\n`); +} diff --git a/src-tauri/src/engine/approot.rs b/src-tauri/src/engine/approot.rs index 7f23d89..c892817 100644 --- a/src-tauri/src/engine/approot.rs +++ b/src-tauri/src/engine/approot.rs @@ -7,13 +7,29 @@ //! Resolution order, first hit wins: //! //! 1. Explicit folder in settings -//! 2. `.stackql` beside the Workbench executable -//! 3. A folder under the app data directory +//! 2. For an installed app, `.stackql` in the home folder. For a build that +//! was not installed, `.stackql` beside the Workbench executable +//! 3. A folder under the local app data directory //! //! The explicit source is strict. If the operator named a folder and it //! cannot be used, that is an error and the search stops there. The second -//! falls through to the third with a note, because an installed app usually -//! sits where an ordinary account cannot write. +//! falls through to the third with a note. +//! +//! An installed app sits where an ordinary account cannot write: the MSI +//! installs for the whole machine under `Program Files`, and on macOS the +//! app is a signed bundle. So its state is kept for each user, and nothing +//! is written to the folder it was installed in. The folder chosen is the +//! one the `stackql` command uses when it is started from the home folder, +//! which is what the command shell the MSI installs does. The installers +//! put the command and the app down together, so a provider pulled in one +//! is there in the other. +//! +//! A build from this repository keeps its own folder beside the executable, +//! apart from the operator's. +//! +//! The last one is a cache that can be pulled again, so it is kept in the +//! local app data directory and not in the one that follows a user from +//! machine to machine. use std::path::{Path, PathBuf}; @@ -25,6 +41,7 @@ pub const FOLDER_NAME: &str = ".stackql"; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Source { Settings, + Home, BesideApp, AppData, } @@ -34,6 +51,7 @@ impl Source { pub fn label(self) -> &'static str { match self { Self::Settings => "settings", + Self::Home => "home folder, shared with the stackql command", Self::BesideApp => "beside the app", Self::AppData => "app data folder", } @@ -43,32 +61,60 @@ impl Source { /// The folders tried when settings name none. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Defaults { - /// `.stackql` beside the executable. `None` when there is no such place - /// or it must not be written to. - pub beside_app: Option, - /// A folder under the app data directory, which an ordinary account can - /// always write to. + /// The folder tried first, and what it is. `None` when there is no such + /// place. + pub first: Option<(PathBuf, Source)>, + /// A folder under the local app data directory, which an ordinary + /// account can always write to. pub fallback: PathBuf, } impl Defaults { /// The defaults for an app whose executable is `exe`. - pub fn for_executable(exe: Option<&Path>, fallback: PathBuf) -> Self { - Self { - beside_app: exe.and_then(beside_executable), - fallback, - } + /// + /// `home` is the home folder of the account, when there is one. + /// `is_file` is injected so tests can describe a file system. + pub fn for_executable( + exe: Option<&Path>, + home: Option<&Path>, + fallback: PathBuf, + is_file: impl Fn(&Path) -> bool, + ) -> Self { + let first = exe.and_then(|exe| { + if installed(exe, &is_file) { + home.map(|home| (home.join(FOLDER_NAME), Source::Home)) + } else { + beside_executable(exe).map(|dir| (dir, Source::BesideApp)) + } + }); + Self { first, fallback } } /// One fixed folder and nothing else. Tests use this. pub fn fixed(dir: PathBuf) -> Self { Self { - beside_app: None, + first: None, fallback: dir, } } } +/// Whether the app at `exe` was put down by an installer. +/// +/// The installers ship the engine with the app, and that is how an installed +/// app is told from a build. On Windows the MSI puts `stackql.exe` in the +/// folder of the Workbench executable. On macOS an installed app is a +/// bundle. This is the same reading discovery makes of "the engine installed +/// with the app". +pub fn installed(exe: &Path, is_file: impl Fn(&Path) -> bool) -> bool { + if super::in_app_bundle(exe) { + return true; + } + exe.parent() + .filter(|dir| !dir.as_os_str().is_empty()) + .is_some_and(|dir| is_file(&dir.join(super::discovery::BINARY_NAME))) +} + /// The data folder beside an executable, if there may be one. /// /// There is none inside a macOS app bundle. Adding a file to a signed bundle @@ -146,18 +192,22 @@ pub fn resolve( } let mut note = None; - if let Some(path) = &defaults.beside_app { + if let Some((path, source)) = &defaults.first { match prepare(path) { Ok(()) => { return Ok(Resolved { path: path.clone(), - source: Source::BesideApp, + source: *source, note: None, }); } Err(err) => { + let what = match source { + Source::Home => "The folder in the home folder", + _ => "The folder beside the app", + }; note = Some(format!( - "The folder beside the app, {}, cannot be written to ({err}), so the app data folder is used.", + "{what}, {}, cannot be written to ({err}), so the app data folder is used.", path.display() )); } @@ -192,13 +242,27 @@ mod tests { } } + /// The defaults of a build that was not installed. fn defaults() -> Defaults { Defaults { - beside_app: Some(abs("/apps/workbench/.stackql")), + first: Some((abs("/apps/workbench/.stackql"), Source::BesideApp)), + fallback: abs("/data/engine"), + } + } + + /// The defaults of an installed app. + fn installed_defaults() -> Defaults { + Defaults { + first: Some((abs("/home/me/.stackql"), Source::Home)), fallback: abs("/data/engine"), } } + /// No file exists. + fn nothing(_: &Path) -> bool { + false + } + fn denied() -> io::Error { io::Error::new(io::ErrorKind::PermissionDenied, "access is denied") } @@ -307,31 +371,104 @@ mod tests { } #[test] - fn the_default_sits_beside_the_executable() { + fn a_build_keeps_its_folder_beside_the_executable() { + // No engine beside it: this is a build from the repository, and its + // folder stays apart from the operator's own. let exe = abs("/apps/workbench/stackql-workbench.exe"); assert_eq!( beside_executable(&exe), Some(abs("/apps/workbench/.stackql")) ); - let made = Defaults::for_executable(Some(&exe), abs("/data/engine")); + assert!(!installed(&exe, nothing)); + let home = abs("/home/me"); + let made = Defaults::for_executable(Some(&exe), Some(&home), abs("/data/engine"), nothing); assert_eq!(made, defaults()); } #[test] - fn nothing_is_written_inside_a_macos_app_bundle() { + fn an_app_installed_beside_the_engine_uses_the_home_folder() { + // The MSI puts the two executables in one folder, under Program + // Files, where an ordinary account cannot write. + let exe = abs("/Program Files/StackQL/stackql-workbench.exe"); + let engine = abs("/Program Files/StackQL").join(crate::engine::discovery::BINARY_NAME); + let beside = |path: &Path| path == engine; + assert!(installed(&exe, beside)); + let home = abs("/home/me"); + let made = Defaults::for_executable(Some(&exe), Some(&home), abs("/data/engine"), beside); + assert_eq!(made, installed_defaults()); + } + + #[test] + fn an_engine_somewhere_else_does_not_make_a_build_installed() { + let exe = abs("/apps/workbench/stackql-workbench.exe"); + let elsewhere = abs("/Program Files/StackQL").join(crate::engine::discovery::BINARY_NAME); + assert!(!installed(&exe, |path| path == elsewhere)); + } + + #[test] + fn an_app_in_a_macos_bundle_uses_the_home_folder() { + // Nothing is written inside the bundle. Adding a file to a signed + // bundle breaks its signature. let exe = Path::new("/Applications/StackQL Workbench.app/Contents/MacOS/stackql-workbench"); assert_eq!(beside_executable(exe), None); - let made = Defaults::for_executable(Some(exe), abs("/data/engine")); + assert!(installed(exe, nothing)); + let home = abs("/home/me"); + let made = Defaults::for_executable(Some(exe), Some(&home), abs("/data/engine"), nothing); + assert_eq!(made, installed_defaults()); + } + + #[test] + fn an_installed_app_with_no_home_folder_gives_only_the_fallback() { + let exe = Path::new("/Applications/StackQL Workbench.app/Contents/MacOS/stackql-workbench"); + let made = Defaults::for_executable(Some(exe), None, abs("/data/engine"), nothing); assert_eq!(made, Defaults::fixed(abs("/data/engine"))); } #[test] fn an_unknown_executable_gives_only_the_fallback() { assert_eq!(beside_executable(Path::new("stackql-workbench")), None); - let made = Defaults::for_executable(None, abs("/data/engine")); + let home = abs("/home/me"); + let made = Defaults::for_executable(None, Some(&home), abs("/data/engine"), nothing); assert_eq!(made, Defaults::fixed(abs("/data/engine"))); } + #[test] + fn the_home_folder_is_the_default_of_an_installed_app() { + let ok = [abs("/home/me/.stackql"), abs("/data/engine")]; + let tried = RefCell::new(Vec::new()); + let found = resolve(None, &installed_defaults(), writable(&ok, &tried)).unwrap(); + assert_eq!(found.path, abs("/home/me/.stackql")); + assert_eq!(found.source, Source::Home); + assert_eq!(found.note, None); + assert_eq!(tried.borrow().len(), 1, "the fallback is not created"); + } + + #[test] + fn a_home_folder_that_cannot_be_used_falls_back_with_a_note() { + let ok = [abs("/data/engine")]; + let tried = RefCell::new(Vec::new()); + let found = resolve(None, &installed_defaults(), writable(&ok, &tried)).unwrap(); + assert_eq!(found.path, abs("/data/engine")); + assert_eq!(found.source, Source::AppData); + let note = found.note.unwrap(); + assert!(note.contains("home folder"), "says which folder: {note}"); + assert!(note.contains(".stackql"), "names the folder: {note}"); + assert!( + note.contains("access is denied"), + "gives the reason: {note}" + ); + } + + #[test] + fn a_folder_in_settings_comes_before_the_home_folder() { + let chosen = abs("/my/approot"); + let ok = [chosen.clone(), abs("/home/me/.stackql")]; + let tried = RefCell::new(Vec::new()); + let found = resolve(Some(&chosen), &installed_defaults(), writable(&ok, &tried)).unwrap(); + assert_eq!(found.source, Source::Settings); + assert_eq!(*tried.borrow(), vec![chosen]); + } + #[test] fn prepare_creates_the_folder_and_leaves_nothing_in_it() { let root = std::env::temp_dir().join(format!("wb-approot-test-{}", std::process::id())); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 93722af..05b46ce 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -43,13 +43,19 @@ fn setup( let cache_dir = app.path().app_cache_dir()?; let settings = Arc::new(SettingsStore::load(config_dir.join("settings.json"))); - // The engine's provider cache goes in a folder beside this executable, - // or under the app data directory when that place cannot be written to. - // The operator can name another folder in settings. The engine's own - // default would be whatever directory the app was started from. + // The engine's provider cache. An installed app sits where an ordinary + // account cannot write, so it uses `.stackql` in the home folder, the + // one the stackql command uses. A build from this repository keeps a + // folder beside its executable. The last resort is a folder under the + // local app data directory: it is a cache, so it does not belong in the + // directory that follows a user between machines. The operator can name + // another folder in settings. The engine's own default would be + // whatever directory the app was started from. let approot_defaults = ApprootDefaults::for_executable( std::env::current_exe().ok().as_deref(), - data_dir.join("engine"), + app.path().home_dir().ok().as_deref(), + app.path().app_local_data_dir()?.join("engine"), + |path| path.is_file(), ); let connection: Arc = Arc::new(LocalConnection::new( approot_defaults, @@ -135,6 +141,7 @@ fn log_engine_state(log: &AppLog, status: &EngineStatus) { "version": status.version, "endpoint": status.endpoint, "dataFolder": status.data_folder, + "dataFolderFrom": status.data_folder_source, }), ), EngineState::Failed => log.error( diff --git a/src-tauri/tests/engine_integration.rs b/src-tauri/tests/engine_integration.rs index e53d77b..29dabc3 100644 --- a/src-tauri/tests/engine_integration.rs +++ b/src-tauri/tests/engine_integration.rs @@ -331,6 +331,44 @@ async fn a_wrong_engine_path_is_reported_in_the_status() { assert!(error.contains("Settings"), "points at settings: {error}"); } +#[tokio::test] +async fn an_installed_app_runs_its_engine_on_the_home_folder() { + if !engine_available() { + return; + } + // A folder that stands in for the home folder of the account. The real + // one is the operator's and is not touched by a test. + let root = scratch_approot("homefolder"); + let home = root.join("home").join(".stackql"); + let fallback = root.join("local").join("engine"); + + let settings = Arc::new(SettingsStore::in_memory(Settings::default())); + let connection = LocalConnection::new( + ApprootDefaults { + first: Some(( + home.clone(), + stackql_workbench_lib::engine::approot::Source::Home, + )), + fallback: fallback.clone(), + }, + root.join("audit"), + settings, + ) + .unwrap(); + let status = connection.start().await; + assert_eq!(status.state, EngineState::Running, "{:?}", status.error); + assert_eq!(status.data_folder.as_deref(), Some(home.to_str().unwrap())); + assert_eq!( + status.data_folder_source.as_deref(), + Some("home folder, shared with the stackql command") + ); + assert_eq!(status.data_folder_note, None); + assert!(home.is_dir(), "the engine's folder exists"); + assert!(!fallback.exists(), "the fallback is left alone"); + + finish(connection, root).await; +} + #[tokio::test] async fn the_data_folder_defaults_to_beside_the_app_and_settings_override_it() { if !engine_available() { @@ -345,7 +383,10 @@ async fn the_data_folder_defaults_to_beside_the_app_and_settings_override_it() { let settings = Arc::new(SettingsStore::in_memory(Settings::default())); let connection = LocalConnection::new( ApprootDefaults { - beside_app: Some(beside.clone()), + first: Some(( + beside.clone(), + stackql_workbench_lib::engine::approot::Source::BesideApp, + )), fallback: fallback.clone(), }, root.join("audit"), diff --git a/src/panes/settings/SettingsDialog.tsx b/src/panes/settings/SettingsDialog.tsx index 9594aaa..deede50 100644 --- a/src/panes/settings/SettingsDialog.tsx +++ b/src/panes/settings/SettingsDialog.tsx @@ -166,9 +166,10 @@ export function SettingsDialog({ status, onClose, section, children }: SettingsD Engine data folder

- Optional. Where the engine keeps the providers it has pulled. Leave empty to use a - .stackql folder beside this app, or the app data folder when that place cannot be - written to. Providers pulled into one folder are not seen from another. + Optional. Where the engine keeps the providers it has pulled. Leave empty to use the + .stackql folder in your home folder, which the stackql command uses too. A build that + was not installed uses a .stackql folder beside itself. Providers pulled into one folder + are not seen from another.