refactor(catalog): import CLI metadata from its owner
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
export function createCliInventory(cli: unknown): {
|
||||||
|
readonly primary: readonly string[];
|
||||||
|
readonly aliases: readonly {
|
||||||
|
readonly name: string;
|
||||||
|
readonly target: string;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
export function cliCommandOptionNames(
|
||||||
|
cli: unknown,
|
||||||
|
name: string,
|
||||||
|
): readonly string[];
|
||||||
|
export function cliCommandDescriptionIssues(cli: unknown): readonly string[];
|
||||||
@@ -26,10 +26,6 @@ export interface ProductCatalog {
|
|||||||
readonly format: string;
|
readonly format: string;
|
||||||
readonly configuration: string;
|
readonly configuration: string;
|
||||||
}[];
|
}[];
|
||||||
readonly schemas: readonly {
|
|
||||||
readonly id: string;
|
|
||||||
readonly version: string | number;
|
|
||||||
}[];
|
|
||||||
readonly cli: {
|
readonly cli: {
|
||||||
readonly primary_count: number;
|
readonly primary_count: number;
|
||||||
readonly commands: readonly string[];
|
readonly commands: readonly string[];
|
||||||
@@ -45,21 +41,6 @@ export interface ProductCatalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createProductCatalog(root: string): Promise<ProductCatalog>;
|
export function createProductCatalog(root: string): Promise<ProductCatalog>;
|
||||||
export function providerCatalogDigest(
|
|
||||||
providers: ProductCatalog["providers"],
|
|
||||||
): string;
|
|
||||||
export function createCliInventory(cli: unknown): {
|
|
||||||
readonly primary: readonly string[];
|
|
||||||
readonly aliases: readonly {
|
|
||||||
readonly name: string;
|
|
||||||
readonly target: string;
|
|
||||||
}[];
|
|
||||||
};
|
|
||||||
export function cliCommandOptionNames(
|
|
||||||
cli: unknown,
|
|
||||||
name: string,
|
|
||||||
): readonly string[];
|
|
||||||
export function cliCommandDescriptionIssues(cli: unknown): readonly string[];
|
|
||||||
export function serializeProductCatalog(
|
export function serializeProductCatalog(
|
||||||
catalog: ProductCatalog,
|
catalog: ProductCatalog,
|
||||||
): Promise<string>;
|
): Promise<string>;
|
||||||
|
|||||||
@@ -1,22 +1,9 @@
|
|||||||
import { formatGeneratedFile } from "./format-generated-file.mjs";
|
import { formatGeneratedFile } from "./format-generated-file.mjs";
|
||||||
|
|
||||||
import { assertSameNames, digest, loadSources } from "./catalog-core.mjs";
|
import { assertSameNames, digest, loadSources } from "./catalog-core.mjs";
|
||||||
import {
|
import { createCliInventory } from "./catalog-cli.mjs";
|
||||||
createCliInventory,
|
|
||||||
cliCommandDescriptionIssues,
|
|
||||||
cliCommandOptionNames,
|
|
||||||
} from "./catalog-cli.mjs";
|
|
||||||
import { providerCatalog, toolFamilyCatalog } from "./catalog-builders.mjs";
|
import { providerCatalog, toolFamilyCatalog } from "./catalog-builders.mjs";
|
||||||
|
|
||||||
export {
|
|
||||||
createCliInventory,
|
|
||||||
cliCommandDescriptionIssues,
|
|
||||||
cliCommandOptionNames,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Return the stable digest for the source-derived provider projection. */
|
|
||||||
export const providerCatalogDigest = (providers) => digest(providers);
|
|
||||||
|
|
||||||
/** Project current runtime contracts into deterministic, machine-readable facts. */
|
/** Project current runtime contracts into deterministic, machine-readable facts. */
|
||||||
export const createProductCatalog = async (root) => {
|
export const createProductCatalog = async (root) => {
|
||||||
const sources = await loadSources(root);
|
const sources = await loadSources(root);
|
||||||
@@ -59,7 +46,7 @@ export const createProductCatalog = async (root) => {
|
|||||||
counts: sources.catalogIdentity.CATALOG_IDENTITY.counts,
|
counts: sources.catalogIdentity.CATALOG_IDENTITY.counts,
|
||||||
digests: {
|
digests: {
|
||||||
// Full runtime schema digests belong to server identity, not this facts projection.
|
// Full runtime schema digests belong to server identity, not this facts projection.
|
||||||
providers_sha256: providerCatalogDigest(providers),
|
providers_sha256: digest(providers),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Cli, z } from "incur";
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { createCli } from "../../../src/cli.js";
|
import { createCli } from "../../../src/cli.js";
|
||||||
import { createCliInventory } from "../../../scripts/lib/product-catalog.mjs";
|
import { createCliInventory } from "../../../scripts/lib/catalog-cli.mjs";
|
||||||
|
|
||||||
type CliInstance = ReturnType<typeof createCli>;
|
type CliInstance = ReturnType<typeof createCli>;
|
||||||
type CommandMap = NonNullable<ReturnType<typeof Cli.toCommands.get>>;
|
type CommandMap = NonNullable<ReturnType<typeof Cli.toCommands.get>>;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { createCli } from "../../../src/cli.js";
|
import { createCli } from "../../../src/cli.js";
|
||||||
import { createCliInventory } from "../../../scripts/lib/product-catalog.mjs";
|
import { createCliInventory } from "../../../scripts/lib/catalog-cli.mjs";
|
||||||
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
|
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
|
||||||
import {
|
import {
|
||||||
CLI_COMMAND_ALIASES,
|
CLI_COMMAND_ALIASES,
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ import {
|
|||||||
createCliInventory,
|
createCliInventory,
|
||||||
cliCommandDescriptionIssues,
|
cliCommandDescriptionIssues,
|
||||||
cliCommandOptionNames,
|
cliCommandOptionNames,
|
||||||
|
} from "../../../scripts/lib/catalog-cli.mjs";
|
||||||
|
import {
|
||||||
createProductCatalog,
|
createProductCatalog,
|
||||||
providerCatalogDigest,
|
|
||||||
serializeProductCatalog,
|
serializeProductCatalog,
|
||||||
} from "../../../scripts/lib/product-catalog.mjs";
|
} from "../../../scripts/lib/product-catalog.mjs";
|
||||||
|
|
||||||
@@ -77,9 +78,6 @@ describe("canonical product catalog", () => {
|
|||||||
catalog.providers.find(({ id }) => id === GHIDRA_PROVIDER_IDENTITY.id)
|
catalog.providers.find(({ id }) => id === GHIDRA_PROVIDER_IDENTITY.id)
|
||||||
?.capabilities,
|
?.capabilities,
|
||||||
).toEqual([...GHIDRA_OPERATIONS].sort());
|
).toEqual([...GHIDRA_OPERATIONS].sort());
|
||||||
expect(catalog.runtime_catalog.digests.providers_sha256).toBe(
|
|
||||||
providerCatalogDigest(catalog.providers),
|
|
||||||
);
|
|
||||||
expect(
|
expect(
|
||||||
JSON.parse(await readFile("docs/public/product-catalog.json", "utf8")),
|
JSON.parse(await readFile("docs/public/product-catalog.json", "utf8")),
|
||||||
).toEqual(catalog);
|
).toEqual(catalog);
|
||||||
@@ -207,19 +205,6 @@ describe("canonical product catalog drift", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("changes the provider projection digest when provider facts drift", async () => {
|
|
||||||
const catalog = await createProductCatalog(root);
|
|
||||||
const firstProvider = catalog.providers[0];
|
|
||||||
if (firstProvider === undefined) throw new TypeError("Missing provider");
|
|
||||||
const driftedProviders = [
|
|
||||||
{ ...firstProvider, name: `${firstProvider.name} drifted` },
|
|
||||||
...catalog.providers.slice(1),
|
|
||||||
];
|
|
||||||
expect(providerCatalogDigest(driftedProviders)).not.toBe(
|
|
||||||
catalog.runtime_catalog.digests.providers_sha256,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("fails check mode without rewriting a stale generated artifact", async () => {
|
it("fails check mode without rewriting a stale generated artifact", async () => {
|
||||||
const directory = await createTestTempDirectory("rea-generated-check-");
|
const directory = await createTestTempDirectory("rea-generated-check-");
|
||||||
temporaryRoots.push(directory);
|
temporaryRoots.push(directory);
|
||||||
|
|||||||
Reference in New Issue
Block a user