mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* fix(cli): describe a contract option whose description sits inside .optional() zod does not carry a wrapped schema's description to its .optional() wrapper. Since #10798 projected analyze_javascript_application from its contract, source_paths is javaScriptSourcePathsSchema.optional(), so 'analyze --help' and 'analyze-javascript-application --help' listed --source-path with no description and cliOptionAliases.test.ts fails on main. The contract option projection now reads the field's description through its wrappers (describedThroughWrappers), once for every argv branch, in place of three per-branch copies that read only the outer schema. The opener and member option projections use the same reader. * test(cli): assert the exact help text of a wrapped contract field and of a projection override
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import { createCli } from "../../../src/cli.js";
|
|
import { javaScriptSourcePathsSchema } from "../../../src/domain/javascript/javascriptSourceSelection.js";
|
|
|
|
const help = async (command: string): Promise<string> => {
|
|
let stdout = "";
|
|
await createCli({}).serve([command, "--help"], {
|
|
env: {},
|
|
exit: () => undefined,
|
|
stdout: (text) => {
|
|
stdout += text;
|
|
},
|
|
});
|
|
return stdout;
|
|
};
|
|
|
|
/** The help line of one option, with its description. */
|
|
const optionLine = (text: string, option: string): string | undefined =>
|
|
text.split("\n").find((line) => line.trimStart().startsWith(`${option} `));
|
|
|
|
// `source_paths` is `javaScriptSourcePathsSchema.optional()`; zod keeps the
|
|
// description on the wrapped schema only. A projection description replaces
|
|
// the contract's (`format` is shown as "Application artifact format").
|
|
it.each(["analyze-javascript-application", "analyze"])(
|
|
"%s --help describes a wrapped contract field and keeps the projection's override",
|
|
async (command) => {
|
|
const text = await help(command);
|
|
const description = javaScriptSourcePathsSchema.description!;
|
|
expect(optionLine(text, "--source-path")).toContain(
|
|
description.slice(0, 60),
|
|
);
|
|
expect(optionLine(text, "--artifact-format")).toContain(
|
|
"Application artifact format",
|
|
);
|
|
},
|
|
);
|