* 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>
200 lines
6.8 KiB
TypeScript
200 lines
6.8 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { addWorkspace, allWorkspaces } from "../workspace.ts";
|
|
import { withTestConfig, clearTestRemotes } from "./test_config_helpers.ts";
|
|
|
|
// Test workspace conflict detection
|
|
test("addWorkspace: prevents duplicate workspace names", async () => {
|
|
await withTestConfig(async (testConfigDir) => {
|
|
await clearTestRemotes(testConfigDir);
|
|
|
|
// Add first workspace
|
|
const workspace1 = {
|
|
name: "test_workspace",
|
|
remote: "http://localhost:8001/",
|
|
workspaceId: "workspace1",
|
|
token: "token1"
|
|
};
|
|
|
|
await addWorkspace(workspace1, { force: true, configDir: testConfigDir });
|
|
|
|
// Try to add workspace with same name but different details
|
|
const workspace2 = {
|
|
name: "test_workspace", // Same name
|
|
remote: "http://localhost:8002/", // Different remote
|
|
workspaceId: "workspace2", // Different ID
|
|
token: "token2"
|
|
};
|
|
|
|
// Force non-interactive mode so addWorkspace throws instead of prompting
|
|
const origStdinTTY = process.stdin.isTTY;
|
|
const origStdoutTTY = process.stdout.isTTY;
|
|
try {
|
|
process.stdin.isTTY = false as any;
|
|
process.stdout.isTTY = false as any;
|
|
|
|
// Should throw error in non-interactive mode without force
|
|
await expect(
|
|
addWorkspace(workspace2, { configDir: testConfigDir })
|
|
).rejects.toThrow("Workspace name conflict. Use --force to overwrite or choose a different name.");
|
|
} finally {
|
|
process.stdin.isTTY = origStdinTTY;
|
|
process.stdout.isTTY = origStdoutTTY;
|
|
}
|
|
|
|
// Should succeed with force flag
|
|
await addWorkspace(workspace2, { force: true, configDir: testConfigDir });
|
|
|
|
// Verify the workspace was overwritten
|
|
const workspaces = await allWorkspaces(testConfigDir);
|
|
expect(workspaces.length).toEqual(1);
|
|
expect(workspaces[0].name).toEqual("test_workspace");
|
|
expect(workspaces[0].remote).toEqual("http://localhost:8002/");
|
|
expect(workspaces[0].workspaceId).toEqual("workspace2");
|
|
});
|
|
});
|
|
|
|
test("addWorkspace: prevents duplicate (remote, workspaceId) tuples", async () => {
|
|
await withTestConfig(async (testConfigDir) => {
|
|
await clearTestRemotes(testConfigDir);
|
|
|
|
// Add first workspace
|
|
const workspace1 = {
|
|
name: "first_workspace",
|
|
remote: "http://localhost:8001/",
|
|
workspaceId: "test",
|
|
token: "token1"
|
|
};
|
|
|
|
await addWorkspace(workspace1, { force: true, configDir: testConfigDir });
|
|
|
|
// Try to add workspace with same (remote, workspaceId) but different name
|
|
const workspace2 = {
|
|
name: "second_workspace", // Different name
|
|
remote: "http://localhost:8001/", // Same remote
|
|
workspaceId: "test", // Same workspaceId
|
|
token: "token2"
|
|
};
|
|
|
|
// Should throw error in non-interactive mode without force
|
|
await expect(
|
|
addWorkspace(workspace2, { configDir: testConfigDir })
|
|
).rejects.toThrow('Backend constraint violation: (http://localhost:8001/, test) already exists as "first_workspace". Use --force to overwrite.');
|
|
|
|
// Should succeed with force flag (overwrites first workspace)
|
|
await addWorkspace(workspace2, { force: true, configDir: testConfigDir });
|
|
|
|
// Verify the first workspace was removed and second was added
|
|
const workspaces = await allWorkspaces(testConfigDir);
|
|
expect(workspaces.length).toEqual(1);
|
|
expect(workspaces[0].name).toEqual("second_workspace");
|
|
expect(workspaces[0].remote).toEqual("http://localhost:8001/");
|
|
expect(workspaces[0].workspaceId).toEqual("test");
|
|
});
|
|
});
|
|
|
|
test("addWorkspace: allows same workspace (name, remote, workspaceId) with token update", async () => {
|
|
await withTestConfig(async (testConfigDir) => {
|
|
await clearTestRemotes(testConfigDir);
|
|
|
|
// Add first workspace
|
|
const workspace1 = {
|
|
name: "same_workspace",
|
|
remote: "http://localhost:8001/",
|
|
workspaceId: "test",
|
|
token: "old_token"
|
|
};
|
|
|
|
await addWorkspace(workspace1, { force: true, configDir: testConfigDir });
|
|
|
|
// Add same workspace with updated token
|
|
const workspace2 = {
|
|
name: "same_workspace", // Same name
|
|
remote: "http://localhost:8001/", // Same remote
|
|
workspaceId: "test", // Same workspaceId
|
|
token: "new_token" // Different token
|
|
};
|
|
|
|
// Should succeed without force (just token update)
|
|
await addWorkspace(workspace2, { configDir: testConfigDir });
|
|
|
|
// Verify token was updated
|
|
const workspaces = await allWorkspaces(testConfigDir);
|
|
expect(workspaces.length).toEqual(1);
|
|
expect(workspaces[0].name).toEqual("same_workspace");
|
|
expect(workspaces[0].token).toEqual("new_token");
|
|
});
|
|
});
|
|
|
|
test("addWorkspace: returns true on successful add", async () => {
|
|
await withTestConfig(async (testConfigDir) => {
|
|
await clearTestRemotes(testConfigDir);
|
|
|
|
const workspace = {
|
|
name: "return_test",
|
|
remote: "http://localhost:8001/",
|
|
workspaceId: "test",
|
|
token: "token1"
|
|
};
|
|
|
|
const result = await addWorkspace(workspace, { force: true, configDir: testConfigDir });
|
|
expect(result).toEqual(true);
|
|
});
|
|
});
|
|
|
|
test("addWorkspace: returns true when force-overwriting conflict", async () => {
|
|
await withTestConfig(async (testConfigDir) => {
|
|
await clearTestRemotes(testConfigDir);
|
|
|
|
const workspace1 = {
|
|
name: "force_test",
|
|
remote: "http://localhost:8001/",
|
|
workspaceId: "workspace1",
|
|
token: "token1"
|
|
};
|
|
await addWorkspace(workspace1, { force: true, configDir: testConfigDir });
|
|
|
|
const workspace2 = {
|
|
name: "force_test",
|
|
remote: "http://localhost:8002/",
|
|
workspaceId: "workspace2",
|
|
token: "token2"
|
|
};
|
|
const result = await addWorkspace(workspace2, { force: true, configDir: testConfigDir });
|
|
expect(result).toEqual(true);
|
|
});
|
|
});
|
|
|
|
test("addWorkspace: allows different workspaces on different remotes", async () => {
|
|
await withTestConfig(async (testConfigDir) => {
|
|
await clearTestRemotes(testConfigDir);
|
|
|
|
// Add workspace on first remote
|
|
const workspace1 = {
|
|
name: "workspace_remote1",
|
|
remote: "http://localhost:8001/",
|
|
workspaceId: "test",
|
|
token: "token1"
|
|
};
|
|
|
|
await addWorkspace(workspace1, { force: true, configDir: testConfigDir });
|
|
|
|
// Add workspace with same workspaceId on different remote (should be allowed)
|
|
const workspace2 = {
|
|
name: "workspace_remote2",
|
|
remote: "http://localhost:8002/", // Different remote
|
|
workspaceId: "test", // Same workspaceId (OK on different remote)
|
|
token: "token2"
|
|
};
|
|
|
|
// Should succeed (different remotes)
|
|
await addWorkspace(workspace2, { configDir: testConfigDir });
|
|
|
|
// Verify both workspaces exist
|
|
const workspaces = await allWorkspaces(testConfigDir);
|
|
expect(workspaces.length).toEqual(2);
|
|
|
|
const names = workspaces.map(w => w.name).sort();
|
|
expect(names).toEqual(["workspace_remote1", "workspace_remote2"]);
|
|
});
|
|
});
|