🌳
pt0/gamesapp/testsF/gamesTestRunnerFactoryAI.mts
1// Factory for games-based app test runners (gamesapp, gamespay)
2// Provides shared CLI extensions, AI mocking, and deleteTestGames cleanup
8import { getAppCfg, type AppCfg } from '../../deployF/k8sF/ctxF/appCfgCtxF.mts'
15export type GamesTestConfig = {
16 allSuites: string[]
17 suiteConfigs: SuiteConfig[]
18 localAppCfg: AppCfg
21export const mkGamesTestActions = (config: GamesTestConfig) => {
22 const { allSuites, suiteConfigs, localAppCfg } = config
24 const gamesRuntestsCli = {
25 ...mkRuntestsCli(allSuites),
26 'del-test-games': { flag: true as const, desc: 'delete test games from db' },
27 'enable-opnrtr': { flag: true as const, desc: 'use real OpenRouter API instead of mock' },
28 }
30 const getConfig = async (): Promise<RunTestsCoreConfig> => {
31 return { allSuites, localAppCfg, suiteConfigs, wrapDbEnv: wrapDbEnv as RunTestsCoreConfig['wrapDbEnv'] }
32 }
34 const runtests = async () => {
35 const cli = parseCli(gamesRuntestsCli)
37 if (cli.history) {
38 const ep = getAppCfg()?.importMetaUrl
39 printTestHistory({ ep, suites: cli.suite })
40 return
41 }
43 if (!cli['enable-opnrtr']) aiDrawMockCtx.enterWith({ useMock: true }) // ctx:clear
45 const delTestGames = cli['del-test-games'] ?? false
46 const delTestGamesOnly = delTestGames && !cliHasArg('--suite')
48 const cfg = await getConfig()
49 const opts = optsFromCli(cli, allSuites)
50 if (delTestGamesOnly) opts.testsuites = []
52 const result = await runTestsCore({ config: cfg, opts })
54 if (delTestGames) {
55 const { localAppCfg } = cfg
56 const ctxAppCfg = getAppCfg()
57 const appCfg = ctxAppCfg || localAppCfg
58 await wrapDbEnv({ appConfig: ctxAppCfg ? undefined : appCfg, reuseConn: false, wrappedFnc: async () => {
59 const { deleted } = await deleteTestGames()
60 console.log(chalkGray(`Deleted ${deleted} test games`))
61 }})
62 }
64 if (!result.allPassed) process.exit(1)
65 }
67 runtests.cliSchema = gamesRuntestsCli
69 const testdeploy = mkTestdeploy({ getTestConfig: getConfig })
71 return { runtests, testdeploy, getConfig }