diff --git a/.agents/skills/stitch-sdk-domain-design/SKILL.md b/.agents/skills/stitch-sdk-domain-design/SKILL.md index 0fb4becf..f36ee130 100644 --- a/.agents/skills/stitch-sdk-domain-design/SKILL.md +++ b/.agents/skills/stitch-sdk-domain-design/SKILL.md @@ -21,7 +21,7 @@ This skill teaches you how to perform **Stage 2** of the generation pipeline: re A valid `domain-map.json` with two sections: `classes` and `bindings`, validated by `ir-schema.ts`. > [!IMPORTANT] -> Your output is validated **twice** by the codegen: structurally (Zod IR schema) and semantically (projection steps verified against `outputSchema` from the tools-manifest). +> Your output is validated **twice** by the codegen: structurally (Zod IR schema) and semantically (sent args verified against `inputSchema`, projection steps verified against `outputSchema` from the tools-manifest). --- @@ -84,6 +84,18 @@ Optional params use `"optional": true`. Renamed params use `"rename": "newName"` A `"default": "VALUE"` (requires `optional: true`) is sent when the caller omits the value: `deviceType: options?.deviceType ?? "DESKTOP"`. +A `computed` template reads `{field}` from the arg of that name, or from +`this.field` when there is none — so a self field needs no arg to be used in a +template. A param marked `"templateOnly": true` stays in the method signature +and feeds the template, but is never sent: `getScreen(screenId)` sends only +``{ name: `projects/${this.projectId}/screens/${screenId}` }``. + +> [!IMPORTANT] +> **Every arg that is sent must be declared by the tool's `inputSchema`.** The +> server rejects undeclared fields ("Request contains an invalid argument"), so +> codegen fails on them. When a re-captured manifest drops an input field, +> remove the arg, or mark the param `templateOnly` if it builds a `name`. + > [!IMPORTANT] > **Method signature shape (D12):** required params are positional, in IR > order; ALL optional params are emitted into a single trailing diff --git a/packages/sdk/README.md b/packages/sdk/README.md index 32a70541..44f8b1c0 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -179,8 +179,7 @@ import { StitchToolClient, GetScreenResponse } from "@google/stitch-sdk"; const client = new StitchToolClient({ apiKey: "..." }); const result = await client.callTool("get_screen", { - projectId: "...", - screenId: "...", + name: "projects/.../screens/...", }); await client.close(); ``` diff --git a/packages/sdk/generated/domain-map.json b/packages/sdk/generated/domain-map.json index 8b280bb5..e84291c2 100644 --- a/packages/sdk/generated/domain-map.json +++ b/packages/sdk/generated/domain-map.json @@ -269,11 +269,9 @@ "class": "Project", "method": "getScreen", "args": { - "projectId": { - "from": "self" - }, "screenId": { - "from": "param" + "from": "param", + "templateOnly": true }, "name": { "from": "computed", @@ -291,12 +289,6 @@ "class": "Screen", "method": "getHtmlUrl", "args": { - "projectId": { - "from": "self" - }, - "screenId": { - "from": "self" - }, "name": { "from": "computed", "template": "projects/{projectId}/screens/{screenId}" @@ -332,12 +324,6 @@ "class": "Screen", "method": "getImageUrl", "args": { - "projectId": { - "from": "self" - }, - "screenId": { - "from": "self" - }, "name": { "from": "computed", "template": "projects/{projectId}/screens/{screenId}" diff --git a/packages/sdk/generated/src/designsystem.ts b/packages/sdk/generated/src/designsystem.ts index 94e5db28..66ed1ef3 100644 --- a/packages/sdk/generated/src/designsystem.ts +++ b/packages/sdk/generated/src/designsystem.ts @@ -3,7 +3,7 @@ DO NOT EDIT — changes will be overwritten. Source: tools-manifest.json (sha256:88ec3dfa066c...) - domain-map.json (sha256:a6177cc7e2f4...) + domain-map.json (sha256:55a31393745c...) */ import { type StitchToolClientSpec } from "../../src/spec/client.js"; import { StitchError } from "../../src/spec/errors.js"; diff --git a/packages/sdk/generated/src/index.ts b/packages/sdk/generated/src/index.ts index 24cfa1c6..c562103f 100644 --- a/packages/sdk/generated/src/index.ts +++ b/packages/sdk/generated/src/index.ts @@ -3,7 +3,7 @@ DO NOT EDIT — changes will be overwritten. Source: tools-manifest.json (sha256:88ec3dfa066c...) - domain-map.json (sha256:a6177cc7e2f4...) + domain-map.json (sha256:55a31393745c...) */ export { Stitch } from "./stitch.js"; export { Project } from "./project.js"; diff --git a/packages/sdk/generated/src/project.ts b/packages/sdk/generated/src/project.ts index 953fb192..5ebbf7f1 100644 --- a/packages/sdk/generated/src/project.ts +++ b/packages/sdk/generated/src/project.ts @@ -3,7 +3,7 @@ DO NOT EDIT — changes will be overwritten. Source: tools-manifest.json (sha256:88ec3dfa066c...) - domain-map.json (sha256:a6177cc7e2f4...) + domain-map.json (sha256:55a31393745c...) */ import { type StitchToolClientSpec } from "../../src/spec/client.js"; import { StitchError } from "../../src/spec/errors.js"; @@ -209,8 +209,6 @@ export class Project { async getScreen(screenId: string): Promise { try { const raw = await this.client.callTool("get_screen", { - projectId: this.projectId, - screenId, name: `projects/${this.projectId}/screens/${screenId}`, }); return this.client.entities.resolve(Screen, ["projectId", "screenId"], { diff --git a/packages/sdk/generated/src/responses.generated.ts b/packages/sdk/generated/src/responses.generated.ts index 40bb79ba..4c8bafe3 100644 --- a/packages/sdk/generated/src/responses.generated.ts +++ b/packages/sdk/generated/src/responses.generated.ts @@ -33,7 +33,7 @@ import { DO NOT EDIT — changes will be overwritten. Source: tools-manifest.json (sha256:88ec3dfa066c...) - domain-map.json (sha256:a6177cc7e2f4...) + domain-map.json (sha256:55a31393745c...) */ /** Response message for create_project. */ diff --git a/packages/sdk/generated/src/screen.ts b/packages/sdk/generated/src/screen.ts index 1c1fab17..d20ea4d3 100644 --- a/packages/sdk/generated/src/screen.ts +++ b/packages/sdk/generated/src/screen.ts @@ -3,7 +3,7 @@ DO NOT EDIT — changes will be overwritten. Source: tools-manifest.json (sha256:88ec3dfa066c...) - domain-map.json (sha256:a6177cc7e2f4...) + domain-map.json (sha256:55a31393745c...) */ import { type StitchToolClientSpec } from "../../src/spec/client.js"; import { StitchError } from "../../src/spec/errors.js"; @@ -261,8 +261,6 @@ export class Screen { try { const raw = await this.client.callTool("get_screen", { - projectId: this.projectId, - screenId: this.screenId, name: `projects/${this.projectId}/screens/${this.screenId}`, }); // writeBack: merge the response into this.data so the next call hits the cache @@ -293,8 +291,6 @@ export class Screen { try { const raw = await this.client.callTool("get_screen", { - projectId: this.projectId, - screenId: this.screenId, name: `projects/${this.projectId}/screens/${this.screenId}`, }); // writeBack: merge the response into this.data so the next call hits the cache diff --git a/packages/sdk/generated/src/stitch.ts b/packages/sdk/generated/src/stitch.ts index 65ddd510..61184ce7 100644 --- a/packages/sdk/generated/src/stitch.ts +++ b/packages/sdk/generated/src/stitch.ts @@ -3,7 +3,7 @@ DO NOT EDIT — changes will be overwritten. Source: tools-manifest.json (sha256:88ec3dfa066c...) - domain-map.json (sha256:a6177cc7e2f4...) + domain-map.json (sha256:55a31393745c...) */ import { type StitchToolClientSpec } from "../../src/spec/client.js"; import { StitchError } from "../../src/spec/errors.js"; diff --git a/packages/sdk/generated/src/tool-definitions.ts b/packages/sdk/generated/src/tool-definitions.ts index 1bdbc83f..1a75a7ac 100644 --- a/packages/sdk/generated/src/tool-definitions.ts +++ b/packages/sdk/generated/src/tool-definitions.ts @@ -3,7 +3,7 @@ DO NOT EDIT — changes will be overwritten. Source: tools-manifest.json (sha256:88ec3dfa066c...) - domain-map.json (sha256:a6177cc7e2f4...) + domain-map.json (sha256:55a31393745c...) */ /** JSON Schema property descriptor for a tool parameter. */ export interface ToolPropertySchema { diff --git a/packages/sdk/generated/src/types.generated.ts b/packages/sdk/generated/src/types.generated.ts index 06a680a7..9f47e077 100644 --- a/packages/sdk/generated/src/types.generated.ts +++ b/packages/sdk/generated/src/types.generated.ts @@ -3,7 +3,7 @@ DO NOT EDIT — changes will be overwritten. Source: tools-manifest.json (sha256:88ec3dfa066c...) - domain-map.json (sha256:a6177cc7e2f4...) + domain-map.json (sha256:55a31393745c...) */ /** A component style token in a design system. */ diff --git a/packages/sdk/generated/stitch-sdk.lock b/packages/sdk/generated/stitch-sdk.lock index b139945d..90d1f6d5 100644 --- a/packages/sdk/generated/stitch-sdk.lock +++ b/packages/sdk/generated/stitch-sdk.lock @@ -1,10 +1,10 @@ { "schemaVersion": 1, "generated": { - "generatedAt": "2026-09-30T23:36:31.707Z", - "sourceHash": "sha256:e4065faf73314496863dc38dae0ba79f4375834c975a4d3e03bfe46bc7d6183c", + "generatedAt": "2026-10-22T02:32:47.218Z", + "sourceHash": "sha256:9afa649b93e650c8fcd905b42c1f98dee761700e769a2ee7d4744e9c1f73d4f8", "manifestHash": "sha256:88ec3dfa066ce5060be236b0a5c0b5fb51671a7dd60d05556c028e6c4c8f0e1c", - "domainMapHash": "sha256:a6177cc7e2f44d2d536928d4e0ae7bd51ed2dd3393235787216b976498c3b1b2", + "domainMapHash": "sha256:55a31393745c750400c7e172cf8c3dd65560d587ded20da79591dfc5e4de191c", "fileCount": 8, "repairedTools": [ "generate_screen_from_text", @@ -13,8 +13,8 @@ ] }, "domainMap": { - "generatedAt": "2026-09-23T18:36:09.460Z", - "sourceHash": "sha256:a6177cc7e2f44d2d536928d4e0ae7bd51ed2dd3393235787216b976498c3b1b2", + "generatedAt": "2026-10-22T02:32:47.218Z", + "sourceHash": "sha256:55a31393745c750400c7e172cf8c3dd65560d587ded20da79591dfc5e4de191c", "manifestHash": "sha256:88ec3dfa066ce5060be236b0a5c0b5fb51671a7dd60d05556c028e6c4c8f0e1c", "classCount": 4, "bindingCount": 15 diff --git a/packages/sdk/src/download-handler.ts b/packages/sdk/src/download-handler.ts index e6ec6fc7..aaad3d4e 100644 --- a/packages/sdk/src/download-handler.ts +++ b/packages/sdk/src/download-handler.ts @@ -176,9 +176,8 @@ export class DownloadAssetsHandler implements DownloadAssetsSpec { let htmlUrl = screen.htmlCode?.downloadUrl; if (!htmlUrl) { try { + // get_screen accepts only `name`; extra fields are rejected const raw = await this.client.callTool("get_screen", { - projectId, - screenId: screenId, name: `projects/${projectId}/screens/${screenId}`, }); htmlUrl = (raw as any)?.htmlCode?.downloadUrl; diff --git a/packages/sdk/test/unit/download.test.ts b/packages/sdk/test/unit/download.test.ts index d4d56421..9fd51954 100644 --- a/packages/sdk/test/unit/download.test.ts +++ b/packages/sdk/test/unit/download.test.ts @@ -460,6 +460,44 @@ describe("DownloadAssetsHandler", () => { }, ]); }); + + it("falls back to get_screen with only the resource name when a screen has no htmlCode", async () => { + const mockClient = { callTool: vi.fn() } as any; + mockClient.callTool.mockImplementation((tool: string) => { + if (tool === "list_screens") { + return Promise.resolve({ + screens: [{ id: "s1", name: "projects/p1/screens/s1" }], + }); + } + if (tool === "get_screen") { + return Promise.resolve({ + htmlCode: { downloadUrl: "https://fake/s1.html" }, + }); + } + return Promise.resolve({}); + }); + vi.stubGlobal( + "fetch", + vi.fn().mockResolvedValue({ + ok: true, + text: () => Promise.resolve(""), + }), + ); + + const handler = new DownloadAssetsHandler(mockClient); + const result = await handler.execute({ + projectId: "p1", + outputDir: "/tmp/out", + }); + + // get_screen accepts only `name`; any extra field is rejected (#381) + expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", { + name: "projects/p1/screens/s1", + }); + expect(result.success).toBe(true); + if (!result.success) return; + expect(result.downloadedScreens.map((s) => s.screenId)).toEqual(["s1"]); + }); }); describe("sanitizeFilename", () => { diff --git a/packages/sdk/test/unit/sdk.test.ts b/packages/sdk/test/unit/sdk.test.ts index 34bb2062..f5ff4c40 100644 --- a/packages/sdk/test/unit/sdk.test.ts +++ b/packages/sdk/test/unit/sdk.test.ts @@ -70,9 +70,8 @@ describe("SDK Unit Tests", () => { const result = await screen.getHtmlUrl(); + // get_screen accepts only `name`; any extra field is rejected (#381) expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", { - projectId: projectId, - screenId: "screen-123", name: "projects/proj-123/screens/screen-123", }); expect(result).toBe("https://api.example.com/html"); @@ -105,8 +104,6 @@ describe("SDK Unit Tests", () => { const result = await screen.getImageUrl(); expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", { - projectId: projectId, - screenId: "screen-123", name: "projects/proj-123/screens/screen-123", }); expect(result).toBe("https://api.example.com/image.png"); @@ -127,8 +124,6 @@ describe("SDK Unit Tests", () => { const err = await screen.getHtmlUrl().catch((e: unknown) => e); expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", { - projectId: projectId, - screenId: "screen-123", name: "projects/proj-123/screens/screen-123", }); // Missing artifact is NOT_FOUND, never a silent empty string @@ -564,6 +559,28 @@ describe("SDK Unit Tests", () => { expect(result).toEqual([]); }); + it("getScreen should call get_screen with only the resource name", async () => { + const project = mockClient.entities.resolve( + Project, + ["projectId"], + projectId, + ); + + (mockClient.callTool as Mock).mockResolvedValue({ + name: `projects/${projectId}/screens/s-42`, + title: "Checkout", + }); + + const screen = await project.getScreen("s-42"); + + expect(mockClient.callTool).toHaveBeenCalledWith("get_screen", { + name: `projects/${projectId}/screens/s-42`, + }); + expect(screen).toBeInstanceOf(Screen); + expect(screen.projectId).toBe(projectId); + expect(screen.screenId).toBe("s-42"); + }); + it("generate should throw StitchError on failure", async () => { const project = mockClient.entities.resolve( Project, diff --git a/scripts/check-skill-consistency.ts b/scripts/check-skill-consistency.ts index 7c2ffb2b..26a5ffba 100644 --- a/scripts/check-skill-consistency.ts +++ b/scripts/check-skill-consistency.ts @@ -71,6 +71,7 @@ const REQUIRED_TOKENS = [ "rename", "default", "template", + "templateOnly", // Class config "constructorParams", "reference", @@ -114,6 +115,10 @@ check( ArgSpec.safeParse({ from: "param", optional: true, default: "D" }).success, "param default is live", ); +check( + ArgSpec.safeParse({ from: "param", templateOnly: true }).success, + "param templateOnly is live", +); check( !DomainClassConfig.safeParse({ description: "d", diff --git a/scripts/generate-sdk.ts b/scripts/generate-sdk.ts index a74cffa0..f77d5bcd 100644 --- a/scripts/generate-sdk.ts +++ b/scripts/generate-sdk.ts @@ -242,6 +242,50 @@ function lintUnbounded( } } +// ── Input Schema Validation ─────────────────────────────────── + +/** + * Validate that every arg a binding SENDS is declared by the tool's + * inputSchema. The server rejects undeclared fields ("Request contains an + * invalid argument"), so this is a codegen error, not a runtime surprise: + * a re-captured manifest that drops an input field fails here. + * + * `templateOnly` params are never sent, so they are exempt — but they must + * feed a `computed` template, otherwise they are dead method parameters. + */ +export function validateArgs( + args: Record, + inputSchema: ToolSchema | null | undefined, + bindingLabel: string, +): void { + const templates = Object.values(args).flatMap((spec) => + spec.from === "computed" ? [spec.template] : [], + ); + const props = inputSchema?.properties; + + for (const [name, spec] of Object.entries(args)) { + if (spec.from === "param" && spec.templateOnly) { + if (!templates.some((t) => t.includes(`{${name}}`))) { + throw new Error( + `❌ Binding "${bindingLabel}": templateOnly param "${name}" is not ` + + `referenced by any computed template.`, + ); + } + continue; + } + if (!props) continue; // Can't validate (schema is too loose) + if (!(name in props)) { + throw new Error( + `❌ Binding "${bindingLabel}": arg "${name}" is not declared in the ` + + `tool's inputSchema.\n` + + ` Available properties: ${Object.keys(props).join(", ")}\n` + + ` Fix: remove the arg, or mark a param "templateOnly" if it only ` + + `feeds a computed template.`, + ); + } + } +} + // ── Projection Code Emission ────────────────────────────────── /** @@ -626,6 +670,8 @@ export function generateArgsObject(args: Record): string { const field = spec.field || name; entries.push(`${name}: [this.${field}]`); } else if (spec.from === "param") { + // templateOnly params only feed computed templates — never sent + if (spec.templateOnly) continue; const paramName = spec.rename || name; // Optional params live on the trailing options object (D12); // a declared default is applied when the caller omits the value. @@ -872,6 +918,19 @@ async function main() { console.log("🔍 Validating binding IR..."); console.log(" ✓ IR schema valid"); + // Validate sent args against input schemas + console.log("🔍 Validating args against input schemas..."); + for (const binding of domainMap.bindings) { + const tool = manifest.find((t) => t.name === binding.tool); + if (!tool) continue; + validateArgs( + binding.args, + tool.inputSchema, + `${binding.class}.${binding.method}`, + ); + } + console.log(" ✓ All sent args declared by tool input schemas"); + // Validate projections against output schemas console.log("🔍 Validating projections against output schemas..."); const lintWarnings: string[] = []; diff --git a/scripts/ir-schema.ts b/scripts/ir-schema.ts index 937a8cad..d30407c7 100644 --- a/scripts/ir-schema.ts +++ b/scripts/ir-schema.ts @@ -90,6 +90,13 @@ const ArgParam = z * on a required param is a contradiction. */ default: z.string().optional(), + /** + * Method parameter that only feeds a `computed` template and is NOT + * sent to the tool. For tools that take a resource `name` built from + * the caller's IDs (get_screen accepts only `name`, and rejects any + * extra field). + */ + templateOnly: z.boolean().optional(), }) .strict() .refine((data) => data.default === undefined || data.optional === true, { diff --git a/scripts/refresh-response-fixtures.ts b/scripts/refresh-response-fixtures.ts index 9d0d92f9..de6f5387 100644 --- a/scripts/refresh-response-fixtures.ts +++ b/scripts/refresh-response-fixtures.ts @@ -83,8 +83,6 @@ await record("list_screens", { projectId }); await record("list_design_systems", { projectId }); if (screenId) { await record("get_screen", { - projectId, - screenId, name: `projects/${projectId}/screens/${screenId}`, }); } else { diff --git a/scripts/test/__snapshots__/codegen-snapshot.test.ts.snap b/scripts/test/__snapshots__/codegen-snapshot.test.ts.snap index 533bbf65..7bf65641 100644 --- a/scripts/test/__snapshots__/codegen-snapshot.test.ts.snap +++ b/scripts/test/__snapshots__/codegen-snapshot.test.ts.snap @@ -83,6 +83,7 @@ import { StitchError } from "../../src/spec/errors.js"; import { GizmoInput, File, Component, GizmoData } from "./types.generated.js"; import { GetGizmoAssetResponse, + GetWidgetResponse, SpawnWidgetsResponse, } from "./responses.generated.js"; import { Widget } from "./widget.js"; @@ -175,6 +176,24 @@ export class Gizmo { } } + /** + * Gets a widget by resource name. + * Tool: get_widget + */ + async getWidget(widgetId: string): Promise { + try { + const raw = await this.client.callTool("get_widget", { + name: \`gizmos/\${this.gizmoId}/widgets/\${widgetId}\`, + }); + return this.client.entities.resolve(Widget, ["gizmoId", "widgetId"], { + ...raw, + gizmoId: this.gizmoId, + }); + } catch (error) { + throw StitchError.fromUnknown(error); + } + } + /** * Spawns widgets from a prompt. * Tool: spawn_widgets @@ -416,6 +435,12 @@ export interface GetGizmoAssetResponse { title?: string; } +/** Response message for get_widget. */ +export interface GetWidgetResponse { + name?: string; + label?: string; +} + /** Response message for spawn_widgets. */ export interface SpawnWidgetsResponse { outputComponents?: Component[]; diff --git a/scripts/test/codegen-snapshot.test.ts b/scripts/test/codegen-snapshot.test.ts index d1fda13a..5e723faa 100644 --- a/scripts/test/codegen-snapshot.test.ts +++ b/scripts/test/codegen-snapshot.test.ts @@ -287,6 +287,25 @@ describe("fixture output behavior", () => { expect(url).toBe("https://x/y.html"); }); + test("templateOnly params feed the computed name but are never sent", async () => { + const { Gizmo } = await import(join(outDir, "gizmo.ts")); + const client = makeFakeClient(); + client.nextResponse = { name: "gizmos/g-9/widgets/w-4", label: "Knob" }; + + const gizmo = client.entities.resolve(Gizmo, ["gizmoId"], { + gizmoId: "g-9", + }); + const widget = await gizmo.getWidget("w-4"); + + // Exactly the declared input: no gizmoId/widgetId beside `name` (#381) + expect(client.calls[0]).toEqual({ + tool: "get_widget", + args: { name: "gizmos/g-9/widgets/w-4" }, + }); + expect(widget.gizmoId).toBe("g-9"); + expect(widget.widgetId).toBe("w-4"); + }); + test("cache projection short-circuits without an API call", async () => { const { Gizmo } = await import(join(outDir, "gizmo.ts")); const client = makeFakeClient(); diff --git a/scripts/test/fixtures/fixture-domain-map.json b/scripts/test/fixtures/fixture-domain-map.json index 8755a8d3..16dc510e 100644 --- a/scripts/test/fixtures/fixture-domain-map.json +++ b/scripts/test/fixtures/fixture-domain-map.json @@ -80,6 +80,22 @@ "description": "Use cached download URL when present" } }, + { + "tool": "get_widget", + "class": "Gizmo", + "method": "getWidget", + "args": { + "widgetId": { "from": "param", "templateOnly": true }, + "name": { + "from": "computed", + "template": "gizmos/{gizmoId}/widgets/{widgetId}" + } + }, + "returns": { + "class": "Widget", + "projection": [] + } + }, { "tool": "spawn_widgets", "class": "Gizmo", diff --git a/scripts/test/fixtures/fixture-manifest.json b/scripts/test/fixtures/fixture-manifest.json index d8ff21a2..d4de4bea 100644 --- a/scripts/test/fixtures/fixture-manifest.json +++ b/scripts/test/fixtures/fixture-manifest.json @@ -72,6 +72,27 @@ } } }, + { + "name": "get_widget", + "description": "Gets a widget by resource name.", + "inputSchema": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Resource name only (regression for get_screen, #381)" + } + }, + "required": ["name"] + }, + "outputSchema": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "label": { "type": "string" } + } + } + }, { "name": "spawn_widgets", "description": "Spawns widgets from a prompt.", diff --git a/scripts/test/generate-sdk.test.ts b/scripts/test/generate-sdk.test.ts index d99fd1e4..25f19c5f 100644 --- a/scripts/test/generate-sdk.test.ts +++ b/scripts/test/generate-sdk.test.ts @@ -32,6 +32,7 @@ import { generateArgsObject, generateMethodParams, resolveRef, + validateArgs, } from "../generate-sdk.js"; import type { ProjectionStep } from "../ir-schema.js"; @@ -577,6 +578,19 @@ describe("generateArgsObject", () => { expect(result).toContain("projects/"); }); + test("templateOnly param → interpolated into the template, never sent", () => { + const result = generateArgsObject({ + screenId: { from: "param", templateOnly: true }, + name: { + from: "computed", + template: "projects/{projectId}/screens/{screenId}", + }, + }); + expect(result).toBe( + "{ name: `projects/${this.projectId}/screens/${screenId}` }", + ); + }); + test("mixed args", () => { const result = generateArgsObject({ projectId: { from: "self" }, @@ -587,6 +601,69 @@ describe("generateArgsObject", () => { }); }); +// ── validateArgs ──────────────────────────────────────────── + +describe("validateArgs", () => { + // get_screen's live inputSchema: `name` only (#381) + const getScreenInput = { + type: "object", + properties: { name: { type: "string" } }, + required: ["name"], + }; + const nameTemplate = { + from: "computed" as const, + template: "projects/{projectId}/screens/{screenId}", + }; + + test("accepts args declared by the inputSchema, plus templateOnly params", () => { + expect(() => + validateArgs( + { + screenId: { from: "param", templateOnly: true }, + name: nameTemplate, + }, + getScreenInput, + "Project.getScreen", + ), + ).not.toThrow(); + }); + + test("rejects a sent arg the inputSchema does not declare", () => { + expect(() => + validateArgs( + { + projectId: { from: "self" }, + screenId: { from: "self" }, + name: nameTemplate, + }, + getScreenInput, + "Screen.getHtmlUrl", + ), + ).toThrow( + /Screen\.getHtmlUrl.*"projectId" is not declared[\s\S]*Available properties: name/, + ); + }); + + test("rejects a templateOnly param that no computed template references", () => { + expect(() => + validateArgs( + { + screenId: { from: "param", templateOnly: true }, + name: { from: "computed", template: "projects/{projectId}" }, + }, + getScreenInput, + "Project.getScreen", + ), + ).toThrow(/templateOnly param "screenId"/); + }); + + test("skips validation when the inputSchema declares no properties", () => { + expect(() => + validateArgs({ anything: { from: "param" } }, { type: "object" }, "T.m"), + ).not.toThrow(); + }); +}); + // ── validateProjection: strict array semantics + lint [V1_PLAN §1.2] ── describe("validateProjection strict semantics", () => { diff --git a/scripts/test/ir-schema.test.ts b/scripts/test/ir-schema.test.ts index 0336b2e8..d5c2ce33 100644 --- a/scripts/test/ir-schema.test.ts +++ b/scripts/test/ir-schema.test.ts @@ -124,6 +124,16 @@ describe("ArgSpec", () => { expect(result.success).toBe(true); }); + test("accepts templateOnly param arg", () => { + const result = ArgSpec.safeParse({ from: "param", templateOnly: true }); + expect(result.success).toBe(true); + }); + + test("rejects templateOnly on a self arg (self fields reach templates without an arg)", () => { + const result = ArgSpec.safeParse({ from: "self", templateOnly: true }); + expect(result.success).toBe(false); + }); + test("rejects unknown 'from' variant", () => { const result = ArgSpec.safeParse({ from: "magic" }); expect(result.success).toBe(false);