-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: normalize document write inputs #2003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,10 +91,11 @@ func TestDocs_DryRunDefaultsToV2OpenAPI(t *testing.T) { | |
| "docs", "+update", | ||
| "--doc", "doxcnDryRunE2E", | ||
| "--command", "block_delete", | ||
| "--block-id", "blkA,blkB,blkC", | ||
| "--block-id", "blkA, blkB, blkC", | ||
| "--dry-run", | ||
| }, | ||
| wantContains: []string{"/open-apis/docs_ai/v1/documents/doxcnDryRunE2E"}, | ||
| wantBody: map[string]any{"block_id": "blkA,blkB,blkC"}, | ||
| }, | ||
| { | ||
| name: "history list", | ||
|
|
@@ -225,3 +226,60 @@ func TestDocs_CreateTitleDryRunPrependsContent(t *testing.T) { | |
| require.Equal(t, "markdown", clie2e.DryRunGet(out, "api.0.body.format").String(), "stdout:\n%s", out) | ||
| require.Equal(t, "<title>Dry Run & Title</title>\n## Body", clie2e.DryRunGet(out, "api.0.body.content").String(), "stdout:\n%s", out) | ||
| } | ||
|
|
||
| func TestDocs_CreateTitleDryRunNormalizesXMLTitle(t *testing.T) { | ||
| t.Setenv("LARKSUITE_CLI_APP_ID", "app") | ||
| t.Setenv("LARKSUITE_CLI_APP_SECRET", "secret") | ||
| t.Setenv("LARKSUITE_CLI_BRAND", "feishu") | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| t.Cleanup(cancel) | ||
|
|
||
| result, err := clie2e.RunCmd(ctx, clie2e.Request{ | ||
| Args: []string{ | ||
| "docs", "+create", | ||
| "--title", "Flag title", | ||
| "--content", "<title>Content title</title><p>body</p>", | ||
| "--dry-run", | ||
| }, | ||
| DefaultAs: "bot", | ||
| }) | ||
| require.NoError(t, err) | ||
| result.AssertExitCode(t, 0) | ||
| require.Equal(t, "<title>Flag title</title>\n<p>body</p>", clie2e.DryRunGet(result.Stdout, "api.0.body.content").String()) | ||
| } | ||
|
Comment on lines
+229
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Isolate CLI configuration state in the new dry-run tests. Both tests set fake credentials but inherit Proposed fix func TestDocs_CreateTitleDryRunNormalizesXMLTitle(t *testing.T) {
+ t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
t.Setenv("LARKSUITE_CLI_APP_ID", "app")
t.Setenv("LARKSUITE_CLI_APP_SECRET", "secret")
@@
func TestDocs_DryRunRejectsUnsafeWriteInputs(t *testing.T) {
+ t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
t.Setenv("LARKSUITE_CLI_APP_ID", "app")
t.Setenv("LARKSUITE_CLI_APP_SECRET", "secret")As per coding guidelines, Also applies to: 251-284 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| func TestDocs_DryRunRejectsUnsafeWriteInputs(t *testing.T) { | ||
| t.Setenv("LARKSUITE_CLI_APP_ID", "app") | ||
| t.Setenv("LARKSUITE_CLI_APP_SECRET", "secret") | ||
| t.Setenv("LARKSUITE_CLI_BRAND", "feishu") | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| t.Cleanup(cancel) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| args []string | ||
| want string | ||
| }{ | ||
| { | ||
| name: "multiline XML str_replace", | ||
| args: []string{"docs", "+update", "--doc", "doxcnDryRunE2E", "--command", "str_replace", "--pattern", "line one\nline two", "--content", "replacement", "--dry-run"}, | ||
| want: "must be inline", | ||
| }, | ||
| { | ||
| name: "duplicate block delete ID", | ||
| args: []string{"docs", "+update", "--doc", "doxcnDryRunE2E", "--command", "block_delete", "--block-id", "blkA,blkA", "--dry-run"}, | ||
| want: "duplicate ID", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result, err := clie2e.RunCmd(ctx, clie2e.Request{Args: tt.args, DefaultAs: "bot"}) | ||
| require.NoError(t, err) | ||
| result.AssertExitCode(t, 2) | ||
| require.Contains(t, result.Stdout+"\n"+result.Stderr, tt.want) | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Preserve non-title content exactly when stripping titles.
strings.TrimSpaceremoves bytes outside the matched<title>ranges, including meaningful leading/trailing text-node whitespace. Remove the trim and update the expectation to retain the surrounding newlines; add an adjacent-text case if needed.shortcuts/doc/docs_create_v2.go#L170-L177: return the reconstructed string withoutstrings.TrimSpace.shortcuts/doc/docs_create_test.go#L34-L36: expect"\n<p>body</p>\n"after removing both title elements.As per coding guidelines, “When transcribing input or transforming requests, preserve values faithfully.”
Proposed fix
📝 Committable suggestion
📍 Affects 2 files
shortcuts/doc/docs_create_v2.go#L170-L177(this comment)shortcuts/doc/docs_create_test.go#L34-L36🤖 Prompt for AI Agents
Source: Coding guidelines