* feat(cli): add unified generate-metadata command - Add generate-metadata command that calls script, flow, and app handlers - Export generateLocks from flow.ts and generateMetadata from script.ts - Add deprecation warnings to individual metadata commands * feat(cli): improve unified generate-metadata command - Use internal handlers for single-pass collection of stale items - Add --dry-run flag to show what would be updated - Fix WASM parser init deprecation warning - Add comprehensive tests for all flags - Match original handler behavior for per-item messages 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(cli): add skip flags and comprehensive tests for generate-metadata - Add --skip-scripts, --skip-flows, --skip-apps flags for granular control - --schema-only now properly skips flows and apps (they only have locks) - Dynamic "Checking X, Y, Z..." message based on what's being processed - Show warning when all types are skipped - Add comprehensive tests for all flags: - --dry-run shows stale items without updating - --schema-only only processes scripts - --skip-scripts, --skip-flows, --skip-apps work correctly - skipping all types shows warning - 'All metadata up-to-date' when nothing to update 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * improve output Signed-off-by: pyranota <pyra@duck.com> * refactor(cli): add shared test fixtures with cross-links Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(cli): add folder argument to generate-metadata command Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Signed-off-by: pyranota <pyra@duck.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
452 lines
15 KiB
TypeScript
452 lines
15 KiB
TypeScript
/**
|
|
* Unified generate-metadata Command Tests
|
|
*
|
|
* Tests the new unified `generate-metadata` command that processes
|
|
* scripts, flows, and apps together.
|
|
*/
|
|
|
|
import { expect, test, describe } from "bun:test";
|
|
import { withTestBackend } from "./test_backend.ts";
|
|
import { addWorkspace } from "../workspace.ts";
|
|
import { writeFile } from "node:fs/promises";
|
|
import {
|
|
createLocalScript,
|
|
createLocalFlow,
|
|
createLocalApp,
|
|
createLocalRawApp,
|
|
} from "./test_fixtures.ts";
|
|
|
|
/**
|
|
* Helper to set up a workspace with wmill.yaml
|
|
*/
|
|
async function setupWorkspace(backend: any, tempDir: string, workspaceName: string) {
|
|
const testWorkspace = {
|
|
remote: backend.baseUrl,
|
|
workspaceId: backend.workspace,
|
|
name: workspaceName,
|
|
token: backend.token
|
|
};
|
|
await addWorkspace(testWorkspace, { force: true, configDir: backend.testConfigDir });
|
|
|
|
await writeFile(`${tempDir}/wmill.yaml`, `defaultTs: bun
|
|
includes:
|
|
- "**"
|
|
excludes: []`, "utf-8");
|
|
}
|
|
|
|
// =============================================================================
|
|
// Main test: processes scripts, flows, and apps together
|
|
// =============================================================================
|
|
|
|
test("generate-metadata: processes scripts, flows, and apps together", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "unified_all_test");
|
|
|
|
// Create one of each type
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
await createLocalFlow(tempDir, "f/test", "my_flow");
|
|
await createLocalApp(tempDir, "f/test", "my_app");
|
|
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes"],
|
|
tempDir,
|
|
"unified_all_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
// Should find stale items
|
|
expect(result.stdout).toContain("Found");
|
|
expect(result.stdout).toContain("stale metadata");
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// Flag tests
|
|
// =============================================================================
|
|
|
|
describe("generate-metadata flags", () => {
|
|
test("--includes filters to specific paths", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "includes_test");
|
|
|
|
// Create two scripts in different folders
|
|
await createLocalScript(tempDir, "f/included", "script_a");
|
|
await createLocalScript(tempDir, "f/excluded", "script_b");
|
|
|
|
// Run with --includes to only process f/included
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "-i", "f/included/**"],
|
|
tempDir,
|
|
"includes_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
// Should only mention the included script
|
|
const output = result.stdout + result.stderr;
|
|
expect(output).toContain("script_a");
|
|
expect(output).not.toContain("script_b");
|
|
});
|
|
});
|
|
|
|
test("--excludes filters out specific paths", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "excludes_test");
|
|
|
|
// Create two scripts
|
|
await createLocalScript(tempDir, "f/keep", "script_keep");
|
|
await createLocalScript(tempDir, "f/skip", "script_skip");
|
|
|
|
// Run with --excludes to skip f/skip
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "-e", "f/skip/**"],
|
|
tempDir,
|
|
"excludes_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
expect(output).toContain("script_keep");
|
|
expect(output).not.toContain("script_skip");
|
|
});
|
|
});
|
|
|
|
test("--dry-run shows stale items without updating", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "dry_run_test");
|
|
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
|
|
// Run with --dry-run
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--dry-run"],
|
|
tempDir,
|
|
"dry_run_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
// Should show stale items (Scripts section header)
|
|
expect(result.stdout).toContain("Scripts");
|
|
expect(result.stdout).toContain("my_script");
|
|
// Should NOT show "Done" (didn't actually update)
|
|
expect(result.stdout).not.toContain("Done");
|
|
|
|
// Run again without --dry-run to verify it would still be stale
|
|
const result2 = await backend.runCLICommand(
|
|
["generate-metadata", "--dry-run"],
|
|
tempDir,
|
|
"dry_run_test"
|
|
);
|
|
expect(result2.stdout).toContain("Scripts");
|
|
});
|
|
});
|
|
|
|
test("--lock-only only regenerates locks", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "lock_only_test");
|
|
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "--lock-only"],
|
|
tempDir,
|
|
"lock_only_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
});
|
|
});
|
|
|
|
test("--schema-only only processes scripts (skips flows and apps)", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "schema_only_test");
|
|
|
|
// Create one of each type
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
await createLocalFlow(tempDir, "f/test", "my_flow");
|
|
await createLocalApp(tempDir, "f/test", "my_app");
|
|
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "--schema-only"],
|
|
tempDir,
|
|
"schema_only_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
// Should show "Checking scripts..." only
|
|
expect(output).toContain("Checking scripts...");
|
|
// Should find the script (Scripts section header)
|
|
expect(output).toContain("Scripts");
|
|
// Should NOT find flows or apps
|
|
expect(output).not.toContain("Flows");
|
|
expect(output).not.toContain("Apps");
|
|
});
|
|
});
|
|
|
|
test("--skip-scripts skips scripts", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "skip_scripts_test");
|
|
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
await createLocalFlow(tempDir, "f/test", "my_flow");
|
|
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "--skip-scripts"],
|
|
tempDir,
|
|
"skip_scripts_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
// Should NOT contain script
|
|
expect(output).not.toContain("Scripts");
|
|
// Should contain flow
|
|
expect(output).toContain("Flows");
|
|
});
|
|
});
|
|
|
|
test("--skip-flows skips flows", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "skip_flows_test");
|
|
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
await createLocalFlow(tempDir, "f/test", "my_flow");
|
|
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "--skip-flows"],
|
|
tempDir,
|
|
"skip_flows_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
// Should contain script
|
|
expect(output).toContain("Scripts");
|
|
// Should NOT contain flow
|
|
expect(output).not.toContain("Flows");
|
|
});
|
|
});
|
|
|
|
test("--skip-apps skips apps", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "skip_apps_test");
|
|
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
await createLocalApp(tempDir, "f/test", "my_app");
|
|
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "--skip-apps"],
|
|
tempDir,
|
|
"skip_apps_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
// Should contain script
|
|
expect(output).toContain("Scripts");
|
|
// Should NOT contain app
|
|
expect(output).not.toContain("Apps");
|
|
});
|
|
});
|
|
|
|
test("shows 'All metadata up-to-date' when nothing to update", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "uptodate_test");
|
|
|
|
// Create a script and run generate-metadata twice
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
|
|
// First run - generates metadata
|
|
await backend.runCLICommand(
|
|
["generate-metadata", "--yes"],
|
|
tempDir,
|
|
"uptodate_test"
|
|
);
|
|
|
|
// Second run - should be up-to-date
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes"],
|
|
tempDir,
|
|
"uptodate_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
expect(result.stdout).toContain("up-to-date");
|
|
});
|
|
});
|
|
|
|
test("skipping all types shows warning", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "skip_all_test");
|
|
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--skip-scripts", "--skip-flows", "--skip-apps"],
|
|
tempDir,
|
|
"skip_all_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
expect(result.stdout).toContain("Nothing to check");
|
|
});
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// Folder argument tests
|
|
// =============================================================================
|
|
|
|
describe("generate-metadata folder argument", () => {
|
|
test("filters to specific script folder", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "folder_script_test");
|
|
|
|
// Create scripts in different folders
|
|
await createLocalScript(tempDir, "f/included", "script_a");
|
|
await createLocalScript(tempDir, "f/excluded", "script_b");
|
|
|
|
// Run with folder argument
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "f/included/script_a.ts"],
|
|
tempDir,
|
|
"folder_script_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
expect(output).toContain("script_a");
|
|
expect(output).not.toContain("script_b");
|
|
});
|
|
});
|
|
|
|
test("filters to specific flow folder", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "folder_flow_test");
|
|
|
|
// Create flows in different folders
|
|
await createLocalFlow(tempDir, "f/included", "flow_a");
|
|
await createLocalFlow(tempDir, "f/excluded", "flow_b");
|
|
|
|
// Run with folder argument (flow folder path - uses .flow suffix by default)
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "f/included/flow_a.flow"],
|
|
tempDir,
|
|
"folder_flow_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
expect(output).toContain("flow_a");
|
|
expect(output).not.toContain("flow_b");
|
|
});
|
|
});
|
|
|
|
test("filters to specific app folder", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "folder_app_test");
|
|
|
|
// Create apps in different folders
|
|
await createLocalApp(tempDir, "f/included", "app_a");
|
|
await createLocalApp(tempDir, "f/excluded", "app_b");
|
|
|
|
// Run with folder argument (app folder path - uses .app suffix by default)
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "f/included/app_a.app"],
|
|
tempDir,
|
|
"folder_app_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
expect(output).toContain("app_a");
|
|
expect(output).not.toContain("app_b");
|
|
});
|
|
});
|
|
|
|
test("shows up-to-date when folder has no stale items", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "folder_uptodate_test");
|
|
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
|
|
// First run to generate metadata
|
|
await backend.runCLICommand(
|
|
["generate-metadata", "--yes"],
|
|
tempDir,
|
|
"folder_uptodate_test"
|
|
);
|
|
|
|
// Second run with folder - should be up-to-date
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "f/test/my_script.ts"],
|
|
tempDir,
|
|
"folder_uptodate_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
expect(result.stdout).toContain("up-to-date");
|
|
});
|
|
});
|
|
|
|
test("trailing slash is stripped (matches deprecated behavior)", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "trailing_slash_test");
|
|
|
|
await createLocalScript(tempDir, "f/test", "my_script");
|
|
|
|
// Run with trailing slash
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "f/test/my_script.ts/"],
|
|
tempDir,
|
|
"trailing_slash_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
expect(result.stdout).toContain("my_script");
|
|
});
|
|
});
|
|
|
|
test("parent folder matches all children", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "parent_folder_test");
|
|
|
|
// Create scripts in nested folders
|
|
await createLocalScript(tempDir, "f/parent", "script_a");
|
|
await createLocalScript(tempDir, "f/parent/child", "script_b");
|
|
await createLocalScript(tempDir, "f/other", "script_c");
|
|
|
|
// Run with parent folder - should match both scripts in f/parent tree
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "f/parent"],
|
|
tempDir,
|
|
"parent_folder_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
const output = result.stdout + result.stderr;
|
|
expect(output).toContain("script_a");
|
|
expect(output).toContain("script_b");
|
|
expect(output).not.toContain("script_c");
|
|
});
|
|
});
|
|
|
|
test("non-existent folder shows up-to-date", async () => {
|
|
await withTestBackend(async (backend, tempDir) => {
|
|
await setupWorkspace(backend, tempDir, "nonexistent_folder_test");
|
|
|
|
await createLocalScript(tempDir, "f/exists", "my_script");
|
|
|
|
// Run with non-existent folder
|
|
const result = await backend.runCLICommand(
|
|
["generate-metadata", "--yes", "f/does_not_exist"],
|
|
tempDir,
|
|
"nonexistent_folder_test"
|
|
);
|
|
|
|
expect(result.code).toEqual(0);
|
|
expect(result.stdout).toContain("up-to-date");
|
|
});
|
|
});
|
|
});
|