test(seam): make testseam the only seam-swap form and legislate it

- Add testseam.Protect for save-and-restore seams with no up-front stub
  value (e.g. os.Args mutated by the code under test).
- Migrate all 35 remaining manual prev/assign/t.Cleanup-restore trios to
  testseam.Swap/Protect across app, auth, cli, event, helpers, output,
  pipeline, and shortcut tests; restores can no longer be forgotten.
- check-schema-catalog.sh: fail closed when a manual seam restore
  reappears in any *_test.go (internal/testseam exempt).

Seam injection is now a mechanism, not a convention.
This commit is contained in:
玉澜 committed 2026-08-03 20:00:47 +08:00
1 parent e5a47a2d18
commit 0fbdfe0130
30 files changed
+183 -90

No files matched your search

+4 -4
View File
@@ -9,6 +9,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/testseam"
)
func TestCrossPlatformCoverageFlagInfoFromCommandIncludesLocalInheritedAndAnnotations(t *testing.T) {
@@ -49,8 +51,7 @@ func TestCrossPlatformCoverageFlagInfoFromCommandIncludesLocalInheritedAndAnnota
}
func TestCrossPlatformCoverageRunPreParseGuardAndTraversalBranches(t *testing.T) {
previousArgs := os.Args
t.Cleanup(func() { os.Args = previousArgs })
testseam.Protect(t, &os.Args)
root := &cobra.Command{Use: "root"}
root.AddCommand(&cobra.Command{Use: "flagless"})
@@ -70,8 +71,7 @@ func TestCrossPlatformCoverageRunPreParseGuardAndTraversalBranches(t *testing.T)
}
func TestCrossPlatformCoverageRunPreParseAppliesCorrectionsOnlyOnSuccess(t *testing.T) {
previousArgs := os.Args
t.Cleanup(func() { os.Args = previousArgs })
testseam.Protect(t, &os.Args)
buildRoot := func() (*cobra.Command, *string) {
root := &cobra.Command{Use: "root", SilenceErrors: true, SilenceUsage: true}