MCPcopy Create free account
hub / github.com/coder/coder / TestAIGovernanceAddon

Function TestAIGovernanceAddon

enterprise/coderd/license/license_test.go:2141–2319  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2139}
2140
2141func TestAIGovernanceAddon(t *testing.T) {
2142 t.Parallel()
2143
2144 empty := map[codersdk.FeatureName]bool{}
2145
2146 t.Run("AIGovernanceAddon enables AI Governance features when enablements are set", func(t *testing.T) {
2147 t.Parallel()
2148 db, _ := dbtestutil.NewDB(t)
2149 db.InsertLicense(context.Background(), database.InsertLicenseParams{
2150 JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
2151 FeatureSet: codersdk.FeatureSetPremium,
2152 Features: license.Features{
2153 codersdk.FeatureAIGovernanceUserLimit: 1000,
2154 codersdk.FeatureManagedAgentLimit: 1000,
2155 },
2156 Addons: []codersdk.Addon{codersdk.AddonAIGovernance},
2157 }),
2158 Exp: dbtime.Now().Add(time.Hour),
2159 })
2160
2161 // Enable AI Governance features in enablements.
2162 enablements := map[codersdk.FeatureName]bool{
2163 codersdk.FeatureAIBridge: true,
2164 codersdk.FeatureBoundary: true,
2165 }
2166 entitlements, err := license.Entitlements(context.Background(), db, 1, 1, coderdenttest.Keys, enablements)
2167 require.NoError(t, err)
2168 require.True(t, entitlements.HasLicense)
2169
2170 // AI Bridge should be enabled without warning when addon is present.
2171 aibridgeFeature := entitlements.Features[codersdk.FeatureAIBridge]
2172 require.True(t, aibridgeFeature.Enabled, "AI Bridge should be enabled when addon is present and enablements are set")
2173 aiBridgeWarningMessage := "The AI Governance add-on is required to use AI Bridge. Please reach out to your account team or sales@coder.com to learn more."
2174 require.NotContains(t, entitlements.Warnings, aiBridgeWarningMessage, "AI Bridge warning should not appear when AI Governance addon is present")
2175
2176 // require.Equal(t, codersdk.EntitlementEntitled, aibridgeFeature.Entitlement, "AI Bridge should be entitled when addon is present")
2177
2178 // TODO: Readd this test once Boundary is enforced as an add-on license.
2179 // boundaryFeature := entitlements.Features[codersdk.FeatureBoundary]
2180 // require.True(t, boundaryFeature.Enabled, "Boundary should be enabled when addon is present and enablements are set")
2181 // require.Equal(t, codersdk.EntitlementEntitled, boundaryFeature.Entitlement, "Boundary should be entitled when addon is present")
2182 })
2183
2184 t.Run("AIGovernanceAddon not present disables AI Governance features", func(t *testing.T) {
2185 t.Parallel()
2186 db, _ := dbtestutil.NewDB(t)
2187 db.InsertLicense(context.Background(), database.InsertLicenseParams{
2188 JWT: coderdenttest.GenerateLicense(t, coderdenttest.LicenseOptions{
2189 FeatureSet: codersdk.FeatureSetPremium,
2190 }),
2191 Exp: dbtime.Now().Add(time.Hour),
2192 })
2193
2194 enablements := map[codersdk.FeatureName]bool{
2195 codersdk.FeatureAIBridge: true,
2196 codersdk.FeatureBoundary: true,
2197 }
2198 entitlements, err := license.Entitlements(context.Background(), db, 1, 1, coderdenttest.Keys, enablements)

Callers

nothing calls this directly

Calls 9

NewDBFunction · 0.92
GenerateLicenseFunction · 0.92
NowFunction · 0.92
EntitlementsFunction · 0.92
RunMethod · 0.65
InsertLicenseMethod · 0.65
AddMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected