| 125 | }; |
| 126 | |
| 127 | export const makeTestConfig = <const TPlugins extends readonly AnyPlugin[] = readonly []>( |
| 128 | options?: TestConfigOptions<TPlugins>, |
| 129 | ): Omit<ExecutorConfig<TPlugins>, "db"> & { |
| 130 | readonly db: FumaDb; |
| 131 | readonly testDb: TestFumaDb; |
| 132 | } => { |
| 133 | const tenant = options?.tenant ?? "test-tenant"; |
| 134 | const subject = options?.subject === undefined ? "test-subject" : options.subject; |
| 135 | |
| 136 | const tables = collectTables(); |
| 137 | const testDb = makeLazyTestFumaDb({ |
| 138 | tables, |
| 139 | backend: options?.backend ?? "sqlite", |
| 140 | dataDir: options?.dataDir, |
| 141 | }); |
| 142 | const db = withQueryContext(testDb.db, { |
| 143 | tenant, |
| 144 | subject, |
| 145 | } satisfies ExecutorOwnerPolicyContext); |
| 146 | |
| 147 | // EXPLICIT OAuth callback: default to a stable test URL so the redirect flow |
| 148 | // tests work without the removed localhost default; `redirectUri: null` omits |
| 149 | // it so a test can exercise the fail-loud "no callback configured" path. |
| 150 | const redirectUri = |
| 151 | options?.redirectUri === undefined ? TEST_OAUTH_REDIRECT_URI : options.redirectUri; |
| 152 | |
| 153 | return { |
| 154 | tenant: Tenant.make(tenant), |
| 155 | ...(subject != null ? { subject: Subject.make(subject) } : {}), |
| 156 | db, |
| 157 | plugins: options?.plugins, |
| 158 | coreTools: options?.coreTools, |
| 159 | testDb, |
| 160 | // Tests default to auto-accepting elicitation prompts. |
| 161 | onElicitation: "accept-all", |
| 162 | ...(redirectUri != null ? { redirectUri } : {}), |
| 163 | oauthCallbackStateOrgSlug: options?.oauthCallbackStateOrgSlug, |
| 164 | }; |
| 165 | }; |
| 166 | |
| 167 | export interface TestWorkspaceHarness< |
| 168 | TPlugins extends readonly AnyPlugin[] = readonly AnyPlugin[], |