Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions js/src/framework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,83 @@ describe("framework2 metadata support", () => {
});
});

describe("CodeParameters tags", () => {
test("parameters stores tags correctly", () => {
const project = projects.create({ name: "test-project" });
const tags = ["ci", "production"];

project.parameters.create({
name: "test-parameters",
schema: {
model: {
type: "model",
default: "gpt-5-mini",
},
},
tags,
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parameters = (project as any)._publishableParameters;
expect(parameters).toHaveLength(1);
expect(parameters[0].tags).toEqual(tags);
});

test("toFunctionDefinition includes tags when present", async () => {
const project = projects.create({ name: "test-project" });
const tags = ["ci", "production"];

project.parameters.create({
name: "test-parameters",
schema: {
model: {
type: "model",
default: "gpt-5-mini",
},
},
tags,
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parameters = (project as any)._publishableParameters;
const mockProjectMap = {
resolve: vi.fn().mockResolvedValue("project-123"),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;

const funcDef = await parameters[0].toFunctionDefinition(mockProjectMap);

expect(funcDef.tags).toEqual(tags);
expect(funcDef.name).toBe("test-parameters");
expect(funcDef.project_id).toBe("project-123");
});

test("toFunctionDefinition excludes tags when undefined", async () => {
const project = projects.create({ name: "test-project" });

project.parameters.create({
name: "test-parameters",
schema: {
model: {
type: "model",
default: "gpt-5-mini",
},
},
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const parameters = (project as any)._publishableParameters;
const mockProjectMap = {
resolve: vi.fn().mockResolvedValue("project-123"),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;

const funcDef = await parameters[0].toFunctionDefinition(mockProjectMap);

expect(funcDef.tags).toBeUndefined();
});
});

describe("CodeParameters defaults", () => {
test("toFunctionDefinition initializes data with schema defaults", async () => {
const project = projects.create({ name: "test-project" });
Expand Down
6 changes: 6 additions & 0 deletions js/src/framework2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ export interface ParametersOpts<S extends EvalParameters> {
description?: string;
schema: S;
ifExists?: IfExists;
tags?: string[];
metadata?: Record<string, unknown>;
}

Expand All @@ -596,6 +597,7 @@ export class CodeParameters {
public readonly description?: string;
public readonly schema: EvalParameters;
public readonly ifExists?: IfExists;
public readonly tags?: string[];
public readonly metadata?: Record<string, unknown>;

constructor(
Expand All @@ -606,6 +608,7 @@ export class CodeParameters {
description?: string;
schema: EvalParameters;
ifExists?: IfExists;
tags?: string[];
metadata?: Record<string, unknown>;
},
) {
Expand All @@ -615,6 +618,7 @@ export class CodeParameters {
this.description = opts.description;
this.schema = opts.schema;
this.ifExists = opts.ifExists;
this.tags = opts.tags;
this.metadata = opts.metadata;
}

Expand All @@ -634,6 +638,7 @@ export class CodeParameters {
__schema: schema,
},
if_exists: this.ifExists,
tags: this.tags,
metadata: this.metadata,
};
}
Expand All @@ -651,6 +656,7 @@ class ParametersBuilder {
description: opts.description,
schema: opts.schema,
ifExists: opts.ifExists,
tags: opts.tags,
metadata: opts.metadata,
});

Expand Down
Loading