* feat: add script module mode with folder model for Bun and Python Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add missing modules field to RawCode in bun_executor Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * sqlx * feat: enrich WAC templates with checkpoint and replay semantics Add prominent comments explaining that all computation must happen inside task/step/taskScript or it will be replayed on resume/retry. Clarify that waitForApproval does not hold a worker and that approve/reject URLs are available in the timeline step details. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): script module sync idempotency, per-module hash tracking, and preview support - Fix pull→push idempotency: use `??` instead of `||` for module lock field so empty strings are preserved (matches API's `lock: ""`) - Add per-module hash tracking in wmill-lock.yaml following the flow inline script pattern (SCRIPT_TOP_HASH + per-module subpath hashes) - Selective module lock regeneration: only regenerate locks for modules whose content actually changed, not all modules - Use unfiltered rawWorkspaceDependencies for module hashes to match what updateModuleLocks passes to fetchScriptLock - Show changed module names in stale script output for clarity - Add module support to `script preview` command: read modules from __mod/ folder and pass them in the preview API request - Add preview tests for taskScript pattern (flat and folder layout) - Update test assertion for module stale detection output Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat(frontend): WAC UI improvements — reorder templates, module tab rename, import consolidation - Reorder WAC template buttons: TypeScript before Python in ScriptBuilder, CreateActionsScript, and CreateActionsFlow - Remove dropdown items from +Script button (simplify to direct link) - Move "Import Workflow-as-Code" to +Flow dropdown with dedicated drawer - Add module tab rename: pencil icon on hover opens popover with validation, fixed-width icon container prevents layout shift Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: remaining module-mode changes from working branch - Backend parser updates for WAC detection - CLI sync/types updates for raw app path and module support - Frontend UI polish (Dev.svelte, ScriptRow, script hash page) - Test fixture updates Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test(cli): add test for module modification detection in generate-metadata Verifies that modifying a single module file re-triggers stale detection and only the changed module is listed, not all modules. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(backend): critical fixes from PR review - Fix hardcoded dev path in bun_executor.rs WAC v2 wrapper — use "windmill-client" import instead of absolute filesystem path - Fix missed no_main_func → auto_kind rename in parser TS test - Add modules column to clone_script SQL (windmill-common and windmill-api-workspaces) so cloned scripts retain their modules - Add modules: None to RawCode structs in worker tests - Restore complete sqlx cache (merge main's cache + our new queries) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(backend): fix clone warning treated as error in CI Change `.clone()` on double reference to `*k` dereference in scripts.rs hash implementation. Update sqlx cache with new query hashes from modified clone_script SQL. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(frontend): use published parser wasm versions for CI build The local file:// paths for windmill-parser-wasm-py and windmill-parser-wasm-ts don't exist in the Cloudflare Pages build environment. Revert to published npm versions (1.655.0). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(frontend): update parser wasm packages to 1.657.2 Use newly published windmill-parser-wasm-ts and windmill-parser-wasm-py v1.657.2 which include auto_kind/WAC detection changes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(frontend): regenerate package-lock.json for npm ci compatibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(frontend): use main's lockfile as base, update only parser wasm packages Regenerating package-lock.json from scratch pulled different dependency versions causing svelte-check type errors. Instead, start from main's lockfile and only update the two changed packages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(backend): add modules column to fetch_script_for_update query The Script<SR> struct has a modules field (FromRow), but fetch_script_for_update didn't SELECT modules, causing a runtime error "no column found for name: modules" when the worker processed dependency jobs. This was the root cause of the relock_skip test timeout. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(backend): fix script module execution for Python and Bun - Fix modules not passed through job queue: inject _MODULES into PushArgs.extra when pushing Code jobs so worker can extract them - Fix Python module imports: use relative imports (from .helper) and add sys.path.insert for module directory in wrapper - Fix Python tests: use relative imports and empty lock to prevent pip from resolving module names as packages - Add local file check in Bun loader for module resolution - Ignore Bun module test (bundle mode loader integration tracked separately) - Add missing modules column to fetch_script_for_update query Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(backend): remove unnecessary empty lock in Python module tests Relative imports (from .helper) are not parsed as pip packages, so the empty lock workaround is not needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(backend): fix module execution for Python and Bun — all tests pass Python modules: - Use relative imports (from .helper import greet) since scripts run as packages - Add sys.path.insert for module directory in wrapper to ensure local modules take precedence over pip packages with same name Bun modules: - Use bundled output (./out/main.js) as wrapper import when modules are present — the bundled output has module content inlined by Bun.build, avoiding runtime loader resolution issues - Add local file check in loader.bun.js onResolve to short-circuit API URL resolution for module files on disk Job queue: - Inject _MODULES into PushArgs.extra when pushing Code jobs so the worker can extract them at execution time Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * refactor: address PR review — simplify, fix correctness, remove dead code Critical fixes: - Replace all CLI `no_main_func` references with `auto_kind` (string) to match the backend migration and API changes - Remove duplicated `compute_python_module_dir` in worker.rs, use the canonical version from python_executor.rs High priority: - Auto-create `__init__.py` in intermediate directories for nested Python modules so imports like `from .utils.math import add` work without users manually creating __init__.py files - Remove redundant `sys_path_insert` — relative imports use Python's package system, not sys.path Medium: - Fix lock file base name extraction: use regex to strip only the final extension (`.replace(/\.[^.]+$/, '')`) instead of `indexOf(".")` which breaks for files like `helper.test.ts` Simplification: - Remove dead `{#if false}` Popover block in ScriptEditor.svelte - Guard loader.bun.js local file check to only run for relative paths (matching the Windows loader pattern) - Add clarifying comment on Bun dual mechanism (build + run phases) - Add maintenance comment on manual Hash impl for NewScript Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: final review fixes — stale cleanup, baseName, auto_kind export - Fix sync.ts baseName extraction using indexOf(".") → regex (same fix as script.ts/metadata.ts, missed this instance) - Add stale module file cleanup in writeModulesToDisk: removes files from __mod/ that are no longer in the modules map before writing, fixing the pull→push cycle that couldn't delete modules - Log warning when _MODULES serialization fails in job push instead of silently dropping modules - Use strict equality (===) for auto_kind comparison - Exclude auto_kind from workspace export — it is auto-detected by the parser at deploy time from script content Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(cli): remove auto_kind from push, comparison, and metadata auto_kind is auto-detected by the parser at deploy time, so the CLI should not send it, compare it, or write it to script.yaml. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove erroneously added backend/backend/.sqlx directory Duplicate .sqlx cache was committed at the wrong nested path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address PR review feedback + fix CI dead_code warning Frontend (ScriptEditor.svelte): - Fix switchToMain() missing lastSyncedCode update — prevents stale code sync on external changes while editing a module tab - Fix formatAction saving module code to main script's localStorage draft — now saves main code when on a module tab - Fix non-null assertion on inferModuleLang in renameModule — fall back to original language instead of force unwrap - Remove redundant activeModuleTab truthy check in runTest CLI (script.ts): - Clean up empty directories after removing stale module files in writeModulesToDisk Backend: - Add path traversal guard in write_module_files — reject module paths containing ".." - Fix dead_code warning on auto_kind field in workspace export struct Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat(frontend): improve auto_kind UX + address review findings - Rename "Include without main function" toggle to "Include library scripts" in script list (ItemsList.svelte) - Update NoMainFuncBadge: "No main" → "Library" with clearer tooltip - Filter module file extensions by main script language — Python scripts only allow .py modules, TypeScript only .ts, etc. - Split flushModuleState into flushModuleContent (no UI side-effect) and flushModuleState (flush + reset tab), reducing duplication - Dynamic placeholder and hint text in add module popover based on main script language Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
592 lines
17 KiB
TypeScript
592 lines
17 KiB
TypeScript
/**
|
|
* Test Fixtures
|
|
*
|
|
* Shared helpers for creating test data (scripts, flows, apps, raw apps) in tests.
|
|
*
|
|
* Two types of helpers:
|
|
* - Fixture functions: Return data structures with paths and contents (no disk I/O)
|
|
* - Local creation functions: Create fixtures AND write them to disk
|
|
*
|
|
* CROSS-LINKS - Related test helper locations (keep in sync when adding new helpers):
|
|
* @see test_backend.ts - API-based creation helpers (createTestApp, createTestResource, etc.)
|
|
* @see sync_pull_push.test.ts - Local fixtures + createRemoteScript (API-based)
|
|
*
|
|
* This file contains: Shared local fixtures (createLocalScript, createLocalFlow, etc.)
|
|
* If you add new helpers, update cross-links in the files above.
|
|
*
|
|
* @example
|
|
* // Using fixtures (data only)
|
|
* const fixture = createScriptFixture("my_script", "bun");
|
|
*
|
|
* // Using local creation (writes to disk)
|
|
* await createLocalScript(tempDir, "f/test", "my_script", "bun");
|
|
*
|
|
* @keywords createLocal, local script, local flow, local app, raw app, fixture, test data
|
|
*/
|
|
|
|
import { writeFile, mkdir } from "node:fs/promises";
|
|
import {
|
|
getFolderSuffix,
|
|
getMetadataFileName,
|
|
getModuleFolderSuffix,
|
|
} from "../src/utils/resource_folders.ts";
|
|
|
|
// =============================================================================
|
|
// Fixture Types
|
|
// =============================================================================
|
|
|
|
export interface FileFixture {
|
|
path: string;
|
|
content: string;
|
|
}
|
|
|
|
export interface ScriptFixture {
|
|
contentFile: FileFixture;
|
|
metadataFile: FileFixture;
|
|
}
|
|
|
|
export interface FlowFixture {
|
|
metadata: FileFixture;
|
|
inlineScript: FileFixture;
|
|
}
|
|
|
|
export interface AppFixture {
|
|
metadata: FileFixture;
|
|
}
|
|
|
|
export interface RawAppFixture {
|
|
metadata: FileFixture;
|
|
indexHtml: FileFixture;
|
|
indexJs: FileFixture;
|
|
[key: string]: FileFixture;
|
|
}
|
|
|
|
// =============================================================================
|
|
// Script Fixtures
|
|
// =============================================================================
|
|
|
|
/**
|
|
* Creates a script fixture (data structure, no disk I/O).
|
|
* See file header for cross-links to related helpers.
|
|
*
|
|
* Use this when you need fine-grained control over the script structure.
|
|
* For simple cases, use {@link createLocalScript} instead.
|
|
*
|
|
* @param name - Script name (without extension)
|
|
* @param language - Script language
|
|
* @param content - Optional custom script content
|
|
* @returns Script fixture with content and metadata files
|
|
*
|
|
* @example
|
|
* const fixture = createScriptFixture("my_script", "bun");
|
|
* const fixture = createScriptFixture("custom", "python3", "def main(): return 42");
|
|
*
|
|
* @keywords script fixture, create script, local script
|
|
*/
|
|
export function createScriptFixture(
|
|
name: string,
|
|
language: "python3" | "deno" | "bun" | "bash" | "go" | "postgresql" = "bun",
|
|
content?: string
|
|
): ScriptFixture {
|
|
const extensions: Record<string, string> = {
|
|
python3: ".py",
|
|
deno: ".ts",
|
|
bun: ".ts",
|
|
bash: ".sh",
|
|
go: ".go",
|
|
postgresql: ".sql",
|
|
};
|
|
|
|
const ext = extensions[language];
|
|
const defaultContent: Record<string, string> = {
|
|
python3: `def main():\n return "Hello from ${name}"`,
|
|
deno: `export async function main() {\n return "Hello from ${name}";\n}`,
|
|
bun: `export async function main() {\n return "Hello from ${name}";\n}`,
|
|
bash: `#!/bin/bash\necho "Hello from ${name}"`,
|
|
go: `package inner\n\nfunc main() string {\n return "Hello from ${name}"\n}`,
|
|
postgresql: `-- ${name}\nSELECT 'Hello from ${name}';`,
|
|
};
|
|
|
|
return {
|
|
contentFile: {
|
|
path: `${name}${ext}`,
|
|
content: content ?? defaultContent[language],
|
|
},
|
|
metadataFile: {
|
|
path: `${name}.script.yaml`,
|
|
content: `summary: "${name} script"
|
|
description: "A ${language} script for testing"
|
|
schema:
|
|
$schema: "https://json-schema.org/draft/2020-12/schema"
|
|
type: object
|
|
properties: {}
|
|
required: []
|
|
is_template: false
|
|
lock: ""
|
|
kind: script
|
|
`,
|
|
},
|
|
};
|
|
}
|
|
|
|
// =============================================================================
|
|
// Flow Fixtures
|
|
// =============================================================================
|
|
|
|
/**
|
|
* Creates a flow fixture (data structure, no disk I/O).
|
|
* See file header for cross-links to related helpers.
|
|
*
|
|
* TODO: Add optional params: language, summary, description
|
|
*
|
|
* Use this when you need fine-grained control over the flow structure.
|
|
* For simple cases, use {@link createLocalFlow} instead.
|
|
*
|
|
* @param name - Flow name
|
|
* @param inlineScriptContent - Optional custom inline script content
|
|
* @returns Flow fixture with metadata and inline script
|
|
*
|
|
* @example
|
|
* const fixture = createFlowFixture("my_flow");
|
|
*
|
|
* @keywords flow fixture, create flow, local flow
|
|
*/
|
|
export function createFlowFixture(
|
|
name: string,
|
|
inlineScriptContent?: string
|
|
): FlowFixture {
|
|
const flowSuffix = getFolderSuffix("flow");
|
|
const metadataFile = getMetadataFileName("flow", "yaml");
|
|
|
|
const scriptContent =
|
|
inlineScriptContent ??
|
|
`export async function main() {\n return "Hello from flow ${name}";\n}`;
|
|
|
|
return {
|
|
metadata: {
|
|
path: `${name}${flowSuffix}/${metadataFile}`,
|
|
content: `summary: "${name} flow"
|
|
description: "A flow for testing"
|
|
value:
|
|
modules:
|
|
- id: a
|
|
value:
|
|
type: rawscript
|
|
content: |
|
|
${scriptContent.split("\n").join("\n ")}
|
|
language: bun
|
|
input_transforms: {}
|
|
schema:
|
|
$schema: "https://json-schema.org/draft/2020-12/schema"
|
|
type: object
|
|
properties: {}
|
|
required: []
|
|
`,
|
|
},
|
|
inlineScript: {
|
|
path: `${name}${flowSuffix}/a.inline_script.ts`,
|
|
content: scriptContent,
|
|
},
|
|
};
|
|
}
|
|
|
|
// =============================================================================
|
|
// App Fixtures
|
|
// =============================================================================
|
|
|
|
/**
|
|
* Creates an app fixture (data structure, no disk I/O).
|
|
* See file header for cross-links to related helpers.
|
|
*
|
|
* TODO: Add optional params: inlineScriptContent, summary, grid
|
|
*
|
|
* Use this when you need fine-grained control over the app structure.
|
|
* For simple cases, use {@link createLocalApp} instead.
|
|
*
|
|
* @param name - App name
|
|
* @returns App fixture with metadata
|
|
*
|
|
* @example
|
|
* const fixture = createAppFixture("my_app");
|
|
*
|
|
* @keywords app fixture, create app, local app
|
|
*/
|
|
export function createAppFixture(name: string): AppFixture {
|
|
const appSuffix = getFolderSuffix("app");
|
|
const metadataFile = getMetadataFileName("app", "yaml");
|
|
|
|
return {
|
|
metadata: {
|
|
path: `${name}${appSuffix}/${metadataFile}`,
|
|
content: `summary: "${name} app"
|
|
value:
|
|
type: app
|
|
grid:
|
|
- id: button1
|
|
data:
|
|
type: buttoncomponent
|
|
componentInput:
|
|
type: runnable
|
|
runnable:
|
|
type: runnableByName
|
|
inlineScript:
|
|
content: |
|
|
export async function main() {
|
|
return "hello from app";
|
|
}
|
|
language: bun
|
|
hiddenInlineScripts: []
|
|
css: {}
|
|
norefreshbar: false
|
|
policy:
|
|
on_behalf_of: null
|
|
on_behalf_of_email: null
|
|
triggerables: {}
|
|
execution_mode: viewer
|
|
`,
|
|
},
|
|
};
|
|
}
|
|
|
|
// =============================================================================
|
|
// Raw App Fixtures
|
|
// =============================================================================
|
|
|
|
/**
|
|
* Creates a raw app fixture (data structure, no disk I/O).
|
|
* See file header for cross-links to related helpers.
|
|
*
|
|
* TODO: Add optional params: inlineScriptContent, htmlContent, jsContent
|
|
*
|
|
* Raw apps are React/frontend apps with separate inline scripts.
|
|
* Use this when you need fine-grained control over the raw app structure.
|
|
* For simple cases, use {@link createLocalRawApp} instead.
|
|
*
|
|
* @param name - Raw app name
|
|
* @returns Raw app fixture with metadata and frontend files
|
|
*
|
|
* @example
|
|
* const fixture = createRawAppFixture("my_raw_app");
|
|
*
|
|
* @keywords raw app fixture, create raw app, local raw app, react app
|
|
*/
|
|
export function createRawAppFixture(name: string): RawAppFixture {
|
|
const rawAppSuffix = getFolderSuffix("raw_app");
|
|
const metadataFile = getMetadataFileName("raw_app", "yaml");
|
|
|
|
return {
|
|
metadata: {
|
|
path: `${name}${rawAppSuffix}/${metadataFile}`,
|
|
content: `summary: "${name} raw app"
|
|
policy:
|
|
execution_mode: publisher
|
|
triggerables: {}
|
|
`,
|
|
},
|
|
indexHtml: {
|
|
path: `${name}${rawAppSuffix}/index.html`,
|
|
content: `<!DOCTYPE html>
|
|
<html>
|
|
<head><title>${name}</title></head>
|
|
<body><div id="root"></div></body>
|
|
</html>`,
|
|
},
|
|
indexJs: {
|
|
path: `${name}${rawAppSuffix}/index.tsx`,
|
|
content: `import React from 'react'
|
|
import { createRoot } from 'react-dom/client'
|
|
|
|
const App = () => <div><h1>${name}</h1></div>
|
|
|
|
const root = createRoot(document.getElementById('root')!)
|
|
root.render(<App/>)
|
|
`,
|
|
},
|
|
packageJson: {
|
|
path: `${name}${rawAppSuffix}/package.json`,
|
|
content: `{
|
|
"dependencies": {
|
|
"react": "19.0.0",
|
|
"react-dom": "19.0.0"
|
|
}
|
|
}`,
|
|
},
|
|
inlineScript: {
|
|
path: `${name}${rawAppSuffix}/inline_scripts/a.inline_script.ts`,
|
|
content: `export async function main(x: string) {
|
|
return x
|
|
}
|
|
`,
|
|
},
|
|
inlineScriptLock: {
|
|
path: `${name}${rawAppSuffix}/inline_scripts/a.inline_script.lock`,
|
|
content: ``,
|
|
},
|
|
};
|
|
}
|
|
|
|
// =============================================================================
|
|
// Local Creation Functions (Fixture + Write to Disk)
|
|
// =============================================================================
|
|
|
|
/**
|
|
* Creates a script on the local filesystem.
|
|
* See file header for cross-links to related helpers.
|
|
*
|
|
* This is a convenience function that creates a script fixture and writes it to disk.
|
|
*
|
|
* @param tempDir - Base directory for the test workspace
|
|
* @param path - Relative path within the workspace (e.g., "f/test")
|
|
* @param name - Script name (without extension)
|
|
* @param language - Script language (default: "bun")
|
|
* @param content - Optional custom script content
|
|
*
|
|
* @example
|
|
* await createLocalScript(tempDir, "f/test", "my_script");
|
|
* await createLocalScript(tempDir, "f/test", "custom", "python3", "def main(): return 42");
|
|
*
|
|
* @keywords create local script, local script, write script, script on disk
|
|
*/
|
|
export async function createLocalScript(
|
|
tempDir: string,
|
|
path: string,
|
|
name: string,
|
|
language: "python3" | "deno" | "bun" | "bash" | "go" | "postgresql" = "bun",
|
|
content?: string
|
|
): Promise<void> {
|
|
const fixture = createScriptFixture(name, language, content);
|
|
await mkdir(`${tempDir}/${path}`, { recursive: true });
|
|
await writeFile(
|
|
`${tempDir}/${path}/${fixture.contentFile.path}`,
|
|
fixture.contentFile.content,
|
|
"utf-8"
|
|
);
|
|
await writeFile(
|
|
`${tempDir}/${path}/${fixture.metadataFile.path}`,
|
|
fixture.metadataFile.content,
|
|
"utf-8"
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Creates a flow on the local filesystem.
|
|
* See file header for cross-links to related helpers.
|
|
*
|
|
* This is a convenience function that creates a flow fixture and writes it to disk.
|
|
*
|
|
* @param tempDir - Base directory for the test workspace
|
|
* @param path - Relative path within the workspace (e.g., "f/test")
|
|
* @param name - Flow name
|
|
* @param inlineScriptContent - Optional custom inline script content
|
|
*
|
|
* @example
|
|
* await createLocalFlow(tempDir, "f/test", "my_flow");
|
|
*
|
|
* @keywords create local flow, local flow, write flow, flow on disk
|
|
*/
|
|
export async function createLocalFlow(
|
|
tempDir: string,
|
|
path: string,
|
|
name: string,
|
|
inlineScriptContent?: string
|
|
): Promise<void> {
|
|
const fixture = createFlowFixture(name, inlineScriptContent);
|
|
const flowDir = `${tempDir}/${path}/${name}${getFolderSuffix("flow")}`;
|
|
await mkdir(flowDir, { recursive: true });
|
|
|
|
for (const file of Object.values(fixture)) {
|
|
const fullPath = `${tempDir}/${path}/${file.path}`;
|
|
await writeFile(fullPath, file.content, "utf-8");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates an app on the local filesystem.
|
|
* See file header for cross-links to related helpers.
|
|
*
|
|
* This is a convenience function that creates an app fixture and writes it to disk.
|
|
*
|
|
* @param tempDir - Base directory for the test workspace
|
|
* @param path - Relative path within the workspace (e.g., "f/test")
|
|
* @param name - App name
|
|
*
|
|
* @example
|
|
* await createLocalApp(tempDir, "f/test", "my_app");
|
|
*
|
|
* @keywords create local app, local app, write app, app on disk
|
|
*/
|
|
export async function createLocalApp(
|
|
tempDir: string,
|
|
path: string,
|
|
name: string
|
|
): Promise<void> {
|
|
const fixture = createAppFixture(name);
|
|
const appDir = `${tempDir}/${path}/${name}${getFolderSuffix("app")}`;
|
|
await mkdir(appDir, { recursive: true });
|
|
|
|
for (const file of Object.values(fixture)) {
|
|
const fullPath = `${tempDir}/${path}/${file.path}`;
|
|
await writeFile(fullPath, file.content, "utf-8");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a raw app on the local filesystem.
|
|
* See file header for cross-links to related helpers.
|
|
*
|
|
* Raw apps are React/frontend apps with separate inline scripts.
|
|
* This is a convenience function that creates a raw app fixture and writes it to disk.
|
|
*
|
|
* @param tempDir - Base directory for the test workspace
|
|
* @param path - Relative path within the workspace (e.g., "f/test")
|
|
* @param name - Raw app name
|
|
*
|
|
* @example
|
|
* await createLocalRawApp(tempDir, "f/test", "my_raw_app");
|
|
*
|
|
* @keywords create local raw app, local raw app, write raw app, raw app on disk, react app
|
|
*/
|
|
export async function createLocalRawApp(
|
|
tempDir: string,
|
|
path: string,
|
|
name: string
|
|
): Promise<void> {
|
|
const fixture = createRawAppFixture(name);
|
|
const rawAppSuffix = getFolderSuffix("raw_app");
|
|
const appDir = `${tempDir}/${path}/${name}${rawAppSuffix}`;
|
|
await mkdir(`${appDir}/inline_scripts`, { recursive: true });
|
|
|
|
for (const file of Object.values(fixture)) {
|
|
const fullPath = `${tempDir}/${path}/${file.path}`;
|
|
const dir = fullPath.substring(0, fullPath.lastIndexOf("/"));
|
|
await mkdir(dir, { recursive: true });
|
|
await writeFile(fullPath, file.content, "utf-8");
|
|
}
|
|
}
|
|
|
|
// =============================================================================
|
|
// Script with Modules Fixtures
|
|
// =============================================================================
|
|
|
|
export interface ModuleFile {
|
|
path: string;
|
|
content: string;
|
|
lock?: string;
|
|
}
|
|
|
|
/**
|
|
* Creates a script with module files on the local filesystem.
|
|
*
|
|
* Creates the main script, its metadata, and module files in a __mod/ folder.
|
|
* Optionally includes lock files for modules.
|
|
*
|
|
* @param tempDir - Base directory for the test workspace
|
|
* @param dir - Relative path within the workspace (e.g., "f/test")
|
|
* @param name - Script name (without extension)
|
|
* @param language - Script language (default: "bun")
|
|
* @param modules - Module files to create
|
|
*
|
|
* @example
|
|
* await createLocalScriptWithModules(tempDir, "f/test", "my_script", "bun", [
|
|
* { path: "helper.ts", content: "export const x = 1;" },
|
|
* { path: "utils/math.ts", content: "export function add(a, b) { return a + b; }", lock: "lodash@4.0.0\n" },
|
|
* ]);
|
|
*/
|
|
export async function createLocalScriptWithModules(
|
|
tempDir: string,
|
|
dir: string,
|
|
name: string,
|
|
language: "python3" | "deno" | "bun" | "bash" | "go" | "postgresql" = "bun",
|
|
modules: ModuleFile[]
|
|
): Promise<void> {
|
|
// Create the main script
|
|
await createLocalScript(tempDir, dir, name, language);
|
|
|
|
// Create module files in __mod/ folder
|
|
const modSuffix = getModuleFolderSuffix();
|
|
const modDir = `${tempDir}/${dir}/${name}${modSuffix}`;
|
|
|
|
for (const mod of modules) {
|
|
const fullPath = `${modDir}/${mod.path}`;
|
|
const parentDir = fullPath.substring(0, fullPath.lastIndexOf("/"));
|
|
await mkdir(parentDir, { recursive: true });
|
|
await writeFile(fullPath, mod.content, "utf-8");
|
|
|
|
// Write lock file if provided
|
|
if (mod.lock) {
|
|
const baseName = mod.path.substring(0, mod.path.indexOf("."));
|
|
const lockPath = `${modDir}/${baseName}.lock`;
|
|
const lockDir = lockPath.substring(0, lockPath.lastIndexOf("/"));
|
|
await mkdir(lockDir, { recursive: true });
|
|
await writeFile(lockPath, mod.lock, "utf-8");
|
|
}
|
|
}
|
|
}
|
|
|
|
// =============================================================================
|
|
// Resource Fixtures (Variables, Resources, Schedules, etc.)
|
|
// =============================================================================
|
|
|
|
/**
|
|
* Creates a resource fixture.
|
|
*
|
|
* @keywords resource fixture, create resource
|
|
*/
|
|
export function createResourceFixture(
|
|
name: string,
|
|
resourceType: string,
|
|
value: Record<string, unknown>
|
|
): FileFixture {
|
|
return {
|
|
path: `${name}.resource.yaml`,
|
|
content: `resource_type: "${resourceType}"
|
|
value:
|
|
${Object.entries(value)
|
|
.map(([k, v]) => ` ${k}: ${JSON.stringify(v)}`)
|
|
.join("\n")}
|
|
`,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a variable fixture.
|
|
*
|
|
* @keywords variable fixture, create variable
|
|
*/
|
|
export function createVariableFixture(
|
|
name: string,
|
|
value: string,
|
|
isSecret: boolean = false
|
|
): FileFixture {
|
|
return {
|
|
path: `${name}.variable.yaml`,
|
|
content: `value: "${value}"
|
|
is_secret: ${isSecret}
|
|
description: "Variable ${name} for testing"
|
|
`,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a schedule fixture.
|
|
*
|
|
* @keywords schedule fixture, create schedule
|
|
*/
|
|
export function createScheduleFixture(
|
|
name: string,
|
|
scriptPath: string,
|
|
schedule: string = "0 * * * *"
|
|
): FileFixture {
|
|
return {
|
|
path: `${name}.schedule.yaml`,
|
|
content: `path: "${name}"
|
|
schedule: "${schedule}"
|
|
script_path: "${scriptPath}"
|
|
is_flow: false
|
|
args: {}
|
|
enabled: true
|
|
timezone: "UTC"
|
|
`,
|
|
};
|
|
}
|