Skip to content

fix: revert .optional() to .default([]) and strip empty evo arrays on write#1074

Merged
notgitika merged 1 commit intomainfrom
fix/strip-empty-evo-arrays
May 1, 2026
Merged

fix: revert .optional() to .default([]) and strip empty evo arrays on write#1074
notgitika merged 1 commit intomainfrom
fix/strip-empty-evo-arrays

Conversation

@notgitika
Copy link
Copy Markdown
Contributor

Summary

Fixes the JSON Schema generation failure introduced by #1073. The .optional() change causes Zod v4's toJsonSchema() to throw "Undefined cannot be represented in JSON Schema" during the release workflow.

Approach

  • Schema: Revert configBundles, abTests, httpGateways back to .default([]) so JSON Schema generation and Zod parsing work correctly
  • writeProjectSpec: Strip empty arrays for these three fields before writing to disk, so preview features don't appear in agentcore.json for users who haven't opted in

This gives us both: correct schema generation AND clean user files.

Test plan

  • npm run typecheck passes
  • Pre-commit hooks pass (eslint, prettier, secretlint)
  • npm run generate-schema succeeds (no "Undefined cannot be represented" error)
  • agentcore create does not write configBundles/abTests/httpGateways
  • agentcore add config-bundle correctly writes configBundles

… write

The .optional() change from #1073 breaks Zod JSON Schema generation
("Undefined cannot be represented in JSON Schema"). Revert to
.default([]) so schema generation and parsing work, but strip empty
configBundles/abTests/httpGateways in writeProjectSpec before writing
to disk so preview features don't pollute agentcore.json.
@notgitika notgitika requested a review from a team May 1, 2026 00:11
@github-actions github-actions Bot added size/s PR size: S agentcore-harness-reviewing AgentCore Harness review in progress labels May 1, 2026
@notgitika notgitika merged commit 8c5cdfe into main May 1, 2026
23 of 24 checks passed
@notgitika notgitika deleted the fix/strip-empty-evo-arrays branch May 1, 2026 00:13
Copy link
Copy Markdown

@agentcore-cli-automation agentcore-cli-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty-array stripping in writeProjectSpec won't actually keep these fields out of agentcore.json. The stripping runs on the input data, but validateAndWrite then calls schema.safeParse(data) and writes result.data — and because the schema uses .default([]), Zod re-populates the stripped fields with empty arrays on parse. The written JSON will still contain "configBundles": [], "abTests": [], "httpGateways": [].

Quick trace with the agentcore create path:

  1. createDefaultProjectSpec() returns an object without configBundles/abTests/httpGateways (see src/cli/project.ts).
  2. writeProjectSpec(spec) — the three cleaned.xxx?.length === 0 checks are all false (the fields are undefined, not empty arrays), so nothing is deleted.
  3. validateAndWriteAgentCoreProjectSpecSchema.safeParse(cleaned) applies .default([]) for each of the three fields.
  4. JSON.stringify(result.data, null, 2) writes configBundles: [], abTests: [], httpGateways: [] to disk.

So the second objective in the PR description ("writeProjectSpec: Strip empty arrays... so preview features don't appear in agentcore.json for users who haven't opted in") isn't met as written.

A few options to actually achieve that:

  1. Strip after validation. Parse with the schema, then delete the empty arrays from result.data before stringifying. This would likely require splitting the logic out of the generic validateAndWrite (e.g., do a manual parse + post-process + write in writeProjectSpec), or adding an optional post-validate hook.

  2. Use a separate write schema that keeps the fields .optional() (no default) for serialization, while the read/runtime schema keeps .default([]). The schema used by generate-schema.mjs (the one that was breaking) can stay .default([]); the write path uses the optional variant.

  3. Keep .optional() everywhere (the #1073 approach) and fix the JSON-Schema generation failure differently. Since generate-schema.mjs already strips defaults from required, the real blocker was z.toJSONSchema throwing on undefined. That can typically be handled by wrapping the optional arrays with .default([]) only at JSON-schema-generation time, or by pre-processing the schema before calling z.toJSONSchema.

Option 1 is probably the smallest change. Either way, the current PR doesn't produce the intended agentcore.json output — worth adding a test that reads the file after agentcore create and asserts these keys are absent, which would catch this.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 42.89% 8936 / 20830
🔵 Statements 42.17% 9485 / 22491
🔵 Functions 39.66% 1537 / 3875
🔵 Branches 39.82% 5769 / 14486
Generated in workflow #2257 for commit 5f1c177 by the Vitest Coverage Report Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants