Skip to content
1 change: 1 addition & 0 deletions .github/scripts/http-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ wait_for_browsers() {
exit 1
fi
browsers_pid=''
grep -E '^(Installed system dependencies|Cache install failed|Stored [0-9]+ packages|Browser install took)' "$browsers_log" || true
}

# start_app <name> <port> <label> [record-http-status]
Expand Down
52 changes: 49 additions & 3 deletions .github/scripts/install-playwright.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/usr/bin/env bash
# The dependency dry run uses the pinned driver's package list without updating apt.
#
# PLAYWRIGHT_APT_CACHE names a directory of .deb files kept between runs (the workflow restores it
# per runner image and browser set). With it, missing system libraries install from those files
# without reaching an Ubuntu mirror, whose stalls have held a suite in this step for 16 minutes.
# A cold or incomplete cache falls back to `install-deps`, then stores what apt downloaded and
# writes `$cache/.updated`, which tells the workflow to save the cache under a new key.
set -euo pipefail

started=$SECONDS

browsers=()
for argument in "$@"; do
case "$argument" in
Expand All @@ -10,7 +18,45 @@ for argument in "$@"; do
esac
done

if ! bunx --no-install playwright install-deps --dry-run "${browsers[@]}"; then
bunx --no-install playwright install-deps "${browsers[@]}"
deps_present() {
bunx --no-install playwright install-deps --dry-run "${browsers[@]}" > /dev/null 2>&1
}

# dpkg, not apt: apt prefers a repository copy of a package whose version matches a cached file
# and fetches it. The cache key pins the runner image, so the files are the exact set apt
# installed there, and dpkg resolves their dependencies among themselves without the network.
install_from_cache() {
[ -n "$cache" ] && compgen -G "$cache/*.deb" > /dev/null || return 1
local output
if ! output=$(sudo DEBIAN_FRONTEND=noninteractive dpkg -i "$cache"/*.deb 2>&1); then
printf '%s\n' "$output" | tail -n 5 | sed 's/^/Cache install failed: /'
dpkg_failed=true
return 1
fi
deps_present
}

cache=${PLAYWRIGHT_APT_CACHE:-}
dpkg_failed=false
if ! deps_present; then
if install_from_cache; then
echo "Installed system dependencies from $cache"
else
# Only a failed dpkg run leaves packages half-configured; apt must finish or remove them
# before install-deps can install anything.
if [ "$dpkg_failed" = true ]; then
sudo DEBIAN_FRONTEND=noninteractive apt-get -f install -y > /dev/null
fi
bunx --no-install playwright install-deps "${browsers[@]}"
if [ -n "$cache" ] && compgen -G '/var/cache/apt/archives/*.deb' > /dev/null; then
mkdir -p "$cache"
cp /var/cache/apt/archives/*.deb "$cache"/
touch "$cache/.updated"
echo "Stored $(find "$cache" -name '*.deb' | wc -l) packages in $cache"
elif [ -n "$cache" ]; then
echo "::warning::apt kept no downloaded packages; nothing to cache for the next run."
fi
fi
fi
exec bunx --no-install playwright install "$@"
bunx --no-install playwright install "$@"
echo "Browser install took $((SECONDS - started))s"
34 changes: 33 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ jobs:
working-directory: packages/db
run: bun scripts/tune-ci-postgres.ts

# Browser system libraries, as downloaded .deb files, per runner image and group (each group
# installs its own browsers); install-playwright.sh reads and fills it.
- name: Read the runner image
id: runner-image
run: echo "version=$ImageOS-$ImageVersion" >> "$GITHUB_OUTPUT"

# Restores the newest saved set by prefix. A cache key is never overwritten, so a run that had
# to add packages saves a new one below.
- name: Restore browser system packages
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5
with:
path: ~/.cache/playwright-apt
key: playwright-apt-${{ steps.runner-image.outputs.version }}-${{ hashFiles('bun.lock') }}-${{ matrix.group }}-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: playwright-apt-${{ steps.runner-image.outputs.version }}-${{ hashFiles('bun.lock') }}-${{ matrix.group }}-

# Migrations create their own extensions, as on a fresh self-hosted install.
- name: Provision the database through migrations
if: matrix.group != 'project-files'
Expand Down Expand Up @@ -322,7 +337,24 @@ jobs:
- name: Run end-to-end suites
timeout-minutes: 19
working-directory: apps/sim
run: bash ../../.github/scripts/http-e2e.sh "${{ matrix.group }}"
run: PLAYWRIGHT_APT_CACHE="$HOME/.cache/playwright-apt" bash ../../.github/scripts/http-e2e.sh "${{ matrix.group }}"

# Packages installed fine even when the suite then fails, so both steps run unless cancelled.
- name: Check for new browser system packages
id: apt-cache
if: ${{ !cancelled() }}
run: |
if [ -f "$HOME/.cache/playwright-apt/.updated" ]; then
rm "$HOME/.cache/playwright-apt/.updated"
echo 'updated=true' >> "$GITHUB_OUTPUT"
fi

- name: Save browser system packages
if: ${{ !cancelled() && steps.apt-cache.outputs.updated == 'true' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5
with:
path: ~/.cache/playwright-apt
key: playwright-apt-${{ steps.runner-image.outputs.version }}-${{ hashFiles('bun.lock') }}-${{ matrix.group }}-${{ github.run_id }}-${{ github.run_attempt }}

- name: Upload acceptance timing and coverage reports
if: always()
Expand Down
21 changes: 19 additions & 2 deletions apps/sim/scripts/test-browser-extension-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ const checkNavigation = (name: string, run: () => Promise<void>) => check('navig
const checkComposer = (name: string, run: () => Promise<void>) => check('composer', name, run)
const checkAccess = (name: string, run: () => Promise<void>) => check('access', name, run)

/**
* A screenshot taken once two consecutive captures match, so a pixel comparison between two
* renderings of an element is not decided by a frame captured mid-paint.
*/
async function settledScreenshot(
target: Locator,
options: Parameters<Locator['screenshot']>[0]
): Promise<Buffer> {
let previous = await target.screenshot(options)
for (let capture = 0; capture < 10; capture++) {
const next = await target.screenshot(options)
if (next.equals(previous)) return next
previous = next
}
throw new Error('The element kept repainting across ten screenshots')
}

async function screenshot(name: string, target = panel) {
if (!target) return
for (const frame of target.frames()) {
Expand Down Expand Up @@ -1163,8 +1180,8 @@ try {
.toBe(true)
if (width === 320) {
const chip = attachments().first()
const visible = await chip.screenshot({ animations: 'disabled' })
const withoutEdgeMask = await chip.screenshot({
const visible = await settledScreenshot(chip, { animations: 'disabled' })
const withoutEdgeMask = await settledScreenshot(chip, {
animations: 'disabled',
style:
'div:has(> div > [aria-label="Page attached to next message"]) { mask-image: none !important; }',
Expand Down
23 changes: 14 additions & 9 deletions apps/sim/scripts/test-markdown-viewer-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,22 @@ async function editLastCell(page: Page, marker: string) {
timeout: 120_000,
})
await page.bringToFront()
await page
.locator('.rich-markdown-prose strong')
.filter({ hasText: /^bold$/ })
.click()
const bold = page.locator('.rich-markdown-prose strong').filter({ hasText: /^bold$/ })
await bold.click()
await expect(page.locator('.rich-markdown-prose[contenteditable="true"]')).toBeFocused()
await page.keyboard.press('ArrowLeft')
// A click can land the caret at the word's edge, where one step left crosses the space before it
// and Shift+ArrowRight selects only that space. Start inside the word: "bo|ld".
await bold.evaluate((element) => {
const text = element.firstChild
if (text?.nodeType !== Node.TEXT_NODE) throw new Error('The bold mark has no text node')
getSelection()?.collapse(text, 2)
})
await page.keyboard.press('Shift+ArrowRight')
assert(
await page.evaluate(() => Boolean(getSelection()?.toString().trim())),
'Keyboard selection did not select text'
)
await expect
.poll(() => page.evaluate(() => getSelection()?.toString() ?? ''), {
message: 'Keyboard selection did not select text',
})
.toBe('l')
await proveToolbar(page, page.getByRole('toolbar', { name: 'Text formatting' }))
await page.keyboard.press('ArrowRight')
}
Expand Down
Loading