Skip to content
Open
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
20 changes: 20 additions & 0 deletions .claude/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,26 @@ the **user-facing outcome** at the UI layer. Don't force a flaky UI assertion.
(integration, sharded 4x, `MIRALL_TEST_TIMEOUT_SCALE=3`, one process per file with a single retry
of a failed file), and **flake-ledger**, which grades each suite's pass-on-retry count against its
own `test/<suite>-flake-budget.json`. Green CI is required to merge.
- **CI on macOS and Windows (nightly and manual, not a gate):**
`.github/workflows/test-platforms.yml` runs `test:node:core`, the flow shards (socket and headless
slices included) and the bare shards on `macos-15` and `windows-latest`. It has no push or
pull-request trigger, so a red there blocks no merge and no release; a job becomes a gate by
moving to those triggers once it is green on its system. Typecheck, lint and knip stay Linux-only,
and these jobs are outside the flake ledger: its budgets are measured on the Linux runners. The
flow shard loop is `scripts/ci/run-flow-shard.sh`. The checkout is LF on every system
(`.gitattributes`), which the invariant tests and the shell scripts rely on.
- **A test runs on Windows too.** Four rules keep it portable:
- A relative path that is compared, matched or printed is spelled with `/`:
`path.relative(...).split(path.sep).join('/')`.
- A file URL becomes a path with `fileURLToPath`, or is passed on as the URL. `new URL(...).pathname`
gives `/C:/…`, which resolves to a wrong path.
- A shell script is started through `test/helpers/bash.js`, never a bare `bash`: it is not on
the path on Windows, or is the WSL launcher. A path handed to the script uses `/`.
- The temp folder is inside the home folder on Windows. A test that tells "under home" from
"outside home" sets the home folder itself.

A property that exists only on POSIX (mode bits, uid, a read-only folder) is skipped on Windows
with its reason, and the part that holds everywhere is kept in a test of its own.
- **Local (you run it — not optional):** `npm run test:fe` is **required** for any UI-affecting
change and runs fine on a dev machine (only CI can't drive the AX tree). The agent runs the
scenarios covering the change itself, in background mode, without asking — for bug fixes, new
Expand Down
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Text is LF in the index and in every checkout, on every system: the invariant tests read source
# files by line, and the shell scripts the tests and CI run do not survive a CRLF checkout.
* text=auto eol=lf

# Byte-pinned by test/invariants/backup-fixtures-frozen.test.js: never converted on checkout.
test/fixtures/backup/** -text
111 changes: 111 additions & 0 deletions .github/workflows/test-platforms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Test (macOS, Windows)

# The suites test.yml runs on Linux, on the two other systems the app ships for. These jobs gate
# nothing: they run nightly and by hand, never on a push or a pull request, so a red here blocks no
# merge and no release. A job becomes a gate only by moving to push and pull_request triggers, and
# only once it is green on its system. Typecheck, lint and the dead-code report read the source and
# give the same answer everywhere, so they stay in test.yml.
#
# Outside the flake ledger: the budgets in test/*-flake-budget.json are measured on the Linux
# runners, and a retry here would spend them without saying anything about that suite. The reports
# are uploaded all the same, in the ledger's shape, so a budget per system can be set from them.
on:
workflow_dispatch:
schedule:
- cron: '17 2 * * *'

permissions:
contents: read

# Bash everywhere: on Windows the default is PowerShell, which reads none of the steps below.
defaults:
run:
shell: bash

jobs:
# Unit, invariant and raw-mechanics tests under Node.
node:
name: node (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
os: [macos-15, windows-latest]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup
- name: Tests (unit + raw)
run: npm run test:node:core

# The two-peer flow shards, partitioned and retried exactly as in test.yml. Shards 7 and 8 re-run
# slice 1 over the worker socket and against headless workers, one transport each, per system.
flow:
name: flow (${{ matrix.os }}, ${{ matrix.shard }}, ${{ matrix.transport }})
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
os: [macos-15, windows-latest]
shard: [1, 2, 3, 4, 5, 6]
transport: [pipe]
include:
- { os: macos-15, shard: 7, slice: 1, transport: socket }
- { os: macos-15, shard: 8, slice: 1, transport: headless }
- { os: windows-latest, shard: 7, slice: 1, transport: socket }
- { os: windows-latest, shard: 8, slice: 1, transport: headless }
env:
MIRALL_TEST_TIMEOUT_SCALE: '3'
MIRALL_TEST_IPC_TRANSPORT: ${{ matrix.transport }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup
- name: Flow tests (shard ${{ matrix.shard }}, ${{ matrix.transport }})
run: >-
bash scripts/ci/run-flow-shard.sh
${{ matrix.shard }} ${{ matrix.slice || matrix.shard }} 6
"${{ matrix.transport }}, ${{ matrix.os }}"
- name: Upload flake report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: flake-report-${{ matrix.os }}-${{ matrix.shard }}
path: flake-report
if-no-files-found: ignore

# The integration shards under Bare, one process per file, as in test.yml.
bare:
name: bare (${{ matrix.os }}, ${{ matrix.shard }})
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
os: [macos-15, windows-latest]
shard: [1, 2, 3, 4]
env:
MIRALL_TEST_TIMEOUT_SCALE: '3'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: ./.github/actions/setup
# Through bare-runtime's Node launcher, the way test/bare-runner.mjs starts it: a missing
# prebuild for this system fails here, by name, instead of once per test file.
- name: Check the bare runtime starts
run: node node_modules/bare-runtime/bin/bare --version
- name: Integration tests (shard ${{ matrix.shard }}/4)
run: |
files="$(node test/bare-shard.mjs ${{ matrix.shard }} 4)"
# One spelling of a path on every system, so a report names a file the same way everywhere.
files="${files//\\//}"
echo "Shard ${{ matrix.shard }}/4:"; echo "$files" | tr ' ' '\n'
node test/bare-runner.mjs --jobs 2 --retries 1 \
--report flake-report/flake-${{ matrix.shard }}.json \
--shard-label ${{ matrix.shard }} $files
- name: Upload flake report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: bare-flake-report-${{ matrix.os }}-${{ matrix.shard }}
path: flake-report
if-no-files-found: ignore
52 changes: 52 additions & 0 deletions scripts/ci/run-flow-shard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
# Runs one flow shard the way CI grades it: every file in its own runner process, so one file's
# crash cannot abort the rest, then ONLY the failed files once more. A file that passes on the
# retry is a flake, recorded in flake-report/flake-<shard>.json in the shape
# scripts/ci/flake-ledger.mjs reads; a file that fails twice fails the shard. The first attempt's
# output of every failed file is kept under flake-report/logs: a flake that only reproduces in CI
# cannot be diagnosed from an annotation.
#
# The transport is not an argument: test/helpers/peer.js reads MIRALL_TEST_IPC_TRANSPORT.
#
# Usage: scripts/ci/run-flow-shard.sh <shard label> <1-based slice> <slice total> [name]
# <shard label> a number; names the report file and the annotations
# <slice> which partition of test/flow-shard.mjs to run (differs from the label when a
# shard re-runs another shard's files over a second transport)
# [name] shown beside the label in the log and the step summary, e.g. "socket, windows"
set -euo pipefail

cd "$(dirname "$0")/../.."

shard="${1:?usage: run-flow-shard.sh <shard label> <slice> <slice total> [name]}"
slice="${2:?missing slice}"
total="${3:?missing slice total}"
name="${4:-${MIRALL_TEST_IPC_TRANSPORT:-pipe}}"

files="$(node test/flow-shard.mjs "$slice" "$total")"
# One spelling of a path on every system: the report's file names are compared across runs, and a
# backslash is neither a path separator to bash nor a legal character in the JSON written below.
files="${files//\\//}"
echo "Shard $shard ($name):"; echo "$files" | tr ' ' '\n'
mkdir -p flake-report/logs

failed=""
for f in $files; do
log="flake-report/logs/$(echo "$f" | tr '/' '_').log"
if node test/flow-runner.mjs "$f" >"$log" 2>&1; then rm -f "$log"; else cat "$log"; failed="$failed $f"; fi
done

entries=""
status=0
if [ -n "$failed" ]; then
echo "::warning title=Flow shard $shard ($name) flaked::retried$failed (a pass-on-retry is a residual flake — the failed attempt's output is in the flake-report artifact)"
for f in $failed; do
if node test/flow-runner.mjs "$f"; then passed=true; else passed=false; status=1; fi
entries="$entries{\"file\":\"$f\",\"attempts\":2,\"passedOnRetry\":$passed},"
done
fi

printf '{"shard":%s,"files":[%s]}\n' "$shard" "${entries%,}" > "flake-report/flake-$shard.json"
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
{ echo "### Flow shard $shard ($name)"; if [ -z "$failed" ]; then echo "No retries."; else echo "Retried:$failed"; fi; } >> "$GITHUB_STEP_SUMMARY"
fi
exit $status
14 changes: 10 additions & 4 deletions test/bare-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ function fail(message) {
process.exit(1)
}

// The bare binary lives in node_modules/.bin, which npm puts on PATH for a script it runs but which
// a direct `node test/bare-runner.mjs` does not have. brittle-bare's shebang resolves `bare` from
// PATH, so the child gets it either way.
// Both are started as scripts handed to an interpreter, never through their node_modules/.bin
// entries: those are shebang files on macOS and Linux and `.cmd` shims on Windows, and a spawn
// without a shell can run neither kind on Windows. bare-runtime's launcher is a Node script that
// starts the platform's bare binary on brittle's entry, which is the chain the shebangs resolve to.
const BARE_LAUNCHER = path.join('node_modules', 'bare-runtime', 'bin', 'bare')
const BRITTLE_ENTRY = path.join('node_modules', 'brittle', 'brittle-bare.js')

// node_modules/.bin is on PATH for a script npm runs, but not for a direct
// `node test/bare-runner.mjs`. A test that starts `bare` by name gets it either way.
function childEnv() {
const bin = path.resolve('node_modules/.bin')
return { ...process.env, PATH: `${bin}${path.delimiter}${process.env.PATH || ''}` }
Expand All @@ -54,7 +60,7 @@ function childEnv() {
function runFile(file) {
return new Promise((resolve) => {
const startedAt = Date.now()
const child = spawn(path.join('node_modules', '.bin', 'brittle-bare'), [file], {
const child = spawn(process.execPath, [BARE_LAUNCHER, BRITTLE_ENTRY, file], {
env: childEnv(),
stdio: ['ignore', 'pipe', 'pipe'],
})
Expand Down
16 changes: 16 additions & 0 deletions test/helpers/bash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// The shell the repository's scripts run under, for a test that spawns one. On Windows a bare
// `bash` can resolve to the WSL launcher, which reads no Windows path, so the bash that Git for
// Windows installs is named outright where it exists.
import { existsSync } from 'node:fs'
import path from 'node:path'

function gitForWindowsBash() {
const exe = path.join(process.env.ProgramFiles || 'C:\\Program Files', 'Git', 'bin', 'bash.exe')
return existsSync(exe) ? exe : 'bash'
}

export const BASH = process.platform === 'win32' ? gitForWindowsBash() : 'bash'

// A script path as bash reads it: forward slashes on every system, since a backslash is an escape
// to the shell and to the tools a script hands the path on to.
export const shellPath = (p) => p.split(path.sep).join('/')
10 changes: 10 additions & 0 deletions test/helpers/listen-address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Where a test's stand-in for the worker listens, the way the worker itself does on this system: a
// socket file in the given directory on POSIX, a named pipe on Windows, which binds no socket to a
// file path.
import path from 'node:path'
import { randomBytes } from 'node:crypto'

export function listenAddress(dir, name) {
if (process.platform !== 'win32') return path.join(dir, name)
return '\\\\.\\pipe\\mirall-test-' + randomBytes(16).toString('hex')
}
5 changes: 4 additions & 1 deletion test/invariants/engine-boundaries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ function walk(dir, out = []) {
return out
}

// One spelling of a path on every system, the one the allowlist is written in.
const rel = (from, to) => path.relative(from, to).split(path.sep).join('/')

function engineImports() {
const found = []
for (const file of [...walk(path.join(root, 'src')), ...walk(path.join(root, 'scripts'))]) {
if (file.startsWith(ENGINE + path.sep)) continue
for (const m of readFileSync(file, 'utf8').matchAll(/(?:from|import)\s*\(?\s*'([^']+)'/g)) {
if (!m[1].startsWith('.')) continue
const target = path.resolve(path.dirname(file), m[1])
if (target.startsWith(ENGINE + path.sep)) found.push({ importer: path.relative(root, file), entry: path.relative(ENGINE, target) })
if (target.startsWith(ENGINE + path.sep)) found.push({ importer: rel(root, file), entry: rel(ENGINE, target) })
}
}
return found
Expand Down
2 changes: 1 addition & 1 deletion test/invariants/engine-license-notice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test('every file derived from upstream opens with its license and modification n
})

test('no first-party engine file claims an upstream origin', (t) => {
const own = readdirSync(ENGINE, { recursive: true }).filter((name) => name.endsWith('.js') && !DERIVED.has(name))
const own = readdirSync(ENGINE, { recursive: true }).map((name) => name.split(path.sep).join('/')).filter((name) => name.endsWith('.js') && !DERIVED.has(name))
t.ok(own.some((name) => name.includes('/')), 'the walk reaches the engine subfolders')
t.alike(own.filter((name) => read(path.join(ENGINE, name)).includes('Derived from hyper-overlay')), [])
})
Expand Down
2 changes: 1 addition & 1 deletion test/invariants/main-env-reads.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function envReads(source) {

const reads = Object.fromEntries(
['src/main', 'src/preload'].flatMap((dir) => walk(path.join(ROOT, dir)))
.map((file) => [path.relative(ROOT, file), envReads(readFileSync(file, 'utf8'))])
.map((file) => [path.relative(ROOT, file).split(path.sep).join('/'), envReads(readFileSync(file, 'utf8'))])
.filter(([, found]) => found.length > 0),
)

Expand Down
2 changes: 1 addition & 1 deletion test/invariants/path-field-harmonized.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function sourceFiles(dir) {
return out
}

const files = sourceFiles(RENDERER).map((f) => ({ rel: path.relative(RENDERER, f), src: read(f) }))
const files = sourceFiles(RENDERER).map((f) => ({ rel: path.relative(RENDERER, f).split(path.sep).join('/'), src: read(f) }))
const pathRow = read(path.join(RENDERER, 'components/path/PathRow.tsx'))

// `FilePath` renders the path text alone. Beside an action it is the bare-text form this
Expand Down
8 changes: 5 additions & 3 deletions test/invariants/poll-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ test('until reports a timeout; waitFor throws it', async (t) => {
// The extra check the three re-checking call sites relied on: a condition that only becomes true
// during the final sleep still has to be seen.
test('a condition that flips during the last sleep is still seen', async (t) => {
let ready = false
setTimeout(() => { ready = true }, 45)
t.is(await until(() => ready, 40, { interval: 30, scale: false }), true)
// True from the deadline on, so no check inside the loop can see it and the answer rests on the
// one made after it. Read off the clock the helper reads, not off a second timer: two timers due
// a few milliseconds apart fire in either order on a coarse system timer.
const flipsAt = Date.now() + 40
t.is(await until(() => Date.now() >= flipsAt, 40, { interval: 30, scale: false }), true)
})

test('a sync predicate is accepted', async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion test/invariants/renderer-no-window-channels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('no renderer action is handed over as a window event', (t) => {
const files = walk(root)
t.ok(files.length > 100, `walked ${files.length} renderer files`)
for (const file of files) {
const rel = path.relative(root, file)
const rel = path.relative(root, file).split(path.sep).join('/')
if (rel === BROADCASTER) continue
t.absent(/window\.dispatchEvent\s*\(/.test(readFileSync(file, 'utf8')),
`${rel}: hands an action over as a window event — give the screen navigation state instead`)
Expand Down
2 changes: 1 addition & 1 deletion test/invariants/renderer-primitive-single-source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test('no renderer file hand-rolls what a primitive owns', (t) => {

for (const rule of RULES) {
for (const file of files) {
const rel = path.relative(root, file)
const rel = path.relative(root, file).split(path.sep).join('/')
if (rel === rule.owner || rule.exempt?.includes(rel)) continue
t.absent(rule.pattern.test(readFileSync(file, 'utf8')),
`${rel} builds ${rule.what} itself — use ${rule.use}`)
Expand Down
2 changes: 1 addition & 1 deletion test/invariants/sck-epoch-plumbing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function walk(dir, out = []) {
return out
}

const rel = (p) => path.relative(root, p)
const rel = (p) => path.relative(root, p).split(path.sep).join('/')
// Code only: comment lines are dropped before matching, so a doc mention is never a reader.
const codeOf = (f) => readFileSync(f, 'utf8').split('\n').filter((l) => !/^\s*(\/\/|\*|\/\*)/.test(l)).join('\n')
const filesMatching = (re) => walk(srcDir).filter((f) => re.test(codeOf(f))).map(rel).sort()
Expand Down
3 changes: 2 additions & 1 deletion test/raw/update-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const { ConfigStore } = require('../../src/main/config-store.js')
// mode allows it.

const host = `${process.platform}-${process.arch}`
const NAME = 'Mirall.AppImage'
// A file the updater swaps in place on this system: on Windows it applies only an .exe that way.
const NAME = process.platform === 'win32' ? 'Mirall.exe' : 'Mirall.AppImage'
const PREFIX = `/by-arch/${host}/app/${NAME}`
const PAYLOAD = Buffer.alloc(64 * 1024 * 16, 7)

Expand Down
2 changes: 1 addition & 1 deletion test/unit/audit-coverage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function walk(dir, out = []) {

// Data-layer sources only: the renderer holds a mirror of the vocabulary for search labels, and
// counting it as a call site would let a kind look "wired" while nothing ever records it.
const dataLayerFiles = walk(SRC).filter((f) => f.includes('/shared/') || f.includes('/worker/'))
const dataLayerFiles = walk(SRC).filter((f) => /[\\/](shared|worker)[\\/]/.test(f))
const dataLayerSource = dataLayerFiles.map((f) => readFileSync(f, 'utf8')).join('\n')

// Every string literal the audit vocabulary could be spelled as. Deliberately NOT anchored to
Expand Down
6 changes: 5 additions & 1 deletion test/unit/bare-runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import path from 'path'
const repo = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
const fixture = (name) => `test/fixtures/bare-runner/${name}`

// How the operating system reports a process that aborted: SIGABRT's 128 + 6 on POSIX, the
// fail-fast status code on Windows.
const ABORT_EXIT = process.platform === 'win32' ? 0xC0000409 : 134

function runRunner(args) {
const r = spawnSync(process.execPath, ['test/bare-runner.mjs', ...args], { cwd: repo, encoding: 'utf8' })
return { status: r.status, out: `${r.stdout}${r.stderr}` }
Expand All @@ -20,7 +24,7 @@ test('REGRESSION (FIX-255: an aborting file is named, and takes no other file wi
const { status, out } = runRunner(['--jobs', '2', fixture('aborting.test.js'), fixture('passing.test.js')])

t.ok(out.includes(`FAIL ${fixture('aborting.test.js')}`), 'the file that aborted is named')
t.ok(out.includes('exit 134'), 'with how it died')
t.ok(out.includes(`exit ${ABORT_EXIT}`), 'with how it died')
t.ok(out.includes('nothing awaits this'), 'and its output is printed, not swallowed')
t.ok(out.includes(`ok ${fixture('passing.test.js')}`), 'the sibling file still ran and passed')
t.not(status, 0, 'the run exits non-zero')
Expand Down
Loading
Loading