mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(cli): 'hyperframes registry search' runs catalog (#7610)
This commit is contained in:
@@ -291,7 +291,6 @@ describe("agent-mode contract", () => {
|
||||
["find crossfade", "Did you mean 'hyperframes catalog'?"],
|
||||
["list", "Did you mean 'hyperframes catalog'?"],
|
||||
["browse", "Did you mean 'hyperframes catalog'?"],
|
||||
["registry", "Did you mean 'hyperframes catalog'?"],
|
||||
])(
|
||||
"unknown command `%s` suggests the closest one, usage on stderr, exit 2",
|
||||
async (args, hint) => {
|
||||
@@ -303,6 +302,17 @@ describe("agent-mode contract", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("`registry search` runs catalog, unlisted", async () => {
|
||||
const [alias, catalog] = await Promise.all([
|
||||
runAsAgent(["registry", "search", "--help"]),
|
||||
runAsAgent(["catalog", "--help"]),
|
||||
]);
|
||||
expectQuiet(alias);
|
||||
expect(alias.code).toBe(0);
|
||||
expect(alias.stdout).toBe(catalog.stdout);
|
||||
expect((await runAsAgent(["--help"])).stdout).not.toMatch(/^\s+registry\b/m);
|
||||
});
|
||||
|
||||
it.each([["lint"], ["check"], ["info"], ["validate"], ["layout"], ["inspect"]])(
|
||||
"%s --json in an empty directory names the real failure, and no notice",
|
||||
async (name) => {
|
||||
|
||||
@@ -109,6 +109,7 @@ import {
|
||||
commandWordIndex,
|
||||
measureProbeShortcutArgv,
|
||||
openShortcutArgv,
|
||||
registryAliasArgv,
|
||||
} from "./utils/projectShortcut.js";
|
||||
|
||||
registerRunningCli();
|
||||
@@ -199,7 +200,7 @@ const commandLoaders = {
|
||||
// `hyperframes <dir>` is `hyperframes open <dir>`; every later read of the command sees `open`.
|
||||
process.argv = [
|
||||
...process.argv.slice(0, 2),
|
||||
...openShortcutArgv(argv, new Set(Object.keys(commandLoaders))),
|
||||
...registryAliasArgv(openShortcutArgv(argv, new Set(Object.keys(commandLoaders)))),
|
||||
];
|
||||
argv = process.argv.slice(2);
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ const COMMAND_REDIRECTS: Record<string, { command: string; then?: string }> = {
|
||||
search: { command: "catalog" },
|
||||
find: { command: "catalog" },
|
||||
browse: { command: "catalog" },
|
||||
registry: { command: "catalog" },
|
||||
list: { command: "catalog" },
|
||||
install: { command: "add" },
|
||||
captions: {
|
||||
|
||||
@@ -2,7 +2,12 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterAll, describe, expect, it } from "vitest";
|
||||
import { commandWordIndex, measureProbeShortcutArgv, openShortcutArgv } from "./projectShortcut.js";
|
||||
import {
|
||||
commandWordIndex,
|
||||
measureProbeShortcutArgv,
|
||||
openShortcutArgv,
|
||||
registryAliasArgv,
|
||||
} from "./projectShortcut.js";
|
||||
|
||||
const commands = new Set(["open", "render", "lint"]);
|
||||
const cwd = mkdtempSync(join(tmpdir(), "hf-shortcut-"));
|
||||
@@ -100,3 +105,29 @@ describe("commandWordIndex", () => {
|
||||
expect(commandWordIndex(argv)).toBe(index);
|
||||
});
|
||||
});
|
||||
|
||||
describe("registryAliasArgv", () => {
|
||||
it.each([
|
||||
[
|
||||
["registry", "search", "rain", "snow", "--json"],
|
||||
["catalog", "rain", "snow", "--json"],
|
||||
],
|
||||
[
|
||||
["registry", "crossfade"],
|
||||
["catalog", "crossfade"],
|
||||
],
|
||||
[
|
||||
["--verbose", "registry", "search", "title"],
|
||||
["--verbose", "catalog", "title"],
|
||||
],
|
||||
[["registry"], ["catalog"]],
|
||||
])("runs %j as %j", (argv, expected) => {
|
||||
expect(registryAliasArgv(argv)).toEqual(expected);
|
||||
});
|
||||
|
||||
it("leaves every other command alone", () => {
|
||||
const argv = ["catalog", "search", "rain"];
|
||||
expect(registryAliasArgv(argv)).toBe(argv);
|
||||
expect(registryAliasArgv(["render", "registry"])).toEqual(["render", "registry"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,6 +24,13 @@ export function openShortcutArgv(
|
||||
return [...argv.slice(0, at), "open", ...argv.slice(at)];
|
||||
}
|
||||
|
||||
export function registryAliasArgv(argv: readonly string[]): readonly string[] {
|
||||
const at = commandWordIndex(argv);
|
||||
if (at < 0 || argv[at] !== "registry") return argv;
|
||||
const words = argv[at + 1] === "search" ? at + 2 : at + 1;
|
||||
return [...argv.slice(0, at), "catalog", ...argv.slice(words)];
|
||||
}
|
||||
|
||||
export function measureProbeShortcutArgv(
|
||||
argv: readonly string[],
|
||||
ops: ReadonlySet<string>,
|
||||
|
||||
Reference in New Issue
Block a user