@nanobpm/nano-workforce 0.159.1 → 0.161.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ // test/deliveryGraphVocabulary-mcp.test.ts — S3/#609 surface guard.
2
+ //
3
+ // Verifies the `getDeliveryGraphVocabulary` READ tool is actually VISIBLE to agents over MCP (the
4
+ // Urban runtime projects `openapi.yaml` into MCP tools, ADR 0067 — zero MCP server code in nwf) and
5
+ // that its operation conforms to S0's self-contained convention: a `$ref`-free `200` response schema
6
+ // with an explicit `type: object` and a worked `example`. Drives the REAL projector (`collectOperations`
7
+ // from `@nanobpm/urban/toolkit`) over the checked-in spec, exactly like `test/mcp-tool-schemas.test.ts`,
8
+ // so a regression (the op excluded, or a re-leaked `$ref`/dropped example) fails the build.
9
+ import { readFileSync } from "node:fs";
10
+ import { test } from "node:test";
11
+ import { collectOperations, parseSpec } from "@nanobpm/urban/toolkit";
12
+ import { parse as parseYaml } from "yaml";
13
+ import assert from "node:assert/strict";
14
+ import { deliveryGraphVocabulary } from "../app/deliveryGraphVocabulary.ts";
15
+
16
+ const ROOT = decodeURIComponent(new URL("../", import.meta.url).pathname);
17
+ const SPEC_TEXT = readFileSync(`${ROOT}openapi.yaml`, "utf8");
18
+ const SPEC = parseSpec(SPEC_TEXT);
19
+ const OP_ID = "getDeliveryGraphVocabulary";
20
+
21
+ const isRecord = (v: unknown): v is Record<string, unknown> =>
22
+ typeof v === "object" && v !== null && !Array.isArray(v);
23
+
24
+ /** Every `$ref` reachable in a schema, JSON-path-qualified for the failure message. */
25
+ function findRefs(node: unknown, path: string, out: string[]): void {
26
+ if (Array.isArray(node)) {
27
+ node.forEach((n, i) => findRefs(n, `${path}[${i}]`, out));
28
+ return;
29
+ }
30
+ if (!isRecord(node)) return;
31
+ for (const [k, v] of Object.entries(node)) {
32
+ if (k === "$ref" && typeof v === "string") out.push(`${path}.$ref -> ${v}`);
33
+ else findRefs(v, `${path}.${k}`, out);
34
+ }
35
+ }
36
+
37
+ test("getDeliveryGraphVocabulary is projected onto the MCP tool surface (not excluded)", () => {
38
+ const op = collectOperations(SPEC).find((o) => o.operationId === OP_ID);
39
+ assert(op, `${OP_ID} must be a declared operation the projector can see`);
40
+ assert(!op!.mcpExcluded, `${OP_ID} must be visible over MCP (no x-mcp exclusion)`);
41
+ });
42
+
43
+ test("the getDeliveryGraphVocabulary 200 response schema is $ref-free with an explicit type + example", () => {
44
+ const doc = parseYaml(SPEC_TEXT) as Record<string, any>;
45
+ const schema = doc?.paths?.["/delivery-graph/vocabulary"]?.get?.responses?.["200"]?.content?.["application/json"]?.schema;
46
+ assert(isRecord(schema), "the 200 response must carry an inline application/json schema");
47
+ assert.equal(schema.type, "object", "the response schema must declare an explicit type: object");
48
+ assert("example" in schema, "the response schema must embed a worked example (S0 self-contained convention)");
49
+ const refs: string[] = [];
50
+ findRefs(schema, `${OP_ID}.responses.200`, refs);
51
+ assert(refs.length === 0, `${OP_ID}: 200 response schema leaks $ref(s): ${refs.join(", ")}`);
52
+ });
53
+
54
+ test("the served payload matches the response schema's required keys (data ⇄ contract)", () => {
55
+ const doc = parseYaml(SPEC_TEXT) as Record<string, any>;
56
+ const schema = doc.paths["/delivery-graph/vocabulary"].get.responses["200"].content["application/json"].schema;
57
+ const required: string[] = schema.required ?? [];
58
+ const payload = deliveryGraphVocabulary() as Record<string, unknown>;
59
+ for (const key of required) {
60
+ assert(key in payload, `served vocabulary is missing required schema key '${key}'`);
61
+ }
62
+ });