| 141 | }; |
| 142 | |
| 143 | export const makeTestConfig = <const TPlugins extends readonly AnyPlugin[] = readonly []>( |
| 144 | options?: TestConfigOptions<TPlugins>, |
| 145 | ): Omit<ExecutorConfig<TPlugins>, "db"> & { |
| 146 | readonly db: FumaDb; |
| 147 | readonly testDb: TestFumaDb; |
| 148 | } => { |
| 149 | const tenant = options?.tenant ?? "test-tenant"; |
| 150 | const subject = options?.subject === undefined ? "test-subject" : options.subject; |
| 151 | |
| 152 | const tables = collectTables(); |
| 153 | const testDb = makeLazyTestFumaDb({ |
| 154 | tables, |
| 155 | backend: options?.backend ?? "sqlite", |
| 156 | dataDir: options?.dataDir, |
| 157 | }); |
| 158 | const db = withQueryContext(testDb.db, { |
| 159 | tenant, |
| 160 | subject, |
| 161 | } satisfies ExecutorOwnerPolicyContext); |
| 162 | |
| 163 | // EXPLICIT OAuth callback: default to a stable test URL so the redirect flow |
| 164 | // tests work without the removed localhost default; `redirectUri: null` omits |
| 165 | // it so a test can exercise the fail-loud "no callback configured" path. |
| 166 | const redirectUri = |
| 167 | options?.redirectUri === undefined ? TEST_OAUTH_REDIRECT_URI : options.redirectUri; |
| 168 | |
| 169 | return { |
| 170 | tenant: Tenant.make(tenant), |
| 171 | ...(subject != null ? { subject: Subject.make(subject) } : {}), |
| 172 | db, |
| 173 | plugins: options?.plugins, |
| 174 | coreTools: options?.coreTools, |
| 175 | testDb, |
| 176 | // Tests default to auto-accepting elicitation prompts. |
| 177 | onElicitation: "accept-all", |
| 178 | onIntegrationChange: options?.onIntegrationChange, |
| 179 | ...(redirectUri != null ? { redirectUri } : {}), |
| 180 | ...(options?.orgWrites === undefined ? {} : { orgWrites: options.orgWrites }), |
| 181 | oauthCallbackStateOrgSlug: options?.oauthCallbackStateOrgSlug, |
| 182 | firstPartyOAuthClients: options?.firstPartyOAuthClients, |
| 183 | enterpriseManagedRollout: options?.enterpriseManagedRollout, |
| 184 | }; |
| 185 | }; |
| 186 | |
| 187 | export interface TestWorkspaceHarness< |
| 188 | TPlugins extends readonly AnyPlugin[] = readonly AnyPlugin[], |