Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[testify-expert] Improve Test Quality: pkg/workflow/unquote_uses_test.go

已关闭 适合新手
#65,635 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
testing

调研方向

首先阅读 pkg/workflow/unquote_uses_test.go 以及源文件 pkg/workflow/compiler_yaml_step_conversion.go,特别是 unquoteUsesWithComments 和 injectZizmorUnverifiedCreatorAnnotations。运行 go test ./pkg/workflow/ -run 'UnquoteUses|Zizmor' 建立基线,然后完成验收清单:将手动 t.Errorf 替换为 testify assert/require,添加缺失的 formatStepEnvValueForYAML 和 ConvertStepToYAML 用例,从 unverifiedCreatorActionPrefixes 生成前缀表,并重命名文件。完成的标准是 make test-unit 通过且所有新用例都已存在。

由索引模型根据 Issue 内容生成。

描述

automated-analysis code-quality cookie testing
Current State
  • Test file: pkg/workflow/unquote_uses_test.go (280 LOC, 4 test functions, 0 assert/require usages; all checks use if got != want { t.Errorf })
  • Source file: pkg/workflow/compiler_yaml_step_conversion.go (functions: injectZizmorUnverifiedCreatorAnnotations, ConvertStepToYAML, unquoteUsesWithComments, (*Compiler).renderStepFromMap, formatStepEnvValueForYAML)
Strengths
  • Already table-driven with descriptive case names.
  • Good edge cases for malformed/unclosed quotes and hash-without-space.
  • Realistic multi-step YAML inputs.
Prioritized Improvements
1. Missing / high-value tests
  • injectZizmorUnverifiedCreatorAnnotations has only 3 cases. Add:
    • every entry in unverifiedCreatorActionPrefixes (iterate the slice so new prefixes are auto-covered),
    • a verified action (actions/checkout@...) gets no annotation,
    • tab indentation and - uses: (list-item form; currently TrimLeft + CutPrefix("uses: ") would NOT match - uses: safedep/..., so document or fix the expected behaviour),
    • a quoted value (uses: "safedep/pmg@sha") — does it match the prefix?,
    • empty input and idempotency (running twice should not double-inject, or the test should pin that it does).
  • ConvertStepToYAML and formatStepEnvValueForYAML have no direct tests in this file (only indirect ones in compiler_generation_test.go / multiline_test.go). Add a small table for formatStepEnvValueForYAML (string, bool, int, multi-line, string needing quoting) and a ConvertStepToYAML case checking that uses with a # v6 comment ends up unquoted end-to-end.
  • unquoteUsesWithComments: add CRLF input, uses: 'single-quoted # v1', and uses: "..." with extra spaces. The "multiple quotes on same line" case pins a questionable behaviour; add a comment saying it is intentional.
2. Testify assertion upgrades
Before / after
// Before
if result != tt.expected {
    t.Errorf("unquoteUsesWithComments() = %q, want %q", result, tt.expected)
}

// After
assert.Equal(t, tt.expected, unquoteUsesWithComments(tt.input), "unquoteUsesWithComments should produce expected YAML")

Add "github.com/stretchr/testify/assert" to imports; use require.NoError for ConvertStepToYAML errors. Replacing the multi-line Got/Want messages also yields better diffs.

3. Table-driven refactors
  • The three unquoteUsesWithComments tests (TestUnquoteUsesWithComments, ...EdgeCases, ...RealWorldExamples) share an identical struct and loop. Merge into one table (or keep three with a shared helper) and t.Parallel() per subtest.
  • Build unverifiedCreatorActionPrefixes cases from the slice rather than hard-coding.
4. Organization / readability
  • File name unquote_uses_test.go also tests injectZizmorUnverifiedCreatorAnnotations; rename to compiler_yaml_step_conversion_test.go to match the source file.
  • Use named raw-string constants for the repeated SHA pins to shorten cases.
Acceptance Checklist
  • testify assert/require used instead of manual t.Errorf comparisons
  • New tests for the gaps listed in section 1
  • Tables merged / generated from unverifiedCreatorActionPrefixes
  • File renamed to match source file
  • make test-unit passes

Generated by 🧪 Daily Testify Uber Super Expert · copilot · auto · 15.3 AIC · ⌖ 9.64 AIC · ⊞ 7.3K · ◷

  • expires on Oct 6, 2026, 10:22 AM UTC-08:00
主要语言
Go
星标
5.4k
派生
584
平均合并
3 小时 16 分钟
30 天内合并 PR
826

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/gh-aw 的其他 Issue

查看 github/gh-aw 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。