[quality] comment-only prow.yaml throws YAMLException instead of loading as an empty configuration (parseProwConfig trim guard misses zero-document input)

クローズ 初心者向け
#393 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #415 @mrbobbytables による — マージ済み

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
github-actions, nodejs, typescript
領域
tooling

調査の方向性

src/utils/config.ts の parseProwConfig(369〜374行目付近)から始めます。ここでは yaml.load の前にある trim() のガードが空の入力だけを処理しています。issue の js-yaml スニペットで再現し、そのうえで空ドキュメントの分岐を、コメントだけの入力も扱えるように広げてください。# prow configuration\n が {} を返し、追加したケースが tests/utils/config.test.ts と tests/bundle/emptyConfigDocument.test.ts で通れば完了です。その後 npm run build && npm run pack を実行して dist/ を一致させてください。

索引モデルが issue の本文から書いたものです。

説明

agent/quality hive/hosted-available-lke648397-260827-5q9t needs-kind quality testing

Finding

A comment-only prow.yaml breaks every configuration-reading command. parseProwConfig (src/utils/config.ts:369-374) treats an empty document as an all-empty configuration:

const loaded: unknown = text.trim() === '' ? undefined : yaml.load(text)
if (loaded === undefined || loaded === null) {
  return {}
}

but the guard only catches a blank/whitespace file. js-yaml 5 (^5.4.2, bumped in #126) throws YAMLException: expected a document, but the input is empty from load() whenever the input contains zero documents, and a file holding only comments is such an input:

$ node -e "const y=require('js-yaml');for (const t of ['','# c\n','---\n','  \n']){try{console.log(JSON.stringify(t),'->',y.load(t))}catch(e){console.log(JSON.stringify(t),'THROWS',e.message)}}"
""      THROWS expected a document, but the input is empty
"# c\n" THROWS expected a document, but the input is empty
"---\n" -> null
"  \n"  THROWS expected a document, but the input is empty

So '' and ' \n' are rescued by the trim() guard, '---\n' loads as null, and '# c\n' falls through to yaml.load and throws. Driven through dist/index.js on main @ aa6a0f8 with .github/prow.yaml = # prow configuration\n# nothing enabled yet\n:

  • /lifecycle stale → exit 1, ::error::TypeError: error handling issue comment: Error: could not get labels from yaml: YAMLException: expected a document, but the input is empty — instead of the built-in frozen,stale,rotten defaults that a blank file yields.
  • /kind cleanup → the same YAMLException, instead of kind: yaml malformed, expected 'kind' top level key.

The same path runs for the org tier (<owner>/.project / <owner>/.github:prow.yaml), so a placeholder, comment-only org file breaks every repository in the organization.

History: #126's commit message accepted the new throw on empty documents ("the failure mode is unchanged"); #144 then deliberately made empty documents an all-empty configuration (return {}) and unit-tested '', '---\n' and ' \n' (__tests__/utils/config.test.ts:420-426) but not a comment-only document, which is the one shape users actually commit as a placeholder.

Recommendation

One deliverable: make the empty-document arm cover zero-document input regardless of comments. Either

  • in parseProwConfig, replace the trim() guard with a zero-document check, e.g. const docs = yaml.loadAll(text); const loaded = docs.length === 0 ? undefined : docs[0] (and keep the existing expected a mapping at the top level rejection for multi-document or non-mapping input), or catch the YAMLException whose message starts with expected a document, but the input is empty and return {}
  • add ['a comment-only file', '# prow configuration\n'] to the treats %s as an all-empty config cases in __tests__/utils/config.test.ts
  • add the same case to the emptyDocuments table of __tests__/bundle/emptyConfigDocument.test.ts (added by the companion PR; it drives the blank and --- arms through dist/index.js and names this issue for the case it leaves out)
  • npm run build && npm run pack so the dist/ drift gate passes

This touches production source (src/utils/config.ts), so it is not a PR this lane opens; it is filed for a maintainer.

Priority

  • Impact: medium (a comment-only placeholder config silently disables every label command for a repository or, at the org tier, every repository)
  • Effort: low

🐝 Hive Agent: quality | Instance: hosted-available-lke648397-260827-5q9t | SHA: aa6a0f8

— hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88

主要言語
TypeScript
スター
132
フォーク
24
平均マージ
1日 6時間
マージ済み PR(30日)
232

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cncf/prow-github-actions のほかの issue

cncf/prow-github-actions の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。