From 5bc9ed10db0eaacd7ec76f8b5baa24fa4a3e8d73 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Feb 13 2026 21:42:54 +0000
Subject: [PATCH 1/4] simulate cg_import in fakepolicy


---

diff --git a/devtools/fakepolicy b/devtools/fakepolicy
index af59baa..7498b57 100755
--- a/devtools/fakepolicy
+++ b/devtools/fakepolicy
@@ -127,6 +127,12 @@ def get_args():
     subp.add_argument('--action', help='select action', default='add')
     subp.add_argument('--force', help='select force setting', action='store_true', default=False)
     subp.set_defaults(func=add_pkg_params)
+
+    subp = subparsers.add_parser('cg-import', help='simulate policy for cg import')
+    subp.add_argument('-b', '--build', help='fetch data from existing build')
+    subp.add_argument('-m', '--metadata', help='fetch data from json file')
+    subp.add_argument('--metadata-only', help='', action='store_true', default=False)
+    subp.set_defaults(func=cg_import_params)
     ## end subcommands ##
 
     args = parser.parse_args()
@@ -376,6 +382,26 @@ def add_pkg_params(args, session):
     return policy, data
 
 
+def cg_import_params(args, session):
+    # simulate policy for cg imports
+    policy = 'cg_import'
+    data = {'metadata_only': bool(args.metadata_only)}
+
+    if args.build:
+        # pull metadata from existing build
+        binfo = session.getBuild(args.build, strict=True)
+        for key in ('name', 'version', 'release', 'source', 'draft'):
+            data[key] = binfo[key]
+        data['btypes'] = list(session.getBuildType(binfo['id']))
+        data['cg_list'] = [binfo['cg_id']]
+
+    elif args.metadata:
+        # TODO
+        raise NotImplementedError()
+
+    return policy, data
+
+
 def do_mocks(session, plugins):
     # a number of internal functions are directly exported
     simple_exports = [

From 1148af5b42354a40a71d13fb59e98beba33ef55e Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Feb 13 2026 22:30:57 +0000
Subject: [PATCH 2/4] also work with metadata file


---

diff --git a/devtools/fakepolicy b/devtools/fakepolicy
index 7498b57..6f916e7 100755
--- a/devtools/fakepolicy
+++ b/devtools/fakepolicy
@@ -389,15 +389,37 @@ def cg_import_params(args, session):
 
     if args.build:
         # pull metadata from existing build
-        binfo = session.getBuild(args.build, strict=True)
+        if args.build.isdigit():
+            binfo = session.getBuild(int(args.build), strict=True)
+        else:
+            binfo = session.getBuild(args.build, strict=True)
         for key in ('name', 'version', 'release', 'source', 'draft'):
             data[key] = binfo[key]
         data['btypes'] = list(session.getBuildType(binfo['id']))
         data['cg_list'] = [binfo['cg_id']]
 
     elif args.metadata:
-        # TODO
-        raise NotImplementedError()
+        metadata = koji.load_json(args.metadata)
+        build = metadata['build']
+        for key in ('name', 'version', 'release'):
+            data[key] = build[key]
+        for key in ('source', 'draft'):
+            data[key] = build.get(key)
+        typeinfo = build.get('extra', {}).get('typeinfo', {})
+        for btype in ('maven', 'win', 'image'):
+            # legacy types can also be at top level of extra
+            if btype in build['extra']:
+                typeinfo.setdefault(btype, build['extra'][btype])
+        data['btypes'] = list(typeinfo)
+        # for metadata, the cg id comes from the buildroot list
+        cg_id = None
+        for brdata in metadata['buildroots']:
+            cginfo = brdata['content_generator']
+            cg = kojihub.lookup_name('content_generator', cginfo['name'], strict=True)
+            # ^ this relies on our mocks
+            # just take the first one. we're not validating
+            cg_id = cg['id']
+        data['cg_list'] = [cg_id]
 
     return policy, data
 

From d83d2c8db0d6aa275ace15eb1a31947fc985b688 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Feb 13 2026 23:18:25 +0000
Subject: [PATCH 3/4] fix metadata_only check


---

diff --git a/devtools/fakepolicy b/devtools/fakepolicy
index 6f916e7..fa02808 100755
--- a/devtools/fakepolicy
+++ b/devtools/fakepolicy
@@ -385,7 +385,7 @@ def add_pkg_params(args, session):
 def cg_import_params(args, session):
     # simulate policy for cg imports
     policy = 'cg_import'
-    data = {'metadata_only': bool(args.metadata_only)}
+    data = {}
 
     if args.build:
         # pull metadata from existing build
@@ -397,6 +397,7 @@ def cg_import_params(args, session):
             data[key] = binfo[key]
         data['btypes'] = list(session.getBuildType(binfo['id']))
         data['cg_list'] = [binfo['cg_id']]
+        data['metadata_only'] = False
 
     elif args.metadata:
         metadata = koji.load_json(args.metadata)
@@ -405,13 +406,16 @@ def cg_import_params(args, session):
             data[key] = build[key]
         for key in ('source', 'draft'):
             data[key] = build.get(key)
+
+        # get btypes
         typeinfo = build.get('extra', {}).get('typeinfo', {})
         for btype in ('maven', 'win', 'image'):
             # legacy types can also be at top level of extra
             if btype in build['extra']:
                 typeinfo.setdefault(btype, build['extra'][btype])
         data['btypes'] = list(typeinfo)
-        # for metadata, the cg id comes from the buildroot list
+
+        # get cg id
         cg_id = None
         for brdata in metadata['buildroots']:
             cginfo = brdata['content_generator']
@@ -419,8 +423,19 @@ def cg_import_params(args, session):
             # ^ this relies on our mocks
             # just take the first one. we're not validating
             cg_id = cg['id']
+            break
         data['cg_list'] = [cg_id]
 
+        # check for metadata-only flag
+        data['metadata_only'] = False
+        for fileinfo in metadata['output']:
+            if fileinfo.get('metadata_only', False):
+                data['metadata_only'] = True
+                break
+
+    if args.metadata_only:
+        data['metadata_only'] = True
+
     return policy, data
 
 

From 2cc7861534e03007e14636bc47005758dfc50561 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Feb 18 2026 14:59:13 +0000
Subject: [PATCH 4/4] fix package entry for cg policy data


---

diff --git a/devtools/fakepolicy b/devtools/fakepolicy
index fa02808..c4b60b8 100755
--- a/devtools/fakepolicy
+++ b/devtools/fakepolicy
@@ -393,8 +393,9 @@ def cg_import_params(args, session):
             binfo = session.getBuild(int(args.build), strict=True)
         else:
             binfo = session.getBuild(args.build, strict=True)
-        for key in ('name', 'version', 'release', 'source', 'draft'):
+        for key in ('version', 'release', 'source', 'draft'):
             data[key] = binfo[key]
+        data['package'] = binfo['name']
         data['btypes'] = list(session.getBuildType(binfo['id']))
         data['cg_list'] = [binfo['cg_id']]
         data['metadata_only'] = False
@@ -402,10 +403,11 @@ def cg_import_params(args, session):
     elif args.metadata:
         metadata = koji.load_json(args.metadata)
         build = metadata['build']
-        for key in ('name', 'version', 'release'):
+        for key in ('version', 'release'):
             data[key] = build[key]
         for key in ('source', 'draft'):
             data[key] = build.get(key)
+        data['package'] = build['name']
 
         # get btypes
         typeinfo = build.get('extra', {}).get('typeinfo', {})

