mirror of
https://github.com/larksuite/cli.git
synced 2026-07-08 10:08:02 +08:00
- hook/install: propagate wrapper-injected ctx to invokeOriginal so RunE/Run see context values added by upstream Wrappers - hook/testing: SetStderrForTesting returns a restore func; tests now defer it via t.Cleanup to avoid cross-test sink leakage - cmdpolicy/active: deep-copy ActivePolicy.Rule on SetActive/GetActive so callers can't mutate the stored global through shared slices - platform/inventory: deep-copy Inventory + nested Plugins / HookEntry / RuleView slices on SetActiveInventory / GetActiveInventory - platform/staging: Restrict clones the plugin-supplied Rule before retaining it so the plugin can't mutate it after Install returns - platform/version: reject RequiredCLIVersion with more than three numeric components instead of silently truncating 1.2.3.4 to 1.2.3 - cmd/platform_bootstrap: clear cmdpolicy.SetActive on yaml resolver error so config policy show doesn't surface a stale rule - cmd/platform_bootstrap_test: tmpHome pins LARKSUITE_CLI_CONFIG_DIR so host env can't bleed into the policy test fixtures - cmdpolicy/apply: installDenyStub returns bool; Apply count no longer over-reports when strict-mode short-circuits the install - cmdpolicy/engine: aggregateParents now returns the runnable hybrid's own denial status when all children are placeholder branches - cmdpolicy/resolver_test: use t.TempDir()-rooted missing path instead of hardcoded /nonexistent for hermetic missing-file assertion - cmd/config/plugins: empty-inventory branch emits total: 0 so the JSON schema stays stable across populated/empty cases - cmd/platform_guards_test: select leaf by RunE != nil (not Runnable) so the test doesn't nil-deref on Run-only commands - gofmt run on previously committed cmdpolicy/path*.go (CI fast-gate)
24 lines
746 B
Go
24 lines
746 B
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package hook
|
|
|
|
import "io"
|
|
|
|
// SetStderrForTesting redirects the hook layer's warning output to a
|
|
// custom writer and returns a restore function the caller MUST defer
|
|
// (or pass to `t.Cleanup`). Without the restore step, a later test in
|
|
// the same binary would inherit the override and either race on a
|
|
// shared bytes.Buffer or write user-visible garbage into a real test
|
|
// stderr.
|
|
//
|
|
// Production code never calls this; the default writer is os.Stderr
|
|
// via defaultStderr.
|
|
func SetStderrForTesting(w io.Writer) (restore func()) {
|
|
prev := stderr
|
|
stderr = func() interface{ Write(p []byte) (int, error) } {
|
|
return w
|
|
}
|
|
return func() { stderr = prev }
|
|
}
|