Skip to content

Parse config JSON containers (#1216)#1244

Open
zhangsan582 wants to merge 1 commit into
Fission-AI:mainfrom
zhangsan582:feature_0623_1
Open

Parse config JSON containers (#1216)#1244
zhangsan582 wants to merge 1 commit into
Fission-AI:mainfrom
zhangsan582:feature_0623_1

Conversation

@zhangsan582

@zhangsan582 zhangsan582 commented Jun 23, 2026

Copy link
Copy Markdown

• ## Issue Summary

#1216: openspec config set workflows '["new","ff","apply","archive"]' failed because the value stayed a string, while schema validation expects workflows to be an array. Impact: non-interactive custom
profile setup could leave users with profile: custom and no workflows.

Selected Fix

Selected #1216 and avoided #1222 / #1226 / #1242 as requested. This issue has a clear repro, a narrow root cause, and a controlled fix in config value coercion.

Root Cause

coerceValue only handled booleans and numbers, then returned everything else as a string. JSON array syntax for workflows was never parsed before schema validation.

Implementation

  1. OpenSpec: no OpenSpec process/spec files were created or modified.
  2. Code: updated src/core/config-schema.ts to parse JSON array/object containers while preserving --string, boolean, number, and plain string behavior.
  3. Tests: updated test/core/config-schema.test.ts and test/commands/config.test.ts for JSON arrays, malformed JSON fallback, --string, and real config set workflows behavior.
  4. Verification:
    • pnpm exec vitest run test/core/config-schema.test.ts test/commands/config.test.ts
    • pnpm run lint
    • pnpm run build
    • pnpm exec vitest run test/commands/artifact-workflow.test.ts -t "outputs JSON mapping of templates"
    • pnpm test

Commit

Commit: 9a4c437

Message: Parse config JSON containers (#1216)

Commit contains only source/test files and no OpenSpec files.

Summary

Fixed #1216 on local branch feature_0623_1 in D:\workspace\2016\开源\个人\OpenSpec. The repository already existed, so clone was skipped.

Previously, JSON array input for workflows was stored as a string and rejected by config schema validation.

This adds JSON container coercion so openspec config set workflows '["new","ff","apply","archive"]' stores an actual array.

Changes

  • Added JSON array/object parsing to config value coercion.
  • Added schema-level coverage for parsed arrays/objects, malformed JSON fallback, and --string.
  • Added command-level coverage for config set workflows.
  • No OpenSpec files were changed or committed.

Verification

  • Focused tests passed.
  • pnpm run lint passed.
  • pnpm run build passed.
  • Full pnpm test passed after rerunning one transient Windows temp-dir timeout case.

Summary by CodeRabbit

Bug Fixes

  • config set workflows now accepts JSON array syntax and passes schema validation.

Documentation

  • No documentation or OpenSpec process files were changed.

Tests

  • Added coverage for JSON config coercion and non-interactive workflow configuration.

Summary by CodeRabbit

  • New Features
    • Configuration values now support JSON array and object syntax, automatically parsing JSON-formatted strings into actual arrays and objects instead of treating them as plain text. This enables more flexible configuration management for complex settings.

@zhangsan582 zhangsan582 requested a review from TabishB as a code owner June 23, 2026 15:34
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0d8f05f0-ced5-4f5c-b518-3b370010c922

📥 Commits

Reviewing files that changed from the base of the PR and between 1b06fdd and 9a4c437.

📒 Files selected for processing (3)
  • src/core/config-schema.ts
  • test/commands/config.test.ts
  • test/core/config-schema.test.ts

📝 Walkthrough

Walkthrough

coerceValue in config-schema.ts is extended with a parseJsonContainer helper that detects and JSON.parses top-level array ([...]) and object ({...}) strings, widening its return type to include unknown[] and Record<string, unknown>. New unit tests and a CLI integration test cover the JSON coercion and the config set workflows flow.

Changes

JSON Container Coercion in coerceValue

Layer / File(s) Summary
coerceValue signature and JSON parsing logic
src/core/config-schema.ts
Return type widened to string | number | boolean | unknown[] | Record<string, unknown>; new parseJsonContainer helper trims input, checks for [/{ delimiters, and safely JSON.parses valid containers, with coerceValue returning the parsed result when successful.
coerceValue unit tests and config set simulation
test/core/config-schema.test.ts
Adds tests for JSON array coercion, JSON object coercion, malformed-container passthrough, forceString override keeping array-like strings unparsed, and a simulation asserting workflows is a parsed array after validateConfig.
Integration test for config set with JSON array string
test/commands/config.test.ts
Introduces runConfigCommand helper, consoleLogSpy setup/teardown, and an integration test that runs config set workflows '[...]' and asserts the parsed array value and the expected log message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐇 A bracket arrived at the config gate,
"Parse me!" it said, "Don't make me wait!"
So coerceValue peeked inside,
Found an array with nowhere to hide,
Now workflows flow — oh, isn't that great! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding JSON container parsing to the config schema, which is the core functionality added across the modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openspec config set workflows '[...]' fails — config set cannot set the array-typed workflows key

1 participant