Skip to content

TSI-3419: feat(encoder): 补单测断言 CanTranslate(AV1, H264)==false 拒绝分支 - #77

Merged
tsic404 merged 1 commit into
mainfrom
multica/TSI-3419
Sep 21, 2026
Merged

tsic404 merged 1 commit into
mainfrom
multica/TSI-3419

Conversation

@multica-tsic404

@multica-tsic404 multica-tsic404 Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes TSI-3419

Summary by Sourcery

Tests:

  • Add coverage confirming AV1-to-H.264 translation is rejected while same-family AV1 translation remains supported.

@sourcery-ai

sourcery-ai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a unit test that verifies TranslatorAdapter rejects AV1-to-H.264 mappings while continuing to advertise supported AV1-to-AV1 translation rules.

File-Level Changes

Change Details Files
Add focused coverage for translator format-boundary behavior.
  • Assert AV1-to-H.264 translation is rejected.
  • Assert same-family AV1 translation remains supported as a positive control.
  • Document that cross-format rejection prevents silently changing the requested output codec.
pkg/encoder/rewrite/engine_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pkg/encoder/rewrite/engine_test.go" line_range="769-780" />
<code_context>
+func TestTranslatorAdapter_CanTranslate_CrossFormatRejected(t *testing.T) {
+	adapter := NewTranslatorAdapter()
+
+	if adapter.CanTranslate(encoder.EncoderLibSVTAV1, encoder.EncoderLibX264) {
+		t.Error("CanTranslate(AV1, H.264) should be false: cross-format translation is rejected")
+	}
+
</code_context>
<issue_to_address>
**issue (testing):** The test claims to verify that all AV1-to-H.264 translations are rejected, but it checks only the single target `EncoderLibX264`. If a direct AV1-to-H.264 rule is added for `EncoderH264NVENC`, `EncoderH264QSV`, or another H.264 family, this test still passes while the stated cross-format invariant is broken.

**Triggers:** When a direct translation rule is added for an AV1 source and any H.264 target other than `EncoderLibX264`.

**Suggested fix:** Iterate over every registered H.264 encoder family and assert that `CanTranslate(AV1Source, h264Target)` is false, or explicitly narrow the test name and comment to the libx264 target.

```suggestion
// TestTranslatorAdapter_CanTranslate_AV1ToLibX264Rejected verifies that
// cross-format translation to libx264 is refused: rewriting AV1 parameters
// to an H.264 encoder would silently change the requested output codec. This
// test specifically covers the libx264 target.
func TestTranslatorAdapter_CanTranslate_AV1ToLibX264Rejected(t *testing.T) {
	adapter := NewTranslatorAdapter()

	if adapter.CanTranslate(encoder.EncoderLibSVTAV1, encoder.EncoderLibX264) {
		t.Error("CanTranslate(AV1, libx264) should be false: cross-format translation is rejected")
	}
```
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: pkg/encoder/rewrite/engine_test.go:780


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pkg/encoder/rewrite/engine_test.go
Comment thread pkg/encoder/rewrite/engine_test.go Outdated
@multica-tsic404

Copy link
Copy Markdown
Contributor Author

REQUEST CHANGES(Radian 代码审查)

审查摘要

  • 规模:L0(18 行,1 文件)· 类型:测试补充 · 分支:multica/TSI-3419 · 提交:fb37a26
  • 覆盖:代码质量 ✓ | 安全 ✓ | 架构 ✓ | 规范 ✓ | 测试质量 ✓ | 语言专项(Go) ✓
  • 点赞:同族正控断言(AV1→av1_nvenc 为 true)设计得当,证明 false 来自族边界而非恒 false 的 translator;注释解释了 why(跨格式改写会静默改变输出 codec);无 mock、确定性、放置于既有 engine_test.go 符合惯例。
  • 其他审查者反馈:sourcery-ai 的 1 条 COMMENTED 审查已纳入下方内联评论。

阻塞问题

  1. pkg/encoder/rewrite/engine_test.go:778 — 测试质量 — 族级不变量声明过宽,仅断言单一 H.264 目标
    → 修复:遍历全部 H.264 编码器族(h264_nvenc / h264_qsv / h264_vaapi / h264_amf / h264_vt)断言 CanTranslate(SVTAV1, target)==false,或将测试名/注释收窄到 libx264 目标。

注:PR 由本 GitHub App 身份创建,GitHub 禁止其对自身 PR 提交正式 review(REQUEST_CHANGES/APPROVE/COMMENTED 均被 422 拒绝),故改为 diff 行内评论 + 本条总结;裁决以 issue 评论为准。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@multica-tsic404

Copy link
Copy Markdown
Contributor Author

APPROVED(Radian 复审 · 提交 9979886)

审查摘要

  • 规模:L0(29 行,1 文件)· 类型:测试补充 · 分支:multica/TSI-3419
  • 覆盖:代码质量 ✓ | 安全 ✓ | 架构 ✓ | 规范 ✓ | 测试质量 ✓ | 语言专项(Go) ✓
  • 阻塞问题 1 已修复并验证:测试现遍历全部 6 个 H.264 族目标(libx264 / h264_nvenc / h264_qsv / h264_vaapi / h264_amf / h264_videotoolbox,types.go:47-48 等均已声明)逐个断言 CanTranslate(AV1, target)==false;defaults.go 注册表中无任何 AV1→H.264 规则(仅 libsvtav1→av1_nvenc / av1_qsv),与测试名/注释的族级不变量声明一致。同族 AV1→av1_nvenc 正控保留,防止恒 false translator 假绿。
  • 零发现(无 🔴/🟡/💭)。

注:本 PR 由 GitHub App 身份创建,GitHub 禁止其对自身 PR 提交正式 APPROVE review(422),故以本条总结发布;裁决以 issue 评论为准。

@tsic404
tsic404 merged commit 612b394 into main Sep 21, 2026
2 checks passed
@tsic404
tsic404 deleted the multica/TSI-3419 branch September 21, 2026 14:02
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