|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import path from 'node:path'; |
| 4 | +import { test } from 'vitest'; |
| 5 | +import { mkdtempForTestSync } from '../../src/__tests__/test-utils/tmp-dir.ts'; |
| 6 | +import { preparePublishAssets } from '../prepare-publish-assets.mjs'; |
| 7 | + |
| 8 | +test('prepares both Android runtime helpers through the shared publish owner', () => { |
| 9 | + const root = mkdtempForTestSync('agent-device-publish-assets-'); |
| 10 | + const scriptsDirectory = path.join(root, 'scripts'); |
| 11 | + fs.mkdirSync(scriptsDirectory, { recursive: true }); |
| 12 | + fs.writeFileSync(path.join(root, 'package.json'), '{"version":"1.2.3"}\n'); |
| 13 | + fs.writeFileSync(path.join(scriptsDirectory, 'package-apple-runner-source.mjs'), ''); |
| 14 | + fs.writeFileSync( |
| 15 | + path.join(scriptsDirectory, 'package-android-helper.sh'), |
| 16 | + `#!/bin/sh |
| 17 | +set -eu |
| 18 | +if [ "$AGENT_DEVICE_ANDROID_HELPER" = "snapshot" ]; then |
| 19 | + output="$3" |
| 20 | +else |
| 21 | + output="$2" |
| 22 | +fi |
| 23 | +mkdir -p "$output" |
| 24 | +prefix="agent-device-android-$AGENT_DEVICE_ANDROID_HELPER-helper-$1" |
| 25 | +printf apk > "$output/$prefix.apk" |
| 26 | +printf manifest > "$output/$prefix.manifest.json" |
| 27 | +printf checksum > "$output/$prefix.apk.sha256" |
| 28 | +`, |
| 29 | + ); |
| 30 | + |
| 31 | + const stalePath = path.join(root, 'android', 'ime-helper', 'dist', 'stale.apk'); |
| 32 | + fs.mkdirSync(path.dirname(stalePath), { recursive: true }); |
| 33 | + fs.writeFileSync(stalePath, 'stale'); |
| 34 | + |
| 35 | + preparePublishAssets({ root }); |
| 36 | + |
| 37 | + assert.equal(fs.existsSync(stalePath), false); |
| 38 | + for (const helper of ['snapshot', 'ime']) { |
| 39 | + const prefix = `agent-device-android-${helper}-helper-1.2.3`; |
| 40 | + const directory = path.join(root, 'android', `${helper}-helper`, 'dist'); |
| 41 | + assert.deepEqual(fs.readdirSync(directory).sort(), [ |
| 42 | + `${prefix}.apk`, |
| 43 | + `${prefix}.apk.sha256`, |
| 44 | + `${prefix}.manifest.json`, |
| 45 | + ]); |
| 46 | + } |
| 47 | +}); |
0 commit comments