11import { Octokit } from '@octokit/rest' ;
22import * as core from '@actions/core' ;
33import { context } from '@actions/github' ;
4- import { GenerativeModel } from '@google/generative-ai ' ;
4+ import { GoogleGenAI } from '@google/genai ' ;
55import { IssueLabeling } from './issue-labeling.js' ;
66
77describe ( 'IssueLabeling' , ( ) => {
@@ -13,7 +13,7 @@ describe('IssueLabeling', () => {
1313 get : jasmine . Spy ;
1414 } ;
1515 } ;
16- let mockModel : jasmine . SpyObj < GenerativeModel > ;
16+ let mockAI : any ;
1717 let mockCore : jasmine . SpyObj < typeof core > ;
1818 let issueLabeling : IssueLabeling ;
1919
@@ -41,7 +41,9 @@ describe('IssueLabeling', () => {
4141 return Promise . resolve ( [ { name : 'area: core' } , { name : 'area: router' } , { name : 'bug' } ] ) ;
4242 } ) ;
4343
44- mockModel = jasmine . createSpyObj < GenerativeModel > ( 'GenerativeModel' , [ 'generateContent' ] ) ;
44+ mockAI = {
45+ models : jasmine . createSpyObj ( 'models' , [ 'generateContent' ] ) ,
46+ } ;
4547 mockCore = jasmine . createSpyObj < typeof core > ( 'core' , [
4648 'getInput' ,
4749 'info' ,
@@ -61,7 +63,7 @@ describe('IssueLabeling', () => {
6163 // This is standard for mocking large interfaces like Octokit.
6264 issueLabeling = new IssueLabeling ( mockGit as unknown as Octokit , mockCore ) ;
6365
64- spyOn ( issueLabeling , 'getGenerativeModel ' ) . and . returnValue ( mockModel ) ;
66+ spyOn ( issueLabeling , 'getGenerativeAI ' ) . and . returnValue ( mockAI ) ;
6567 } ) ;
6668
6769 it ( 'should initialize labels correctly' , async ( ) => {
@@ -72,11 +74,9 @@ describe('IssueLabeling', () => {
7274 } ) ;
7375
7476 it ( 'should apply a label when Gemini is confident' , async ( ) => {
75- mockModel . generateContent . and . returnValue (
77+ mockAI . models . generateContent . and . returnValue (
7678 Promise . resolve ( {
77- response : {
78- text : ( ) => 'area: core' ,
79- } as any , // Cast response structure as any because it's deeply nested and hard to construct manually
79+ text : 'area: core' ,
8080 } ) ,
8181 ) ;
8282
@@ -90,11 +90,9 @@ describe('IssueLabeling', () => {
9090 } ) ;
9191
9292 it ( 'should NOT apply a label when Gemini returns "ambiguous"' , async ( ) => {
93- mockModel . generateContent . and . returnValue (
93+ mockAI . models . generateContent . and . returnValue (
9494 Promise . resolve ( {
95- response : {
96- text : ( ) => 'ambiguous' ,
97- } as any ,
95+ text : 'ambiguous' ,
9896 } ) ,
9997 ) ;
10098
@@ -104,11 +102,9 @@ describe('IssueLabeling', () => {
104102 } ) ;
105103
106104 it ( 'should NOT apply a label when Gemini returns an invalid label' , async ( ) => {
107- mockModel . generateContent . and . returnValue (
105+ mockAI . models . generateContent . and . returnValue (
108106 Promise . resolve ( {
109- response : {
110- text : ( ) => 'area: invalid' ,
111- } as any ,
107+ text : 'area: invalid' ,
112108 } ) ,
113109 ) ;
114110
0 commit comments