fix(config): accept undefined entries in config records (ENG-1538)
What
These config records take undefined values: secrets, credentials, services, agents, an agent's tools and providerOptions, and a target's app.permissions. A config like this now keeps its inferred type in a project without exactOptionalPropertyTypes (the compiler default):
const config = defineConfig({
secrets: ci ? { token: process.env.TOKEN } : {},
services: ci ? { email } : {},
agents: { default: { tools: ci ? { lookupOrder } : {} } },
targets: [{ engine: web(), app: { url: 'http://localhost:3000', permissions: ci ? { geolocation: 'grant' } : {} } }],
});
const extended = test.extend<{}, {}, typeof config>(); // `browser` and `services.email?.url` are typed
- An
undefinedservice, agent, tool, provider, or permission is left out. A service's value in tests is thenundefined. - For an agent this changes what a JavaScript config did:
agents: { buyer: undefined }used to createbuyerwith the default options, and now--agent buyerfails as an unknown agent. Writebuyer: {}for an agent with the defaults. - A secret set to
undefinedtakes its value fromE2E_SECRET_<NAME>, or the config load fails withINVALID_CONFIG, as before. - A credential set to
undefinedtakes its username and password fromE2E_USER_<NAME>_USERNAMEandE2E_USER_<NAME>_PASSWORD. Before, it wasINVALID_CONFIG.
Why
Without exactOptionalPropertyTypes, TypeScript types ci ? { token: 'x' } : {} as { token: string } | { token?: undefined }. The undefined failed Record<string, SecretConfig>, so defineConfig's Config extends E2EConfig constraint failed. Config then fell back to plain E2EConfig, and test.extend<{}, {}, typeof config>() failed with "The config's targets don't have inferred types because of a type annotation", which points at the wrong cause. The services stack hit it with services: ci ? { email } : {}. agents, tools, and providerOptions failed the same way, and app.permissions didn't type-check at all. The repository's own tsconfig turns exactOptionalPropertyTypes on, so none of our type tests saw it.
Letting the record values accept undefined makes the inferred type satisfy the constraint again.
How it works
- The config types take
X | undefinedrecord values (packages/core/src/types.ts):app.permissions(:1720), an agent'sproviderOptions(:1967) andtools(:1990),agents(:2086),credentials(:2103), andsecrets(:2111).ServiceMaptakesService | undefined(packages/core/src/types/services.ts:48).defineConfig's signature doesn't change, and neither does the sharedProviderOptionstype the model calls use. ServiceValuesmaps each entry throughConfiguredServiceValue(packages/core/src/types/services.ts:137), which distributes over a union. Soemail: ci ? email : undefinedtypesservices.emailas the service value orundefined, in tests and inapp.command.env.- The resolvers drop the
undefinedentries, so nothing after them sees one:resolveServices(packages/e2e/src/config/resolve-run.ts:73), which every runner,e2e mcp, andopenHoststart the services from.resolveAgents(packages/core/src/config/resolve.ts:1004).resolveToolsandresolveProviderOptionsthroughdefinedEntries(packages/core/src/config/agent.ts:370).checkPermissions(packages/core/src/config/app.ts:190), before an engine'svalidateAppor launch reads the map. It builds the map withObject.fromEntries, so a__proto__name still reaches the engine, which rejects it.
digestAgentsskips anundefinedagent and tool (packages/core/src/config/resolve.ts:1114), so such a config digests like one that leaves the entry out. The digest of a config withoutundefinedentries doesn't change, and the replay cache key doesn't include the config digest.collectSecretsruns the credential shape check only on a defined entry and readsusernameandpasswordthrough?.(packages/core/src/config/resolve.ts:830), so theE2E_USER_<NAME>_*variables fill anundefinedcredential.nullis still rejected. Secrets already took a missing value fromE2E_SECRET_<NAME>and need no change.- One deliberate type check goes:
secrets: { key: process.env['STRIPE_KEY'] }used to be a type error insdk-types.ts. It now type-checks, and when the variable is unset the config load still fails withINVALID_CONFIGunlessE2E_SECRET_KEYis set. TypeScript can't tell an explicitundefinedfrom the optional key the conditional produces, so the check can't stay. packages/e2e/tests/integration/types-loose-optional-properties.test.tscompiles configs with each of these records written asci ? { … } : {}in a project withexactOptionalPropertyTypesoff, and callstest.extendandopenHoston them. It also asserts that invalid secrets, services, and permissions still fail.config.test.tsandagent-config.test.tscover the runtime of eachundefinedentry.
app.command.env keeps its type: a static env or an env function written as ci ? { … } : {} still fails to type-check without exactOptionalPropertyTypes.
I dropped an earlier approach that changed defineConfig's signature to a conditional parameter type. It fixed test.extend, but the returned type was no longer an E2EConfig, so openHost, run, list, and explore rejected the config. It also moved an invalid service's error from the entry to the services key.
Issue
ENG-1538
Verified
Ran it locally: yes
- A scratch project under
docs/compiled the file below withtsc --strict --module nodenext, once on main and once on this branch, built packages in both.
const config = defineConfig({
secrets: ci ? { token: 'secret-token' } : {},
credentials: ci ? { admin: { username: 'admin', password: 'password1' } } : {},
services: ci ? { email } : {},
targets: [{ engine: web(), app: { url: 'http://localhost:3000', command: { executable: 'node', args: ['server.mjs'], env: ({ services }) => ({ EMAIL_URL: services.email?.url ?? '' }) } } }],
});
config satisfies E2EConfig;
void openHost({ config });
test.extend<{}, {}, typeof config>()('types the fixtures', async ({ browser, services }) => { … });
| main | this PR |
|---|---|
4 errors: TS2344 "The config's targets don't have inferred types because of a type annotation" on test.extend, TS2339 browser does not exist, TS2339 url does not exist on object (in env and in the test) | 0 errors, with and without --exactOptionalPropertyTypes. The file's @ts-expect-error lines for secrets: ci ? { token: 1 } : {}, services: { email, db: 42 }, and an excess reporter key are all still used |
- A second scratch file wrote
agents,tools,providerOptions, andapp.permissionseach asci ? { … } : {}:
| main | this PR |
|---|---|
TS2344 on test.extend and TS2339 browser for agents, tools, and providerOptions. TS2322 on app.permissions itself | 0 errors, with and without --exactOptionalPropertyTypes. @ts-expect-error lines for permissions: ci ? { geolocation: 'granted' } : {} and agents: ci ? { buyer: 42 } : {} are still used |
resolveConfigfrom the builtdist:
services started: [ 'email' ] # services: { email, sms: undefined }
secret from env: from-env-token # secrets: { token: undefined }, E2E_SECRET_TOKEN set
secret without env: INVALID_CONFIG secret "token" must be a non-empty string or a provider function
credential from env: admin # credentials: { admin: undefined }, E2E_USER_ADMIN_* set
credential without env: INVALID_CONFIG credential "admin" has no username; set username or E2E_USER_ADMIN_USERNAME
credential null: INVALID_CONFIG credential "admin" must be an object of { username, password }, got null
agents: [ 'seller', 'default' ] # agents: { buyer: undefined, seller: { … } }
tools: [ 'lookup' ] # tools: { lookup, other: undefined }
providerOptions: { openai: { reasoningEffort: 'low' } } # anthropic: undefined
permissions: { geolocation: 'grant' } # camera: undefined
permission __proto__: INVALID_CONFIG target "web" app.permissions on chromium has unknown key "__proto__"; expected one of …
digest same: true # agents: { buyer: undefined } against agents: {}
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.