Skip to content

fix: customConfig type 白名单对齐真实 GUI,修复 CI 长期红灯 - #6

Merged
Tespera merged 1 commit into
mainfrom
fix/config-type-whitelist
Aug 20, 2026
Merged

fix: customConfig type 白名单对齐真实 GUI,修复 CI 长期红灯#6
Tespera merged 1 commit into
mainfrom
fix/config-type-whitelist

Conversation

@Tespera

@Tespera Tespera commented Aug 20, 2026

Copy link
Copy Markdown
Member

问题

main 分支的 CI 三个引擎从 2026-07-09 起一直是红的

根因:scaffold_theme.py 生成的 config.json 里主色调写的是 "type": "color",而 validate_syntax.py 判定 color 非法 —— 脚手架的产物通不过自己的校验器

查证

对照 Gridea Pro 主项目的设置面板源码 frontend/src/views/theme/components/CustomSetting.vue 逐条核对,发现问题比一个 typo 大:

1. color 确实不是合法 type。 取色器的真实写法是 "type": "input" + "card": "color"CustomSetting.vue:40)。后端 domain.ThemeConfigItemCard 字段注释也写着「卡片类型(如 color)」。校验器拦得对,是脚手架写错了。

2. 但校验器的白名单本身也过时了。 注释写着「GUI 只渲染这 5 种」,实测 GUI 还支持 6 种:

type GUI 中的位置
radio CustomSetting.vue:93
switch(与 toggle 等价) CustomSetting.vue:27
markdown CustomSetting.vue:146
array(配 arrayItems CustomSetting.vue:152
picture / image(与 picture-upload 等价) CustomSetting.vue:116

也就是说主题作者写了这些完全能用的类型,反而会被校验器拦下来,还被建议改成更差的写法。references/theme-config-schema.md 里那句「经真实 GUI 验证只有 5 种」同样是错的。

3. 附加字段不会在后端被吃掉。 主题 config.json 是通过 domain.Theme.CustomConfig []interface{} 原样透传到前端的,card / options / arrayItems 都完好到达 GUI。

改了什么

文件 改动
scripts/scaffold_theme.py primaryColor 改用 input + card: "color" —— 用户拿到真正的取色器,而不是纯文本框
assets/starters/*/config.json ×3 同步跟进
scripts/validate_syntax.py 白名单补齐 6 种;新增三条校验(见下)
references/theme-config-schema.md 类型表重写,补充 arrayItems 完整示例
CHANGELOG.md 记录本次修正

新增的三条校验:

  • card 只允许 color / post,且只对 type: input 生效
  • type: arrayarrayItems → 报错(否则面板渲染空白卡片)
  • select / radiooptions → 报错(否则控件根本不渲染)

验证

本地按 CI 的步骤跑过:

jinja2 / go / ejs   scaffold + validate   →  三个引擎全部通过
jinja2              render_test           →  全部模板渲染通过

新校验规则做了正反向测试,7 个用例行为均正确:

合法:input + card:color     → 放行
合法:radio + options        → 放行
合法:markdown               → 放行
非法:type=color             → 拦截,提示改用 input + card:"color"
非法:card=rainbow           → 拦截,提示仅支持 color/post
非法:array 缺 arrayItems    → 拦截,提示会渲染空卡片
非法:select 缺 options      → 拦截,提示控件不会渲染

关联

🤖 Generated with Claude Code

scaffold_theme.py 生成的 config.json 用了 type: "color",而 GUI 的取色器实际是
type: "input" + card: "color",validate_syntax.py 因此判其非法 —— 脚手架产物通不过
自己的校验器,CI 三个引擎自 2026-07-09 起全红。

- scaffold_theme.py / 三个 starter:primaryColor 改用 input + card: color
- validate_syntax.py:白名单补齐 radio/switch/markdown/array/picture/image
  (逐条对照 CustomSetting.vue 的 v-if 分支核对)
- validate_syntax.py:新增 card 合法值、array 缺 arrayItems、select/radio 缺 options 三项校验
- theme-config-schema.md:类型表重写并补充 arrayItems 示例
- CHANGELOG.md:记录本次修正
@Tespera Tespera mentioned this pull request Aug 20, 2026
@Tespera
Tespera merged commit f2f559a into main Aug 20, 2026
3 checks passed
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.

1 participant