* fix: only enable EE features in test backend when license key is available Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: skip EE tests without license key and exclude test-skills from test discovery Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: unskip passing tests and add duplicate (remote, workspaceId) check in addWorkspace Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor(cli): migrate from Deno APIs to Node.js/Bun-compatible APIs Replace Deno-specific APIs with Node.js equivalents across the entire CLI codebase to enable running on Node.js/Bun. Switch build system from dnt to bun, update imports from jsr:/npm: prefixed to bare specifiers, and add package.json/tsconfig.json for the Node.js ecosystem. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * all * test(cli): expand test coverage with new integration and unit tests Add standalone_commands.test.ts covering folder list, schedule list, resource-type list/push/update, script show/run/bootstrap, and user commands. Add unit tests for filePathExtensionFromContentType and removeExtensionToPath. Add git_unit, local_encryption_unit, resource_folders_unit, and settings_unit test files. Fix schedule cron expressions (6-field format), add includeSchedules flag, improve test setup with pre-build and auto-cleanup, and support TEST_CLI_RUNTIME=node. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): replace Deno.readFile with node:fs in WASM loaders and add schema parsing tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(cli): switch WASM parsers from local files to npm packages Use published windmill-parser-wasm-* npm packages instead of local wasm/ files. A loadParser() helper uses createRequire to resolve the .wasm binary from node_modules and passes it to init() via readFileSync, avoiding fetch() and Deno.readFile() patches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test(cli): add coverage for --locks-required lint feature Add 15 tests covering the lock-checking functionality merged from main: - checkMissingLocks: standalone scripts (python, bun, bash), inline lock file resolution (valid, empty, missing), flow inline rawscripts (with/without locks, nested forloopflow), app inline scripts, raw apps without backend folder - runLint --locks-required integration: reports issues when locks missing, skips checks when flag absent, passes when locks exist Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci(cli): replace Deno with Bun in CI workflows - cli-tests.yml: remove Deno setup, use `bun test` instead of `deno test`, add `bun install` step for dependency installation - npm_on_release.yml: replace Deno setup with Bun setup for CLI publishing - build.sh: add `bun install` before building so CI has dependencies Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): pre-start backend in test preload and remove Deno test leftovers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): normalize path separators for Windows compatibility Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * more tests + windows * ci(cli): use Blacksmith runner for Windows tests Switch test-windows job from windows-latest to blacksmith-16vcpu-windows-2025 for faster CI execution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): fix Windows path separator expectations in unit tests buildMetadataPath and extractResourceName normalize to forward slashes internally, so tests should not expect platform-specific separators in their output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): fix Windows CI test failures for dev_server and script_run Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): set BUN_PATH and NODE_BIN_PATH for backend worker on Windows Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci(cli): add SSH debug step on Windows test failure Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): use native path separators for ignore check in dev mode on Windows Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
257 lines
8.7 KiB
TypeScript
257 lines
8.7 KiB
TypeScript
/**
|
|
* Script envs sync test
|
|
*
|
|
* Tests that script metadata envs field is correctly preserved during sync push.
|
|
* Reproduces issue: env variables set in metadata of scripts don't work correctly
|
|
* if created by API, then sync pulled, then script modified, then sync push,
|
|
* the env variables aren't there anymore.
|
|
*/
|
|
|
|
import { expect, test } from "bun:test";
|
|
import { writeFile, readFile, mkdir } from "node:fs/promises";
|
|
import { withTestBackend } from "./test_backend.ts";
|
|
|
|
test("Integration: Script envs field is preserved during sync pull/push cycle", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
const uniqueId = Date.now();
|
|
const scriptPath = `f/test/envs_script_${uniqueId}`;
|
|
|
|
// Step 1: Create a script via API with envs set
|
|
await mkdir(`${tempDir}/f/test`, { recursive: true });
|
|
|
|
// Create folder first
|
|
const folderResp = await backend.apiRequest!(`/api/w/${backend.workspace}/folders/create`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ name: "test" }),
|
|
});
|
|
// Ignore error if folder already exists
|
|
|
|
// Create a script with envs via API
|
|
const createResp = await backend.apiRequest!(`/api/w/${backend.workspace}/scripts/create`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
path: scriptPath,
|
|
content: `export async function main() {\n return "Hello world";\n}`,
|
|
summary: "Test script with envs",
|
|
description: "A script to test envs preservation",
|
|
language: "bun",
|
|
envs: ["MY_ENV_VAR", "ANOTHER_VAR"],
|
|
kind: "script",
|
|
}),
|
|
});
|
|
|
|
expect(createResp.ok).toEqual(true);
|
|
|
|
// Verify the script was created with envs
|
|
const getResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/scripts/get/p/${scriptPath}`,
|
|
);
|
|
const createdScriptText = await getResp.text();
|
|
expect(getResp.ok).toEqual(true);
|
|
const createdScript = JSON.parse(createdScriptText);
|
|
expect(createdScript.envs).toEqual(["MY_ENV_VAR", "ANOTHER_VAR"]);
|
|
|
|
// Step 2: Create wmill.yaml and sync pull
|
|
await writeFile(
|
|
`${tempDir}/wmill.yaml`,
|
|
`defaultTs: bun
|
|
includes:
|
|
- "f/test/envs_script_${uniqueId}**"
|
|
excludes: []
|
|
`,
|
|
"utf-8",
|
|
);
|
|
|
|
const pullResult = await backend.runCLICommand(["sync", "pull", "--yes"], tempDir);
|
|
expect(pullResult.code).toEqual(0);
|
|
|
|
// Verify the pulled metadata contains envs
|
|
const metadataPath = `${tempDir}/f/test/envs_script_${uniqueId}.script.yaml`;
|
|
const metadataContent = await readFile(metadataPath, "utf-8");
|
|
expect(
|
|
metadataContent.includes("envs:") ||
|
|
metadataContent.includes("MY_ENV_VAR") ||
|
|
metadataContent.includes("ANOTHER_VAR"),
|
|
).toBeTruthy();
|
|
|
|
// Step 3: Modify the script locally (change content)
|
|
const scriptFilePath = `${tempDir}/f/test/envs_script_${uniqueId}.ts`;
|
|
const originalContent = await readFile(scriptFilePath, "utf-8");
|
|
await writeFile(
|
|
scriptFilePath,
|
|
originalContent.replace("Hello world", "Hello world modified"),
|
|
"utf-8",
|
|
);
|
|
|
|
// Step 4: Sync push
|
|
const pushResult = await backend.runCLICommand(["sync", "push", "--yes"], tempDir);
|
|
expect(pushResult.code).toEqual(0);
|
|
|
|
// Step 5: Verify envs are still present on the remote
|
|
const getResp2 = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/scripts/get/p/${scriptPath}`,
|
|
);
|
|
const updatedScriptText = await getResp2.text();
|
|
expect(getResp2.ok).toEqual(true);
|
|
const updatedScript = JSON.parse(updatedScriptText);
|
|
|
|
expect(updatedScript.envs).toEqual(["MY_ENV_VAR", "ANOTHER_VAR"]);
|
|
|
|
// Also verify the content was updated
|
|
expect(
|
|
updatedScript.content.includes("Hello world modified"),
|
|
).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
test("Integration: Script envs field changes are detected and pushed", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
const uniqueId = Date.now();
|
|
const scriptPath = `f/test/envs_change_${uniqueId}`;
|
|
|
|
// Create folder
|
|
await mkdir(`${tempDir}/f/test`, { recursive: true });
|
|
await backend.apiRequest!(`/api/w/${backend.workspace}/folders/create`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ name: "test" }),
|
|
});
|
|
|
|
// Create a script with initial envs
|
|
const createResp = await backend.apiRequest!(`/api/w/${backend.workspace}/scripts/create`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
path: scriptPath,
|
|
content: `export async function main() {\n return "Hello";\n}`,
|
|
summary: "Test envs change",
|
|
description: "",
|
|
language: "bun",
|
|
envs: ["INITIAL_VAR"],
|
|
kind: "script",
|
|
}),
|
|
});
|
|
expect(createResp.ok).toEqual(true);
|
|
|
|
// Setup wmill.yaml
|
|
await writeFile(
|
|
`${tempDir}/wmill.yaml`,
|
|
`defaultTs: bun
|
|
includes:
|
|
- "f/test/envs_change_${uniqueId}**"
|
|
excludes: []
|
|
`,
|
|
"utf-8",
|
|
);
|
|
|
|
// Pull
|
|
const pullResult = await backend.runCLICommand(["sync", "pull", "--yes"], tempDir);
|
|
expect(pullResult.code).toEqual(0);
|
|
|
|
// Modify envs in the local metadata file
|
|
const metadataPath = `${tempDir}/f/test/envs_change_${uniqueId}.script.yaml`;
|
|
let metadataContent = await readFile(metadataPath, "utf-8");
|
|
|
|
// Replace the envs line(s)
|
|
if (metadataContent.includes("envs:")) {
|
|
// Replace existing envs
|
|
metadataContent = metadataContent.replace(
|
|
/envs:\s*\n(\s+-\s+\S+\n?)*/,
|
|
"envs:\n - NEW_VAR1\n - NEW_VAR2\n",
|
|
);
|
|
} else {
|
|
// Add envs if not present
|
|
metadataContent += "\nenvs:\n - NEW_VAR1\n - NEW_VAR2\n";
|
|
}
|
|
await writeFile(metadataPath, metadataContent, "utf-8");
|
|
|
|
// Push
|
|
const pushResult = await backend.runCLICommand(["sync", "push", "--yes"], tempDir);
|
|
expect(pushResult.code).toEqual(0);
|
|
|
|
// Verify envs were updated on remote
|
|
const getResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/scripts/get/p/${scriptPath}`,
|
|
);
|
|
const scriptText = await getResp.text();
|
|
expect(getResp.ok).toEqual(true);
|
|
const script = JSON.parse(scriptText);
|
|
|
|
expect(script.envs).toEqual(["NEW_VAR1", "NEW_VAR2"]);
|
|
});
|
|
});
|
|
|
|
test("Integration: Script with empty envs is handled correctly", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
const uniqueId = Date.now();
|
|
const scriptPath = `f/test/empty_envs_${uniqueId}`;
|
|
|
|
// Create folder
|
|
await mkdir(`${tempDir}/f/test`, { recursive: true });
|
|
await backend.apiRequest!(`/api/w/${backend.workspace}/folders/create`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ name: "test" }),
|
|
});
|
|
|
|
// Create a script WITHOUT envs
|
|
const createResp = await backend.apiRequest!(`/api/w/${backend.workspace}/scripts/create`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
path: scriptPath,
|
|
content: `export async function main() {\n return "No envs";\n}`,
|
|
summary: "Test no envs",
|
|
description: "",
|
|
language: "bun",
|
|
kind: "script",
|
|
}),
|
|
});
|
|
expect(createResp.ok).toEqual(true);
|
|
|
|
// Setup wmill.yaml
|
|
await writeFile(
|
|
`${tempDir}/wmill.yaml`,
|
|
`defaultTs: bun
|
|
includes:
|
|
- "f/test/empty_envs_${uniqueId}**"
|
|
excludes: []
|
|
`,
|
|
"utf-8",
|
|
);
|
|
|
|
// Pull
|
|
const pullResult = await backend.runCLICommand(["sync", "pull", "--yes"], tempDir);
|
|
expect(pullResult.code).toEqual(0);
|
|
|
|
// Modify content
|
|
const scriptFilePath = `${tempDir}/f/test/empty_envs_${uniqueId}.ts`;
|
|
await writeFile(
|
|
scriptFilePath,
|
|
`export async function main() {\n return "Modified no envs";\n}`,
|
|
"utf-8",
|
|
);
|
|
|
|
// Push
|
|
const pushResult = await backend.runCLICommand(["sync", "push", "--yes"], tempDir);
|
|
expect(pushResult.code).toEqual(0);
|
|
|
|
// Verify script was updated and envs is still null/empty
|
|
const getResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/scripts/get/p/${scriptPath}`,
|
|
);
|
|
const script = await getResp.json();
|
|
|
|
expect(
|
|
script.content.includes("Modified no envs"),
|
|
).toBeTruthy();
|
|
|
|
// envs should be null, empty, or undefined
|
|
expect(
|
|
!script.envs || script.envs.length === 0,
|
|
).toBeTruthy();
|
|
});
|
|
});
|