Files
windmill/cli/test/folder_schedule_push.test.ts
Ruben Fiszel a2cefdf0a2 refactor(cli): migrate CLI from Deno to Bun/Node.js (#8041)
* 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>
2026-02-21 21:19:04 +00:00

410 lines
13 KiB
TypeScript

/**
* Integration tests for folder and schedule CLI commands.
* Tests list and push operations via CLI and direct API.
*/
import { expect, test, describe } from "bun:test";
import { writeFile, mkdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import { withTestBackend } from "./test_backend.ts";
import { addWorkspace } from "../workspace.ts";
async function setupWorkspaceProfile(backend: any): Promise<void> {
await addWorkspace(
{
remote: backend.baseUrl,
workspaceId: backend.workspace,
name: "localhost_test",
token: backend.token,
},
{ force: true, configDir: backend.testConfigDir }
);
}
// =============================================================================
// Folder Tests
// =============================================================================
describe("folder", () => {
test("list returns seeded folders", async () => {
await withTestBackend(async (backend, tempDir) => {
await setupWorkspaceProfile(backend);
const result = await backend.runCLICommand(["folder"], tempDir);
expect(result.code).toEqual(0);
// seedTestData creates "test" folder
expect(result.stdout).toContain("test");
});
});
test("push creates a new folder via sync push", async () => {
await withTestBackend(async (backend, tempDir) => {
await setupWorkspaceProfile(backend);
const uniqueId = Date.now();
const folderName = `inttest${uniqueId}`;
// Create wmill.yaml
await writeFile(
join(tempDir, "wmill.yaml"),
`defaultTs: bun\nincludes:\n - "**"\nexcludes: []\n`,
"utf-8"
);
// Create folder meta file
await mkdir(join(tempDir, "f", folderName), { recursive: true });
await writeFile(
join(tempDir, "f", folderName, "folder.meta.yaml"),
`display_name: "Integration Test Folder ${uniqueId}"\nowners:\n - "admin@windmill.dev"\nextra_perms: {}\n`,
"utf-8"
);
// Push
const pushResult = await backend.runCLICommand(
["sync", "push", "--yes", "--includes", `f/${folderName}/**`],
tempDir
);
expect(pushResult.code).toEqual(0);
// Verify folder was created via API
const apiResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/folders/get/${folderName}`
);
expect(apiResp.status).toEqual(200);
const folderData = await apiResp.json();
expect(folderData.name).toBe(folderName);
});
});
test("push updates an existing folder", async () => {
await withTestBackend(async (backend, tempDir) => {
await setupWorkspaceProfile(backend);
const uniqueId = Date.now();
const folderName = `updfolder${uniqueId}`;
// Create folder via API
const createResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/folders/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: folderName }),
}
);
expect(createResp.status).toBeLessThan(300);
await createResp.text();
// Create wmill.yaml and updated folder meta
await writeFile(
join(tempDir, "wmill.yaml"),
`defaultTs: bun\nincludes:\n - "**"\nexcludes: []\n`,
"utf-8"
);
await mkdir(join(tempDir, "f", folderName), { recursive: true });
await writeFile(
join(tempDir, "f", folderName, "folder.meta.yaml"),
`display_name: "Updated Display Name"\nowners:\n - "u/admin"\nextra_perms:\n u/admin: true\n`,
"utf-8"
);
// Push the update
const pushResult = await backend.runCLICommand(
["sync", "push", "--yes", "--includes", `f/${folderName}/**`],
tempDir
);
expect(pushResult.code).toEqual(0);
// Verify the display_name was updated
const apiResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/folders/get/${folderName}`
);
expect(apiResp.status).toEqual(200);
const folderData = await apiResp.json();
expect(folderData.display_name).toBe("Updated Display Name");
});
});
test("pull retrieves folder metadata", async () => {
await withTestBackend(async (backend, tempDir) => {
await setupWorkspaceProfile(backend);
const uniqueId = Date.now();
const folderName = `pullfolder${uniqueId}`;
// Create folder via API
const createResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/folders/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: folderName }),
}
);
expect(createResp.status).toBeLessThan(300);
await createResp.text();
// Create wmill.yaml
await writeFile(
join(tempDir, "wmill.yaml"),
`defaultTs: bun\nincludes:\n - "f/${folderName}/**"\nexcludes: []\nskipVariables: true\nskipResources: true\n`,
"utf-8"
);
// Pull
const pullResult = await backend.runCLICommand(
["sync", "pull", "--yes"],
tempDir
);
expect(pullResult.code).toEqual(0);
// Check the folder meta file was created
const content = await readFile(
join(tempDir, "f", folderName, "folder.meta.yaml"), "utf-8"
);
expect(content).toBeDefined();
});
});
});
// =============================================================================
// Schedule Tests
// =============================================================================
describe("schedule", () => {
test("list returns empty table for fresh workspace", async () => {
await withTestBackend(async (backend, tempDir) => {
await setupWorkspaceProfile(backend);
const result = await backend.runCLICommand(["schedule"], tempDir);
expect(result.code).toEqual(0);
// Table headers should be present
expect(result.stdout).toContain("Path");
expect(result.stdout).toContain("Schedule");
});
});
test("push creates a schedule targeting an existing script", async () => {
await withTestBackend(async (backend, tempDir) => {
await setupWorkspaceProfile(backend);
const uniqueId = Date.now();
// First create a script that the schedule can target
const scriptResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/scripts/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
path: `f/test/sched_target_${uniqueId}`,
content: 'export async function main() { return "ok"; }',
language: "bun",
summary: "Schedule target script",
description: "",
schema: {
$schema: "https://json-schema.org/draft/2020-12/schema",
type: "object",
properties: {},
required: [],
},
}),
}
);
expect(scriptResp.status).toBeLessThan(300);
await scriptResp.text();
// Create wmill.yaml with includeSchedules
await writeFile(
join(tempDir, "wmill.yaml"),
`defaultTs: bun\nincludes:\n - "**"\nexcludes: []\nincludeSchedules: true\n`,
"utf-8"
);
// Create schedule file
await mkdir(join(tempDir, "f", "test"), { recursive: true });
await writeFile(
join(tempDir, `f/test/cron_${uniqueId}.schedule.yaml`),
`path: "f/test/cron_${uniqueId}"\nschedule: "0 0 */6 * * *"\nscript_path: "f/test/sched_target_${uniqueId}"\nis_flow: false\nargs: {}\nenabled: false\ntimezone: "UTC"\n`,
"utf-8"
);
// Push
const pushResult = await backend.runCLICommand(
["sync", "push", "--yes", "--includes", `f/test/cron_${uniqueId}**`],
tempDir
);
expect(pushResult.code).toEqual(0);
// Verify via API
const apiResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/schedules/get/f/test/cron_${uniqueId}`
);
expect(apiResp.status).toEqual(200);
const schedData = await apiResp.json();
expect(schedData.schedule).toBe("0 0 */6 * * *");
expect(schedData.script_path).toBe(`f/test/sched_target_${uniqueId}`);
expect(schedData.enabled).toBe(false);
});
});
test("push updates a schedule's cron expression", async () => {
await withTestBackend(async (backend, tempDir) => {
await setupWorkspaceProfile(backend);
const uniqueId = Date.now();
// Create target script via API
const scriptResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/scripts/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
path: `f/test/upd_sched_target_${uniqueId}`,
content: 'export async function main() { return "ok"; }',
language: "bun",
summary: "Target",
description: "",
schema: {
$schema: "https://json-schema.org/draft/2020-12/schema",
type: "object",
properties: {},
required: [],
},
}),
}
);
expect(scriptResp.status).toBeLessThan(300);
await scriptResp.text();
// Create schedule via API
const createResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/schedules/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
path: `f/test/upd_cron_${uniqueId}`,
schedule: "0 0 * * * *",
script_path: `f/test/upd_sched_target_${uniqueId}`,
is_flow: false,
args: {},
enabled: false,
timezone: "UTC",
}),
}
);
expect(createResp.status).toBeLessThan(300);
await createResp.text();
// Create wmill.yaml with includeSchedules and updated schedule
await writeFile(
join(tempDir, "wmill.yaml"),
`defaultTs: bun\nincludes:\n - "**"\nexcludes: []\nincludeSchedules: true\n`,
"utf-8"
);
await mkdir(join(tempDir, "f", "test"), { recursive: true });
await writeFile(
join(tempDir, `f/test/upd_cron_${uniqueId}.schedule.yaml`),
`path: "f/test/upd_cron_${uniqueId}"\nschedule: "0 30 2 * * *"\nscript_path: "f/test/upd_sched_target_${uniqueId}"\nis_flow: false\nargs: {}\nenabled: false\ntimezone: "UTC"\n`,
"utf-8"
);
// Push the update
const pushResult = await backend.runCLICommand(
["sync", "push", "--yes", "--includes", `f/test/upd_cron_${uniqueId}**`],
tempDir
);
expect(pushResult.code).toEqual(0);
// Verify the schedule was updated
const apiResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/schedules/get/f/test/upd_cron_${uniqueId}`
);
expect(apiResp.status).toEqual(200);
const schedData = await apiResp.json();
expect(schedData.schedule).toBe("0 30 2 * * *");
});
});
test("pull retrieves schedules into local files", async () => {
await withTestBackend(async (backend, tempDir) => {
await setupWorkspaceProfile(backend);
const uniqueId = Date.now();
// Create target script via API
const scriptResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/scripts/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
path: `f/test/pull_sched_target_${uniqueId}`,
content: 'export async function main() { return "ok"; }',
language: "bun",
summary: "Target for pull test",
description: "",
schema: {
$schema: "https://json-schema.org/draft/2020-12/schema",
type: "object",
properties: {},
required: [],
},
}),
}
);
expect(scriptResp.status).toBeLessThan(300);
await scriptResp.text();
// Create schedule via API
const createResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/schedules/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
path: `f/test/pull_cron_${uniqueId}`,
schedule: "0 15 3 * * 1",
script_path: `f/test/pull_sched_target_${uniqueId}`,
is_flow: false,
args: {},
enabled: false,
timezone: "UTC",
}),
}
);
expect(createResp.status).toBeLessThan(300);
await createResp.text();
// Create wmill.yaml
await writeFile(
join(tempDir, "wmill.yaml"),
`defaultTs: bun\nincludes:\n - "f/test/pull_cron_${uniqueId}**"\nexcludes: []\nincludeSchedules: true\nskipVariables: true\nskipResources: true\nskipScripts: true\n`,
"utf-8"
);
// Pull
const pullResult = await backend.runCLICommand(
["sync", "pull", "--yes"],
tempDir
);
expect(pullResult.code).toEqual(0);
// Check the schedule file was created
const content = await readFile(
join(tempDir, `f/test/pull_cron_${uniqueId}.schedule.yaml`), "utf-8"
);
expect(content).toContain("0 15 3 * * 1");
expect(content).toContain(`f/test/pull_sched_target_${uniqueId}`);
});
});
});