* 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>
341 lines
11 KiB
TypeScript
341 lines
11 KiB
TypeScript
/**
|
|
* Integration tests for variable and resource 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 }
|
|
);
|
|
}
|
|
|
|
// =============================================================================
|
|
// Variable Tests
|
|
// =============================================================================
|
|
|
|
describe("variable", () => {
|
|
test("list returns seeded variables", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspaceProfile(backend);
|
|
|
|
const result = await backend.runCLICommand(["variable"], tempDir);
|
|
|
|
expect(result.code).toEqual(0);
|
|
// seedTestData creates f/test/my_variable
|
|
expect(result.stdout).toContain("f/test/my_variable");
|
|
});
|
|
});
|
|
|
|
test("push creates a new variable via sync push", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspaceProfile(backend);
|
|
|
|
const uniqueId = Date.now();
|
|
|
|
// Create wmill.yaml
|
|
await writeFile(
|
|
join(tempDir, "wmill.yaml"),
|
|
`defaultTs: bun\nincludes:\n - "**"\nexcludes: []\n`,
|
|
"utf-8"
|
|
);
|
|
|
|
// Create variable file
|
|
await mkdir(join(tempDir, "f", "test"), { recursive: true });
|
|
const varPath = `f/test/test_var_${uniqueId}.variable.yaml`;
|
|
await writeFile(
|
|
join(tempDir, varPath),
|
|
`value: "hello_from_test_${uniqueId}"\nis_secret: false\ndescription: "Test variable created by integration test"\n`,
|
|
"utf-8"
|
|
);
|
|
|
|
// Push with sync push targeting just our variable
|
|
const pushResult = await backend.runCLICommand(
|
|
["sync", "push", "--yes", "--includes", `f/test/test_var_${uniqueId}**`],
|
|
tempDir
|
|
);
|
|
|
|
expect(pushResult.code).toEqual(0);
|
|
|
|
// Verify via API that the variable was created
|
|
const apiResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/variables/get/f/test/test_var_${uniqueId}`
|
|
);
|
|
expect(apiResp.status).toEqual(200);
|
|
const varData = await apiResp.json();
|
|
expect(varData.path).toBe(`f/test/test_var_${uniqueId}`);
|
|
expect(varData.is_secret).toBe(false);
|
|
});
|
|
});
|
|
|
|
test("push updates an existing variable", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspaceProfile(backend);
|
|
|
|
const uniqueId = Date.now();
|
|
|
|
// Create variable via API first
|
|
const createResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/variables/create`,
|
|
{
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
path: `f/test/update_var_${uniqueId}`,
|
|
value: "original_value",
|
|
is_secret: false,
|
|
description: "Original description",
|
|
}),
|
|
}
|
|
);
|
|
expect(createResp.status).toBeLessThan(300);
|
|
await createResp.text();
|
|
|
|
// Create wmill.yaml and updated variable file
|
|
await writeFile(
|
|
join(tempDir, "wmill.yaml"),
|
|
`defaultTs: bun\nincludes:\n - "**"\nexcludes: []\n`,
|
|
"utf-8"
|
|
);
|
|
await mkdir(join(tempDir, "f", "test"), { recursive: true });
|
|
await writeFile(
|
|
join(tempDir, `f/test/update_var_${uniqueId}.variable.yaml`),
|
|
`value: "updated_value"\nis_secret: false\ndescription: "Updated description"\n`,
|
|
"utf-8"
|
|
);
|
|
|
|
// Push the update
|
|
const pushResult = await backend.runCLICommand(
|
|
["sync", "push", "--yes", "--includes", `f/test/update_var_${uniqueId}**`],
|
|
tempDir
|
|
);
|
|
|
|
expect(pushResult.code).toEqual(0);
|
|
|
|
// Verify the update via API
|
|
const apiResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/variables/get/f/test/update_var_${uniqueId}`
|
|
);
|
|
expect(apiResp.status).toEqual(200);
|
|
const varData = await apiResp.json();
|
|
expect(varData.description).toBe("Updated description");
|
|
});
|
|
});
|
|
|
|
test("pull retrieves variables into local files", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspaceProfile(backend);
|
|
|
|
const uniqueId = Date.now();
|
|
|
|
// Create a variable via API
|
|
const createResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/variables/create`,
|
|
{
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
path: `f/test/pull_var_${uniqueId}`,
|
|
value: "pull_test_value",
|
|
is_secret: false,
|
|
description: "Variable for pull test",
|
|
}),
|
|
}
|
|
);
|
|
expect(createResp.status).toBeLessThan(300);
|
|
await createResp.text();
|
|
|
|
// Create wmill.yaml
|
|
await writeFile(
|
|
join(tempDir, "wmill.yaml"),
|
|
`defaultTs: bun\nincludes:\n - "f/test/pull_var_${uniqueId}**"\nexcludes: []\n`,
|
|
"utf-8"
|
|
);
|
|
|
|
// Pull
|
|
const pullResult = await backend.runCLICommand(
|
|
["sync", "pull", "--yes"],
|
|
tempDir
|
|
);
|
|
expect(pullResult.code).toEqual(0);
|
|
|
|
// Check the file was created
|
|
const content = await readFile(
|
|
join(tempDir, `f/test/pull_var_${uniqueId}.variable.yaml`), "utf-8"
|
|
);
|
|
expect(content).toContain("pull_test_value");
|
|
expect(content).toContain("is_secret: false");
|
|
});
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// Resource Tests
|
|
// =============================================================================
|
|
|
|
describe("resource", () => {
|
|
test("list returns seeded resources", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspaceProfile(backend);
|
|
|
|
const result = await backend.runCLICommand(["resource"], tempDir);
|
|
|
|
expect(result.code).toEqual(0);
|
|
// seedTestData creates f/test/my_resource
|
|
expect(result.stdout).toContain("f/test/my_resource");
|
|
});
|
|
});
|
|
|
|
test("push creates a new resource via sync push", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspaceProfile(backend);
|
|
|
|
const uniqueId = Date.now();
|
|
|
|
// Create wmill.yaml
|
|
await writeFile(
|
|
join(tempDir, "wmill.yaml"),
|
|
`defaultTs: bun\nincludes:\n - "**"\nexcludes: []\n`,
|
|
"utf-8"
|
|
);
|
|
|
|
// Create resource file
|
|
await mkdir(join(tempDir, "f", "test"), { recursive: true });
|
|
const resPath = `f/test/test_res_${uniqueId}.resource.yaml`;
|
|
await writeFile(
|
|
join(tempDir, resPath),
|
|
`resource_type: "any"\nvalue:\n host: "localhost"\n port: 3000\ndescription: "Test resource"\n`,
|
|
"utf-8"
|
|
);
|
|
|
|
// Push
|
|
const pushResult = await backend.runCLICommand(
|
|
["sync", "push", "--yes", "--includes", `f/test/test_res_${uniqueId}**`],
|
|
tempDir
|
|
);
|
|
|
|
expect(pushResult.code).toEqual(0);
|
|
|
|
// Verify via API
|
|
const apiResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/resources/get/f/test/test_res_${uniqueId}`
|
|
);
|
|
expect(apiResp.status).toEqual(200);
|
|
const resData = await apiResp.json();
|
|
expect(resData.path).toBe(`f/test/test_res_${uniqueId}`);
|
|
expect(resData.resource_type).toBe("any");
|
|
expect(resData.value.host).toBe("localhost");
|
|
});
|
|
});
|
|
|
|
test("push updates an existing resource", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspaceProfile(backend);
|
|
|
|
const uniqueId = Date.now();
|
|
|
|
// Create resource via API
|
|
const createResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/resources/create`,
|
|
{
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
path: `f/test/update_res_${uniqueId}`,
|
|
resource_type: "any",
|
|
value: { host: "old_host" },
|
|
description: "Original",
|
|
}),
|
|
}
|
|
);
|
|
expect(createResp.status).toBeLessThan(300);
|
|
await createResp.text();
|
|
|
|
// Create wmill.yaml and updated resource file
|
|
await writeFile(
|
|
join(tempDir, "wmill.yaml"),
|
|
`defaultTs: bun\nincludes:\n - "**"\nexcludes: []\n`,
|
|
"utf-8"
|
|
);
|
|
await mkdir(join(tempDir, "f", "test"), { recursive: true });
|
|
await writeFile(
|
|
join(tempDir, `f/test/update_res_${uniqueId}.resource.yaml`),
|
|
`resource_type: "any"\nvalue:\n host: "new_host"\n port: 9999\ndescription: "Updated"\n`,
|
|
"utf-8"
|
|
);
|
|
|
|
// Push the update
|
|
const pushResult = await backend.runCLICommand(
|
|
["sync", "push", "--yes", "--includes", `f/test/update_res_${uniqueId}**`],
|
|
tempDir
|
|
);
|
|
|
|
expect(pushResult.code).toEqual(0);
|
|
|
|
// Verify update
|
|
const apiResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/resources/get/f/test/update_res_${uniqueId}`
|
|
);
|
|
expect(apiResp.status).toEqual(200);
|
|
const resData = await apiResp.json();
|
|
expect(resData.value.host).toBe("new_host");
|
|
expect(resData.value.port).toBe(9999);
|
|
});
|
|
});
|
|
|
|
test("pull retrieves resources into local files", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspaceProfile(backend);
|
|
|
|
const uniqueId = Date.now();
|
|
|
|
// Create resource via API
|
|
const createResp = await backend.apiRequest!(
|
|
`/api/w/${backend.workspace}/resources/create`,
|
|
{
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
path: `f/test/pull_res_${uniqueId}`,
|
|
resource_type: "any",
|
|
value: { key: "pull_test" },
|
|
}),
|
|
}
|
|
);
|
|
expect(createResp.status).toBeLessThan(300);
|
|
await createResp.text();
|
|
|
|
// Create wmill.yaml
|
|
await writeFile(
|
|
join(tempDir, "wmill.yaml"),
|
|
`defaultTs: bun\nincludes:\n - "f/test/pull_res_${uniqueId}**"\nexcludes: []\nskipVariables: true\n`,
|
|
"utf-8"
|
|
);
|
|
|
|
// Pull
|
|
const pullResult = await backend.runCLICommand(
|
|
["sync", "pull", "--yes"],
|
|
tempDir
|
|
);
|
|
expect(pullResult.code).toEqual(0);
|
|
|
|
// Check the resource file was created
|
|
const content = await readFile(
|
|
join(tempDir, `f/test/pull_res_${uniqueId}.resource.yaml`), "utf-8"
|
|
);
|
|
expect(content).toContain("pull_test");
|
|
});
|
|
});
|
|
});
|