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
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The installer must start before the VC++ Redistributable is installed.
[target.'cfg(all(windows, target_env = "msvc"))']
rustflags = ["-C", "target-feature=+crt-static"]
10 changes: 9 additions & 1 deletion .github/workflows/agent-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ jobs:
key: pb-${{ runner.os }}-${{ hashFiles('agent-app/spec/pocketbase.version') }}

- name: Install workspace
run: npm install
run: npm ci

- name: PocketBase bootstrap regressions
run: node --test tools/src/commands/pb.test.ts

- name: Cold PocketBase download
env:
AGENT_APP_PB_CACHE: ${{ runner.temp }}/craftbot-pb-cold
run: node tools/src/cli.ts pb fetch

- name: Typecheck (kit + tools)
run: npm run typecheck
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/launcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ on:
push:
paths:
- "launcher/**"
- ".cargo/config.toml"
- "app/runtime-manifest.json"
- ".github/workflows/launcher.yml"
pull_request:
paths:
- "launcher/**"
- ".cargo/config.toml"
- "app/runtime-manifest.json"
- ".github/workflows/launcher.yml"

env:
Expand Down Expand Up @@ -69,5 +73,16 @@ jobs:
- name: Test
run: cargo test --release

- name: Bootstrap pinned Python without a system interpreter
run: cargo test --release live_python_bootstrap -- --ignored

- name: Build
run: cargo build --release

- name: Start on minimal Linux without desktop or developer packages
if: matrix.os_label == 'linux'
run: |
. /etc/os-release
docker run --rm --network none \
--volume "$PWD/target/release/CraftBotInstaller:/installer:ro" \
"ubuntu:$VERSION_ID" /installer --headless status
35 changes: 35 additions & 0 deletions .github/workflows/runtime-bootstrap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Runtime bootstrap

on:
pull_request:
paths:
- 'app/runtime*'
- 'app/node_runtime.py'
- 'app/downloads.py'
- 'app/provision/**'
- 'agent-app/**'
- 'install.py'
- 'craftbot.py'
- 'run.py'
- 'tests/install_bootstrap/**'
- 'scripts/test_runtime_bootstrap.py'
- '.github/workflows/runtime-bootstrap.yml'
workflow_dispatch:

jobs:
bootstrap:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Bootstrap regression tests (stdlib only)
run: python -m unittest discover -s tests/install_bootstrap -v
- name: Download runtimes and prepare Agent Apps with an empty PATH
run: python scripts/test_runtime_bootstrap.py
9 changes: 9 additions & 0 deletions agent-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions agent-app/spec/pocketbase-checksums.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"pocketbase_0.39.7_darwin_amd64.zip": "32ee65426529c5fc48b7899431b9cf22e54c40a2f39f9fde92948bcabebaa933",
"pocketbase_0.39.7_darwin_arm64.zip": "f94b96eac1684d35cad5368334c156673fa21ae28df721e712e1cf3b8176aeb8",
"pocketbase_0.39.7_linux_amd64.zip": "0fe09a4e1a8f6e5b53d206c2e6b94a5812febcb43082d66d69bc8ba4d8e8429c",
"pocketbase_0.39.7_linux_arm64.zip": "ff6296e90bb5545592c5696e9d591fa4570fbdf31aaec58b51c70ce7d15f581d",
"pocketbase_0.39.7_linux_armv7.zip": "be8f85b0a6e5bf284e26ca6dca5d88e2ab5234d030274069020566f1b836941c",
"pocketbase_0.39.7_linux_ppc64le.zip": "a643da593e4c234bec4a91039fae4530003f9012137fab181f0d7f1799413301",
"pocketbase_0.39.7_linux_s390x.zip": "5f2dc7cf20d04b548f9f23e124670d97ab4d51ecff1215b391255c268050bed0",
"pocketbase_0.39.7_windows_amd64.zip": "0f32dfda39949cfbec38ea18fe99f1e9e49350ce1efe87537591b44dcee51517",
"pocketbase_0.39.7_windows_arm64.zip": "93ea40181210b1db7d7a885caf832cbd8945ab6ae1d43ed2c858bfc4390b4d26"
}
3 changes: 3 additions & 0 deletions agent-app/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"devDependencies": {
"@types/node": "^24.0.0",
"playwright": "^1.61.1"
},
"dependencies": {
"fflate": "0.8.3"
}
}
6 changes: 2 additions & 4 deletions agent-app/tools/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ export async function run(args: string[]): Promise<number> {
);
children.push(pb);

// Windows: npm is npm.cmd, which Node refuses to spawn without a shell.
const isWin = process.platform === 'win32';
const vite = spawn(isWin ? 'npm.cmd' : 'npm', ['run', 'dev'], {
const [node, npm] = osAdapter.npmCommand();
const vite = spawn(node, [npm, 'run', 'dev'], {
cwd: join(projectDir, 'frontend'),
stdio: 'inherit',
shell: isWin,
env: {
...process.env,
VITE_PB_URL: `http://127.0.0.1:${pbPort}`,
Expand Down
150 changes: 150 additions & 0 deletions agent-app/tools/src/commands/pb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';
import { zipSync, strToU8 } from 'fflate';
import { OSAdapter } from '../lib/os-adapter.ts';
import { acquireDownloadLock, binaryReady, downloadArchive, ensurePbBinary } from './pb.ts';

test('npm is invoked as a JS entry point with the selected Node, including special paths', () => {
const root = mkdtempSync(join(tmpdir(), 'node & caf\u00e9-'));
try {
const node = join(root, 'node');
writeFileSync(node, 'placeholder');
const adapter = new OSAdapter();
assert.throws(() => adapter.npmCommand(node), /Matching npm is missing/);
const directory = join(root, 'node_modules/npm/bin');
mkdirSync(directory, { recursive: true });
const cli = join(directory, 'npm-cli.js');
writeFileSync(cli, 'placeholder');
assert.deepEqual(adapter.npmCommand(node), [realpathSync(node), realpathSync(cli)]);
} finally { rmSync(root, { recursive: true, force: true }); }
});

test('npm discovery supports distro symlinks', { skip: process.platform === 'win32' }, () => {
const root = mkdtempSync(join(tmpdir(), 'node-distro-'));
try {
mkdirSync(join(root, 'bin'));
mkdirSync(join(root, 'share/npm/bin'), { recursive: true });
const node = join(root, 'bin/node');
const cli = join(root, 'share/npm/bin/npm-cli.js');
writeFileSync(node, 'placeholder');
writeFileSync(cli, 'placeholder');
symlinkSync(cli, join(root, 'bin/npm'));
assert.deepEqual(new OSAdapter().npmCommand(node), [realpathSync(node), realpathSync(cli)]);
} finally { rmSync(root, { recursive: true, force: true }); }
});

test('extracts ZIP on each platform without tools, including Unicode and spaces', () => {
const root = mkdtempSync(join(tmpdir(), 'pb-zip-'));
const oldPath = process.env.PATH;
try {
const zip = join(root, 'input.zip');
writeFileSync(zip, zipSync({ 'folder/hello.txt': strToU8('hello') }));
process.env.PATH = join(root, 'no-tools');
for (const platform of ['win32', 'darwin', 'linux'] as const) {
const dest = join(root, platform, 'User Name & caf\u00e9 \u6587\u4ef6');
new OSAdapter(platform, 'x64').extractZip(zip, dest);
assert.equal(readFileSync(join(dest, 'folder/hello.txt'), 'utf8'), 'hello');
}
} finally {
process.env.PATH = oldPath;
rmSync(root, { recursive: true, force: true });
}
});

test('rejects escaping ZIP entries before writing outside staging', () => {
const root = mkdtempSync(join(tmpdir(), 'pb-unsafe-'));
try {
for (const name of ['../outside', '..\\outside', '/absolute', 'C:/absolute']) {
const zip = join(root, 'input.zip');
writeFileSync(zip, zipSync({ [name]: strToU8('bad') }));
assert.throws(() => new OSAdapter().extractZip(zip, join(root, 'out')), /Unsafe ZIP/);
assert.equal(existsSync(join(root, 'outside')), false);
}
} finally { rmSync(root, { recursive: true, force: true }); }
});

test('rejects truncated ZIP data', () => {
const root = mkdtempSync(join(tmpdir(), 'pb-truncated-'));
try {
const zip = join(root, 'input.zip');
writeFileSync(zip, zipSync({ hello: strToU8('hello') }).subarray(0, 10));
assert.throws(() => new OSAdapter().extractZip(zip, join(root, 'out')));
} finally { rmSync(root, { recursive: true, force: true }); }
});

test('unsupported architectures cannot silently select x64', () => {
assert.throws(() => new OSAdapter('linux', 'riscv64'), /Unsupported CPU/);
assert.throws(() => new OSAdapter('win32', 'ia32'), /Unsupported CPU/);
});

test('cached binaries must run and report the expected version', () => {
const root = mkdtempSync(join(tmpdir(), 'pb-binary-'));
try {
const broken = join(root, 'pocketbase.exe');
writeFileSync(broken, '');
assert.equal(binaryReady(broken, '0.39.7'), false);
assert.equal(binaryReady(process.execPath, process.version), true);
assert.equal(binaryReady(process.execPath, '0.39.7'), false);
} finally { rmSync(root, { recursive: true, force: true }); }
});

test('readiness check never fetches missing PocketBase', async () => {
const root = mkdtempSync(join(tmpdir(), 'pb-check-'));
const cache = process.env.AGENT_APP_PB_CACHE;
const fetch = globalThis.fetch;
try {
process.env.AGENT_APP_PB_CACHE = root;
globalThis.fetch = async () => { throw new Error('unexpected download'); };
await assert.rejects(ensurePbBinary(false), /missing or damaged/);
} finally {
globalThis.fetch = fetch;
if (cache === undefined) delete process.env.AGENT_APP_PB_CACHE;
else process.env.AGENT_APP_PB_CACHE = cache;
rmSync(root, { recursive: true, force: true });
}
});

test('download checks the pinned digest', async () => {
const root = mkdtempSync(join(tmpdir(), 'pb-download-'));
const fetch = globalThis.fetch;
try {
const data = Buffer.from('archive');
globalThis.fetch = async () => new Response(data);
await downloadArchive('https://example.test/pb.zip', join(root, 'ok'), createHash('sha256').update(data).digest('hex'));
await assert.rejects(downloadArchive('https://example.test/pb.zip', join(root, 'bad'), '0'.repeat(64)), /SHA-256/);
} finally { globalThis.fetch = fetch; rmSync(root, { recursive: true, force: true }); }
});

test('simultaneous downloads serialize across lock owners', async () => {
const root = mkdtempSync(join(tmpdir(), 'pb-lock-'));
try {
const lock = join(root, '.lock');
const release = await acquireDownloadLock(lock);
let entered = false;
const next = acquireDownloadLock(lock).then((unlock) => { entered = true; return unlock; });
await new Promise((resolve) => setTimeout(resolve, 150));
assert.equal(entered, false);
release();
const unlock = await next;
assert.equal(entered, true);
unlock();
assert.equal(existsSync(lock), false);
} finally { rmSync(root, { recursive: true, force: true }); }
});

test('empty lock left by an interrupted writer can be recovered', async () => {
const { utimesSync } = await import('node:fs');
const root = mkdtempSync(join(tmpdir(), 'pb-stale-'));
try {
const lock = join(root, '.lock');
writeFileSync(lock, '');
utimesSync(lock, new Date(0), new Date(0));
const release = await acquireDownloadLock(lock);
release();
assert.equal(existsSync(lock), false);
} finally { rmSync(root, { recursive: true, force: true }); }
});
Loading
Loading