🌳
pt0/deployF/testsF/deployverifySuiteAI.mts
4import { ptenvTestprod, type Ptenv } from '../../sharedF/ptenvF.mts'
8import type { SuiteRunner } from './runTestsCoreAI.mts'
10const checkDeployedGitSha = async ({hostname, ptenv}: {hostname: string, ptenv: Ptenv}) => {
11 const appCfg = getAppCfg()
12 const {mkTestGqlFetch} = appCfg || {}
13 const testGqlFetch = mkTestGqlFetch ? await mkTestGqlFetch(ptenv) : null
14 const doFetch = testGqlFetch?.fetch ?? gqlFetch
15 const getKey = testGqlFetch?.mapKey ?? ((k: string) => k)
17 const baseUrl = `https://${hostname}`
18 const resp = await doFetch({baseUrl, query: '{ gqDeployInfo }'})
19 const deployedSha = resp?.data?.[getKey('gqDeployInfo')]
21 if (!deployedSha) return { passed: false, msg: 'no deployed SHA returned' }
23 const epRel = toPtRelPath(appCfg?.importMetaUrl || '')
24 const lastDeploy = readLedger().findLast(r => r.ep === epRel && isDeployAction(r.action) && r.success)
26 if (!lastDeploy?.gitSha) return { passed: true, msg: `SHA ${deployedSha.slice(0,7)} (no deploy history to compare)`, skipped: true }
27 if (lastDeploy.imageReused) return { passed: true, msg: `SHA ${deployedSha.slice(0,7)} (image reused/cached)`, skipped: true }
29 const expectedSha = lastDeploy.buildSha || lastDeploy.gitSha
30 const matches = deployedSha === expectedSha
31 return matches
32 ? { passed: true, msg: `SHA ${deployedSha.slice(0,7)} matches` }
33 : { passed: false, msg: `deployed ${deployedSha.slice(0,7)} != expected ${expectedSha.slice(0,7)}` }
36export const runDeployverifySuite: SuiteRunner = async ({ ptenv, isTestdeploy }) => {
37 if (!isTestdeploy) return skipSuite('deployverify only runs during testdeploy')
39 const hostname = getTestAgainstHn()
40 if (!hostname) return skipSuite('no deployed hostname')
43 suiteName: 'deployverify',
44 tests: [{
45 name: 'gitShaMatchesDeployedTrue',
46 fn: () => checkDeployedGitSha({hostname, ptenv}),
47 }],
48 })
51export const deployverifySuiteConfig = { name: 'deployverify', runner: runDeployverifySuite, deps: [] as const }