Files
windmill/cli/test/settings_unit.test.ts
T
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

198 lines
6.1 KiB
TypeScript

/**
* Unit tests for settings.ts pure functions.
* Tests migrateToGroupedFormat which converts legacy flat settings to grouped format.
*/
import { expect, test, describe } from "bun:test";
import { migrateToGroupedFormat } from "../src/core/settings.ts";
// =============================================================================
// migrateToGroupedFormat
// =============================================================================
describe("migrateToGroupedFormat", () => {
test("migrates legacy auto_invite fields to grouped format", () => {
const legacy = {
name: "my-workspace",
auto_invite_enabled: true,
auto_invite_as: "operator",
auto_invite_mode: "add",
};
const result = migrateToGroupedFormat(legacy);
expect(result.auto_invite).toEqual({
enabled: true,
operator: true,
mode: "add",
});
});
test("migrates legacy auto_invite with non-operator role", () => {
const legacy = {
name: "ws",
auto_invite_enabled: true,
auto_invite_as: "developer",
auto_invite_mode: "invite",
};
const result = migrateToGroupedFormat(legacy);
expect(result.auto_invite).toEqual({
enabled: true,
operator: false,
mode: "invite",
});
});
test("migrates legacy auto_invite when disabled", () => {
const legacy = {
name: "ws",
auto_invite_enabled: false,
auto_invite_as: "operator",
};
const result = migrateToGroupedFormat(legacy);
expect(result.auto_invite!.enabled).toBe(false);
});
test("preserves already-grouped auto_invite", () => {
const grouped = {
name: "ws",
auto_invite: { enabled: true, operator: false, mode: "invite" as const },
};
const result = migrateToGroupedFormat(grouped);
expect(result.auto_invite).toEqual({
enabled: true,
operator: false,
mode: "invite",
});
});
test("migrates legacy error_handler string to grouped format", () => {
const legacy = {
name: "ws",
error_handler: "u/admin/error_handler",
error_handler_extra_args: { notify: true },
error_handler_muted_on_cancel: true,
};
const result = migrateToGroupedFormat(legacy);
expect(result.error_handler).toEqual({
path: "u/admin/error_handler",
extra_args: { notify: true },
muted_on_cancel: true,
});
});
test("preserves already-grouped error_handler", () => {
const grouped = {
name: "ws",
error_handler: {
path: "u/admin/handler",
extra_args: {},
muted_on_cancel: false,
},
};
const result = migrateToGroupedFormat(grouped);
expect(result.error_handler).toEqual({
path: "u/admin/handler",
extra_args: {},
muted_on_cancel: false,
});
});
test("migrates legacy success_handler string to grouped format", () => {
const legacy = {
name: "ws",
success_handler: "u/admin/on_success",
success_handler_extra_args: { channel: "#deploys" },
};
const result = migrateToGroupedFormat(legacy);
expect(result.success_handler).toEqual({
path: "u/admin/on_success",
extra_args: { channel: "#deploys" },
});
});
test("preserves already-grouped success_handler", () => {
const grouped = {
name: "ws",
success_handler: { path: "u/admin/handler", extra_args: {} },
};
const result = migrateToGroupedFormat(grouped);
expect(result.success_handler).toEqual({
path: "u/admin/handler",
extra_args: {},
});
});
test("copies non-legacy fields through", () => {
const settings = {
name: "my-workspace",
webhook: "https://example.com/hook",
deploy_to: "staging",
default_app: "u/admin/dashboard",
mute_critical_alerts: true,
color: "#ff0000",
};
const result = migrateToGroupedFormat(settings);
expect(result.name).toBe("my-workspace");
expect(result.webhook).toBe("https://example.com/hook");
expect(result.deploy_to).toBe("staging");
expect(result.default_app).toBe("u/admin/dashboard");
expect(result.mute_critical_alerts).toBe(true);
expect(result.color).toBe("#ff0000");
});
test("handles minimal settings with only name", () => {
const result = migrateToGroupedFormat({ name: "ws" });
expect(result.name).toBe("ws");
expect(result.auto_invite).toBeUndefined();
expect(result.error_handler).toBeUndefined();
expect(result.success_handler).toBeUndefined();
});
test("defaults name to empty string when missing", () => {
const result = migrateToGroupedFormat({});
expect(result.name).toBe("");
});
test("defaults auto_invite_mode to invite when missing", () => {
const legacy = {
name: "ws",
auto_invite_enabled: true,
auto_invite_as: "operator",
};
const result = migrateToGroupedFormat(legacy);
expect(result.auto_invite!.mode).toBe("invite");
});
test("defaults error_handler_muted_on_cancel to false when missing", () => {
const legacy = {
name: "ws",
error_handler: "u/admin/handler",
};
const result = migrateToGroupedFormat(legacy);
expect(result.error_handler!.muted_on_cancel).toBe(false);
});
test("preserves ai_config, large_file_storage, git_sync, default_scripts, operator_settings", () => {
const settings = {
name: "ws",
ai_config: { provider: "openai" },
large_file_storage: { type: "s3" },
git_sync: { enabled: true },
default_scripts: { python: "template.py" },
operator_settings: { hideCode: true },
};
const result = migrateToGroupedFormat(settings);
expect(result.ai_config).toEqual({ provider: "openai" });
expect(result.large_file_storage).toEqual({ type: "s3" });
expect(result.git_sync).toEqual({ enabled: true });
expect(result.default_scripts).toEqual({ python: "template.py" });
expect(result.operator_settings).toEqual({ hideCode: true });
});
test("does not include undefined fields in result", () => {
const result = migrateToGroupedFormat({ name: "ws" });
expect("webhook" in result).toBe(false);
expect("deploy_to" in result).toBe(false);
expect("color" in result).toBe(false);
});
});