MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / checkSchemaCommand

Function checkSchemaCommand

ts/workflow-cli/cli/check-schema.ts:74–109  ·  view source on GitHub ↗
(filePath?: string)

Source from the content-addressed store, hash-verified

72 * checks the file as written against the current contract.
73 */
74export async function checkSchemaCommand(filePath?: string): Promise<void> {
75 if (!filePath) {
76 process.stderr.write("Usage: fh-workflow check-schema <file.json>\n");
77 process.exit(1);
78 }
79
80 const abs = path.resolve(process.cwd(), filePath);
81 let raw: string;
82 try {
83 raw = await fs.readFile(abs, "utf-8");
84 } catch (err: unknown) {
85 const code = (err as NodeJS.ErrnoException).code;
86 if (code === "ENOENT") {
87 process.stderr.write(`File not found: ${abs}\n`);
88 process.exit(1);
89 }
90 throw err;
91 }
92
93 let parsed: unknown;
94 try {
95 parsed = JSON.parse(raw);
96 } catch (err) {
97 process.stderr.write(`Invalid JSON: ${err instanceof Error ? err.message : String(err)}\n`);
98 process.exit(1);
99 }
100
101 const { ok, errors } = validateAgainstContract(parsed);
102 if (ok) {
103 process.stdout.write(`✓ ${abs}: schema valid\n`);
104 return;
105 }
106
107 printSchemaReport(abs, errors);
108 process.exit(1);
109}
110
111function printSchemaReport(file: string, errors: ErrorObject[]): void {
112 const out = process.stdout;

Callers 1

index.tsFile · 0.90

Calls 3

validateAgainstContractFunction · 0.85
printSchemaReportFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected