fix(config): accept undefined entries in config records (ENG-1538)

Merged
SA
3d ago
+336-78

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 undefined service, agent, tool, provider, or permission is left out. A service's value in tests is then undefined.
  • For an agent this changes what a JavaScript config did: agents: { buyer: undefined } used to create buyer with the default options, and now --agent buyer fails as an unknown agent. Write buyer: {} for an agent with the defaults.
  • A secret set to undefined takes its value from E2E_SECRET_<NAME>, or the config load fails with INVALID_CONFIG, as before.
  • A credential set to undefined takes its username and password from E2E_USER_<NAME>_USERNAME and E2E_USER_<NAME>_PASSWORD. Before, it was INVALID_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

  1. The config types take X | undefined record values (packages/core/src/types.ts): app.permissions (:1720), an agent's providerOptions (:1967) and tools (:1990), agents (:2086), credentials (:2103), and secrets (:2111). ServiceMap takes Service | undefined (packages/core/src/types/services.ts:48). defineConfig's signature doesn't change, and neither does the shared ProviderOptions type the model calls use.
  2. ServiceValues maps each entry through ConfiguredServiceValue (packages/core/src/types/services.ts:137), which distributes over a union. So email: ci ? email : undefined types services.email as the service value or undefined, in tests and in app.command.env.
  3. The resolvers drop the undefined entries, so nothing after them sees one:
    • resolveServices (packages/e2e/src/config/resolve-run.ts:73), which every runner, e2e mcp, and openHost start the services from.
    • resolveAgents (packages/core/src/config/resolve.ts:1004).
    • resolveTools and resolveProviderOptions through definedEntries (packages/core/src/config/agent.ts:370).
    • checkPermissions (packages/core/src/config/app.ts:190), before an engine's validateApp or launch reads the map. It builds the map with Object.fromEntries, so a __proto__ name still reaches the engine, which rejects it.
  4. digestAgents skips an undefined agent 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 without undefined entries doesn't change, and the replay cache key doesn't include the config digest.
  5. collectSecrets runs the credential shape check only on a defined entry and reads username and password through ?. (packages/core/src/config/resolve.ts:830), so the E2E_USER_<NAME>_* variables fill an undefined credential. null is still rejected. Secrets already took a missing value from E2E_SECRET_<NAME> and need no change.
  6. One deliberate type check goes: secrets: { key: process.env['STRIPE_KEY'] } used to be a type error in sdk-types.ts. It now type-checks, and when the variable is unset the config load still fails with INVALID_CONFIG unless E2E_SECRET_KEY is set. TypeScript can't tell an explicit undefined from the optional key the conditional produces, so the check can't stay.
  7. packages/e2e/tests/integration/types-loose-optional-properties.test.ts compiles configs with each of these records written as ci ? { … } : {} in a project with exactOptionalPropertyTypes off, and calls test.extend and openHost on them. It also asserts that invalid secrets, services, and permissions still fail. config.test.ts and agent-config.test.ts cover the runtime of each undefined entry.

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 with tsc --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 }) => { … });
mainthis 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, and app.permissions each as ci ? { … } : {}:
mainthis PR
TS2344 on test.extend and TS2339 browser for agents, tools, and providerOptions. TS2322 on app.permissions itself0 errors, with and without --exactOptionalPropertyTypes. @ts-expect-error lines for permissions: ci ? { geolocation: 'granted' } : {} and agents: ci ? { buyer: 42 } : {} are still used
  • resolveConfig from the built dist:
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/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.