Skip to content

refactor: 审计阶段 0、1——护栏转绿与低风险清理 - #2

Open
SolarCrown57 wants to merge 14 commits into
desktop-vnext-devfrom
desktop-vnext-refactor
Open

SolarCrown57 wants to merge 14 commits into
desktop-vnext-devfrom
desktop-vnext-refactor

Conversation

@SolarCrown57

@SolarCrown57 SolarCrown57 commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

概要

按审计报告 docs/refactor/AUDIT.md 完成阶段 0(让护栏变绿)和阶段 1(低风险清理)。不改变业务行为,每个提交只处理一项,可以单独审阅或回退。报告末尾的 §8 是逐项处理记录。

提交

提交 审计项 内容
01706c9 docs(refactor) — 审计报告
0e98942 test(desktop) §3 即 #1 的测试修复(两个桌面端测试崩溃和收尾异常)。如果先合并了 #1,这个提交内容相同,不会冲突
f2acb63 test(desktop) §3 新增的私有 patch 改为依赖注入或替身对象:SubtitlePreviewService 接受可选 probe_video;测试改为替换 waveform_cache.load_or_generate,或者用 FakePlayer 断言跳转结果。私有 patch 回到上限 17
172d818 test(architecture) §3 顶层函数数量改为对照生成的快照,不再写死 1059
015fcf7 fix(desktop) M9 桌面端改由 runtime_config 解析投稿目录,删除写死的本机路径;6 份 desktop-vnext 文档同步。发布扫描恢复通过
7e171cc refactor(subtitles) M4 字幕断行和字宽改用 transcription.segments 的唯一实现;校对状态的结构字段由 _edit_structure_payload 统一生成;删除未使用的 _split_subtitle_cues
7ca99c9 refactor(security) M4 两个 Flask 程序的响应收尾(会话 Cookie 和 LAN 脱敏)移到 SecurityPolicy.finalize_flask_response
ad54613 chore L1 删除 _render_task、CueSelection.retain、template_defaults
a0afcd5 fix L2/L3/L4 两处宽泛捕获改为只捕获具体异常;闭包用默认参数绑定;去掉集合字面量里的重复项
f327be1 refactor(web) M3 Web 主程序和启动器改为直接从真实模块导入,不再经过 topic_engine;测试的 patch 目标同步修改。兼容层本身和 core 兼容测试保持不变
8ed7860 refactor(web) M7 主工作台 1061 行内联脚本抽到 static/topic_v2.js;默认目录经 JSON 数据块注入(LAN 模式下仍为空);15 个 on* 属性改为 addEventListener;CI 对 topic_v2.js 和 subtitle_workflow.js 跑 node --check;打包冒烟清单加入新文件
dbb899c chore(architecture) §3 重新生成架构快照。注意 dev 上的快照本来就落后于代码(模块 199 个,实际 204 个)
b0f16c5 docs(refactor) — 审计报告补充处理记录
75ee9e6 test §3 dev 新增的 3 条测试在 Windows CI 上不稳定(dev 以前快照检查先失败,所以从没跑到):2 条拿 8.3 短路径临时目录(RUNNER~1)和 resolve 后的长路径比较;1 条“外部修改”写入的内容与原文同为 42 字节,两次写入落在同一个 mtime 刻度内,大小加 mtime 的指纹没变。都在测试侧修复

需要维护者留意

  • 投稿目录默认值:桌面端以前在代码里写死了维护者本机的投稿目录,现在和 Web 端一样走 AUTOSLICE_SUBMISSION_DIR。如果本机的 autoslice.local.json 已经为 Web 字幕工作台配置了这个键,桌面端行为不变;否则请加上:
    { "AUTOSLICE_SUBMISSION_DIR": "<本机投稿目录>" }
  • M5 旧 Tk 桌面壳:是否删除或改默认入口,由你决定,这个 PR 没有动。

未包含

  • 阶段 2(H1 拆分 DesktopWindow、M6 迁出预览包):会大面积改动 window.py,需要先和 desktop-ui-opus55v2 约定合并顺序。
  • 阶段 3、4(H2~H4、M1、M2、M8):涉及流水线和核心算法,需要先补刻画测试,部分改动需要单独授权用真实录播验收。
  • L1 的 follow_playback:暂时保留,避免和 UI 分支冲突。
  • L3 的日志:项目没有使用 logging,只收窄了异常类型,没有加日志。
  • L2 的规则表:只去掉了重复项。

验证

  • python -B scripts/run_hermetic_tests.py:共 1575 条,失败 5 条,跳过 5 条(本地 Windows、Python 3.12)。其中 4 条 test_migrated_source_and_ast_hashes_are_exact 只在 3.12 下失败(ast.dump 多了 type_params 字段),用 CI 的 Python 3.10 复跑通过;另 1 条 test_playhead_full_height_blank_scrub_and_cue_priority 在 dev 的 7f7f047 上就已失败,和本 PR 无关。
  • scripts/architecture_snapshot.py --check、scripts/validate_public_docs.py、scripts/scan_public_release.py、compileall、git diff --check 均通过;改动文件 ruff 无新增告警。
  • 主工作台在浏览器中实测:外置脚本正常加载,默认目录正确填充,扫描、时间轴模式切换、时间轴路径输入等事件都生效,控制台无报错。

🤖 Generated with Claude Code

sc57 and others added 14 commits October 2, 2026 00:56
基于 7f7f047(与 desktop-vnext-dev 一致)的只读审计,结论:整体不是屎山,
技术债集中在桌面主窗口上帝类、流水线参数透传、边界规则链、Web 上帝模块、
绕过护栏的改名复制,以及当前未通过的架构快照、私有 patch 上限与发布扫描。
报告给出证据、严重度、建议与分阶段重构顺序,未修改业务代码。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- test_discard_unsaved_edit_reopens_from_formally_saved_subtitle:
  构造第二个窗口时用 patch.object 替换 DesktopWindow 类属性 _start_waveform,
  在已有窗口存活时会让 PySide 在 _appbar 设置图标处 access violation,用例稳定崩溃;
  且该 patch 只在构造期间生效,拦不到异步载入后才发生的调用。
  改为构造后在实例上替换,并由 addCleanup 覆盖整个用例。
- test_explicit_seek_ignores_stale_player_position_and_playing_highlight:
  FakePlayer 缺少 close(),收尾关窗时 closeEvent 调用 player.close() 抛出 AttributeError,
  后续 Qt 事件再进入 Python 重写时处于异常状态;补一个空的 close()。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 00d177c)
Bring the test private-patch count back to the 17 allowed by the
architecture contract:

- SubtitlePreviewService accepts an injectable probe_video, so the canvas
  test no longer patches subtitle_preview._probe_video_info.
- The reopened-window test stubs waveform_cache.load_or_generate instead
  of the private DesktopWindow._start_waveform.
- The bottom-click seek test asserts player and timeline results with a
  fake player instead of patching DesktopWindow._seek_to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two owner tests pinned the repository-wide top-level function count to a
hand-written 1059, which already disagreed with the generated baseline
(1060) and broke whenever unrelated modules gained a function. Compare
with architecture_baseline.json instead: growth still has to go through
a reviewed snapshot regeneration, which the CI step
`architecture_snapshot.py --check` enforces, without hard-coding a
volatile number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
projects.py hard-coded the maintainer's local submission folder as the
fallback and re-parsed AUTOSLICE_SUBMISSION_DIR on its own. That left two
defaults for one setting (the web workbench falls back to the repository
`submissions` folder), showed "目录不存在" on any other machine and made
scripts/scan_public_release.py fail.

configured_submission_root() now delegates to
runtime_config.configured_path(), the existing owner of this setting, so
the precedence stays environment > autoslice.local.json > repository
default, still resolved at call time. Machines that configure the folder
in autoslice.local.json keep the same behaviour. Desktop docs describe
the configured folder instead of a literal local path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- _split_subtitle_text_for_ass and _subtitle_display_text_size were
  line-for-line copies of transcription.segments.split_subtitle_text_for_display
  and subtitle_text_size under different names, so the duplicate-definition
  guard could not see them. The ASS wrapper now calls the segment owner.
- save_corrected_srt and load_subtitle_edit_state built the same five
  structure fields (deleted, merge pairs/overrides, time overrides, split
  groups) independently; both now use _edit_structure_payload, keeping
  key order so written state files are byte-for-byte unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
autoslice.web.app and autoslice_cover.app each carried an identical
after_request hook that issues the local session cookie and redacts LAN
responses. Security behaviour duplicated across two apps can silently
drift, so move it into SecurityPolicy.finalize_flask_response, next to
the existing duck-typed authorize_flask_request helpers. Both hooks now
delegate with their own bootstrap paths and JSON encoder; behaviour is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Delete functions that nothing in src/, tests/, scripts/, templates or JS
references: subtitle_workflow._split_subtitle_cues,
autoslice_cover.app._render_task, CueSelection.retain and
runtime_config.template_defaults. SubtitleTimeline.follow_playback is
also unused but is left in place because desktop-ui-opus55v2 edits it;
it can go when that branch lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- analysis/topic/analysis.py: skip malformed LLM timecodes on ValueError
  and IndexError only, instead of hiding every exception.
- analysis/manual/timebase.py: the zip fallback for .docx timelines only
  swallows OSError, KeyError and BadZipFile; the outer python-docx
  fallback stays as designed.
- llm/transport.py: bind active_prompt/active_tokens explicitly in the
  retry closure (B023), so a future deferred call cannot see a later
  loop iteration's values.
- analysis/topic/normalization.py: drop duplicate items from set
  literals (B033); the sets' contents are unchanged.

The project has no logging setup, so these keep their current silent
fallbacks rather than introducing new log output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/架构重构.md requires production consumers to depend on the real
owner rather than compatibility modules. web/app.py (7 call sites) and
launcher.py still imported ensure_srt, funasr_public_status,
optimize_manual_timeline_for_video, retry_clip_review_from_artifacts,
run_pipeline, slice_from_marks and subtitle_title_services through
autoslice.topic_engine. They now import from autoslice.pipeline,
autoslice.slicing, autoslice.transcription.workflow and
autoslice.transcription.model_runtime.

Tests that drive the web tasks patch those owners instead of the facade.
core.py stays a compatibility forwarder, so its tests (including the
core.generate_srt case in test_app.py) keep patching topic_engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The topic_v2 page carried a 1,061-line inline script that no CI step
syntax-checked. Move it to static/topic_v2.js, following the existing
subtitle_workflow.js layout:

- Default directories are injected through a JSON data block instead of
  Jinja expressions inside the script; LAN mode still renders them empty.
- The 15 inline on* attributes become addEventListener bindings, bound
  right after restoreWorkspacePaths() so the Node behaviour tests keep
  executing only the definitions.
- Page tests fetch the script through the Flask static route.
- CI runs node --check on topic_v2.js and subtitle_workflow.js, and the
  packaging smoke checks list the new resource.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The baseline on desktop-vnext-dev already lagged the code (199 modules
recorded, 204 present), so architecture_snapshot.py --check failed before
this branch. Regenerate it after the audit stage 0/1 changes; the private
patch total stays at 17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
These tests came with desktop-vnext-dev and never ran in CI, because the
architecture snapshot check failed first. Once it passed, the Windows job
exposed them:

- The launcher media-tool test and the subtitle render service test
  compared resolved long paths with the runner's 8.3 short temp path
  (RUNNER~1). Resolve the temp root before building expectations.
- The draft baseline test rewrites the source with content of the same
  byte size (42 bytes). On the runner both writes landed in one mtime
  tick, so the size + mtime signature did not change and the draft read
  back as ready. Push the mtime forward explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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