Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
describe("@toolctrl/plugins package entrypoint", () => {
describe("@hivegrid/plugins package entrypoint", () => {
it("exports the manifest schema API", async () => {
const module = await import("../src/index.ts");
@@ -0,0 +1,56 @@
import { readdir, readFile } from "node:fs/promises";
import { afterEach, describe, expect, it, vi, type Mock } from "vitest";
import { loadFeatureManifests } from "./manifest-loader";
// vi.mock is hoisted above the imports by vitest, so the loader binds to these
// fakes. We drive the defensive "instanceof Error" fallbacks, which real
// fs/JSON.parse rejections (always Error subclasses) can never reach. A default
// export is supplied because the loader resolves node:fs/promises through ESM
// interop that expects one.
vi.mock("node:fs/promises", () => {
const readdirFn = vi.fn();
const readFileFn = vi.fn();
return { readdir: readdirFn, readFile: readFileFn, default: { readdir: readdirFn, readFile: readFileFn } };
});
const readdirMock = readdir as unknown as Mock;
const readFileMock = readFile as unknown as Mock;
describe("loadFeatureManifests non-Error rejections", () => {
afterEach(() => {
vi.clearAllMocks();
});
it("uses the generic directory message when readdir rejects with a non-Error value", async () => {
readdirMock.mockRejectedValueOnce("not-an-error");
const result = await loadFeatureManifests({ rootDir: "/synthetic/root" });
expect(result.ok).toBe(false);
expect(result.manifestFiles).toEqual([]);
expect(result.diagnostics).toHaveLength(1);
expect(result.diagnostics[0]).toMatchObject({
code: "missing_directory",
manifestId: null,
message: "Failed to read feature manifest directory: Unknown directory read failure.",
});
});
it("uses the generic parse message when readFile rejects with a non-Error value", async () => {
readdirMock.mockResolvedValueOnce(["candidate.json"]);
readFileMock.mockRejectedValueOnce(42);
const result = await loadFeatureManifests({ rootDir: "/synthetic/root" });
expect(result.ok).toBe(false);
expect(result.manifests).toEqual([]);
expect(result.diagnostics).toContainEqual(
expect.objectContaining({
code: "invalid_json",
manifestId: null,
message: "Failed to parse candidate.json: Unknown JSON parse failure.",
}),
);
});
});
@@ -0,0 +1,464 @@
import { describe, expect, it } from "vitest";
import pluginCandidates from "../../../docs/feature-manifests/plugin-candidates.json";
import { validateFeatureManifestShape } from "./manifest-schema";
// Returns a mutable, deeply-cloned copy of the canonical fixture so individual
// tests can delete or overwrite fields without leaking state between cases.
function clone(): Record<string, unknown> {
return structuredClone(pluginCandidates) as Record<string, unknown>;
}
// Spreads overrides over the fixture, mirroring the helper used by the
// neighbouring test/ suite so the assertions stay comparable.
function manifestWith(overrides: Record<string, unknown>) {
return structuredClone({ ...pluginCandidates, ...overrides });
}
const FIXTURE_ID = "plugin-candidates";
describe("validateFeatureManifestShape valid manifests", () => {
it("accepts the canonical fixture and returns the manifest by reference", () => {
const result = validateFeatureManifestShape(pluginCandidates);
expect(result.ok).toBe(true);
expect(result.diagnostics).toEqual([]);
// On success the validated object is returned untouched (identity cast).
expect(result.manifest).toBe(pluginCandidates);
expect(result.manifest?.id).toBe(FIXTURE_ID);
});
it("accepts a manifest without the optional components array", () => {
const input = clone();
delete input.components;
const result = validateFeatureManifestShape(input);
expect(result.ok).toBe(true);
expect(result.diagnostics).toEqual([]);
});
});
describe("validateFeatureManifestShape string fields", () => {
it("reports a required string that is missing", () => {
const input = clone();
delete input.owner;
const result = validateFeatureManifestShape(input);
expect(result.ok).toBe(false);
expect(result.manifest).toBeNull();
expect(result.diagnostics).toContainEqual({
code: "missing_required",
manifestId: FIXTURE_ID,
path: "owner",
message: "owner is required.",
});
});
it("reports a required string with a non-string value", () => {
const result = validateFeatureManifestShape(manifestWith({ description: 42 }));
expect(result.ok).toBe(false);
expect(result.diagnostics).toContainEqual({
code: "invalid_type",
manifestId: FIXTURE_ID,
path: "description",
message: "description must be a string.",
});
});
it("reports a const-mismatch for schemaVersion", () => {
const result = validateFeatureManifestShape(manifestWith({ schemaVersion: "2.0" }));
expect(result.ok).toBe(false);
expect(result.diagnostics).toContainEqual({
code: "invalid_enum",
manifestId: FIXTURE_ID,
path: "schemaVersion",
message: "schemaVersion must be 1.0.",
});
});
it("reports an empty non-empty-required string", () => {
const result = validateFeatureManifestShape(manifestWith({ title: "" }));
expect(result.ok).toBe(false);
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: FIXTURE_ID,
path: "title",
message: "title must not be empty.",
});
});
it("reports an id that violates the id pattern", () => {
const result = validateFeatureManifestShape(manifestWith({ id: "Bad_ID" }), { manifestId: "ctx-id" });
expect(result.ok).toBe(false);
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: "ctx-id",
path: "id",
message: "id has an invalid format.",
});
});
});
describe("validateFeatureManifestShape enum fields", () => {
it("reports a missing enum field", () => {
const input = clone();
delete input.status;
const result = validateFeatureManifestShape(input);
expect(result.diagnostics).toContainEqual({
code: "missing_required",
manifestId: FIXTURE_ID,
path: "status",
message: "status is required.",
});
});
it("reports a non-string enum value as invalid_type", () => {
const result = validateFeatureManifestShape(manifestWith({ classification: 7 }));
expect(result.diagnostics).toContainEqual({
code: "invalid_type",
manifestId: FIXTURE_ID,
path: "classification",
message: "classification must be a string.",
});
});
it("reports an out-of-set enum value with the allowed list", () => {
const result = validateFeatureManifestShape(manifestWith({ status: "archived" }));
expect(result.diagnostics).toContainEqual({
code: "invalid_enum",
manifestId: FIXTURE_ID,
path: "status",
message: "status must be one of: active, proposed, review-needed.",
});
});
});
describe("validateFeatureManifestShape array fields", () => {
it("reports a missing required array", () => {
const input = clone();
delete input.rationale;
const result = validateFeatureManifestShape(input);
expect(result.diagnostics).toContainEqual({
code: "missing_required",
manifestId: FIXTURE_ID,
path: "rationale",
message: "rationale is required.",
});
});
it("reports a non-array value", () => {
const result = validateFeatureManifestShape(manifestWith({ consumers: "none" }));
expect(result.diagnostics).toContainEqual({
code: "invalid_type",
manifestId: FIXTURE_ID,
path: "consumers",
message: "consumers must be an array.",
});
});
it("reports a non-string array item by index", () => {
const result = validateFeatureManifestShape(manifestWith({ consumers: ["ok", 3] }));
expect(result.diagnostics).toContainEqual({
code: "invalid_item",
manifestId: FIXTURE_ID,
path: "consumers.1",
message: "consumers.1 must be a string.",
});
});
it("reports a dependency id that violates the item pattern", () => {
const result = validateFeatureManifestShape(manifestWith({ dependencies: ["valid-dep", "Bad_Dep"] }));
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: FIXTURE_ID,
path: "dependencies.1",
message: "dependencies.1 has an invalid format.",
});
});
});
describe("validateFeatureManifestShape nested objects and booleans", () => {
it("reports a missing required object and skips its nested checks", () => {
const input = clone();
delete input.boundaries;
const result = validateFeatureManifestShape(input);
const boundaryDiagnostics = result.diagnostics.filter((diagnostic) => diagnostic.path.startsWith("boundaries"));
// Only the top-level missing_required is reported; nested keys are not probed.
expect(boundaryDiagnostics).toEqual([
{ code: "missing_required", manifestId: FIXTURE_ID, path: "boundaries", message: "boundaries is required." },
]);
});
it("reports an array used where an object is required", () => {
const result = validateFeatureManifestShape(manifestWith({ pruning: [] }));
expect(result.diagnostics).toContainEqual({
code: "invalid_type",
manifestId: FIXTURE_ID,
path: "pruning",
message: "pruning must be an object.",
});
});
it("reports a missing boolean inside integration.workers", () => {
const workers = structuredClone(pluginCandidates.integration.workers) as Record<string, unknown>;
delete workers.required;
const integration = { ...pluginCandidates.integration, workers };
const result = validateFeatureManifestShape(manifestWith({ integration }));
expect(result.diagnostics).toContainEqual({
code: "missing_required",
manifestId: FIXTURE_ID,
path: "integration.workers.required",
message: "integration.workers.required is required.",
});
});
it("reports a non-boolean integration.workers.required", () => {
const integration = {
...pluginCandidates.integration,
workers: { ...pluginCandidates.integration.workers, required: "yes" },
};
const result = validateFeatureManifestShape(manifestWith({ integration }));
expect(result.diagnostics).toContainEqual({
code: "invalid_type",
manifestId: FIXTURE_ID,
path: "integration.workers.required",
message: "integration.workers.required must be a boolean.",
});
});
});
describe("validateFeatureManifestShape components", () => {
it("reports a non-array components value", () => {
const result = validateFeatureManifestShape(manifestWith({ components: "crm" }));
expect(result.diagnostics).toContainEqual({
code: "invalid_type",
manifestId: FIXTURE_ID,
path: "components",
message: "components must be an array.",
});
});
it("reports a non-object component entry", () => {
const result = validateFeatureManifestShape(manifestWith({ components: [42] }));
expect(result.diagnostics).toContainEqual({
code: "invalid_item",
manifestId: FIXTURE_ID,
path: "components.0",
message: "components.0 must be an object.",
});
});
it("reports an invalid component id and a non-string notes field", () => {
const components = [{ ...pluginCandidates.components[0], id: "Bad Id", notes: 5 }];
const result = validateFeatureManifestShape(manifestWith({ components }));
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: FIXTURE_ID,
path: "components.0.id",
message: "components.0.id has an invalid format.",
});
expect(result.diagnostics).toContainEqual({
code: "invalid_type",
manifestId: FIXTURE_ID,
path: "components.0.notes",
message: "components.0.notes must be a string.",
});
});
it("accepts a component that supplies a valid optional notes string", () => {
const components = [{ ...pluginCandidates.components[0], notes: "Kept as a single planning note." }];
const result = validateFeatureManifestShape(manifestWith({ components }));
expect(result.ok).toBe(true);
});
});
describe("validateFeatureManifestShape integration section", () => {
it("short-circuits when integration itself is missing", () => {
const input = clone();
delete input.integration;
const result = validateFeatureManifestShape(input);
const integrationDiagnostics = result.diagnostics.filter((diagnostic) => diagnostic.path.startsWith("integration"));
expect(integrationDiagnostics).toEqual([
{ code: "missing_required", manifestId: FIXTURE_ID, path: "integration", message: "integration is required." },
]);
});
it("reports missing nested surfaces and configuration objects", () => {
const integration = structuredClone(pluginCandidates.integration) as Record<string, unknown>;
delete integration.surfaces;
delete integration.configuration;
const result = validateFeatureManifestShape(manifestWith({ integration }));
expect(result.diagnostics).toContainEqual({
code: "missing_required",
manifestId: FIXTURE_ID,
path: "integration.surfaces",
message: "integration.surfaces is required.",
});
expect(result.diagnostics).toContainEqual({
code: "missing_required",
manifestId: FIXTURE_ID,
path: "integration.configuration",
message: "integration.configuration is required.",
});
});
it("rejects prose in permission and audit-event token arrays", () => {
const integration = {
...pluginCandidates.integration,
permissions: ["admin.plugins.* when exposed"],
auditEvents: ["Plugin Enabled"],
};
const result = validateFeatureManifestShape(manifestWith({ integration }));
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: FIXTURE_ID,
path: "integration.permissions.0",
message: "integration.permissions.0 has an invalid format.",
});
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: FIXTURE_ID,
path: "integration.auditEvents.0",
message: "integration.auditEvents.0 has an invalid format.",
});
});
it("accepts wildcard permission tokens and dotted audit events", () => {
const integration = {
...pluginCandidates.integration,
permissions: ["admin.plugins.*", "app.settings.apiKeys.view"],
auditEvents: ["plugin.enabled", "admin.ai.provider_key.updated"],
};
const result = validateFeatureManifestShape(manifestWith({ integration }));
expect(result.ok).toBe(true);
});
});
describe("validateFeatureManifestShape lastReviewed date", () => {
it("rejects a value that does not match the date pattern", () => {
const validation = { ...pluginCandidates.validation, lastReviewed: "May 27 2026" };
const result = validateFeatureManifestShape(manifestWith({ validation }));
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: FIXTURE_ID,
path: "validation.lastReviewed",
message: "validation.lastReviewed must be an ISO date in YYYY-MM-DD format.",
});
});
it("rejects a pattern-shaped but impossible calendar date", () => {
// Matches YYYY-MM-DD but Date() rolls 02-30 forward to 03-02, so the
// ISO round-trip differs and the value is flagged invalid.
const validation = { ...pluginCandidates.validation, lastReviewed: "2026-02-30" };
const result = validateFeatureManifestShape(manifestWith({ validation }));
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: FIXTURE_ID,
path: "validation.lastReviewed",
message: "validation.lastReviewed must be an ISO date in YYYY-MM-DD format.",
});
});
it("rejects a month-out-of-range date that yields NaN", () => {
const validation = { ...pluginCandidates.validation, lastReviewed: "2026-13-01" };
const result = validateFeatureManifestShape(manifestWith({ validation }));
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: FIXTURE_ID,
path: "validation.lastReviewed",
message: "validation.lastReviewed must be an ISO date in YYYY-MM-DD format.",
});
});
it("accepts a well-formed ISO date", () => {
const validation = { ...pluginCandidates.validation, lastReviewed: "2026-06-28" };
const result = validateFeatureManifestShape(manifestWith({ validation }));
expect(result.ok).toBe(true);
});
});
describe("validateFeatureManifestShape manifest id resolution", () => {
it("falls back to a null manifest id when neither context nor input carry one", () => {
const input = clone();
delete input.id;
const result = validateFeatureManifestShape(input);
expect(result.ok).toBe(false);
expect(result.diagnostics).toContainEqual({
code: "missing_required",
manifestId: null,
path: "id",
message: "id is required.",
});
});
it("prefers the context manifest id over a present input id", () => {
const result = validateFeatureManifestShape(manifestWith({ title: "" }), { manifestId: "context-wins" });
expect(result.diagnostics).toContainEqual({
code: "invalid_format",
manifestId: "context-wins",
path: "title",
message: "title must not be empty.",
});
});
});
describe("validateFeatureManifestShape non-object input", () => {
it("returns a single diagnostic with the default path when no context is given", () => {
const result = validateFeatureManifestShape(42);
expect(result).toEqual({
ok: false,
manifest: null,
diagnostics: [{ code: "invalid_type", manifestId: null, path: "$", message: "$ must be an object." }],
});
});
it("honours the context path and manifest id for non-object input", () => {
const result = validateFeatureManifestShape([], { manifestId: "bad", path: "fixture.json" });
expect(result.diagnostics).toEqual([
{ code: "invalid_type", manifestId: "bad", path: "fixture.json", message: "fixture.json must be an object." },
]);
});
});