fix(workflow-sdk): extract examples workflows zip in pretest hook

The examples-roundtrip test reads workflow JSONs from examples/workflows/,
which are extracted from examples/templates.zip (the only committed
artifact). The pretest extract script only handled the test-fixtures zip;
on a fresh CI checkout that left examples/workflows/ empty and every
roundtrip case failed with ENOENT.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mutasem Aldmour 2026-05-12 15:42:11 +02:00
parent a18513dc85
commit 3f8ff823e1
No known key found for this signature in database
GPG Key ID: 3DFA8122BB7FD6B8

View File

@ -1,8 +1,11 @@
/**
* Extract Test Workflows from Zip
* Extract Test Workflows from Zips
*
* Extracts workflow JSON files from the committed zip file for testing.
* This runs automatically via `pretest` hook before running tests.
* Extracts workflow JSON files from committed zip files for testing:
* - test-fixtures/real-workflows/public_published_templates.zip test-fixtures/real-workflows/
* - examples/templates.zip examples/workflows/ (used by examples-roundtrip test)
*
* Runs automatically via `pretest` hook before running tests.
*
* Usage:
* npx tsx scripts/extract-workflows.ts
@ -13,35 +16,45 @@ import * as path from 'path';
import AdmZip from 'adm-zip';
const FIXTURES_DIR = path.resolve(__dirname, '../test-fixtures/real-workflows');
const ZIP_FILE = path.join(FIXTURES_DIR, 'public_published_templates.zip');
const FIXTURES_ZIP = path.join(FIXTURES_DIR, 'public_published_templates.zip');
function main() {
if (!fs.existsSync(ZIP_FILE)) {
console.log('No zip file found, skipping extraction');
const EXAMPLES_DIR = path.resolve(__dirname, '../examples');
const EXAMPLES_ZIP = path.join(EXAMPLES_DIR, 'templates.zip');
const EXAMPLES_WORKFLOWS_DIR = path.join(EXAMPLES_DIR, 'workflows');
function extractZip(zipPath: string, outputDir: string, label: string) {
if (!fs.existsSync(zipPath)) {
console.log(`No ${label} zip found at ${zipPath}, skipping extraction`);
return;
}
// Check if extraction is needed by looking for any .json file
const existingFiles = fs.readdirSync(FIXTURES_DIR).filter((f) => f.endsWith('.json'));
fs.mkdirSync(outputDir, { recursive: true });
const existingFiles = fs.readdirSync(outputDir).filter((f) => f.endsWith('.json'));
if (existingFiles.length > 0) {
console.log(`Found ${existingFiles.length} workflow files, skipping extraction`);
console.log(`Found ${existingFiles.length} ${label} files, skipping extraction`);
return;
}
console.log('Extracting workflows from zip...');
const zip = new AdmZip(ZIP_FILE);
console.log(`Extracting ${label} from zip...`);
const zip = new AdmZip(zipPath);
const entries = zip.getEntries();
let count = 0;
for (const entry of entries) {
if (entry.entryName.endsWith('.json')) {
const outputPath = path.join(FIXTURES_DIR, entry.entryName);
const outputPath = path.join(outputDir, entry.entryName);
fs.writeFileSync(outputPath, entry.getData());
count++;
}
}
console.log(`Extracted ${count} workflow files`);
console.log(`Extracted ${count} ${label} files`);
}
function main() {
extractZip(FIXTURES_ZIP, FIXTURES_DIR, 'test-fixtures workflows');
extractZip(EXAMPLES_ZIP, EXAMPLES_WORKFLOWS_DIR, 'examples workflows');
}
main();